comparison aac_ac3_parser.c @ 6576:5e7c69ebc019 libavcodec

undo changes in aac_ac3_parser
author bwolowiec
date Wed, 09 Apr 2008 22:11:21 +0000
parents c92b7e617a0a
children 1980eba5fd0e
comparison
equal deleted inserted replaced
6575:d869966e57e5 6576:5e7c69ebc019
27 AVCodecContext *avctx, 27 AVCodecContext *avctx,
28 const uint8_t **poutbuf, int *poutbuf_size, 28 const uint8_t **poutbuf, int *poutbuf_size,
29 const uint8_t *buf, int buf_size) 29 const uint8_t *buf, int buf_size)
30 { 30 {
31 AACAC3ParseContext *s = s1->priv_data; 31 AACAC3ParseContext *s = s1->priv_data;
32 ParseContext *pc = &s->pc; 32 AACAC3FrameFlag frame_flag;
33 int len, i; 33 const uint8_t *buf_ptr;
34 int len;
34 35
35 while(s->remaining_size <= buf_size){ 36 *poutbuf = NULL;
36 if(s->remaining_size && !s->need_next_header){ 37 *poutbuf_size = 0;
37 i= s->remaining_size;
38 s->remaining_size = 0;
39 goto output_frame;
40 }else{ //we need a header first
41 len=0;
42 for(i=s->remaining_size; i<buf_size; i++){
43 s->state = (s->state<<8) + buf[i];
44 if((len=s->sync(s->state, s, &s->need_next_header, &s->new_frame_start)))
45 break;
46 }
47 i-= s->header_size -1;
48 if(len>0){
49 s->remaining_size = len + i;
50 38
51 if(pc->index+i > 0 && s->new_frame_start){ 39 buf_ptr = buf;
52 s->remaining_size -= i; // remaining_size=len 40 while (buf_size > 0) {
53 output_frame: 41 int size_needed= s->frame_size ? s->frame_size : s->header_size;
54 if(!s->frame_in_buffer){ 42 len = s->inbuf_ptr - s->inbuf;
55 s->frame_in_buffer=1;
56 buf+=i;
57 buf_size-=i;
58 continue;
59 }
60 ff_combine_frame(pc, i, &buf, &buf_size);
61 *poutbuf = buf;
62 *poutbuf_size = buf_size;
63 43
44 if(len<size_needed){
45 len = FFMIN(size_needed - len, buf_size);
46 memcpy(s->inbuf_ptr, buf_ptr, len);
47 buf_ptr += len;
48 s->inbuf_ptr += len;
49 buf_size -= len;
50 }
51
52 if (s->frame_size == 0) {
53 if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
54 len = s->sync(s, &frame_flag);
55 if (len == 0) {
56 /* no sync found : move by one byte (inefficient, but simple!) */
57 memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
58 s->inbuf_ptr--;
59 } else {
60 s->frame_size = len;
64 /* update codec info */ 61 /* update codec info */
65 avctx->sample_rate = s->sample_rate; 62 avctx->sample_rate = s->sample_rate;
66 /* allow downmixing to stereo (or mono for AC3) */ 63 /* allow downmixing to stereo (or mono for AC3) */
67 if(avctx->request_channels > 0 && 64 if(avctx->request_channels > 0 &&
68 avctx->request_channels < s->channels && 65 avctx->request_channels < s->channels &&
73 } else { 70 } else {
74 avctx->channels = s->channels; 71 avctx->channels = s->channels;
75 } 72 }
76 avctx->bit_rate = s->bit_rate; 73 avctx->bit_rate = s->bit_rate;
77 avctx->frame_size = s->samples; 74 avctx->frame_size = s->samples;
78
79 return i;
80 } 75 }
81 s->frame_in_buffer=1; 76 }
82 }else{ 77 } else {
78 if(s->inbuf_ptr - s->inbuf == s->frame_size){
79 *poutbuf = s->inbuf;
80 *poutbuf_size = s->frame_size;
81 s->inbuf_ptr = s->inbuf;
82 s->frame_size = 0;
83 break; 83 break;
84 } 84 }
85 } 85 }
86 } 86 }
87 87 return buf_ptr - buf;
88 ff_combine_frame(pc, END_NOT_FOUND, &buf, &buf_size);
89 s->remaining_size -= FFMIN(s->remaining_size, buf_size);
90 *poutbuf = NULL;
91 *poutbuf_size = 0;
92 return buf_size;
93 } 88 }