X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fdebugutils%2Fgstcapssetter.c;h=6b3db76d8311d8a124d5dde45637f82e1663add7;hb=2cb6bb425384ac1187bb4317cb3425e8797285fb;hp=12077c0dec2f52626da9450f091230bf8a21a30d;hpb=8217895170f71bde8d594117745aeebb98047538;p=platform%2Fupstream%2Fgst-plugins-good.git diff --git a/gst/debugutils/gstcapssetter.c b/gst/debugutils/gstcapssetter.c index 12077c0..6b3db76 100644 --- a/gst/debugutils/gstcapssetter.c +++ b/gst/debugutils/gstcapssetter.c @@ -20,34 +20,24 @@ /** * SECTION:element-capssetter * - * - * - * Sets or merges caps on a stream's buffers. - * That is, a buffer's caps are updated using (fields of) - * caps. Note that this may - * contain multiple structures (though not likely recommended), but each - * of these must be fixed (or will otherwise be rejected). - * - * - * If join - * is TRUE, then the incoming caps' mime-type is compared to the mime-type(s) - * of provided caps and only matching structure(s) are considered for updating. - * - * - * If replace - * is TRUE, then any caps update is preceded by clearing existing fields, - * making provided fields (as a whole) replace incoming ones. - * Otherwise, no clearing is performed, in which case provided fields are - * added/merged onto incoming caps - * - * + * Sets or merges caps on a stream's buffers. That is, a buffer's caps are + * updated using (fields of) #GstCapsSetter:caps. Note that this may contain + * multiple structures (though not likely recommended), but each of these must + * be fixed (or will otherwise be rejected). + * + * If #GstCapsSetter:join is %TRUE, then the incoming caps' mime-type is + * compared to the mime-type(s) of provided caps and only matching structure(s) + * are considered for updating. + * + * If #GstCapsSetter:replace is %TRUE, then any caps update is preceded by + * clearing existing fields, making provided fields (as a whole) replace + * incoming ones. Otherwise, no clearing is performed, in which case provided + * fields are added/merged onto incoming caps + * * Although this element might mainly serve as debug helper, * it can also practically be used to correct a faulty pixel-aspect-ratio, * or to modify a yuv fourcc value to effectively swap chroma components or such * alike. - * - * - * */ @@ -83,12 +73,6 @@ enum #define DEFAULT_JOIN TRUE #define DEFAULT_REPLACE FALSE -static GstElementDetails caps_setter_details = -GST_ELEMENT_DETAILS ("CapsSetter", - "Generic", - "Set/merge caps on stream", - "Mark Nauwelaerts "); - static GstStaticPadTemplate gst_caps_setter_src_template = GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SRC_NAME, GST_PAD_SRC, @@ -103,10 +87,10 @@ GST_STATIC_PAD_TEMPLATE (GST_BASE_TRANSFORM_SINK_NAME, static gboolean gst_caps_setter_transform_size (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps, guint size, - GstCaps * othercaps, guint * othersize); + GstPadDirection direction, GstCaps * caps, gsize size, + GstCaps * othercaps, gsize * othersize); static GstCaps *gst_caps_setter_transform_caps (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps); + GstPadDirection direction, GstCaps * caps, GstCaps * cfilter); static GstFlowReturn gst_caps_setter_transform_ip (GstBaseTransform * btrans, GstBuffer * in); @@ -117,49 +101,45 @@ static void gst_caps_setter_set_property (GObject * object, guint prop_id, static void gst_caps_setter_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); -GST_BOILERPLATE (GstCapsSetter, gst_caps_setter, GstBaseTransform, - GST_TYPE_BASE_TRANSFORM); - -static void -gst_caps_setter_base_init (gpointer g_class) -{ - GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); - - gst_element_class_set_details (element_class, &caps_setter_details); - - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_caps_setter_sink_template)); - gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_caps_setter_src_template)); -} +#define gst_caps_setter_parent_class parent_class +G_DEFINE_TYPE (GstCapsSetter, gst_caps_setter, GST_TYPE_BASE_TRANSFORM); static void gst_caps_setter_class_init (GstCapsSetterClass * g_class) { - GObjectClass *gobject_class; - GstBaseTransformClass *trans_class; - - gobject_class = G_OBJECT_CLASS (g_class); - trans_class = GST_BASE_TRANSFORM_CLASS (g_class); + GObjectClass *gobject_class = (GObjectClass *) g_class; + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + GstBaseTransformClass *trans_class = (GstBaseTransformClass *) g_class; GST_DEBUG_CATEGORY_INIT (caps_setter_debug, "capssetter", 0, "capssetter"); gobject_class->set_property = gst_caps_setter_set_property; gobject_class->get_property = gst_caps_setter_get_property; - gobject_class->finalize = GST_DEBUG_FUNCPTR (gst_caps_setter_finalize); + gobject_class->finalize = gst_caps_setter_finalize; g_object_class_install_property (gobject_class, PROP_CAPS, g_param_spec_boxed ("caps", "Merge caps", "Merge these caps (thereby overwriting) in the stream", - GST_TYPE_CAPS, G_PARAM_READWRITE)); + GST_TYPE_CAPS, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_JOIN, g_param_spec_boolean ("join", "Join", "Match incoming caps' mime-type to mime-type of provided caps", - DEFAULT_JOIN, G_PARAM_READWRITE)); + DEFAULT_JOIN, G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); g_object_class_install_property (gobject_class, PROP_REPLACE, g_param_spec_boolean ("replace", "Replace", - "Drop fields of incoming caps", DEFAULT_REPLACE, G_PARAM_READWRITE)); + "Drop fields of incoming caps", DEFAULT_REPLACE, + G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + + gst_element_class_set_static_metadata (element_class, "CapsSetter", + "Generic", + "Set/merge caps on stream", + "Mark Nauwelaerts "); + + gst_element_class_add_static_pad_template (element_class, + &gst_caps_setter_sink_template); + gst_element_class_add_static_pad_template (element_class, + &gst_caps_setter_src_template); trans_class->transform_size = GST_DEBUG_FUNCPTR (gst_caps_setter_transform_size); @@ -170,7 +150,7 @@ gst_caps_setter_class_init (GstCapsSetterClass * g_class) } static void -gst_caps_setter_init (GstCapsSetter * filter, GstCapsSetterClass * g_class) +gst_caps_setter_init (GstCapsSetter * filter) { filter->caps = gst_caps_new_any (); filter->join = DEFAULT_JOIN; @@ -189,8 +169,8 @@ gst_caps_setter_finalize (GObject * object) static gboolean gst_caps_setter_transform_size (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps, guint size, - GstCaps * othercaps, guint * othersize) + GstPadDirection direction, GstCaps * caps, gsize size, + GstCaps * othercaps, gsize * othersize) { *othersize = size; @@ -199,47 +179,54 @@ gst_caps_setter_transform_size (GstBaseTransform * trans, static GstCaps * gst_caps_setter_transform_caps (GstBaseTransform * trans, - GstPadDirection direction, GstCaps * caps) + GstPadDirection direction, GstCaps * caps, GstCaps * cfilter) { - GstCapsSetter *filter; - GstCaps *ret, *filter_caps; + GstCapsSetter *filter = GST_CAPS_SETTER (trans); + GstCaps *ret = NULL, *filter_caps = NULL; GstStructure *structure, *merge; const gchar *name; - gint i, j; - - filter = GST_CAPS_SETTER (trans); - - GST_DEBUG_OBJECT (trans, "receiving caps: %" GST_PTR_FORMAT, caps); + gint i, j, k; + + GST_DEBUG_OBJECT (trans, + "receiving caps: %" GST_PTR_FORMAT ", with filter: %" GST_PTR_FORMAT, + caps, cfilter); + + /* pass filter caps upstream, or any if no filter */ + if (direction != GST_PAD_SINK) { + if (!cfilter || gst_caps_is_empty (cfilter)) { + return gst_caps_ref (GST_CAPS_ANY); + } else { + return gst_caps_ref (cfilter); + } + } ret = gst_caps_copy (caps); - /* this function is always called with a simple caps */ - if (!GST_CAPS_IS_SIMPLE (ret) || direction != GST_PAD_SINK) - return ret; - - structure = gst_caps_get_structure (ret, 0); - name = gst_structure_get_name (structure); - GST_OBJECT_LOCK (filter); filter_caps = gst_caps_ref (filter->caps); GST_OBJECT_UNLOCK (filter); - for (i = 0; i < gst_caps_get_size (filter_caps); ++i) { - merge = gst_caps_get_structure (filter_caps, i); - if (gst_structure_has_name (merge, name) || !filter->join) { + for (k = 0; k < gst_caps_get_size (ret); k++) { + structure = gst_caps_get_structure (ret, k); + name = gst_structure_get_name (structure); - if (!filter->join) - gst_structure_set_name (structure, gst_structure_get_name (merge)); + for (i = 0; i < gst_caps_get_size (filter_caps); ++i) { + merge = gst_caps_get_structure (filter_caps, i); + if (gst_structure_has_name (merge, name) || !filter->join) { - if (filter->replace) - gst_structure_remove_all_fields (structure); + if (!filter->join) + gst_structure_set_name (structure, gst_structure_get_name (merge)); - for (j = 0; j < gst_structure_n_fields (merge); ++j) { - const gchar *fname; + if (filter->replace) + gst_structure_remove_all_fields (structure); - fname = gst_structure_nth_field_name (merge, j); - gst_structure_set_value (structure, fname, - gst_structure_get_value (merge, fname)); + for (j = 0; j < gst_structure_n_fields (merge); ++j) { + const gchar *fname; + + fname = gst_structure_nth_field_name (merge, j); + gst_structure_set_value (structure, fname, + gst_structure_get_value (merge, fname)); + } } } } @@ -268,10 +255,7 @@ static void gst_caps_setter_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) { - GstCapsSetter *filter; - - g_return_if_fail (GST_IS_CAPS_SETTER (object)); - filter = GST_CAPS_SETTER (object); + GstCapsSetter *filter = GST_CAPS_SETTER (object); switch (prop_id) { case PROP_CAPS:{ @@ -309,7 +293,7 @@ gst_caps_setter_set_property (GObject * object, guint prop_id, } /* try to activate these new caps next time around */ - gst_base_transform_reconfigure (GST_BASE_TRANSFORM (filter)); + gst_base_transform_reconfigure_src (GST_BASE_TRANSFORM (filter)); break; } case PROP_JOIN: @@ -328,10 +312,7 @@ static void gst_caps_setter_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) { - GstCapsSetter *filter; - - g_return_if_fail (GST_IS_CAPS_SETTER (object)); - filter = GST_CAPS_SETTER (object); + GstCapsSetter *filter = GST_CAPS_SETTER (object); switch (prop_id) { case PROP_CAPS: