tests: matroskamux, qtmux: don't add codec_data buffers to template caps
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>
Tue, 7 Feb 2017 16:27:56 +0000 (17:27 +0100)
committerTim-Philipp Müller <tim@centricular.com>
Tue, 21 Feb 2017 15:47:16 +0000 (15:47 +0000)
streamheader and codec_data buffers fields are only meant to be
in the negotiated caps, not the template caps.

Fixes false-positive leaks of those buffers detected by the leaks
tracer, as template caps are static, and we decided to not include
code in gstreamer core to handle this unusual case of template caps
having buffers in them.

https://bugzilla.gnome.org/show_bug.cgi?id=768762

tests/check/elements/matroskamux.c
tests/check/elements/qtmux.c

index 7772d8f..bc2928c 100644 (file)
@@ -33,10 +33,12 @@ GstPad *mysrcpad, *mysinkpad;
 #define AC3_CAPS_STRING "audio/x-ac3, " \
                         "channels = (int) 1, " \
                         "rate = (int) 8000"
-#define VORBIS_CAPS_STRING "audio/x-vorbis, " \
-                           "channels = (int) 1, " \
-                           "rate = (int) 8000, " \
-                           "streamheader=(buffer)<10, 2020, 303030>"
+#define VORBIS_TMPL_CAPS_STRING "audio/x-vorbis, " \
+                                "channels = (int) 1, " \
+                                "rate = (int) 8000"
+/* streamheader shouldn't be in the template caps, only in the actual caps */
+#define VORBIS_CAPS_STRING VORBIS_TMPL_CAPS_STRING \
+                           ", streamheader=(buffer)<10, 2020, 303030>"
 
 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
@@ -45,7 +47,7 @@ static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
 static GstStaticPadTemplate srcvorbistemplate = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (VORBIS_CAPS_STRING));
+    GST_STATIC_CAPS (VORBIS_TMPL_CAPS_STRING));
 
 static GstStaticPadTemplate srcac3template = GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
index a029c52..642b409 100644 (file)
@@ -46,15 +46,17 @@ static GstPad *mysrcpad, *mysinkpad;
                         "channels = (int) 2, " \
                         "rate = (int) 48000"
 
-#define AUDIO_AAC_CAPS_STRING "audio/mpeg, " \
-                            "mpegversion=(int)4, " \
-                            "channels=(int)1, " \
-                            "rate=(int)44100, " \
-                            "stream-format=(string)raw, " \
-                            "level=(string)2, " \
-                            "base-profile=(string)lc, " \
-                            "profile=(string)lc, " \
-                            "codec_data=(buffer)1208"
+#define AUDIO_AAC_TMPL_CAPS_STRING "audio/mpeg, " \
+                                   "mpegversion=(int)4, " \
+                                   "channels=(int)1, " \
+                                   "rate=(int)44100, " \
+                                   "stream-format=(string)raw, " \
+                                   "level=(string)2, " \
+                                   "base-profile=(string)lc, " \
+                                   "profile=(string)lc"
+/* codec_data shouldn't be in the template caps, only in the actual caps */
+#define AUDIO_AAC_CAPS_STRING AUDIO_AAC_TMPL_CAPS_STRING \
+                              ", codec_data=(buffer)1208"
 
 #define VIDEO_CAPS_STRING "video/mpeg, " \
                            "mpegversion = (int) 4, " \
@@ -63,18 +65,20 @@ static GstPad *mysrcpad, *mysinkpad;
                            "height = (int) 288, " \
                            "framerate = (fraction) 25/1"
 
