Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: change the on-demand purpose to allow rewind/goto back
  • Loading branch information
perexg committed Dec 31, 2015
1 parent 49ab691 commit 752b8f0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
7 changes: 5 additions & 2 deletions src/timeshift.c
Expand Up @@ -154,7 +154,9 @@ const idclass_t timeshift_conf_class = {
{
.type = PT_BOOL,
.id = "ondemand",
.name = N_("On-demand (no rewind)"),
.name = N_("On-demand (no first rewind)"),
.desc = N_("Use timeshift only on-demand. It is started when the first request "
"to move in the playback time occurs (fast-forward, rewind, goto)."),
.off = offsetof(timeshift_conf_t, ondemand),
},
{
Expand Down Expand Up @@ -379,7 +381,7 @@ static void timeshift_input
ts->packet_mode = 0;

/* Buffer to disk */
if ((ts->state > TS_LIVE) || (!ts->ondemand && (ts->state == TS_LIVE))) {
if ((ts->state > TS_LIVE) || (ts->dobuf && (ts->state == TS_LIVE))) {
if (ts->packet_mode) {
sm->sm_time = ts->last_time;
if (type == SMT_PACKET) {
Expand Down Expand Up @@ -493,6 +495,7 @@ streaming_target_t *timeshift_create
ts->vididx = -1;
ts->id = timeshift_index;
ts->ondemand = timeshift_conf.ondemand;
ts->dobuf = ts->ondemand ? 0 : 1;
ts->packet_mode= 1;
ts->last_time = 0;
ts->start_pts = 0;
Expand Down
1 change: 1 addition & 0 deletions src/timeshift/private.h
Expand Up @@ -92,6 +92,7 @@ typedef struct timeshift {
time_t max_time; ///< Maximum period to shift
int ondemand; ///< Whether this is an on-demand timeshift
int packet_mode;///< Packet mode (otherwise MPEG-TS data mode)
int dobuf; ///< Buffer packets (store)
int64_t last_time; ///< Last time in us (PTS conversion)
int64_t start_pts; ///< Start time for packets (PTS)
int64_t ref_time; ///< Start time in us (monoclock)
Expand Down
14 changes: 4 additions & 10 deletions src/timeshift/timeshift_reader.c
Expand Up @@ -617,7 +617,7 @@ void *timeshift_reader ( void *p )
if (speed < -3200) speed = -3200;

/* Ignore negative */
if (ts->ondemand && (speed < 0))
if (!ts->dobuf && (speed < 0))
speed = cur_file ? speed : 0;

/* Process */
Expand All @@ -637,6 +637,7 @@ void *timeshift_reader ( void *p )
tvhlog(LOG_DEBUG, "timeshift", "ts %d enter timeshift mode",
ts->id);
timeshift_writer_flush(ts);
ts->dobuf = 1;
pthread_mutex_lock(&ts->rdwr_mutex);
cur_file = timeshift_filemgr_newest(ts);
cur_file = timeshift_filemgr_get(ts, cur_file ? cur_file->last :
Expand Down Expand Up @@ -747,6 +748,7 @@ void *timeshift_reader ( void *p )
skip = NULL;
} else {
ts->state = TS_PLAY;
ts->dobuf = 1;
tvhtrace("timeshift", "reader - set TS_PLAY");
}
}
Expand Down Expand Up @@ -924,10 +926,6 @@ void *timeshift_reader ( void *p )
cur_file->rfd = -1;
}

/* Flush ALL files */
if (ts->ondemand)
timeshift_filemgr_flush(ts, NULL);

/* Pause */
} else {
if (cur_speed <= 0) {
Expand All @@ -938,6 +936,7 @@ void *timeshift_reader ( void *p )
cur_speed = 100;
tvhtrace("timeshift", "reader - set TS_PLAY");
ts->state = TS_PLAY;
ts->dobuf = 1;
if (mono_play_time != mono_now)
tvhtrace("timeshift", "update play time (pause) - %"PRId64, mono_now);
mono_play_time = mono_now;
Expand All @@ -949,11 +948,6 @@ void *timeshift_reader ( void *p )
ctrl = NULL;
}

/* Flush unwanted */
} else if (ts->ondemand && cur_file) {
pthread_mutex_lock(&ts->rdwr_mutex);
timeshift_filemgr_flush(ts, cur_file);
pthread_mutex_unlock(&ts->rdwr_mutex);
}

pthread_mutex_unlock(&ts->state_mutex);
Expand Down

0 comments on commit 752b8f0

Please sign in to comment.