diff options
author | Michael Niedermayer <michaelni@gmx.at> | 2004-04-04 14:39:20 +0000 |
---|---|---|
committer | Michael Niedermayer <michaelni@gmx.at> | 2004-04-04 14:39:20 +0000 |
commit | 6d8f985ecfb1cab04dc114307091282db6f16933 (patch) | |
tree | 1746d6c8ea874ee4a6ed565d38ce1a58b0adb893 /libavformat | |
parent | 7d1bbcd42fdb990dae849a1019e6b53cfe54a815 (diff) | |
download | ffmpeg-6d8f985ecfb1cab04dc114307091282db6f16933.tar.gz |
fix obnoxious ogg_packet passing from encoder to muxer
Originally committed as revision 2955 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavformat')
-rw-r--r-- | libavformat/ogg.c | 65 | ||||
-rw-r--r-- | libavformat/utils.c | 8 |
2 files changed, 41 insertions, 32 deletions
diff --git a/libavformat/ogg.c b/libavformat/ogg.c index ed5bc3f56c..3c8b1e2b9c 100644 --- a/libavformat/ogg.c +++ b/libavformat/ogg.c @@ -14,6 +14,9 @@ #include "avformat.h" #include "oggvorbis.h" +#undef NDEBUG +#include <assert.h> + #define DECODER_BUFFER_SIZE 4096 @@ -21,8 +24,7 @@ typedef struct OggContext { /* output */ ogg_stream_state os ; int header_handled ; - ogg_int64_t base_packet_no ; - ogg_int64_t base_granule_pos ; + ogg_packet op; /* input */ ogg_sync_state oy ; @@ -40,7 +42,9 @@ static int ogg_write_header(AVFormatContext *avfcontext) vorbis_block vb ; ogg_packet header, header_comm, header_code ; int n ; - + + av_set_pts_info(avfcontext, 60, 1, AV_TIME_BASE); + ogg_stream_init(&context->os, 31415); for(n = 0 ; n < avfcontext->nb_streams ; n++) { @@ -79,7 +83,6 @@ static int ogg_write_header(AVFormatContext *avfcontext) /* end of vorbis specific code */ context->header_handled = 0 ; - context->base_packet_no = 0 ; } return 0 ; @@ -88,13 +91,21 @@ static int ogg_write_header(AVFormatContext *avfcontext) static int ogg_write_packet(AVFormatContext *avfcontext, int stream_index, - const uint8_t *buf, int size, int64_t force_pts) + const uint8_t *buf, int size, int64_t pts) { OggContext *context = avfcontext->priv_data ; - ogg_packet *op ; + AVCodecContext *avctx= &avfcontext->streams[stream_index]->codec; + ogg_packet *op= &context->op; ogg_page og ; - int l = 0 ; - + + pts= av_rescale(pts, avctx->sample_rate, AV_TIME_BASE); + + if(!size){ +// av_log(avfcontext, AV_LOG_DEBUG, "zero packet\n"); + return 0; + } +// av_log(avfcontext, AV_LOG_DEBUG, "M%d\n", size); + /* flush header packets so audio starts on a new page */ if(!context->header_handled) { @@ -106,29 +117,21 @@ static int ogg_write_packet(AVFormatContext *avfcontext, context->header_handled = 1 ; } - while(l < size) { - op = (ogg_packet*)(buf + l) ; - op->packet = (uint8_t*) buf + l + sizeof( ogg_packet) ; /* fix data pointer */ - - if(!context->base_packet_no) { /* this is the first packet */ - context->base_packet_no = op->packetno ; - context->base_granule_pos = op->granulepos ; - } - - /* correct the fields in the packet -- essential for streaming */ - - op->packetno -= context->base_packet_no ; - op->granulepos -= context->base_granule_pos ; - - ogg_stream_packetin(&context->os, op) ; - l += sizeof(ogg_packet) + op->bytes ; - - while(ogg_stream_pageout(&context->os, &og)) { - put_buffer(&avfcontext->pb, og.header, og.header_len) ; - put_buffer(&avfcontext->pb, og.body, og.body_len) ; - put_flush_packet(&avfcontext->pb); - } - } + op->packet = (uint8_t*) buf; + op->bytes = size; + op->b_o_s = op->packetno == 0; + op->granulepos= pts; + + /* correct the fields in the packet -- essential for streaming */ + + ogg_stream_packetin(&context->os, op); + + while(ogg_stream_pageout(&context->os, &og)) { + put_buffer(&avfcontext->pb, og.header, og.header_len); + put_buffer(&avfcontext->pb, og.body, og.body_len); + put_flush_packet(&avfcontext->pb); + } + op->packetno++; return 0; } diff --git a/libavformat/utils.c b/libavformat/utils.c index c170c03577..14f965d697 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -1707,7 +1707,11 @@ int av_write_frame(AVFormatContext *s, int stream_index, const uint8_t *buf, switch (st->codec.codec_type) { case CODEC_TYPE_AUDIO: frame_size = get_audio_frame_size(&st->codec, size); - if (frame_size >= 0) { + + /* note, we skip the initial 0-size packets as they are most likely equal to the encoder delay, + but it would be better if we had the real timestamps from the encoder */ +// av_log(s, AV_LOG_DEBUG, "%d %lld %lld\n", size, st->pts.num, st->pts.val); + if (frame_size >= 0 && (size || st->pts.num!=st->pts.den>>1 || st->pts.val)) { av_frac_add(&st->pts, (int64_t)s->pts_den * frame_size); } @@ -1900,6 +1904,8 @@ int64_t parse_date(const char *datestr, int duration) const char *q; int is_utc, len; char lastch; + +#undef time time_t now = time(0); len = strlen(datestr); |