]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
timeshift: change buffer file period to limit number of files.
authorAdam Sutton <dev@adamsutton.me.uk>
Mon, 14 Jan 2013 22:00:34 +0000 (22:00 +0000)
committerAdam Sutton <dev@adamsutton.me.uk>
Mon, 14 Jan 2013 22:00:34 +0000 (22:00 +0000)
src/timeshift/private.h
src/timeshift/timeshift_filemgr.c
src/timeshift/timeshift_reader.c

index abb2171bc2b1bbda46c60a505fb3c9d02ae671bc..63b7479d0dd4521a2080b0b2cf0fbd4f90ccc700 100644 (file)
@@ -19,7 +19,8 @@
 #ifndef __TVH_TIMESHIFT_PRIVATE_H__
 #define __TVH_TIMESHIFT_PRIVATE_H__
 
-#define TS_PLAY_BUF 100000 // us to buffer in TX
+#define TIMESHIFT_PLAY_BUF    100000 // us to buffer in TX
+#define TIMESHIFT_FILE_PERIOD     60 // number of secs in each buffer file
 
 /**
  * Indexes of import data in the stream
index f8fafad5d1e1dde49350bed89b56dd9842812d45..2e2661bd318633ecc8a30b2bda250a1810b72732 100644 (file)
@@ -181,6 +181,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
   timeshift_file_t *tsf_tl, *tsf_hd, *tsf_tmp;
   timeshift_index_data_t *ti;
   char path[512];
+  time_t time;
 
   /* Return last file */
   if (!create)
@@ -192,8 +193,9 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
 
   /* Store to file */
   clock_gettime(CLOCK_MONOTONIC_COARSE, &tp);
+  time   = tp.tv_sec / TIMESHIFT_FILE_PERIOD;
   tsf_tl = TAILQ_LAST(&ts->files, timeshift_file_list);
-  if (!tsf_tl || tsf_tl->time != tp.tv_sec) {
+  if (!tsf_tl || tsf_tl->time != time) {
     tsf_hd = TAILQ_FIRST(&ts->files);
 
     /* Close existing */
@@ -202,7 +204,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
 
     /* Check period */
     if (ts->max_time && tsf_hd && tsf_tl) {
-      time_t d = tsf_tl->time - tsf_hd->time;
+      time_t d = (tsf_tl->time - tsf_hd->time) * TIMESHIFT_FILE_PERIOD;
       if (d > (ts->max_time+5)) {
         if (!tsf_hd->refcount) {
           timeshift_filemgr_remove(ts, tsf_hd, 0);
@@ -221,13 +223,13 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int create )
     /* Create new file */
     tsf_tmp = NULL;
     if (!ts->full) {
-      snprintf(path, sizeof(path), "%s/tvh-%"PRItime_t, ts->path, tp.tv_sec);
+      snprintf(path, sizeof(path), "%s/tvh-%"PRItime_t, ts->path, time);
 #ifdef TSHFT_TRACE
       tvhlog(LOG_DEBUG, "timeshift", "ts %d create file %s", ts->id, path);
 #endif
       if ((fd = open(path, O_WRONLY | O_CREAT, 0600)) > 0) {
         tsf_tmp = calloc(1, sizeof(timeshift_file_t));
-        tsf_tmp->time     = tp.tv_sec;
+        tsf_tmp->time     = time;
         tsf_tmp->fd       = fd;
         tsf_tmp->path     = strdup(path);
         tsf_tmp->refcount = 0;
index c62e83300d7e127066adcab171a3381c11033cec..5bb509a1e682170cad3256052946d85792e0f021 100644 (file)
@@ -194,7 +194,7 @@ static int _timeshift_skip
 {
   timeshift_index_iframe_t *tsi  = *iframe;
   timeshift_file_t         *tsf  = cur_file;
-  int64_t                   sec  = req_time / 1000000;
+  int64_t                   sec  = req_time / (1000000 * TIMESHIFT_FILE_PERIOD);
   int                       back = (req_time < cur_time) ? 1 : 0;
   int                       end  = 0;
 
@@ -575,7 +575,7 @@ void *timeshift_reader ( void *p )
     pthread_mutex_lock(&ts->rdwr_mutex);
 
     /* Calculate delivery time */
-    deliver = (now - play_time) + TS_PLAY_BUF;
+    deliver = (now - play_time) + TIMESHIFT_PLAY_BUF;
     deliver = (deliver * cur_speed) / 100;
     deliver = (deliver + pause_time);