annotate aiffdec.c @ 5395:af65f63f2063 libavformat

decode qcelp in aiff, implement #1524, patch by Vitor
author bcoudurier
date Mon, 30 Nov 2009 22:01:21 +0000
parents 6b37260d470e
children 4211f91f69b1
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 /*
5283
63c52dca959b Split up the AIFF muxer and demuxer into separate files.
jbr
parents: 5279
diff changeset
2 * AIFF/AIFF-C 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"
5283
63c52dca959b Split up the AIFF muxer and demuxer into separate files.
jbr
parents: 5279
diff changeset
25 #include "aiff.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
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
27 #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
28 #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
29
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
30 typedef struct {
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
31 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
32 } AIFFInputContext;
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
33
3967
4fd67f05bad9 Use enum typers instead of int.
benoit
parents: 3908
diff changeset
34 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
35 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
36 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
37 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
38 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
39 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
40 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
41 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
42 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
43 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
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 /* bigger than 32 isn't allowed */
3967
4fd67f05bad9 Use enum typers instead of int.
benoit
parents: 3908
diff changeset
46 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
47 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
48
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
49 /* 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
50 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
51 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
52 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
53
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
54 if (url_feof(pb))
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2273
diff changeset
55 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
56
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
57 *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
58 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
59
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
60 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
61 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
62
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
63 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
64 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
65
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
66 /* Metadata string read */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
67 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
68 {
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
69 uint8_t str[1024];
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
70 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
71 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
72 return;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
73
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
74 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
75 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
76 size++;
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 -= res;
1792
bcoudurier
parents: 1791
diff changeset
78 if (size)
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
79 url_fskip(s->pb, size);
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
80
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
81 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
82 }
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 /* 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
85 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
86 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
87 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
88 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
89 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
90 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
91
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
92 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
93 size++;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
94 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
95 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
96 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
97 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
98
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
99 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
100 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
101 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
102 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
103
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
104 /* 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
105 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
106 codec->codec_tag = get_le32(pb);
5283
63c52dca959b Split up the AIFF muxer and demuxer into separate files.
jbr
parents: 5279
diff changeset
107 codec->codec_id = ff_codec_get_id(ff_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
108
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
109 switch (codec->codec_id) {
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
110 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
111 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
112 codec->bits_per_coded_sample = av_get_bits_per_sample(codec->codec_id);
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
113 break;
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
114 case CODEC_ID_ADPCM_IMA_QT:
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
115 codec->block_align = 34*codec->channels;
3067
2dc78258f848 fix duration for ima4
bcoudurier
parents: 3066
diff changeset
116 codec->frame_size = 64;
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
117 break;
3079
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
118 case CODEC_ID_MACE3:
3111
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
119 codec->block_align = 2*codec->channels;
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
120 codec->frame_size = 6;
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
121 break;
3079
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
122 case CODEC_ID_MACE6:
3111
6f505b24ed57 set block align for mace3/6
bcoudurier
parents: 3110
diff changeset
123 codec->block_align = 1*codec->channels;
3079
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
124 codec->frame_size = 6;
475106eb507e fix mace duration
bcoudurier
parents: 3075
diff changeset
125 break;
3891
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
126 case CODEC_ID_GSM:
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
127 codec->block_align = 33;
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
128 codec->frame_size = 160;
fbe8704f513a set block align and frame size for gsm in aiff
bcoudurier
parents: 3871
diff changeset
129 break;
5395
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
130 case CODEC_ID_QCELP:
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
131 codec->block_align = 35;
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
132 codec->frame_size= 160;
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
133 break;
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
134 default:
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
135 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
136 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
137 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
138 } else {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
139 /* Need the codec type */
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
140 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
141 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
142 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
143
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
144 /* 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
145 * is specific to applications -> here we use the WAVE format definition */
3066
5a69d7493dab ima4 in aiff support
bcoudurier
parents: 2771
diff changeset
146 if (!codec->block_align)
3908
1d3d17de20ba Bump Major version, this commit is almost just renaming bits_per_sample to
michael
parents: 3891
diff changeset
147 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
148
3110
3dade22abed6 correctly compute bit rate for compressed audio, should fix seeking in aiff
bcoudurier
parents: 3079
diff changeset
149 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
150 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
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 /* 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
153 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
154 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
155
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
156 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
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 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
160 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
161 /* 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
162 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
163 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
164 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
165 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
166 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
167 else
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
168 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
169 }
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 /* 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
172 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
173 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
174 {
2206
c049274b7bd4 support files with COMM chunk after SSND, fix invalid_nocommon.aiff which is spec compliant
bcoudurier
parents: 2060
diff changeset
175 int size, filesize;
3973
549a09cf23fe Remove offset_t typedef and use int64_t directly instead.
diego
parents: 3967
diff changeset
176 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
177 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
178 unsigned version = AIFF_C_VERSION1;
2771
d52c718e83f9 Use dynamically allocated ByteIOContext in AVFormatContext
andoma
parents: 2545
diff changeset
179 ByteIOContext *pb = s->pb;
4889
848722752aa5 Remove useless init from aiff_read_header() found by CSA.
michael
parents: 4364
diff changeset
180 AVStream * st;
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
181 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
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 /* 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
184 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
185 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
186 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
187
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
188 /* 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
189 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
190 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
191 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
192 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
193 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
194
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
195 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
196
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
197 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
198 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2209
diff changeset
199 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
200
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
201 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
202 /* 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
203 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
204 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
205 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
206
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
207 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
208
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
209 switch (tag) {
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
210 case MKTAG('C', 'O', 'M', 'M'): /* Common chunk */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
211 /* Then for the complete header info */
3295
4616ba855d62 cosmetics, remove space before opening parenthesis
bcoudurier
parents: 3286
diff changeset
212 st->nb_frames = get_aiff_header(pb, st->codec, size, version);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
213 if (st->nb_frames < 0)
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
214 return st->nb_frames;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
215 if (offset > 0) // COMM is after SSND
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
216 goto got_sound;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
217 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
218 case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
219 version = get_be32(pb);
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
220 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
221 case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
222 get_meta(s, "title" , size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
223 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
224 case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
225 get_meta(s, "author" , size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
226 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
227 case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
228 get_meta(s, "copyright", size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
229 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
230 case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
4364
52e876e7c0cf use new metadata API in aiff demuxer
aurel
parents: 4362
diff changeset
231 get_meta(s, "comment" , size);
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
232 break;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
233 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
234 aiff->data_end = url_ftell(pb) + size;
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
235 offset = get_be32(pb); /* Offset of sound data */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
236 get_be32(pb); /* BlockSize... don't care */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
237 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
238 if (st->codec->block_align) /* Assume COMM already parsed */
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
239 goto got_sound;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
240 if (url_is_streamed(pb)) {
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
241 av_log(s, AV_LOG_ERROR, "file is not seekable\n");
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
242 return -1;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
243 }
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
244 url_fskip(pb, size - 8);
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
245 break;
3074
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
246 case MKTAG('w', 'a', 'v', 'e'):
3075
b273d958cf52 10l, protect malloc overflow
bcoudurier
parents: 3074
diff changeset
247 if ((uint64_t)size > (1<<30))
b273d958cf52 10l, protect malloc overflow
bcoudurier
parents: 3074
diff changeset
248 return -1;
3074
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
249 st->codec->extradata = av_mallocz(size + FF_INPUT_BUFFER_PADDING_SIZE);
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
250 if (!st->codec->extradata)
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
251 return AVERROR(ENOMEM);
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
252 st->codec->extradata_size = size;
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
253 get_buffer(pb, st->codec->extradata, size);
815859771e8b support QDM2 in aiff, QDM2.aif
bcoudurier
parents: 3073
diff changeset
254 break;
3072
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
255 default: /* Jump */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
256 if (size & 1) /* Always even aligned */
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
257 size++;
0e84da9b7183 indentation
bcoudurier
parents: 3071
diff changeset
258 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
259 }
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
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
262 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
263 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
264 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
265 }
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
266
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
267 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
268 /* 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
269 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
270 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
271
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
272 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
273 st->start_time = 0;
3067
2dc78258f848 fix duration for ima4
bcoudurier
parents: 3066
diff changeset
274 st->duration = st->codec->frame_size ?
2dc78258f848 fix duration for ima4
bcoudurier
parents: 3066
diff changeset
275 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
276
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
277 /* 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
278 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
279
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
280 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
281 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
282
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
283 #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
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 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
286 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
287 {
1087
8ffbf9385972 fix pcm_s24be demuxing, simplify
bcoudurier
parents: 925
diff changeset
288 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
289 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
290 int64_t max_size;
5395
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
291 int res, 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
292
5279
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
293 /* 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
294 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
295 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
296 return AVERROR_EOF;
0a917464c1dc Do not read data past the end of the SSND chunk in the AIFF demuxer.
jbr
parents: 5255
diff changeset
297
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 /* Now for that packet */
5395
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
299 if (st->codec->block_align >= 33) // GSM, QCLP, IMA4
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
300 size = st->codec->block_align;
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
301 else
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
302 size = (MAX_SIZE / st->codec->block_align) * st->codec->block_align;
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
303 size = FFMIN(max_size, size);
af65f63f2063 decode qcelp in aiff, implement #1524, patch by Vitor
bcoudurier
parents: 5284
diff changeset
304 res = av_get_packet(s->pb, pkt, 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
305 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
306 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
307
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
308 /* 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
309 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
310 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
311 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
312
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
313 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
314 "aiff",
3424
7a0230981402 Make long_names in lavf/lavdev optional depending on CONFIG_SMALL.
diego
parents: 3297
diff changeset
315 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
316 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
317 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
318 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
319 aiff_read_packet,
3073
ed7b32bedcb5 remove useless close function
bcoudurier
parents: 3072
diff changeset
320 NULL,
3435
a81155640306 Remove wrappers of pcm_read_seek().
ramiro
parents: 3424
diff changeset
321 pcm_read_seek,
5283
63c52dca959b Split up the AIFF muxer and demuxer into separate files.
jbr
parents: 5279
diff changeset
322 .codec_tag= (const AVCodecTag* const []){ff_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
323 };