]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/aiffdec.c
mp3dec: fix reading the Xing tag
[ffmpeg] / libavformat / aiffdec.c
index 11bbcac77591cdc87ce67ce605fbe7d563e56e5a..6243bcb30fade8f06d2a54bd5802bfd54e42c4c0 100644 (file)
@@ -34,19 +34,19 @@ typedef struct {
     int block_duration;
 } AIFFInputContext;
 
-static enum CodecID aiff_codec_get_id(int bps)
+static enum AVCodecID aiff_codec_get_id(int bps)
 {
     if (bps <= 8)
-        return CODEC_ID_PCM_S8;
+        return AV_CODEC_ID_PCM_S8;
     if (bps <= 16)
-        return CODEC_ID_PCM_S16BE;
+        return AV_CODEC_ID_PCM_S16BE;
     if (bps <= 24)
-        return CODEC_ID_PCM_S24BE;
+        return AV_CODEC_ID_PCM_S24BE;
     if (bps <= 32)
-        return CODEC_ID_PCM_S32BE;
+        return AV_CODEC_ID_PCM_S32BE;
 
     /* bigger than 32 isn't allowed  */
-    return CODEC_ID_NONE;
+    return AV_CODEC_ID_NONE;
 }
 
 /* returns the size of the found tag */
@@ -110,46 +110,47 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
     codec->sample_rate = sample_rate;
     size -= 18;
 
-    /* Got an AIFF-C? */
+    /* get codec id for AIFF-C */
     if (version == AIFF_C_VERSION1) {
         codec->codec_tag = avio_rl32(pb);
         codec->codec_id  = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag);
+        size -= 4;
+    }
 
+    if (version != AIFF_C_VERSION1 || codec->codec_id == AV_CODEC_ID_PCM_S16BE) {
+        codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
+        codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
+        aiff->block_duration = 1;
+    } else {
         switch (codec->codec_id) {
-        case CODEC_ID_PCM_S16BE:
-            codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
-            codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
+        case AV_CODEC_ID_PCM_F32BE:
+        case AV_CODEC_ID_PCM_F64BE:
+        case AV_CODEC_ID_PCM_S16LE:
+        case AV_CODEC_ID_PCM_ALAW:
+        case AV_CODEC_ID_PCM_MULAW:
             aiff->block_duration = 1;
             break;
-        case CODEC_ID_ADPCM_IMA_QT:
+        case AV_CODEC_ID_ADPCM_IMA_QT:
             codec->block_align = 34*codec->channels;
-            aiff->block_duration = 64;
             break;
-        case CODEC_ID_MACE3:
+        case AV_CODEC_ID_MACE3:
             codec->block_align = 2*codec->channels;
-            aiff->block_duration = 6;
             break;
-        case CODEC_ID_MACE6:
+        case AV_CODEC_ID_MACE6:
             codec->block_align = 1*codec->channels;
-            aiff->block_duration = 6;
             break;
-        case CODEC_ID_GSM:
+        case AV_CODEC_ID_GSM:
             codec->block_align = 33;
-            aiff->block_duration = 160;
             break;
-        case CODEC_ID_QCELP:
+        case AV_CODEC_ID_QCELP:
             codec->block_align = 35;
-            aiff->block_duration = 160;
             break;
         default:
             break;
         }
-        size -= 4;
-    } else {
-        /* Need the codec type */
-        codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
-        codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
-        aiff->block_duration = 1;
+        if (codec->block_align > 0)
+            aiff->block_duration = av_get_audio_frame_duration(codec,
+                                                               codec->block_align);
     }
 
     /* Block align needs to be computed in all cases, as the definition
@@ -157,8 +158,10 @@ static unsigned int get_aiff_header(AVFormatContext *s, int size,
     if (!codec->block_align)
         codec->block_align = (codec->bits_per_coded_sample * codec->channels) >> 3;
 
-    codec->bit_rate = codec->sample_rate * (codec->block_align << 3) /
-                      aiff->block_duration;
+    if (aiff->block_duration) {
+        codec->bit_rate = codec->sample_rate * (codec->block_align << 3) /
+                          aiff->block_duration;
+    }
 
     /* Chunk is over */
     if (size)
@@ -325,5 +328,5 @@ AVInputFormat ff_aiff_demuxer = {
     .read_header    = aiff_read_header,
     .read_packet    = aiff_read_packet,
     .read_seek      = ff_pcm_read_seek,
-    .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0},
+    .codec_tag      = (const AVCodecTag* const []){ ff_codec_aiff_tags, 0 },
 };