return types;
}
+/* this function either returns the input buffer without incrementing the
+ * refcount or it allocates a new (writable) buffer */
static GstFlowReturn
default_prepare_output_buffer (GstBaseTransform * trans,
GstBuffer * inbuf, GstBuffer ** outbuf)
/* passthrough, we will not modify the incomming buffer so we can just
* reuse it */
GST_DEBUG_OBJECT (trans, "passthrough: reusing input buffer");
- *outbuf = gst_buffer_ref (inbuf);
+ *outbuf = inbuf;
} else {
/* we can't reuse the input buffer */
if (priv->pool) {
if (ret != GST_FLOW_OK || *outbuf == NULL)
goto no_buffer;
- /* FIXME 0.11:
- * decrease refcount again if vmethod returned refcounted inbuf. This
- * is because we need to make sure that the buffer is writable for the
- * in_place transform. The docs of the vmethod say that you should return
- * a reffed inbuf, which is exactly what we don't want :), oh well.. */
if (inbuf == *outbuf) {
GST_DEBUG_OBJECT (trans, "reusing input buffer");
- gst_buffer_unref (inbuf);
} else if (trans->passthrough) {
/* we are asked to perform a passthrough transform but the input and
* output buffers are different. We have to discard the output buffer and
}
skip:
- /* only unref input buffer if we allocated a new outbuf buffer */
+ /* only unref input buffer if we allocated a new outbuf buffer. If we reused
+ * the input buffer, no refcount is changed to keep the input buffer writable
+ * when needed. */
if (*outbuf != inbuf)
gst_buffer_unref (inbuf);
* Subclasses can override this to do their own
* allocation of output buffers. Elements that only do
* analysis can return a subbuffer or even just
- * increment the reference to the input buffer (if in
+ * return a reference to the input buffer (if in
* passthrough mode). The default implementation will
* use the negotiated allocator or bufferpool and
- * transform_size to allocate an output buffer.
+ * transform_size to allocate an output buffer or it
+ * will return the input buffer in passthrough mode.
* @copy_metadata: Optional.
* Copy the metadata from the input buffer to the output buffer.
* The default implementation will copy the flags, timestamps and
{
GstFlowReturn ret = GST_FLOW_OK;
- /* always ref input as output buffer */
+ /* always return the input as output buffer */
*buf = input;
- gst_buffer_ref (input);
if (!gst_pad_has_current_caps (trans->sinkpad)) {
/* Buffer has no caps. See if the output pad only supports fixed caps */
/* only bother if we may have to alter metadata */
if (identity->datarate > 0 || identity->single_segment) {
if (gst_buffer_is_writable (in_buf))
- *out_buf = gst_buffer_ref (in_buf);
+ /* reuse */
+ *out_buf = in_buf;
else {
- /* make even less writable */
- gst_buffer_ref (in_buf);
- /* extra ref is dropped going through the official process */
- *out_buf = gst_buffer_make_writable (in_buf);
+ /* copy */
+ *out_buf = gst_buffer_copy (in_buf);
}
} else
- *out_buf = gst_buffer_ref (in_buf);
+ *out_buf = in_buf;
return GST_FLOW_OK;
}