From 86a4771f8e20769335e1d1a362036268fe6fa0cc Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 29 Apr 2011 13:28:17 +0200 Subject: [PATCH] remove buffer_alloc --- ext/libvisual/visual.c | 15 +-- ext/pango/gstbasetextoverlay.c | 26 ---- ext/pango/gsttextrender.c | 8 +- ext/theora/gsttheoradec.c | 14 +- ext/vorbis/gstvorbisdec.c | 7 +- gst/audioresample/gstaudioresample.c | 12 +- gst/audiotestsrc/gstaudiotestsrc.c | 7 +- gst/playback/gststreamselector.c | 46 ------- gst/playback/gststreamsynchronizer.c | 22 ---- gst/playback/gstsubtitleoverlay.c | 1 - gst/subparse/gstsubparse.c | 53 ++++---- sys/ximage/ximagesink.c | 184 -------------------------- sys/xvimage/xvimagesink.c | 248 ----------------------------------- 13 files changed, 40 insertions(+), 603 deletions(-) diff --git a/ext/libvisual/visual.c b/ext/libvisual/visual.c index 6c71c05..13be044 100644 --- a/ext/libvisual/visual.c +++ b/ext/libvisual/visual.c @@ -588,8 +588,6 @@ gst_visual_src_query (GstPad * pad, GstQuery * query) static GstFlowReturn get_buffer (GstVisual * visual, GstBuffer ** outbuf) { - GstFlowReturn ret; - /* we don't know an output format yet, pick one */ if (GST_PAD_CAPS (visual->srcpad) == NULL) { if (!gst_vis_src_negotiate (visual)) @@ -599,17 +597,8 @@ get_buffer (GstVisual * visual, GstBuffer ** outbuf) GST_DEBUG_OBJECT (visual, "allocating output buffer with caps %" GST_PTR_FORMAT, GST_PAD_CAPS (visual->srcpad)); - /* now allocate a buffer with the last negotiated format. - * Downstream could renegotiate a new format, which will trigger - * our setcaps function on the source pad. */ - ret = - gst_pad_alloc_buffer_and_set_caps (visual->srcpad, - GST_BUFFER_OFFSET_NONE, visual->outsize, - GST_PAD_CAPS (visual->srcpad), outbuf); - - /* no buffer allocated, we don't care why. */ - if (ret != GST_FLOW_OK) - return ret; + *outbuf = gst_buffer_new_and_alloc (visual->outsize); + gst_buffer_set_caps (*outbuf, GST_PAD_CAPS (visual->srcpad)); return GST_FLOW_OK; } diff --git a/ext/pango/gstbasetextoverlay.c b/ext/pango/gstbasetextoverlay.c index 6767a51..37b6c03 100644 --- a/ext/pango/gstbasetextoverlay.c +++ b/ext/pango/gstbasetextoverlay.c @@ -331,8 +331,6 @@ static gboolean gst_base_text_overlay_video_event (GstPad * pad, GstEvent * event); static GstFlowReturn gst_base_text_overlay_video_chain (GstPad * pad, GstBuffer * buffer); -static GstFlowReturn gst_base_text_overlay_video_bufferalloc (GstPad * pad, - guint64 offset, guint size, GstCaps * caps, GstBuffer ** buffer); static gboolean gst_base_text_overlay_text_event (GstPad * pad, GstEvent * event); @@ -622,8 +620,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay, GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_event)); gst_pad_set_chain_function (overlay->video_sinkpad, GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_chain)); - gst_pad_set_bufferalloc_function (overlay->video_sinkpad, - GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_bufferalloc)); gst_element_add_pad (GST_ELEMENT (overlay), overlay->video_sinkpad); template = @@ -2270,28 +2266,6 @@ gst_base_text_overlay_video_event (GstPad * pad, GstEvent * event) return ret; } -static GstFlowReturn -gst_base_text_overlay_video_bufferalloc (GstPad * pad, guint64 offset, - guint size, GstCaps * caps, GstBuffer ** buffer) -{ - GstBaseTextOverlay *overlay = - GST_BASE_TEXT_OVERLAY (gst_pad_get_parent (pad)); - GstFlowReturn ret = GST_FLOW_WRONG_STATE; - GstPad *allocpad; - - GST_OBJECT_LOCK (overlay); - allocpad = overlay->srcpad ? gst_object_ref (overlay->srcpad) : NULL; - GST_OBJECT_UNLOCK (overlay); - - if (allocpad) { - ret = gst_pad_alloc_buffer (allocpad, offset, size, caps, buffer); - gst_object_unref (allocpad); - } - - gst_object_unref (overlay); - return ret; -} - /* Called with lock held */ static void gst_base_text_overlay_pop_text (GstBaseTextOverlay * overlay) diff --git a/ext/pango/gsttextrender.c b/ext/pango/gsttextrender.c index 764765b..8e17bee 100644 --- a/ext/pango/gsttextrender.c +++ b/ext/pango/gsttextrender.c @@ -505,12 +505,8 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf) } GST_DEBUG ("Allocating buffer WxH = %dx%d", render->width, render->height); - ret = - gst_pad_alloc_buffer_and_set_caps (render->srcpad, GST_BUFFER_OFFSET_NONE, - render->width * render->height * 4, caps, &outbuf); - - if (ret != GST_FLOW_OK) - goto done; + outbuf = gst_buffer_new_and_alloc (render->width * render->height * 4); + gst_buffer_set_caps (outbuf, caps); gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1); data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE); diff --git a/ext/theora/gsttheoradec.c b/ext/theora/gsttheoradec.c index e401364..6357a5f 100644 --- a/ext/theora/gsttheoradec.c +++ b/ext/theora/gsttheoradec.c @@ -1043,12 +1043,12 @@ static GstFlowReturn theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out) { gint width, height, stride; - GstFlowReturn result; int i, plane; GstVideoFormat format; guint8 *dest, *src; gsize size; guint8 *data; + guint vsize; switch (dec->info.pixel_fmt) { case TH_PF_444: @@ -1064,15 +1064,9 @@ theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out) g_assert_not_reached (); } - result = - gst_pad_alloc_buffer_and_set_caps (dec->srcpad, GST_BUFFER_OFFSET_NONE, - gst_video_format_get_size (format, dec->width, dec->height), - GST_PAD_CAPS (dec->srcpad), out); - if (G_UNLIKELY (result != GST_FLOW_OK)) { - GST_DEBUG_OBJECT (dec, "could not get buffer, reason: %s", - gst_flow_get_name (result)); - return result; - } + vsize = gst_video_format_get_size (format, dec->width, dec->height); + *out = gst_buffer_new_and_alloc (vsize); + gst_buffer_set_caps (*out, GST_PAD_CAPS (dec->srcpad)); data = gst_buffer_map (*out, &size, NULL, GST_MAP_WRITE); diff --git a/ext/vorbis/gstvorbisdec.c b/ext/vorbis/gstvorbisdec.c index 78fc79a..d52c505 100644 --- a/ext/vorbis/gstvorbisdec.c +++ b/ext/vorbis/gstvorbisdec.c @@ -913,11 +913,8 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet, size); /* alloc buffer for it */ - result = - gst_pad_alloc_buffer_and_set_caps (vd->srcpad, GST_BUFFER_OFFSET_NONE, - size, GST_PAD_CAPS (vd->srcpad), &out); - if (G_UNLIKELY (result != GST_FLOW_OK)) - goto done; + out = gst_buffer_new_and_alloc (size); + gst_buffer_set_caps (out, GST_PAD_CAPS (vd->srcpad)); /* get samples ready for reading now, should be sample_count */ #ifdef USE_TREMOLO diff --git a/gst/audioresample/gstaudioresample.c b/gst/audioresample/gstaudioresample.c index 50a2567..44a22dd 100644 --- a/gst/audioresample/gstaudioresample.c +++ b/gst/audioresample/gstaudioresample.c @@ -820,15 +820,9 @@ gst_audio_resample_push_drain (GstAudioResample * resample, guint history_len) if (out_len == 0) return; - res = - gst_pad_alloc_buffer_and_set_caps (GST_BASE_TRANSFORM_SRC_PAD (resample), - GST_BUFFER_OFFSET_NONE, outsize, - GST_PAD_CAPS (GST_BASE_TRANSFORM_SRC_PAD (resample)), &outbuf); - if (G_UNLIKELY (res != GST_FLOW_OK)) { - GST_WARNING_OBJECT (resample, "failed allocating buffer of %d bytes", - outsize); - return; - } + outbuf = gst_buffer_new_and_alloc (outsize); + gst_buffer_set_caps (outbuf, + GST_PAD_CAPS (GST_BASE_TRANSFORM_SRC_PAD (resample))); data = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); diff --git a/gst/audiotestsrc/gstaudiotestsrc.c b/gst/audiotestsrc/gstaudiotestsrc.c index 043b164..144a230 100644 --- a/gst/audiotestsrc/gstaudiotestsrc.c +++ b/gst/audiotestsrc/gstaudiotestsrc.c @@ -1021,7 +1021,6 @@ static GstFlowReturn gst_audio_test_src_create (GstBaseSrc * basesrc, guint64 offset, guint length, GstBuffer ** buffer) { - GstFlowReturn res; GstAudioTestSrc *src; GstBuffer *buf; GstClockTime next_time; @@ -1092,10 +1091,8 @@ gst_audio_test_src_create (GstBaseSrc * basesrc, guint64 offset, bytes = src->generate_samples_per_buffer * src->sample_size * src->channels; - if ((res = gst_pad_alloc_buffer (basesrc->srcpad, src->next_sample, - bytes, GST_PAD_CAPS (basesrc->srcpad), &buf)) != GST_FLOW_OK) { - return res; - } + buf = gst_buffer_new_and_alloc (bytes); + gst_buffer_set_caps (buf, GST_PAD_CAPS (basesrc->srcpad)); next_byte = src->next_byte + (src->reverse ? (-bytes) : bytes); next_time = gst_util_uint64_scale_int (next_sample, GST_SECOND, diff --git a/gst/playback/gststreamselector.c b/gst/playback/gststreamselector.c index 294eac4..713d802 100644 --- a/gst/playback/gststreamselector.c +++ b/gst/playback/gststreamselector.c @@ -103,8 +103,6 @@ static void gst_selector_pad_reset (GstSelectorPad * pad); static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event); static GstCaps *gst_selector_pad_getcaps (GstPad * pad); static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf); -static GstFlowReturn gst_selector_pad_bufferalloc (GstPad * pad, - guint64 offset, guint size, GstCaps * caps, GstBuffer ** buf); enum { @@ -313,48 +311,6 @@ gst_selector_pad_getcaps (GstPad * pad) } static GstFlowReturn -gst_selector_pad_bufferalloc (GstPad * pad, guint64 offset, - guint size, GstCaps * caps, GstBuffer ** buf) -{ - GstStreamSelector *sel; - GstFlowReturn result; - GstPad *active_sinkpad; - - sel = GST_STREAM_SELECTOR (gst_pad_get_parent (pad)); - - active_sinkpad = gst_stream_selector_activate_sinkpad (sel, pad); - - /* Fallback allocation for buffers from pads except the selected one */ - if (pad != active_sinkpad) { - GST_DEBUG_OBJECT (sel, - "Pad %s:%s is not selected. Performing fallback allocation", - GST_DEBUG_PAD_NAME (pad)); - - *buf = NULL; - result = GST_FLOW_OK; - } else { - result = gst_pad_alloc_buffer (sel->srcpad, offset, size, caps, buf); - - /* FIXME: HACK. If buffer alloc returns not-linked, perform a fallback - * allocation. This should NOT be necessary, because playbin should - * properly block the source pad from running until it's finished hooking - * everything up, but playbin needs refactoring first. */ - if (result == GST_FLOW_NOT_LINKED) { - GST_DEBUG_OBJECT (sel, - "No peer pad yet - performing fallback allocation for pad %s:%s", - GST_DEBUG_PAD_NAME (pad)); - - *buf = NULL; - result = GST_FLOW_OK; - } - } - - gst_object_unref (sel); - - return result; -} - -static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf) { GstStreamSelector *sel; @@ -719,8 +675,6 @@ gst_stream_selector_request_new_pad (GstElement * element, GST_DEBUG_FUNCPTR (gst_selector_pad_chain)); gst_pad_set_iterate_internal_links_function (sinkpad, GST_DEBUG_FUNCPTR (gst_stream_selector_pad_iterate_linked_pads)); - gst_pad_set_bufferalloc_function (sinkpad, - GST_DEBUG_FUNCPTR (gst_selector_pad_bufferalloc)); gst_pad_set_active (sinkpad, TRUE); gst_element_add_pad (GST_ELEMENT (sel), sinkpad); diff --git a/gst/playback/gststreamsynchronizer.c b/gst/playback/gststreamsynchronizer.c index f6d1ba2..9b79192 100644 --- a/gst/playback/gststreamsynchronizer.c +++ b/gst/playback/gststreamsynchronizer.c @@ -551,26 +551,6 @@ done: } static GstFlowReturn -gst_stream_synchronizer_sink_bufferalloc (GstPad * pad, guint64 offset, - guint size, GstCaps * caps, GstBuffer ** buf) -{ - GstPad *opad; - GstFlowReturn ret = GST_FLOW_ERROR; - - GST_LOG_OBJECT (pad, "Allocating buffer: size=%u", size); - - opad = gst_stream_get_other_pad_from_pad (pad); - if (opad) { - ret = gst_pad_alloc_buffer (opad, offset, size, caps, buf); - gst_object_unref (opad); - } - - GST_LOG_OBJECT (pad, "Allocation: %s", gst_flow_get_name (ret)); - - return ret; -} - -static GstFlowReturn gst_stream_synchronizer_sink_chain (GstPad * pad, GstBuffer * buffer) { GstStreamSynchronizer *self = @@ -727,8 +707,6 @@ gst_stream_synchronizer_request_new_pad (GstElement * element, GST_DEBUG_FUNCPTR (gst_stream_synchronizer_sink_event)); gst_pad_set_chain_function (stream->sinkpad, GST_DEBUG_FUNCPTR (gst_stream_synchronizer_sink_chain)); - gst_pad_set_bufferalloc_function (stream->sinkpad, - GST_DEBUG_FUNCPTR (gst_stream_synchronizer_sink_bufferalloc)); tmp = g_strdup_printf ("src_%d", self->current_stream_number); stream->srcpad = gst_pad_new_from_static_template (&srctemplate, tmp); diff --git a/gst/playback/gstsubtitleoverlay.c b/gst/playback/gstsubtitleoverlay.c index 00ecf84..cb8c353 100644 --- a/gst/playback/gstsubtitleoverlay.c +++ b/gst/playback/gstsubtitleoverlay.c @@ -2099,7 +2099,6 @@ gst_subtitle_overlay_init (GstSubtitleOverlay * self) GST_DEBUG_FUNCPTR (gst_subtitle_overlay_subtitle_sink_getcaps)); gst_pad_set_acceptcaps_function (self->subtitle_sinkpad, GST_DEBUG_FUNCPTR (gst_subtitle_overlay_subtitle_sink_acceptcaps)); - gst_pad_set_bufferalloc_function (self->subtitle_sinkpad, NULL); proxypad = NULL; it = gst_pad_iterate_internal_links (self->subtitle_sinkpad); diff --git a/gst/subparse/gstsubparse.c b/gst/subparse/gstsubparse.c index af322d4..b7b6815 100644 --- a/gst/subparse/gstsubparse.c +++ b/gst/subparse/gstsubparse.c @@ -1483,37 +1483,34 @@ handle_buffer (GstSubParse * self, GstBuffer * buf) guint subtitle_len = strlen (subtitle); /* +1 for terminating NUL character */ - ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad, - GST_BUFFER_OFFSET_NONE, subtitle_len + 1, - GST_PAD_CAPS (self->srcpad), &buf); - - if (ret == GST_FLOW_OK) { - /* copy terminating NUL character as well */ - gst_buffer_fill (buf, 0, subtitle, subtitle_len + 1); - gst_buffer_set_size (buf, subtitle_len); - - GST_BUFFER_TIMESTAMP (buf) = self->state.start_time; - GST_BUFFER_DURATION (buf) = self->state.duration; - - /* in some cases (e.g. tmplayer) we can only determine the duration - * of a text chunk from the timestamp of the next text chunk; in those - * cases, we probably want to limit the duration to something - * reasonable, so we don't end up showing some text for e.g. 40 seconds - * just because nothing else is being said during that time */ - if (self->state.max_duration > 0 && GST_BUFFER_DURATION_IS_VALID (buf)) { - if (GST_BUFFER_DURATION (buf) > self->state.max_duration) - GST_BUFFER_DURATION (buf) = self->state.max_duration; - } + buf = gst_buffer_new_and_alloc (subtitle_len + 1); + gst_buffer_set_caps (buf, GST_PAD_CAPS (self->srcpad)); + + /* copy terminating NUL character as well */ + gst_buffer_fill (buf, 0, subtitle, subtitle_len + 1); + gst_buffer_set_size (buf, subtitle_len); + + GST_BUFFER_TIMESTAMP (buf) = self->state.start_time; + GST_BUFFER_DURATION (buf) = self->state.duration; + + /* in some cases (e.g. tmplayer) we can only determine the duration + * of a text chunk from the timestamp of the next text chunk; in those + * cases, we probably want to limit the duration to something + * reasonable, so we don't end up showing some text for e.g. 40 seconds + * just because nothing else is being said during that time */ + if (self->state.max_duration > 0 && GST_BUFFER_DURATION_IS_VALID (buf)) { + if (GST_BUFFER_DURATION (buf) > self->state.max_duration) + GST_BUFFER_DURATION (buf) = self->state.max_duration; + } - gst_segment_set_last_stop (&self->segment, GST_FORMAT_TIME, - self->state.start_time); + gst_segment_set_last_stop (&self->segment, GST_FORMAT_TIME, + self->state.start_time); - GST_DEBUG_OBJECT (self, "Sending text '%s', %" GST_TIME_FORMAT " + %" - GST_TIME_FORMAT, subtitle, GST_TIME_ARGS (self->state.start_time), - GST_TIME_ARGS (self->state.duration)); + GST_DEBUG_OBJECT (self, "Sending text '%s', %" GST_TIME_FORMAT " + %" + GST_TIME_FORMAT, subtitle, GST_TIME_ARGS (self->state.start_time), + GST_TIME_ARGS (self->state.duration)); - ret = gst_pad_push (self->srcpad, buf); - } + ret = gst_pad_push (self->srcpad, buf); /* move this forward (the tmplayer parser needs this) */ if (self->state.duration != GST_CLOCK_TIME_NONE) diff --git a/sys/ximage/ximagesink.c b/sys/ximage/ximagesink.c index 0374b81..8c9cdff 100644 --- a/sys/ximage/ximagesink.c +++ b/sys/ximage/ximagesink.c @@ -1341,188 +1341,6 @@ gst_ximagesink_event (GstBaseSink * sink, GstEvent * event) return TRUE; } -/* Buffer management - * - * The buffer_alloc function must either return a buffer with given size and - * caps or create a buffer with different caps attached to the buffer. This - * last option is called reverse negotiation, ie, where the sink suggests a - * different format from the upstream peer. - * - * We try to do reverse negotiation when our geometry changes and we like a - * resized buffer. - */ -static GstFlowReturn -gst_ximagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size, - GstCaps * caps, GstBuffer ** buf) -{ - GstXImageSink *ximagesink; - GstBuffer *ximage = NULL; - GstStructure *structure = NULL; - GstFlowReturn ret = GST_FLOW_OK; - GstCaps *alloc_caps; - gboolean alloc_unref = FALSE; - gint width, height; - GstVideoRectangle dst, src, result; - gboolean caps_accepted = FALSE; - - ximagesink = GST_XIMAGESINK (bsink); - - if (G_UNLIKELY (!caps)) { - GST_WARNING_OBJECT (ximagesink, "have no caps, doing fallback allocation"); - *buf = NULL; - ret = GST_FLOW_OK; - goto beach; - } - - /* This shouldn't really happen because state changes will fail - * if the xcontext can't be allocated */ - if (!ximagesink->xcontext) - return GST_FLOW_ERROR; - - GST_LOG_OBJECT (ximagesink, - "a buffer of %d bytes was requested with caps %" GST_PTR_FORMAT - " and offset %" G_GUINT64_FORMAT, size, caps, offset); - - /* assume we're going to alloc what was requested, keep track of - * wheter we need to unref or not. When we suggest a new format - * upstream we will create a new caps that we need to unref. */ - alloc_caps = caps; - alloc_unref = FALSE; - - /* get struct to see what is requested */ - structure = gst_caps_get_structure (caps, 0); - if (!gst_structure_get_int (structure, "width", &width) || - !gst_structure_get_int (structure, "height", &height)) { - GST_WARNING_OBJECT (ximagesink, "invalid caps for buffer allocation %" - GST_PTR_FORMAT, caps); - ret = GST_FLOW_NOT_NEGOTIATED; - goto beach; - } - - src.w = width; - src.h = height; - - /* We take the flow_lock because the window might go away */ - g_mutex_lock (ximagesink->flow_lock); - if (!ximagesink->xwindow) { - g_mutex_unlock (ximagesink->flow_lock); - goto alloc; - } - - /* What is our geometry */ - dst.w = ximagesink->xwindow->width; - dst.h = ximagesink->xwindow->height; - - g_mutex_unlock (ximagesink->flow_lock); - - if (ximagesink->keep_aspect) { - GST_LOG_OBJECT (ximagesink, "enforcing aspect ratio in reverse caps " - "negotiation"); - gst_video_sink_center_rect (src, dst, &result, TRUE); - } else { - GST_LOG_OBJECT (ximagesink, "trying to resize to window geometry " - "ignoring aspect ratio"); - result.x = result.y = 0; - result.w = dst.w; - result.h = dst.h; - } - - /* We would like another geometry */ - if (width != result.w || height != result.h) { - int nom, den; - GstCaps *desired_caps; - GstStructure *desired_struct; - - /* make a copy of the incomming caps to create the new - * suggestion. We can't use make_writable because we might - * then destroy the original caps which we still need when the - * peer does not accept the suggestion. */ - desired_caps = gst_caps_copy (caps); - desired_struct = gst_caps_get_structure (desired_caps, 0); - - GST_DEBUG ("we would love to receive a %dx%d video", result.w, result.h); - gst_structure_set (desired_struct, "width", G_TYPE_INT, result.w, NULL); - gst_structure_set (desired_struct, "height", G_TYPE_INT, result.h, NULL); - - /* PAR property overrides the X calculated one */ - if (ximagesink->par) { - nom = gst_value_get_fraction_numerator (ximagesink->par); - den = gst_value_get_fraction_denominator (ximagesink->par); - gst_structure_set (desired_struct, "pixel-aspect-ratio", - GST_TYPE_FRACTION, nom, den, NULL); - } else if (ximagesink->xcontext->par) { - nom = gst_value_get_fraction_numerator (ximagesink->xcontext->par); - den = gst_value_get_fraction_denominator (ximagesink->xcontext->par); - gst_structure_set (desired_struct, "pixel-aspect-ratio", - GST_TYPE_FRACTION, nom, den, NULL); - } - - - /* see if peer accepts our new suggestion, if there is no peer, this - * function returns true. */ - if (!ximagesink->xcontext->last_caps || - !gst_caps_is_equal (desired_caps, ximagesink->xcontext->last_caps)) { - caps_accepted = - gst_pad_peer_accept_caps (GST_VIDEO_SINK_PAD (ximagesink), - desired_caps); - - /* Suggestion failed, prevent future attempts for the same caps - * to fail as well. */ - if (!caps_accepted) - gst_caps_replace (&ximagesink->xcontext->last_caps, desired_caps); - } - - if (caps_accepted) { - /* we will not alloc a buffer of the new suggested caps. Make sure - * we also unref this new caps after we set it on the buffer. */ - alloc_caps = desired_caps; - alloc_unref = TRUE; - width = result.w; - height = result.h; - GST_DEBUG ("peer pad accepts our desired caps %" GST_PTR_FORMAT, - desired_caps); - } else { - GST_DEBUG ("peer pad does not accept our desired caps %" GST_PTR_FORMAT, - desired_caps); - /* we alloc a buffer with the original incomming caps already in the - * width and height variables */ - gst_caps_unref (desired_caps); - } - } - -alloc: - - if (gst_caps_is_equal (GST_PAD_CAPS (bsink->sinkpad), alloc_caps)) { - /* we negotiated this format before, use the pool */ - if (ximagesink->pool) { - GST_LOG_OBJECT (ximagesink, "retrieving buffer from pool"); - ret = gst_buffer_pool_acquire_buffer (ximagesink->pool, &ximage, NULL); - } - } - - if (ximage == NULL) { - /* Something new make a new image a new one */ - GST_LOG_OBJECT (ximagesink, "allocating new image"); - ximage = gst_ximage_buffer_new (ximagesink, width, height); - } - - /* Now we should have a ximage, set appropriate caps on it */ - if (ximage) { - /* Make sure the buffer is cleared of any previously used flags */ - GST_MINI_OBJECT_CAST (ximage)->flags = 0; - gst_buffer_set_caps (ximage, alloc_caps); - } - - /* could be our new reffed suggestion or the original unreffed caps */ - if (alloc_unref) - gst_caps_unref (alloc_caps); - - *buf = ximage; - -beach: - return ret; -} - /* Interfaces stuff */ static gboolean @@ -2006,8 +1824,6 @@ gst_ximagesink_class_init (GstXImageSinkClass * klass) gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_getcaps); gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_setcaps); - gstbasesink_class->buffer_alloc = - GST_DEBUG_FUNCPTR (gst_ximagesink_buffer_alloc); gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_ximagesink_get_times); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_ximagesink_event); diff --git a/sys/xvimage/xvimagesink.c b/sys/xvimage/xvimagesink.c index 7017d96..7731aff 100644 --- a/sys/xvimage/xvimagesink.c +++ b/sys/xvimage/xvimagesink.c @@ -2019,252 +2019,6 @@ config_failed: } } -/* Buffer management */ -static GstCaps * -gst_xvimage_sink_different_size_suggestion (GstXvImageSink * xvimagesink, - GstCaps * caps) -{ - GstCaps *intersection; - GstCaps *new_caps; - GstStructure *s; - gint width, height; - gint par_n = 1, par_d = 1; - gint dar_n, dar_d; - gint w, h; - - new_caps = gst_caps_copy (caps); - - s = gst_caps_get_structure (new_caps, 0); - - gst_structure_get_int (s, "width", &width); - gst_structure_get_int (s, "height", &height); - gst_structure_get_fraction (s, "pixel-aspect-ratio", &par_n, &par_d); - - gst_structure_remove_field (s, "width"); - gst_structure_remove_field (s, "height"); - gst_structure_remove_field (s, "pixel-aspect-ratio"); - - intersection = gst_caps_intersect (xvimagesink->xcontext->caps, new_caps); - gst_caps_unref (new_caps); - - if (gst_caps_is_empty (intersection)) - return intersection; - - s = gst_caps_get_structure (intersection, 0); - - gst_util_fraction_multiply (width, height, par_n, par_d, &dar_n, &dar_d); - - /* xvimagesink supports all PARs */ - - gst_structure_fixate_field_nearest_int (s, "width", width); - gst_structure_fixate_field_nearest_int (s, "height", height); - gst_structure_get_int (s, "width", &w); - gst_structure_get_int (s, "height", &h); - - gst_util_fraction_multiply (h, w, dar_n, dar_d, &par_n, &par_d); - gst_structure_set (s, "pixel-aspect-ratio", GST_TYPE_FRACTION, par_n, par_d, - NULL); - - return intersection; -} - -static GstFlowReturn -gst_xvimagesink_buffer_alloc (GstBaseSink * bsink, guint64 offset, guint size, - GstCaps * caps, GstBuffer ** buf) -{ - GstXvImageSink *xvimagesink; - GstBuffer *xvimage = NULL; - GstStructure *structure = NULL; - GstFlowReturn ret = GST_FLOW_OK; - GstCaps *intersection = NULL; - gint width, height, image_format; - - xvimagesink = GST_XVIMAGESINK (bsink); - - if (G_UNLIKELY (!caps)) - goto no_caps; - - if (G_LIKELY (xvimagesink->xcontext->last_caps && - gst_caps_is_equal (caps, xvimagesink->xcontext->last_caps))) { - GST_LOG_OBJECT (xvimagesink, - "buffer alloc for same last_caps, reusing caps"); - intersection = gst_caps_ref (caps); - image_format = xvimagesink->xcontext->last_format; - width = xvimagesink->xcontext->last_width; - height = xvimagesink->xcontext->last_height; - - goto reuse_last_caps; - } - - GST_DEBUG_OBJECT (xvimagesink, "buffer alloc requested size %d with caps %" - GST_PTR_FORMAT ", intersecting with our caps %" GST_PTR_FORMAT, size, - caps, xvimagesink->xcontext->caps); - - /* Check the caps against our xcontext */ - intersection = gst_caps_intersect (xvimagesink->xcontext->caps, caps); - - GST_DEBUG_OBJECT (xvimagesink, "intersection in buffer alloc returned %" - GST_PTR_FORMAT, intersection); - - if (gst_caps_is_empty (intersection)) { - GstCaps *new_caps; - - gst_caps_unref (intersection); - - /* So we don't support this kind of buffer, let's define one we'd like */ - new_caps = gst_caps_copy (caps); - - structure = gst_caps_get_structure (new_caps, 0); - if (!gst_structure_has_field (structure, "width") || - !gst_structure_has_field (structure, "height")) { - gst_caps_unref (new_caps); - goto invalid; - } - - /* Try different dimensions */ - intersection = - gst_xvimage_sink_different_size_suggestion (xvimagesink, new_caps); - - if (gst_caps_is_empty (intersection)) { - /* Try with different YUV formats first */ - gst_structure_set_name (structure, "video/x-raw-yuv"); - - /* Remove format specific fields */ - gst_structure_remove_field (structure, "format"); - gst_structure_remove_field (structure, "endianness"); - gst_structure_remove_field (structure, "depth"); - gst_structure_remove_field (structure, "bpp"); - gst_structure_remove_field (structure, "red_mask"); - gst_structure_remove_field (structure, "green_mask"); - gst_structure_remove_field (structure, "blue_mask"); - gst_structure_remove_field (structure, "alpha_mask"); - - /* Reuse intersection with Xcontext */ - intersection = gst_caps_intersect (xvimagesink->xcontext->caps, new_caps); - } - - if (gst_caps_is_empty (intersection)) { - /* Try with different dimensions and YUV formats */ - intersection = - gst_xvimage_sink_different_size_suggestion (xvimagesink, new_caps); - } - - if (gst_caps_is_empty (intersection)) { - /* Now try with RGB */ - gst_structure_set_name (structure, "video/x-raw-rgb"); - /* And interset again */ - gst_caps_unref (intersection); - intersection = gst_caps_intersect (xvimagesink->xcontext->caps, new_caps); - } - - if (gst_caps_is_empty (intersection)) { - /* Try with different dimensions and RGB formats */ - intersection = - gst_xvimage_sink_different_size_suggestion (xvimagesink, new_caps); - } - - /* Clean this copy */ - gst_caps_unref (new_caps); - - if (gst_caps_is_empty (intersection)) - goto incompatible; - } - - /* Ensure the returned caps are fixed */ - gst_caps_truncate (intersection); - - GST_DEBUG_OBJECT (xvimagesink, "allocating a buffer with caps %" - GST_PTR_FORMAT, intersection); - if (gst_caps_is_equal (intersection, caps)) { - /* Things work better if we return a buffer with the same caps ptr - * as was asked for when we can */ - gst_caps_replace (&intersection, caps); - } - - /* Get image format from caps */ - image_format = gst_xvimagesink_get_format_from_caps (xvimagesink, - intersection); - - /* Get geometry from caps */ - structure = gst_caps_get_structure (intersection, 0); - if (!gst_structure_get_int (structure, "width", &width) || - !gst_structure_get_int (structure, "height", &height) || - image_format == -1) - goto invalid_caps; - - /* Store our caps and format as the last_caps to avoid expensive - * caps intersection next time */ - gst_caps_replace (&xvimagesink->xcontext->last_caps, intersection); - xvimagesink->xcontext->last_format = image_format; - xvimagesink->xcontext->last_width = width; - xvimagesink->xcontext->last_height = height; - -reuse_last_caps: - - if (gst_caps_is_equal (GST_PAD_CAPS (bsink->sinkpad), caps)) { - /* we negotiated this format before, use the pool */ - if (xvimagesink->pool) { - GstBuffer *tmp; - - GST_LOG_OBJECT (xvimagesink, "retrieving buffer from pool"); - ret = gst_buffer_pool_acquire_buffer (xvimagesink->pool, &tmp, NULL); - xvimage = tmp; - } - } - - if (xvimage == NULL) { - /* Something new make a new image a new one */ - GST_LOG_OBJECT (xvimagesink, "allocating new image"); - xvimage = gst_xvimage_buffer_new (xvimagesink, width, height, image_format); - } - - if (xvimage) { - /* Make sure the buffer is cleared of any previously used flags */ - GST_MINI_OBJECT_CAST (xvimage)->flags = 0; - gst_buffer_set_caps (xvimage, intersection); - } - - *buf = xvimage; - -beach: - if (intersection) { - gst_caps_unref (intersection); - } - - return ret; - - /* ERRORS */ -invalid: - { - GST_DEBUG_OBJECT (xvimagesink, "the pool is flushing"); - ret = GST_FLOW_WRONG_STATE; - goto beach; - } -incompatible: - { - GST_WARNING_OBJECT (xvimagesink, "we were requested a buffer with " - "caps %" GST_PTR_FORMAT ", but our xcontext caps %" GST_PTR_FORMAT - " are completely incompatible with those caps", caps, - xvimagesink->xcontext->caps); - ret = GST_FLOW_NOT_NEGOTIATED; - goto beach; - } -invalid_caps: - { - GST_WARNING_OBJECT (xvimagesink, "invalid caps for buffer allocation %" - GST_PTR_FORMAT, intersection); - ret = GST_FLOW_NOT_NEGOTIATED; - goto beach; - } -no_caps: - { - GST_WARNING_OBJECT (xvimagesink, "have no caps, doing fallback allocation"); - *buf = NULL; - ret = GST_FLOW_OK; - goto beach; - } -} - /* Interfaces stuff */ static gboolean @@ -3209,8 +2963,6 @@ gst_xvimagesink_class_init (GstXvImageSinkClass * klass) gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_getcaps); gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_setcaps); - gstbasesink_class->buffer_alloc = - GST_DEBUG_FUNCPTR (gst_xvimagesink_buffer_alloc); gstbasesink_class->get_times = GST_DEBUG_FUNCPTR (gst_xvimagesink_get_times); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_xvimagesink_event); -- 2.7.4