From 77299ba6aeb30a80b4ce9fc1fffd5e1c98c0842a Mon Sep 17 00:00:00 2001
From: Wim Taymans <wim.taymans@collabora.co.uk>
Date: Sun, 11 Mar 2012 19:06:59 +0100
Subject: [PATCH] fix for caps api changes

---
 ext/assrender/gstassrender.c                  |  8 +++++---
 ext/modplug/gstmodplug.cc                     |  2 +-
 gst-libs/gst/video/gstbasevideoencoder.c      |  7 ++++---
 gst/audiovisualizers/gstbaseaudiovisualizer.c |  5 +++--
 gst/autoconvert/gstautoconvert.c              |  4 ++--
 gst/dtmf/gstdtmfsrc.c                         | 12 +++++++-----
 gst/dtmf/gstrtpdtmfsrc.c                      |  3 ++-
 gst/dvbsuboverlay/gstdvbsuboverlay.c          |  9 +++++----
 gst/dvdspu/gstdvdspu.c                        |  6 +++---
 gst/rtpmux/gstrtpmux.c                        |  9 ++++-----
 gst/videoparsers/gsth264parse.c               |  5 ++---
 tests/check/pipelines/colorspace.c            |  5 +++--
 12 files changed, 41 insertions(+), 34 deletions(-)

diff --git a/ext/assrender/gstassrender.c b/ext/assrender/gstassrender.c
index e7b5e14cab..882efc92ed 100644
--- a/ext/assrender/gstassrender.c
+++ b/ext/assrender/gstassrender.c
@@ -430,27 +430,29 @@ gst_ass_render_getcaps (GstPad * pad, GstCaps * filter)
   GstAssRender *render = GST_ASS_RENDER (gst_pad_get_parent (pad));
   GstPad *otherpad;
   GstCaps *caps;
+  GstCaps *templ;
 
   if (pad == render->srcpad)
     otherpad = render->video_sinkpad;
   else
     otherpad = render->srcpad;
 
+  templ = gst_pad_get_pad_template_caps (otherpad);
+
   /* we can do what the peer can */
   caps = gst_pad_peer_query_caps (otherpad, filter);
   if (caps) {
     GstCaps *temp;
-    const GstCaps *templ;
 
     /* filtered against our padtemplate */
-    templ = gst_pad_get_pad_template_caps (otherpad);
     temp = gst_caps_intersect (caps, templ);
     gst_caps_unref (caps);
+    gst_caps_unref (templ);
     /* this is what we can do */
     caps = temp;
   } else {
     /* no peer, our padtemplate is enough then */
-    caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
+    caps = templ;
   }
 
   gst_object_unref (render);
diff --git a/ext/modplug/gstmodplug.cc b/ext/modplug/gstmodplug.cc
index 05d8278537..5e1d176fe0 100644
--- a/ext/modplug/gstmodplug.cc
+++ b/ext/modplug/gstmodplug.cc
@@ -474,7 +474,7 @@ gst_modplug_load_song (GstModPlug * modplug)
 
   GST_DEBUG_OBJECT (modplug, "normalized caps %"GST_PTR_FORMAT, newcaps);
 
-  gst_caps_fixate (newcaps);
+  newcaps = gst_caps_fixate (newcaps);
 
   GST_DEBUG_OBJECT (modplug, "fixated caps %"GST_PTR_FORMAT, newcaps);
 
