annotate aacdec.c @ 6448:4775a49a6045 libavformat

split raw.c into rawdec.c and rawenc.c
author aurel
date Mon, 30 Aug 2010 23:16:35 +0000
parents 6a8fc2ab012c
children 5d5fbab4d608
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 /*
6424
6a8fc2ab012c move ADTS AAC demuxer to its own file
aurel
parents: 6323
diff changeset
2 * raw ADTS AAC demuxer
6a8fc2ab012c move ADTS AAC demuxer to its own file
aurel
parents: 6323
diff changeset
3 * Copyright (c) 2008 Michael Niedermayer <michaelni@gmx.at>
6a8fc2ab012c move ADTS AAC demuxer to its own file
aurel
parents: 6323
diff changeset
4 * Copyright (c) 2009 Robert Swain ( rob opendot cl )
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
6 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
7 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
8 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * 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
11 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1245
diff changeset
13 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 * 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
19 * 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
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 */
3286
6f61c3b36632 Use full path for #includes from another directory.
diego
parents: 3274
diff changeset
22
6424
6a8fc2ab012c move ADTS AAC demuxer to its own file
aurel
parents: 6323
diff changeset
23 #include "libavutil/intreadwrite.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include "avformat.h"
6448
4775a49a6045 split raw.c into rawdec.c and rawenc.c
aurel
parents: 6424
diff changeset
25 #include "rawdec.h"
4254
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
26 #include "id3v2.h"
5046
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
27 #include "id3v1.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28
1078
0bc9422cc0ad Raw flac muxer, patch by Justin Ruggles (jruggle earthlink net). Can be
banan
parents: 1070
diff changeset
29
4055
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
30 static int adts_aac_probe(AVProbeData *p)
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
31 {
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
32 int max_frames = 0, first_frames = 0;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
33 int fsize, frames;
4254
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
34 uint8_t *buf0 = p->buf;
4055
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
35 uint8_t *buf2;
4254
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
36 uint8_t *buf;
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
37 uint8_t *end = buf0 + p->buf_size - 7;
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
38
6121
81614e9b541b Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents: 6120
diff changeset
39 if (ff_id3v2_match(buf0, ID3v2_DEFAULT_MAGIC)) {
4254
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
40 buf0 += ff_id3v2_tag_len(buf0);
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
41 }
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
42 buf = buf0;
4055
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
43
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
44 for(; buf < end; buf= buf2+1) {
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
45 buf2 = buf;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
46
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
47 for(frames = 0; buf2 < end; frames++) {
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
48 uint32_t header = AV_RB16(buf2);
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
49 if((header&0xFFF6) != 0xFFF0)
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
50 break;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
51 fsize = (AV_RB32(buf2+3)>>13) & 0x8FFF;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
52 if(fsize < 7)
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
53 break;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
54 buf2 += fsize;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
55 }
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
56 max_frames = FFMAX(max_frames, frames);
4254
d05b13327b07 Fix probing of files with ID3v2 tags. Discussed at
alexc
parents: 4251
diff changeset
57 if(buf == buf0)
4055
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
58 first_frames= frames;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
59 }
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
60 if (first_frames>=3) return AVPROBE_SCORE_MAX/2+1;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
61 else if(max_frames>500)return AVPROBE_SCORE_MAX/2;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
62 else if(max_frames>=3) return AVPROBE_SCORE_MAX/4;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
63 else if(max_frames>=1) return 1;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
64 else return 0;
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
65 }
5046
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
66
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
67 static int adts_aac_read_header(AVFormatContext *s,
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
68 AVFormatParameters *ap)
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
69 {
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
70 AVStream *st;
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
71
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
72 st = av_new_stream(s, 0);
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
73 if (!st)
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
74 return AVERROR(ENOMEM);
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
75
5910
536e5527c1e0 Define AVMediaType enum, and use it instead of enum CodecType, which
stefano
parents: 5657
diff changeset
76 st->codec->codec_type = AVMEDIA_TYPE_AUDIO;
5046
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
77 st->codec->codec_id = s->iformat->value;
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
78 st->need_parsing = AVSTREAM_PARSE_FULL;
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
79
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
80 ff_id3v1_read(s);
6121
81614e9b541b Generalize ID3v2 functions to support ID3v2-like ID headers with a
cehoyos
parents: 6120
diff changeset
81 ff_id3v2_read(s, ID3v2_DEFAULT_MAGIC);
5046
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
82
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
83 return 0;
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
84 }
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
85
3546
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
86 AVInputFormat aac_demuxer = {
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
87 "aac",
4501
3e5b9c1a413e Make format long_names consistent.
diego
parents: 4293
diff changeset
88 NULL_IF_CONFIG_SMALL("raw ADTS AAC"),
3405
9e77f940abc4 raw mlp demuxer
ramiro
parents: 3289
diff changeset
89 0,
4055
69a2d02089e1 ADTS AAC probe.
michael
parents: 4004
diff changeset
90 adts_aac_probe,
5046
b4b0df2c408b Add support for id3 tag parsing for ADTS AAC streams
superdump
parents: 4901
diff changeset
91 adts_aac_read_header,
4610
41542d2edcf4 Separate the raw FLAC demuxer from raw.c and put in a new file,
jbr
parents: 4577
diff changeset
92 ff_raw_read_partial_packet,
3405
9e77f940abc4 raw mlp demuxer
ramiro
parents: 3289
diff changeset
93 .flags= AVFMT_GENERIC_INDEX,
3546
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
94 .extensions = "aac",
45c3d2b2b2fb Alphabetically order AVInputFormat/AVOutputFormat declarations.
diego
parents: 3545
diff changeset
95 .value = CODEC_ID_AAC,
1070
26d75e74c7b7 Add support for raw flac decoding based on the .flac suffix of input files.
banan
parents: 1003
diff changeset
96 };