]> git.sesse.net Git - ffmpeg/blobdiff - libavformat/aiff.c
remove now useless codec_tag setting code in muxers
[ffmpeg] / libavformat / aiff.c
index 0e7152ca706f0ae468d6b1366a3531cc0e0eeeb2..10eb1d1f4b33ad6e9aae206767e90c48f5af1cf1 100644 (file)
@@ -1,26 +1,29 @@
 /*
- * AIFF/AIFF-C encoder and decoder
+ * AIFF/AIFF-C muxer and demuxer
  * Copyright (c) 2006  Patrick Guimond
  *
- * This library is free software; you can redistribute it and/or
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
+ * version 2.1 of the License, or (at your option) any later version.
  *
- * This library is distributed in the hope that it will be useful,
+ * FFmpeg is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
+ * License along with FFmpeg; if not, write to the Free Software
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 #include "avformat.h"
-#include "avi.h"
+#include "allformats.h"
+#include "riff.h"
 #include "intfloat_readwrite.h"
 
-const CodecTag codec_aiff_tags[] = {
+static const AVCodecTag codec_aiff_tags[] = {
     { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') },
     { CODEC_ID_PCM_S8, MKTAG('N','O','N','E') },
     { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') },
@@ -92,23 +95,6 @@ static void get_meta(ByteIOContext *pb, char * str, int strsize, int size)
         url_fskip(pb, size);
 }
 
-/* Returns the number of bits per second */
-static int fix_bps(int codec_id)
-{
-    switch (codec_id) {
-        case CODEC_ID_PCM_S8:
-                return 8;
-        case CODEC_ID_PCM_S16BE:
-                return 16;
-        case CODEC_ID_PCM_S24BE:
-                return 24;
-        case CODEC_ID_PCM_S32BE:
-                return 32;
-    }
-
-    return -1;
-}
-
 /* Returns the number of sound data frames or negative on error */
 static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
                              int size, unsigned version)
@@ -138,14 +124,14 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
 
         if (codec->codec_id == CODEC_ID_PCM_S16BE) {
             codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
-            codec->bits_per_sample = fix_bps(codec->codec_id);
+            codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
         }
 
         size -= 4;
     } else {
         /* Need the codec type */
         codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
-        codec->bits_per_sample = fix_bps(codec->codec_id);
+        codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
     }
 
     if (!codec->codec_id)
@@ -155,7 +141,7 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
      * is specific to applications -> here we use the WAVE format definition */
     codec->block_align = (codec->bits_per_sample * codec->channels) >> 3;
 
-    codec->bit_rate = codec->sample_rate * codec->block_align;
+    codec->bit_rate = codec->sample_rate * (codec->block_align << 3);
 
     /* Chunk is over */
     if (size)
@@ -177,17 +163,13 @@ static int aiff_write_header(AVFormatContext *s)
     ByteIOContext *pb = &s->pb;
     AVCodecContext *enc = s->streams[0]->codec;
     AVExtFloat sample_rate;
-    int coder_len;
 
     /* First verify if format is ok */
-    enc->codec_tag = codec_get_tag(codec_aiff_tags, enc->codec_id);
     if (!enc->codec_tag) {
         av_free(aiff);
         return -1;
     }
 
-    coder_len = strlen(enc->codec->name);
-
     /* FORM AIFF header */
     put_tag(pb, "FORM");
     aiff->form = url_ftell(pb);
@@ -201,31 +183,28 @@ static int aiff_write_header(AVFormatContext *s)
 
     /* Common chunk */
     put_tag(pb, "COMM");
-    if (coder_len & 1)                  /* Common chunk is of var size */
-        put_be32(pb, 23+coder_len);
-    else
-        put_be32(pb, 24+coder_len);
+    put_be32(pb, 24); /* size */
     put_be16(pb, enc->channels);        /* Number of channels */
 
     aiff->frames = url_ftell(pb);
     put_be32(pb, 0);                    /* Number of frames */
 
     if (!enc->bits_per_sample)
-        enc->bits_per_sample = (enc->block_align<<3) / enc->channels;
+        enc->bits_per_sample = av_get_bits_per_sample(enc->codec_id);
+    if (!enc->bits_per_sample) {
+        av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
+        return -1;
+    }
+    if (!enc->block_align)
+        enc->block_align = (enc->bits_per_sample * enc->channels) >> 3;
+
     put_be16(pb, enc->bits_per_sample); /* Sample size */
 
     sample_rate = av_dbl2ext((double)enc->sample_rate);
     put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate));
 
     put_le32(pb, enc->codec_tag);
-    if (coder_len & 1) {
-        put_byte(pb, coder_len);
-        put_buffer(pb, (const uint8_t*)enc->codec->name, coder_len);
-    } else {
-        put_byte(pb, coder_len+1);
-        put_buffer(pb, (const uint8_t*)enc->codec->name, coder_len);
-        put_byte(pb, 0);
-    }
+    put_be16(pb, 0);
 
     /* Sound data chunk */
     put_tag(pb, "SSND");
@@ -427,8 +406,8 @@ static int aiff_read_seek(AVFormatContext *s,
     return pcm_read_seek(s, stream_index, timestamp, flags);
 }
 
-
-static AVInputFormat aiff_iformat = {
+#ifdef CONFIG_AIFF_DEMUXER
+AVInputFormat aiff_demuxer = {
     "aiff",
     "Audio IFF",
     0,
@@ -437,10 +416,12 @@ static AVInputFormat aiff_iformat = {
     aiff_read_packet,
     aiff_read_close,
     aiff_read_seek,
+    .codec_tag= (const AVCodecTag*[]){codec_aiff_tags, 0},
 };
+#endif
 
-#ifdef CONFIG_MUXERS
-static AVOutputFormat aiff_oformat = {
+#ifdef CONFIG_AIFF_MUXER
+AVOutputFormat aiff_muxer = {
     "aiff",
     "Audio IFF",
     "audio/aiff",
@@ -451,15 +432,6 @@ static AVOutputFormat aiff_oformat = {
     aiff_write_header,
     aiff_write_packet,
     aiff_write_trailer,
+    .codec_tag= (const AVCodecTag*[]){codec_aiff_tags, 0},
 };
-#endif //CONFIG_MUXERS
-
-int ff_aiff_init(void)
-{
-    av_register_input_format(&aiff_iformat);
-#ifdef CONFIG_MUXERS
-    av_register_output_format(&aiff_oformat);
-#endif //CONFIG_MUXERS
-    return 0;
-}
-
+#endif