Browse code

Split up the AIFF muxer and demuxer into separate files.

Originally committed as revision 20234 to svn://svn.ffmpeg.org/ffmpeg/trunk

Justin Ruggles authored on 2009/10/15 18:45:16
Showing 4 changed files
... ...
@@ -14,7 +14,7 @@ OBJS-$(CONFIG_AC3_MUXER)                 += raw.o
14 14
 OBJS-$(CONFIG_ADTS_MUXER)                += adtsenc.o
15 15
 OBJS-$(CONFIG_AEA_DEMUXER)               += aea.o
16 16
 OBJS-$(CONFIG_AIFF_DEMUXER)              += aiff.o riff.o raw.o
17
-OBJS-$(CONFIG_AIFF_MUXER)                += aiff.o riff.o
17
+OBJS-$(CONFIG_AIFF_MUXER)                += aiffenc.o riff.o
18 18
 OBJS-$(CONFIG_AMR_DEMUXER)               += amr.o
19 19
 OBJS-$(CONFIG_AMR_MUXER)                 += amr.o
20 20
 OBJS-$(CONFIG_APC_DEMUXER)               += apc.o
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- * AIFF/AIFF-C muxer and demuxer
2
+ * AIFF/AIFF-C demuxer
3 3
  * Copyright (c) 2006  Patrick Guimond
4 4
  *
5 5
  * This file is part of FFmpeg.
... ...
@@ -22,26 +22,7 @@
22 22
 #include "libavutil/intfloat_readwrite.h"
23 23
 #include "avformat.h"
24 24
 #include "raw.h"
