From c463b7d7ba73161dd939681e550ba2a5b55b4f73 Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 14 Jan 2013 22:00:34 +0000 Subject: [PATCH] timeshift: change buffer file period to limit number of files. --- src/timeshift/private.h | 3 ++- src/timeshift/timeshift_filemgr.c | 10 ++++++---- src/timeshift/timeshift_reader.c | 4 ++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/timeshift/private.h b/src/timeshift/private.h index abb2171b..63b7479d 100644 --- a/src/timeshift/private.h +++ b/src/timeshift/private.h @@ -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 diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index f8fafad5..2e2661bd 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -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; diff --git a/src/timeshift/timeshift_reader.c b/src/timeshift/timeshift_reader.c index c62e8330..5bb509a1 100644 --- a/src/timeshift/timeshift_reader.c +++ b/src/timeshift/timeshift_reader.c @@ -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);