mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-04-26 04:46:13 +00:00
rndbuffersize: add support for seeks
Useful for e.g. filesrc ! rndbuffersize ! queue2 ! ...
This commit is contained in:
parent
920e91e072
commit
84c842cfe9
1 changed files with 52 additions and 0 deletions
|
@ -93,6 +93,7 @@ static gboolean gst_rnd_buffer_size_activate_mode (GstPad * pad,
|
||||||
static void gst_rnd_buffer_size_loop (GstRndBufferSize * self);
|
static void gst_rnd_buffer_size_loop (GstRndBufferSize * self);
|
||||||
static GstStateChangeReturn gst_rnd_buffer_size_change_state (GstElement *
|
static GstStateChangeReturn gst_rnd_buffer_size_change_state (GstElement *
|
||||||
element, GstStateChange transition);
|
element, GstStateChange transition);
|
||||||
|
static gboolean gst_rnd_buffer_size_src_event (GstPad * pad, GstEvent * event);
|
||||||
|
|
||||||
GType gst_rnd_buffer_size_get_type (void);
|
GType gst_rnd_buffer_size_get_type (void);
|
||||||
#define gst_rnd_buffer_size_parent_class parent_class
|
#define gst_rnd_buffer_size_parent_class parent_class
|
||||||
|
@ -152,6 +153,8 @@ gst_rnd_buffer_size_init (GstRndBufferSize * self)
|
||||||
gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
|
gst_element_add_pad (GST_ELEMENT (self), self->sinkpad);
|
||||||
|
|
||||||
self->srcpad = gst_pad_new_from_static_template (&src_template, "src");
|
self->srcpad = gst_pad_new_from_static_template (&src_template, "src");
|
||||||
|
gst_pad_set_event_function (self->srcpad,
|
||||||
|
GST_DEBUG_FUNCPTR (gst_rnd_buffer_size_src_event));
|
||||||
gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
|
gst_element_add_pad (GST_ELEMENT (self), self->srcpad);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -274,6 +277,55 @@ gst_rnd_buffer_size_activate_mode (GstPad * pad, GstObject * parent,
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
gst_rnd_buffer_size_src_event (GstPad * pad, GstEvent * event)
|
||||||
|
{
|
||||||
|
GstRndBufferSize *self;
|
||||||
|
GstSeekType start_type;
|
||||||
|
GstSeekFlags flags;
|
||||||
|
GstFormat format;
|
||||||
|
gint64 start;
|
||||||
|
|
||||||
|
if (GST_EVENT_TYPE (event) != GST_EVENT_SEEK) {
|
||||||
|
GST_WARNING_OBJECT (pad, "dropping %s event", GST_EVENT_TYPE_NAME (event));
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
self = GST_RND_BUFFER_SIZE (GST_OBJECT_PARENT (pad));
|
||||||
|
gst_event_parse_seek (event, NULL, &format, &flags, &start_type, &start,
|
||||||
|
NULL, NULL);
|
||||||
|
|
||||||
|
if (format != GST_FORMAT_BYTES) {
|
||||||
|
GST_WARNING_OBJECT (pad, "only BYTE format supported");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (start_type != GST_SEEK_TYPE_SET) {
|
||||||
|
GST_WARNING_OBJECT (pad, "only SEEK_TYPE_SET supported");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((flags & GST_SEEK_FLAG_FLUSH)) {
|
||||||
|
gst_pad_push_event (self->srcpad, gst_event_new_flush_start ());
|
||||||
|
gst_pad_push_event (self->sinkpad, gst_event_new_flush_start ());
|
||||||
|
gst_pad_push_event (self->srcpad, gst_event_new_flush_stop ());
|
||||||
|
gst_pad_push_event (self->sinkpad, gst_event_new_flush_stop ());
|
||||||
|
} else {
|
||||||
|
gst_pad_pause_task (self->sinkpad);
|
||||||
|
}
|
||||||
|
|
||||||
|
GST_PAD_STREAM_LOCK (self->sinkpad);
|
||||||
|
|
||||||
|
GST_INFO_OBJECT (pad, "seeking to offset %" G_GINT64_FORMAT, start);
|
||||||
|
|
||||||
|
self->offset = start;
|
||||||
|
self->need_newsegment = TRUE;
|
||||||
|
|
||||||
|
gst_pad_start_task (self->sinkpad, (GstTaskFunction) gst_rnd_buffer_size_loop,
|
||||||
|
self);
|
||||||
|
|
||||||
|
GST_PAD_STREAM_UNLOCK (self->sinkpad);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gst_rnd_buffer_size_loop (GstRndBufferSize * self)
|
gst_rnd_buffer_size_loop (GstRndBufferSize * self)
|
||||||
|
|
Loading…
Reference in a new issue