#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
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)
/* 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 */
/* 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);
/* 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;
{
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;
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);