]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: for initial pts value, scan more packets (now 6)
authorJaroslav Kysela <perex@perex.cz>
Thu, 23 Oct 2014 13:23:24 +0000 (15:23 +0200)
committerJaroslav Kysela <perex@perex.cz>
Thu, 23 Oct 2014 13:24:41 +0000 (15:24 +0200)
src/timeshift.c
src/timeshift/private.h

index 12e7601ffd0896680c516ec382ffb4fe3096c304..de4b0675a03f0aa3a9bedc873ca0dd0ba6fe1fd8 100644 (file)
@@ -170,8 +170,21 @@ static void timeshift_input
 
     /* Record (one-off) PTS delta */
     if (sm->sm_type == SMT_PACKET && ts->pts_delta == PTS_UNSET) {
-      if (pkt->pkt_pts != PTS_UNSET)
-        ts->pts_delta = getmonoclock() - ts_rescale(pkt->pkt_pts, 1000000);
+      if (pkt->pkt_pts != PTS_UNSET) {
+        int i;
+        int64_t smallest = INT64_MAX;
+        for (i = 0; i < ARRAY_SIZE(ts->pts_val); i++) {
+          int64_t i64 = ts->pts_val[i];
+          if (i64 == PTS_UNSET) {
+            ts->pts_val[i] = pkt->pkt_pts;
+            break;
+          }
+          if (i64 < smallest)
+            smallest = i64;
+        }
+        if (i >= ARRAY_SIZE(ts->pts_val))
+          ts->pts_delta = getmonoclock() - ts_rescale(smallest, 1000000);
+      }
     }
 
     /* Buffer to disk */
@@ -256,6 +269,7 @@ streaming_target_t *timeshift_create
   (streaming_target_t *out, time_t max_time)
 {
   timeshift_t *ts = calloc(1, sizeof(timeshift_t));
+  int i;
 
   /* Must hold global lock */
   lock_assert(&global_lock);
@@ -271,6 +285,8 @@ streaming_target_t *timeshift_create
   ts->id         = timeshift_index;
   ts->ondemand   = timeshift_ondemand;
   ts->pts_delta  = PTS_UNSET;
+  for (i = 0; i < ARRAY_SIZE(ts->pts_val); i++)
+    ts->pts_val[i] = PTS_UNSET;
   pthread_mutex_init(&ts->rdwr_mutex, NULL);
   pthread_mutex_init(&ts->state_mutex, NULL);
 
index 314fe0c7e636f02d8eb6e1ed73ab9607d70f7252..db72d402782c141b29b94488d5ca8931ea43e2ce 100644 (file)
@@ -83,6 +83,7 @@ typedef struct timeshift {
   time_t                      max_time;   ///< Maximum period to shift
   int                         ondemand;   ///< Whether this is an on-demand timeshift
   int64_t                     pts_delta;  ///< Delta between system clock and PTS
+  int64_t                     pts_val[6]; ///< Decision PTS values for multiple packets
 
   enum {
     TS_INIT,