Merge branch 'master' into 0.11
[platform/upstream/gstreamer.git] / libs / gst / base / gstbasetransform.c
index 8875336..9ec798e 100644 (file)
@@ -271,7 +271,7 @@ struct _GstBaseTransformPrivate
 
   /* upstream caps and size suggestions */
   GstCaps *sink_suggest;
-  guint size_suggest;
+  gsize size_suggest;
   gboolean suggest_pending;
 
   gboolean reconfigure;
@@ -329,7 +329,7 @@ static gboolean gst_base_transform_sink_activate_push (GstPad * pad,
 static gboolean gst_base_transform_activate (GstBaseTransform * trans,
     gboolean active);
 static gboolean gst_base_transform_get_unit_size (GstBaseTransform * trans,
-    GstCaps * caps, guint * size);
+    GstCaps * caps, gsize * size);
 
 static gboolean gst_base_transform_src_event (GstPad * pad, GstEvent * event);
 static gboolean gst_base_transform_src_eventfunc (GstBaseTransform * trans,
@@ -566,9 +566,9 @@ gst_base_transform_transform_caps (GstBaseTransform * trans,
 static gboolean
 gst_base_transform_transform_size (GstBaseTransform * trans,
     GstPadDirection direction, GstCaps * caps,
-    guint size, GstCaps * othercaps, guint * othersize)
+    gsize size, GstCaps * othercaps, gsize * othersize)
 {
-  guint inunitsize, outunitsize, units;
+  gsize inunitsize, outunitsize, units;
   GstBaseTransformClass *klass;
   gboolean ret;
 
@@ -628,8 +628,8 @@ no_multiple:
   {
     GST_DEBUG_OBJECT (trans, "Size %u is not a multiple of unit size %u", size,
         inunitsize);
-    g_warning ("%s: size %u is not a multiple of unit size %u",
-        GST_ELEMENT_NAME (trans), size, inunitsize);
+    g_warning ("%s: size %" G_GSIZE_FORMAT " is not a multiple of unit size %"
+        G_GSIZE_FORMAT, GST_ELEMENT_NAME (trans), size, inunitsize);
     return FALSE;
   }
 no_out_size:
@@ -661,7 +661,7 @@ gst_base_transform_getcaps (GstPad * pad)
   otherpad = (pad == trans->srcpad) ? trans->sinkpad : trans->srcpad;
 
   /* we can do what the peer can */
-  caps = gst_pad_peer_get_caps_reffed (otherpad);
+  caps = gst_pad_peer_get_caps (otherpad);
   if (caps) {
     GstCaps *temp;
     const GstCaps *templ;
@@ -911,7 +911,7 @@ gst_base_transform_find_transform (GstBaseTransform * trans, GstPad * pad,
 
     GST_DEBUG_OBJECT (trans, "othercaps now %" GST_PTR_FORMAT, othercaps);
 
-    peercaps = gst_pad_get_caps_reffed (otherpeer);
+    peercaps = gst_pad_get_caps (otherpeer);
     intersect = gst_caps_intersect (peercaps, othercaps);
     gst_caps_unref (peercaps);
     gst_caps_unref (othercaps);
@@ -1052,9 +1052,9 @@ gst_base_transform_acceptcaps_default (GstBaseTransform * trans,
 
     /* get all the formats we can handle on this pad */
     if (direction == GST_PAD_SRC)
-      allowed = gst_pad_get_caps_reffed (trans->srcpad);
+      allowed = gst_pad_get_caps (trans->srcpad);
     else
-      allowed = gst_pad_get_caps_reffed (trans->sinkpad);
+      allowed = gst_pad_get_caps (trans->sinkpad);
 
     if (!allowed) {
       GST_DEBUG_OBJECT (trans, "gst_pad_get_caps() failed");
@@ -1273,7 +1273,7 @@ gst_base_transform_query_type (GstPad * pad)
 }
 
 static void
-compute_upstream_suggestion (GstBaseTransform * trans, guint expsize,
+compute_upstream_suggestion (GstBaseTransform * trans, gsize expsize,
     GstCaps * caps)
 {
   GstCaps *othercaps;
@@ -1291,7 +1291,7 @@ compute_upstream_suggestion (GstBaseTransform * trans, guint expsize,
      * because it should have checked if we could handle these caps. We can
      * simply ignore these caps and produce a buffer with our original caps. */
   } else {
-    guint size_suggest;
+    gsize size_suggest;
 
     GST_DEBUG_OBJECT (trans, "getting size of suggestion");
 
@@ -1332,7 +1332,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
   GstBaseTransformClass *bclass;
   GstBaseTransformPrivate *priv;
   GstFlowReturn ret = GST_FLOW_OK;
-  guint outsize, newsize, expsize;
+  gsize insize, outsize, newsize, expsize;
   gboolean discard, setcaps, copymeta;
   GstCaps *incaps, *oldcaps, *newcaps, *outcaps;
 
@@ -1342,13 +1342,15 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
 
   *out_buf = NULL;
 
+  insize = gst_buffer_get_size (in_buf);
+
   /* figure out how to allocate a buffer based on the current configuration */
   if (trans->passthrough) {
     GST_DEBUG_OBJECT (trans, "doing passthrough alloc");
     /* passthrough, we don't really need to call pad alloc but we still need to
      * in order to get upstream negotiation. The output size is the same as the
      * input size. */
-    outsize = GST_BUFFER_SIZE (in_buf);
+    outsize = insize;
     /* we always alloc and discard here */
     discard = TRUE;
   } else {
@@ -1358,7 +1360,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
     if (want_in_place) {
       GST_DEBUG_OBJECT (trans, "doing inplace alloc");
       /* we alloc a buffer of the same size as the input */
-      outsize = GST_BUFFER_SIZE (in_buf);
+      outsize = insize;
       /* only discard it when the input was not writable, otherwise, we reuse
        * the input buffer. */
       discard = gst_buffer_is_writable (in_buf);
@@ -1368,8 +1370,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
       /* copy transform, figure out the output size */
       if (!gst_base_transform_transform_size (trans,
               GST_PAD_SINK, GST_PAD_CAPS (trans->sinkpad),
-              GST_BUFFER_SIZE (in_buf), GST_PAD_CAPS (trans->srcpad),
-              &outsize)) {
+              insize, GST_PAD_CAPS (trans->srcpad), &outsize)) {
         goto unknown_size;
       }
       /* never discard this buffer, we need it for storing the output */
@@ -1428,7 +1429,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
 
   /* check if we got different caps on this new output buffer */
   newcaps = GST_BUFFER_CAPS (*out_buf);
-  newsize = GST_BUFFER_SIZE (*out_buf);
+  newsize = gst_buffer_get_size (*out_buf);
 
   if (newcaps && !gst_caps_is_equal (newcaps, oldcaps)) {
     GstCaps *othercaps;
@@ -1447,7 +1448,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
       GST_DEBUG_OBJECT (trans, "cannot perform transform on current buffer");
 
       gst_base_transform_transform_size (trans,
-          GST_PAD_SINK, incaps, GST_BUFFER_SIZE (in_buf), newcaps, &expsize);
+          GST_PAD_SINK, incaps, insize, newcaps, &expsize);
 
       compute_upstream_suggestion (trans, expsize, newcaps);
 
@@ -1459,7 +1460,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
       if (othercaps && !gst_caps_is_empty (othercaps)) {
         GST_DEBUG_OBJECT (trans, "we found target caps %" GST_PTR_FORMAT,
             othercaps);
-        *out_buf = gst_buffer_make_metadata_writable (*out_buf);
+        *out_buf = gst_buffer_make_writable (*out_buf);
         gst_buffer_set_caps (*out_buf, othercaps);
         gst_caps_unref (othercaps);
         newcaps = GST_BUFFER_CAPS (*out_buf);
@@ -1472,7 +1473,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
      * expected size here, we will check the size if we are going to use the
      * buffer later on. */
     gst_base_transform_transform_size (trans,
-        GST_PAD_SINK, incaps, GST_BUFFER_SIZE (in_buf), newcaps, &expsize);
+        GST_PAD_SINK, incaps, insize, newcaps, &expsize);
 
     if (can_convert) {
       GST_DEBUG_OBJECT (trans, "reconfigure transform for current buffer");
@@ -1487,7 +1488,7 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
             GST_DEBUG_PAD_NAME (trans->srcpad));
         bclass->fixate_caps (trans, GST_PAD_SINK, incaps, newcaps);
 
-        *out_buf = gst_buffer_make_metadata_writable (*out_buf);
+        *out_buf = gst_buffer_make_writable (*out_buf);
         gst_buffer_set_caps (*out_buf, newcaps);
         gst_caps_unref (newcaps);
         newcaps = GST_BUFFER_CAPS (*out_buf);
@@ -1538,8 +1539,8 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
           outsize);
       /* no valid buffer yet, make one, metadata is writable */
       *out_buf = gst_buffer_new_and_alloc (outsize);
-      gst_buffer_copy_metadata (*out_buf, in_buf,
-          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
+      gst_buffer_copy_into (*out_buf, in_buf,
+          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
     } else {
       GST_DEBUG_OBJECT (trans, "reuse input buffer");
       *out_buf = in_buf;
@@ -1596,19 +1597,19 @@ gst_base_transform_prepare_output_buffer (GstBaseTransform * trans,
 
   if (setcaps || copymeta) {
     GST_DEBUG_OBJECT (trans, "setcaps %d, copymeta %d", setcaps, copymeta);
-    if (!gst_buffer_is_metadata_writable (*out_buf)) {
-      GST_DEBUG_OBJECT (trans, "buffer metadata %p not writable", *out_buf);
+    if (!gst_buffer_is_writable (*out_buf)) {
+      GST_DEBUG_OBJECT (trans, "buffer %p not writable", *out_buf);
       if (in_buf == *out_buf)
-        *out_buf = gst_buffer_create_sub (in_buf, 0, GST_BUFFER_SIZE (in_buf));
+        *out_buf = gst_buffer_copy (in_buf);
       else
-        *out_buf = gst_buffer_make_metadata_writable (*out_buf);
+        *out_buf = gst_buffer_make_writable (*out_buf);
     }
     /* when we get here, the metadata should be writable */
     if (setcaps)
       gst_buffer_set_caps (*out_buf, outcaps);
     if (copymeta)
-      gst_buffer_copy_metadata (*out_buf, in_buf,
-          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS);
+      gst_buffer_copy_into (*out_buf, in_buf,
+          GST_BUFFER_COPY_FLAGS | GST_BUFFER_COPY_TIMESTAMPS, 0, -1);
     /* clear the GAP flag when the subclass does not understand it */
     if (!trans->priv->gap_aware)
       GST_BUFFER_FLAG_UNSET (*out_buf, GST_BUFFER_FLAG_GAP);
@@ -1655,7 +1656,7 @@ failed_configure:
  */
 static gboolean
 gst_base_transform_get_unit_size (GstBaseTransform * trans, GstCaps * caps,
-    guint * size)
+    gsize * size)
 {
   gboolean res = FALSE;
   GstBaseTransformClass *bclass;
@@ -1712,7 +1713,7 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
   GstFlowReturn res;
   gboolean proxy, suggest, same_caps;
   GstCaps *sink_suggest = NULL;
-  guint size_suggest;
+  gsize size_suggest;
 
   trans = GST_BASE_TRANSFORM (gst_pad_get_parent (pad));
   klass = GST_BASE_TRANSFORM_GET_CLASS (trans);
@@ -1773,8 +1774,7 @@ gst_base_transform_buffer_alloc (GstPad * pad, guint64 offset, guint size,
         GST_DEBUG_OBJECT (trans, "Suggested caps is not fixed: %"
             GST_PTR_FORMAT, sink_suggest);
 
-        peercaps =
-            gst_pad_peer_get_caps_reffed (GST_BASE_TRANSFORM_SINK_PAD (trans));
+        peercaps = gst_pad_peer_get_caps (GST_BASE_TRANSFORM_SINK_PAD (trans));
         /* try fixating by intersecting with peer caps */
         if (peercaps) {
           GstCaps *intersect;
@@ -2148,6 +2148,7 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
   GstClockTime running_time;
   GstClockTime timestamp;
   GstCaps *incaps;
+  gsize insize;
 
   bclass = GST_BASE_TRANSFORM_GET_CLASS (trans);
 
@@ -2167,13 +2168,16 @@ gst_base_transform_handle_buffer (GstBaseTransform * trans, GstBuffer * inbuf,
     }
   }
 
+  insize = gst_buffer_get_size (inbuf);
+
   if (GST_BUFFER_OFFSET_IS_VALID (inbuf))
-    GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset %"
-        G_GUINT64_FORMAT, inbuf, GST_BUFFER_SIZE (inbuf),
-        GST_BUFFER_OFFSET (inbuf));
+    GST_DEBUG_OBJECT (trans,
+        "handling buffer %p of size %" G_GSIZE_FORMAT " and offset %"
+        G_GUINT64_FORMAT, inbuf, insize, GST_BUFFER_OFFSET (inbuf));
   else
-    GST_DEBUG_OBJECT (trans, "handling buffer %p of size %d and offset NONE",
-        inbuf, GST_BUFFER_SIZE (inbuf));
+    GST_DEBUG_OBJECT (trans,
+        "handling buffer %p of size %" G_GSIZE_FORMAT " and offset NONE", inbuf,
+        insize);
 
   /* Don't allow buffer handling before negotiation, except in passthrough mode
    * or if the class doesn't implement a set_caps function (in which case it doesn't
@@ -2275,16 +2279,20 @@ no_qos:
 
       if (inbuf != *outbuf) {
         guint8 *indata, *outdata;
+        gsize insize, outsize;
 
         /* Different buffer. The data can still be the same when we are dealing
          * with subbuffers of the same buffer. Note that because of the FIXME in
          * prepare_output_buffer() we have decreased the refcounts of inbuf and
          * outbuf to keep them writable */
-        indata = GST_BUFFER_DATA (inbuf);
-        outdata = GST_BUFFER_DATA (*outbuf);
+        indata = gst_buffer_map (inbuf, &insize, NULL, GST_MAP_READ);
+        outdata = gst_buffer_map (*outbuf, &outsize, NULL, GST_MAP_WRITE);
 
         if (indata != outdata)
-          memcpy (outdata, indata, GST_BUFFER_SIZE (inbuf));
+          memcpy (outdata, indata, insize);
+
+        gst_buffer_unmap (inbuf, indata, insize);
+        gst_buffer_unmap (*outbuf, outdata, outsize);
       }
       ret = bclass->transform_ip (trans, *outbuf);
     } else {
@@ -2436,7 +2444,7 @@ gst_base_transform_chain (GstPad * pad, GstBuffer * buffer)
       /* apply DISCONT flag if the buffer is not yet marked as such */
       if (trans->priv->discont) {
         if (!GST_BUFFER_IS_DISCONT (outbuf)) {
-          outbuf = gst_buffer_make_metadata_writable (outbuf);
+          outbuf = gst_buffer_make_writable (outbuf);
           GST_BUFFER_FLAG_SET (outbuf, GST_BUFFER_FLAG_DISCONT);
         }
         trans->priv->discont = FALSE;
@@ -2837,7 +2845,7 @@ gst_base_transform_set_gap_aware (GstBaseTransform * trans, gboolean gap_aware)
  */
 void
 gst_base_transform_suggest (GstBaseTransform * trans, GstCaps * caps,
-    guint size)
+    gsize size)
 {
   g_return_if_fail (GST_IS_BASE_TRANSFORM (trans));