comparison aac_ac3_parser.c @ 6642:866b9ade048c libavcodec

Change aac and ac3 parsers to use ff_combine_frame().
author michael
date Sat, 19 Apr 2008 01:50:40 +0000
parents 1980eba5fd0e
children 4d04fcb5e1e4
comparison
equal deleted inserted replaced
6641:25a963680a88 6642:866b9ade048c
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 const uint8_t *buf_ptr; 32 ParseContext *pc = &s->pc;
33 int len; 33 int len, i;
34 34
35 *poutbuf = NULL; 35 i=END_NOT_FOUND;
36 *poutbuf_size = 0; 36 if(s->remaining_size <= buf_size){
37 if(s->remaining_size){
38 i= s->remaining_size;
39 s->remaining_size = 0;
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)))
45 break;
46 }
47 if(len<=0){
48 i=END_NOT_FOUND;
49 }else{
50 i-= s->header_size -1;
51 s->remaining_size = len + i;
52 }
53 }
54 }
37 55
38 buf_ptr = buf; 56 if(ff_combine_frame(pc, i, &buf, &buf_size)<0){
39 while (buf_size > 0) { 57 s->remaining_size -= FFMIN(s->remaining_size, buf_size);
40 int size_needed= s->frame_size ? s->frame_size : s->header_size; 58 *poutbuf = NULL;
41 len = s->inbuf_ptr - s->inbuf; 59 *poutbuf_size = 0;
60 return buf_size;
61 }
42 62
43 if(len<size_needed){ 63 *poutbuf = buf;
44 len = FFMIN(size_needed - len, buf_size); 64 *poutbuf_size = buf_size;
45 memcpy(s->inbuf_ptr, buf_ptr, len);
46 buf_ptr += len;
47 s->inbuf_ptr += len;
48 buf_size -= len;
49 }
50 65
51 if (s->frame_size == 0) {
52 if ((s->inbuf_ptr - s->inbuf) == s->header_size) {
53 len = s->sync(s);
54 if (len == 0) {
55 /* no sync found : move by one byte (inefficient, but simple!) */
56 memmove(s->inbuf, s->inbuf + 1, s->header_size - 1);
57 s->inbuf_ptr--;
58 } else {
59 s->frame_size = len;
60 /* update codec info */ 66 /* update codec info */
61 avctx->sample_rate = s->sample_rate; 67 avctx->sample_rate = s->sample_rate;
62 /* allow downmixing to stereo (or mono for AC3) */ 68 /* allow downmixing to stereo (or mono for AC3) */
63 if(avctx->request_channels > 0 && 69 if(avctx->request_channels > 0 &&
64 avctx->request_channels < s->channels && 70 avctx->request_channels < s->channels &&
69 } else { 75 } else {
70 avctx->channels = s->channels; 76 avctx->channels = s->channels;
71 } 77 }
72 avctx->bit_rate = s->bit_rate; 78 avctx->bit_rate = s->bit_rate;
73 avctx->frame_size = s->samples; 79 avctx->frame_size = s->samples;
74 } 80
75 } 81 return i;
76 } else {
77 if(s->inbuf_ptr - s->inbuf == s->frame_size){
78 *poutbuf = s->inbuf;
79 *poutbuf_size = s->frame_size;
80 s->inbuf_ptr = s->inbuf;
81 s->frame_size = 0;
82 break;
83 }
84 }
85 }
86 return buf_ptr - buf;
87 } 82 }