gst/tcp/gstmultifdsink.c: Small cleanups.
authorWim Taymans <wim.taymans@gmail.com>
Fri, 25 Aug 2006 16:39:38 +0000 (16:39 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Fri, 25 Aug 2006 16:39:38 +0000 (16:39 +0000)
Original commit message from CVS:
* gst/tcp/gstmultifdsink.c: (gst_multi_fd_sink_render):
Small cleanups.
If a buffer is received with no caps, make the buffer metadata
writable and set the caps, making sure that we don't screw up the
refcounts.

ChangeLog
gst/tcp/gstmultifdsink.c

index 1234196..98caca4 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2006-08-25  Wim Taymans  <wim@fluendo.com>
+
+       * gst/tcp/gstmultifdsink.c: (gst_multi_fd_sink_render):
+       Small cleanups.
+       If a buffer is received with no caps, make the buffer metadata
+       writable and set the caps, making sure that we don't screw up the
+       refcounts.
+
 2006-08-25  Michael Smith  <msmith@fluendo.com>
 
        * gst/gdp/gstgdppay.c: (gst_gdp_pay_reset),
index 8d1c3ab..61582ee 100644 (file)
@@ -2207,30 +2207,34 @@ gst_multi_fd_sink_render (GstBaseSink * bsink, GstBuffer * buf)
 
   sink = GST_MULTI_FD_SINK (bsink);
 
+  g_return_val_if_fail (GST_OBJECT_FLAG_IS_SET (sink, GST_MULTI_FD_SINK_OPEN),
+      GST_FLOW_WRONG_STATE);
+
   /* since we check every buffer for streamheader caps, we need to make
    * sure every buffer has caps set */
   bufcaps = gst_buffer_get_caps (buf);
   padcaps = GST_PAD_CAPS (GST_BASE_SINK_PAD (bsink));
 
   /* make sure we have caps on the pad */
-  if (!padcaps) {
-    if (!bufcaps) {
-      GST_ELEMENT_ERROR (sink, CORE, NEGOTIATION, (NULL),
-          ("Received first buffer without caps set"));
-      return GST_FLOW_NOT_NEGOTIATED;
-    }
-  }
+  if (!padcaps && !bufcaps)
+    goto no_caps;
 
   /* stamp the buffer with previous caps if no caps set */
   if (!bufcaps) {
-    /* We keep this buffer around, and need to write it, but we can't just use
-     * gst_buffer_make_writable(), because we're not allowed to unref this buf,
-     * basesink will do that for us */
-    if (!gst_buffer_is_writable (buf))
-      buf = gst_buffer_copy (buf);
-    else
+    if (!gst_buffer_is_metadata_writable (buf)) {
+      /* metadata is not writable, copy will be made and original buffer
+       * will be unreffed so we need to ref so that we don't loose the
+       * buffer in the render method. */
       gst_buffer_ref (buf);
-
+      /* the new buffer is ours only, we keep it out of the scope of this
+       * function */
+      buf = gst_buffer_make_metadata_writable (buf);
+    } else {
+      /* else the metadata is writable, we ref because we keep the buffer
+       * out of the scope of this method */
+      gst_buffer_ref (buf);
+    }
+    /* buffer metadata is writable now, set the caps */
     GST_DEBUG_OBJECT (sink, "result is %p", buf);
     gst_buffer_set_caps (buf, padcaps);
   } else {
@@ -2240,10 +2244,6 @@ gst_multi_fd_sink_render (GstBaseSink * bsink, GstBuffer * buf)
     gst_buffer_ref (buf);
   }
 
-
-  g_return_val_if_fail (GST_OBJECT_FLAG_IS_SET (sink, GST_MULTI_FD_SINK_OPEN),
-      GST_FLOW_ERROR);
-
   in_caps = GST_BUFFER_FLAG_IS_SET (buf, GST_BUFFER_FLAG_IN_CAPS);
 
   GST_LOG_OBJECT (sink, "received buffer %p, in_caps: %d", buf, in_caps);
@@ -2281,8 +2281,15 @@ gst_multi_fd_sink_render (GstBaseSink * bsink, GstBuffer * buf)
 
     sink->bytes_to_serve += GST_BUFFER_SIZE (buf);
   }
-
   return GST_FLOW_OK;
+
+  /* ERRORS */
+no_caps:
+  {
+    GST_ELEMENT_ERROR (sink, CORE, NEGOTIATION, (NULL),
+        ("Received first buffer without caps set"));
+    return GST_FLOW_NOT_NEGOTIATED;
+  }
 }
 
 static void