diff --git a/gst-libs/gst/video/gstbasevideoencoder.c b/gst-libs/gst/video/gstbasevideoencoder.c
index 3f38c298b4..6b1cfb0fb1 100644
--- a/gst-libs/gst/video/gstbasevideoencoder.c
+++ b/gst-libs/gst/video/gstbasevideoencoder.c
@@ -384,7 +384,7 @@ static GstCaps *
 gst_base_video_encoder_sink_getcaps (GstPad * pad, GstCaps * filter)
 {
   GstBaseVideoEncoder *base_video_encoder;
-  const GstCaps *templ_caps;
+  GstCaps *templ_caps;
   GstCaps *allowed;
   GstCaps *fcaps, *filter_caps;
   gint i, j;
@@ -403,7 +403,7 @@ gst_base_video_encoder_sink_getcaps (GstPad * pad, GstCaps * filter)
       gst_pad_get_allowed_caps (GST_BASE_VIDEO_CODEC_SRC_PAD
       (base_video_encoder));
   if (!allowed || gst_caps_is_empty (allowed) || gst_caps_is_any (allowed)) {
-    fcaps = gst_caps_copy (templ_caps);
+    fcaps = templ_caps;
     goto done;
   }
 
@@ -432,7 +432,7 @@ gst_base_video_encoder_sink_getcaps (GstPad * pad, GstCaps * filter)
       if ((val = gst_structure_get_value (allowed_s, "pixel-aspect-ratio")))
         gst_structure_set_value (s, "pixel-aspect-ratio", val);
 
-      gst_caps_merge_structure (filter_caps, s);
+      filter_caps = gst_caps_merge_structure (filter_caps, s);
     }
   }
 
@@ -440,6 +440,7 @@ gst_base_video_encoder_sink_getcaps (GstPad * pad, GstCaps * filter)
       filter_caps);
 
   fcaps = gst_caps_intersect (filter_caps, templ_caps);
+  gst_caps_unref (templ_caps);
   gst_caps_unref (filter_caps);
 
   if (filter) {
diff --git a/gst/audiovisualizers/gstbaseaudiovisualizer.c b/gst/audiovisualizers/gstbaseaudiovisualizer.c
index 6761d01d94..5663037962 100644
--- a/gst/audiovisualizers/gstbaseaudiovisualizer.c
+++ b/gst/audiovisualizers/gstbaseaudiovisualizer.c
@@ -685,11 +685,12 @@ gst_base_audio_visualizer_src_negotiate (GstBaseAudioVisualizer * scope)
     if (gst_caps_is_empty (target))
       goto no_format;
 
-    gst_caps_truncate (target);
+    target = gst_caps_truncate (target);
   } else {
-    target = gst_caps_ref ((GstCaps *) templ);
+    target = templ;
   }
 
+  target = gst_caps_make_writable (target);
   structure = gst_caps_get_structure (target, 0);
   gst_structure_fixate_field_nearest_int (structure, "width", scope->width);
   gst_structure_fixate_field_nearest_int (structure, "height", scope->height);
diff --git a/gst/autoconvert/gstautoconvert.c b/gst/autoconvert/gstautoconvert.c
index 32bab04463..1ecc354991 100644
--- a/gst/autoconvert/gstautoconvert.c
+++ b/gst/autoconvert/gstautoconvert.c
@@ -1147,7 +1147,7 @@ gst_auto_convert_getcaps (GstAutoConvert * autoconvert, GstCaps * filter,
       if (element_caps) {
         if (!gst_caps_is_any (element_caps) &&
             !gst_caps_is_empty (element_caps)) {
-          gst_caps_merge (caps, element_caps);
+          caps = gst_caps_merge (caps, element_caps);
         } else {
           gst_caps_unref (element_caps);
         }
@@ -1166,7 +1166,7 @@ gst_auto_convert_getcaps (GstAutoConvert * autoconvert, GstCaps * filter,
 
           if (static_caps && !gst_caps_is_any (static_caps) &&
               !gst_caps_is_empty (static_caps)) {
-            gst_caps_merge (caps, static_caps);
+            caps = gst_caps_merge (caps, static_caps);
           }
         }
       }
diff --git a/gst/dtmf/gstdtmfsrc.c b/gst/dtmf/gstdtmfsrc.c
index e5a8eef585..b3f24ffda1 100644
--- a/gst/dtmf/gstdtmfsrc.c
+++ b/gst/dtmf/gstdtmfsrc.c
@@ -852,14 +852,16 @@ gst_dtmf_src_negotiate (GstBaseSrc * basesrc)
   caps = gst_pad_get_allowed_caps (GST_BASE_SRC_PAD (basesrc));
 
   if (!caps)
-    caps =
-        gst_caps_copy (gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD
-            (basesrc)));
+    caps = gst_pad_get_pad_template_caps (GST_BASE_SRC_PAD (basesrc));
 
