00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libavutil/common.h"
00024 #include "parser.h"
00025 #include "aac_ac3_parser.h"
00026
00027 int ff_aac_ac3_parse(AVCodecParserContext *s1,
00028 AVCodecContext *avctx,
00029 const uint8_t **poutbuf, int *poutbuf_size,
00030 const uint8_t *buf, int buf_size)
00031 {
00032 AACAC3ParseContext *s = s1->priv_data;
00033 ParseContext *pc = &s->pc;
00034 int len, i;
00035 int new_frame_start;
00036
00037 get_next:
00038 i=END_NOT_FOUND;
00039 if(s->remaining_size <= buf_size){
00040 if(s->remaining_size && !s->need_next_header){
00041 i= s->remaining_size;
00042 s->remaining_size = 0;
00043 }else{
00044 len=0;
00045 for(i=s->remaining_size; i<buf_size; i++){
00046 s->state = (s->state<<8) + buf[i];
00047 if((len=s->sync(s->state, s, &s->need_next_header, &new_frame_start)))
00048 break;
00049 }
00050 if(len<=0){
00051 i=END_NOT_FOUND;
00052 }else{
00053 s->state=0;
00054 i-= s->header_size -1;
00055 s->remaining_size = len;
00056 if(!new_frame_start || pc->index+i<=0){
00057 s->remaining_size += i;
00058 goto get_next;
00059 }
00060 }
00061 }
00062 }
00063
00064 if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
00065 s->remaining_size -= FFMIN(s->remaining_size, buf_size);
00066 *poutbuf = NULL;
00067 *poutbuf_size = 0;
00068 return buf_size;
00069 }
00070
00071 *poutbuf = buf;
00072 *poutbuf_size = buf_size;
00073
00074
00075 if(s->codec_id)
00076 avctx->codec_id = s->codec_id;
00077
00078
00079
00080
00081
00082 if (avctx->codec_id != AV_CODEC_ID_AAC) {
00083 avctx->sample_rate = s->sample_rate;
00084
00085
00086 if(avctx->request_channels > 0 &&
00087 avctx->request_channels < s->channels &&
00088 (avctx->request_channels <= 2 ||
00089 (avctx->request_channels == 1 &&
00090 (avctx->codec_id == AV_CODEC_ID_AC3 ||
00091 avctx->codec_id == AV_CODEC_ID_EAC3)))) {
00092 avctx->channels = avctx->request_channels;
00093 } else {
00094 avctx->channels = s->channels;
00095 avctx->channel_layout = s->channel_layout;
00096 }
00097 s1->duration = s->samples;
00098 avctx->audio_service_type = s->service_type;
00099 }
00100
00101 avctx->bit_rate = s->bit_rate;
00102
00103 return i;
00104 }