25
-#include "riff.h"
26
-
27
-static const AVCodecTag codec_aiff_tags[] = {
28
-    { CODEC_ID_PCM_S16BE,    MKTAG('N','O','N','E') },
29
-    { CODEC_ID_PCM_S8,       MKTAG('N','O','N','E') },
30
-    { CODEC_ID_PCM_S24BE,    MKTAG('N','O','N','E') },
31
-    { CODEC_ID_PCM_S32BE,    MKTAG('N','O','N','E') },
32
-    { CODEC_ID_PCM_F32BE,    MKTAG('f','l','3','2') },
33
-    { CODEC_ID_PCM_F64BE,    MKTAG('f','l','6','4') },
34
-    { CODEC_ID_PCM_ALAW,     MKTAG('a','l','a','w') },
35
-    { CODEC_ID_PCM_MULAW,    MKTAG('u','l','a','w') },
36
-    { CODEC_ID_MACE3,        MKTAG('M','A','C','3') },
37
-    { CODEC_ID_MACE6,        MKTAG('M','A','C','6') },
38
-    { CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
39
-    { CODEC_ID_ADPCM_G726,   MKTAG('G','7','2','6') },
40
-    { CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
41
-    { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
42
-    { CODEC_ID_QDM2,         MKTAG('Q','D','M','2') },
43
-    { 0, 0 },
44
-};
25
+#include "aiff.h"
45 26
 
46 27
 #define AIFF                    0
47 28
 #define AIFF_C_VERSION1         0xA2805140
... ...
@@ -123,7 +104,7 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
123 123
     /* Got an AIFF-C? */
124 124
     if (version == AIFF_C_VERSION1) {
125 125
         codec->codec_tag = get_le32(pb);
126
-        codec->codec_id  = ff_codec_get_id(codec_aiff_tags, codec->codec_tag);
126
+        codec->codec_id  = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag);
127 127
 
128 128
         switch (codec->codec_id) {
129 129
         case CODEC_ID_PCM_S16BE:
... ...
@@ -171,131 +152,6 @@ static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
171 171
     return num_frames;
172 172
 }
173 173
 
174
-#if CONFIG_AIFF_MUXER
175
-typedef struct {
176
-    int64_t form;
177
-    int64_t frames;
178
-    int64_t ssnd;
179
-} AIFFOutputContext;
180
-
181
-static int aiff_write_header(AVFormatContext *s)
182
-{
183
-    AIFFOutputContext *aiff = s->priv_data;
184
-    ByteIOContext *pb = s->pb;
185
-    AVCodecContext *enc = s->streams[0]->codec;
186
-    AVExtFloat sample_rate;
187
-    int aifc = 0;
188
-
189
-    /* First verify if format is ok */
190
-    if (!enc->codec_tag)
191
-        return -1;
192
-    if (enc->codec_tag != MKTAG('N','O','N','E'))
193
-        aifc = 1;
194
-
195
-    /* FORM AIFF header */
196
-    put_tag(pb, "FORM");
197
-    aiff->form = url_ftell(pb);
198
-    put_be32(pb, 0);                    /* file length */
199
-    put_tag(pb, aifc ? "AIFC" : "AIFF");
200
-
201
-    if (aifc) { // compressed audio
202
-        enc->bits_per_coded_sample = 16;
203
-        if (!enc->block_align) {
204
-            av_log(s, AV_LOG_ERROR, "block align not set\n");
205
-            return -1;
206
-        }
207
-        /* Version chunk */
208
-        put_tag(pb, "FVER");
209
-        put_be32(pb, 4);
210
-        put_be32(pb, 0xA2805140);
211
-    }
212
-
213
-    /* Common chunk */
214
-    put_tag(pb, "COMM");
215
-    put_be32(pb, aifc ? 24 : 18); /* size */
216
-    put_be16(pb, enc->channels);  /* Number of channels */
217
-
218
-    aiff->frames = url_ftell(pb);
219
-    put_be32(pb, 0);              /* Number of frames */
220
-
221
-    if (!enc->bits_per_coded_sample)
222
-        enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id);
223
-    if (!enc->bits_per_coded_sample) {
224
-        av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
225
-        return -1;
226
-    }
227
-    if (!enc->block_align)
228
-        enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3;
229
-
230
-    put_be16(pb, enc->bits_per_coded_sample); /* Sample size */
231
-
232
-    sample_rate = av_dbl2ext((double)enc->sample_rate);
233
-    put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate));
234
-
235
-    if (aifc) {
236
-        put_le32(pb, enc->codec_tag);
237
-        put_be16(pb, 0);
238
-    }
239
-
240
-    /* Sound data chunk */
241
-    put_tag(pb, "SSND");
242
-    aiff->ssnd = url_ftell(pb);         /* Sound chunk size */
243
-    put_be32(pb, 0);                    /* Sound samples data size */
244
-    put_be32(pb, 0);                    /* Data offset */
245
-    put_be32(pb, 0);                    /* Block-size (block align) */
246
-
247
-    av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
248
-
249
-    /* Data is starting here */
250
-    put_flush_packet(pb);
251
-
252
-    return 0;
253
-}
254
-
255
-static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
256
-{
257
-    ByteIOContext *pb = s->pb;
258
-    put_buffer(pb, pkt->data, pkt->size);
259
-    return 0;
260
-}
261
-
262
-static int aiff_write_trailer(AVFormatContext *s)
263
-{
264
-    ByteIOContext *pb = s->pb;
265
-    AIFFOutputContext *aiff = s->priv_data;
266
-    AVCodecContext *enc = s->streams[0]->codec;
267
-
268
-    /* Chunks sizes must be even */
269
-    int64_t file_size, end_size;
270
-    end_size = file_size = url_ftell(pb);
271
-    if (file_size & 1) {
272
-        put_byte(pb, 0);
273
-        end_size++;
274
-    }
275
-
276
-    if (!url_is_streamed(s->pb)) {
277
-        /* File length */
278
-        url_fseek(pb, aiff->form, SEEK_SET);
279
-        put_be32(pb, file_size - aiff->form - 4);
280
-
281
-        /* Number of sample frames */
282
-        url_fseek(pb, aiff->frames, SEEK_SET);
283
-        put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align);
284
-
285
-        /* Sound Data chunk size */
286
-        url_fseek(pb, aiff->ssnd, SEEK_SET);
287
-        put_be32(pb, file_size - aiff->ssnd - 4);
288
-
289
-        /* return to the end */
290
-        url_fseek(pb, end_size, SEEK_SET);
291
-
292
-        put_flush_packet(pb);
293
-    }
294
-
295
-    return 0;
296
-}
297
-#endif /* CONFIG_AIFF_MUXER */
298
-
299 174
 static int aiff_probe(AVProbeData *p)
