timeoverlay: Add support to display timecode

Choosing time-mode=time-code will display the time code attached to the
buffer, or 00:00:00:00 if no time code is found.

https://bugzilla.gnome.org/show_bug.cgi?id=766419
This commit is contained in:
Vivia Nikolaidou 2016-05-18 19:30:52 +03:00 committed by Sebastian Dröge
parent 8d8384f20a
commit a993dd40b6
2 changed files with 40 additions and 26 deletions

View File

@ -74,6 +74,7 @@ gst_time_overlay_time_line_type (void)
{GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME, "buffer-time", "buffer-time"}, {GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME, "buffer-time", "buffer-time"},
{GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME, "stream-time", "stream-time"}, {GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME, "stream-time", "stream-time"},
{GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME, "running-time", "running-time"}, {GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME, "running-time", "running-time"},
{GST_TIME_OVERLAY_TIME_LINE_TIME_CODE, "time-code", "time-code"},
{0, NULL, NULL}, {0, NULL, NULL},
}; };
@ -105,39 +106,51 @@ gst_time_overlay_get_text (GstBaseTextOverlay * overlay,
GstBuffer * video_frame) GstBuffer * video_frame)
{ {
GstTimeOverlayTimeLine time_line; GstTimeOverlayTimeLine time_line;
GstClockTime ts, ts_buffer;
GstSegment *segment = &overlay->segment;
gchar *time_str, *txt, *ret; gchar *time_str, *txt, *ret;
overlay->need_render = TRUE; overlay->need_render = TRUE;
ts_buffer = GST_BUFFER_TIMESTAMP (video_frame);
if (!GST_CLOCK_TIME_IS_VALID (ts_buffer)) {
GST_DEBUG ("buffer without valid timestamp");
return g_strdup ("");
}
GST_DEBUG ("buffer with timestamp %" GST_TIME_FORMAT,
GST_TIME_ARGS (ts_buffer));
time_line = g_atomic_int_get (&GST_TIME_OVERLAY_CAST (overlay)->time_line); time_line = g_atomic_int_get (&GST_TIME_OVERLAY_CAST (overlay)->time_line);
switch (time_line) { if (time_line == GST_TIME_OVERLAY_TIME_LINE_TIME_CODE) {
case GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME: GstVideoTimeCodeMeta *tc_meta =
ts = gst_segment_to_stream_time (segment, GST_FORMAT_TIME, ts_buffer); gst_buffer_get_video_time_code_meta (video_frame);
break; if (!tc_meta) {
case GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME: GST_DEBUG ("buffer without valid timecode");
ts = gst_segment_to_running_time (segment, GST_FORMAT_TIME, ts_buffer); return g_strdup ("00:00:00:00");
break; }
case GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME: time_str = gst_video_time_code_to_string (&tc_meta->tc);
default: GST_DEBUG ("buffer with timecode %s", time_str);
ts = ts_buffer; } else {
break; GstClockTime ts, ts_buffer;
} GstSegment *segment = &overlay->segment;
ts_buffer = GST_BUFFER_TIMESTAMP (video_frame);
if (!GST_CLOCK_TIME_IS_VALID (ts_buffer)) {
GST_DEBUG ("buffer without valid timestamp");
return g_strdup ("");
}
GST_DEBUG ("buffer with timestamp %" GST_TIME_FORMAT,
GST_TIME_ARGS (ts_buffer));
switch (time_line) {
case GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME:
ts = gst_segment_to_stream_time (segment, GST_FORMAT_TIME, ts_buffer);
break;
case GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME:
ts = gst_segment_to_running_time (segment, GST_FORMAT_TIME, ts_buffer);
break;
case GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME:
default:
ts = ts_buffer;
break;
}
time_str = gst_time_overlay_render_time (GST_TIME_OVERLAY (overlay), ts);
}
txt = g_strdup (overlay->default_text); txt = g_strdup (overlay->default_text);
time_str = gst_time_overlay_render_time (GST_TIME_OVERLAY (overlay), ts);
if (txt != NULL && *txt != '\0') { if (txt != NULL && *txt != '\0') {
ret = g_strdup_printf ("%s %s", txt, time_str); ret = g_strdup_printf ("%s %s", txt, time_str);
} else { } else {

View File

@ -44,7 +44,8 @@ typedef struct _GstTimeOverlayClass GstTimeOverlayClass;
typedef enum { typedef enum {
GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME, GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME,
GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME, GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME,
GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME,
GST_TIME_OVERLAY_TIME_LINE_TIME_CODE
} GstTimeOverlayTimeLine; } GstTimeOverlayTimeLine;
/** /**