From 29abf2f783abdfa4c9b74287223a715c7e4a475a Mon Sep 17 00:00:00 2001 From: Adam Sutton Date: Mon, 14 Jan 2013 16:19:42 +0000 Subject: [PATCH] timeshift: Add processing of the SMT_START index --- src/timeshift.c | 11 ++++++++++ src/timeshift/private.h | 2 ++ src/timeshift/timeshift_reader.c | 35 +++++++++++++++++++++++++++++--- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/src/timeshift.c b/src/timeshift.c index 34b21040e..d0cdd8566 100644 --- a/src/timeshift.c +++ b/src/timeshift.c @@ -22,6 +22,7 @@ #include "timeshift/private.h" #include "config2.h" #include "settings.h" +#include "atomic.h" #include #include @@ -138,6 +139,12 @@ static void timeshift_input /* Pass-thru */ if (ts->state <= TS_LIVE) { + if (sm->sm_type == SMT_START) { + if (ts->smt_start) + streaming_start_unref(ts->smt_start); + ts->smt_start = sm->sm_data; + atomic_add(&ts->smt_start->ss_refcount, 1); + } streaming_target_deliver2(ts->output, streaming_msg_clone(sm)); } @@ -204,6 +211,10 @@ timeshift_destroy(streaming_target_t *pad) /* Flush files */ timeshift_filemgr_flush(ts, NULL); + /* Release SMT_START index */ + if (ts->smt_start) + streaming_start_unref(ts->smt_start); + free(ts->path); free(ts); } diff --git a/src/timeshift/private.h b/src/timeshift/private.h index 480f334e6..abb2171bc 100644 --- a/src/timeshift/private.h +++ b/src/timeshift/private.h @@ -92,6 +92,8 @@ typedef struct timeshift { } state; ///< Play state pthread_mutex_t state_mutex; ///< Protect state changes uint8_t full; ///< Buffer is full + + streaming_start_t *smt_start; ///< Current stream makeup streaming_queue_t wr_queue; ///< Writer queue pthread_t wr_thread; ///< Writer thread diff --git a/src/timeshift/timeshift_reader.c b/src/timeshift/timeshift_reader.c index d4099e76c..c62e83300 100644 --- a/src/timeshift/timeshift_reader.c +++ b/src/timeshift/timeshift_reader.c @@ -20,6 +20,7 @@ #include "streaming.h" #include "timeshift.h" #include "timeshift/private.h" +#include "atomic.h" #include #include @@ -173,6 +174,19 @@ static ssize_t _read_msg ( int fd, streaming_message_t **sm ) * Utilities * *************************************************************************/ +static streaming_message_t *_timeshift_find_sstart + ( timeshift_file_t *tsf, int64_t time ) +{ + timeshift_index_data_t *ti; + + /* Find the SMT_START message that relates (comes before) the given time */ + ti = TAILQ_LAST(&tsf->sstart, timeshift_index_data_list); + while (ti && ti->data->sm_time > time) + ti = TAILQ_PREV(ti, timeshift_index_data_list, link); + + return ti ? ti->data : NULL; +} + static int _timeshift_skip ( timeshift_t *ts, int64_t req_time, int64_t cur_time, timeshift_file_t *cur_file, timeshift_file_t **new_file, @@ -290,10 +304,13 @@ static int _timeshift_read #endif /* Incomplete */ - if (r == 0) + if (r == 0) { lseek(*fd, *cur_off, SEEK_SET); - else - *cur_off += r; + return 0; + } + + /* Update */ + *cur_off += r; /* Special case - EOF */ if (r == sizeof(size_t) || *cur_off > (*cur_file)->size) { @@ -302,6 +319,18 @@ static int _timeshift_read *cur_file = timeshift_filemgr_next(*cur_file, NULL, 0); *cur_off = 0; // reset *wait = 0; + + /* Check SMT_START index */ + } else { + streaming_message_t *ssm = _timeshift_find_sstart(*cur_file, (*sm)->sm_time); + if (ssm && ssm->sm_data != ts->smt_start) { + printf("SENDING NEW SMT_START MESSAGE\n"); + streaming_target_deliver2(ts->output, streaming_msg_clone(ssm)); + if (ts->smt_start) + streaming_start_unref(ts->smt_start); + ts->smt_start = ssm->sm_data; + atomic_add(&ts->smt_start->ss_refcount, 1); + } } } return 0; -- 2.47.2