300 175
 {
301 176
     /* check file header */
... ...
@@ -446,7 +302,6 @@ static int aiff_read_packet(AVFormatContext *s,
446 446
     return 0;
447 447
 }
448 448
 
449
-#if CONFIG_AIFF_DEMUXER
450 449
 AVInputFormat aiff_demuxer = {
451 450
     "aiff",
452 451
     NULL_IF_CONFIG_SMALL("Audio IFF"),
... ...
@@ -456,22 +311,5 @@ AVInputFormat aiff_demuxer = {
456 456
     aiff_read_packet,
457 457
     NULL,
458 458
     pcm_read_seek,
459
-    .codec_tag= (const AVCodecTag* const []){codec_aiff_tags, 0},
460
-};
461
-#endif
462
-
463
-#if CONFIG_AIFF_MUXER
464
-AVOutputFormat aiff_muxer = {
465
-    "aiff",
466
-    NULL_IF_CONFIG_SMALL("Audio IFF"),
467
-    "audio/aiff",
468
-    "aif,aiff,afc,aifc",
469
-    sizeof(AIFFOutputContext),
470
-    CODEC_ID_PCM_S16BE,
471
-    CODEC_ID_NONE,
472
-    aiff_write_header,
473
-    aiff_write_packet,
474
-    aiff_write_trailer,
475
-    .codec_tag= (const AVCodecTag* const []){codec_aiff_tags, 0},
459
+    .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0},
476 460
 };
477
-#endif
478 461
new file mode 100644
... ...
@@ -0,0 +1,52 @@
0
+/*
1
+ * AIFF/AIFF-C muxer/demuxer common header
2
+ * Copyright (c) 2006  Patrick Guimond
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+/**
22
+ * @file libavformat/aiff.h
23
+ * common header for AIFF muxer and demuxer
24
+ */
25
+
26
+#ifndef AVFORMAT_AIFF_H
27
+#define AVFORMAT_AIFF_H
28
+
29
+#include "avformat.h"
30
+#include "riff.h"
31
+
32
+static const AVCodecTag ff_codec_aiff_tags[] = {
33
+    { CODEC_ID_PCM_S16BE,    MKTAG('N','O','N','E') },
34
+    { CODEC_ID_PCM_S8,       MKTAG('N','O','N','E') },
35
+    { CODEC_ID_PCM_S24BE,    MKTAG('N','O','N','E') },
36
+    { CODEC_ID_PCM_S32BE,    MKTAG('N','O','N','E') },
37
+    { CODEC_ID_PCM_F32BE,    MKTAG('f','l','3','2') },
38
+    { CODEC_ID_PCM_F64BE,    MKTAG('f','l','6','4') },
39
+    { CODEC_ID_PCM_ALAW,     MKTAG('a','l','a','w') },
40
+    { CODEC_ID_PCM_MULAW,    MKTAG('u','l','a','w') },
41
+    { CODEC_ID_MACE3,        MKTAG('M','A','C','3') },
42
+    { CODEC_ID_MACE6,        MKTAG('M','A','C','6') },
43
+    { CODEC_ID_GSM,          MKTAG('G','S','M',' ') },
44
+    { CODEC_ID_ADPCM_G726,   MKTAG('G','7','2','6') },
45
+    { CODEC_ID_PCM_S16LE,    MKTAG('s','o','w','t') },
46
+    { CODEC_ID_ADPCM_IMA_QT, MKTAG('i','m','a','4') },
47
+    { CODEC_ID_QDM2,         MKTAG('Q','D','M','2') },
48
+    { 0, 0 },
49
+};
50
+
51
+#endif /* AVFORMAT_AIFF_H */
0 52
new file mode 100644
... ...
@@ -0,0 +1,160 @@
0
+/*
1
+ * AIFF/AIFF-C muxer
2
+ * Copyright (c) 2006  Patrick Guimond
3
+ *
4
+ * This file is part of FFmpeg.
5
+ *
6
+ * FFmpeg is free software; you can redistribute it and/or
7
+ * modify it under the terms of the GNU Lesser General Public
8
+ * License as published by the Free Software Foundation; either
9
+ * version 2.1 of the License, or (at your option) any later version.
10
+ *
11
+ * FFmpeg is distributed in the hope that it will be useful,
12
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14
+ * Lesser General Public License for more details.
15
+ *
16
+ * You should have received a copy of the GNU Lesser General Public
17
+ * License along with FFmpeg; if not, write to the Free Software
18
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19
+ */
20
+
21
+#include "avformat.h"
22
+#include "aiff.h"
23
+
24
+typedef struct {
25
+    int64_t form;
26
+    int64_t frames;
27
+    int64_t ssnd;
28
+} AIFFOutputContext;
29
+
30
+static int aiff_write_header(AVFormatContext *s)
31
+{
32
+    AIFFOutputContext *aiff = s->priv_data;
33
+    ByteIOContext *pb = s->pb;
34
+    AVCodecContext *enc = s->streams[0]->codec;
35
+    AVExtFloat sample_rate;
36
+    int aifc = 0;
37
+
38
+    /* First verify if format is ok */
39
+    if (!enc->codec_tag)
40
+        return -1;
41
+    if (enc->codec_tag != MKTAG('N','O','N','E'))
42
+        aifc = 1;
43
+
44
+    /* FORM AIFF header */
45
+    put_tag(pb, "FORM");
46
+    aiff->form = url_ftell(pb);
47
+    put_be32(pb, 0);                    /* file length */
48
+    put_tag(pb, aifc ? "AIFC" : "AIFF");
49
+
50
+    if (aifc) { // compressed audio
51
+        enc->bits_per_coded_sample = 16;
52
+        if (!enc->block_align) {
53
+            av_log(s, AV_LOG_ERROR, "block align not set\n");
54
+            return -1;
55
+        }
56
+        /* Version chunk */
57
+        put_tag(pb, "FVER");
58
+        put_be32(pb, 4);
59
+        put_be32(pb, 0xA2805140);
60
+    }
61
+
62
+    /* Common chunk */
63
+    put_tag(pb, "COMM");
64
+    put_be32(pb, aifc ? 24 : 18); /* size */
65
+    put_be16(pb, enc->channels);  /* Number of channels */
66
+
67
+    aiff->frames = url_ftell(pb);
68
+    put_be32(pb, 0);              /* Number of frames */
69
+
70
+    if (!enc->bits_per_coded_sample)
71
+        enc->bits_per_coded_sample = av_get_bits_per_sample(enc->codec_id);
72
+    if (!enc->bits_per_coded_sample) {
73
+        av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
74
+        return -1;
75
+    }
76
+    if (!enc->block_align)
77
+        enc->block_align = (enc->bits_per_coded_sample * enc->channels) >> 3;
78
+
79
+    put_be16(pb, enc->bits_per_coded_sample); /* Sample size */
80
+
81
+    sample_rate = av_dbl2ext((double)enc->sample_rate);
82
+    put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate));
83
+
84
+    if (aifc) {
85
+        put_le32(pb, enc->codec_tag);
86
+        put_be16(pb, 0);
87
+    }
88
+
89
+    /* Sound data chunk */
90
+    put_tag(pb, "SSND");
91
+    aiff->ssnd = url_ftell(pb);         /* Sound chunk size */
92
+    put_be32(pb, 0);                    /* Sound samples data size */
93
+    put_be32(pb, 0);                    /* Data offset */
94
+    put_be32(pb, 0);                    /* Block-size (block align) */
95
+
96
+    av_set_pts_info(s->streams[0], 64, 1, s->streams[0]->codec->sample_rate);
97
+
98
+    /* Data is starting here */
99
+    put_flush_packet(pb);
100
+
101
+    return 0;
102
+}
103
+
104
+static int aiff_write_packet(AVFormatContext *s, AVPacket *pkt)
105
+{
106
+    ByteIOContext *pb = s->pb;
107
+    put_buffer(pb, pkt->data, pkt->size);
108
+    return 0;
109
+}
110
+
111
+static int aiff_write_trailer(AVFormatContext *s)
112
+{
113
+    ByteIOContext *pb = s->pb;
114
+    AIFFOutputContext *aiff = s->priv_data;
115
+    AVCodecContext *enc = s->streams[0]->codec;
116
+
117
+    /* Chunks sizes must be even */
118
+    int64_t file_size, end_size;
119
+    end_size = file_size = url_ftell(pb);
120
+    if (file_size & 1) {
121
+        put_byte(pb, 0);
122
+        end_size++;
123
+    }
124
+
125
+    if (!url_is_streamed(s->pb)) {
126
+        /* File length */
127
+        url_fseek(pb, aiff->form, SEEK_SET);
128
+        put_be32(pb, file_size - aiff->form - 4);
129
+
130
+        /* Number of sample frames */
131
+        url_fseek(pb, aiff->frames, SEEK_SET);
132
+        put_be32(pb, (file_size-aiff->ssnd-12)/enc->block_align);
133
+
134
+        /* Sound Data chunk size */
135
+        url_fseek(pb, aiff->ssnd, SEEK_SET);
136
+        put_be32(pb, file_size - aiff->ssnd - 4);
137
+
138
+        /* return to the end */
139
+        url_fseek(pb, end_size, SEEK_SET);
140
+
141
+        put_flush_packet(pb);
142
+    }
143
+
144
+    return 0;
145
+}
146
+
147
+AVOutputFormat aiff_muxer = {
148
+    "aiff",
149
+    NULL_IF_CONFIG_SMALL("Audio IFF"),
150
+    "audio/aiff",
151
+    "aif,aiff,afc,aifc",
152
+    sizeof(AIFFOutputContext),
153
+    CODEC_ID_PCM_S16BE,
154
+    CODEC_ID_NONE,
155
+    aiff_write_header,
156
+    aiff_write_packet,
157
+    aiff_write_trailer,
158
+    .codec_tag= (const AVCodecTag* const []){ff_codec_aiff_tags, 0},
159
+};