2007-05-09 01:25:31 +02:00
|
|
|
/*
|
2008-08-03 18:42:32 +02:00
|
|
|
* Common AAC and AC-3 parser
|
2009-01-19 16:46:40 +01:00
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
* Copyright (c) 2003 Michael Niedermayer
|
2007-05-09 01:25:31 +02: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 01:29:07 +02:00
|
|
|
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
2007-05-09 01:25:31 +02:00
|
|
|
AVCodecContext *avctx,
|
|
|
|
const uint8_t **poutbuf, int *poutbuf_size,
|
|
|
|
const uint8_t *buf, int buf_size)
|
|
|
|
{
|
2007-05-09 01:29:07 +02:00
|
|
|
AACAC3ParseContext *s = s1->priv_data;
|
2008-04-19 03:50:40 +02:00
|
|
|
ParseContext *pc = &s->pc;
|
|
|
|
int len, i;
|
2008-04-19 03:59:55 +02:00
|
|
|
int new_frame_start;
|
2007-05-09 01:25:31 +02:00
|
|
|
|
2008-04-19 04:28:24 +02:00
|
|
|
get_next:
|
2008-04-19 03:50:40 +02:00
|
|
|
i=END_NOT_FOUND;
|
|
|
|
if(s->remaining_size <= buf_size){
|
2008-04-19 04:28:24 +02:00
|
|
|
if(s->remaining_size && !s->need_next_header){
|
2008-04-19 03:50:40 +02: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 03:59:55 +02:00
|
|
|
if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
|
2008-04-19 03:50:40 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(len<=0){
|
|
|
|
i=END_NOT_FOUND;
|
|
|
|
}else{
|
2008-10-29 22:08:14 +01:00
|
|
|
s->state=0;
|
2008-04-19 03:50:40 +02:00
|
|
|
i-= s->header_size -1;
|
2008-04-19 04:58:36 +02:00
|
|
|
s->remaining_size = len;
|
2008-09-22 05:00:26 +02:00
|
|
|
if(!new_frame_start || pc->index+i<=0){
|
2008-04-19 13:14:55 +02:00
|
|
|
s->remaining_size += i;
|
2008-04-19 04:28:24 +02:00
|
|
|
goto get_next;
|
2008-04-19 13:14:55 +02:00
|
|
|
}
|
2008-04-19 03:50:40 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-09 01:25:31 +02:00
|
|
|
|
2008-04-19 03:50:40 +02: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 00:11:21 +02:00
|
|
|
|
2008-04-19 03:50:40 +02:00
|
|
|
*poutbuf = buf;
|
|
|
|
*poutbuf_size = buf_size;
|
2007-10-13 11:58:39 +02:00
|
|
|
|
2008-04-19 12:48:50 +02:00
|
|
|
/* update codec info */
|
2009-02-19 01:28:19 +01:00
|
|
|
if(s->codec_id)
|
|
|
|
avctx->codec_id = s->codec_id;
|
|
|
|
|
2010-03-04 03:30:51 +01:00
|
|
|
/* Due to backwards compatible HE-AAC the sample rate, channel count,
|
|
|
|
and total number of samples found in an AAC ADTS header are not
|
|
|
|
reliable. Bit rate is still accurate because the total frame duration in
|
|
|
|
seconds is still correct (as is the number of bits in the frame). */
|
|
|
|
if (avctx->codec_id != CODEC_ID_AAC) {
|
|
|
|
avctx->sample_rate = s->sample_rate;
|
|
|
|
|
2010-03-04 03:32:48 +01:00
|
|
|
/* allow downmixing to stereo (or mono for AC-3) */
|
|
|
|
if(avctx->request_channels > 0 &&
|
|
|
|
avctx->request_channels < s->channels &&
|
|
|
|
(avctx->request_channels <= 2 ||
|
|
|
|
(avctx->request_channels == 1 &&
|
|
|
|
(avctx->codec_id == CODEC_ID_AC3 ||
|
|
|
|
avctx->codec_id == CODEC_ID_EAC3)))) {
|
|
|
|
avctx->channels = avctx->request_channels;
|
|
|
|
} else {
|
|
|
|
avctx->channels = s->channels;
|
|
|
|
avctx->channel_layout = s->channel_layout;
|
|
|
|
}
|
|
|
|
avctx->frame_size = s->samples;
|
2011-03-24 17:10:38 +01:00
|
|
|
avctx->audio_service_type = s->service_type;
|
2010-03-04 03:30:51 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
avctx->bit_rate = s->bit_rate;
|
2008-04-19 03:50:40 +02:00
|
|
|
|
|
|
|
return i;
|
2007-05-09 01:25:31 +02:00
|
|
|
}
|