-base: use caps event

Remove uses of setcaps function and use the caps event.
This commit is contained in:
Wim Taymans 2011-06-07 11:55:36 +02:00
parent beb864bd93
commit 2940249a84
7 changed files with 157 additions and 116 deletions

View file

@ -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;

View file

@ -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;

View file

@ -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);

View file

@ -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:

View file

@ -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);

View file

@ -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 */

View file

@ -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);
gst_pad_push_event (videorate->srcpad, gst_event_new_caps (caps));
return TRUE;
/* ERRORS */
no_framerate:
{
GST_DEBUG_OBJECT (videorate, "no framerate specified");
return FALSE;
}
}
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, "sink 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;
videorate->from_rate_numerator = rate_numerator;
videorate->from_rate_denominator = rate_denominator;
/* 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);
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 = TRUE;
} else {
GstCaps *transform = NULL;
ret = FALSE;
ret = FALSE;
/* see how we can transform the input caps */
if (!gst_video_rate_transformcaps (videorate->sinkpad, caps,
videorate->srcpad, &transform, NULL))
goto no_transform;
/* see how we can transform the input caps */
if (!gst_video_rate_transformcaps (pad, caps, otherpad, &transform, NULL))
goto no_transform;
GST_DEBUG_OBJECT (videorate, "transform %" GST_PTR_FORMAT, transform);
GST_DEBUG_OBJECT (videorate, "transform %" GST_PTR_FORMAT, transform);
/* see what the peer can do */
caps = gst_pad_peer_get_caps (videorate->srcpad, transform);
/* see what the peer can do */
caps = gst_pad_get_caps (opeer, transform);
GST_DEBUG_OBJECT (videorate, "icaps %" GST_PTR_FORMAT, caps);
GST_DEBUG_OBJECT (opeer, "icaps %" GST_PTR_FORMAT, caps);
/* could turn up empty, due to e.g. colorspace etc */
if (gst_caps_get_size (caps) == 0) {
gst_caps_unref (caps);
goto no_transform;
}
/* 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);
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;
}
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;