annotate aiff.c @ 1358:0899bfe4105c libavformat

Change license headers to say 'FFmpeg' instead of 'this program/this library' and fix GPL/LGPL version mismatches.
author diego
date Sat, 07 Oct 2006 15:30:46 +0000
parents 6a5e58d2114b
children 75e006876c55
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 /*
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
2 * AIFF/AIFF-C encoder and decoder
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 */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
21 #include "avformat.h"
1142
e3a585883bbd Move initialisations and internal symbols in allformats.h,
gpoirier
parents: 1124
diff changeset
22 #include "allformats.h"
1172
6a5e58d2114b move common stuff from avienc.c and wav.c to new file riff.c
mru
parents: 1170
diff changeset
23 #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
24 #include "intfloat_readwrite.h"
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
25
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
26 const CodecTag codec_aiff_tags[] = {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
27 { CODEC_ID_PCM_S16BE, MKTAG('N','O','N','E') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
28 { CODEC_ID_PCM_S8, MKTAG('N','O','N','E') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
29 { CODEC_ID_PCM_S24BE, MKTAG('N','O','N','E') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
30 { CODEC_ID_PCM_S32BE, MKTAG('N','O','N','E') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
31 { CODEC_ID_PCM_ALAW, MKTAG('a','l','a','w') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
32 { CODEC_ID_PCM_ALAW, MKTAG('A','L','A','W') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
33 { CODEC_ID_PCM_MULAW, MKTAG('u','l','a','w') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
34 { CODEC_ID_PCM_MULAW, MKTAG('U','L','A','W') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
35 { CODEC_ID_MACE3, MKTAG('M','A','C','3') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
36 { CODEC_ID_MACE6, MKTAG('M','A','C','6') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
37 { CODEC_ID_GSM, MKTAG('G','S','M',' ') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
38 { CODEC_ID_ADPCM_G726, MKTAG('G','7','2','6') },
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
39 { 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
40 };
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
41
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
42 #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
43 #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
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 static int aiff_codec_get_id (int bps)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
46 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
47 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
48 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
49 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
50 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
51 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
52 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
53 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
54 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
55
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
56 /* bigger than 32 isn't allowed */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
57 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
58 }
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 /* 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
61 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
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 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
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 if (url_feof(pb))
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
66 return AVERROR_IO;
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 *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
69 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
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 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
72 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
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 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
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
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
77 /* Metadata string read */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
78 static void get_meta(ByteIOContext *pb, char * str, int strsize, 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
79 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
80 int res;
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 if (size > strsize-1)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
83 res = get_buffer(pb, (uint8_t*)str, strsize-1);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
84 else
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
85 res = get_buffer(pb, (uint8_t*)str, size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
86
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
87 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
88 return;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
89
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
90 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
91 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
92 size++;
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 -= res;
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);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
95 url_fskip(pb, 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 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
97
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
98 /* Returns the number of bits per second */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
99 static int fix_bps(int codec_id)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
100 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
101 switch (codec_id) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
102 case 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
103 return 8;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
104 case 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
105 return 16;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
106 case 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
107 return 24;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
108 case 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
109 return 32;
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
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
112 return -1;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
113 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
114
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
115 /* 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
116 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
117 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
118 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
119 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
120 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
121 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
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
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 (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
125 size++;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
126
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
127 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
128 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
129 num_frames = 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
130 codec->bits_per_sample = 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
131
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
132 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
133 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
134 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
135 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
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 /* 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
138 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
139 codec->codec_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
140 codec->codec_id = codec_get_id (codec_aiff_tags, codec->codec_tag);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
141
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
142 if (codec->codec_id == 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
143 codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
144 codec->bits_per_sample = fix_bps(codec->codec_id);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
145 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
146
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
147 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
148 } else {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
149 /* Need the codec type */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
150 codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
151 codec->bits_per_sample = fix_bps(codec->codec_id);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
152 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
153
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
154 if (!codec->codec_id)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
155 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
156
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
157 /* 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
158 * is specific to applications -> here we use the WAVE format definition */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
159 codec->block_align = (codec->bits_per_sample * codec->channels) >> 3;
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 codec->bit_rate = codec->sample_rate * 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
162
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
163 /* 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
164 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
165 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
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 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
168 }
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 #ifdef CONFIG_MUXERS
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
171 typedef struct {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
172 offset_t form;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
173 offset_t frames;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
174 offset_t ssnd;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
175 } AIFFOutputContext;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
176
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
177 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
178 {
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 *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
180 ByteIOContext *pb = &s->pb;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
181 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
182 AVExtFloat 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
183 int coder_len;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
184
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
185 /* First verify if format is ok */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
186 enc->codec_tag = codec_get_tag(codec_aiff_tags, enc->codec_id);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
187 if (!enc->codec_tag) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
188 av_free(aiff);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
189 return -1;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
190 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
191
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
192 coder_len = strlen(enc->codec->name);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
193
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
194 /* 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
195 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
196 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
197 put_be32(pb, 0); /* 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
198 put_tag(pb, "AIFC");
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
199
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
200 /* Version chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
201 put_tag(pb, "FVER");
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
202 put_be32(pb, 4);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
203 put_be32(pb, 0xA2805140);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
204
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
205 /* 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
206 put_tag(pb, "COMM");
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
207 if (coder_len & 1) /* Common chunk is of var size */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
208 put_be32(pb, 23+coder_len);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
209 else
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
210 put_be32(pb, 24+coder_len);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
211 put_be16(pb, enc->channels); /* Number of channels */
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 aiff->frames = 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
214 put_be32(pb, 0); /* Number of frames */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
215
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
216 if (!enc->bits_per_sample)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
217 enc->bits_per_sample = (enc->block_align<<3) / enc->channels;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
218 put_be16(pb, enc->bits_per_sample); /* Sample size */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
219
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
220 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
221 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
222
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
223 put_le32(pb, enc->codec_tag);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
224 if (coder_len & 1) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
225 put_byte(pb, coder_len);
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1087
diff changeset
226 put_buffer(pb, (const uint8_t*)enc->codec->name, coder_len);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
227 } else {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
228 put_byte(pb, coder_len+1);
1123
6992dd78ff68 Add (mostly) const to variable and parameter declaration, where a char* was
diego
parents: 1087
diff changeset
229 put_buffer(pb, (const uint8_t*)enc->codec->name, coder_len);
925
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
230 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
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
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
233 /* 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
234 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
235 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
236 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
237 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
238 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
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 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
241
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
242 /* 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
243 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
244
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
245 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
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
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
248 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
249 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
250 ByteIOContext *pb = &s->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 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
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_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
256 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
257 ByteIOContext *pb = &s->pb;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
258 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
259 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
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 /* Chunks sizes must be even */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
262 offset_t file_size, 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
263 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
264 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
265 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
266 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
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
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 (!url_is_streamed(&s->pb)) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
270 /* 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
271 url_fseek(pb, aiff->form, 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
272 put_be32(pb, (uint32_t)(file_size - aiff->form - 4));
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
273
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
274 /* 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
275 url_fseek(pb, aiff->frames, 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
276 put_be32(pb, ((uint32_t)(file_size-aiff->ssnd-12))/enc->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
277
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
278 /* 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
279 url_fseek(pb, aiff->ssnd, 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
280 put_be32(pb, (uint32_t)(file_size - aiff->ssnd - 4));
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 /* 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
283 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
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 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
286 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
287
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
288 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
289 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
290 #endif //CONFIG_MUXERS
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 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
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 /* 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
295 if (p->buf_size < 16)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
296 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
297 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
298 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
299 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
300 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
301 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
302 else
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
303 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
304 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
305
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
306 /* 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
307 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
308 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
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 int size, filesize, offset;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
311 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
312 unsigned 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
313 ByteIOContext *pb = &s->pb;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
314 AVStream * st = s->streams[0];
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
315
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
316 /* 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
317 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
318 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
319 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
320
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
321 /* 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
322 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
323 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
324 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
325 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
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 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
329
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
330 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
331 if (!st)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
332 return AVERROR_NOMEM;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
333
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
334 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
335 /* 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
336 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
337 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
338 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
339
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
340 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
341
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
342 switch (tag) {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
343 case MKTAG('C', 'O', 'M', 'M'): /* 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
344 /* Then for the complete header info */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
345 st->nb_frames = get_aiff_header (pb, st->codec, size, version);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
346 if (st->nb_frames < 0)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
347 return 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
348 break;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
349
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
350 case MKTAG('F', 'V', 'E', 'R'): /* Version chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
351 version = 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
352 break;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
353
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
354 case MKTAG('N', 'A', 'M', 'E'): /* Sample name chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
355 get_meta (pb, s->title, sizeof(s->title), size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
356 break;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
357
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
358 case MKTAG('A', 'U', 'T', 'H'): /* Author chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
359 get_meta (pb, s->author, sizeof(s->author), size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
360 break;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
361
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
362 case MKTAG('(', 'c', ')', ' '): /* Copyright chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
363 get_meta (pb, s->copyright, sizeof(s->copyright), size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
364 break;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
365
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
366 case MKTAG('A', 'N', 'N', 'O'): /* Annotation chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
367 get_meta (pb, s->comment, sizeof(s->comment), size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
368 break;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
369
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
370 case MKTAG('S', 'S', 'N', 'D'): /* Sampled sound chunk */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
371 get_be32(pb); /* Block align... don't care */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
372 offset = get_be32(pb); /* Offset of sound data */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
373 goto 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
374
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
375 default: /* Jump */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
376 if (size & 1) /* Always even aligned */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
377 size++;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
378 url_fskip (pb, size);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
379 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
380 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
381
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
382 /* End of loop and didn't get sound */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
383 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
384
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
385 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
386 /* 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
387 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
388 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
389
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
390 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
391 st->start_time = 0;
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
392 st->duration = 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
393
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
394 /* Position the stream at the first block */
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
395 url_fskip(pb, offset);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
396
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
397 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
398 }
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 #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
401
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
402 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
403 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
404 {
1087
8ffbf9385972 fix pcm_s24be demuxing, simplify
bcoudurier
parents: 925
diff changeset
405 AVStream *st = s->streams[0];
8ffbf9385972 fix pcm_s24be demuxing, simplify
bcoudurier
parents: 925
diff changeset
406 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
407
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
408 /* End of stream may be reached */
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 (url_feof(&s->pb))
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
410 return AVERROR_IO;
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 /* Now for that packet */
1087
8ffbf9385972 fix pcm_s24be demuxing, simplify
bcoudurier
parents: 925
diff changeset
413 res = av_get_packet(&s->pb, pkt, (MAX_SIZE / st->codec->block_align) * st->codec->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
414 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
415 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
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 /* 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
418 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
419 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
420 }
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 static int aiff_read_close(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
423 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
424 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
425 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
426
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
427 static int aiff_read_seek(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
428 int stream_index, int64_t timestamp, int flags)
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
429 {
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
430 return pcm_read_seek(s, stream_index, timestamp, flags);
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
431 }
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
432
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
433 #ifdef CONFIG_AIFF_DEMUXER
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
434 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
435 "aiff",
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
436 "Audio IFF",
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
437 0,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
438 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
439 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
440 aiff_read_packet,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
441 aiff_read_close,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
442 aiff_read_seek,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
443 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
444 #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
445
1170
de5e5e04a33a CONFIG_AIFF_DEMUXER vs CONFIG_AIFF_MUXER typo
diego
parents: 1169
diff changeset
446 #ifdef CONFIG_AIFF_MUXER
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
447 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
448 "aiff",
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
449 "Audio IFF",
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
450 "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
451 "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
452 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
453 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
454 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
455 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
456 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
457 aiff_write_trailer,
2d9a65a1d9ea AIFF format support by (Patrick Guimond <patg a.t patg d.o.t homeunix d.o.t org)
michael
parents:
diff changeset
458 };
1169
d18cc9a1fd02 allow individual selection of muxers and demuxers
mru
parents: 1167
diff changeset
459 #endif