Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: maintain packet backlog also for ondemand
  • Loading branch information
perexg committed Dec 31, 2015
1 parent 0f6f786 commit ffb4674
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/timeshift.c
Expand Up @@ -233,7 +233,7 @@ timeshift_packet_deliver ( timeshift_t *ts, streaming_message_t *sm )
}

static void
timeshift_packet_flush ( timeshift_t *ts, int64_t time )
timeshift_packet_flush ( timeshift_t *ts, int64_t time, int deliver )
{
streaming_message_t *lowest, *sm;
struct streaming_message_queue *sq;
Expand All @@ -251,12 +251,15 @@ timeshift_packet_flush ( timeshift_t *ts, int64_t time )
if (!lowest)
break;
TAILQ_REMOVE(sq, lowest, sm_link);
timeshift_packet_deliver(ts, lowest);
if (deliver)
timeshift_packet_deliver(ts, lowest);
else
streaming_msg_free(lowest);
}
}

static void
timeshift_packet( timeshift_t *ts, th_pkt_t *pkt )
timeshift_packet( timeshift_t *ts, th_pkt_t *pkt, int deliver )
{
streaming_message_t *sm;
int64_t time;
Expand All @@ -269,12 +272,13 @@ timeshift_packet( timeshift_t *ts, th_pkt_t *pkt )
time = ts_rescale(pkt->pkt_pts, 1000000);
if (time > ts->last_time) {
atomic_exchange_s64(&ts->last_time, time);
timeshift_packet_flush(ts, time);
timeshift_packet_flush(ts, time, deliver);
}

sm->sm_time = time;
if (time + MAX_TIME_DELTA < ts->last_time) {
timeshift_packet_deliver(ts, sm);
if (deliver)
timeshift_packet_deliver(ts, sm);
} else {
if (pkt->pkt_componentindex >= ts->backlog_max)
ts->backlog_max = pkt->pkt_componentindex + 1;
Expand Down Expand Up @@ -364,7 +368,7 @@ static void timeshift_input
ts->smt_start = sm->sm_data;
atomic_add(&ts->smt_start->ss_refcount, 1);
if (ts->packet_mode) {
timeshift_packet_flush(ts, ts->last_time + MAX_TIME_DELTA + 1000);
timeshift_packet_flush(ts, ts->last_time + MAX_TIME_DELTA + 1000, ts->dobuf);
if (ts->last_time)
ts->start_pts = ts->last_time + 1000;
}
Expand All @@ -385,7 +389,7 @@ static void timeshift_input
if (ts->packet_mode) {
sm->sm_time = ts->last_time;
if (type == SMT_PACKET) {
timeshift_packet(ts, pkt);
timeshift_packet(ts, pkt, 1);
goto msg_free;
}
} else {
Expand All @@ -399,6 +403,7 @@ static void timeshift_input
streaming_target_deliver2(&ts->wr_queue.sq_st, sm);
} else {
if (type == SMT_PACKET) {
timeshift_packet(ts, pkt, 0);
tvhtrace("timeshift",
"ts %d pkt in - stream %d type %c pts %10"PRId64
" dts %10"PRId64" dur %10d len %6zu",
Expand Down

0 comments on commit ffb4674

Please sign in to comment.