annotate aiff.c @ 5279:0a917464c1dc libavformat

Do not read data past the end of the SSND chunk in the AIFF demuxer. Fixes Issue 1455.
author jbr
date Tue, 13 Oct 2009 00:19:34 +0000
parents 6a23d76cc72c
children 63c52dca959b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
1 /*
1415
3b00fb8ef8e4 replace coder/decoder file description in libavformat by muxer/demuxer
aurel
parents: 1377
diff changeset
2 * AIFF/AIFF-C muxer and demuxer
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
3 * Copyright (c) 2006 Patrick Guimond
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
15 * Lesser General Public License for more details.
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
16 *
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1172
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
20 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3111
diff changeset
21
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3111
diff changeset
22 #include "libavutil/intfloat_readwrite.h"
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
23 #include "avformat.h"
2545
213268d7594e move unrelated functions declarations out of allformats.h
aurel
parents: 2274
diff changeset
24 #include "raw.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1170
diff changeset
25 #include "riff.h"
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
26
1677
2a85c82b8538 add codec_id <-> codec_tag tables to AVIn/OutputFormat
michael
parents: 1481
diff changeset
27 static const AVCodecTag codec_aiff_tags[] = {
3529
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
28 { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
29 { CODEC_ID_PCM_S8, MKTAG('N','O','N','E') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
30 { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
31 { CODEC_ID_PCM_S32BE, MKTAG('N','O','N','E') },
3739
d7fa8d9effe5 Make AIFF demuxer handle F32BE and F64BE PCM audio.
pross
parents: 3530
diff changeset
32 { CODEC_ID_PCM_F32BE, MKTAG('f','l','3','2') },
d7fa8d9effe5 Make AIFF demuxer handle F32BE and F64BE PCM audio.
pross
parents: 3530
diff changeset
33 { CODEC_ID_PCM_F64BE, MKTAG('f','l','6','4') },
3529
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
34 { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
35 { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
36 { CODEC_ID_MACE3, MKTAG('M','A','C','3') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
37 { CODEC_ID_MACE6, MKTAG('M','A','C','6') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
38 { CODEC_ID_GSM, MKTAG('G','S','M',' ') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
39 { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') },
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
40 { CODEC_ID_PCM_S16LE, MKTAG('s','o','w','t') },
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
41 { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
3529
579f6524e344 cosmetics, align vertically
bcoudurier
parents: 3435
diff changeset
42 { CODEC_ID_QDM2, MKTAG('Q','D','M','2') },
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
43 { 0, 0 },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
44 };
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
45
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
46 #define AIFF 0
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
47 #define AIFF_C_VERSION1 0xA2805140
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
48
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
49 typedef struct {
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
50 int64_t data_end;
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
51 } AIFFInputContext;
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
52
3967
4fd67f05bad9 Use enum typers instead of int.
benoit
parents: 3908
diff changeset
53 static enum CodecID aiff_codec_get_id(int bps)
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
54 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
55 if (bps <= 8)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
56 return CODEC_ID_PCM_S8;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
57 if (bps <= 16)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
58 return CODEC_ID_PCM_S16BE;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
59 if (bps <= 24)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
60 return CODEC_ID_PCM_S24BE;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
61 if (bps <= 32)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
62 return CODEC_ID_PCM_S32BE;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
63
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
64 /* bigger than 32 isn't allowed */
3967
4fd67f05bad9 Use enum typers instead of int.
benoit
parents: 3908
diff changeset
65 return CODEC_ID_NONE;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
66 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
67
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
68 /* returns the size of the found tag */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
69 static int get_tag(ByteIOContext *pb, uint32_t * tag)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
70 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
71 int size;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
72
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
73 if (url_feof(pb))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
74 return AVERROR(EIO);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
75
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
76 *tag = get_le32(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
77 size = get_be32(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
78
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
79 if (size < 0)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
80 size = 0x7fffffff;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
81
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
82 return size;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
83 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
84
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
85 /* Metadata string read */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
86 static void get_meta(AVFormatContext *s, const char *key, int size)
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
87 {
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
88 uint8_t str[1024];
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
89 int res = get_buffer(s->pb, str, FFMIN(sizeof(str)-1, size));
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
90 if (res < 0)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
91 return;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
92
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
93 str[res] = 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
94 if (size & 1)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
95 size++;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
96 size -= res;
1792
bcoudurier
parents: 1791
diff changeset
97 if (size)
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
98 url_fskip(s->pb, size);
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
99
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
100 av_metadata_set(&s->metadata, key, str);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
101 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
102
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
103 /* Returns the number of sound data frames or negative on error */
1124
d3aff2c607f9 Add const to (mostly) char* and make some functions static, which aren't used
diego
parents: 1123
diff changeset
104 static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
105 int size, unsigned version)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
106 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
107 AVExtFloat ext;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
108 double sample_rate;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
109 unsigned int num_frames;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
110
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
111 if (size & 1)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
112 size++;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
113 codec->codec_type = CODEC_TYPE_AUDIO;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
114 codec->channels = get_be16(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
115 num_frames = get_be32(pb);
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
116 codec->bits_per_coded_sample = get_be16(pb);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
117
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
118 get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
119 sample_rate = av_ext2dbl(ext); /* 80 bits BE IEEE extended float */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
120 codec->sample_rate = sample_rate;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
121 size -= 18;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
122
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
123 /* Got an AIFF-C? */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
124 if (version == AIFF_C_VERSION1) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
125 codec->codec_tag = get_le32(pb);
5058
33a244b7ca65 Add ff_ prefixes to exported symbols in libavformat/riff.h.
diego
parents: 4889
diff changeset
126 codec->codec_id = ff_codec_get_id(codec_aiff_tags, codec->codec_tag);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
127
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
128 switch (codec->codec_id) {
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
129 case CODEC_ID_PCM_S16BE:
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
130 codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
131 codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
132 break;
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
133 case CODEC_ID_ADPCM_IMA_QT:
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
134 codec->block_align = 34*codec->channels;
3067
2dc78258f848 fix duration for ima4
bcoudurier
parents: 3066
diff changeset
135 codec->frame_size = 64;
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
136 break;
3079
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
137 case CODEC_ID_MACE3:
3111
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
138 codec->block_align = 2*codec->channels;
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
139 codec->frame_size = 6;
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
140 break;
3079
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
141 case CODEC_ID_MACE6:
3111
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
142 codec->block_align = 1*codec->channels;
3079
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
143 codec->frame_size = 6;
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
144 break;
3891
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
145 case CODEC_ID_GSM:
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
146 codec->block_align = 33;
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
147 codec->frame_size = 160;
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
148 break;
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
149 default:
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
150 break;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
151 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
152 size -= 4;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
153 } else {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
154 /* Need the codec type */
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
155 codec->codec_id = aiff_codec_get_id(codec->bits_per_coded_sample);
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
156 codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
157 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
158
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
159 /* Block align needs to be computed in all cases, as the definition
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
160 * is specific to applications -> here we use the WAVE format definition */
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
161 if (!codec->block_align)
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
162 codec->block_align = (codec->bits_per_coded_sample * codec->channels) >> 3;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
163
3110
3dade22abed6 correctly compute bit rate for compressed audio, should fix seeking in aiff
bcoudurier
parents: 3079
diff changeset
164 codec->bit_rate = (codec->frame_size ? codec->sample_rate/codec->frame_size :
3dade22abed6 correctly compute bit rate for compressed audio, should fix seeking in aiff
bcoudurier
parents: 3079
diff changeset
165 codec->sample_rate) * (codec->block_align << 3);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
166
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
167 /* Chunk is over */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
168 if (size)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
169 url_fseek(pb, size, SEEK_CUR);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
170
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
171 return num_frames;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
172 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
173
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 3973
diff changeset
174 #if CONFIG_AIFF_MUXER
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
175 typedef struct {
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3967
diff changeset
176 int64_t form;
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3967
diff changeset
177 int64_t frames;
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3967
diff changeset
178 int64_t ssnd;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
179 } AIFFOutputContext;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
180
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
181 static int aiff_write_header(AVFormatContext *s)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
182 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
183 AIFFOutputContext *aiff = s->priv_data;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
184 ByteIOContext *pb = s->pb;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
185 AVCodecContext *enc = s->streams[0]->codec;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
186 AVExtFloat sample_rate;
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
187 int aifc = 0;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
188
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
189 /* First verify if format is ok */
3070
f4d4687e5b1f cosmetics
bcoudurier
parents: 3069
diff changeset
190 if (!enc->codec_tag)
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
191 return -1;
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
192 if (enc->codec_tag != MKTAG('N','O','N','E'))
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
193 aifc = 1;
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
194
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
195 /* FORM AIFF header */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
196 put_tag(pb, "FORM");
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
197 aiff->form = url_ftell(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
198 put_be32(pb, 0); /* file length */
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
199 put_tag(pb, aifc ? "AIFC" : "AIFF");
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
200
3068
9cc9ff5aff9c set bps to uncompressed original sound data for compressed audio
bcoudurier
parents: 3067
diff changeset
201 if (aifc) { // compressed audio
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
202 enc->bits_per_coded_sample = 16;
3068
9cc9ff5aff9c set bps to uncompressed original sound data for compressed audio
bcoudurier
parents: 3067
diff changeset
203 if (!enc->block_align) {
9cc9ff5aff9c set bps to uncompressed original sound data for compressed audio
bcoudurier
parents: 3067
diff changeset
204 av_log(s, AV_LOG_ERROR, "block align not set\n");
9cc9ff5aff9c set bps to uncompressed original sound data for compressed audio
bcoudurier
parents: 3067
diff changeset
205 return -1;
9cc9ff5aff9c set bps to uncompressed original sound data for compressed audio
bcoudurier
parents: 3067
diff changeset
206 }
1791
0523fb44aa72 indentation
bcoudurier
parents: 1790
diff changeset
207 /* Version chunk */
0523fb44aa72 indentation
bcoudurier
parents: 1790
diff changeset
208 put_tag(pb, "FVER");
0523fb44aa72 indentation
bcoudurier
parents: 1790
diff changeset
209 put_be32(pb, 4);
0523fb44aa72 indentation
bcoudurier
parents: 1790
diff changeset
210 put_be32(pb, 0xA2805140);
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
211 }
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
212
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
213 /* Common chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
214 put_tag(pb, "COMM");
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
215 put_be32(pb, aifc ? 24 : 18); /* size */
3070
f4d4687e5b1f cosmetics
bcoudurier
parents: 3069
diff changeset
216 put_be16(pb, enc->channels); /* Number of channels */
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
217
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
218 aiff->frames = url_ftell(pb);
3070
f4d4687e5b1f cosmetics
bcoudurier
parents: 3069
diff changeset
219 put_be32(pb, 0); /* Number of frames */
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
220
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
221 if (!enc->bits_per_coded_sample)
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
222 enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id);
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
223 if (!enc->bits_per_coded_sample) {
1375
c42cb95fa0d4 use av_get_bits_per_sample, compute block align if not set
bcoudurier
parents: 1374
diff changeset
224 av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
c42cb95fa0d4 use av_get_bits_per_sample, compute block align if not set
bcoudurier
parents: 1374
diff changeset
225 return -1;
c42cb95fa0d4 use av_get_bits_per_sample, compute block align if not set
bcoudurier
parents: 1374
diff changeset
226 }
c42cb95fa0d4 use av_get_bits_per_sample, compute block align if not set
bcoudurier
parents: 1374
diff changeset
227 if (!enc->block_align)
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
228 enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3;
1375
c42cb95fa0d4 use av_get_bits_per_sample, compute block align if not set
bcoudurier
parents: 1374
diff changeset
229
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
230 put_be16(pb, enc->bits_per_coded_sample); /* Sample size */
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
231
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
232 sample_rate = av_dbl2ext((double)enc->sample_rate);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
233 put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate));
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
234
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
235 if (aifc) {
1791
0523fb44aa72 indentation
bcoudurier
parents: 1790
diff changeset
236 put_le32(pb, enc->codec_tag);
0523fb44aa72 indentation
bcoudurier
parents: 1790
diff changeset
237 put_be16(pb, 0);
1790
d30211065a35 use aiff when we can, some players only support aiff
bcoudurier
parents: 1684
diff changeset
238 }
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
239
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
240 /* Sound data chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
241 put_tag(pb, "SSND");
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
242 aiff->ssnd = url_ftell(pb); /* Sound chunk size */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
243 put_be32(pb, 0); /* Sound samples data size */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
244 put_be32(pb, 0); /* Data offset */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
245 put_be32(pb, 0); /* Block-size (block align) */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
246
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
247 av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
248
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
249 /* Data is starting here */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
250 put_flush_packet(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
251
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
252 return 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
253 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
254
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
255 static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
256 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
257 ByteIOContext *pb = s->pb;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
258 put_buffer(pb, pkt->data, pkt->size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
259 return 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
260 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
261
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
262 static int aiff_write_trailer(AVFormatContext *s)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
263 {
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
264 ByteIOContext *pb = s->pb;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
265 AIFFOutputContext *aiff = s->priv_data;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
266 AVCodecContext *enc = s->streams[0]->codec;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
267
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
268 /* Chunks sizes must be even */
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3967
diff changeset
269 int64_t file_size, end_size;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
270 end_size = file_size = url_ftell(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
271 if (file_size & 1) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
272 put_byte(pb, 0);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
273 end_size++;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
274 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
275
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
276 if (!url_is_streamed(s->pb)) {
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
277 /* File length */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
278 url_fseek(pb, aiff->form, SEEK_SET);
3071
c4121744e2a7 remove useless casts
bcoudurier
parents: 3070
diff changeset
279 put_be32(pb, file_size - aiff->form - 4);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
280
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
281 /* Number of sample frames */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
282 url_fseek(pb, aiff->frames, SEEK_SET);
3071
c4121744e2a7 remove useless casts
bcoudurier
parents: 3070
diff changeset
283 put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
284
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
285 /* Sound Data chunk size */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
286 url_fseek(pb, aiff->ssnd, SEEK_SET);
3071
c4121744e2a7 remove useless casts
bcoudurier
parents: 3070
diff changeset
287 put_be32(pb, file_size - aiff->ssnd - 4);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
288
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
289 /* return to the end */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
290 url_fseek(pb, end_size, SEEK_SET);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
291
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
292 put_flush_packet(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
293 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
294
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
295 return 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
296 }
3871
e6aeb2733e34 Replace generic CONFIG_MUXERS preprocessor conditionals by more specific
diego
parents: 3766
diff changeset
297 #endif /* CONFIG_AIFF_MUXER */
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
298
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
299 static int aiff_probe(AVProbeData *p)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
300 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
301 /* check file header */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
302 if (p->buf[0] == 'F' && p->buf[1] == 'O' &&
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
303 p->buf[2] == 'R' && p->buf[3] == 'M' &&
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
304 p->buf[8] == 'A' && p->buf[9] == 'I' &&
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
305 p->buf[10] == 'F' && (p->buf[11] == 'F' || p->buf[11] == 'C'))
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
306 return AVPROBE_SCORE_MAX;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
307 else
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
308 return 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
309 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
310
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
311 /* aiff input */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
312 static int aiff_read_header(AVFormatContext *s,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
313 AVFormatParameters *ap)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
314 {
2206
c049274b7bd4 support files with COMM chunk after SSND, fix invalid_nocommon.aiff which is spec compliant
bcoudurier
parents: 2060
diff changeset
315 int size, filesize;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3967
diff changeset
316 int64_t offset = 0;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
317 uint32_t tag;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
318 unsigned version = AIFF_C_VERSION1;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
319 ByteIOContext *pb = s->pb;
4889
848722752aa5 Remove useless init from aiff_read_header() found by CSA.
michael
parents: 4364
diff changeset
320 AVStream * st;
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
321 AIFFInputContext *aiff = s->priv_data;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
322
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
323 /* check FORM header */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
324 filesize = get_tag(pb, &tag);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
325 if (filesize < 0 || tag != MKTAG('F', 'O', 'R', 'M'))
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
326 return AVERROR_INVALIDDATA;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
327
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
328 /* AIFF data type */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
329 tag = get_le32(pb);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
330 if (tag == MKTAG('A', 'I', 'F', 'F')) /* Got an AIFF file */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
331 version = AIFF;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
332 else if (tag != MKTAG('A', 'I', 'F', 'C')) /* An AIFF-C file then */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
333 return AVERROR_INVALIDDATA;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
334
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
335 filesize -= 4;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
336
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
337 st = av_new_stream(s, 0);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
338 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2209
diff changeset
339 return AVERROR(ENOMEM);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
340
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
341 while (filesize > 0) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
342 /* parse different chunks */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
343 size = get_tag(pb, &tag);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
344 if (size < 0)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
345 return size;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
346
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
347 filesize -= size + 8;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
348
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
349 switch (tag) {
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
350 case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
351 /* Then for the complete header info */
3295
4616ba855d62 cosmetics, remove space before opening parenthesis
bcoudurier
parents: 3286
diff changeset
352 st->nb_frames = get_aiff_header(pb, st->codec, size, version);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
353 if (st->nb_frames < 0)
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
354 return st->nb_frames;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
355 if (offset > 0) // COMM is after SSND
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
356 goto got_sound;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
357 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
358 case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
359 version = get_be32(pb);
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
360 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
361 case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
362 get_meta(s, "title" , size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
363 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
364 case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
365 get_meta(s, "author" , size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
366 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
367 case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
368 get_meta(s, "copyright", size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
369 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
370 case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
371 get_meta(s, "comment" , size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
372 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
373 case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
374 aiff->data_end = url_ftell(pb) + size;
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
375 offset = get_be32(pb); /* Offset of sound data */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
376 get_be32(pb); /* BlockSize... don't care */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
377 offset += url_ftell(pb); /* Compute absolute data offset */
3297
df2df4c07d12 try to demux even if codec is not recognized, should demux M1F1-float32C-AFsp.aif and fix #454
bcoudurier
parents: 3296
diff changeset
378 if (st->codec->block_align) /* Assume COMM already parsed */
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
379 goto got_sound;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
380 if (url_is_streamed(pb)) {
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
381 av_log(s, AV_LOG_ERROR, "file is not seekable\n");
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
382 return -1;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
383 }
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
384 url_fskip(pb, size - 8);
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
385 break;
3074
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
386 case MKTAG('w', 'a', 'v', 'e'):
3075
b273d958cf52 10l, protect malloc overflow
bcoudurier
parents: 3074
diff changeset
387 if ((uint64_t)size > (1<<30))
b273d958cf52 10l, protect malloc overflow
bcoudurier
parents: 3074
diff changeset
388 return -1;
3074
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
389 st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
390 if (!st->codec->extradata)
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
391 return AVERROR(ENOMEM);
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
392 st->codec->extradata_size = size;
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
393 get_buffer(pb, st->codec->extradata, size);
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
394 break;
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
395 default: /* Jump */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
396 if (size & 1) /* Always even aligned */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
397 size++;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
398 url_fskip (pb, size);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
399 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
400 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
401
3297
df2df4c07d12 try to demux even if codec is not recognized, should demux M1F1-float32C-AFsp.aif and fix #454
bcoudurier
parents: 3296
diff changeset
402 if (!st->codec->block_align) {
df2df4c07d12 try to demux even if codec is not recognized, should demux M1F1-float32C-AFsp.aif and fix #454
bcoudurier
parents: 3296
diff changeset
403 av_log(s, AV_LOG_ERROR, "could not find COMM tag\n");
df2df4c07d12 try to demux even if codec is not recognized, should demux M1F1-float32C-AFsp.aif and fix #454
bcoudurier
parents: 3296
diff changeset
404 return -1;
df2df4c07d12 try to demux even if codec is not recognized, should demux M1F1-float32C-AFsp.aif and fix #454
bcoudurier
parents: 3296
diff changeset
405 }
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
406
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
407 got_sound:
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
408 /* Now positioned, get the sound data start and end */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
409 if (st->nb_frames)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
410 s->file_size = st->nb_frames * st->codec->block_align;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
411
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
412 av_set_pts_info(st, 64, 1, st->codec->sample_rate);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
413 st->start_time = 0;
3067
2dc78258f848 fix duration for ima4
bcoudurier
parents: 3066
diff changeset
414 st->duration = st->codec->frame_size ?
2dc78258f848 fix duration for ima4
bcoudurier
parents: 3066
diff changeset
415 st->nb_frames * st->codec->frame_size : st->nb_frames;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
416
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
417 /* Position the stream at the first block */
2206
c049274b7bd4 support files with COMM chunk after SSND, fix invalid_nocommon.aiff which is spec compliant
bcoudurier
parents: 2060
diff changeset
418 url_fseek(pb, offset, SEEK_SET);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
419
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
420 return 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
421 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
422
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
423 #define MAX_SIZE 4096
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
424
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
425 static int aiff_read_packet(AVFormatContext *s,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
426 AVPacket *pkt)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
427 {
1087
8ffbf9385972 fix pcm_s24be demuxing, simplify
bcoudurier
parents: 925
diff changeset
428 AVStream *st = s->streams[0];
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
429 AIFFInputContext *aiff = s->priv_data;
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
430 int64_t max_size;
1087
8ffbf9385972 fix pcm_s24be demuxing, simplify
bcoudurier
parents: 925
diff changeset
431 int res;
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
432
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
433 /* calculate size of remaining data */
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
434 max_size = aiff->data_end - url_ftell(s->pb);
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
435 if (max_size <= 0)
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
436 return AVERROR_EOF;
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
437
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
438 /* Now for that packet */
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
439 max_size = FFMIN(max_size, (MAX_SIZE / st->codec->block_align) * st->codec->block_align);
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
440 res = av_get_packet(s->pb, pkt, max_size);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
441 if (res < 0)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
442 return res;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
443
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
444 /* Only one stream in an AIFF file */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
445 pkt->stream_index = 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
446 return 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
447 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
448
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 3973
diff changeset
449 #if CONFIG_AIFF_DEMUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
450 AVInputFormat aiff_demuxer = {
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
451 "aiff",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3297
diff changeset
452 NULL_IF_CONFIG_SMALL("Audio IFF"),
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
453 sizeof(AIFFInputContext),
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
454 aiff_probe,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
455 aiff_read_header,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
456 aiff_read_packet,
3073
ed7b32bedcb5 remove useless close function
bcoudurier
parents: 3072
diff changeset
457 NULL,
3435
a81155640306 Remove wrappers of pcm_read_seek().
ramiro
parents: 3424
diff changeset
458 pcm_read_seek,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3739
diff changeset
459 .codec_tag= (const AVCodecTag* const []){codec_aiff_tags, 0},
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
460 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
461 #endif
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
462
4206
c3102b189cb6 Change semantic of CONFIG_*, HAVE_* and ARCH_*.
aurel
parents: 3973
diff changeset
463 #if CONFIG_AIFF_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
464 AVOutputFormat aiff_muxer = {
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
465 "aiff",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3297
diff changeset
466 NULL_IF_CONFIG_SMALL("Audio IFF"),
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
467 "audio/aiff",
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
468 "aif,aiff,afc,aifc",
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
469 sizeof(AIFFOutputContext),
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
470 CODEC_ID_PCM_S16BE,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
471 CODEC_ID_NONE,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
472 aiff_write_header,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
473 aiff_write_packet,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
474 aiff_write_trailer,
3766
f062deeedb8d Change codec_tag type from const struct AVCodecTag ** to const struct AVCodecTag * const *
reimar
parents: 3739
diff changeset
475 .codec_tag= (const AVCodecTag* const []){codec_aiff_tags, 0},
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
476 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
477 #endif