Make sure decvobsub.c generates valid timestamps
authorjstebbins <jstebbins.hb@gmail.com>
Tue, 15 Nov 2011 21:36:45 +0000 (21:36 +0000)
committerjstebbins <jstebbins.hb@gmail.com>
Tue, 15 Nov 2011 21:36:45 +0000 (21:36 +0000)
sync.c expects that timestamps will all be resolved by the time buffers
reach it.  Reader will invalidate timestamps while waiting to
resynchronize the SCR.  So decoders (inparticular decvobsub) need to
extrapolate timestamps when they are not supplied.

git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4352 b64f7644-9d1e-0410-96f1-a4d463321fa5

libhb/decvobsub.c
libhb/muxmp4.c

index 9bd1b7808bcc1939d7ba5d38aa1239c529d61947..fcada87d1f3f56b77c144ebd3b03cca5a95d4743 100644 (file)
@@ -61,7 +61,7 @@ int decsubInit( hb_work_object_t * w, hb_job_t * job )
     w->private_data = pv;
 
     pv->job = job;
-    pv->pts = -1;
+    pv->pts = 0;
     
     // Warn if the input color palette is empty
     int paletteEmpty = 1;
@@ -116,7 +116,10 @@ int decsubWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
             pv->buf->id = in->id;
             pv->buf->sequence = in->sequence;
             pv->size_got = in->size;
-            pv->pts      = in->start;
+            if( in->start >= 0 )
+            {
+                pv->pts      = in->start;
+            }
         }
     }
     else
@@ -163,7 +166,12 @@ int decsubWork( hb_work_object_t * w, hb_buffer_t ** buf_in,
         pv->size_sub = 0;
         pv->size_got = 0;
         pv->size_rle = 0;
-        pv->pts      = -1;
+
+        // If we don't get a valid next timestamp, use the stop time
+        // of the current sub as the start of the next.
+        // This can happen if reader invalidates timestamps while 
+        // waiting for an audio to update the SCR.
+        pv->pts      = pv->pts_stop;
     }
 
     return HB_WORK_OK;
@@ -207,7 +215,7 @@ static void ParseControls( hb_work_object_t * w )
     int command;
     int date, next;
 
-    pv->pts_start = 0;
+    pv->pts_start = -1;
     pv->pts_stop  = -1;
     pv->pts_forced  = 0;
 
@@ -377,6 +385,17 @@ static void ParseControls( hb_work_object_t * w )
         }
         i = next;
     }
+    // Generate timestamps if they are not set
+    if( pv->pts_start == -1 )
+    {
+        // Set pts to end of last sub if the start time is unknown.
+        pv->pts_start = pv->pts;
+    }
+    if( pv->pts_stop == -1 )
+    {
+        // Set durtion to 10 sec if unknown.
+        pv->pts_stop = pv->pts + 90000L * 10;
+    }
 }
 
 /***********************************************************************
index 5234c5a7a721106519de86aa28922f746e388e00..d03326b80c53685a35e8b56e3c6597e5ab59900e 100644 (file)
@@ -1106,6 +1106,9 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
             {
                 int64_t duration;
 
+                if( buf->start < 0 )
+                    buf->start = mux_data->sum_dur;
+
                 if( buf->stop < 0 )
                     duration = 90000L * 10;
                 else
@@ -1175,6 +1178,9 @@ static int MP4Mux( hb_mux_object_t * m, hb_mux_data_t * mux_data,
         {
             int64_t duration;
 
+            if( buf->start < 0 )
+                buf->start = mux_data->sum_dur;
+
             if( buf->stop < 0 )
                 duration = 90000L * 10;
             else