codec-utils: Add utilities for AAC and the AACHead header
authorJimmy Ohn <yongjin.ohn@lge.com>
Tue, 22 Mar 2016 02:25:49 +0000 (11:25 +0900)
committerSebastian Dröge <sebastian@centricular.com>
Thu, 24 Mar 2016 12:27:21 +0000 (14:27 +0200)
Add utilities about the channels and sample rate for AAC.

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

docs/libs/gst-plugins-base-libs-sections.txt
gst-libs/gst/pbutils/codec-utils.c
gst-libs/gst/pbutils/codec-utils.h
win32/common/libgstpbutils.def

index d00e67c..fa23f24 100644 (file)
@@ -2217,6 +2217,8 @@ gst_codec_utils_aac_get_sample_rate_from_index
 gst_codec_utils_aac_get_index_from_sample_rate
 gst_codec_utils_aac_get_profile
 gst_codec_utils_aac_get_level
+gst_codec_utils_aac_get_channels
+gst_codec_utils_aac_get_sample_rate
 gst_codec_utils_aac_caps_set_level_and_profile
 <SUBSECTION>
 gst_codec_utils_h264_get_profile
index 2c8c5a9..5d497eb 100644 (file)
@@ -110,6 +110,59 @@ gst_codec_utils_aac_get_index_from_sample_rate (guint rate)
 }
 
 /**
+ * gst_codec_utils_aac_get_sample_rate:
+ * @audio_config: a pointer to the AudioSpecificConfig as specified in the
+ *                Elementary Stream Descriptor (esds) in ISO/IEC 14496-1.
+ * @len: Length of @audio_config in bytes
+ *
+ * Translates the sample rate index found in AAC headers to the actual sample
+ * rate.
+ *
+ * Returns: The sample rate if sr_idx is valid, 0 otherwise.
+ *
+ * Since 1.10
+ */
+guint
+gst_codec_utils_aac_get_sample_rate (const guint8 * audio_config, guint len)
+{
+  guint rate_index;
+
+  if (len < 2)
+    return 0;
+
+  rate_index = ((audio_config[0] & 0x7) << 1) | ((audio_config[1] & 0x80) >> 7);
+  return gst_codec_utils_aac_get_sample_rate_from_index (rate_index);
+}
+
+/**
+ * gst_codec_utils_aac_get_channels:
+ * @audio_config: a pointer to the AudioSpecificConfig as specified in the
+ *                Elementary Stream Descriptor (esds) in ISO/IEC 14496-1.
+ *
+ * Returns the channels of the given AAC stream.
+ *
+ * Returns: The channels or 0 if the channel could not be determined.
+ *
+ * Since 1.10
+ */
+guint
+gst_codec_utils_aac_get_channels (const guint8 * audio_config, guint len)
+{
+  guint channels;
+
+  if (len < 2)
+    return 0;
+
+  channels = (audio_config[1] & 0x7f) >> 3;
+  if (channels > 0 && channels < 7)
+    return channels;
+  else if (channels == 7)
+    return 8;
+  else
+    return 0;
+}
+
+/**
  * gst_codec_utils_aac_get_profile:
  * @audio_config: a pointer to the AudioSpecificConfig as specified in the
  *                Elementary Stream Descriptor (esds) in ISO/IEC 14496-1 (see
index e1def83..979abaf 100644 (file)
@@ -35,6 +35,10 @@ const gchar * gst_codec_utils_aac_get_profile (const guint8 * audio_config, guin
 
 const gchar * gst_codec_utils_aac_get_level   (const guint8 * audio_config, guint len);
 
+guint         gst_codec_utils_aac_get_sample_rate (const guint8 * audio_config, guint len);
+
+guint         gst_codec_utils_aac_get_channels (const guint8 * audio_config, guint len);
+
 gboolean      gst_codec_utils_aac_caps_set_level_and_profile (GstCaps      * caps,
                                                               const guint8 * audio_config,
                                                               guint          len);
index 785bfb4..dac952b 100644 (file)
@@ -5,6 +5,8 @@ EXPORTS
        gst_codec_utils_aac_get_index_from_sample_rate
        gst_codec_utils_aac_get_level
        gst_codec_utils_aac_get_profile
+       gst_codec_utils_aac_get_sample_rate
+       gst_codec_utils_aac_get_channels
        gst_codec_utils_aac_get_sample_rate_from_index
        gst_codec_utils_h264_caps_set_level_and_profile
        gst_codec_utils_h264_get_level