2007-05-09 02:25:31 +03:00
|
|
|
/*
|
2008-08-03 19:42:32 +03:00
|
|
|
* Common AAC and AC-3 parser
|
2009-01-19 17:46:40 +02:00
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
* Copyright (c) 2003 Michael Niedermayer
|
2007-05-09 02:25:31 +03:00
|
|
|
*
|
|
|
|
* This file is part of FFmpeg.
|
|
|
|
*
|
|
|
|
* FFmpeg is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* FFmpeg is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with FFmpeg; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "parser.h"
|
|
|
|
#include "aac_ac3_parser.h"
|
|
|
|
|
2007-05-09 02:29:07 +03:00
|
|
|
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
2007-05-09 02:25:31 +03:00
|
|
|
AVCodecContext *avctx,
|
|
|
|
const uint8_t **poutbuf, int *poutbuf_size,
|
|
|
|
const uint8_t *buf, int buf_size)
|
|
|
|
{
|
2007-05-09 02:29:07 +03:00
|
|
|
AACAC3ParseContext *s = s1->priv_data;
|
2008-04-19 04:50:40 +03:00
|
|
|
ParseContext *pc = &s->pc;
|
|
|
|
int len, i;
|
2008-04-19 04:59:55 +03:00
|
|
|
int new_frame_start;
|
2007-05-09 02:25:31 +03:00
|
|
|
|
2008-04-19 05:28:24 +03:00
|
|
|
get_next:
|
2008-04-19 04:50:40 +03:00
|
|
|
i=END_NOT_FOUND;
|
|
|
|
if(s->remaining_size <= buf_size){
|
2008-04-19 05:28:24 +03:00
|
|
|
if(s->remaining_size && !s->need_next_header){
|
2008-04-19 04:50:40 +03:00
|
|
|
i= s->remaining_size;
|
|
|
|
s->remaining_size = 0;
|
|
|
|
}else{ //we need a header first
|
|
|
|
len=0;
|
|
|
|
for(i=s->remaining_size; i<buf_size; i++){
|
|
|
|
s->state = (s->state<<8) + buf[i];
|
2008-04-19 04:59:55 +03:00
|
|
|
if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
|
2008-04-19 04:50:40 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(len<=0){
|
|
|
|
i=END_NOT_FOUND;
|
|
|
|
}else{
|
2008-10-29 23:08:14 +02:00
|
|
|
s->state=0;
|
2008-04-19 04:50:40 +03:00
|
|
|
i-= s->header_size -1;
|
2008-04-19 05:58:36 +03:00
|
|
|
s->remaining_size = len;
|
2008-09-22 06:00:26 +03:00
|
|
|
if(!new_frame_start || pc->index+i<=0){
|
2008-04-19 14:14:55 +03:00
|
|
|
s->remaining_size += i;
|
2008-04-19 05:28:24 +03:00
|
|
|
goto get_next;
|
2008-04-19 14:14:55 +03:00
|
|
|
}
|
2008-04-19 04:50:40 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-09 02:25:31 +03:00
|
|
|
|
2008-04-19 04:50:40 +03:00
|
|
|
if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
|
|
|
|
s->remaining_size -= FFMIN(s->remaining_size, buf_size);
|
|
|
|
*poutbuf = NULL;
|
|
|
|
*poutbuf_size = 0;
|
|
|
|
return buf_size;
|
|
|
|
}
|
2008-04-10 01:11:21 +03:00
|
|
|
|
2008-04-19 04:50:40 +03:00
|
|
|
*poutbuf = buf;
|
|
|
|
*poutbuf_size = buf_size;
|
2007-10-13 12:58:39 +03:00
|
|
|
|
2008-04-19 13:48:50 +03:00
|
|
|
/* update codec info */
|
|
|
|
avctx->sample_rate = s->sample_rate;
|
2009-02-19 02:28:19 +02:00
|
|
|
if(s->codec_id)
|
|
|
|
avctx->codec_id = s->codec_id;
|
|
|
|
|
2008-08-03 19:42:32 +03:00
|
|
|
/* allow downmixing to stereo (or mono for AC-3) */
|
2008-04-19 13:48:50 +03:00
|
|
|
if(avctx->request_channels > 0 &&
|
|
|
|
avctx->request_channels < s->channels &&
|
|
|
|
(avctx->request_channels <= 2 ||
|
|
|
|
(avctx->request_channels == 1 &&
|
2008-09-01 17:33:54 +03:00
|
|
|
(avctx->codec_id == CODEC_ID_AC3 ||
|
|
|
|
avctx->codec_id == CODEC_ID_EAC3)))) {
|
2008-04-19 13:48:50 +03:00
|
|
|
avctx->channels = avctx->request_channels;
|
|
|
|
} else {
|
|
|
|
avctx->channels = s->channels;
|
|
|
|
}
|
|
|
|
avctx->bit_rate = s->bit_rate;
|
|
|
|
avctx->frame_size = s->samples;
|
2008-04-19 04:50:40 +03:00
|
|
|
|
|
|
|
return i;
|
2007-05-09 02:25:31 +03:00
|
|
|
}
|