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
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* This file is part of Libav.
|
2007-05-09 02:25:31 +03:00
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is free software; you can redistribute it and/or
|
2007-05-09 02:25:31 +03:00
|
|
|
* 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.
|
|
|
|
*
|
2011-03-18 19:35:10 +02:00
|
|
|
* Libav is distributed in the hope that it will be useful,
|
2007-05-09 02:25:31 +03:00
|
|
|
* 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
|
2011-03-18 19:35:10 +02:00
|
|
|
* License along with Libav; if not, write to the Free Software
|
2007-05-09 02:25:31 +03:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*/
|
|
|
|
|
2012-08-06 16:49:32 +03:00
|
|
|
#include "libavutil/common.h"
|
2007-05-09 02:25:31 +03:00
|
|
|
#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 */
|
2009-02-19 02:28:19 +02:00
|
|
|
if(s->codec_id)
|
|
|
|
avctx->codec_id = s->codec_id;
|
|
|
|
|
2010-03-04 04:30:51 +02: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). */
|
2012-08-05 12:11:04 +03:00
|
|
|
if (avctx->codec_id != AV_CODEC_ID_AAC) {
|
2010-03-04 04:30:51 +02:00
|
|
|
avctx->sample_rate = s->sample_rate;
|
|
|
|
|
2010-03-04 04:32:48 +02: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 &&
|
2012-08-05 12:11:04 +03:00
|
|
|
(avctx->codec_id == AV_CODEC_ID_AC3 ||
|
|
|
|
avctx->codec_id == AV_CODEC_ID_EAC3)))) {
|
2010-03-04 04:32:48 +02:00
|
|
|
avctx->channels = avctx->request_channels;
|
|
|
|
} else {
|
|
|
|
avctx->channels = s->channels;
|
|
|
|
avctx->channel_layout = s->channel_layout;
|
|
|
|
}
|
2012-01-13 04:59:43 +03:00
|
|
|
s1->duration = s->samples;
|
2011-03-24 18:10:38 +02:00
|
|
|
avctx->audio_service_type = s->service_type;
|
2010-03-04 04:30:51 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
avctx->bit_rate = s->bit_rate;
|
2008-04-19 04:50:40 +03:00
|
|
|
|
|
|
|
return i;
|
2007-05-09 02:25:31 +03:00
|
|
|
}
|