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
45 got_frame = 1;
46 } else {
47 get_next:
49 if(
s->remaining_size <= buf_size){
50 if(
s->remaining_size && !
s->need_next_header){
52 s->remaining_size = 0;
53 }else{ //we need a header first
55 for(
i=
s->remaining_size;
i<buf_size;
i++){
56 s->state = (
s->state<<8) + buf[
i];
57 if((
len=
s->sync(
s->state, &
s->need_next_header, &new_frame_start)))
58 break;
59 }
62 }else{
63 got_frame = 1;
65 i-=
s->header_size -1;
66 s->remaining_size =
len;
67 if(!new_frame_start || pc->
index+
i<=0){
68 s->remaining_size +=
i;
69 goto get_next;
70 }
72 s->remaining_size +=
i;
73 }
74 }
75 }
76 }
77
79 s->remaining_size -=
FFMIN(
s->remaining_size, buf_size);
81 *poutbuf_size = 0;
82 return buf_size;
83 }
84 }
85
86 *poutbuf = buf;
87 *poutbuf_size = buf_size;
88
89 if (got_frame) {
90 int bit_rate;
91
92 /* Due to backwards compatible HE-AAC the sample rate, channel count,
93 and total number of samples found in an AAC ADTS header are not
94 reliable. Bit rate is still accurate because the total frame
95 duration in seconds is still correct (as is the number of bits in
96 the frame). */
100
103
106 while (buf_size > 0) {
108
109 if (ret < 0 || hdr.frame_size > buf_size)
111
115 continue;
116 }
117 /* Check for false positives since the syncword is not enough.
118 See section 6.1.2 of A/52. */
121 break;
122 }
123
125
128
133 } else {
136 }
137 #if FF_API_OLD_CHANNEL_LAYOUT
142 #endif
143 }
149 } else {
152
155
157 }
158
159 /* Calculate the average bit rate */
163 (bit_rate - avctx->
bit_rate) /
s->frame_number;
164 }
165 }
166
168 }