audioparsers: use ACCEPT_INTERSECT flag
authorWim Taymans <wtaymans@redhat.com>
Tue, 3 Dec 2013 20:41:28 +0000 (21:41 +0100)
committerWim Taymans <wtaymans@redhat.com>
Tue, 3 Dec 2013 21:26:44 +0000 (22:26 +0100)
The parser can accept input that is not completely specified. Use the
ACCEPT_INTERSECT flag on the sinkpad to tweak the acceptcaps function to
check for intersection only. This allows us to proxy downstream
constraints while still allowing non-subset caps as input.
We can then also remove the appended template caps workaround.
Make a unit-test to check the new feature.

This reverts commit 26040ee38cb9e7c42f3d9a0282b3e5cace7ca42d

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

gst/audioparsers/gstaacparse.c
gst/audioparsers/gstac3parse.c
gst/audioparsers/gstamrparse.c
gst/audioparsers/gstdcaparse.c
gst/audioparsers/gstflacparse.c
gst/audioparsers/gstmpegaudioparse.c
gst/audioparsers/gstsbcparse.c
gst/audioparsers/gstwavpackparse.c
tests/check/elements/aacparse.c

index 745e95b..cb22f6b 100644 (file)
@@ -143,6 +143,7 @@ static void
 gst_aac_parse_init (GstAacParse * aacparse)
 {
   GST_DEBUG ("initialized");
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (aacparse));
 }
 
 
@@ -1391,13 +1392,6 @@ gst_aac_parse_sink_getcaps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index f63dec4..5f32b11 100644 (file)
@@ -218,6 +218,7 @@ gst_ac3_parse_init (GstAc3Parse * ac3parse)
   gst_ac3_parse_reset (ac3parse);
   ac3parse->baseparse_chainfunc =
       GST_BASE_PARSE_SINK_PAD (GST_BASE_PARSE (ac3parse))->chainfunc;
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (ac3parse));
 }
 
 static void
@@ -837,13 +838,6 @@ gst_ac3_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index 1a32152..be1f711 100644 (file)
@@ -128,7 +128,7 @@ gst_amr_parse_init (GstAmrParse * amrparse)
   /* init rest */
   gst_base_parse_set_min_frame_size (GST_BASE_PARSE (amrparse), 62);
   GST_DEBUG ("initialized");
-
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (amrparse));
 }
 
 
index 0f3cac4..76890a1 100644 (file)
@@ -132,6 +132,8 @@ gst_dca_parse_init (GstDcaParse * dcaparse)
   gst_dca_parse_reset (dcaparse);
   dcaparse->baseparse_chainfunc =
       GST_BASE_PARSE_SINK_PAD (GST_BASE_PARSE (dcaparse))->chainfunc;
+
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (dcaparse));
 }
 
 static void
@@ -510,13 +512,6 @@ gst_dca_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index 6619f9e..9ef50ee 100644 (file)
@@ -258,6 +258,7 @@ static void
 gst_flac_parse_init (GstFlacParse * flacparse)
 {
   flacparse->check_frame_checksums = DEFAULT_CHECK_FRAME_CHECKSUMS;
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (flacparse));
 }
 
 static void
@@ -1829,13 +1830,6 @@ gst_flac_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index 534f466..87f1445 100644 (file)
@@ -225,6 +225,7 @@ static void
 gst_mpeg_audio_parse_init (GstMpegAudioParse * mp3parse)
 {
   gst_mpeg_audio_parse_reset (mp3parse);
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (mp3parse));
 }
 
 static void
@@ -1434,13 +1435,6 @@ gst_mpeg_audio_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index 307cb27..1d65e5c 100644 (file)
@@ -121,6 +121,7 @@ static void
 gst_sbc_parse_init (GstSbcParse * sbcparse)
 {
   gst_sbc_parse_reset (sbcparse);
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (sbcparse));
 }
 
 static gboolean
@@ -335,13 +336,6 @@ gst_sbc_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index 6846048..44bae19 100644 (file)
@@ -117,6 +117,7 @@ static void
 gst_wavpack_parse_init (GstWavpackParse * wvparse)
 {
   gst_wavpack_parse_reset (wvparse);
+  GST_PAD_SET_ACCEPT_INTERSECT (GST_BASE_PARSE_SINK_PAD (wvparse));
 }
 
 static void
@@ -644,13 +645,6 @@ gst_wavpack_parse_get_sink_caps (GstBaseParse * parse, GstCaps * filter)
 
     res = gst_caps_intersect_full (peercaps, templ, GST_CAPS_INTERSECT_FIRST);
     gst_caps_unref (peercaps);
-    res = gst_caps_make_writable (res);
-
-    /* Append the template caps because we still want to accept
-     * caps without any fields in the case upstream does not
-     * know anything.
-     */
-    gst_caps_append (res, templ);
   } else {
     res = templ;
   }
index b611297..53dcbdb 100644 (file)
@@ -185,6 +185,50 @@ GST_START_TEST (test_parse_handle_codec_data)
 
 GST_END_TEST;
 
+GST_START_TEST (test_parse_proxy_constraints)
+{
+  GstCaps *caps;
+  GstElement *parse, *filter;
+  GstPad *sinkpad;
+  GstStructure *s;
+
+  parse = gst_element_factory_make ("aacparse", NULL);
+  filter = gst_element_factory_make ("capsfilter", NULL);
+
+  /* constraint on rate and version */
+  caps = gst_caps_from_string ("audio/mpeg,mpegversion=2,rate=44100");
+  g_object_set (filter, "caps", caps, NULL);
+  gst_caps_unref (caps);
+
+  gst_element_link (parse, filter);
+
+  sinkpad = gst_element_get_static_pad (parse, "sink");
+  caps = gst_pad_query_caps (sinkpad, NULL);
+  GST_LOG ("caps %" GST_PTR_FORMAT, caps);
+
+  fail_unless (gst_caps_get_size (caps) == 1);
+
+  /* getcaps should proxy the rate constraint */
+  s = gst_caps_get_structure (caps, 0);
+  fail_unless (gst_structure_has_name (s, "audio/mpeg"));
+  fail_unless_structure_field_int_equals (s, "rate", 44100);
+  gst_caps_unref (caps);
+
+  /* should accept without the constraint */
+  caps = gst_caps_from_string ("audio/mpeg,mpegversion=2");
+  fail_unless (gst_pad_query_accept_caps (sinkpad, caps));
+  gst_caps_unref (caps);
+
+  /* should not accept with conflicting version */
+  caps = gst_caps_from_string ("audio/mpeg,mpegversion=4");
+  fail_if (gst_pad_query_accept_caps (sinkpad, caps));
+  gst_caps_unref (caps);
+
+  gst_object_unref (sinkpad);
+
+}
+
+GST_END_TEST;
 
 static Suite *
 aacparse_suite (void)
@@ -207,6 +251,9 @@ aacparse_suite (void)
   /* Other tests */
   tcase_add_test (tc_chain, test_parse_handle_codec_data);
 
+  /* caps tests */
+  tcase_add_test (tc_chain, test_parse_proxy_constraints);
+
   return s;
 }