remove buffer_alloc

This commit is contained in:
Wim Taymans 2011-04-29 13:28:17 +02:00
parent 4dab93ed51
commit 86a4771f8e
13 changed files with 39 additions and 602 deletions

View file

@ -588,8 +588,6 @@ gst_visual_src_query (GstPad * pad, GstQuery * query)
static GstFlowReturn static GstFlowReturn
get_buffer (GstVisual * visual, GstBuffer ** outbuf) get_buffer (GstVisual * visual, GstBuffer ** outbuf)
{ {
GstFlowReturn ret;
/* we don't know an output format yet, pick one */ /* we don't know an output format yet, pick one */
if (GST_PAD_CAPS (visual->srcpad) == NULL) { if (GST_PAD_CAPS (visual->srcpad) == NULL) {
if (!gst_vis_src_negotiate (visual)) 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_DEBUG_OBJECT (visual, "allocating output buffer with caps %"
GST_PTR_FORMAT, GST_PAD_CAPS (visual->srcpad)); GST_PTR_FORMAT, GST_PAD_CAPS (visual->srcpad));
/* now allocate a buffer with the last negotiated format. *outbuf = gst_buffer_new_and_alloc (visual->outsize);
* Downstream could renegotiate a new format, which will trigger gst_buffer_set_caps (*outbuf, GST_PAD_CAPS (visual->srcpad));
* 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;
return GST_FLOW_OK; return GST_FLOW_OK;
} }

View file

@ -331,8 +331,6 @@ static gboolean gst_base_text_overlay_video_event (GstPad * pad,
GstEvent * event); GstEvent * event);
static GstFlowReturn gst_base_text_overlay_video_chain (GstPad * pad, static GstFlowReturn gst_base_text_overlay_video_chain (GstPad * pad,
GstBuffer * buffer); 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, static gboolean gst_base_text_overlay_text_event (GstPad * pad,
GstEvent * event); GstEvent * event);
@ -622,8 +620,6 @@ gst_base_text_overlay_init (GstBaseTextOverlay * overlay,
GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_event)); GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_event));
gst_pad_set_chain_function (overlay->video_sinkpad, gst_pad_set_chain_function (overlay->video_sinkpad,
GST_DEBUG_FUNCPTR (gst_base_text_overlay_video_chain)); 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); gst_element_add_pad (GST_ELEMENT (overlay), overlay->video_sinkpad);
template = template =
@ -2270,28 +2266,6 @@ gst_base_text_overlay_video_event (GstPad * pad, GstEvent * event)
return ret; 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 */ /* Called with lock held */
static void static void
gst_base_text_overlay_pop_text (GstBaseTextOverlay * overlay) gst_base_text_overlay_pop_text (GstBaseTextOverlay * overlay)

View file

@ -505,12 +505,8 @@ gst_text_render_chain (GstPad * pad, GstBuffer * inbuf)
} }
GST_DEBUG ("Allocating buffer WxH = %dx%d", render->width, render->height); GST_DEBUG ("Allocating buffer WxH = %dx%d", render->width, render->height);
ret = outbuf = gst_buffer_new_and_alloc (render->width * render->height * 4);
gst_pad_alloc_buffer_and_set_caps (render->srcpad, GST_BUFFER_OFFSET_NONE, gst_buffer_set_caps (outbuf, caps);
render->width * render->height * 4, caps, &outbuf);
if (ret != GST_FLOW_OK)
goto done;
gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1); gst_buffer_copy_into (outbuf, inbuf, GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE); data = gst_buffer_map (outbuf, &size, NULL, GST_MAP_WRITE);

View file

