comparison faad.c @ 3097:41fb9bda307d libavcodec

decode adts aac streams
author mru
date Wed, 08 Feb 2006 00:30:58 +0000
parents 0b546eab515d
children c7d2c122a718
comparison
equal deleted inserted replaced
3096:966b3f321af0 3097:41fb9bda307d
47 #endif 47 #endif
48 48
49 typedef struct { 49 typedef struct {
50 void* handle; /* dlopen handle */ 50 void* handle; /* dlopen handle */
51 void* faac_handle; /* FAAD library handle */ 51 void* faac_handle; /* FAAD library handle */
52 int frame_size;
53 int sample_size; 52 int sample_size;
54 int flags; 53 int init;
55 54
56 /* faad calls */ 55 /* faad calls */
57 faacDecHandle FAADAPI (*faacDecOpen)(void); 56 faacDecHandle FAADAPI (*faacDecOpen)(void);
58 faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder); 57 faacDecConfigurationPtr FAADAPI (*faacDecGetCurrentConfiguration)(faacDecHandle hDecoder);
59 #ifndef FAAD2_VERSION 58 #ifndef FAAD2_VERSION
109 #else 108 #else
110 unsigned char channels; 109 unsigned char channels;
111 #endif 110 #endif
112 int r = 0; 111 int r = 0;
113 112
114 if (avctx->extradata) 113 if (avctx->extradata){
115 r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata, 114 r = s->faacDecInit2(s->faac_handle, (uint8_t*) avctx->extradata,
116 avctx->extradata_size, 115 avctx->extradata_size,
117 &samplerate, &channels); 116 &samplerate, &channels);
118 // else r = s->faacDecInit(s->faac_handle ... ); 117 if (r < 0){
119 118 av_log(avctx, AV_LOG_ERROR,
120 if (r < 0) 119 "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n",
121 av_log(avctx, AV_LOG_ERROR, "faacDecInit2 failed r:%d sr:%ld ch:%ld s:%d\n", 120 r, samplerate, (long)channels, avctx->extradata_size);
122 r, samplerate, (long)channels, avctx->extradata_size); 121 } else {
123 avctx->sample_rate = samplerate; 122 avctx->sample_rate = samplerate;
124 avctx->channels = channels; 123 avctx->channels = channels;
124 s->init = 1;
125 }
126 }
125 127
126 return r; 128 return r;
127 } 129 }
128 130
129 static int faac_decode_frame(AVCodecContext *avctx, 131 static int faac_decode_frame(AVCodecContext *avctx,
153 *data_size = samples; 155 *data_size = samples;
154 return (buf_size < (int)bytesconsumed) 156 return (buf_size < (int)bytesconsumed)
155 ? buf_size : (int)bytesconsumed; 157 ? buf_size : (int)bytesconsumed;
156 #else 158 #else
157 159
160 if(!s->init){
161 unsigned long srate;
162 unsigned char channels;
163 int r = faacDecInit(s->faac_handle, buf, buf_size, &srate, &channels);
164 if(r < 0){
165 av_log(avctx, AV_LOG_ERROR, "faac: codec init failed: %s\n",
166 s->faacDecGetErrorMessage(frame_info.error));
167 return 0;
168 }
169 avctx->sample_rate = srate;
170 avctx->channels = channels;
171 s->init = 1;
172 }
173
158 out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size); 174 out = s->faacDecDecode(s->faac_handle, &frame_info, (unsigned char*)buf, (unsigned long)buf_size);
159 175
160 if (frame_info.error > 0) { 176 if (frame_info.error > 0) {
161 av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n", 177 av_log(avctx, AV_LOG_ERROR, "faac: frame decoding failed: %s\n",
162 s->faacDecGetErrorMessage(frame_info.error)); 178 s->faacDecGetErrorMessage(frame_info.error));