From 2940249a841daafccb731977f6105d97b0765fd4 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Tue, 7 Jun 2011 11:55:36 +0200 Subject: [PATCH] -base: use caps event Remove uses of setcaps function and use the caps event. --- ext/ogg/gstoggaviparse.c | 14 +++- ext/pango/gstbasetextoverlay.c | 24 ++++-- ext/pango/gsttextrender.c | 15 ++-- ext/theora/gsttheoradec.c | 1 + ext/theora/gsttheoraenc.c | 17 ++-- ext/vorbis/gstvorbisenc.c | 15 ++-- gst/videorate/gstvideorate.c | 177 ++++++++++++++++++++++------------------- 7 files changed, 152 insertions(+), 111 deletions(-) diff --git a/ext/ogg/gstoggaviparse.c b/ext/ogg/gstoggaviparse.c index d79a2dd..8abc1f9 100644 --- a/ext/ogg/gstoggaviparse.c +++ b/ext/ogg/gstoggaviparse.c @@ -164,7 +164,6 @@ gst_ogg_avi_parse_init (GstOggAviParse * ogg) ogg->sinkpad = gst_pad_new_from_static_template (&ogg_avi_parse_sink_template_factory, "sink"); - gst_pad_set_setcaps_function (ogg->sinkpad, gst_ogg_avi_parse_setcaps); gst_pad_set_event_function (ogg->sinkpad, gst_ogg_avi_parse_event); gst_pad_set_chain_function (ogg->sinkpad, gst_ogg_avi_parse_chain); gst_element_add_pad (GST_ELEMENT (ogg), ogg->sinkpad); @@ -252,7 +251,8 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps) /* set caps */ outcaps = gst_caps_new_simple ("audio/x-vorbis", NULL); - gst_pad_set_caps (ogg->srcpad, outcaps); + gst_pad_push_event (ogg->srcpad, gst_event_new_caps (outcaps)); + gst_caps_unref (outcaps); /* copy header data */ offs = 34; @@ -266,7 +266,6 @@ gst_ogg_avi_parse_setcaps (GstPad * pad, GstCaps * caps) offs += sizes[i]; } gst_buffer_unmap (buffer, data, size); - gst_caps_unref (outcaps); return TRUE; @@ -298,6 +297,15 @@ gst_ogg_avi_parse_event (GstPad * pad, GstEvent * event) ogg = GST_OGG_AVI_PARSE (GST_OBJECT_PARENT (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + ret = gst_ogg_avi_parse_setcaps (pad, caps); + gst_event_unref (event); + break; + } case GST_EVENT_FLUSH_START: ret = gst_pad_push_event (ogg->srcpad, event); break; diff --git a/ext/pango/gstbasetextoverlay.c b/ext/pango/gstbasetextoverlay.c index d437ac1..4b5554e 100644 --- a/ext/pango/gstbasetextoverlay.c +++ b/ext/pango/gstbasetextoverlay.c @@ -629,8 +629,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, gst_object_unref (template); gst_pad_set_getcaps_function (overlay->video_sinkpad, GST_DEBUG_FUNCPTR (gst_base_text_overlay_getcaps)); - gst_pad_set_setcaps_function (overlay->video_sinkpad, - GST_DEBUG_FUNCPTR (gst_base_text_overlay_setcaps)); gst_pad_set_event_function (overlay->video_sinkpad, GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_event)); gst_pad_set_chain_function (overlay->video_sinkpad, @@ -645,8 +643,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, overlay->text_sinkpad = gst_pad_new_from_template (template, "text_sink"); gst_object_unref (template); - gst_pad_set_setcaps_function (overlay->text_sinkpad, - GST_DEBUG_FUNCPTR (gst_base_text_overlay_setcaps_txt)); gst_pad_set_event_function (overlay->text_sinkpad, GST_DEBUG_FUNCPTR (gst_base_text_overlay_text_event)); gst_pad_set_chain_function (overlay->text_sinkpad, @@ -802,7 +798,7 @@ gst_base_text_overlay_setcaps (GstPad * pad, GstCaps * caps) if (fps && gst_video_format_parse_caps (caps, &overlay->format, &overlay->width, &overlay->height)) { - ret = gst_pad_set_caps (overlay->srcpad, caps); + ret = gst_pad_push_event (overlay->srcpad, gst_event_new_caps (caps)); } overlay->fps_n = gst_value_get_fraction_numerator (fps); @@ -2156,6 +2152,15 @@ gst_base_text_overlay_text_event (GstPad * pad, GstEvent * event) GST_LOG_OBJECT (pad, "received event %s", GST_EVENT_TYPE_NAME (event)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + ret = gst_base_text_overlay_setcaps_txt (pad, caps); + gst_event_unref (event); + break; + } case GST_EVENT_SEGMENT: { const GstSegment *segment; @@ -2237,6 +2242,15 @@ gst_base_text_overlay_video_event (GstPad * pad, GstEvent * event) GST_DEBUG_OBJECT (pad, "received event %s", GST_EVENT_TYPE_NAME (event)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + ret = gst_base_text_overlay_setcaps (pad, caps); + gst_event_unref (event); + break; + } case GST_EVENT_SEGMENT: { const GstSegment *segment; diff --git a/ext/pango/gsttextrender.c b/ext/pango/gsttextrender.c index cc174f7..ac2d4b3 100644 --- a/ext/pango/gsttextrender.c +++ b/ext/pango/gsttextrender.c @@ -345,28 +345,27 @@ gst_text_render_check_argb (GstTextRender * render) } static gboolean -gst_text_render_setcaps (GstPad * pad, GstCaps * caps) +gst_text_render_src_setcaps (GstTextRender * render, GstCaps * caps) { - GstTextRender *render = GST_TEXT_RENDER (gst_pad_get_parent (pad)); GstStructure *structure; - gboolean ret = FALSE; + gboolean ret; gint width = 0, height = 0; structure = gst_caps_get_structure (caps, 0); gst_structure_get_int (structure, "width", &width); gst_structure_get_int (structure, "height", &height); - GST_DEBUG ("Got caps %" GST_PTR_FORMAT, caps); + GST_DEBUG_OBJECT (render, "Got caps %" GST_PTR_FORMAT, caps); if (width >= render->image_width && height >= render->image_height) { render->width = width; render->height = height; - ret = TRUE; } gst_text_render_check_argb (render); - gst_object_unref (render); + ret = gst_pad_push_event (render->srcpad, gst_event_new_caps (caps)); + return ret; } @@ -502,7 +501,7 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf) gst_caps_truncate (caps); gst_pad_fixate_caps (render->srcpad, caps); - if (!gst_pad_set_caps (render->srcpad, caps)) { + if (!gst_text_render_src_setcaps (render, caps)) { GST_ELEMENT_ERROR (render, CORE, NEGOTIATION, (NULL), (NULL)); ret = GST_FLOW_ERROR; goto done; @@ -605,8 +604,6 @@ gst_text_render_init (GstTextRender * render) gst_object_unref (template); gst_pad_set_fixatecaps_function (render->srcpad, GST_DEBUG_FUNCPTR (gst_text_render_fixate_caps)); - gst_pad_set_setcaps_function (render->srcpad, - GST_DEBUG_FUNCPTR (gst_text_render_setcaps)); gst_element_add_pad (GST_ELEMENT (render), render->srcpad); diff --git a/ext/theora/gsttheoradec.c b/ext/theora/gsttheoradec.c index b57ccfd..291c391 100644 --- a/ext/theora/gsttheoradec.c +++ b/ext/theora/gsttheoradec.c @@ -658,6 +658,7 @@ theora_dec_sink_event (GstPad * pad, GstEvent * event) gst_event_parse_caps (event, &caps); ret = theora_dec_setcaps (dec, caps); + gst_event_unref (event); break; } case GST_EVENT_TAG: diff --git a/ext/theora/gsttheoraenc.c b/ext/theora/gsttheoraenc.c index 6a29fc9..25f333a 100644 --- a/ext/theora/gsttheoraenc.c +++ b/ext/theora/gsttheoraenc.c @@ -255,7 +255,7 @@ static GstFlowReturn theora_enc_chain (GstPad * pad, GstBuffer * buffer); static GstStateChangeReturn theora_enc_change_state (GstElement * element, GstStateChange transition); static GstCaps *theora_enc_sink_getcaps (GstPad * pad, GstCaps * filter); -static gboolean theora_enc_sink_setcaps (GstPad * pad, GstCaps * caps); +static gboolean theora_enc_sink_setcaps (GstTheoraEnc * enc, GstCaps * caps); static void theora_enc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec); static void theora_enc_set_property (GObject * object, guint prop_id, @@ -420,7 +420,6 @@ gst_theora_enc_init (GstTheoraEnc * enc) gst_pad_set_chain_function (enc->sinkpad, theora_enc_chain); gst_pad_set_event_function (enc->sinkpad, theora_enc_sink_event); gst_pad_set_getcaps_function (enc->sinkpad, theora_enc_sink_getcaps); - gst_pad_set_setcaps_function (enc->sinkpad, theora_enc_sink_setcaps); gst_element_add_pad (GST_ELEMENT (enc), enc->sinkpad); enc->srcpad = @@ -651,10 +650,9 @@ theora_enc_sink_getcaps (GstPad * pad, GstCaps * filter) } static gboolean -theora_enc_sink_setcaps (GstPad * pad, GstCaps * caps) +theora_enc_sink_setcaps (GstTheoraEnc * enc, GstCaps * caps) { GstStructure *structure = gst_caps_get_structure (caps, 0); - GstTheoraEnc *enc = GST_THEORA_ENC (gst_pad_get_parent (pad)); guint32 fourcc; const GValue *par; gint fps_n, fps_d; @@ -714,8 +712,6 @@ theora_enc_sink_setcaps (GstPad * pad, GstCaps * caps) theora_enc_reset (enc); enc->initialised = TRUE; - gst_object_unref (enc); - return TRUE; } @@ -872,6 +868,15 @@ theora_enc_sink_event (GstPad * pad, GstEvent * event) enc = GST_THEORA_ENC (GST_PAD_PARENT (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + res = theora_enc_sink_setcaps (enc, caps); + gst_event_unref (event); + break; + } case GST_EVENT_SEGMENT: { gst_event_copy_segment (event, &enc->segment); diff --git a/ext/vorbis/gstvorbisenc.c b/ext/vorbis/gstvorbisenc.c index ffa796b..60fd174 100644 --- a/ext/vorbis/gstvorbisenc.c +++ b/ext/vorbis/gstvorbisenc.c @@ -284,12 +284,10 @@ gst_vorbis_enc_sink_getcaps (GstPad * pad, GstCaps * filter) } static gboolean -gst_vorbis_enc_sink_setcaps (GstPad * pad, GstCaps * caps) +gst_vorbis_enc_sink_setcaps (GstVorbisEnc * vorbisenc, GstCaps * caps) { - GstVorbisEnc *vorbisenc; GstStructure *structure; - vorbisenc = GST_VORBISENC (GST_PAD_PARENT (pad)); vorbisenc->setup = FALSE; structure = gst_caps_get_structure (caps, 0); @@ -574,8 +572,6 @@ gst_vorbis_enc_init (GstVorbisEnc * vorbisenc) GST_DEBUG_FUNCPTR (gst_vorbis_enc_sink_event)); gst_pad_set_chain_function (vorbisenc->sinkpad, GST_DEBUG_FUNCPTR (gst_vorbis_enc_chain)); - gst_pad_set_setcaps_function (vorbisenc->sinkpad, - GST_DEBUG_FUNCPTR (gst_vorbis_enc_sink_setcaps)); gst_pad_set_getcaps_function (vorbisenc->sinkpad, GST_DEBUG_FUNCPTR (gst_vorbis_enc_sink_getcaps)); gst_pad_set_query_function (vorbisenc->sinkpad, @@ -946,6 +942,15 @@ gst_vorbis_enc_sink_event (GstPad * pad, GstEvent * event) vorbisenc = GST_VORBISENC (GST_PAD_PARENT (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + res = gst_vorbis_enc_sink_setcaps (vorbisenc, caps); + gst_event_unref (event); + break; + } case GST_EVENT_EOS: /* Tell the library we're at end of stream so that it can handle * the last frame and mark end of stream in the output properly */ diff --git a/gst/videorate/gstvideorate.c b/gst/videorate/gstvideorate.c index 45382c3..cbd8e0c 100644 --- a/gst/videorate/gstvideorate.c +++ b/gst/videorate/gstvideorate.c @@ -324,110 +324,115 @@ gst_video_rate_getcaps (GstPad * pad, GstCaps * filter) } static gboolean -gst_video_rate_setcaps (GstPad * pad, GstCaps * caps) +gst_video_rate_set_src_caps (GstVideoRate * videorate, GstCaps * caps) { - GstVideoRate *videorate; GstStructure *structure; - gboolean ret = TRUE; - GstPad *otherpad, *opeer; gint rate_numerator, rate_denominator; - videorate = GST_VIDEO_RATE (gst_pad_get_parent (pad)); - - GST_DEBUG_OBJECT (pad, "setcaps called %" GST_PTR_FORMAT, caps); + GST_DEBUG_OBJECT (videorate, "src caps %" GST_PTR_FORMAT, caps); structure = gst_caps_get_structure (caps, 0); if (!gst_structure_get_fraction (structure, "framerate", &rate_numerator, &rate_denominator)) goto no_framerate; - if (pad == videorate->srcpad) { - /* out_frame_count is scaled by the frame rate caps when calculating next_ts. - * when the frame rate caps change, we must update base_ts and reset - * out_frame_count */ - if (videorate->to_rate_numerator) { - videorate->base_ts += - gst_util_uint64_scale (videorate->out_frame_count, - videorate->to_rate_denominator * GST_SECOND, - videorate->to_rate_numerator); - } - videorate->out_frame_count = 0; - videorate->to_rate_numerator = rate_numerator; - videorate->to_rate_denominator = rate_denominator; - videorate->wanted_diff = gst_util_uint64_scale_int (GST_SECOND, - rate_denominator, rate_numerator); - otherpad = videorate->sinkpad; - } else { - videorate->from_rate_numerator = rate_numerator; - videorate->from_rate_denominator = rate_denominator; - otherpad = videorate->srcpad; + /* out_frame_count is scaled by the frame rate caps when calculating next_ts. + * when the frame rate caps change, we must update base_ts and reset + * out_frame_count */ + if (videorate->to_rate_numerator) { + videorate->base_ts += + gst_util_uint64_scale (videorate->out_frame_count, + videorate->to_rate_denominator * GST_SECOND, + videorate->to_rate_numerator); } + videorate->out_frame_count = 0; + videorate->to_rate_numerator = rate_numerator; + videorate->to_rate_denominator = rate_denominator; + videorate->wanted_diff = gst_util_uint64_scale_int (GST_SECOND, + rate_denominator, rate_numerator); - /* now try to find something for the peer */ - opeer = gst_pad_get_peer (otherpad); - if (opeer) { - if (gst_pad_accept_caps (opeer, caps)) { - /* the peer accepts the caps as they are */ - gst_pad_set_caps (otherpad, caps); + gst_pad_push_event (videorate->srcpad, gst_event_new_caps (caps)); - ret = TRUE; - } else { - GstCaps *transform = NULL; + return TRUE; - ret = FALSE; + /* ERRORS */ +no_framerate: + { + GST_DEBUG_OBJECT (videorate, "no framerate specified"); + return FALSE; + } +} - /* see how we can transform the input caps */ - if (!gst_video_rate_transformcaps (pad, caps, otherpad, &transform, NULL)) - goto no_transform; +static gboolean +gst_video_rate_set_sink_caps (GstVideoRate * videorate, GstCaps * caps) +{ + GstStructure *structure; + gboolean ret = TRUE; + gint rate_numerator, rate_denominator; - GST_DEBUG_OBJECT (videorate, "transform %" GST_PTR_FORMAT, transform); + GST_DEBUG_OBJECT (videorate, "sink caps %" GST_PTR_FORMAT, caps); - /* see what the peer can do */ - caps = gst_pad_get_caps (opeer, transform); + structure = gst_caps_get_structure (caps, 0); + if (!gst_structure_get_fraction (structure, "framerate", + &rate_numerator, &rate_denominator)) + goto no_framerate; - GST_DEBUG_OBJECT (opeer, "icaps %" GST_PTR_FORMAT, caps); + videorate->from_rate_numerator = rate_numerator; + videorate->from_rate_denominator = rate_denominator; - /* could turn up empty, due to e.g. colorspace etc */ - if (gst_caps_get_size (caps) == 0) { - gst_caps_unref (caps); - goto no_transform; - } + /* now try to find something for the peer */ + if (gst_pad_peer_accept_caps (videorate->srcpad, caps)) { + /* the peer accepts the caps as they are */ + ret = gst_video_rate_set_src_caps (videorate, caps); + } else { + GstCaps *transform = NULL; + + ret = FALSE; - /* take first possibility */ - caps = gst_caps_make_writable (caps); - gst_caps_truncate (caps); - structure = gst_caps_get_structure (caps, 0); + /* see how we can transform the input caps */ + if (!gst_video_rate_transformcaps (videorate->sinkpad, caps, + videorate->srcpad, &transform, NULL)) + goto no_transform; - /* and fixate */ - gst_structure_fixate_field_nearest_fraction (structure, "framerate", - rate_numerator, rate_denominator); + GST_DEBUG_OBJECT (videorate, "transform %" GST_PTR_FORMAT, transform); - gst_structure_get_fraction (structure, "framerate", - &rate_numerator, &rate_denominator); + /* see what the peer can do */ + caps = gst_pad_peer_get_caps (videorate->srcpad, transform); - if (otherpad == videorate->srcpad) { - videorate->to_rate_numerator = rate_numerator; - videorate->to_rate_denominator = rate_denominator; - } else { - videorate->from_rate_numerator = rate_numerator; - videorate->from_rate_denominator = rate_denominator; - } + GST_DEBUG_OBJECT (videorate, "icaps %" GST_PTR_FORMAT, caps); - if (gst_structure_has_field (structure, "interlaced")) - gst_structure_fixate_field_boolean (structure, "interlaced", FALSE); - if (gst_structure_has_field (structure, "color-matrix")) - gst_structure_fixate_field_string (structure, "color-matrix", "sdtv"); - if (gst_structure_has_field (structure, "chroma-site")) - gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2"); - if (gst_structure_has_field (structure, "pixel-aspect-ratio")) - gst_structure_fixate_field_nearest_fraction (structure, - "pixel-aspect-ratio", 1, 1); - - gst_pad_set_caps (otherpad, caps); + /* could turn up empty, due to e.g. colorspace etc */ + if (gst_caps_get_size (caps) == 0) { gst_caps_unref (caps); - ret = TRUE; + goto no_transform; } - gst_object_unref (opeer); + + /* take first possibility */ + caps = gst_caps_make_writable (caps); + gst_caps_truncate (caps); + structure = gst_caps_get_structure (caps, 0); + + /* and fixate */ + gst_structure_fixate_field_nearest_fraction (structure, "framerate", + rate_numerator, rate_denominator); + gst_structure_get_fraction (structure, "framerate", + &rate_numerator, &rate_denominator); + + videorate->to_rate_numerator = rate_numerator; + videorate->to_rate_denominator = rate_denominator; + + if (gst_structure_has_field (structure, "interlaced")) + gst_structure_fixate_field_boolean (structure, "interlaced", FALSE); + if (gst_structure_has_field (structure, "color-matrix")) + gst_structure_fixate_field_string (structure, "color-matrix", "sdtv"); + if (gst_structure_has_field (structure, "chroma-site")) + gst_structure_fixate_field_string (structure, "chroma-site", "mpeg2"); + if (gst_structure_has_field (structure, "pixel-aspect-ratio")) + gst_structure_fixate_field_nearest_fraction (structure, + "pixel-aspect-ratio", 1, 1); + + ret = gst_video_rate_set_src_caps (videorate, caps); + gst_caps_unref (caps); } done: /* After a setcaps, our caps may have changed. In that case, we can't use @@ -435,7 +440,6 @@ done: GST_DEBUG_OBJECT (videorate, "swapping old buffers"); gst_video_rate_swap_prev (videorate, NULL, GST_CLOCK_TIME_NONE); - gst_object_unref (videorate); return ret; no_framerate: @@ -482,8 +486,6 @@ gst_video_rate_init (GstVideoRate * videorate) GST_DEBUG_FUNCPTR (gst_video_rate_chain)); gst_pad_set_getcaps_function (videorate->sinkpad, GST_DEBUG_FUNCPTR (gst_video_rate_getcaps)); - gst_pad_set_setcaps_function (videorate->sinkpad, - GST_DEBUG_FUNCPTR (gst_video_rate_setcaps)); gst_element_add_pad (GST_ELEMENT (videorate), videorate->sinkpad); videorate->srcpad = @@ -492,8 +494,6 @@ gst_video_rate_init (GstVideoRate * videorate) GST_DEBUG_FUNCPTR (gst_video_rate_query)); gst_pad_set_getcaps_function (videorate->srcpad, GST_DEBUG_FUNCPTR (gst_video_rate_getcaps)); - gst_pad_set_setcaps_function (videorate->srcpad, - GST_DEBUG_FUNCPTR (gst_video_rate_setcaps)); gst_element_add_pad (GST_ELEMENT (videorate), videorate->srcpad); gst_video_rate_reset (videorate); @@ -614,6 +614,17 @@ gst_video_rate_event (GstPad * pad, GstEvent * event) videorate = GST_VIDEO_RATE (gst_pad_get_parent (pad)); switch (GST_EVENT_TYPE (event)) { + case GST_EVENT_CAPS: + { + GstCaps *caps; + + gst_event_parse_caps (event, &caps); + ret = gst_video_rate_set_sink_caps (videorate, caps); + gst_event_unref (event); + + /* don't forward */ + goto done; + } case GST_EVENT_SEGMENT: { const GstSegment *segment; -- 2.7.4