Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: fix SMT_START copy for ondemand
  • Loading branch information
perexg committed Jan 5, 2016
1 parent c0779ca commit 5aeaf52
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/streaming.c
Expand Up @@ -247,7 +247,7 @@ streaming_msg_clone(streaming_message_t *src)

case SMT_START:
ss = dst->sm_data = src->sm_data;
atomic_add(&ss->ss_refcount, 1);
streaming_start_ref(ss);
break;

case SMT_SKIP:
Expand Down
5 changes: 5 additions & 0 deletions src/streaming.h
Expand Up @@ -109,6 +109,11 @@ streaming_target_deliver(streaming_target_t *st, streaming_message_t *sm)

void streaming_target_deliver2(streaming_target_t *st, streaming_message_t *sm);

static inline void streaming_start_ref(streaming_start_t *ss)
{
atomic_add(&ss->ss_refcount, 1);
}

void streaming_start_unref(streaming_start_t *ss);

streaming_start_t *streaming_start_copy(const streaming_start_t *src);
Expand Down
3 changes: 3 additions & 0 deletions src/timeshift.c
Expand Up @@ -397,6 +397,9 @@ timeshift_destroy(streaming_target_t *pad)
/* Flush files */
timeshift_filemgr_flush(ts, NULL);

if (ts->smt_start)
streaming_start_unref(ts->smt_start);

if (ts->path)
free(ts->path);
free(ts);
Expand Down
2 changes: 2 additions & 0 deletions src/timeshift/private.h
Expand Up @@ -134,6 +134,8 @@ typedef struct timeshift {

int vididx; ///< Index of (current) video stream

streaming_start_t *smt_start; ///< Streaming start info

} timeshift_t;

/*
Expand Down
18 changes: 13 additions & 5 deletions src/timeshift/timeshift_filemgr.c
Expand Up @@ -258,6 +258,7 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int64_t start_time )
int fd;
timeshift_file_t *tsf_tl, *tsf_hd, *tsf_tmp;
timeshift_index_data_t *ti;
streaming_message_t *sm;
char path[PATH_MAX];
int64_t time;

Expand Down Expand Up @@ -364,13 +365,20 @@ timeshift_file_t *timeshift_filemgr_get ( timeshift_t *ts, int64_t start_time )
}
}

if (tsf_tmp) {
if (tsf_tmp && tsf_tl) {
/* Copy across last start message */
if (tsf_tl && (ti = TAILQ_LAST(&tsf_tl->sstart, timeshift_index_data_list))) {
tvhtrace("timeshift", "ts %d copy smt_start to new file",
ts->id);
if ((ti = TAILQ_LAST(&tsf_tl->sstart, timeshift_index_data_list)) || ts->smt_start) {
tvhtrace("timeshift", "ts %d copy smt_start to new file%s",
ts->id, ti ? " (from last file)" : "");
timeshift_index_data_t *ti2 = calloc(1, sizeof(timeshift_index_data_t));
ti2->data = streaming_msg_clone(ti->data);
if (ti) {
sm = streaming_msg_clone(ti->data);
} else {
sm = streaming_msg_create(SMT_START);
streaming_start_ref(ts->smt_start);
sm->sm_data = ts->smt_start;
}
ti2->data = sm;
TAILQ_INSERT_TAIL(&tsf_tmp->sstart, ti2, link);
}
}
Expand Down
9 changes: 9 additions & 0 deletions src/timeshift/timeshift_writer.c
Expand Up @@ -302,6 +302,7 @@ static void _process_msg
{
int err;
timeshift_file_t *tsf;
streaming_start_t *ss;

/* Process */
switch (sm->sm_type) {
Expand Down Expand Up @@ -341,6 +342,14 @@ static void _process_msg
if (sm->sm_type == SMT_PACKET)
timeshift_packet_log("liv", ts, sm);
}
if (sm->sm_type == SMT_START) {
/* remember start */
if (ts->smt_start)
streaming_start_unref(ts->smt_start);
ss = sm->sm_data;
streaming_start_ref(ss);
ts->smt_start = ss;
}
if (ts->dobuf) {
if ((tsf = timeshift_filemgr_get(ts, sm->sm_time)) != NULL) {
if (tsf->wfd >= 0 || tsf->ram) {
Expand Down

0 comments on commit 5aeaf52

Please sign in to comment.