81
78
return s->frame_size;
84
static av_cold int mpegaudio_parse_init(AVCodecParserContext *s1)
86
MpegAudioParseContext *s = s1->priv_data;
87
s->inbuf_ptr = s->inbuf;
91
81
static int mpegaudio_parse(AVCodecParserContext *s1,
92
82
AVCodecContext *avctx,
93
83
const uint8_t **poutbuf, int *poutbuf_size,
94
84
const uint8_t *buf, int buf_size)
96
86
MpegAudioParseContext *s = s1->priv_data;
97
int len, ret, sr, channels, bit_rate, frame_size;
99
const uint8_t *buf_ptr;
104
while (buf_size > 0) {
105
len = s->inbuf_ptr - s->inbuf;
106
if (s->frame_size == 0) {
107
/* special case for next header for first frame in free
108
format case (XXX: find a simpler method) */
109
if (s->free_format_next_header != 0) {
110
AV_WB32(s->inbuf, s->free_format_next_header);
111
s->inbuf_ptr = s->inbuf + 4;
112
s->free_format_next_header = 0;
115
/* no header seen : find one. We need at least MPA_HEADER_SIZE
117
len = FFMIN(MPA_HEADER_SIZE - len, buf_size);
119
memcpy(s->inbuf_ptr, buf_ptr, len);
124
if ((s->inbuf_ptr - s->inbuf) >= MPA_HEADER_SIZE) {
126
header = AV_RB32(s->inbuf);
128
ret = ff_mpa_decode_header(avctx, header, &sr, &channels, &frame_size, &bit_rate);
87
ParseContext *pc = &s->pc;
88
uint32_t state= pc->state;
90
int next= END_NOT_FOUND;
92
for(i=0; i<buf_size; ){
94
int inc= FFMIN(buf_size - i, s->frame_size);
104
int ret, sr, channels, bit_rate, frame_size;
106
state= (state<<8) + buf[i++];
108
ret = ff_mpa_decode_header(avctx, state, &sr, &channels, &frame_size, &bit_rate);
130
110
s->header_count= -2;
131
/* no sync found : move by one byte (inefficient, but simple!) */
132
memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
134
dprintf(avctx, "skip %x\n", header);
135
/* reset free format frame size to give a chance
136
to get a new bitrate */
137
s->free_format_frame_size = 0;
139
if((header&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
112
if((state&SAME_HEADER_MASK) != (s->header&SAME_HEADER_MASK) && s->header)
140
113
s->header_count= -3;
142
115
s->header_count++;
116
s->frame_size = ret-4;
146
/* free format: prepare to compute frame size */
147
if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
151
118
if(s->header_count > 1){
152
119
avctx->sample_rate= sr;
153
120
avctx->channels = channels;
154
121
avctx->frame_size = frame_size;
155
122
avctx->bit_rate = bit_rate;
161
if (s->frame_size == -1) {
162
/* free format : find next sync to compute frame size */
163
len = MPA_MAX_CODED_FRAME_SIZE - len;
167
/* frame too long: resync */
169
memmove(s->inbuf, s->inbuf + 1, s->inbuf_ptr - s->inbuf - 1);
176
memcpy(s->inbuf_ptr, buf_ptr, len);
177
/* check for header */
178
p = s->inbuf_ptr - 3;
179
pend = s->inbuf_ptr + len - 4;
182
header1 = AV_RB32(s->inbuf);
183
/* check with high probability that we have a
185
if ((header & SAME_HEADER_MASK) ==
186
(header1 & SAME_HEADER_MASK)) {
187
/* header found: update pointers */
188
len = (p + 4) - s->inbuf_ptr;
192
/* compute frame size */
193
s->free_format_next_header = header;
194
s->free_format_frame_size = s->inbuf_ptr - s->inbuf;
195
padding = (header1 >> 9) & 1;
197
s->free_format_frame_size -= padding * 4;
199
s->free_format_frame_size -= padding;
200
dprintf(avctx, "free frame size=%d padding=%d\n",
201
s->free_format_frame_size, padding);
202
ff_mpegaudio_decode_header((MPADecodeHeader *)s, header1);
207
/* not found: simply increase pointers */
214
if (len < s->frame_size) {
215
if (s->frame_size > MPA_MAX_CODED_FRAME_SIZE)
216
s->frame_size = MPA_MAX_CODED_FRAME_SIZE;
217
len = FFMIN(s->frame_size - len, buf_size);
218
memcpy(s->inbuf_ptr, buf_ptr, len);
224
if(s->frame_size > 0 && buf_ptr - buf == s->inbuf_ptr - s->inbuf
225
&& buf_size + buf_ptr - buf >= s->frame_size){
226
if(s->header_count > 0){
228
*poutbuf_size = s->frame_size;
230
buf_ptr = buf + s->frame_size;
231
s->inbuf_ptr = s->inbuf;
237
if (s->frame_size > 0 &&
238
(s->inbuf_ptr - s->inbuf) >= s->frame_size) {
239
if(s->header_count > 0){
241
*poutbuf_size = s->inbuf_ptr - s->inbuf;
243
s->inbuf_ptr = s->inbuf;
248
return buf_ptr - buf;
131
if (ff_combine_frame(pc, next, &buf, &buf_size) < 0) {
138
*poutbuf_size = buf_size;
252
143
AVCodecParser mpegaudio_parser = {
253
144
{ CODEC_ID_MP1, CODEC_ID_MP2, CODEC_ID_MP3 },
254
145
sizeof(MpegAudioParseContext),
255
mpegaudio_parse_init,