From e6338c5858795c42ca45afbabe8b765d8050db58 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 26 Jan 2006 19:32:07 +0000 Subject: change muxer_write_chunk() so that pts/dts _could_ be passed from encoder to muxer git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@17488 b3059339-0415-0410-9bf9-f77b7e298cf2 --- libmpdemux/muxer.c | 29 ++++++++++++++--------------- libmpdemux/muxer.h | 8 +++++--- libmpdemux/muxer_avi.c | 2 +- libmpdemux/muxer_lavf.c | 2 +- libmpdemux/muxer_mpeg.c | 2 +- libmpdemux/muxer_rawaudio.c | 2 +- libmpdemux/muxer_rawvideo.c | 2 +- 7 files changed, 24 insertions(+), 23 deletions(-) (limited to 'libmpdemux') diff --git a/libmpdemux/muxer.c b/libmpdemux/muxer.c index e2da4efa3b..0a075886e6 100644 --- a/libmpdemux/muxer.c +++ b/libmpdemux/muxer.c @@ -52,9 +52,12 @@ muxer_t *muxer_new_muxer(int type,FILE *f){ /* buffer frames until we either: * (a) have at least one frame from each stream * (b) run out of memory */ -void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags) { +void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts) { + if(dts == MP_NOPTS_VALUE) dts= s->timer; + if(pts == MP_NOPTS_VALUE) pts= s->timer; // this is wrong + if (s->muxer->muxbuf_skip_buffer) { - s->muxer->cont_write_chunk(s, len, flags); + s->muxer->cont_write_chunk(s, len, flags, dts, pts); } else { int num = s->muxer->muxbuf_num++; @@ -70,7 +73,8 @@ void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags) { /* buffer this frame */ buf->stream = s; - buf->timer = s->timer; + buf->dts= dts; + buf->pts= pts; buf->len = len; buf->flags = flags; buf->buffer = malloc(len * sizeof (unsigned char)); @@ -89,11 +93,6 @@ void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags) { /* see if we can flush buffer now */ if (s->muxer->muxbuf_skip_buffer) { - muxbuf_t *tmp_buf = malloc(sizeof(muxbuf_t)); - if (!tmp_buf) { - mp_msg(MSGT_MUXER, MSGL_FATAL, MSGTR_MuxbufMallocErr); - return; - } mp_msg(MSGT_MUXER, MSGL_V, MSGTR_MuxbufSending, s->muxer->muxbuf_num); /* fix parameters for all streams */ @@ -109,23 +108,23 @@ void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags) { /* send all buffered frames to muxer */ for (num = 0; num < s->muxer->muxbuf_num; ++num) { + muxbuf_t tmp_buf; buf = s->muxer->muxbuf + num; s = buf->stream; /* 1. save timer and buffer (might have changed by now) */ - tmp_buf->timer = s->timer; - tmp_buf->buffer = s->buffer; + tmp_buf.dts = s->timer; + tmp_buf.buffer = s->buffer; /* 2. move stored timer and buffer into stream and mux it */ - s->timer = buf->timer; + s->timer = buf->dts; s->buffer = buf->buffer; - s->muxer->cont_write_chunk(s, buf->len, buf->flags); + s->muxer->cont_write_chunk(s, buf->len, buf->flags, buf->dts, buf->pts); /* 3. restore saved timer and buffer */ - s->timer = tmp_buf->timer; - s->buffer = tmp_buf->buffer; + s->timer = tmp_buf.dts; + s->buffer = tmp_buf.buffer; } - free(tmp_buf); free(s->muxer->muxbuf); s->muxer->muxbuf_num = 0; diff --git a/libmpdemux/muxer.h b/libmpdemux/muxer.h index 353da665e7..fedbad64f8 100644 --- a/libmpdemux/muxer.h +++ b/libmpdemux/muxer.h @@ -76,7 +76,7 @@ typedef struct muxer_t{ int muxbuf_skip_buffer; // functions: void (*fix_stream_parameters)(muxer_stream_t *); - void (*cont_write_chunk)(muxer_stream_t *,size_t,unsigned int); + void (*cont_write_chunk)(muxer_stream_t *,size_t,unsigned int, double dts, double pts); void (*cont_write_header)(struct muxer_t *); void (*cont_write_index)(struct muxer_t *); muxer_stream_t* (*cont_new_stream)(struct muxer_t *,int); @@ -87,17 +87,19 @@ typedef struct muxer_t{ /* muxer frame buffer */ typedef struct muxbuf_t { muxer_stream_t *stream; /* pointer back to corresponding stream */ - double timer; /* snapshot of stream timer */ + double dts; /* decode timestamp / time at which this packet should be feeded into the decoder */ + double pts; /* presentation timestamp / time at which the data in this packet will be presented to the user */ unsigned char *buffer; size_t len; unsigned int flags; } muxbuf_t; +#define MP_NOPTS_VALUE (-1LL<<63) //both int64_t and double should be able to represent this exactly muxer_t *muxer_new_muxer(int type,FILE *); #define muxer_new_stream(muxer,a) muxer->cont_new_stream(muxer,a) #define muxer_stream_fix_parameters(muxer, a) muxer->fix_stream_parameters(a) -void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags); +void muxer_write_chunk(muxer_stream_t *s, size_t len, unsigned int flags, double dts, double pts); #define muxer_write_header(muxer) muxer->cont_write_header(muxer) #define muxer_write_index(muxer) muxer->cont_write_index(muxer) diff --git a/libmpdemux/muxer_avi.c b/libmpdemux/muxer_avi.c index 32d47bc947..7169a8a4b0 100644 --- a/libmpdemux/muxer_avi.c +++ b/libmpdemux/muxer_avi.c @@ -191,7 +191,7 @@ static void avifile_odml_new_riff(muxer_t *muxer) static void avifile_write_header(muxer_t *muxer); -static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){ +static void avifile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){ off_t rifflen; muxer_t *muxer=s->muxer; struct avi_stream_info *si = s->priv; diff --git a/libmpdemux/muxer_lavf.c b/libmpdemux/muxer_lavf.c index 5ae2ab4f19..88aa1dfc96 100644 --- a/libmpdemux/muxer_lavf.c +++ b/libmpdemux/muxer_lavf.c @@ -248,7 +248,7 @@ static void fix_parameters(muxer_stream_t *stream) } } -static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags) +static void write_chunk(muxer_stream_t *stream, size_t len, unsigned int flags, double dts, double pts) { muxer_t *muxer = (muxer_t*) stream->muxer; muxer_priv_t *priv = (muxer_priv_t *) muxer->priv; diff --git a/libmpdemux/muxer_mpeg.c b/libmpdemux/muxer_mpeg.c index 58c8646bb7..59751b17f8 100644 --- a/libmpdemux/muxer_mpeg.c +++ b/libmpdemux/muxer_mpeg.c @@ -2349,7 +2349,7 @@ static int parse_audio(muxer_stream_t *s, int finalize, int *nf, double *timer) -static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){ +static void mpegfile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts_arg, double pts_arg){ size_t ptr=0, sz = 0; uint64_t pts, tmp; muxer_t *muxer = s->muxer; diff --git a/libmpdemux/muxer_rawaudio.c b/libmpdemux/muxer_rawaudio.c index 71bf56628e..a7132d227b 100644 --- a/libmpdemux/muxer_rawaudio.c +++ b/libmpdemux/muxer_rawaudio.c @@ -45,7 +45,7 @@ static muxer_stream_t* rawaudiofile_new_stream(muxer_t *muxer,int type){ return s; } -static void rawaudiofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){ +static void rawaudiofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){ muxer_t *muxer=s->muxer; // write out the chunk: diff --git a/libmpdemux/muxer_rawvideo.c b/libmpdemux/muxer_rawvideo.c index 00c4436562..fda4eb8bac 100644 --- a/libmpdemux/muxer_rawvideo.c +++ b/libmpdemux/muxer_rawvideo.c @@ -50,7 +50,7 @@ static void write_rawvideo_chunk(FILE *f,int len,void* data){ } } -static void rawvideofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags){ +static void rawvideofile_write_chunk(muxer_stream_t *s,size_t len,unsigned int flags, double dts, double pts){ muxer_t *muxer=s->muxer; // write out the chunk: -- cgit v1.2.3