Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: handle correctly SMT_START in the writer thread
  • Loading branch information
perexg committed Dec 31, 2015
1 parent 752b8f0 commit 0f6f786
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/timeshift/timeshift_reader.c
Expand Up @@ -377,7 +377,7 @@ static int _timeshift_do_skip
if (tsi)
cur_file->roff = tsi->pos;
else
cur_file->roff = 0;
cur_file->roff = req_time > last_time ? cur_file->size : 0;
tvhtrace("timeshift", "do skip cur_file %p roff %"PRId64, cur_file, cur_file->roff);
}

Expand Down
55 changes: 42 additions & 13 deletions src/timeshift/timeshift_writer.c
Expand Up @@ -226,33 +226,59 @@ ssize_t timeshift_write_eof ( timeshift_file_t *tsf )
return _write(tsf, &sz, sizeof(sz));
}

/*
* Stream start handling
*/
static void _handle_sstart ( timeshift_t *ts, timeshift_file_t *tsf, streaming_message_t *sm )
{
timeshift_index_data_t *ti = calloc(1, sizeof(timeshift_index_data_t));
streaming_start_t *ss;
int i;

ti->pos = tsf->size;
ti->data = sm;
TAILQ_INSERT_TAIL(&tsf->sstart, ti, link);

/* Update video index */
ss = sm->sm_data;
for (i = 0; i < ss->ss_num_components; i++)
if (SCT_ISVIDEO(ss->ss_components[i].ssc_type)) {
ts->vididx = ss->ss_components[i].ssc_index;
break;
}
}

static void _copy_last_sstart ( timeshift_t *ts, timeshift_file_t *tsf )
{
streaming_message_t *sm;
streaming_start_t *ss = ts->smt_start;

if (ss) {
atomic_add(&ss->ss_refcount, 1);
sm = streaming_msg_create_data(SMT_START, ss);
_handle_sstart(ts, tsf, sm);
}
}

/* **************************************************************************
* Thread
* *************************************************************************/

static inline ssize_t _process_msg0
( timeshift_t *ts, timeshift_file_t *tsf, streaming_message_t **smp )
{
int i;
ssize_t err;
streaming_start_t *ss;
streaming_message_t *sm = *smp;

if (sm->sm_type == SMT_START) {
err = 0;
timeshift_index_data_t *ti = calloc(1, sizeof(timeshift_index_data_t));
ti->pos = tsf->size;
ti->data = sm;
_handle_sstart(ts, tsf, sm);
*smp = NULL;
TAILQ_INSERT_TAIL(&tsf->sstart, ti, link);

/* Update video index */
ss = sm->sm_data;
for (i = 0; i < ss->ss_num_components; i++)
if (SCT_ISVIDEO(ss->ss_components[i].ssc_type))
ts->vididx = ss->ss_components[i].ssc_index;
} else if (sm->sm_type == SMT_SIGNAL_STATUS)
err = timeshift_write_sigstat(tsf, sm->sm_time, sm->sm_data);
else if (sm->sm_type == SMT_PACKET) {
if (TAILQ_EMPTY(&tsf->sstart))
_copy_last_sstart(ts, tsf);
err = timeshift_write_packet(tsf, sm->sm_time, sm->sm_data);
if (err > 0) {
th_pkt_t *pkt = sm->sm_data;
Expand All @@ -266,8 +292,11 @@ static inline ssize_t _process_msg0
TAILQ_INSERT_TAIL(&tsf->iframes, ti, link);
}
}
} else if (sm->sm_type == SMT_MPEGTS)
} else if (sm->sm_type == SMT_MPEGTS) {
if (TAILQ_EMPTY(&tsf->sstart))
_copy_last_sstart(ts, tsf);
err = timeshift_write_mpegts(tsf, sm->sm_time, sm->sm_data);
}
else
err = 0;

Expand Down

0 comments on commit 0f6f786

Please sign in to comment.