]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/aiff.c
Remove Fabrice's copyright from the Makefiles. They have been entirely
[ffmpeg] / libavformat / aiff.c
index c3a245e570d748cdf7fe46c55592d2bca7fc49d4..4c701fb383140be553c1a1ee66b6d720b5de5ea8 100644 (file)
  * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
+
+#include "libavutil/intfloat_readwrite.h"
 #include "avformat.h"
 #include "raw.h"
 #include "riff.h"
-#include "intfloat_readwrite.h"
 
 static const AVCodecTag codec_aiff_tags[] = {
     { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') },
@@ -36,6 +37,7 @@ static const AVCodecTag codec_aiff_tags[] = {
     { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') },
     { CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') },
     { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
+    { CODEC_ID_QDM2, MKTAG('Q','D','M','2') },
     { 0, 0 },
 };
 
@@ -129,6 +131,14 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
             codec->block_align = 34*codec->channels;
             codec->frame_size = 64;
             break;
+        case CODEC_ID_MACE3:
+            codec->block_align = 2*codec->channels;
+            codec->frame_size = 6;
+            break;
+        case CODEC_ID_MACE6:
+            codec->block_align = 1*codec->channels;
+            codec->frame_size = 6;
+            break;
         default:
             break;
         }
@@ -139,15 +149,13 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
         codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
     }
 
-    if (!codec->codec_id)
-        return AVERROR_INVALIDDATA;
-
     /* Block align needs to be computed in all cases, as the definition
      * is specific to applications -> here we use the WAVE format definition */
     if (!codec->block_align)
         codec->block_align = (codec->bits_per_sample * codec->channels) >> 3;
 
-    codec->bit_rate = codec->sample_rate * (codec->block_align << 3);
+    codec->bit_rate = (codec->frame_size ? codec->sample_rate/codec->frame_size :
+                       codec->sample_rate) * (codec->block_align << 3);
 
     /* Chunk is over */
     if (size)
@@ -333,7 +341,7 @@ static int aiff_read_header(AVFormatContext *s,
         switch (tag) {
         case MKTAG('C', 'O', 'M', 'M'):     /* Common chunk */
             /* Then for the complete header info */
-            st->nb_frames = get_aiff_header (pb, st->codec, size, version);
+            st->nb_frames = get_aiff_header(pb, st->codec, size, version);
             if (st->nb_frames < 0)
                 return st->nb_frames;
             if (offset > 0) // COMM is after SSND
@@ -343,22 +351,22 @@ static int aiff_read_header(AVFormatContext *s,
             version = get_be32(pb);
             break;
         case MKTAG('N', 'A', 'M', 'E'):     /* Sample name chunk */
-            get_meta (pb, s->title, sizeof(s->title), size);
+            get_meta(pb, s->title, sizeof(s->title), size);
             break;
         case MKTAG('A', 'U', 'T', 'H'):     /* Author chunk */
-            get_meta (pb, s->author, sizeof(s->author), size);
+            get_meta(pb, s->author, sizeof(s->author), size);
             break;
         case MKTAG('(', 'c', ')', ' '):     /* Copyright chunk */
-            get_meta (pb, s->copyright, sizeof(s->copyright), size);
+            get_meta(pb, s->copyright, sizeof(s->copyright), size);
             break;
         case MKTAG('A', 'N', 'N', 'O'):     /* Annotation chunk */
-            get_meta (pb, s->comment, sizeof(s->comment), size);
+            get_meta(pb, s->comment, sizeof(s->comment), size);
             break;
         case MKTAG('S', 'S', 'N', 'D'):     /* Sampled sound chunk */
             offset = get_be32(pb);      /* Offset of sound data */
             get_be32(pb);               /* BlockSize... don't care */
             offset += url_ftell(pb);    /* Compute absolute data offset */
-            if (st->codec->codec_id)    /* Assume COMM already parsed */
+            if (st->codec->block_align)    /* Assume COMM already parsed */
                 goto got_sound;
             if (url_is_streamed(pb)) {
                 av_log(s, AV_LOG_ERROR, "file is not seekable\n");
@@ -366,6 +374,15 @@ static int aiff_read_header(AVFormatContext *s,
             }
             url_fskip(pb, size - 8);
             break;
+        case MKTAG('w', 'a', 'v', 'e'):
+            if ((uint64_t)size > (1<<30))
+                return -1;
+            st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
+            if (!st->codec->extradata)
+                return AVERROR(ENOMEM);
+            st->codec->extradata_size = size;
+            get_buffer(pb, st->codec->extradata, size);
+            break;
         default: /* Jump */
             if (size & 1)   /* Always even aligned */
                 size++;
@@ -373,8 +390,10 @@ static int aiff_read_header(AVFormatContext *s,
         }
     }
 
-    /* End of loop and didn't get sound */
-    return AVERROR_INVALIDDATA;
+    if (!st->codec->block_align) {
+        av_log(s, AV_LOG_ERROR, "could not find COMM tag\n");
+        return -1;
+    }
 
 got_sound:
     /* Now positioned, get the sound data start and end */
@@ -423,7 +442,7 @@ static int aiff_read_seek(AVFormatContext *s,
 #ifdef CONFIG_AIFF_DEMUXER
 AVInputFormat aiff_demuxer = {
     "aiff",
-    "Audio IFF",
+    NULL_IF_CONFIG_SMALL("Audio IFF"),
     0,
     aiff_probe,
     aiff_read_header,
@@ -437,7 +456,7 @@ AVInputFormat aiff_demuxer = {
 #ifdef CONFIG_AIFF_MUXER
 AVOutputFormat aiff_muxer = {
     "aiff",
-    "Audio IFF",
+    NULL_IF_CONFIG_SMALL("Audio IFF"),
     "audio/aiff",
     "aif,aiff,afc,aifc",
     sizeof(AIFFOutputContext),