@@ -211,6 +211,8 @@ struct _GstTIPerfOverlay
211211 graph_height;
212212 guint
213213 num_graphs;
214+ gboolean
215+ num_graphs_negotiated;
214216 guint
215217 update_stats_interval;
216218 gint64
@@ -223,6 +225,8 @@ struct _GstTIPerfOverlay
223225 frames_rendered;
224226 guint8
225227 fps;
228+ guint64
229+ frame_count;
226230 GstClockTime
227231 previous_fps_timestamp;
228232 GstClockTime
@@ -264,9 +268,11 @@ gst_ti_perf_overlay_set_caps (GstBaseTransform * trans,
264268static
265269 GstFlowReturn
266270gst_ti_perf_overlay_transform_ip (GstBaseTransform * trans, GstBuffer * buffer);
271+ static void
272+ update_perf_stats (GstTIPerfOverlay * self);
267273static
268274 guint
269- update_perf_stats (GstTIPerfOverlay * self);
275+ get_graph_count (GstTIPerfOverlay * self);
270276static void
271277display_perf_stats_text (GstTIPerfOverlay * self);
272278static void
@@ -377,6 +383,7 @@ gst_ti_perf_overlay_init (GstTIPerfOverlay * self)
377383 self->graph_width = 0 ;
378384 self->graph_height = 0 ;
379385 self->num_graphs = 0 ;
386+ self->num_graphs_negotiated = FALSE ;
380387 self->update_fps_interval = DEFAULT_UPDATE_FPS_INTERVAL ;
381388 self->update_fps_interval_m = GST_MSECOND * self->update_fps_interval ;
382389 self->update_stats_interval = DEFAULT_UPDATE_STATS_INTERVAL ;
@@ -407,6 +414,7 @@ gst_ti_perf_overlay_init (GstTIPerfOverlay * self)
407414 if (NULL == self->tiovx_context ) {
408415 GST_ERROR_OBJECT (self, " Failed to do common initialization" );
409416 }
417+ self->frame_count = 0 ;
410418 return ;
411419}
412420
@@ -531,21 +539,10 @@ gst_ti_perf_overlay_set_caps (GstBaseTransform * trans, GstCaps * incaps,
531539 getFont (self->main_title_font_property , (int ) (0.02 * self->image_width ));
532540 getFont (self->title_font_property , (int ) (0.015 * self->image_width ));
533541
534- self->num_graphs = update_perf_stats (self);
535- for (guint i = 0 ; i < self->num_graphs ; i++) {
536- self->bar_graphs [i] = new BarGraph;
537- }
538-
539- self->graph_height = (0.5 * self->overlay_height );
540- self->graph_pos_y = self->overlay_pos_y + 10 ;
541- self->graph_width = (0.03 * self->overlay_width );
542- self->graph_offset_x = (self->overlay_width -
543- (self->graph_width * self->num_graphs )) / self->num_graphs ;
544- self->graph_pos_x = self->graph_offset_x - (self->graph_offset_x / 2 );
545- self->fps_x_pos = (self->image_width - (9 *self->big_font_property ->width ));
542+ self->fps_x_pos = (self->image_width - (16 *self->big_font_property ->width ));
546543 self->fps_y_pos = 0 ;
547- self->fps_width = 9 *self->big_font_property ->width ;
548- self->fps_height = self->big_font_property ->height ;
544+ self->fps_width = 16 *self->big_font_property ->width ;
545+ self->fps_height = ( 2 * self->big_font_property ->height )+ 1 ;
549546
550547exit:
551548 return ret;
@@ -560,14 +557,29 @@ gst_ti_perf_overlay_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
560557 GstFlowReturn ret = GST_FLOW_ERROR ;
561558 GstMapInfo buffer_mapinfo;
562559 GstClockTime current_timestamp;
563- gchar fps_buffer[ 20 ];
560+ gchar text_buffer[ 50 ];
564561
565562 GST_LOG_OBJECT (self, " transform_ip" );
566563 if (!gst_buffer_map (buffer, &buffer_mapinfo, GST_MAP_READWRITE )) {
567564 GST_ERROR_OBJECT (self, " failed to map buffer" );
568565 goto exit;
569566 }
570567
568+ if (!self->num_graphs_negotiated ) {
569+ update_perf_stats (self);
570+ self->num_graphs = get_graph_count (self);
571+ for (guint i = 0 ; i < self->num_graphs ; i++) {
572+ self->bar_graphs [i] = new BarGraph;
573+ }
574+ self->graph_height = (0.5 * self->overlay_height );
575+ self->graph_pos_y = self->overlay_pos_y + 10 ;
576+ self->graph_width = (0.03 * self->overlay_width );
577+ self->graph_offset_x = (self->overlay_width -
578+ (self->graph_width * self->num_graphs )) / self->num_graphs ;
579+ self->graph_pos_x = self->graph_offset_x - (self->graph_offset_x / 2 );
580+ self->num_graphs_negotiated = TRUE ;
581+ }
582+
571583 self->image_handler ->yRowAddr = (uint8_t *) buffer_mapinfo.data ;
572584 self->image_handler ->uvRowAddr =
573585 self->image_handler ->yRowAddr + self->uv_offset ;
@@ -587,7 +599,6 @@ gst_ti_perf_overlay_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
587599 self->color_green );
588600 }
589601
590-
591602 if (self->overlay_graphics || self->overlay_text ) {
592603 g_atomic_int_inc (&self->frames_rendered );
593604 current_timestamp = gst_util_get_timestamp ();
@@ -597,10 +608,11 @@ gst_ti_perf_overlay_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
597608 }
598609 else if (GST_CLOCK_DIFF (self->previous_fps_timestamp , current_timestamp) >
599610 self->update_fps_interval_m ) {
600- gdouble mul_factor = (double )(self->update_fps_interval )/1000 ;
601- self->fps = round (self->frames_rendered /mul_factor);
602- self->previous_fps_timestamp = current_timestamp;
603- self->frames_rendered = 0 ;
611+ gdouble mul_factor = (double )(self->update_fps_interval )/1000 ;
612+ self->fps = round (self->frames_rendered /mul_factor);
613+ self->previous_fps_timestamp = current_timestamp;
614+ self->frame_count += self->frames_rendered ;
615+ self->frames_rendered = 0 ;
604616 }
605617
606618 if (self->previous_stats_timestamp == GST_CLOCK_TIME_NONE ) {
@@ -617,25 +629,31 @@ gst_ti_perf_overlay_transform_ip (GstBaseTransform * trans, GstBuffer * buffer)
617629 if (self->overlay_text )
618630 display_perf_stats_text (self);
619631
620- sprintf (fps_buffer ," FPS: %u" ,self->fps );
632+ sprintf (text_buffer ," FPS: %u" ,self->fps );
621633 fillRegion (self->image_handler ,
622634 self->fps_x_pos ,
623635 self->fps_y_pos ,
624636 self->fps_width ,
625637 self->fps_height ,
626638 self->color_black );
627639 drawText (self->image_handler ,
628- fps_buffer ,
629- self->fps_x_pos +self->big_font_property ->width ,
640+ text_buffer ,
641+ self->fps_x_pos +( 4 * self->big_font_property ->width ) ,
630642 self->fps_y_pos ,
631643 self->big_font_property ,
632644 self->color_white );
645+ sprintf (text_buffer," Frame: %lu" ,self->frame_count );
646+ drawText (self->image_handler ,
647+ text_buffer,
648+ self->fps_x_pos +self->big_font_property ->width ,
649+ self->fps_y_pos + self->big_font_property ->height + 1 ,
650+ self->big_font_property ,
651+ self->color_white );
633652 }
634653 gst_buffer_unmap (buffer, &buffer_mapinfo);
635654 ret = GST_FLOW_OK ;
636655exit:
637656 return ret;
638-
639657}
640658
641659static void
@@ -818,18 +836,50 @@ display_perf_stats_graphics (GstTIPerfOverlay * self)
818836 count++;
819837}
820838
821-
822839static
823840 guint
841+ get_graph_count (GstTIPerfOverlay * self)
842+ {
843+ guint count = 0 ;
844+ guint cpu_id;
845+ guint i;
846+ // CPU Load
847+ for (cpu_id = 0 ; cpu_id < APP_IPC_CPU_MAX ; cpu_id++) {
848+ if (appIpcIsCpuEnabled (cpu_id)) {
849+ count++;
850+ }
851+ }
852+
853+ // HWA
854+ for (i = 0 ; i < sizeof (self->hwa_loads ) / sizeof (self->hwa_loads [0 ]); i++) {
855+ guint hwa_id;
856+ app_perf_stats_hwa_load_t *
857+ hwaLoad;
858+ for (hwa_id = 0 ; hwa_id < APP_PERF_HWA_MAX ; hwa_id++) {
859+ app_perf_hwa_id_t id = (app_perf_hwa_id_t ) hwa_id;
860+ hwaLoad = &self->hwa_loads [i].hwa_stats [id];
861+ if (hwaLoad->active_time > 0 && hwaLoad->pixels_processed > 0
862+ && hwaLoad->total_time > 0 ) {
863+ count++;
864+ }
865+ }
866+ }
867+
868+ // DDR READ AND WRITE
869+ count += 2 ;
870+ return count;
871+ }
872+
873+
874+ static
875+ void
824876update_perf_stats (GstTIPerfOverlay * self)
825877{
826878 // CPU
827- guint count = 0 ;
828879 guint cpu_id;
829880 for (cpu_id = 0 ; cpu_id < APP_IPC_CPU_MAX ; cpu_id++) {
830881 if (appIpcIsCpuEnabled (cpu_id)) {
831882 appPerfStatsCpuLoadGet (cpu_id, &self->cpu_loads [cpu_id]);
832- count++;
833883 }
834884 }
835885
@@ -845,11 +895,9 @@ update_perf_stats (GstTIPerfOverlay * self)
845895#endif
846896#endif
847897 appPerfStatsHwaStatsGet (APP_IPC_CPU_MPU1_0 , &self->hwa_loads [hwa_count++]);
848- count += hwa_count - 1 ;
849898
850899 // DDR
851900 appPerfStatsDdrStatsGet (&self->ddr_load );
852- count += 2 ;
853901
854902 // Reset
855903 for (cpu_id = 0 ; cpu_id < APP_IPC_CPU_MAX ; cpu_id++) {
@@ -877,5 +925,4 @@ update_perf_stats (GstTIPerfOverlay * self)
877925 appRemoteServiceRun (APP_PERF_STATS_GET_DDR_STATS_CORE ,
878926 APP_PERF_STATS_SERVICE_NAME ,
879927 APP_PERF_STATS_CMD_RESET_DDR_STATS , NULL , 0 , 0 );
880- return count;
881928}
0 commit comments