[FFmpeg-cvslog] riff: Factor out WAVEFORMATEX parsing

Luca Barbato git at videolan.org
Mon Apr 22 13:01:25 CEST 2013


ffmpeg | branch: master | Luca Barbato <lu_zero at gentoo.org> | Sat Apr 20 13:36:48 2013 +0200| [b845f5e97b655de0a191f736594777fec9754cf5] | committer: Diego Biurrun

riff: Factor out WAVEFORMATEX parsing

Makes the code simpler to follow.

Signed-off-by: Diego Biurrun <diego at biurrun.de>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=b845f5e97b655de0a191f736594777fec9754cf5
---

 libavformat/riff.c |   41 +++++++++++++++++++++++------------------
 1 file changed, 23 insertions(+), 18 deletions(-)

diff --git a/libavformat/riff.c b/libavformat/riff.c
index 8a1962a..eae1f64 100644
--- a/libavformat/riff.c
+++ b/libavformat/riff.c
@@ -682,6 +682,28 @@ void ff_riff_write_info(AVFormatContext *s)
  * WAVEFORMATEX adds 'WORD  cbSize' and basically makes itself
  * an openended structure.
  */
+
+static void parse_waveformatex(AVIOContext *pb, AVCodecContext *c)
+{
+    ff_asf_guid subformat;
+    c->bits_per_coded_sample = avio_rl16(pb);
+    c->channel_layout        = avio_rl32(pb); /* dwChannelMask */
+
+    ff_get_guid(pb, &subformat);
+    if (!memcmp(subformat + 4,
+                (const uint8_t[]){ FF_MEDIASUBTYPE_BASE_GUID }, 12)) {
+        c->codec_tag = AV_RL32(subformat);
+        c->codec_id  = ff_wav_codec_get_id(c->codec_tag,
+                                           c->bits_per_coded_sample);
+    } else {
+        c->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids, subformat);
+        if (!c->codec_id)
+            av_log(c, AV_LOG_WARNING,
+                   "unknown subformat:"FF_PRI_GUID"\n",
+                   FF_ARG_GUID(subformat));
+    }
+}
+
 int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
 {
     int id;
@@ -708,24 +730,7 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
         size  -= 18;
         cbSize = FFMIN(size, cbSize);
         if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
-            ff_asf_guid subformat;
-            codec->bits_per_coded_sample = avio_rl16(pb);
-            codec->channel_layout        = avio_rl32(pb); /* dwChannelMask */
-
-            ff_get_guid(pb, &subformat);
-            if (!memcmp(subformat + 4,
-                        (const uint8_t[]){ FF_MEDIASUBTYPE_BASE_GUID }, 12)) {
-                codec->codec_tag = AV_RL32(subformat);
-                codec->codec_id  = ff_wav_codec_get_id(codec->codec_tag,
-                                                       codec->bits_per_coded_sample);
-            } else {
-                codec->codec_id = ff_codec_guid_get_id(ff_codec_wav_guids,
-                                                       subformat);
-                if (!codec->codec_id)
-                    av_log(codec, AV_LOG_WARNING,
-                           "unknown subformat: "FF_PRI_GUID"\n",
-                           FF_ARG_GUID(subformat));
-            }
+            parse_waveformatex(pb, codec);
             cbSize -= 22;
             size   -= 22;
         }



More information about the ffmpeg-cvslog mailing list