comparison oggvorbis.c @ 1920:9b87ed973dda libavcodec

kill obnoxious ogg_packet passing from demuxer to decoder
author michael
date Sun, 04 Apr 2004 02:07:15 +0000
parents 20e4d4511fd2
children 0ed2d7ecd1e9
comparison
equal deleted inserted replaced
1919:20e4d4511fd2 1920:9b87ed973dda
17 vorbis_dsp_state vd ; 17 vorbis_dsp_state vd ;
18 vorbis_block vb ; 18 vorbis_block vb ;
19 19
20 /* decoder */ 20 /* decoder */
21 vorbis_comment vc ; 21 vorbis_comment vc ;
22 ogg_packet op;
22 } OggVorbisContext ; 23 } OggVorbisContext ;
23 24
24 25
25 int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) { 26 int oggvorbis_init_encoder(vorbis_info *vi, AVCodecContext *avccontext) {
26 27
144 static int oggvorbis_decode_init(AVCodecContext *avccontext) { 145 static int oggvorbis_decode_init(AVCodecContext *avccontext) {
145 OggVorbisContext *context = avccontext->priv_data ; 146 OggVorbisContext *context = avccontext->priv_data ;
146 147
147 vorbis_info_init(&context->vi) ; 148 vorbis_info_init(&context->vi) ;
148 vorbis_comment_init(&context->vc) ; 149 vorbis_comment_init(&context->vc) ;
150 context->op.packetno= 0;
149 151
150 return 0 ; 152 return 0 ;
151 } 153 }
152 154
153 155
179 static int oggvorbis_decode_frame(AVCodecContext *avccontext, 181 static int oggvorbis_decode_frame(AVCodecContext *avccontext,
180 void *data, int *data_size, 182 void *data, int *data_size,
181 uint8_t *buf, int buf_size) 183 uint8_t *buf, int buf_size)
182 { 184 {
183 OggVorbisContext *context = avccontext->priv_data ; 185 OggVorbisContext *context = avccontext->priv_data ;
184 ogg_packet *op = (ogg_packet*)buf ;
185 float **pcm ; 186 float **pcm ;
187 ogg_packet *op= &context->op;
186 int samples, total_samples, total_bytes,i; 188 int samples, total_samples, total_bytes,i;
187 189
188 if(!buf_size){ 190 if(!buf_size){
189 //FIXME flush 191 //FIXME flush
190 *data_size=0; 192 *data_size=0;
191 return 0; 193 return 0;
192 } 194 }
193 195
194 op->packet = (char*)op + sizeof(ogg_packet) ; /* correct data pointer */ 196 op->packet = buf;
197 op->bytes = buf_size;
198 op->b_o_s = op->packetno == 0;
195 199
196 // av_log(avccontext, AV_LOG_DEBUG, "%d %d %d %lld %lld %d %d\n", op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno, buf_size, context->vi.rate); 200 // av_log(avccontext, AV_LOG_DEBUG, "%d %d %d %lld %lld %d %d\n", op->bytes, op->b_o_s, op->e_o_s, op->granulepos, op->packetno, buf_size, context->vi.rate);
197 201
198 /* for(i=0; i<op->bytes; i++) 202 /* for(i=0; i<op->bytes; i++)
199 av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]); 203 av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]);
200 av_log(avccontext, AV_LOG_DEBUG, "\n");*/ 204 av_log(avccontext, AV_LOG_DEBUG, "\n");*/
201 // op->b_o_s= op->packetno == 0;
202 if(op->packetno < 3) { 205 if(op->packetno < 3) {
203 if(vorbis_synthesis_headerin(&context->vi, &context->vc, op)<0){ 206 if(vorbis_synthesis_headerin(&context->vi, &context->vc, op)<0){
204 av_log(avccontext, AV_LOG_ERROR, "%lld. vorbis header damaged\n", op->packetno+1); 207 av_log(avccontext, AV_LOG_ERROR, "%lld. vorbis header damaged\n", op->packetno+1);
205 return -1; 208 return -1;
206 } 209 }
207 avccontext->channels = context->vi.channels ; 210 avccontext->channels = context->vi.channels ;
208 avccontext->sample_rate = context->vi.rate ; 211 avccontext->sample_rate = context->vi.rate ;
212 op->packetno++;
209 return buf_size ; 213 return buf_size ;
210 } 214 }
211 215
212 if(op->packetno == 3) { 216 if(op->packetno == 3) {
213 // av_log(avccontext, AV_LOG_INFO, "vorbis_decode: %d channel, %ldHz, encoder `%s'\n", 217 // av_log(avccontext, AV_LOG_INFO, "vorbis_decode: %d channel, %ldHz, encoder `%s'\n",
228 total_bytes += samples * 2 * context->vi.channels ; 232 total_bytes += samples * 2 * context->vi.channels ;
229 total_samples += samples ; 233 total_samples += samples ;
230 vorbis_synthesis_read(&context->vd, samples) ; 234 vorbis_synthesis_read(&context->vd, samples) ;
231 } 235 }
232 236
237 op->packetno++;
233 *data_size = total_bytes ; 238 *data_size = total_bytes ;
234 return buf_size ; 239 return buf_size ;
235 } 240 }
236 241
237 242