mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-23 22:46:24 +00:00
timeoverlay: Add elapsed-running-time mode
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>
This commit is contained in:
parent
aa89ae8beb
commit
28ff6b377d
3 changed files with 66 additions and 0 deletions
|
@ -8563,6 +8563,11 @@
|
||||||
"desc": "time-code",
|
"desc": "time-code",
|
||||||
"name": "time-code",
|
"name": "time-code",
|
||||||
"value": "3"
|
"value": "3"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"desc": "elapsed-running-time",
|
||||||
|
"name": "elapsed-running-time",
|
||||||
|
"value": "4"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
@ -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,
|
static void gst_time_overlay_get_property (GObject * object, guint prop_id,
|
||||||
GValue * value, GParamSpec * pspec);
|
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())
|
#define GST_TYPE_TIME_OVERLAY_TIME_LINE (gst_time_overlay_time_line_type())
|
||||||
static GType
|
static GType
|
||||||
gst_time_overlay_time_line_type (void)
|
gst_time_overlay_time_line_type (void)
|
||||||
|
@ -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_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"},
|
{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},
|
{0, NULL, NULL},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -150,6 +160,12 @@ gst_time_overlay_get_text (GstBaseTextOverlay * overlay,
|
||||||
case GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME:
|
case GST_TIME_OVERLAY_TIME_LINE_RUNNING_TIME:
|
||||||
ts = gst_segment_to_running_time (segment, GST_FORMAT_TIME, ts_buffer);
|
ts = gst_segment_to_running_time (segment, GST_FORMAT_TIME, ts_buffer);
|
||||||
break;
|
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:
|
case GST_TIME_OVERLAY_TIME_LINE_BUFFER_TIME:
|
||||||
default:
|
default:
|
||||||
ts = ts_buffer;
|
ts = ts_buffer;
|
||||||
|
@ -184,6 +200,22 @@ gst_time_overlay_get_text (GstBaseTextOverlay * overlay,
|
||||||
return ret;
|
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
|
static void
|
||||||
gst_time_overlay_finalize (GObject * gobject)
|
gst_time_overlay_finalize (GObject * gobject)
|
||||||
{
|
{
|
||||||
|
@ -212,6 +244,8 @@ gst_time_overlay_class_init (GstTimeOverlayClass * klass)
|
||||||
|
|
||||||
gsttextoverlay_class->get_text = gst_time_overlay_get_text;
|
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->finalize = gst_time_overlay_finalize;
|
||||||
gobject_class->set_property = gst_time_overlay_set_property;
|
gobject_class->set_property = gst_time_overlay_set_property;
|
||||||
gobject_class->get_property = gst_time_overlay_get_property;
|
gobject_class->get_property = gst_time_overlay_get_property;
|
||||||
|
@ -241,12 +275,30 @@ gst_time_overlay_class_init (GstTimeOverlayClass * klass)
|
||||||
gst_type_mark_as_plugin_api (GST_TYPE_TIME_OVERLAY_TIME_LINE, 0);
|
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
|
static void
|
||||||
gst_time_overlay_init (GstTimeOverlay * overlay)
|
gst_time_overlay_init (GstTimeOverlay * overlay)
|
||||||
{
|
{
|
||||||
GstBaseTextOverlay *textoverlay;
|
GstBaseTextOverlay *textoverlay;
|
||||||
PangoContext *context;
|
PangoContext *context;
|
||||||
PangoFontDescription *font_description;
|
PangoFontDescription *font_description;
|
||||||
|
GstPad *video_sink;
|
||||||
|
|
||||||
textoverlay = GST_BASE_TEXT_OVERLAY (overlay);
|
textoverlay = GST_BASE_TEXT_OVERLAY (overlay);
|
||||||
|
|
||||||
|
@ -272,6 +324,10 @@ gst_time_overlay_init (GstTimeOverlay * overlay)
|
||||||
pango_font_description_set_size (font_description, 18 * PANGO_SCALE);
|
pango_font_description_set_size (font_description, 18 * PANGO_SCALE);
|
||||||
pango_context_set_font_description (context, font_description);
|
pango_context_set_font_description (context, font_description);
|
||||||
pango_font_description_free (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
|
static void
|
||||||
|
|
|
@ -46,6 +46,7 @@ typedef enum {
|
||||||
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,
|
GST_TIME_OVERLAY_TIME_LINE_TIME_CODE,
|
||||||
|
GST_TIME_OVERLAY_TIME_LINE_ELAPSED_RUNNING_TIME,
|
||||||
} GstTimeOverlayTimeLine;
|
} GstTimeOverlayTimeLine;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,6 +64,10 @@ struct _GstTimeOverlay {
|
||||||
gboolean show_times_as_dates;
|
gboolean show_times_as_dates;
|
||||||
gchar *datetime_format;
|
gchar *datetime_format;
|
||||||
GDateTime *datetime_epoch;
|
GDateTime *datetime_epoch;
|
||||||
|
|
||||||
|
/* For GST_TIME_OVERLAY_TIME_LINE_ELAPSED_RUNNING_TIME mode */
|
||||||
|
GstClockTime first_running_time;
|
||||||
|
GstPadEventFunction orig_video_event;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _GstTimeOverlayClass {
|
struct _GstTimeOverlayClass {
|
||||||
|
|
Loading…
Reference in a new issue