]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: move the pts_delta init code to a function
authorJaroslav Kysela <perex@perex.cz>
Fri, 24 Oct 2014 07:02:21 +0000 (09:02 +0200)
committerJaroslav Kysela <perex@perex.cz>
Fri, 24 Oct 2014 07:02:21 +0000 (09:02 +0200)
src/timeshift.c

index 6f1ab5decc71f9f520933a6460c9a5b9d8de69dd..c677531243502072d5540064cddcb15a5ebecc26 100644 (file)
@@ -111,6 +111,37 @@ void timeshift_save ( void )
   hts_settings_save(m, "timeshift/config");
 }
 
+/*
+ * Decode initial time diff
+ *
+ * Gather some packets and select the lowest pts to identify
+ * the correct start. Note that for timeshift, the tsfix
+ * stream plugin is applied, so the starting pts should be
+ * near zero. If not - it's a bug.
+ */
+static void
+timeshift_set_pts_delta ( timeshift_t *ts, int64_t pts )
+{
+  int i;
+  int64_t smallest = INT64_MAX;
+
+  if (pts == PTS_UNSET)
+    return;
+
+  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] = pts;
+      break;
+    }
+    if (i64 < smallest)
+      smallest = i64;
+  }
+
+  if (i >= ARRAY_SIZE(ts->pts_val))
+    ts->pts_delta = getmonoclock() - ts_rescale(smallest, 1000000);
+}
+
 /*
  * Receive data
  */
@@ -169,29 +200,8 @@ static void timeshift_input
       exit = 1;
 
     /* Record (one-off) PTS delta */
-    if (sm->sm_type == SMT_PACKET && ts->pts_delta == PTS_UNSET) {
-      if (pkt->pkt_pts != PTS_UNSET) {
-        /*
-         * Gather some packets and select the lowest pts to identify
-         * the correct start. Note that for timeshift, the tsfix
-         * stream plugin is applied, so the starting pts should be
-         * near zero. If not - it's a bug.
-         */
-        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);
-      }
-    }
+    if (sm->sm_type == SMT_PACKET && ts->pts_delta == PTS_UNSET)
+      timeshift_set_pts_delta(ts, pkt->pkt_pts);
 
     /* Buffer to disk */
     if ((ts->state > TS_LIVE) || (!ts->ondemand && (ts->state == TS_LIVE))) {