~medibuntu-maintainers/mplayer/medibuntu.precise

« back to all changes in this revision

Viewing changes to ffmpeg/libavformat/flacdec.c

  • Committer: Package Import Robot
  • Author(s): Reinhard Tartler
  • Date: 2012-01-12 22:23:28 UTC
  • mfrom: (0.4.7 sid)
  • mto: This revision was merged to the branch mainline in revision 76.
  • Revision ID: package-import@ubuntu.com-20120112222328-8jqdyodym3p84ygu
Tags: 2:1.0~rc4.dfsg1+svn34540-1
* New upstream snapshot
* upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
#include "libavcodec/flac.h"
23
23
#include "avformat.h"
 
24
#include "internal.h"
24
25
#include "rawdec.h"
25
26
#include "oggdec.h"
26
27
#include "vorbiscomment.h"
 
28
#include "libavcodec/bytestream.h"
27
29
 
28
30
static int flac_read_header(AVFormatContext *s,
29
31
                             AVFormatParameters *ap)
31
33
    int ret, metadata_last=0, metadata_type, metadata_size, found_streaminfo=0;
32
34
    uint8_t header[4];
33
35
    uint8_t *buffer=NULL;
34
 
    AVStream *st = av_new_stream(s, 0);
 
36
    AVStream *st = avformat_new_stream(s, NULL);
35
37
    if (!st)
36
38
        return AVERROR(ENOMEM);
37
39
    st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
48
50
    /* process metadata blocks */
49
51
    while (!s->pb->eof_reached && !metadata_last) {
50
52
        avio_read(s->pb, header, 4);
51
 
        ff_flac_parse_block_header(header, &metadata_last, &metadata_type,
 
53
        avpriv_flac_parse_block_header(header, &metadata_last, &metadata_type,
52
54
                                   &metadata_size);
53
55
        switch (metadata_type) {
54
56
        /* allocate and read metadata block for supported types */
55
57
        case FLAC_METADATA_TYPE_STREAMINFO:
 
58
        case FLAC_METADATA_TYPE_CUESHEET:
56
59
        case FLAC_METADATA_TYPE_VORBIS_COMMENT:
57
60
            buffer = av_mallocz(metadata_size + FF_INPUT_BUFFER_PADDING_SIZE);
58
61
            if (!buffer) {
87
90
            buffer = NULL;
88
91
 
89
92
            /* get codec params from STREAMINFO header */
90
 
            ff_flac_parse_streaminfo(st->codec, &si, st->codec->extradata);
 
93
            avpriv_flac_parse_streaminfo(st->codec, &si, st->codec->extradata);
91
94
 
92
95
            /* set time base and duration */
93
96
            if (si.samplerate > 0) {
94
 
                av_set_pts_info(st, 64, 1, si.samplerate);
 
97
                avpriv_set_pts_info(st, 64, 1, si.samplerate);
95
98
                if (si.samples > 0)
96
99
                    st->duration = si.samples;
97
100
            }
 
101
        } else if (metadata_type == FLAC_METADATA_TYPE_CUESHEET) {
 
102
            uint8_t isrc[13];
 
103
            uint64_t start;
 
104
            const uint8_t *offset;
 
105
            int i, chapters, track, ti;
 
106
            if (metadata_size < 431)
 
107
                return AVERROR_INVALIDDATA;
 
108
            offset = buffer + 395;
 
109
            chapters = bytestream_get_byte(&offset) - 1;
 
110
            if (chapters <= 0)
 
111
                return AVERROR_INVALIDDATA;
 
112
            for (i = 0; i < chapters; i++) {
 
113
                if (offset + 36 - buffer > metadata_size)
 
114
                    return AVERROR_INVALIDDATA;
 
115
                start = bytestream_get_be64(&offset);
 
116
                track = bytestream_get_byte(&offset);
 
117
                bytestream_get_buffer(&offset, isrc, 12);
 
118
                isrc[12] = 0;
 
119
                offset += 14;
 
120
                ti = bytestream_get_byte(&offset);
 
121
                if (ti <= 0) return AVERROR_INVALIDDATA;
 
122
                offset += ti * 12;
 
123
                avpriv_new_chapter(s, track, st->time_base, start, AV_NOPTS_VALUE, isrc);
 
124
            }
98
125
        } else {
99
126
            /* STREAMINFO must be the first block */
100
127
            if (!found_streaminfo) {
124
151
}
125
152
 
126
153
AVInputFormat ff_flac_demuxer = {
127
 
    "flac",
128
 
    NULL_IF_CONFIG_SMALL("raw FLAC"),
129
 
    0,
130
 
    flac_probe,
131
 
    flac_read_header,
132
 
    ff_raw_read_partial_packet,
 
154
    .name           = "flac",
 
155
    .long_name      = NULL_IF_CONFIG_SMALL("raw FLAC"),
 
156
    .read_probe     = flac_probe,
 
157
    .read_header    = flac_read_header,
 
158
    .read_packet    = ff_raw_read_partial_packet,
133
159
    .flags= AVFMT_GENERIC_INDEX,
134
160
    .extensions = "flac",
135
161
    .value = CODEC_ID_FLAC,