@ -1043,12 +1043,12 @@ static GstFlowReturn
theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out) theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out)
{ {
gint width, height, stride; gint width, height, stride;
GstFlowReturn result;
int i, plane; int i, plane;
GstVideoFormat format; GstVideoFormat format;
guint8 *dest, *src; guint8 *dest, *src;
gsize size; gsize size;
guint8 *data; guint8 *data;
guint vsize;
switch (dec->info.pixel_fmt) { switch (dec->info.pixel_fmt) {
case TH_PF_444: case TH_PF_444:
@ -1064,15 +1064,9 @@ theora_handle_image (GstTheoraDec * dec, th_ycbcr_buffer buf, GstBuffer ** out)
g_assert_not_reached (); g_assert_not_reached ();
} }
result = vsize = gst_video_format_get_size (format, dec->width, dec->height);
gst_pad_alloc_buffer_and_set_caps (dec->srcpad, GST_BUFFER_OFFSET_NONE, *out = gst_buffer_new_and_alloc (vsize);
gst_video_format_get_size (format, dec->width, dec->height), gst_buffer_set_caps (*out, GST_PAD_CAPS (dec->srcpad));
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;
}
data = gst_buffer_map (*out, &size, NULL, GST_MAP_WRITE); data = gst_buffer_map (*out, &size, NULL, GST_MAP_WRITE);

View file

@ -913,11 +913,8 @@ vorbis_handle_data_packet (GstVorbisDec * vd, ogg_packet * packet,
size); size);
/* alloc buffer for it */ /* alloc buffer for it */
result = out = gst_buffer_new_and_alloc (size);
gst_pad_alloc_buffer_and_set_caps (vd->srcpad, GST_BUFFER_OFFSET_NONE, gst_buffer_set_caps (out, GST_PAD_CAPS (vd->srcpad));
size, GST_PAD_CAPS (vd->srcpad), &out);
if (G_UNLIKELY (result != GST_FLOW_OK))
goto done;
/* get samples ready for reading now, should be sample_count */ /* get samples ready for reading now, should be sample_count */
#ifdef USE_TREMOLO #ifdef USE_TREMOLO

View file

@ -820,15 +820,9 @@ gst_audio_resample_push_drain (GstAudioResample * resample, guint history_len)
if (out_len == 0) if (out_len == 0)
return; return;
res = outbuf = gst_buffer_new_and_alloc (outsize);
gst_pad_alloc_buffer_and_set_caps (GST_BASE_TRANSFORM_SRC_PAD (resample), gst_buffer_set_caps (outbuf,
GST_BUFFER_OFFSET_NONE, outsize, GST_PAD_CAPS (GST_BASE_TRANSFORM_SRC_PAD (resample)));
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;
}
data = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE); data = gst_buffer_map (outbuf, NULL, NULL, GST_MAP_WRITE);

View file

