Skip to content

Commit

Permalink
timeoverlay: Add elapsed-running-time mode
Browse files Browse the repository at this point in the history
This takes the first running time and the first after each flush-stop as
an offset for the running time that is rendered.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-base/-/merge_requests/737>
  • Loading branch information
sdroege committed Oct 8, 2020
1 parent aa89ae8 commit 28ff6b3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/plugins/gst_plugins_cache.json
Expand Up @@ -8563,6 +8563,11 @@
"desc": "time-code",
"name": "time-code",
"value": "3"
},
{
"desc": "elapsed-running-time",
"name": "elapsed-running-time",
"value": "4"
}
]
}
Expand Down
56 changes: 56 additions & 0 deletions ext/pango/gsttimeoverlay.c
Expand Up @@ -73,6 +73,14 @@ static void gst_time_overlay_set_property (GObject * object, guint prop_id,
static void gst_time_overlay_get_property (GObject * object, guint prop_id,
GValue * value, GParamSpec * pspec);

/**
* GstTimeOverlayTimeLine::elapsed-running-time:
*
* Overlay elapsed running time since the first observed running time.
*
* Since: 1.20
*/

#define GST_TYPE_TIME_OVERLAY_TIME_LINE (gst_time_overlay_time_line_type())
static GType
gst_time_overlay_time_line_type (void)
Expand All @@ -83,6 +91,8 @@ gst_time_overlay_time_line_type (void)
{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_TIME_CODE, "time-code", "time-code"},
{GST_TIME_OVERLAY_TIME_LINE_ELAPSED_RUNNING_TIME,
"elapsed-running-time", "elapsed-running-time"},
{0, NULL, NULL},
};

Expand Down Expand Up @@ -150,6 +160,12 @@ gst_time_overlay_get_text (GstBaseTextOverlay * overlay,
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_ELAPSED_RUNNING_TIME:
ts = gst_segment_to_running_time (segment, GST_FORMAT_TIME, ts_buffer);
if (self->first_running_time == GST_CLOCK_TIME_NONE)
self->first_running_time = ts;
ts -= self->first_running_time;
break;
case GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME:
default:
ts = ts_buffer;
Expand Down Expand Up @@ -184,6 +200,22 @@ gst_time_overlay_get_text (GstBaseTextOverlay * overlay,
return ret;
}

static GstStateChangeReturn
gst_time_overlay_change_state (GstElement * element, GstStateChange transition)
{
GstTimeOverlay *self = GST_TIME_OVERLAY (element);

switch (transition) {
case GST_STATE_CHANGE_READY_TO_PAUSED:
self->first_running_time = GST_CLOCK_TIME_NONE;
break;
default:
break;
}

return GST_ELEMENT_CLASS (parent_class)->change_state (element, transition);
}

static void
gst_time_overlay_finalize (GObject * gobject)
{
Expand Down Expand Up @@ -212,6 +244,8 @@ gst_time_overlay_class_init (GstTimeOverlayClass * klass)

gsttextoverlay_class->get_text = gst_time_overlay_get_text;

gstelement_class->change_state = gst_time_overlay_change_state;

gobject_class->finalize = gst_time_overlay_finalize;
gobject_class->set_property = gst_time_overlay_set_property;
gobject_class->get_property = gst_time_overlay_get_property;
Expand Down Expand Up @@ -241,12 +275,30 @@ gst_time_overlay_class_init (GstTimeOverlayClass * klass)
gst_type_mark_as_plugin_api (GST_TYPE_TIME_OVERLAY_TIME_LINE, 0);
}

static gboolean
gst_time_overlay_video_event (GstPad * pad, GstObject * parent,
GstEvent * event)
{
GstTimeOverlay *overlay = GST_TIME_OVERLAY (parent);

switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_FLUSH_STOP:
overlay->first_running_time = GST_CLOCK_TIME_NONE;
break;
default:
break;
}

return overlay->orig_video_event (pad, parent, event);
}

static void
gst_time_overlay_init (GstTimeOverlay * overlay)
{
GstBaseTextOverlay *textoverlay;
PangoContext *context;
PangoFontDescription *font_description;
GstPad *video_sink;

textoverlay = GST_BASE_TEXT_OVERLAY (overlay);

Expand All @@ -272,6 +324,10 @@ gst_time_overlay_init (GstTimeOverlay * overlay)
pango_font_description_set_size (font_description, 18 * PANGO_SCALE);
pango_context_set_font_description (context, font_description);
pango_font_description_free (font_description);

video_sink = gst_element_get_static_pad (GST_ELEMENT (overlay), "video_sink");
overlay->orig_video_event = GST_PAD_EVENTFUNC (video_sink);
gst_pad_set_event_function (video_sink, gst_time_overlay_video_event);
}

static void
Expand Down
5 changes: 5 additions & 0 deletions ext/pango/gsttimeoverlay.h
Expand Up @@ -46,6 +46,7 @@ typedef enum {
GST_TIME_OVERLAY_TIME_LINE_STREAM_TIME,
GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME,
GST_TIME_OVERLAY_TIME_LINE_TIME_CODE,
GST_TIME_OVERLAY_TIME_LINE_ELAPSED_RUNNING_TIME,
} GstTimeOverlayTimeLine;

/**
Expand All @@ -63,6 +64,10 @@ struct _GstTimeOverlay {
gboolean show_times_as_dates;
gchar *datetime_format;
GDateTime *datetime_epoch;

/* For GST_TIME_OVERLAY_TIME_LINE_ELAPSED_RUNNING_TIME mode */
GstClockTime first_running_time;
GstPadEventFunction orig_video_event;
};

struct _GstTimeOverlayClass {
Expand Down

0 comments on commit 28ff6b3

Please sign in to comment.