1 /*
2 * Common AAC and AC-3 parser
3 * Copyright (c) 2003 Fabrice Bellard
4 * Copyright (c) 2003 Michael Niedermayer
5 *
6 * This file is part of FFmpeg.
7 *
8 * FFmpeg is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * FFmpeg is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include "config_components.h"
24
31
34 const uint8_t **poutbuf, int *poutbuf_size,
35 const uint8_t *buf, int buf_size)
36 {
40 int new_frame_start;
41 int got_frame = 0;
42
44
47 got_frame = 1;
48 } else {
49 get_next:
51 if(
s->remaining_size <= buf_size){
52 if(
s->remaining_size && !
s->need_next_header){
54 s->remaining_size = 0;
55 }else{ //we need a header first
57 for(
i=
s->remaining_size;
i<buf_size;
i++){
58 s->state = (
s->state<<8) + buf[
i];
59 if((
len=
s->sync(
s->state, &
s->need_next_header, &new_frame_start)))
60 break;
61 }
64 }else{
65 got_frame = 1;
67 i-=
s->header_size -1;
68 s->remaining_size =
len;
69 if(!new_frame_start || pc->
index+
i<=0){
70 s->remaining_size +=
i;
71 goto get_next;
72 }
74 s->remaining_size +=
i;
75 }
76 }
77 }
78 }
79
81 s->remaining_size -=
FFMIN(
s->remaining_size, buf_size);
83 *poutbuf_size = 0;
84 return buf_size;
85 }
86 }
87
88 *poutbuf = buf;
89 *poutbuf_size = buf_size;
90
91 if (got_frame) {
92 int bit_rate;
93
94 /* Due to backwards compatible HE-AAC the sample rate, channel count,
95 and total number of samples found in an AAC ADTS header are not
96 reliable. Bit rate is still accurate because the total frame
97 duration in seconds is still correct (as is the number of bits in
98 the frame). */
100 #if CONFIG_AC3_PARSER
103
106
109 while (buf_size > 0) {
111
112 if (ret < 0 || hdr.frame_size > buf_size)
114
118 continue;
119 }
120 /* Check for false positives since the syncword is not enough.
121 See section 6.1.2 of A/52. */
124 break;
125 }
126
128
131
136 } else {
139 }
140 }
146 #endif
147 } else {
148 #if CONFIG_AAC_PARSER
156
160 #endif
161 }
162
163 /* Calculate the average bit rate */
167 (bit_rate - avctx->
bit_rate) /
s->frame_number;
168 }
169 }
170
172 }