From: Jaroslav Kysela Date: Tue, 5 Jan 2016 08:43:17 +0000 (+0100) Subject: timeshift: fix SMT_START copy for ondemand X-Git-Tag: v4.2.1~1220 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=5aeaf5239339232846d4b9eb8bbb8c1132bc9a5a;p=thirdparty%2Ftvheadend.git timeshift: fix SMT_START copy for ondemand --- diff --git a/src/streaming.c b/src/streaming.c index b6c5cadd9..2702ff328 100644 --- a/src/streaming.c +++ b/src/streaming.c @@ -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: diff --git a/src/streaming.h b/src/streaming.h index a6f66df47..e0f3916c6 100644 --- a/src/streaming.h +++ b/src/streaming.h @@ -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); diff --git a/src/timeshift.c b/src/timeshift.c index aa96aa0fa..5e369bba9 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -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); diff --git a/src/timeshift/private.h b/src/timeshift/private.h index 2f8fb13be..af70ad19f 100644 --- a/src/timeshift/private.h +++ b/src/timeshift/private.h @@ -134,6 +134,8 @@ typedef struct timeshift { int vididx; ///< Index of (current) video stream + streaming_start_t *smt_start; ///< Streaming start info + } timeshift_t; /* diff --git a/src/timeshift/timeshift_filemgr.c b/src/timeshift/timeshift_filemgr.c index 2f0236bb6..f00b81f55 100644 --- a/src/timeshift/timeshift_filemgr.c +++ b/src/timeshift/timeshift_filemgr.c @@ -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; @@ -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); } } diff --git a/src/timeshift/timeshift_writer.c b/src/timeshift/timeshift_writer.c index 15ca9b789..6c08b1ac0 100644 --- a/src/timeshift/timeshift_writer.c +++ b/src/timeshift/timeshift_writer.c @@ -302,6 +302,7 @@ static void _process_msg { int err; timeshift_file_t *tsf; + streaming_start_t *ss; /* Process */ switch (sm->sm_type) { @@ -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) {