]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: Add processing of the SMT_START index
authorAdam Sutton <dev@adamsutton.me.uk>
Mon, 14 Jan 2013 16:19:42 +0000 (16:19 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 14 Jan 2013 16:44:26 +0000 (16:44 +0000)
src/timeshift.c
src/timeshift/private.h
src/timeshift/timeshift_reader.c

index 34b21040e83d716c1c270a5bf47bd9231325b33e..d0cdd8566fe625ad2dd5076d286deb94e9728987 100644 (file)
@@ -22,6 +22,7 @@
 #include "timeshift/private.h"
 #include "config2.h"
 #include "settings.h"
+#include "atomic.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -138,6 +139,12 @@ static void timeshift_input
 
     /* Pass-thru */
     if (ts->state <= TS_LIVE) {
+      if (sm->sm_type == SMT_START) {
+        if (ts->smt_start)
+          streaming_start_unref(ts->smt_start);
+        ts->smt_start = sm->sm_data;
+        atomic_add(&ts->smt_start->ss_refcount, 1);
+      }
       streaming_target_deliver2(ts->output, streaming_msg_clone(sm));
     }
 
@@ -204,6 +211,10 @@ timeshift_destroy(streaming_target_t *pad)
   /* Flush files */
   timeshift_filemgr_flush(ts, NULL);
 
+  /* Release SMT_START index */
+  if (ts->smt_start)
+    streaming_start_unref(ts->smt_start);
+
   free(ts->path);
   free(ts);
 }
index 480f334e695bcfc23e4feaf7f5a37b279feb8094..abb2171bc2b1bbda46c60a505fb3c9d02ae671bc 100644 (file)
@@ -92,6 +92,8 @@ typedef struct timeshift {
   }                           state;       ///< Play state
   pthread_mutex_t             state_mutex; ///< Protect state changes
   uint8_t                     full;        ///< Buffer is full
+  
+  streaming_start_t          *smt_start;   ///< Current stream makeup
 
   streaming_queue_t           wr_queue;   ///< Writer queue
   pthread_t                   wr_thread;  ///< Writer thread
index d4099e76c1faffbfbf4cdf3ff2ee4a0b92a693da..c62e83300d7e127066adcab171a3381c11033cec 100644 (file)
@@ -20,6 +20,7 @@
 #include "streaming.h"
 #include "timeshift.h"
 #include "timeshift/private.h"
+#include "atomic.h"
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -173,6 +174,19 @@ static ssize_t _read_msg ( int fd, streaming_message_t **sm )
  * Utilities
  * *************************************************************************/
 
+static streaming_message_t *_timeshift_find_sstart
+  ( timeshift_file_t *tsf, int64_t time )
+{
+  timeshift_index_data_t *ti;
+
+  /* Find the SMT_START message that relates (comes before) the given time */
+  ti = TAILQ_LAST(&tsf->sstart, timeshift_index_data_list);
+  while (ti && ti->data->sm_time > time)
+    ti = TAILQ_PREV(ti, timeshift_index_data_list, link);
+
+  return ti ? ti->data : NULL;
+}
+
 static int _timeshift_skip
   ( timeshift_t *ts, int64_t req_time, int64_t cur_time,
     timeshift_file_t *cur_file, timeshift_file_t **new_file,
@@ -290,10 +304,13 @@ static int _timeshift_read
 #endif
 
     /* Incomplete */
-    if (r == 0)
+    if (r == 0) {
       lseek(*fd, *cur_off, SEEK_SET);
-    else
-      *cur_off += r;
+      return 0;
+    }
+
+    /* Update */
+    *cur_off += r;
 
     /* Special case - EOF */
     if (r == sizeof(size_t) || *cur_off > (*cur_file)->size) {
@@ -302,6 +319,18 @@ static int _timeshift_read
       *cur_file = timeshift_filemgr_next(*cur_file, NULL, 0);
       *cur_off  = 0; // reset
       *wait     = 0;
+
+    /* Check SMT_START index */
+    } else {
+      streaming_message_t *ssm = _timeshift_find_sstart(*cur_file, (*sm)->sm_time);
+      if (ssm && ssm->sm_data != ts->smt_start) {
+        printf("SENDING NEW SMT_START MESSAGE\n");
+        streaming_target_deliver2(ts->output, streaming_msg_clone(ssm));
+        if (ts->smt_start)
+          streaming_start_unref(ts->smt_start);
+        ts->smt_start = ssm->sm_data;
+        atomic_add(&ts->smt_start->ss_refcount, 1);
+      }
     }
   }
   return 0;