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->request_channels > 0 &&
00065 avctx->request_channels < channels &&
00066 (avctx->request_channels <= 2 ||
00067 (avctx->request_channels == 1 &&
00068 avctx->codec_id == CODEC_ID_AC3))) {
00069 avctx->channels = avctx->request_channels;
00070 } else {
00071 avctx->channels = channels;
00072 }
00073 avctx->bit_rate = bit_rate;
00074 avctx->frame_size = samples;
00075 }
00076 }
00077 } else {
00078 if(s->inbuf_ptr - s->inbuf == s->frame_size){
00079 *poutbuf = s->inbuf;
00080 *poutbuf_size = s->frame_size;
00081 s->inbuf_ptr = s->inbuf;
00082 s->frame_size = 0;
00083 break;
00084 }
00085 }
00086 }
00087 return buf_ptr - buf;
00088 }