-#define VIDEO_CAPS_H264_STRING "video/x-h264, " \
-                               "width=(int)320, " \
-                               "height=(int)240, " \
-                               "framerate=(fraction)30/1, " \
-                               "pixel-aspect-ratio=(fraction)1/1, " \
-                               "codec_data=(buffer)01640014ffe1001867640014a" \
+#define VIDEO_TMPL_CAPS_H264_STRING "video/x-h264, " \
+                                    "width=(int)320, " \
+                                    "height=(int)240, " \
+                                    "framerate=(fraction)30/1, " \
+                                    "pixel-aspect-ratio=(fraction)1/1, " \
+                                    "stream-format=(string)avc, " \
+                                    "alignment=(string)au, " \
+                                    "level=(string)2, " \
+                                    "profile=(string)high"
+/* codec_data shouldn't be in the template caps, only in the actual caps */
+#define VIDEO_CAPS_H264_STRING VIDEO_TMPL_CAPS_H264_STRING \
+                               ", codec_data=(buffer)01640014ffe1001867640014a" \
                                    "cd94141fb0110000003001773594000f14299600" \
-                                   "1000568ebecb22c, " \
-                               "stream-format=(string)avc, " \
-                               "alignment=(string)au, " \
-                               "level=(string)2, " \
-                               "profile=(string)high"
+                                   "1000568ebecb22c"
 
 static GstStaticPadTemplate sinktemplate = GST_STATIC_PAD_TEMPLATE ("sink",
     GST_PAD_SINK,
@@ -90,7 +94,7 @@ static GstStaticPadTemplate srcvideoh264template =
 GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (VIDEO_CAPS_H264_STRING));
+    GST_STATIC_CAPS (VIDEO_TMPL_CAPS_H264_STRING));
 
 static GstStaticPadTemplate srcvideorawtemplate =
 GST_STATIC_PAD_TEMPLATE ("src",
@@ -107,7 +111,7 @@ static GstStaticPadTemplate srcaudioaactemplate =
 GST_STATIC_PAD_TEMPLATE ("src",
     GST_PAD_SRC,
     GST_PAD_ALWAYS,
-    GST_STATIC_CAPS (AUDIO_AAC_CAPS_STRING));
+    GST_STATIC_CAPS (AUDIO_AAC_TMPL_CAPS_STRING));
 
 /* setup and teardown needs some special handling for muxer */
 static GstPad *
@@ -819,7 +823,8 @@ extract_tags (const gchar * location, GstTagList ** taglist)
 
 static void
 test_average_bitrate_custom (const gchar * elementname,
-    GstStaticPadTemplate * tmpl, const gchar * sinkpadname)
+    GstStaticPadTemplate * tmpl, const gchar * caps_str,
+    const gchar * sinkpadname)
 {
   gchar *location;
   GstElement *qtmux;
@@ -854,7 +859,7 @@ test_average_bitrate_custom (const gchar * elementname,
 
   gst_pad_push_event (mysrcpad, gst_event_new_stream_start ("test"));
 
-  caps = gst_pad_get_pad_template_caps (mysrcpad);
+  caps = gst_caps_from_string (caps_str);
   gst_pad_set_caps (mysrcpad, caps);
   gst_caps_unref (caps);
 
@@ -910,11 +915,15 @@ test_average_bitrate_custom (const gchar * elementname,
 
 GST_START_TEST (test_average_bitrate)
 {
-  test_average_bitrate_custom ("mp4mux", &srcaudioaactemplate, "audio_%u");
-  test_average_bitrate_custom ("mp4mux", &srcvideoh264template, "video_%u");
-
-  test_average_bitrate_custom ("qtmux", &srcaudioaactemplate, "audio_%u");
-  test_average_bitrate_custom ("qtmux", &srcvideoh264template, "video_%u");
+  test_average_bitrate_custom ("mp4mux", &srcaudioaactemplate,
+      AUDIO_AAC_CAPS_STRING, "audio_%u");
+  test_average_bitrate_custom ("mp4mux", &srcvideoh264template,
+      VIDEO_CAPS_H264_STRING, "video_%u");
+
+  test_average_bitrate_custom ("qtmux", &srcaudioaactemplate,
+      AUDIO_AAC_CAPS_STRING, "audio_%u");
+  test_average_bitrate_custom ("qtmux", &srcvideoh264template,
+      VIDEO_CAPS_H264_STRING, "video_%u");
 }
 
 GST_END_TEST;