00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "parser.h"
00024 #include "aac_ac3_parser.h"
00025
00026 int ff_aac_ac3_parse(AVCodecParserContext *s1,
00027 AVCodecContext *avctx,
00028 const uint8_t **poutbuf, int *poutbuf_size,
00029 const uint8_t *buf, int buf_size)
00030 {
00031 AACAC3ParseContext *s = s1->priv_data;
00032 const uint8_t *buf_ptr;
00033 int len, sample_rate, bit_rate, channels, samples;
00034
00035 *poutbuf = NULL;
00036 *poutbuf_size = 0;
00037
00038 buf_ptr = buf;
00039 while (buf_size > 0) {
00040 int size_needed= s->frame_size ? s->frame_size : s->header_size;
00041 len = s->inbuf_ptr - s->inbuf;
00042
00043 if(len<size_needed){
00044 len = FFMIN(size_needed - len, buf_size);
00045 memcpy(s->inbuf_ptr, buf_ptr, len);
00046 buf_ptr += len;
00047 s->inbuf_ptr += len;
00048 buf_size -= len;
00049 }
00050
00051 if (s->frame_size == 0) {
00052 if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
00053 len = s->sync(s->inbuf, &channels, &sample_rate, &bit_rate,
00054 &samples);
00055 if (len == 0) {
00056
00057 memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
00058 s->inbuf_ptr--;
00059 } else {
00060 s->frame_size = len;
00061
00062 avctx->sample_rate = sample_rate;
00063
00064 if(avctx->codec_id == CODEC_ID_AC3){
00065 if(avctx->channels!=1 && avctx->channels!=2){
00066 avctx->channels = channels;
00067 }
00068 } else {
00069 avctx->channels = channels;
00070 }
00071 avctx->bit_rate = bit_rate;
00072 avctx->frame_size = samples;
00073 }
00074 }
00075 } else {
00076 if(s->inbuf_ptr - s->inbuf == s->frame_size){
00077 *poutbuf = s->inbuf;
00078 *poutbuf_size = s->frame_size;
00079 s->inbuf_ptr = s->inbuf;
00080 s->frame_size = 0;
00081 break;
00082 }
00083 }
00084 }
00085 return buf_ptr - buf;
00086 }