changeset 26037:bee99864f397

New member in demuxer_t: reference_clock. If it's != MP_NOPTS_VALUE ds_fill_buffer() will keep on demuxing until the pts of the next_pts is <= reference_clock. It guarantees the compliance with the buffering model indicated by the transmitter of the multiplex and a long-time stability of playback (at least for me). In any case up to a maximum of 64 packets are accumulated to prevent memory hogging and leaks.
author nicodvb
date Sat, 23 Feb 2008 10:31:44 +0000
parents 8d8c52a169ad
children 4f9a30caadff
files libmpdemux/demuxer.c libmpdemux/demuxer.h
diffstat 2 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libmpdemux/demuxer.c	Fri Feb 22 21:24:35 2008 +0000
+++ b/libmpdemux/demuxer.c	Sat Feb 23 10:31:44 2008 +0000
@@ -206,6 +206,7 @@
   memset(d,0,sizeof(demuxer_t));
   d->stream=stream;
   d->stream_pts = MP_NOPTS_VALUE;
+  d->reference_clock = MP_NOPTS_VALUE;
   d->movi_start=stream->start_pos;
   d->movi_end=stream->end_pos;
   d->seekable=1;
@@ -405,6 +406,7 @@
 // return value:
 //     0 = EOF
 //     1 = successful
+#define MAX_ACUMULATED_PACKETS 64
 int ds_fill_buffer(demux_stream_t *ds){
   demuxer_t *demux=ds->demuxer;
   if(ds->current) free_demux_packet(ds->current);
@@ -418,6 +420,13 @@
   while(1){
     if(ds->packs){
       demux_packet_t *p=ds->first;
+      if(demux->reference_clock != MP_NOPTS_VALUE) {
+        if((p->pts != MP_NOPTS_VALUE) && (p->pts > demux->reference_clock)
+            && (ds->packs < MAX_ACUMULATED_PACKETS)) {
+            if(demux_fill_buffer(demux,ds))
+              continue;
+        }
+      }
       // copy useful data:
       ds->buffer=p->buffer;
       ds->buffer_pos=0;
--- a/libmpdemux/demuxer.h	Fri Feb 22 21:24:35 2008 +0000
+++ b/libmpdemux/demuxer.h	Sat Feb 23 10:31:44 2008 +0000
@@ -194,6 +194,7 @@
   off_t movi_end;
   stream_t *stream;
   double stream_pts;       // current stream pts, if applicable (e.g. dvd)
+  double reference_clock;
   char *filename; ///< Needed by avs_check_file
   int synced;  // stream synced (used by mpeg)
   int type;    // demuxer type: mpeg PS, mpeg ES, avi, avi-ni, avi-nini, asf