~ubuntu-dev/mplayer/ubuntu-feisty

« back to all changes in this revision

Viewing changes to libavformat/aiff.c

  • Committer: William Grant
  • Date: 2007-02-03 03:16:07 UTC
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: william.grant@ubuntu.org.au-20070203031607-08gc2ompbz6spt9i
Update to 1.0rc1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * AIFF/AIFF-C encoder and decoder
3
3
 * Copyright (c) 2006  Patrick Guimond
4
4
 *
5
 
 * This library is free software; you can redistribute it and/or
 
5
 * This file is part of FFmpeg.
 
6
 *
 
7
 * FFmpeg is free software; you can redistribute it and/or
6
8
 * modify it under the terms of the GNU Lesser General Public
7
9
 * License as published by the Free Software Foundation; either
8
 
 * version 2 of the License, or (at your option) any later version.
 
10
 * version 2.1 of the License, or (at your option) any later version.
9
11
 *
10
 
 * This library is distributed in the hope that it will be useful,
 
12
 * FFmpeg is distributed in the hope that it will be useful,
11
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
15
 * Lesser General Public License for more details.
14
16
 *
15
17
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License along with this library; if not, write to the Free Software
 
18
 * License along with FFmpeg; if not, write to the Free Software
17
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
20
 */
19
21
#include "avformat.h"
20
 
#include "avi.h"
 
22
#include "allformats.h"
 
23
#include "riff.h"
21
24
#include "intfloat_readwrite.h"
22
25
 
23
26
const CodecTag codec_aiff_tags[] = {
92
95
        url_fskip(pb, size);
93
96
}
94
97
 
95
 
/* Returns the number of bits per second */
96
 
static int fix_bps(int codec_id)
97
 
{
98
 
    switch (codec_id) {
99
 
        case CODEC_ID_PCM_S8:
100
 
                return 8;
101
 
        case CODEC_ID_PCM_S16BE:
102
 
                return 16;
103
 
        case CODEC_ID_PCM_S24BE:
104
 
                return 24;
105
 
        case CODEC_ID_PCM_S32BE:
106
 
                return 32;
107
 
    }
108
 
 
109
 
    return -1;
110
 
}
111
 
 
112
98
/* Returns the number of sound data frames or negative on error */
113
 
unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
 
99
static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
114
100
                             int size, unsigned version)
115
101
{
116
102
    AVExtFloat ext;
138
124
 
139
125
        if (codec->codec_id == CODEC_ID_PCM_S16BE) {
140
126
            codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
141
 
            codec->bits_per_sample = fix_bps(codec->codec_id);
 
127
            codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
142
128
        }
143
129
 
144
130
        size -= 4;
145
131
    } else {
146
132
        /* Need the codec type */
147
133
        codec->codec_id = aiff_codec_get_id (codec->bits_per_sample);
148
 
        codec->bits_per_sample = fix_bps(codec->codec_id);
 
134
        codec->bits_per_sample = av_get_bits_per_sample(codec->codec_id);
149
135
    }
150
136
 
151
137
    if (!codec->codec_id)
155
141
     * is specific to applications -> here we use the WAVE format definition */
156
142
    codec->block_align = (codec->bits_per_sample * codec->channels) >> 3;
157
143
 
158
 
    codec->bit_rate = codec->sample_rate * codec->block_align;
 
144
    codec->bit_rate = codec->sample_rate * (codec->block_align << 3);
159
145
 
160
146
    /* Chunk is over */
161
147
    if (size)
177
163
    ByteIOContext *pb = &s->pb;
178
164
    AVCodecContext *enc = s->streams[0]->codec;
179
165
    AVExtFloat sample_rate;
180
 
    int coder_len;
181
166
 
182
167
    /* First verify if format is ok */
183
168
    enc->codec_tag = codec_get_tag(codec_aiff_tags, enc->codec_id);
186
171
        return -1;
187
172
    }
188
173
 
189
 
    coder_len = strlen(enc->codec->name);
190
 
 
191
174
    /* FORM AIFF header */
192
175
    put_tag(pb, "FORM");
193
176
    aiff->form = url_ftell(pb);
201
184
 
202
185
    /* Common chunk */
203
186
    put_tag(pb, "COMM");
204
 
    if (coder_len & 1)                  /* Common chunk is of var size */
205
 
        put_be32(pb, 23+coder_len);
206
 
    else
207
 
        put_be32(pb, 24+coder_len);
 
187
    put_be32(pb, 24); /* size */
208
188
    put_be16(pb, enc->channels);        /* Number of channels */
209
189
 
210
190
    aiff->frames = url_ftell(pb);
211
191
    put_be32(pb, 0);                    /* Number of frames */
212
192
 
213
193
    if (!enc->bits_per_sample)
214
 
        enc->bits_per_sample = (enc->block_align<<3) / enc->channels;
 
194
        enc->bits_per_sample = av_get_bits_per_sample(enc->codec_id);
 
195
    if (!enc->bits_per_sample) {
 
196
        av_log(s, AV_LOG_ERROR, "could not compute bits per sample\n");
 
197
        return -1;
 
198
    }
 
199
    if (!enc->block_align)
 
200
        enc->block_align = (enc->bits_per_sample * enc->channels) >> 3;
 
201
 
215
202
    put_be16(pb, enc->bits_per_sample); /* Sample size */
216
203
 
217
204
    sample_rate = av_dbl2ext((double)enc->sample_rate);
218
205
    put_buffer(pb, (uint8_t*)&sample_rate, sizeof(sample_rate));
219
206
 
220
207
    put_le32(pb, enc->codec_tag);
221
 
    if (coder_len & 1) {
222
 
        put_byte(pb, coder_len);
223
 
        put_buffer(pb, (uint8_t*)enc->codec->name, coder_len);
224
 
    } else {
225
 
        put_byte(pb, coder_len+1);
226
 
        put_buffer(pb, (uint8_t*)enc->codec->name, coder_len);
227
 
        put_byte(pb, 0);
228
 
    }
 
208
    put_be16(pb, 0);
229
209
 
230
210
    /* Sound data chunk */
231
211
    put_tag(pb, "SSND");
427
407
    return pcm_read_seek(s, stream_index, timestamp, flags);
428
408
}
429
409
 
430
 
 
431
 
static AVInputFormat aiff_iformat = {
 
410
#ifdef CONFIG_AIFF_DEMUXER
 
411
AVInputFormat aiff_demuxer = {
432
412
    "aiff",
433
413
    "Audio IFF",
434
414
    0,
438
418
    aiff_read_close,
439
419
    aiff_read_seek,
440
420
};
 
421
#endif
441
422
 
442
 
#ifdef CONFIG_MUXERS
443
 
static AVOutputFormat aiff_oformat = {
 
423
#ifdef CONFIG_AIFF_MUXER
 
424
AVOutputFormat aiff_muxer = {
444
425
    "aiff",
445
426
    "Audio IFF",
446
427
    "audio/aiff",
452
433
    aiff_write_packet,
453
434
    aiff_write_trailer,
454
435
};
455
 
#endif //CONFIG_MUXERS
456
 
 
457
 
int ff_aiff_init(void)
458
 
{
459
 
    av_register_input_format(&aiff_iformat);
460
 
#ifdef CONFIG_MUXERS
461
 
    av_register_output_format(&aiff_oformat);
462
 
#endif //CONFIG_MUXERS
463
 
    return 0;
464
 
}
465
 
 
 
436
#endif