2006-02-02 16:21:19 +01:00
|
|
|
/*
|
2006-10-23 10:57:54 +02:00
|
|
|
* AIFF/AIFF-C muxer and demuxer
|
2006-02-02 16:21:19 +01:00
|
|
|
* Copyright (c) 2006 Patrick Guimond
|
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
2006-02-02 16:21:19 +01:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2006-10-07 17:30:46 +02:00
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
2006-02-02 16:21:19 +01:00
|
|
|
*
|
2006-10-07 17:30:46 +02:00
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
2006-02-02 16:21:19 +01:00
|
|
|
* 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
|
2006-10-07 17:30:46 +02:00
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
2006-02-02 16:21:19 +01:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
2008-05-09 13:56:36 +02:00
|
|
|
|
|
|
|
#include "libavutil/intfloat_readwrite.h"
|
2006-02-02 16:21:19 +01:00
|
|
|
#include "avformat.h"
|
2007-09-11 11:27:46 +02:00
|
|
|
#include "raw.h"
|
2006-07-12 02:09:34 +02:00
|
|
|
#include "riff.h"
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2007-01-21 02:39:17 +01:00
|
|
|
static const AVCodecTag codec_aiff_tags[] = {
|
2008-06-28 06:53:01 +02:00
|
|
|
{ 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') },
|
|
|
|
{ CODEC_ID_PCM_S32BE, MKTAG('N','O','N','E') },
|
2008-08-19 13:05:29 +02:00
|
|
|
{ CODEC_ID_PCM_F32BE, MKTAG('f','l','3','2') },
|
|
|
|
{ CODEC_ID_PCM_F64BE, MKTAG('f','l','6','4') },
|
2008-06-28 06:53:01 +02:00
|
|
|
{ CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') },
|
|
|
|
{ CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') },
|
|
|
|
{ CODEC_ID_MACE3, MKTAG('M','A','C','3') },
|
|
|
|
{ CODEC_ID_MACE6, MKTAG('M','A','C','6') },
|
|
|
|
{ CODEC_ID_GSM, MKTAG('G','S','M',' ') },
|
|
|
|
{ CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') },
|
|
|
|
{ CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') },
|
2008-02-25 11:57:22 +01:00
|
|
|
{ CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
|
2008-06-28 06:53:01 +02:00
|
|
|
{ CODEC_ID_QDM2, MKTAG('Q','D','M','2') },
|
2006-02-02 16:21:19 +01:00
|
|
|
{ 0, 0 },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define AIFF 0
|
|
|
|
#define AIFF_C_VERSION1 0xA2805140
|
|
|
|
|
2008-10-02 18:03:00 +02:00
|
|
|
static enum CodecID aiff_codec_get_id(int bps)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
|
|
|
if (bps <= 8)
|
|
|
|
return CODEC_ID_PCM_S8;
|
|
|
|
if (bps <= 16)
|
|
|
|
return CODEC_ID_PCM_S16BE;
|
|
|
|
if (bps <= 24)
|
|
|
|
return CODEC_ID_PCM_S24BE;
|
|
|
|
if (bps <= 32)
|
|
|
|
return CODEC_ID_PCM_S32BE;
|
|
|
|
|
|
|
|
/* bigger than 32 isn't allowed */
|
2008-10-02 18:03:00 +02:00
|
|
|
return CODEC_ID_NONE;
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* returns the size of the found tag */
|
|
|
|
static int get_tag(ByteIOContext *pb, uint32_t * tag)
|
|
|
|
{
|
|
|
|
int size;
|
|
|
|
|
|
|
|
if (url_feof(pb))
|
2007-07-19 17:23:32 +02:00
|
|
|
return AVERROR(EIO);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
*tag = get_le32(pb);
|
|
|
|
size = get_be32(pb);
|
|
|
|
|
|
|
|
if (size < 0)
|
|
|
|
size = 0x7fffffff;
|
|
|
|
|
|
|
|
return size;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Metadata string read */
|
2009-02-03 00:43:12 +01:00
|
|
|
static void get_meta(AVFormatContext *s, const char *key, int size)
|
2006-02-02 16:21:19 +01:00
|
|
|
{
|
2009-02-03 00:43:12 +01:00
|
|
|
uint8_t str[1024];
|
|
|
|
int res = get_buffer(s->pb, str, FFMIN(sizeof(str)-1, size));
|
2006-02-02 16:21:19 +01:00
|
|
|
if (res < 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
str[res] = 0;
|
|
|
|
if (size & 1)
|
|
|
|
size++;
|
|
|
|
size -= res;
|
2007-02-14 12:23:11 +01:00
|
|
|
if (size)
|
2009-02-03 00:43:12 +01:00
|
|
|
url_fskip(s->pb, size);
|
|
|
|
|
|
|
|
av_metadata_set(&s->metadata, key, str);
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Returns the number of sound data frames or negative on error */
|
2006-06-18 13:33:14 +02:00
|
|
|
static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
|
2006-02-02 16:21:19 +01:00
|
|
|
int size, unsigned version)
|
|
|
|
{
|
|
|
|
AVExtFloat ext;
|
|
|
|
double sample_rate;
|
|
|
|
unsigned int num_frames;
|
|
|
|
|
|
|
|
if (size & 1)
|
|
|
|
size++;
|
|
|
|
codec->codec_type = CODEC_TYPE_AUDIO;
|
|
|
|
codec->channels = get_be16(pb);
|
|
|
|
num_frames = get_be32(pb);
|
2008-09-08 16:24:59 +02:00
|
|
|
codec->bits_per_coded_sample = get_be16(pb);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */
|
|
|
|
sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */
|
|
|
|
codec->sample_rate = sample_rate;
|
|
|
|
size -= 18;
|
|
|
|
|
|
|
|
/* Got an AIFF-C? */
|
|
|
|
if (version == AIFF_C_VERSION1) {
|
|
|
|
codec->codec_tag = get_le32(pb);
|
2009-06-23 01:09:34 +02:00
|
|
|
codec->codec_id = ff_codec_get_id(codec_aiff_tags, codec->codec_tag);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2008-02-25 11:57:22 +01:00
|
|
|
switch (codec->codec_id) {
|
|
|
|
case CODEC_ID_PCM_S16BE:
|
2008-09-08 16:24:59 +02:00
|
|
|
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);
|
2008-02-25 11:57:22 +01:00
|
|
|
break;
|
|
|
|
case CODEC_ID_ADPCM_IMA_QT:
|
|
|
|
codec->block_align = 34*codec->channels;
|
2008-02-25 12:34:26 +01:00
|
|
|
codec->frame_size = 64;
|
2008-02-25 11:57:22 +01:00
|
|
|
break;
|
2008-02-25 13:59:42 +01:00
|
|
|
case CODEC_ID_MACE3:
|
2008-03-05 13:06:57 +01:00
|
|
|
codec->block_align = 2*codec->channels;
|
|
|
|
codec->frame_size = 6;
|
|
|
|
break;
|
2008-02-25 13:59:42 +01:00
|
|
|
case CODEC_ID_MACE6:
|
2008-03-05 13:06:57 +01:00
|
|
|
codec->block_align = 1*codec->channels;
|
2008-02-25 13:59:42 +01:00
|
|
|
codec->frame_size = 6;
|
|
|
|
break;
|
2008-09-05 00:35:05 +02:00
|
|
|
case CODEC_ID_GSM:
|
|
|
|
codec->block_align = 33;
|
|
|
|
codec->frame_size = 160;
|
|
|
|
break;
|
2008-02-25 11:57:22 +01:00
|
|
|
default:
|
|
|
|
break;
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
size -= 4;
|
|
|
|
} else {
|
|
|
|
/* Need the codec type */
|
2008-09-08 16:24:59 +02:00
|
|
|
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);
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Block align needs to be computed in all cases, as the definition
|
|
|
|
* is specific to applications -> here we use the WAVE format definition */
|
2008-02-25 11:57:22 +01:00
|
|
|
if (!codec->block_align)
|
2008-09-08 16:24:59 +02:00
|
|
|
codec->block_align = (codec->bits_per_coded_sample * codec->channels) >> 3;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2008-03-05 13:02:32 +01:00
|
|
|
codec->bit_rate = (codec->frame_size ? codec->sample_rate/codec->frame_size :
|
|
|
|
codec->sample_rate) * (codec->block_align << 3);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Chunk is over */
|
|
|
|
if (size)
|
|
|
|
url_fseek(pb, size, SEEK_CUR);
|
|
|
|
|
|
|
|
return num_frames;
|
|
|
|
}
|
|
|
|
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_AIFF_MUXER
|
2006-02-02 16:21:19 +01:00
|
|
|
typedef struct {
|
2008-10-03 12:16:29 +02:00
|
|
|
int64_t form;
|
|
|
|
int64_t frames;
|
|
|
|
int64_t ssnd;
|
2006-02-02 16:21:19 +01:00
|
|
|
} AIFFOutputContext;
|
|
|
|
|
|
|
|
static int aiff_write_header(AVFormatContext *s)
|
|
|
|
{
|
|
|
|
AIFFOutputContext *aiff = s->priv_data;
|
2007-11-21 08:41:00 +01:00
|
|
|
ByteIOContext *pb = s->pb;
|
2006-02-02 16:21:19 +01:00
|
|
|
AVCodecContext *enc = s->streams[0]->codec;
|
|
|
|
AVExtFloat sample_rate;
|
2007-02-14 12:01:05 +01:00
|
|
|
int aifc = 0;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* First verify if format is ok */
|
2008-02-25 13:14:15 +01:00
|
|
|
if (!enc->codec_tag)
|
2006-02-02 16:21:19 +01:00
|
|
|
return -1;
|
2007-02-14 12:01:05 +01:00
|
|
|
if (enc->codec_tag != MKTAG('N','O','N','E'))
|
|
|
|
aifc = 1;
|
|
|
|
|
2006-02-02 16:21:19 +01:00
|
|
|
/* FORM AIFF header */
|
|
|
|
put_tag(pb, "FORM");
|
|
|
|
aiff->form = url_ftell(pb);
|
|
|
|
put_be32(pb, 0); /* file length */
|
2007-02-14 12:01:05 +01:00
|
|
|
put_tag(pb, aifc ? "AIFC" : "AIFF");
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2008-02-25 13:00:31 +01:00
|
|
|
if (aifc) { // compressed audio
|
2008-09-08 16:24:59 +02:00
|
|
|
enc->bits_per_coded_sample = 16;
|
2008-02-25 13:00:31 +01:00
|
|
|
if (!enc->block_align) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "block align not set\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2007-02-14 12:18:34 +01:00
|
|
|
/* Version chunk */
|
|
|
|
put_tag(pb, "FVER");
|
|
|
|
put_be32(pb, 4);
|
|
|
|
put_be32(pb, 0xA2805140);
|
2007-02-14 12:01:05 +01:00
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Common chunk */
|
|
|
|
put_tag(pb, "COMM");
|
2007-02-14 12:01:05 +01:00
|
|
|
put_be32(pb, aifc ? 24 : 18); /* size */
|
2008-02-25 13:14:15 +01:00
|
|
|
put_be16(pb, enc->channels); /* Number of channels */
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
aiff->frames = url_ftell(pb);
|
2008-02-25 13:14:15 +01:00
|
|
|
put_be32(pb, 0); /* Number of frames */
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2008-09-08 16:24:59 +02:00
|
|
|
if (!enc->bits_per_coded_sample)
|
|
|
|
enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id);
|
|
|
|
if (!enc->bits_per_coded_sample) {
|
2006-10-11 12:15:05 +02:00
|
|
|
av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (!enc->block_align)
|
2008-09-08 16:24:59 +02:00
|
|
|
enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3;
|
2006-10-11 12:15:05 +02:00
|
|
|
|
2008-09-08 16:24:59 +02:00
|
|
|
put_be16(pb, enc->bits_per_coded_sample); /* Sample size */
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
sample_rate = av_dbl2ext((double)enc->sample_rate);
|
|
|
|
put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate));
|
|
|
|
|
2007-02-14 12:01:05 +01:00
|
|
|
if (aifc) {
|
2007-02-14 12:18:34 +01:00
|
|
|
put_le32(pb, enc->codec_tag);
|
|
|
|
put_be16(pb, 0);
|
2007-02-14 12:01:05 +01:00
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Sound data chunk */
|
|
|
|
put_tag(pb, "SSND");
|
|
|
|
aiff->ssnd = url_ftell(pb); /* Sound chunk size */
|
|
|
|
put_be32(pb, 0); /* Sound samples data size */
|
|
|
|
put_be32(pb, 0); /* Data offset */
|
|
|
|
put_be32(pb, 0); /* Block-size (block align) */
|
|
|
|
|
|
|
|
av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
|
|
|
|
|
|
|
|
/* Data is starting here */
|
|
|
|
put_flush_packet(pb);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
|
|
|
|
{
|
2007-11-21 08:41:00 +01:00
|
|
|
ByteIOContext *pb = s->pb;
|
2006-02-02 16:21:19 +01:00
|
|
|
put_buffer(pb, pkt->data, pkt->size);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int aiff_write_trailer(AVFormatContext *s)
|
|
|
|
{
|
2007-11-21 08:41:00 +01:00
|
|
|
ByteIOContext *pb = s->pb;
|
2006-02-02 16:21:19 +01:00
|
|
|
AIFFOutputContext *aiff = s->priv_data;
|
|
|
|
AVCodecContext *enc = s->streams[0]->codec;
|
|
|
|
|
|
|
|
/* Chunks sizes must be even */
|
2008-10-03 12:16:29 +02:00
|
|
|
int64_t file_size, end_size;
|
2006-02-02 16:21:19 +01:00
|
|
|
end_size = file_size = url_ftell(pb);
|
|
|
|
if (file_size & 1) {
|
|
|
|
put_byte(pb, 0);
|
|
|
|
end_size++;
|
|
|
|
}
|
|
|
|
|
2007-11-21 08:41:00 +01:00
|
|
|
if (!url_is_streamed(s->pb)) {
|
2006-02-02 16:21:19 +01:00
|
|
|
/* File length */
|
|
|
|
url_fseek(pb, aiff->form, SEEK_SET);
|
2008-02-25 13:15:26 +01:00
|
|
|
put_be32(pb, file_size - aiff->form - 4);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Number of sample frames */
|
|
|
|
url_fseek(pb, aiff->frames, SEEK_SET);
|
2008-02-25 13:15:26 +01:00
|
|
|
put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Sound Data chunk size */
|
|
|
|
url_fseek(pb, aiff->ssnd, SEEK_SET);
|
2008-02-25 13:15:26 +01:00
|
|
|
put_be32(pb, file_size - aiff->ssnd - 4);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* return to the end */
|
|
|
|
url_fseek(pb, end_size, SEEK_SET);
|
|
|
|
|
|
|
|
put_flush_packet(pb);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2008-09-03 00:45:13 +02:00
|
|
|
#endif /* CONFIG_AIFF_MUXER */
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
static int aiff_probe(AVProbeData *p)
|
|
|
|
{
|
|
|
|
/* check file header */
|
|
|
|
if (p->buf[0] == 'F' && p->buf[1] == 'O' &&
|
|
|
|
p->buf[2] == 'R' && p->buf[3] == 'M' &&
|
|
|
|
p->buf[8] == 'A' && p->buf[9] == 'I' &&
|
|
|
|
p->buf[10] == 'F' && (p->buf[11] == 'F' || p->buf[11] == 'C'))
|
|
|
|
return AVPROBE_SCORE_MAX;
|
|
|
|
else
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* aiff input */
|
|
|
|
static int aiff_read_header(AVFormatContext *s,
|
|
|
|
AVFormatParameters *ap)
|
|
|
|
{
|
2007-06-25 23:31:33 +02:00
|
|
|
int size, filesize;
|
2008-10-03 12:16:29 +02:00
|
|
|
int64_t offset = 0;
|
2006-02-02 16:21:19 +01:00
|
|
|
uint32_t tag;
|
|
|
|
unsigned version = AIFF_C_VERSION1;
|
2007-11-21 08:41:00 +01:00
|
|
|
ByteIOContext *pb = s->pb;
|
2009-04-17 20:18:29 +02:00
|
|
|
AVStream * st;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* check FORM header */
|
|
|
|
filesize = get_tag(pb, &tag);
|
|
|
|
if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
/* AIFF data type */
|
|
|
|
tag = get_le32(pb);
|
|
|
|
if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */
|
|
|
|
version = AIFF;
|
|
|
|
else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */
|
|
|
|
return AVERROR_INVALIDDATA;
|
|
|
|
|
|
|
|
filesize -= 4;
|
|
|
|
|
|
|
|
st = av_new_stream(s, 0);
|
|
|
|
if (!st)
|
2007-07-19 17:21:30 +02:00
|
|
|
return AVERROR(ENOMEM);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
while (filesize > 0) {
|
|
|
|
/* parse different chunks */
|
|
|
|
size = get_tag(pb, &tag);
|
|
|
|
if (size < 0)
|
|
|
|
return size;
|
|
|
|
|
|
|
|
filesize -= size + 8;
|
|
|
|
|
|
|
|
switch (tag) {
|
2008-02-25 13:23:27 +01:00
|
|
|
case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */
|
|
|
|
/* Then for the complete header info */
|
2008-05-16 00:14:29 +02:00
|
|
|
st->nb_frames = get_aiff_header(pb, st->codec, size, version);
|
2008-02-25 13:23:27 +01:00
|
|
|
if (st->nb_frames < 0)
|
|
|
|
return st->nb_frames;
|
|
|
|
if (offset > 0) // COMM is after SSND
|
|
|
|
goto got_sound;
|
|
|
|
break;
|
|
|
|
case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */
|
|
|
|
version = get_be32(pb);
|
|
|
|
break;
|
|
|
|
case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "title" , size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "author" , size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "copyright", size);
|
2008-02-25 13:23:27 +01:00
|
|
|
break;
|
|
|
|
case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
|
2009-02-03 00:43:12 +01:00
|
|
|
get_meta(s, "comment" , size);
|
2008-02-25 13:23:27 +01:00
|
|
|
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 */
|
2008-05-16 00:47:40 +02:00
|
|
|
if (st->codec->block_align) /* Assume COMM already parsed */
|
2008-02-25 13:23:27 +01:00
|
|
|
goto got_sound;
|
|
|
|
if (url_is_streamed(pb)) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "file is not seekable\n");
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
url_fskip(pb, size - 8);
|
|
|
|
break;
|
2008-02-25 13:29:34 +01:00
|
|
|
case MKTAG('w', 'a', 'v', 'e'):
|
2008-02-25 13:38:37 +01:00
|
|
|
if ((uint64_t)size > (1<<30))
|
|
|
|
return -1;
|
2008-02-25 13:29:34 +01:00
|
|
|
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;
|
2008-02-25 13:23:27 +01:00
|
|
|
default: /* Jump */
|
|
|
|
if (size & 1) /* Always even aligned */
|
|
|
|
size++;
|
|
|
|
url_fskip (pb, size);
|
2006-02-02 16:21:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-05-16 00:47:40 +02:00
|
|
|
if (!st->codec->block_align) {
|
|
|
|
av_log(s, AV_LOG_ERROR, "could not find COMM tag\n");
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
got_sound:
|
|
|
|
/* Now positioned, get the sound data start and end */
|
|
|
|
if (st->nb_frames)
|
|
|
|
s->file_size = st->nb_frames * st->codec->block_align;
|
|
|
|
|
|
|
|
av_set_pts_info(st, 64, 1, st->codec->sample_rate);
|
|
|
|
st->start_time = 0;
|
2008-02-25 12:34:26 +01:00
|
|
|
st->duration = st->codec->frame_size ?
|
|
|
|
st->nb_frames * st->codec->frame_size : st->nb_frames;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Position the stream at the first block */
|
2007-06-25 23:31:33 +02:00
|
|
|
url_fseek(pb, offset, SEEK_SET);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define MAX_SIZE 4096
|
|
|
|
|
|
|
|
static int aiff_read_packet(AVFormatContext *s,
|
|
|
|
AVPacket *pkt)
|
|
|
|
{
|
2006-05-15 14:38:33 +02:00
|
|
|
AVStream *st = s->streams[0];
|
|
|
|
int res;
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* End of stream may be reached */
|
2007-11-21 08:41:00 +01:00
|
|
|
if (url_feof(s->pb))
|
2007-07-19 17:23:32 +02:00
|
|
|
return AVERROR(EIO);
|
2006-02-02 16:21:19 +01:00
|
|
|
|
|
|
|
/* Now for that packet */
|
2007-11-21 08:41:00 +01:00
|
|
|
res = av_get_packet(s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->block_align);
|
2006-02-02 16:21:19 +01:00
|
|
|
if (res < 0)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
/* Only one stream in an AIFF file */
|
|
|
|
pkt->stream_index = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_AIFF_DEMUXER
|
2006-07-10 23:14:37 +02:00
|
|
|
AVInputFormat aiff_demuxer = {
|
2006-02-02 16:21:19 +01:00
|
|
|
"aiff",
|
2008-06-03 18:20:54 +02:00
|
|
|
NULL_IF_CONFIG_SMALL("Audio IFF"),
|
2006-02-02 16:21:19 +01:00
|
|
|
0,
|
|
|
|
aiff_probe,
|
|
|
|
aiff_read_header,
|
|
|
|
aiff_read_packet,
|
2008-02-25 13:24:30 +01:00
|
|
|
NULL,
|
2008-06-06 23:53:03 +02:00
|
|
|
pcm_read_seek,
|
2008-08-24 18:51:50 +02:00
|
|
|
.codec_tag= (const AVCodecTag* const []){codec_aiff_tags, 0},
|
2006-02-02 16:21:19 +01:00
|
|
|
};
|
2006-07-10 23:14:37 +02:00
|
|
|
#endif
|
2006-02-02 16:21:19 +01:00
|
|
|
|
2009-01-14 00:44:16 +01:00
|
|
|
#if CONFIG_AIFF_MUXER
|
2006-07-10 23:14:37 +02:00
|
|
|
AVOutputFormat aiff_muxer = {
|
2006-02-02 16:21:19 +01:00
|
|
|
"aiff",
|
2008-06-03 18:20:54 +02:00
|
|
|
NULL_IF_CONFIG_SMALL("Audio IFF"),
|
2006-02-02 16:21:19 +01:00
|
|
|
"audio/aiff",
|
|
|
|
"aif,aiff,afc,aifc",
|
|
|
|
sizeof(AIFFOutputContext),
|
|
|
|
CODEC_ID_PCM_S16BE,
|
|
|
|
CODEC_ID_NONE,
|
|
|
|
aiff_write_header,
|
|
|
|
aiff_write_packet,
|
|
|
|
aiff_write_trailer,
|
2008-08-24 18:51:50 +02:00
|
|
|
.codec_tag= (const AVCodecTag* const []){codec_aiff_tags, 0},
|
2006-02-02 16:21:19 +01:00
|
|
|
};
|
2006-07-10 23:14:37 +02:00
|
|
|
#endif
|