Mercurial > libavcodec.hg
comparison oggvorbis.c @ 2967:ef2149182f1c libavcodec
COSMETICS: Remove all trailing whitespace.
author | diego |
---|---|
date | Sat, 17 Dec 2005 18:14:38 +0000 |
parents | 6f8bcb169256 |
children | bfabfdf9ce55 |
comparison
equal
deleted
inserted
replaced
2966:564788471dd4 | 2967:ef2149182f1c |
---|---|
67 vorbis_comment_init(&context->vc); | 67 vorbis_comment_init(&context->vc); |
68 vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; | 68 vorbis_comment_add_tag(&context->vc, "encoder", LIBAVCODEC_IDENT) ; |
69 | 69 |
70 vorbis_analysis_headerout(&context->vd, &context->vc, &header, | 70 vorbis_analysis_headerout(&context->vd, &context->vc, &header, |
71 &header_comm, &header_code); | 71 &header_comm, &header_code); |
72 | 72 |
73 len = header.bytes + header_comm.bytes + header_code.bytes; | 73 len = header.bytes + header_comm.bytes + header_code.bytes; |
74 avccontext->extradata_size= 64 + len + len/255; | 74 avccontext->extradata_size= 64 + len + len/255; |
75 p = avccontext->extradata= av_mallocz(avccontext->extradata_size); | 75 p = avccontext->extradata= av_mallocz(avccontext->extradata_size); |
76 p[0] = 2; | 76 p[0] = 2; |
77 offset = 1; | 77 offset = 1; |
83 offset += header_comm.bytes; | 83 offset += header_comm.bytes; |
84 memcpy(&p[offset], header_code.packet, header_code.bytes); | 84 memcpy(&p[offset], header_code.packet, header_code.bytes); |
85 offset += header_code.bytes; | 85 offset += header_code.bytes; |
86 avccontext->extradata_size = offset; | 86 avccontext->extradata_size = offset; |
87 avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size); | 87 avccontext->extradata= av_realloc(avccontext->extradata, avccontext->extradata_size); |
88 | 88 |
89 /* vorbis_block_clear(&context->vb); | 89 /* vorbis_block_clear(&context->vb); |
90 vorbis_dsp_clear(&context->vd); | 90 vorbis_dsp_clear(&context->vd); |
91 vorbis_info_clear(&context->vi);*/ | 91 vorbis_info_clear(&context->vi);*/ |
92 vorbis_comment_clear(&context->vc); | 92 vorbis_comment_clear(&context->vc); |
93 | 93 |
94 avccontext->frame_size = OGGVORBIS_FRAME_SIZE ; | 94 avccontext->frame_size = OGGVORBIS_FRAME_SIZE ; |
95 | 95 |
96 avccontext->coded_frame= avcodec_alloc_frame(); | 96 avccontext->coded_frame= avcodec_alloc_frame(); |
97 avccontext->coded_frame->key_frame= 1; | 97 avccontext->coded_frame->key_frame= 1; |
98 | 98 |
99 return 0 ; | 99 return 0 ; |
100 } | 100 } |
101 | 101 |
102 | 102 |
103 static int oggvorbis_encode_frame(AVCodecContext *avccontext, | 103 static int oggvorbis_encode_frame(AVCodecContext *avccontext, |
119 for(l = 0 ; l < samples ; l++){ | 119 for(l = 0 ; l < samples ; l++){ |
120 buffer[0][l]=audio[l*2]/32768.f; | 120 buffer[0][l]=audio[l*2]/32768.f; |
121 buffer[1][l]=audio[l*2+1]/32768.f; | 121 buffer[1][l]=audio[l*2+1]/32768.f; |
122 } | 122 } |
123 } | 123 } |
124 | 124 |
125 vorbis_analysis_wrote(&context->vd, samples) ; | 125 vorbis_analysis_wrote(&context->vd, samples) ; |
126 | 126 |
127 while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) { | 127 while(vorbis_analysis_blockout(&context->vd, &context->vb) == 1) { |
128 vorbis_analysis(&context->vb, NULL); | 128 vorbis_analysis(&context->vb, NULL); |
129 vorbis_bitrate_addblock(&context->vb) ; | 129 vorbis_bitrate_addblock(&context->vb) ; |
130 | 130 |
159 | 159 |
160 | 160 |
161 static int oggvorbis_encode_close(AVCodecContext *avccontext) { | 161 static int oggvorbis_encode_close(AVCodecContext *avccontext) { |
162 OggVorbisContext *context = avccontext->priv_data ; | 162 OggVorbisContext *context = avccontext->priv_data ; |
163 /* ogg_packet op ; */ | 163 /* ogg_packet op ; */ |
164 | 164 |
165 vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */ | 165 vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */ |
166 | 166 |
167 vorbis_block_clear(&context->vb); | 167 vorbis_block_clear(&context->vb); |
168 vorbis_dsp_clear(&context->vd); | 168 vorbis_dsp_clear(&context->vd); |
169 vorbis_info_clear(&context->vi); | 169 vorbis_info_clear(&context->vi); |
170 | 170 |
171 av_freep(&avccontext->coded_frame); | 171 av_freep(&avccontext->coded_frame); |
172 av_freep(&avccontext->extradata); | 172 av_freep(&avccontext->extradata); |
173 | 173 |
174 return 0 ; | 174 return 0 ; |
175 } | 175 } |
176 | 176 |
177 | 177 |
178 AVCodec oggvorbis_encoder = { | 178 AVCodec oggvorbis_encoder = { |
254 avccontext->channels = context->vi.channels; | 254 avccontext->channels = context->vi.channels; |
255 avccontext->sample_rate = context->vi.rate; | 255 avccontext->sample_rate = context->vi.rate; |
256 avccontext->time_base= (AVRational){1, avccontext->sample_rate}; | 256 avccontext->time_base= (AVRational){1, avccontext->sample_rate}; |
257 | 257 |
258 vorbis_synthesis_init(&context->vd, &context->vi); | 258 vorbis_synthesis_init(&context->vd, &context->vi); |
259 vorbis_block_init(&context->vd, &context->vb); | 259 vorbis_block_init(&context->vd, &context->vb); |
260 | 260 |
261 return 0 ; | 261 return 0 ; |
262 } | 262 } |
263 | 263 |
264 | 264 |
265 static inline int conv(int samples, float **pcm, char *buf, int channels) { | 265 static inline int conv(int samples, float **pcm, char *buf, int channels) { |
266 int i, j, val ; | 266 int i, j, val ; |
267 ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ; | 267 ogg_int16_t *ptr, *data = (ogg_int16_t*)buf ; |
268 float *mono ; | 268 float *mono ; |
269 | 269 |
270 for(i = 0 ; i < channels ; i++){ | 270 for(i = 0 ; i < channels ; i++){ |
271 ptr = &data[i]; | 271 ptr = &data[i]; |
272 mono = pcm[i] ; | 272 mono = pcm[i] ; |
273 | 273 |
274 for(j = 0 ; j < samples ; j++) { | 274 for(j = 0 ; j < samples ; j++) { |
275 | 275 |
276 val = mono[j] * 32767.f; | 276 val = mono[j] * 32767.f; |
277 | 277 |
278 if(val > 32767) val = 32767 ; | 278 if(val > 32767) val = 32767 ; |
279 if(val < -32768) val = -32768 ; | 279 if(val < -32768) val = -32768 ; |
280 | 280 |
281 *ptr = val ; | 281 *ptr = val ; |
282 ptr += channels; | 282 ptr += channels; |
283 } | 283 } |
284 } | 284 } |
285 | 285 |
286 return 0 ; | 286 return 0 ; |
287 } | 287 } |
288 | 288 |
289 | 289 |
290 static int oggvorbis_decode_frame(AVCodecContext *avccontext, | 290 static int oggvorbis_decode_frame(AVCodecContext *avccontext, |
291 void *data, int *data_size, | 291 void *data, int *data_size, |
292 uint8_t *buf, int buf_size) | 292 uint8_t *buf, int buf_size) |
293 { | 293 { |
294 OggVorbisContext *context = avccontext->priv_data ; | 294 OggVorbisContext *context = avccontext->priv_data ; |
295 float **pcm ; | 295 float **pcm ; |
296 ogg_packet *op= &context->op; | 296 ogg_packet *op= &context->op; |
297 int samples, total_samples, total_bytes; | 297 int samples, total_samples, total_bytes; |
298 | 298 |
299 if(!buf_size){ | 299 if(!buf_size){ |
300 //FIXME flush | 300 //FIXME flush |
301 return 0; | 301 return 0; |
302 } | 302 } |
303 | 303 |
304 op->packet = buf; | 304 op->packet = buf; |
305 op->bytes = buf_size; | 305 op->bytes = buf_size; |
306 | 306 |
307 // 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); | 307 // 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); |
308 | 308 |
309 /* for(i=0; i<op->bytes; i++) | 309 /* for(i=0; i<op->bytes; i++) |
310 av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]); | 310 av_log(avccontext, AV_LOG_DEBUG, "%02X ", op->packet[i]); |
311 av_log(avccontext, AV_LOG_DEBUG, "\n");*/ | 311 av_log(avccontext, AV_LOG_DEBUG, "\n");*/ |
312 | 312 |
313 if(vorbis_synthesis(&context->vb, op) == 0) | 313 if(vorbis_synthesis(&context->vb, op) == 0) |
314 vorbis_synthesis_blockin(&context->vd, &context->vb) ; | 314 vorbis_synthesis_blockin(&context->vd, &context->vb) ; |
315 | 315 |
316 total_samples = 0 ; | 316 total_samples = 0 ; |
317 total_bytes = 0 ; | 317 total_bytes = 0 ; |
318 | 318 |
319 while((samples = vorbis_synthesis_pcmout(&context->vd, &pcm)) > 0) { | 319 while((samples = vorbis_synthesis_pcmout(&context->vd, &pcm)) > 0) { |
320 conv(samples, pcm, (char*)data + total_bytes, context->vi.channels) ; | 320 conv(samples, pcm, (char*)data + total_bytes, context->vi.channels) ; |
321 total_bytes += samples * 2 * context->vi.channels ; | 321 total_bytes += samples * 2 * context->vi.channels ; |
322 total_samples += samples ; | 322 total_samples += samples ; |
323 vorbis_synthesis_read(&context->vd, samples) ; | 323 vorbis_synthesis_read(&context->vd, samples) ; |
324 } | 324 } |
325 | 325 |
326 *data_size = total_bytes ; | 326 *data_size = total_bytes ; |
327 return buf_size ; | 327 return buf_size ; |
328 } | 328 } |
329 | 329 |
330 | 330 |
331 static int oggvorbis_decode_close(AVCodecContext *avccontext) { | 331 static int oggvorbis_decode_close(AVCodecContext *avccontext) { |
332 OggVorbisContext *context = avccontext->priv_data ; | 332 OggVorbisContext *context = avccontext->priv_data ; |
333 | 333 |
334 vorbis_info_clear(&context->vi) ; | 334 vorbis_info_clear(&context->vi) ; |
335 vorbis_comment_clear(&context->vc) ; | 335 vorbis_comment_clear(&context->vc) ; |
336 | 336 |
337 return 0 ; | 337 return 0 ; |
338 } | 338 } |