From 729e3c8a1034ad7cb53e69d6578de66fdc342d6e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Mon, 9 Dec 2013 16:33:40 +0100 Subject: [PATCH] videoencoder: Add sink_query() src_query() virtual functions Based on the videodecoder change by Nicolas Dufresne and applied here for consistency. https://bugzilla.gnome.org/show_bug.cgi?id=720103 --- gst-libs/gst/video/gstvideoencoder.c | 61 ++++++++++++++++++++++++---- gst-libs/gst/video/gstvideoencoder.h | 18 +++++++- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/gst-libs/gst/video/gstvideoencoder.c b/gst-libs/gst/video/gstvideoencoder.c index e211fc621f..8fb1a4cb23 100644 --- a/gst-libs/gst/video/gstvideoencoder.c +++ b/gst-libs/gst/video/gstvideoencoder.c @@ -235,6 +235,11 @@ static gboolean gst_video_encoder_negotiate_default (GstVideoEncoder * encoder); static gboolean gst_video_encoder_negotiate_unlocked (GstVideoEncoder * encoder); +static gboolean gst_video_encoder_sink_query_default (GstVideoEncoder * encoder, + GstQuery * query); +static gboolean gst_video_encoder_src_query_default (GstVideoEncoder * encoder, + GstQuery * query); + /* we can't use G_DEFINE_ABSTRACT_TYPE because we need the klass in the _init * method to get to the padtemplates */ GType @@ -296,6 +301,8 @@ gst_video_encoder_class_init (GstVideoEncoderClass * klass) klass->propose_allocation = gst_video_encoder_propose_allocation_default; klass->decide_allocation = gst_video_encoder_decide_allocation_default; klass->negotiate = gst_video_encoder_negotiate_default; + klass->sink_query = gst_video_encoder_sink_query_default; + klass->src_query = gst_video_encoder_src_query_default; } static gboolean @@ -812,14 +819,12 @@ config_failed: } static gboolean -gst_video_encoder_sink_query (GstPad * pad, GstObject * parent, +gst_video_encoder_sink_query_default (GstVideoEncoder * encoder, GstQuery * query) { - GstVideoEncoder *encoder; + GstPad *pad = GST_VIDEO_ENCODER_SINK_PAD (encoder); gboolean res = FALSE; - encoder = GST_VIDEO_ENCODER (parent); - switch (GST_QUERY_TYPE (query)) { case GST_QUERY_CAPS: { @@ -841,12 +846,32 @@ gst_video_encoder_sink_query (GstPad * pad, GstObject * parent, break; } default: - res = gst_pad_query_default (pad, parent, query); + res = gst_pad_query_default (pad, GST_OBJECT (encoder), query); break; } return res; } +static gboolean +gst_video_encoder_sink_query (GstPad * pad, GstObject * parent, + GstQuery * query) +{ + GstVideoEncoder *encoder; + GstVideoEncoderClass *encoder_class; + gboolean ret = FALSE; + + encoder = GST_VIDEO_ENCODER (parent); + encoder_class = GST_VIDEO_ENCODER_GET_CLASS (encoder); + + GST_DEBUG_OBJECT (encoder, "received query %d, %s", GST_QUERY_TYPE (query), + GST_QUERY_TYPE_NAME (query)); + + if (encoder_class->sink_query) + ret = encoder_class->sink_query (encoder, query); + + return ret; +} + static void gst_video_encoder_finalize (GObject * object) { @@ -1141,13 +1166,12 @@ gst_video_encoder_src_event (GstPad * pad, GstObject * parent, GstEvent * event) } static gboolean -gst_video_encoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query) +gst_video_encoder_src_query_default (GstVideoEncoder * enc, GstQuery * query) { + GstPad *pad = GST_VIDEO_ENCODER_SRC_PAD (enc); GstVideoEncoderPrivate *priv; - GstVideoEncoder *enc; gboolean res; - enc = GST_VIDEO_ENCODER (parent); priv = enc->priv; GST_LOG_OBJECT (enc, "handling query: %" GST_PTR_FORMAT, query); @@ -1193,7 +1217,7 @@ gst_video_encoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query) } break; default: - res = gst_pad_query_default (pad, parent, query); + res = gst_pad_query_default (pad, GST_OBJECT (enc), query); } return res; @@ -1202,6 +1226,25 @@ error: return res; } +static gboolean +gst_video_encoder_src_query (GstPad * pad, GstObject * parent, GstQuery * query) +{ + GstVideoEncoder *encoder; + GstVideoEncoderClass *encoder_class; + gboolean ret = FALSE; + + encoder = GST_VIDEO_ENCODER (parent); + encoder_class = GST_VIDEO_ENCODER_GET_CLASS (encoder); + + GST_DEBUG_OBJECT (encoder, "received query %d, %s", GST_QUERY_TYPE (query), + GST_QUERY_TYPE_NAME (query)); + + if (encoder_class->src_query) + ret = encoder_class->src_query (encoder, query); + + return ret; +} + static GstVideoCodecFrame * gst_video_encoder_new_frame (GstVideoEncoder * encoder, GstBuffer * buf, GstClockTime pts, GstClockTime dts, GstClockTime duration) diff --git a/gst-libs/gst/video/gstvideoencoder.h b/gst-libs/gst/video/gstvideoencoder.h index 0ea845b862..aea119d5a4 100644 --- a/gst-libs/gst/video/gstvideoencoder.h +++ b/gst-libs/gst/video/gstvideoencoder.h @@ -214,6 +214,16 @@ struct _GstVideoEncoder * @flush: Optional. * Flush all remaining data from the encoder without * pushing it downstream. Since: 1.2 + * @sink_query: Optional. + * Query handler on the sink pad. This function should + * return TRUE if the query could be performed. Subclasses + * should chain up to the parent implementation to invoke the + * default handler. Since 1.4 + * @src_query: Optional. + * Query handler on the source pad. This function should + * return TRUE if the query could be performed. Subclasses + * should chain up to the parent implementation to invoke the + * default handler. Since 1.4 * * Subclasses can override any of the available virtual methods or not, as * needed. At minimum @handle_frame needs to be overridden, and @set_format @@ -265,8 +275,14 @@ struct _GstVideoEncoderClass GstQuery * query); gboolean (*flush) (GstVideoEncoder *encoder); + gboolean (*sink_query) (GstVideoEncoder *encoder, + GstQuery *query); + + gboolean (*src_query) (GstVideoEncoder *encoder, + GstQuery *query); + /*< private >*/ - gpointer _gst_reserved[GST_PADDING_LARGE-1]; + gpointer _gst_reserved[GST_PADDING_LARGE-3]; }; GType gst_video_encoder_get_type (void);