From 555a3a5d147bc0ea7c4e57c8da4803c9b21150e1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim-Philipp=20M=C3=BCller?= Date: Mon, 12 Apr 2010 14:02:34 +0100 Subject: [PATCH] typefinding: add channels and rate to ADTS caps if we can --- gst/typefind/gsttypefindfunctions.c | 38 +++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/gst/typefind/gsttypefindfunctions.c b/gst/typefind/gsttypefindfunctions.c index cb30e8d..b5cd7f5 100644 --- a/gst/typefind/gsttypefindfunctions.c +++ b/gst/typefind/gsttypefindfunctions.c @@ -686,8 +686,10 @@ aac_type_find (GstTypeFind * tf, gpointer unused) goto next; } + /* check if there's a second ADTS frame */ snc = GST_READ_UINT16_BE (c.data + len); if ((snc & 0xfff6) == 0xfff0) { + GstCaps *caps; guint mpegversion, sample_freq_idx, channel_config, profile, rate; gint level; @@ -713,29 +715,33 @@ aac_type_find (GstTypeFind * tf, gpointer unused) /* ADTS counts profiles from 0 instead of 1 to save bits */ level = gst_aac_level_from_header (profile + 1, rate, channel_config); - if (level == -1) { - /* Could not determine the level */ - gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg", - "framed", G_TYPE_BOOLEAN, FALSE, - "mpegversion", G_TYPE_INT, mpegversion, - "stream-type", G_TYPE_STRING, "adts", - "base-profile", G_TYPE_STRING, profile_to_string[profile], - "profile", G_TYPE_STRING, profile_to_string[profile], NULL); - } else { + caps = gst_caps_new_simple ("audio/mpeg", + "framed", G_TYPE_BOOLEAN, FALSE, + "mpegversion", G_TYPE_INT, mpegversion, + "stream-type", G_TYPE_STRING, "adts", + "base-profile", G_TYPE_STRING, profile_to_string[profile], + "profile", G_TYPE_STRING, profile_to_string[profile], NULL); + + if (level != -1) { gchar level_str[16]; /* we use a string here because h.264 levels are also strings and * there aren't a lot of levels, so it's not too awkward to not use * and integer here and keep the field type consistent with h.264 */ g_snprintf (level_str, sizeof (level_str), "%d", level); - gst_type_find_suggest_simple (tf, GST_TYPE_FIND_LIKELY, "audio/mpeg", - "framed", G_TYPE_BOOLEAN, FALSE, - "mpegversion", G_TYPE_INT, mpegversion, - "stream-type", G_TYPE_STRING, "adts", - "base-profile", G_TYPE_STRING, profile_to_string[profile], - "profile", G_TYPE_STRING, profile_to_string[profile], - "level", G_TYPE_STRING, level_str, NULL); + gst_caps_set_simple (caps, "level", G_TYPE_STRING, level_str, NULL); + } + + /* add rate and number of channels if we can */ + if (channel_config != 0 && channel_config <= 7) { + const guint channels_map[] = { 0, 1, 2, 3, 4, 5, 6, 8 }; + + gst_caps_set_simple (caps, "channels", G_TYPE_INT, + channels_map[channel_config], "rate", G_TYPE_INT, rate, NULL); } + + gst_type_find_suggest (tf, GST_TYPE_FIND_LIKELY, caps); + gst_caps_unref (caps); break; } -- 2.7.4