diff libmpdemux/demuxer.c @ 31558:a3a50df246f8

Move the subtitle pts handling code to demuxer.c This also fixes endpts using first->endpts instead of current->endpts and the move should avoid missing such fixes in the future by having all related code in one place.
author reimar
date Fri, 02 Jul 2010 21:14:42 +0000
parents d2fd0e4d0b9a
children cd81fce1f010
line wrap: on
line diff
--- a/libmpdemux/demuxer.c	Fri Jul 02 19:59:02 2010 +0000
+++ b/libmpdemux/demuxer.c	Fri Jul 02 21:14:42 2010 +0000
@@ -794,16 +794,42 @@
     return len;
 }
 
-int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start)
+/**
+ * Get a subtitle packet. In particular avoid reading the stream.
+ * \param pts input: maximum pts value of subtitle packet. NOPTS or NULL for any.
+ *            output: start/referece pts of subtitle
+ *            May be NULL.
+ * \param endpts output: pts for end of display time. May be NULL.
+ * \return -1 if no packet is available
+ */
+int ds_get_packet_sub(demux_stream_t *ds, unsigned char **start,
+                      double *pts, double *endpts)
 {
     int len;
+    *start = NULL;
+    // initialize pts
+    if (pts)
+        *pts    = MP_NOPTS_VALUE;
+    if (endpts)
+        *endpts = MP_NOPTS_VALUE;
     if (ds->buffer_pos >= ds->buffer_size) {
-        *start = NULL;
         if (!ds->packs)
             return -1;  // no sub
         if (!ds_fill_buffer(ds))
             return -1;  // EOF
     }
+    // only start of buffer has valid pts
+    if (ds->buffer_pos == 0) {
+        if (endpts)
+            *endpts = ds->current->endpts;
+        if (pts) {
+            *pts    = ds->current->pts;
+            // check if we are too early
+            if (*pts != MP_NOPTS_VALUE && ds->current->pts != MP_NOPTS_VALUE &&
+                ds->current->pts > *pts)
+                return -1;
+        }
+    }
     len = ds->buffer_size - ds->buffer_pos;
     *start = &ds->buffer[ds->buffer_pos];
     ds->buffer_pos += len;