/*
- * AIFF/AIFF-C encoder and decoder
+ * AIFF/AIFF-C muxer and demuxer
* Copyright (c) 2006 Patrick Guimond
*
* This file is part of FFmpeg.
#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') },
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)
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)
* 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)
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);
/* 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");
aiff_read_packet,
aiff_read_close,
aiff_read_seek,
+ .codec_tag= (const AVCodecTag*[]){codec_aiff_tags, 0},
};
#endif
aiff_write_header,
aiff_write_packet,
aiff_write_trailer,
+ .codec_tag= (const AVCodecTag*[]){codec_aiff_tags, 0},
};
#endif