-  if (gst_caps_is_empty (caps))
+  if (gst_caps_is_empty (caps)) {
+    gst_caps_unref (caps);
     return FALSE;
+  }
 
-  gst_caps_truncate (caps);
+  caps = gst_caps_truncate (caps);
+
+  caps = gst_caps_make_writable (caps);
   s = gst_caps_get_structure (caps, 0);
 
   gst_structure_fixate_field_nearest_int (s, "rate", DEFAULT_SAMPLE_RATE);
diff --git a/gst/dtmf/gstrtpdtmfsrc.c b/gst/dtmf/gstrtpdtmfsrc.c
index 6e6140af76..a078a111d7 100644
--- a/gst/dtmf/gstrtpdtmfsrc.c
+++ b/gst/dtmf/gstrtpdtmfsrc.c
@@ -904,7 +904,8 @@ gst_rtp_dtmf_src_negotiate (GstBaseSrc * basesrc)
     }
 
     /* now fixate, start by taking the first caps */
-    gst_caps_truncate (temp);
+    temp = gst_caps_truncate (temp);
+    temp = gst_caps_make_writable (temp);
     srccaps = temp;
 
     /* get first structure */
diff --git a/gst/dvbsuboverlay/gstdvbsuboverlay.c b/gst/dvbsuboverlay/gstdvbsuboverlay.c
index 235f86a241..833c8dfdc7 100644
--- a/gst/dvbsuboverlay/gstdvbsuboverlay.c
+++ b/gst/dvbsuboverlay/gstdvbsuboverlay.c
@@ -401,28 +401,29 @@ gst_dvbsub_overlay_getcaps (GstPad * pad, GstCaps * filter)
 {
   GstDVBSubOverlay *render = GST_DVBSUB_OVERLAY (gst_pad_get_parent (pad));
   GstPad *otherpad;
-  GstCaps *caps;
+  GstCaps *caps, *templ;
 
   if (pad == render->srcpad)
     otherpad = render->video_sinkpad;
   else
     otherpad = render->srcpad;
 
+  templ = gst_pad_get_pad_template_caps (otherpad);
+
   /* we can do what the peer can */
   caps = gst_pad_peer_query_caps (otherpad, filter);
   if (caps) {
     GstCaps *temp;
-    const GstCaps *templ;
 
     /* filtered against our padtemplate */
-    templ = gst_pad_get_pad_template_caps (otherpad);
     temp = gst_caps_intersect (caps, templ);
+    gst_caps_unref (templ);
     gst_caps_unref (caps);
     /* this is what we can do */
     caps = temp;
   } else {
     /* no peer, our padtemplate is enough then */
-    caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
+    caps = templ;
   }
 
   gst_object_unref (render);
diff --git a/gst/dvdspu/gstdvdspu.c b/gst/dvdspu/gstdvdspu.c
index 0447832706..2088581f0c 100644
--- a/gst/dvdspu/gstdvdspu.c
+++ b/gst/dvdspu/gstdvdspu.c
@@ -363,15 +363,15 @@ gst_dvd_spu_video_proxy_getcaps (GstPad * pad, GstCaps * filter)
 
   caps = gst_pad_peer_query_caps (otherpad, filter);
   if (caps) {
-    GstCaps *temp;
-    const GstCaps *templ;
+    GstCaps *temp, *templ;
 
     templ = gst_pad_get_pad_template_caps (otherpad);
     temp = gst_caps_intersect (caps, templ);
+    gst_caps_unref (templ);
     gst_caps_unref (caps);
     caps = temp;
   } else {
-    caps = gst_caps_copy (gst_pad_get_pad_template_caps (pad));
+    caps = gst_pad_get_pad_template_caps (pad);
   }
 
   gst_object_unref (dvdspu);
diff --git a/gst/rtpmux/gstrtpmux.c b/gst/rtpmux/gstrtpmux.c
index de09fd488a..5babda47dd 100644
--- a/gst/rtpmux/gstrtpmux.c
+++ b/gst/rtpmux/gstrtpmux.c
@@ -591,15 +591,14 @@ same_clock_rate_fold (const GValue * item, GValue * ret, gpointer user_data)
   GstPad *mypad = user_data;
   GstPad *pad = g_value_get_object (item);
   GstCaps *peercaps;
-  const GstCaps *accumcaps;
+  GstCaps *accumcaps;
   GstCaps *intersect;
 
-  if (pad == mypad) {
+  if (pad == mypad)
     return TRUE;
-  }
 
-  accumcaps = gst_value_get_caps (ret);
-  peercaps = gst_pad_peer_query_caps (pad, (GstCaps *) accumcaps);
+  accumcaps = g_value_get_boxed (ret);
+  peercaps = gst_pad_peer_query_caps (pad, accumcaps);
   if (!peercaps) {
     g_warning ("no peercaps");
     return TRUE;
diff --git a/gst/videoparsers/gsth264parse.c b/gst/videoparsers/gsth264parse.c
index 5074bdc6d3..58264d59e8 100644
--- a/gst/videoparsers/gsth264parse.c
+++ b/gst/videoparsers/gsth264parse.c
@@ -328,8 +328,7 @@ gst_h264_parse_negotiate (GstH264Parse * h264parse, gint in_format,
   /* concentrate on leading structure, since decodebin2 parser
    * capsfilter always includes parser template caps */
   if (caps) {
-    caps = gst_caps_make_writable (caps);
-    gst_caps_truncate (caps);
+    caps = gst_caps_truncate (caps);
     GST_DEBUG_OBJECT (h264parse, "negotiating with caps: %" GST_PTR_FORMAT,
         caps);
   }
@@ -345,7 +344,7 @@ gst_h264_parse_negotiate (GstH264Parse * h264parse, gint in_format,
 
   if (caps) {
     /* fixate to avoid ambiguity with lists when parsing */
-    gst_caps_fixate (caps);
+    caps = gst_caps_fixate (caps);
     gst_h264_parse_format_from_caps (caps, &format, &align);
     gst_caps_unref (caps);
   }
diff --git a/tests/check/pipelines/colorspace.c b/tests/check/pipelines/colorspace.c
index 1acb4ab67f..56ec9c114e 100644
--- a/tests/check/pipelines/colorspace.c
+++ b/tests/check/pipelines/colorspace.c
@@ -58,7 +58,7 @@ colorspace_compare (gint width, gint height, gboolean comp)
   GstElement *pipeline, *src, *filter1, *filter2, *csp, *fcsp, *fakesink;
   GstElement *queue1, *queue2, *tee, *compare;
   GstCaps *caps, *tcaps, *rcaps, *fcaps;
-  const GstCaps *ccaps;
+  GstCaps *ccaps;
   GstPad *pad;
 
   gint i, j;
@@ -122,7 +122,7 @@ colorspace_compare (gint width, gint height, gboolean comp)
     fail_unless (pad != NULL);
     ccaps = gst_pad_get_pad_template_caps (pad);
     fail_unless (ccaps != NULL);
-    fcaps = gst_caps_copy (ccaps);
+    fcaps = ccaps;
     gst_object_unref (pad);
   } else {
     fcaps = gst_caps_new_any ();
@@ -163,6 +163,7 @@ colorspace_compare (gint width, gint height, gboolean comp)
 
   tcaps = gst_caps_intersect (fcaps, ccaps);
   gst_caps_unref (fcaps);
+  gst_caps_unref (ccaps);
   caps = gst_caps_intersect (tcaps, caps);
   gst_caps_unref (tcaps);
   tcaps = caps;