~ubuntu-branches/ubuntu/oneiric/libav/oneiric

« back to all changes in this revision

Viewing changes to libavformat/aiffdec.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2011-04-30 14:27:42 UTC
  • mfrom: (1.1.2 experimental)
  • Revision ID: james.westby@ubuntu.com-20110430142742-quvblxk1tj6adlh5
Tags: 4:0.7~b1-1ubuntu1
* Merge from debian. Remaining changes:
  - don't build against libfaad, libdirac, librtmp and libopenjpeg
    (all in universe)
  - explicitly --enable-pic on powerpc, cf. LP #654666
  - different arm configure bits that should probably better be
    merged into debian
* Cherry-picked from git: 
  - install doc/APIChanges and refer to them in NEWS.Debian (Closes: #623682)
  - don't try to install non-existing documentation, fixes FTBFS on powerpc

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 * AIFF/AIFF-C demuxer
3
3
 * Copyright (c) 2006  Patrick Guimond
4
4
 *
5
 
 * This file is part of FFmpeg.
 
5
 * This file is part of Libav.
6
6
 *
7
 
 * FFmpeg is free software; you can redistribute it and/or
 
7
 * Libav is free software; you can redistribute it and/or
8
8
 * modify it under the terms of the GNU Lesser General Public
9
9
 * License as published by the Free Software Foundation; either
10
10
 * version 2.1 of the License, or (at your option) any later version.
11
11
 *
12
 
 * FFmpeg is distributed in the hope that it will be useful,
 
12
 * Libav is distributed in the hope that it will be useful,
13
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
15
 * Lesser General Public License for more details.
16
16
 *
17
17
 * You should have received a copy of the GNU Lesser General Public
18
 
 * License along with FFmpeg; if not, write to the Free Software
 
18
 * License along with Libav; if not, write to the Free Software
19
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
20
 */
21
21
 
22
22
#include "libavutil/intfloat_readwrite.h"
23
23
#include "avformat.h"
24
 
#include "raw.h"
 
24
#include "pcm.h"
25
25
#include "aiff.h"
26
26
 
27
27
#define AIFF                    0
47
47
}
48
48
 
49
49
/* returns the size of the found tag */
50
 
static int get_tag(ByteIOContext *pb, uint32_t * tag)
 
50
static int get_tag(AVIOContext *pb, uint32_t * tag)
51
51
{
52
52
    int size;
53
53
 
54
 
    if (url_feof(pb))
 
54
    if (pb->eof_reached)
55
55
        return AVERROR(EIO);
56
56
 
57
 
    *tag = get_le32(pb);
58
 
    size = get_be32(pb);
 
57
    *tag = avio_rl32(pb);
 
58
    size = avio_rb32(pb);
59
59
 
60
60
    if (size < 0)
61
61
        size = 0x7fffffff;
70
70
    int res;
71
71
 
72
72
    if (!str) {
73
 
        url_fskip(s->pb, size);
 
73
        avio_skip(s->pb, size);
74
74
        return;
75
75
    }
76
76
 
77
 
    res = get_buffer(s->pb, str, size);
 
77
    res = avio_read(s->pb, str, size);
78
78
    if (res < 0)
79
79
        return;
80
80
 
83
83
}
84
84
 
85
85
/* Returns the number of sound data frames or negative on error */
86
 
