2007-05-08 23:25:31 +00:00
|
|
|
/*
|
2008-08-03 16:42:32 +00:00
|
|
|
* Common AAC and AC-3 parser
|
2009-01-19 15:46:40 +00:00
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
* Copyright (c) 2003 Michael Niedermayer
|
2007-05-08 23:25:31 +00: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
|
|
|
|
*/
|
|
|
|
|
2013-11-22 16:25:48 +00:00
|
|
|
#include "libavutil/channel_layout.h"
|
2012-08-06 13:49:32 +00:00
|
|
|
#include "libavutil/common.h"
|
2007-05-08 23:25:31 +00:00
|
|
|
#include "parser.h"
|
|
|
|
#include "aac_ac3_parser.h"
|
|
|
|
|
2007-05-08 23:29:07 +00:00
|
|
|
int ff_aac_ac3_parse(AVCodecParserContext *s1,
|
2007-05-08 23:25:31 +00:00
|
|
|
AVCodecContext *avctx,
|
|
|
|
const uint8_t **poutbuf, int *poutbuf_size,
|
|
|
|
const uint8_t *buf, int buf_size)
|
|
|
|
{
|
2007-05-08 23:29:07 +00:00
|
|
|
AACAC3ParseContext *s = s1->priv_data;
|
2008-04-19 01:50:40 +00:00
|
|
|
ParseContext *pc = &s->pc;
|
|
|
|
int len, i;
|
2008-04-19 01:59:55 +00:00
|
|
|
int new_frame_start;
|
2015-11-24 09:20:09 +00:00
|
|
|
int got_frame = 0;
|
2007-05-08 23:25:31 +00:00
|
|
|
|
2008-04-19 02:28:24 +00:00
|
|
|
get_next:
|
2008-04-19 01:50:40 +00:00
|
|
|
i=END_NOT_FOUND;
|
|
|
|
if(s->remaining_size <= buf_size){
|
2008-04-19 02:28:24 +00:00
|
|
|
if(s->remaining_size && !s->need_next_header){
|
2008-04-19 01:50:40 +00: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 01:59:55 +00:00
|
|
|
if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
|
2008-04-19 01:50:40 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if(len<=0){
|
|
|
|
i=END_NOT_FOUND;
|
|
|
|
}else{
|
2015-11-24 09:20:09 +00:00
|
|
|
got_frame = 1;
|
2008-10-29 21:08:14 +00:00
|
|
|
s->state=0;
|
2008-04-19 01:50:40 +00:00
|
|
|
i-= s->header_size -1;
|
2008-04-19 02:58:36 +00:00
|
|
|
s->remaining_size = len;
|
2008-09-22 03:00:26 +00:00
|
|
|
if(!new_frame_start || pc->index+i<=0){
|
2008-04-19 11:14:55 +00:00
|
|
|
s->remaining_size += i;
|
2008-04-19 02:28:24 +00:00
|
|
|
goto get_next;
|
2008-04-19 11:14:55 +00:00
|
|
|
}
|
2008-04-19 01:50:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-05-08 23:25:31 +00:00
|
|
|
|
2008-04-19 01:50:40 +00: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-09 22:11:21 +00:00
|
|
|
|
2008-04-19 01:50:40 +00:00
|
|
|
*poutbuf = buf;
|
|
|
|
*poutbuf_size = buf_size;
|
2007-10-13 09:58:39 +00:00
|
|
|
|
2008-04-19 10:48:50 +00:00
|
|
|
/* update codec info */
|
2009-02-19 00:28:19 +00:00
|
|
|
if(s->codec_id)
|
|
|
|
avctx->codec_id = s->codec_id;
|
|
|
|
|
2015-11-24 09:20:09 +00:00
|
|
|
if (got_frame) {
|
2015-11-25 20:53:06 +00: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 != AV_CODEC_ID_AAC) {
|
|
|
|
avctx->sample_rate = s->sample_rate;
|
2017-10-30 20:18:20 +00:00
|
|
|
avctx->channels = s->channels;
|
|
|
|
avctx->channel_layout = s->channel_layout;
|
2015-11-25 20:53:06 +00:00
|
|
|
s1->duration = s->samples;
|
|
|
|
avctx->audio_service_type = s->service_type;
|
2010-03-04 02:32:48 +00:00
|
|
|
}
|
2010-03-04 02:30:51 +00:00
|
|
|
|
2015-11-25 20:53:06 +00:00
|
|
|
avctx->bit_rate = s->bit_rate;
|
2015-11-24 09:20:09 +00:00
|
|
|
}
|
2008-04-19 01:50:40 +00:00
|
|
|
|
|
|
|
return i;
|
2007-05-08 23:25:31 +00:00
|
|
|
}
|