From e199d7e1cd25eee6d7d3314f83bdda461eb1b509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Sat, 1 Aug 2009 17:26:23 +0100 Subject: [PATCH] typefinding: fix detection of fLaC id packet in broken flac-in-ogg There are flac-in-ogg files without the usual flac packet framing and these files just have a 4-byte fLaC ID packet as first packet. We need to recognise the type just from these four bytes if we want oggdemux to recognise these streams correctly. --- gst/typefind/gsttypefindfunctions.c | 8 ++++++-- tests/check/gst/typefindfunctions.c | 29 +++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index 5600c53f9a..be7371aa78 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -554,15 +554,19 @@ flac_type_find (GstTypeFind * tf, gpointer unused) { DataScanCtx c = { 0, NULL, 0 }; - if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6))) + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 4))) return; - /* standard flac */ + /* standard flac (also old/broken flac-in-ogg with an initial 4-byte marker + * packet and without the usual packet framing) */ if (memcmp (c.data, "fLaC", 4) == 0) { gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS); return; } + if (G_UNLIKELY (!data_scan_ctx_ensure_data (tf, &c, 6))) + return; + /* flac-in-ogg, see http://flac.sourceforge.net/ogg_mapping.html */ if (memcmp (c.data, "\177FLAC\001", 6) == 0) { gst_type_find_suggest (tf, GST_TYPE_FIND_MAXIMUM, FLAC_CAPS); diff --git a/tests/check/gst/typefindfunctions.c b/tests/check/gst/typefindfunctions.c index e74aaf37f0..08d3f1bc53 100644 --- a/tests/check/gst/typefindfunctions.c +++ b/tests/check/gst/typefindfunctions.c @@ -80,6 +80,34 @@ GST_START_TEST (test_quicktime_mpeg4video) GST_END_TEST; +GST_START_TEST (test_broken_flac_in_ogg) +{ + const guint8 flac_id_packet[4] = { 'f', 'L', 'a', 'C' }; + GstTypeFindProbability prob; + const gchar *type; + GstBuffer *buf; + GstCaps *caps = NULL; + + buf = gst_buffer_new (); + GST_BUFFER_DATA (buf) = (guint8 *) flac_id_packet; + GST_BUFFER_SIZE (buf) = sizeof (flac_id_packet); + GST_BUFFER_OFFSET (buf) = 0; + + caps = gst_type_find_helper_for_buffer (NULL, buf, &prob); + fail_unless (caps != NULL); + GST_LOG ("Found type: %" GST_PTR_FORMAT, caps); + + type = gst_structure_get_name (gst_caps_get_structure (caps, 0)); + fail_unless_equals_string (type, "audio/x-flac"); + fail_unless (prob > GST_TYPE_FIND_MINIMUM && prob <= GST_TYPE_FIND_MAXIMUM); + + gst_buffer_unref (buf); + gst_caps_unref (caps); + +} + +GST_END_TEST; + static Suite * typefindfunctions_suite (void) { @@ -89,6 +117,7 @@ typefindfunctions_suite (void) suite_add_tcase (s, tc_chain); tcase_add_test (tc_chain, test_quicktime_mpeg4video); + tcase_add_test (tc_chain, test_broken_flac_in_ogg); return s; }