]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: fix SMT_START copy for ondemand
authorJaroslav Kysela <perex@perex.cz>
Tue, 5 Jan 2016 08:43:17 +0000 (09:43 +0100)
committerJaroslav Kysela <perex@perex.cz>
Tue, 5 Jan 2016 09:20:22 +0000 (10:20 +0100)
src/streaming.c
src/streaming.h
src/timeshift.c
src/timeshift/private.h
src/timeshift/timeshift_filemgr.c
src/timeshift/timeshift_writer.c

index b6c5cadd970b64c2737f8f4659610237c0fd2622..2702ff32847fef21b3601bbb688f19a92af227a7 100644 (file)
@@ -247,7 +247,7 @@ streaming_msg_clone(streaming_message_t *src)
 
   case SMT_START:
     ss = dst->sm_data = src->sm_data;
-    atomic_add(&ss->ss_refcount, 1);
+    streaming_start_ref(ss);
     break;
 
   case SMT_SKIP:
index a6f66df47b938d28249457097db25cd93e652460..e0f3916c68e84dabb61016b9da980c2899269553 100644 (file)
@@ -109,6 +109,11 @@ streaming_target_deliver(streaming_target_t *st, streaming_message_t *sm)
 
 void streaming_target_deliver2(streaming_target_t *st, streaming_message_t *sm);
 
+static inline void streaming_start_ref(streaming_start_t *ss)
+{
+  atomic_add(&ss->ss_refcount, 1);
+}
+
 void streaming_start_unref(streaming_start_t *ss);
 
 streaming_start_t *streaming_start_copy(const streaming_start_t *src);
index aa96aa0fae26c8f4a373508a9c06f96699c987dc..5e369bba93c39a006c3549c893fb17aef0e60d9b 100644 (file)
@@ -397,6 +397,9 @@ timeshift_destroy(streaming_target_t *pad)
   /* Flush files */
   timeshift_filemgr_flush(ts, NULL);
 
+  if (ts->smt_start)
+    streaming_start_unref(ts->smt_start);
+
   if (ts->path)
     free(ts->path);
   free(ts);
index 2f8fb13be508e6249a3bd380d2cc077ffc38528c..af70ad19f0a08fbed373df19b57bed9293722af2 100644 (file)
@@ -134,6 +134,8 @@ typedef struct timeshift {
 
   int                         vididx;     ///< Index of (current) video stream
 
+  streaming_start_t          *smt_start;  ///< Streaming start info
+
 } timeshift_t;
 
 /*
index 2f0236bb666a69962a1bb545def73c6d4270a2dc..f00b81f55677c4837bb0ba8738e2d082369034ba 100644 (file)
@@ -258,6 +258,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int64_t start_time )
   int fd;
   timeshift_file_t *tsf_tl, *tsf_hd, *tsf_tmp;
   timeshift_index_data_t *ti;
+  streaming_message_t *sm;
   char path[PATH_MAX];
   int64_t time;
 
@@ -364,13 +365,20 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int64_t start_time )
         }
       }
 
-      if (tsf_tmp) {
+      if (tsf_tmp && tsf_tl) {
         /* Copy across last start message */
-        if (tsf_tl && (ti = TAILQ_LAST(&tsf_tl->sstart, timeshift_index_data_list))) {
-          tvhtrace("timeshift", "ts %d copy smt_start to new file",
-                   ts->id);
+        if ((ti = TAILQ_LAST(&tsf_tl->sstart, timeshift_index_data_list)) || ts->smt_start) {
+          tvhtrace("timeshift", "ts %d copy smt_start to new file%s",
+                   ts->id, ti ? " (from last file)" : "");
           timeshift_index_data_t *ti2 = calloc(1, sizeof(timeshift_index_data_t));
-          ti2->data = streaming_msg_clone(ti->data);
+          if (ti) {
+            sm = streaming_msg_clone(ti->data);
+          } else {
+            sm = streaming_msg_create(SMT_START);
+            streaming_start_ref(ts->smt_start);
+            sm->sm_data = ts->smt_start;
+          }
+          ti2->data = sm;
           TAILQ_INSERT_TAIL(&tsf_tmp->sstart, ti2, link);
         }
       }
index 15ca9b789a614efae01efa6b027b93336fbadae7..6c08b1ac063582341fae9e0d4200087dc2801f75 100644 (file)
@@ -302,6 +302,7 @@ static void _process_msg
 {
   int err;
   timeshift_file_t *tsf;
+  streaming_start_t *ss;
 
   /* Process */
   switch (sm->sm_type) {
@@ -341,6 +342,14 @@ static void _process_msg
         if (sm->sm_type == SMT_PACKET)
           timeshift_packet_log("liv", ts, sm);
       }
+      if (sm->sm_type == SMT_START) {
+        /* remember start */
+        if (ts->smt_start)
+          streaming_start_unref(ts->smt_start);
+        ss = sm->sm_data;
+        streaming_start_ref(ss);
+        ts->smt_start = ss;
+      }
       if (ts->dobuf) {
         if ((tsf = timeshift_filemgr_get(ts, sm->sm_time)) != NULL) {
           if (tsf->wfd >= 0 || tsf->ram) {