@ -1021,7 +1021,6 @@ static GstFlowReturn
gst_audio_test_src_create (GstBaseSrc * basesrc, guint64 offset, gst_audio_test_src_create (GstBaseSrc * basesrc, guint64 offset,
guint length, GstBuffer ** buffer) guint length, GstBuffer ** buffer)
{ {
GstFlowReturn res;
GstAudioTestSrc *src; GstAudioTestSrc *src;
GstBuffer *buf; GstBuffer *buf;
GstClockTime next_time; 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; bytes = src->generate_samples_per_buffer * src->sample_size * src->channels;
if ((res = gst_pad_alloc_buffer (basesrc->srcpad, src->next_sample, buf = gst_buffer_new_and_alloc (bytes);
bytes, GST_PAD_CAPS (basesrc->srcpad), &buf)) != GST_FLOW_OK) { gst_buffer_set_caps (buf, GST_PAD_CAPS (basesrc->srcpad));
return res;
}
next_byte = src->next_byte + (src->reverse ? (-bytes) : bytes); next_byte = src->next_byte + (src->reverse ? (-bytes) : bytes);
next_time = gst_util_uint64_scale_int (next_sample, GST_SECOND, next_time = gst_util_uint64_scale_int (next_sample, GST_SECOND,

View file

@ -103,8 +103,6 @@ static void gst_selector_pad_reset (GstSelectorPad * pad);
static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event); static gboolean gst_selector_pad_event (GstPad * pad, GstEvent * event);
static GstCaps *gst_selector_pad_getcaps (GstPad * pad); static GstCaps *gst_selector_pad_getcaps (GstPad * pad);
static GstFlowReturn gst_selector_pad_chain (GstPad * pad, GstBuffer * buf); 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 enum
{ {
@ -312,48 +310,6 @@ gst_selector_pad_getcaps (GstPad * pad)
return caps; return caps;
} }
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 static GstFlowReturn
gst_selector_pad_chain (GstPad * pad, GstBuffer * buf) gst_selector_pad_chain (GstPad * pad, GstBuffer * buf)
{ {
@ -719,8 +675,6 @@ gst_stream_selector_request_new_pad (GstElement * element,
GST_DEBUG_FUNCPTR (gst_selector_pad_chain)); GST_DEBUG_FUNCPTR (gst_selector_pad_chain));
gst_pad_set_iterate_internal_links_function (sinkpad, gst_pad_set_iterate_internal_links_function (sinkpad,
GST_DEBUG_FUNCPTR (gst_stream_selector_pad_iterate_linked_pads)); 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_pad_set_active (sinkpad, TRUE);
gst_element_add_pad (GST_ELEMENT (sel), sinkpad); gst_element_add_pad (GST_ELEMENT (sel), sinkpad);

View file

@ -550,26 +550,6 @@ done:
return ret; return ret;
} }
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 static GstFlowReturn
gst_stream_synchronizer_sink_chain (GstPad * pad, GstBuffer * buffer) gst_stream_synchronizer_sink_chain (GstPad * pad, GstBuffer * buffer)
{ {
@ -727,8 +707,6 @@ gst_stream_synchronizer_request_new_pad (GstElement * element,
GST_DEBUG_FUNCPTR (gst_stream_synchronizer_sink_event)); GST_DEBUG_FUNCPTR (gst_stream_synchronizer_sink_event));
gst_pad_set_chain_function (stream->sinkpad, gst_pad_set_chain_function (stream->sinkpad,
GST_DEBUG_FUNCPTR (gst_stream_synchronizer_sink_chain)); 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); tmp = g_strdup_printf ("src_%d", self->current_stream_number);
stream->srcpad = gst_pad_new_from_static_template (&srctemplate, tmp); stream->srcpad = gst_pad_new_from_static_template (&srctemplate, tmp);

View file

@ -2099,7 +2099,6 @@ gst_subtitle_overlay_init (GstSubtitleOverlay * self)
GST_DEBUG_FUNCPTR (gst_subtitle_overlay_subtitle_sink_getcaps)); GST_DEBUG_FUNCPTR (gst_subtitle_overlay_subtitle_sink_getcaps));
gst_pad_set_acceptcaps_function (self->subtitle_sinkpad, gst_pad_set_acceptcaps_function (self->subtitle_sinkpad,
GST_DEBUG_FUNCPTR (gst_subtitle_overlay_subtitle_sink_acceptcaps)); GST_DEBUG_FUNCPTR (gst_subtitle_overlay_subtitle_sink_acceptcaps));
gst_pad_set_bufferalloc_function (self->subtitle_sinkpad, NULL);
proxypad = NULL; proxypad = NULL;
it = gst_pad_iterate_internal_links (self->subtitle_sinkpad); it = gst_pad_iterate_internal_links (self->subtitle_sinkpad);

View file

@ -1483,11 +1483,9 @@ handle_buffer (GstSubParse * self, GstBuffer * buf)
guint subtitle_len = strlen (subtitle); guint subtitle_len = strlen (subtitle);
/* +1 for terminating NUL character */ /* +1 for terminating NUL character */
ret = gst_pad_alloc_buffer_and_set_caps (self->srcpad, buf = gst_buffer_new_and_alloc (subtitle_len + 1);
GST_BUFFER_OFFSET_NONE, subtitle_len + 1, gst_buffer_set_caps (buf, GST_PAD_CAPS (self->srcpad));
GST_PAD_CAPS (self->srcpad), &buf);
if (ret == GST_FLOW_OK) {
/* copy terminating NUL character as well */ /* copy terminating NUL character as well */
gst_buffer_fill (buf, 0, subtitle, subtitle_len + 1); gst_buffer_fill (buf, 0, subtitle, subtitle_len + 1);
gst_buffer_set_size (buf, subtitle_len); gst_buffer_set_size (buf, subtitle_len);
@ -1513,7 +1511,6 @@ handle_buffer (GstSubParse * self, GstBuffer * buf)
GST_TIME_ARGS (self->state.duration)); 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) */ /* move this forward (the tmplayer parser needs this) */
if (self->state.duration != GST_CLOCK_TIME_NONE) if (self->state.duration != GST_CLOCK_TIME_NONE)

View file

@ -1341,188 +1341,6 @@ gst_ximagesink_event (GstBaseSink * sink, GstEvent * event)
return TRUE; 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 */ /* Interfaces stuff */
static gboolean static gboolean
@ -2006,8 +1824,6 @@ gst_ximagesink_class_init (GstXImageSinkClass * klass)
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_getcaps); gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_getcaps);
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_ximagesink_setcaps); 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->get_times = GST_DEBUG_FUNCPTR (gst_ximagesink_get_times);
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_ximagesink_event); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_ximagesink_event);

View file

@ -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 */ /* Interfaces stuff */
static gboolean static gboolean
@ -3209,8 +2963,6 @@ gst_xvimagesink_class_init (GstXvImageSinkClass * klass)
gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_getcaps); gstbasesink_class->get_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_getcaps);
gstbasesink_class->set_caps = GST_DEBUG_FUNCPTR (gst_xvimagesink_setcaps); 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->get_times = GST_DEBUG_FUNCPTR (gst_xvimagesink_get_times);
gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_xvimagesink_event); gstbasesink_class->event = GST_DEBUG_FUNCPTR (gst_xvimagesink_event);