annotate flacdec.c @ 4610:41542d2edcf4 libavformat

Separate the raw FLAC demuxer from raw.c and put in a new file, flacdec.c.
author jbr
date Sat, 28 Feb 2009 17:24:46 +0000
parents raw.c@1cc2041c2e03
children 259725e31ef1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 868
diff changeset
1 /*
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
2 * Raw FLAC demuxer
4251
77e0c7511d41 cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 4206
diff changeset
3 * Copyright (c) 2001 Fabrice Bellard
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
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: 1245
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
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: 1245
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 887
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3274
diff changeset
21
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include "avformat.h"
2545
213268d7594e move unrelated functions declarations out of allformats.h
aurel
parents: 2368
diff changeset
23 #include "raw.h"
4254
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
24 #include "id3v2.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
26 static int flac_read_header(AVFormatContext *s,
3268
319c36da904b set demuxers .value and use common audio_read_header function
bcoudurier
parents: 3238
diff changeset
27 AVFormatParameters *ap)
63
8329ba7cbd01 raw ac3 auto detects parameters
bellard
parents: 49
diff changeset
28 {
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
29 uint8_t buf[ID3v2_HEADER_SIZE];
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
30 int ret;
3268
319c36da904b set demuxers .value and use common audio_read_header function
bcoudurier
parents: 3238
diff changeset
31 AVStream *st = av_new_stream(s, 0);
686
e2687b784c3a shorten decoder by (Jeff Muizelaar <jrmuizel gmail com>)
michael
parents: 637
diff changeset
32 if (!st)
2273
7eb456c4ed8a Replace all occurrences of AVERROR_NOMEM with AVERROR(ENOMEM).
takis
parents: 2231
diff changeset
33 return AVERROR(ENOMEM);
820
feca73904e67 changing AVCodecContext codec -> *codec in AVStream so additions to AVCodecContext dont randomize AVStream and break binary compatibility
michael
parents: 814
diff changeset
34 st->codec->codec_type = CODEC_TYPE_AUDIO;
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
35 st->codec->codec_id = CODEC_ID_FLAC;
2023
a3e79d6e4e3c add an enum for need_parsing
aurel
parents: 2022
diff changeset
36 st->need_parsing = AVSTREAM_PARSE_FULL;
931
7420a756dc7a read/write adts aac
mru
parents: 930
diff changeset
37 /* the parameters will be extracted from the compressed bitstream */
4285
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
38
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
39 /* skip ID3v2 header if found */
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
40 ret = get_buffer(s->pb, buf, ID3v2_HEADER_SIZE);
4285
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
41 if (ret == ID3v2_HEADER_SIZE && ff_id3v2_match(buf)) {
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
42 int len = ff_id3v2_tag_len(buf);
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
43 url_fseek(s->pb, len - ID3v2_HEADER_SIZE, SEEK_CUR);
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
44 } else {
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
45 url_fseek(s->pb, 0, SEEK_SET);
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
46 }
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 }
4548
2c9ebc4029ae add raw demuxer for Chinese AVS elementary streams
stefang
parents: 4510
diff changeset
49
2365
76827ffd1cf6 flac probe
michael
parents: 2313
diff changeset
50 static int flac_probe(AVProbeData *p)
76827ffd1cf6 flac probe
michael
parents: 2313
diff changeset
51 {
4285
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
52 uint8_t *bufptr = p->buf;
4292
0e275ee37217 Check buffer is inside what is passed when probing for flac.
benoit
parents: 4285
diff changeset
53 uint8_t *end = p->buf + p->buf_size;
4285
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
54
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
55 if(ff_id3v2_match(bufptr))
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
56 bufptr += ff_id3v2_tag_len(bufptr);
d8803d0a4274 Handle ID3v2 tags in raw FLAC streams by skipping them.
jbr
parents: 4254
diff changeset
57
4292
0e275ee37217 Check buffer is inside what is passed when probing for flac.
benoit
parents: 4285
diff changeset
58 if(bufptr > end-4 || memcmp(bufptr, "fLaC", 4)) return 0;
4293
491a0b1d4f62 Whitespace cosmetics to align return statements.
benoit
parents: 4292
diff changeset
59 else return AVPROBE_SCORE_MAX/2;
2365
76827ffd1cf6 flac probe
michael
parents: 2313
diff changeset
60 }
76827ffd1cf6 flac probe
michael
parents: 2313
diff changeset
61
3546
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
62 AVInputFormat flac_demuxer = {
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
63 "flac",
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
64 NULL_IF_CONFIG_SMALL("raw FLAC"),
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
65 0,
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
66 flac_probe,
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
67 flac_read_header,
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
68 ff_raw_read_partial_packet,
1756
5d72afc6c8aa better generic index building and seeking code
michael
parents: 1463
diff changeset
69 .flags= AVFMT_GENERIC_INDEX,
3546
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
70 .extensions = "flac",
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
71 .value = CODEC_ID_FLAC,
931
7420a756dc7a read/write adts aac
mru
parents: 930
diff changeset
72 };