Mercurial > libavcodec.hg
annotate dca_parser.c @ 12483:0159a19bfff7 libavcodec
aacdec: Rework channel mapping compatibility hacks.
For a PCE based configuration map the channels solely based on tags.
For an indexed configuration map the channels solely based on position.
This works with all known exotic samples including al17, elem_id0, bad_concat,
and lfe_is_sce.
author | alexc |
---|---|
date | Fri, 10 Sep 2010 18:01:48 +0000 |
parents | 7dd2a45249a9 |
children |
rev | line source |
---|---|
4599 | 1 /* |
4899 | 2 * DCA parser |
4599 | 3 * Copyright (C) 2004 Gildas Bazin |
4 * Copyright (C) 2004 Benjamin Zores | |
5 * Copyright (C) 2006 Benjamin Larsson | |
6 * Copyright (C) 2007 Konstantin Shishkov | |
7 * | |
8 * This file is part of FFmpeg. | |
9 * | |
10 * FFmpeg is free software; you can redistribute it and/or | |
11 * modify it under the terms of the GNU Lesser General Public | |
12 * License as published by the Free Software Foundation; either | |
13 * version 2.1 of the License, or (at your option) any later version. | |
14 * | |
15 * FFmpeg is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
18 * Lesser General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU Lesser General Public | |
21 * License along with FFmpeg; if not, write to the Free Software | |
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
23 */ | |
24 | |
25 #include "parser.h" | |
4899 | 26 #include "dca.h" |
4599 | 27 |
28 typedef struct DCAParseContext { | |
29 ParseContext pc; | |
30 uint32_t lastmarker; | |
6598 | 31 int size; |
32 int framesize; | |
8226
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
33 int hd_pos; |
4599 | 34 } DCAParseContext; |
35 | |
36 #define IS_MARKER(state, i, buf, buf_size) \ | |
37 ((state == DCA_MARKER_14B_LE && (i < buf_size-2) && (buf[i+1] & 0xF0) == 0xF0 && buf[i+2] == 0x07) \ | |
38 || (state == DCA_MARKER_14B_BE && (i < buf_size-2) && buf[i+1] == 0x07 && (buf[i+2] & 0xF0) == 0xF0) \ | |
39 || state == DCA_MARKER_RAW_LE || state == DCA_MARKER_RAW_BE) | |
40 | |
41 /** | |
42 * finds the end of the current frame in the bitstream. | |
43 * @return the position of the first byte of the next frame, or -1 | |
44 */ | |
45 static int dca_find_frame_end(DCAParseContext * pc1, const uint8_t * buf, | |
46 int buf_size) | |
47 { | |
48 int start_found, i; | |
49 uint32_t state; | |
50 ParseContext *pc = &pc1->pc; | |
51 | |
52 start_found = pc->frame_start_found; | |
53 state = pc->state; | |
54 | |
55 i = 0; | |
56 if (!start_found) { | |
57 for (i = 0; i < buf_size; i++) { | |
58 state = (state << 8) | buf[i]; | |
59 if (IS_MARKER(state, i, buf, buf_size)) { | |
60 if (pc1->lastmarker && state == pc1->lastmarker) { | |
61 start_found = 1; | |
62 break; | |
63 } else if (!pc1->lastmarker) { | |
64 start_found = 1; | |
65 pc1->lastmarker = state; | |
66 break; | |
67 } | |
68 } | |
69 } | |
70 } | |
71 if (start_found) { | |
72 for (; i < buf_size; i++) { | |
6598 | 73 pc1->size++; |
4599 | 74 state = (state << 8) | buf[i]; |
8226
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
75 if (state == DCA_HD_MARKER && !pc1->hd_pos) |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
76 pc1->hd_pos = pc1->size; |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
77 if (state == pc1->lastmarker && IS_MARKER(state, i, buf, buf_size)) { |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
78 if(pc1->framesize > pc1->size) |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
79 continue; |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
80 if(!pc1->framesize){ |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
81 pc1->framesize = pc1->hd_pos ? pc1->hd_pos : pc1->size; |
ee1b8c54a603
Add support for parsing and decoding DCA-HD streams.
kostya
parents:
6598
diff
changeset
|
82 } |
4599 | 83 pc->frame_start_found = 0; |
84 pc->state = -1; | |
6598 | 85 pc1->size = 0; |
4599 | 86 return i - 3; |
87 } | |
88 } | |
89 } | |
90 pc->frame_start_found = start_found; | |
91 pc->state = state; | |
92 return END_NOT_FOUND; | |
93 } | |
94 | |
6517
48759bfbd073
Apply 'cold' attribute to init/uninit functions in libavcodec
zuxy
parents:
4931
diff
changeset
|
95 static av_cold int dca_parse_init(AVCodecParserContext * s) |
4599 | 96 { |
97 DCAParseContext *pc1 = s->priv_data; | |
98 | |
99 pc1->lastmarker = 0; | |
100 return 0; | |
101 } | |
102 | |
103 static int dca_parse(AVCodecParserContext * s, | |
104 AVCodecContext * avctx, | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4919
diff
changeset
|
105 const uint8_t ** poutbuf, int *poutbuf_size, |
4599 | 106 const uint8_t * buf, int buf_size) |
107 { | |
108 DCAParseContext *pc1 = s->priv_data; | |
109 ParseContext *pc = &pc1->pc; | |
110 int next; | |
111 | |
112 if (s->flags & PARSER_FLAG_COMPLETE_FRAMES) { | |
113 next = buf_size; | |
114 } else { | |
115 next = dca_find_frame_end(pc1, buf, buf_size); | |
116 | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4919
diff
changeset
|
117 if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) { |
4599 | 118 *poutbuf = NULL; |
119 *poutbuf_size = 0; | |
120 return buf_size; | |
121 } | |
122 } | |
4931
0d1cc37d9430
make some parser parameters const to avoid casting const to non-const
aurel
parents:
4919
diff
changeset
|
123 *poutbuf = buf; |
4599 | 124 *poutbuf_size = buf_size; |
125 return next; | |
126 } | |
127 | |
128 AVCodecParser dca_parser = { | |
129 {CODEC_ID_DTS}, | |
130 sizeof(DCAParseContext), | |
131 dca_parse_init, | |
132 dca_parse, | |
133 ff_parse_close, | |
134 }; |