basesink: make it easy to override the pad query

Add a vmethod to handle the pad query.
Install a default handler for the pad query.
Use the new query function in filesink
This commit is contained in:
Nicolas Dufresne 2011-09-07 17:21:55 -04:00 committed by Sebastian Dröge
parent 7a82ed41f8
commit f0219b327d
3 changed files with 62 additions and 18 deletions

View file

@ -366,7 +366,7 @@ static void gst_base_sink_get_property (GObject * object, guint prop_id,
static gboolean gst_base_sink_send_event (GstElement * element,
GstEvent * event);
static gboolean gst_base_sink_query (GstElement * element, GstQuery * query);
static gboolean default_element_query (GstElement * element, GstQuery * query);
static const GstQueryType *gst_base_sink_get_query_types (GstElement * element);
static GstCaps *gst_base_sink_get_caps (GstBaseSink * sink);
@ -387,6 +387,7 @@ static gboolean gst_base_sink_default_prepare_seek_segment (GstBaseSink * sink,
static GstStateChangeReturn gst_base_sink_change_state (GstElement * element,
GstStateChange transition);
static gboolean gst_base_sink_sink_query (GstPad * pad, GstQuery * query);
static GstFlowReturn gst_base_sink_chain (GstPad * pad, GstBuffer * buffer);
static GstFlowReturn gst_base_sink_chain_list (GstPad * pad,
GstBufferList * list);
@ -397,6 +398,8 @@ static gboolean gst_base_sink_pad_activate_push (GstPad * pad, gboolean active);
static gboolean gst_base_sink_pad_activate_pull (GstPad * pad, gboolean active);
static gboolean gst_base_sink_event (GstPad * pad, GstEvent * event);
static gboolean default_sink_query (GstBaseSink * sink, GstQuery * query);
static gboolean gst_base_sink_negotiate_pull (GstBaseSink * basesink);
static GstCaps *gst_base_sink_pad_getcaps (GstPad * pad);
static gboolean gst_base_sink_pad_setcaps (GstPad * pad, GstCaps * caps);
@ -552,7 +555,7 @@ gst_base_sink_class_init (GstBaseSinkClass * klass)
gstelement_class->change_state =
GST_DEBUG_FUNCPTR (gst_base_sink_change_state);
gstelement_class->send_event = GST_DEBUG_FUNCPTR (gst_base_sink_send_event);
gstelement_class->query = GST_DEBUG_FUNCPTR (gst_base_sink_query);
gstelement_class->query = GST_DEBUG_FUNCPTR (default_element_query);
gstelement_class->get_query_types =
GST_DEBUG_FUNCPTR (gst_base_sink_get_query_types);
@ -562,6 +565,7 @@ gst_base_sink_class_init (GstBaseSinkClass * klass)
klass->get_times = GST_DEBUG_FUNCPTR (gst_base_sink_get_times);
klass->activate_pull =
GST_DEBUG_FUNCPTR (gst_base_sink_default_activate_pull);
klass->query = GST_DEBUG_FUNCPTR (default_sink_query);
/* Registering debug symbols for function pointers */
GST_DEBUG_REGISTER_FUNCPTR (gst_base_sink_pad_getcaps);
@ -693,6 +697,7 @@ gst_base_sink_init (GstBaseSink * basesink, gpointer g_class)
gst_base_sink_pad_activate_push);
gst_pad_set_activatepull_function (basesink->sinkpad,
gst_base_sink_pad_activate_pull);
gst_pad_set_query_function (basesink->sinkpad, gst_base_sink_sink_query);
gst_pad_set_event_function (basesink->sinkpad, gst_base_sink_event);
gst_pad_set_chain_function (basesink->sinkpad, gst_base_sink_chain);
gst_pad_set_chain_list_function (basesink->sinkpad, gst_base_sink_chain_list);
@ -4819,7 +4824,7 @@ gst_base_sink_get_query_types (GstElement * element)
}
static gboolean
gst_base_sink_query (GstElement * element, GstQuery * query)
default_element_query (GstElement * element, GstQuery * query)
{
gboolean res = FALSE;
@ -4944,6 +4949,37 @@ gst_base_sink_query (GstElement * element, GstQuery * query)
return res;
}
static gboolean
default_sink_query (GstBaseSink * basesink, GstQuery * query)
{
return gst_pad_query_default (basesink->sinkpad, query);
}
static gboolean
gst_base_sink_sink_query (GstPad * pad, GstQuery * query)
{
GstBaseSink *basesink;
GstBaseSinkClass *bclass;
gboolean res;
basesink = GST_BASE_SINK_CAST (gst_pad_get_parent (pad));
if (G_UNLIKELY (basesink == NULL)) {
gst_query_unref (query);
return FALSE;
}
bclass = GST_BASE_SINK_GET_CLASS (basesink);
if (bclass->query)
res = bclass->query (basesink, query);
else
res = FALSE;
gst_object_unref (basesink);
return res;
}
static GstStateChangeReturn
gst_base_sink_change_state (GstElement * element, GstStateChange transition)
{

View file

@ -133,6 +133,7 @@ struct _GstBaseSink {
* @fixate: Only useful in pull mode, this vmethod will be called in response to
* gst_pad_fixate_caps() being called on the sink pad. Implement if you have
* ideas about what should be the default values for the caps you support.
* @query: perform a #GstQuery on the element. Since: 0.10.36
*
* Subclasses can override any of the available virtual methods or not, as
* needed. At the minimum, the @render method should be overridden to
@ -186,8 +187,11 @@ struct _GstBaseSinkClass {
/* Render a BufferList */
GstFlowReturn (*render_list) (GstBaseSink *sink, GstBufferList *buffer_list);
/* notify subclass of query */
gboolean (*query) (GstBaseSink *sink, GstQuery *query);
/*< private >*/
gpointer _gst_reserved[GST_PADDING_LARGE-5];
gpointer _gst_reserved[GST_PADDING_LARGE-6];
};
GType gst_base_sink_get_type(void);

View file

@ -168,7 +168,7 @@ static gboolean gst_file_sink_do_seek (GstFileSink * filesink,
static gboolean gst_file_sink_get_current_offset (GstFileSink * filesink,
guint64 * p_pos);
static gboolean gst_file_sink_query (GstPad * pad, GstQuery * query);
static gboolean gst_file_sink_query (GstBaseSink * bsink, GstQuery * query);
static void gst_file_sink_uri_handler_init (gpointer g_iface,
gpointer iface_data);
@ -246,6 +246,7 @@ gst_file_sink_class_init (GstFileSinkClass * klass)
gstbasesink_class->start = GST_DEBUG_FUNCPTR (gst_file_sink_start);
gstbasesink_class->stop = GST_DEBUG_FUNCPTR (gst_file_sink_stop);
gstbasesink_class->query = GST_DEBUG_FUNCPTR (gst_file_sink_query);
gstbasesink_class->render = GST_DEBUG_FUNCPTR (gst_file_sink_render);
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_file_sink_event);
@ -258,12 +259,6 @@ gst_file_sink_class_init (GstFileSinkClass * klass)
static void
gst_file_sink_init (GstFileSink * filesink, GstFileSinkClass * g_class)
{
GstPad *pad;
pad = GST_BASE_SINK_PAD (filesink);
gst_pad_set_query_function (pad, GST_DEBUG_FUNCPTR (gst_file_sink_query));
filesink->filename = NULL;
filesink->file = NULL;
filesink->buffer_mode = DEFAULT_BUFFER_MODE;
@ -466,36 +461,45 @@ close_failed:
}
static gboolean
gst_file_sink_query (GstPad * pad, GstQuery * query)
gst_file_sink_query (GstBaseSink * bsink, GstQuery * query)
{
gboolean res;
GstFileSink *self;
GstFormat format;
self = GST_FILE_SINK (GST_PAD_PARENT (pad));
self = GST_FILE_SINK (bsink);
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_POSITION:
gst_query_parse_position (query, &format, NULL);
switch (format) {
case GST_FORMAT_DEFAULT:
case GST_FORMAT_BYTES:
gst_query_set_position (query, GST_FORMAT_BYTES, self->current_pos);
return TRUE;
res = TRUE;
break;
default:
return FALSE;
res = FALSE;
break;
}
break;
case GST_QUERY_FORMATS:
gst_query_set_formats (query, 2, GST_FORMAT_DEFAULT, GST_FORMAT_BYTES);
return TRUE;
res = TRUE;
break;
case GST_QUERY_URI:
gst_query_set_uri (query, self->uri);
return TRUE;
res = TRUE;
break;
default:
return gst_pad_query_default (pad, query);
res = GST_BASE_SINK_CLASS (parent_class)->query (bsink, query);
break;
}
return res;
}
#ifdef HAVE_FSEEKO