Mercurial > libavcodec.hg
diff oggvorbis.c @ 2091:02a4fd7c606c libavcodec
flush audio encoder buffers at the end
fix vorbis in nut again
author | michael |
---|---|
date | Tue, 22 Jun 2004 21:14:01 +0000 |
parents | 141a9539e270 |
children | 0433866b1075 |
line wrap: on
line diff
--- a/oggvorbis.c Mon Jun 21 01:01:44 2004 +0000 +++ b/oggvorbis.c Tue Jun 22 21:14:01 2004 +0000 @@ -21,7 +21,6 @@ vorbis_block vb ; uint8_t buffer[BUFFER_SIZE]; int buffer_index; - int64_t fake_pts; //pts which libavformat will guess, HACK FIXME /* decoder */ vorbis_comment vc ; @@ -104,7 +103,7 @@ float **buffer ; ogg_packet op ; signed char *audio = data ; - int l, samples = OGGVORBIS_FRAME_SIZE ; + int l, samples = data ? OGGVORBIS_FRAME_SIZE : 0; buffer = vorbis_analysis_buffer(&context->vd, samples) ; @@ -125,6 +124,8 @@ vorbis_bitrate_addblock(&context->vb) ; while(vorbis_bitrate_flushpacket(&context->vd, &op)) { + if(op.bytes==1) //id love to say this is a hack, bad sadly its not, appearently the end of stream decission is in libogg + continue; memcpy(context->buffer + context->buffer_index, &op, sizeof(ogg_packet)); context->buffer_index += sizeof(ogg_packet); memcpy(context->buffer + context->buffer_index, op.packet, op.bytes); @@ -138,21 +139,15 @@ ogg_packet *op2= (ogg_packet*)context->buffer; op2->packet = context->buffer + sizeof(ogg_packet); - if(op2->granulepos <= context->fake_pts /*&& (context->fake_pts || context->buffer_index > 4*1024)*/){ - assert(op2->granulepos == context->fake_pts); - l= op2->bytes; + l= op2->bytes; + avccontext->coded_frame->pts= av_rescale(op2->granulepos, AV_TIME_BASE, avccontext->sample_rate); - memcpy(packets, op2->packet, l); - context->buffer_index -= l + sizeof(ogg_packet); - memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); - } + memcpy(packets, op2->packet, l); + context->buffer_index -= l + sizeof(ogg_packet); + memcpy(context->buffer, context->buffer + l + sizeof(ogg_packet), context->buffer_index); // av_log(avccontext, AV_LOG_DEBUG, "E%d\n", l); } - if(l || context->fake_pts){ - context->fake_pts += avccontext->frame_size; - } - return l; } @@ -163,19 +158,6 @@ vorbis_analysis_wrote(&context->vd, 0) ; /* notify vorbisenc this is EOF */ - /* We need to write all the remaining packets into the stream - * on closing */ - - av_log(avccontext, AV_LOG_ERROR, "fixme: not all packets written on oggvorbis_encode_close()\n") ; - -/* - while(vorbis_bitrate_flushpacket(&context->vd, &op)) { - memcpy(packets + l, &op, sizeof(ogg_packet)) ; - memcpy(packets + l + sizeof(ogg_packet), op.packet, op.bytes) ; - l += sizeof(ogg_packet) + op.bytes ; - } -*/ - vorbis_block_clear(&context->vb); vorbis_dsp_clear(&context->vd); vorbis_info_clear(&context->vi); @@ -194,7 +176,8 @@ sizeof(OggVorbisContext), oggvorbis_encode_init, oggvorbis_encode_frame, - oggvorbis_encode_close + oggvorbis_encode_close, + .capabilities= CODEC_CAP_DELAY, } ; @@ -313,4 +296,5 @@ NULL, oggvorbis_decode_close, oggvorbis_decode_frame, + .capabilities= CODEC_CAP_DELAY, } ;