]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/riff.c
nsvdec: Remove commented-out debug cruft
[ffmpeg] / libavformat / riff.c
index 694d299ecf31190a641e9ae7421623e205a5626c..eae1f644ca2746100ebf0b1a98103724ee12de93 100644 (file)
@@ -374,6 +374,14 @@ const AVCodecTag ff_codec_wav_tags[] = {
     { AV_CODEC_ID_NONE,      0 },
 };
 
+const AVCodecGuid ff_codec_wav_guids[] = {
+    { AV_CODEC_ID_AC3,      { 0x2C, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, 0xEA } },
+    { AV_CODEC_ID_ATRAC3P,  { 0xBF, 0xAA, 0x23, 0xE9, 0x58, 0xCB, 0x71, 0x44, 0xA1, 0x19, 0xFF, 0xFA, 0x01, 0xE4, 0xCE, 0x62 } },
+    { AV_CODEC_ID_EAC3,     { 0xAF, 0x87, 0xFB, 0xA7, 0x02, 0x2D, 0xFB, 0x42, 0xA4, 0xD4, 0x05, 0xCD, 0x93, 0x84, 0x3B, 0xDD } },
+    { AV_CODEC_ID_MP2,      { 0x2B, 0x80, 0x6D, 0xE0, 0x46, 0xDB, 0xCF, 0x11, 0xB4, 0xD1, 0x00, 0x80, 0x5F, 0x6C, 0xBB, 0xEA } },
+    { AV_CODEC_ID_NONE }
+};
+
 const AVMetadataConv ff_riff_info_conv[] = {
     { "IART", "artist"     },
     { "ICMT", "comment"    },
@@ -389,6 +397,15 @@ const AVMetadataConv ff_riff_info_conv[] = {
     { 0 },
 };
 
+enum AVCodecID ff_codec_guid_get_id(const AVCodecGuid *guids, ff_asf_guid guid)
+{
+    int i;
+    for (i = 0; guids[i].id != AV_CODEC_ID_NONE; i++)
+        if (!ff_guidcmp(guids[i].guid, guid))
+            return guids[i].id;
+    return AV_CODEC_ID_NONE;
+}
+
 #if CONFIG_MUXERS
 int64_t ff_start_tag(AVIOContext *pb, const char *tag)
 {
@@ -665,13 +682,34 @@ 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;
 
     id                 = avio_rl16(pb);
     codec->codec_type  = AVMEDIA_TYPE_AUDIO;
-    codec->codec_tag   = id;
     codec->channels    = avio_rl16(pb);
     codec->sample_rate = avio_rl32(pb);
     codec->bit_rate    = avio_rl32(pb) * 8;
@@ -680,15 +718,19 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
         codec->bits_per_coded_sample = 8;
     } else
         codec->bits_per_coded_sample = avio_rl16(pb);
+    if (id == 0xFFFE) {
+        codec->codec_tag = 0;
+    } else {
+        codec->codec_tag = id;
+        codec->codec_id  = ff_wav_codec_get_id(id,
+                                               codec->bits_per_coded_sample);
+    }
     if (size >= 18) {  /* We're obviously dealing with WAVEFORMATEX */
         int cbSize = avio_rl16(pb); /* cbSize */
         size  -= 18;
         cbSize = FFMIN(size, cbSize);
         if (cbSize >= 22 && id == 0xfffe) { /* WAVEFORMATEXTENSIBLE */
-            codec->bits_per_coded_sample = avio_rl16(pb);
-            codec->channel_layout        = avio_rl32(pb); /* dwChannelMask */
-            id                           = avio_rl32(pb); /* 4 first bytes of GUID */
-            avio_skip(pb, 12); /* skip end of GUID */
+            parse_waveformatex(pb, codec);
             cbSize -= 22;
             size   -= 22;
         }
@@ -707,7 +749,6 @@ int ff_get_wav_header(AVIOContext *pb, AVCodecContext *codec, int size)
         if (size > 0)
             avio_skip(pb, size);
     }
-    codec->codec_id = ff_wav_codec_get_id(id, codec->bits_per_coded_sample);
     if (codec->codec_id == AV_CODEC_ID_AAC_LATM) {
         /* Channels and sample_rate values are those prior to applying SBR
          * and/or PS. */
@@ -785,6 +826,10 @@ int ff_read_riff_info(AVFormatContext *s, int64_t size)
         if (!chunk_code) {
             if (chunk_size)
                 avio_skip(pb, chunk_size);
+            else if (pb->eof_reached) {
+                av_log(s, AV_LOG_WARNING, "truncated file\n");
+                return AVERROR_EOF;
+            }
             continue;
         }