static unsigned int get_aiff_header(ByteIOContext *pb, AVCodecContext *codec,
 
86
static unsigned int get_aiff_header(AVIOContext *pb, AVCodecContext *codec,
87
87
                             int size, unsigned version)
88
88
{
89
89
    AVExtFloat ext;
93
93
    if (size & 1)
94
94
        size++;
95
95
    codec->codec_type = AVMEDIA_TYPE_AUDIO;
96
 
    codec->channels = get_be16(pb);
97
 
    num_frames = get_be32(pb);
98
 
    codec->bits_per_coded_sample = get_be16(pb);
 
96
    codec->channels = avio_rb16(pb);
 
97
    num_frames = avio_rb32(pb);
 
98
    codec->bits_per_coded_sample = avio_rb16(pb);
99
99
 
100
 
    get_buffer(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */
 
100
    avio_read(pb, (uint8_t*)&ext, sizeof(ext));/* Sample rate is in */
101
101
    sample_rate = av_ext2dbl(ext);          /* 80 bits BE IEEE extended float */
102
102
    codec->sample_rate = sample_rate;
103
103
    size -= 18;
104
104
 
105
105
    /* Got an AIFF-C? */
106
106
    if (version == AIFF_C_VERSION1) {
107
 
        codec->codec_tag = get_le32(pb);
 
107
        codec->codec_tag = avio_rl32(pb);
108
108
        codec->codec_id  = ff_codec_get_id(ff_codec_aiff_tags, codec->codec_tag);
109
109
 
110
110
        switch (codec->codec_id) {
152
152
 
153
153
    /* Chunk is over */
154
154
    if (size)
155
 
        url_fseek(pb, size, SEEK_CUR);
 
155
        avio_skip(pb, size);
156
156
 
157
157
    return num_frames;
158
158
}
177
177
    int64_t offset = 0;
178
178
    uint32_t tag;
179
179
    unsigned version = AIFF_C_VERSION1;
180
 
    ByteIOContext *pb = s->pb;
 
180
    AVIOContext *pb = s->pb;
181
181
    AVStream * st;
182
182
    AIFFInputContext *aiff = s->priv_data;
183
183
 
187
187
        return AVERROR_INVALIDDATA;
188
188
 
189
189
    /* AIFF data type */
190
 
    tag = get_le32(pb);
 
190
    tag = avio_rl32(pb);
191
191
    if (tag == MKTAG('A', 'I', 'F', 'F'))       /* Got an AIFF file */
192
192
        version = AIFF;
193
193
    else if (tag != MKTAG('A', 'I', 'F', 'C'))  /* An AIFF-C file then */
217
217
                goto got_sound;
218
218
            break;
219
219
        case MKTAG('F', 'V', 'E', 'R'):     /* Version chunk */
220
 
            version = get_be32(pb);
 
220
            version = avio_rb32(pb);
221
221
            break;
222
222
        case MKTAG('N', 'A', 'M', 'E'):     /* Sample name chunk */
223
223
            get_meta(s, "title"    , size);
232
232
            get_meta(s, "comment"  , size);
233
233
            break;
234
234
        case MKTAG('S', 'S', 'N', 'D'):     /* Sampled sound chunk */
235
 
            aiff->data_end = url_ftell(pb) + size;
236
 
            offset = get_be32(pb);      /* Offset of sound data */
237
 
            get_be32(pb);               /* BlockSize... don't care */
238
 
            offset += url_ftell(pb);    /* Compute absolute data offset */
 
235
            aiff->data_end = avio_tell(pb) + size;
 
236
            offset = avio_rb32(pb);      /* Offset of sound data */
 
237
            avio_rb32(pb);               /* BlockSize... don't care */
 
238
            offset += avio_tell(pb);    /* Compute absolute data offset */
239
239
            if (st->codec->block_align)    /* Assume COMM already parsed */
240
240
                goto got_sound;
241
 
            if (url_is_streamed(pb)) {
 
241
            if (!pb->seekable) {
242
242
                av_log(s, AV_LOG_ERROR, "file is not seekable\n");
243
243
                return -1;
244
244
            }
245
 
            url_fskip(pb, size - 8);
 
245
            avio_skip(pb, size - 8);
246
246
            break;
247
247
        case MKTAG('w', 'a', 'v', 'e'):
248
248
            if ((uint64_t)size > (1<<30))
251
251
            if (!st->codec->extradata)
252
252
                return AVERROR(ENOMEM);
253
253
            st->codec->extradata_size = size;
254
 
            get_buffer(pb, st->codec->extradata, size);
 
254
            avio_read(pb, st->codec->extradata, size);
255
255
            break;
256
256
        default: /* Jump */
257
257
            if (size & 1)   /* Always even aligned */
258
258
                size++;
259
 
            url_fskip (pb, size);
 
259
            avio_skip(pb, size);
260
260
        }
261
261
    }
262
262
 
276
276
        st->nb_frames * st->codec->frame_size : st->nb_frames;
277
277
 
278
278
    /* Position the stream at the first block */
279
 
    url_fseek(pb, offset, SEEK_SET);
 
279
    avio_seek(pb, offset, SEEK_SET);
280
280
 
281
281
    return 0;
282
282
}
292
292
    int res, size;
293
293
 
294
294
    /* calculate size of remaining data */
295
 
    max_size = aiff->data_end - url_ftell(s->pb);
 
295
    max_size = aiff->data_end - avio_tell(s->pb);
296
296
    if (max_size <= 0)
297
297
        return AVERROR_EOF;
298
298
 
311
311
    return 0;
312
312
}
313
313
 
314
 
AVInputFormat aiff_demuxer = {
 
314
AVInputFormat ff_aiff_demuxer = {
315
315
    "aiff",
316
316
    NULL_IF_CONFIG_SMALL("Audio IFF"),
317
317
    sizeof(AIFFInputContext),