Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
timeshift: remove the packet PTS align, causes issues, fixes #3482
- and adds extra latency
- it seems that the sorting is not required (it probably hid
  the another bugs which are actually fixed)
  • Loading branch information
perexg committed Jan 7, 2016
1 parent 429d95c commit 196b1d9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 63 deletions.
67 changes: 6 additions & 61 deletions src/timeshift.c
Expand Up @@ -237,66 +237,21 @@ const idclass_t timeshift_conf_class = {
};

/*
* Process a packet with time sorting
* Process a packet
*/

#define MAX_TIME_DELTA (2*1000000) /* 2 seconds */
#define BACKLOG_COUNT ARRAY_SIZE(timeshift_t->backlog)


static void
timeshift_packet_flush ( timeshift_t *ts, int64_t time )
{
streaming_message_t *lowest, *sm;
struct streaming_message_queue *sq, *sq_lowest;
int i;

while (1) {
lowest = NULL;
sq_lowest = NULL;
for (i = 0; i < ts->backlog_max; i++) {
sq = &ts->backlog[i];
sm = TAILQ_FIRST(sq);
if (sm && sm->sm_time + MAX_TIME_DELTA < time)
if (lowest == NULL || lowest->sm_time > sm->sm_time) {
lowest = sm;
sq_lowest = sq;
}
}
if (!lowest)
break;
TAILQ_REMOVE(sq_lowest, lowest, sm_link);
ts->last_wr_time = lowest->sm_time;
timeshift_packet_log("wr ", ts, lowest);
streaming_target_deliver2(&ts->wr_queue.sq_st, lowest);
}
}

static int
timeshift_packet( timeshift_t *ts, streaming_message_t *sm )
{
th_pkt_t *pkt = sm->sm_data;
int64_t time;

if (pkt->pkt_componentindex >= TIMESHIFT_BACKLOG_MAX)
return -1;

time = ts_rescale(pkt->pkt_pts, 1000000);
if (time > ts->last_time) {
ts->last_time = time;
timeshift_packet_flush(ts, time);
}

sm->sm_time = time;
if (time + MAX_TIME_DELTA < ts->last_time) {
if (ts->last_wr_time < time)
ts->last_wr_time = time;
timeshift_packet_log("wr2", ts, sm);
streaming_target_deliver2(&ts->wr_queue.sq_st, sm);
} else {
if (pkt->pkt_componentindex >= ts->backlog_max)
ts->backlog_max = pkt->pkt_componentindex + 1;
TAILQ_INSERT_TAIL(&ts->backlog[pkt->pkt_componentindex], sm, sm_link);
}
sm->sm_time = ts->last_wr_time;
timeshift_packet_log("wr ", ts, sm);
streaming_target_deliver2(&ts->wr_queue.sq_st, sm);
return 0;
}

Expand All @@ -319,11 +274,8 @@ static void timeshift_input
streaming_msg_free(sm);
} else {

if (type == SMT_START)
timeshift_packet_flush(ts, ts->last_time + MAX_TIME_DELTA);

/* Change PTS/DTS offsets */
else if (ts->packet_mode && ts->start_pts && type == SMT_PACKET) {
if (ts->packet_mode && ts->start_pts && type == SMT_PACKET) {
pkt = sm->sm_data;
pkt2 = pkt_copy_shallow(pkt);
pkt_ref_dec(pkt);
Expand Down Expand Up @@ -370,7 +322,6 @@ timeshift_destroy(streaming_target_t *pad)
{
timeshift_t *ts = (timeshift_t*)pad;
streaming_message_t *sm;
int i;

/* Must hold global lock */
lock_assert(&global_lock);
Expand All @@ -390,8 +341,6 @@ timeshift_destroy(streaming_target_t *pad)

/* Shut stuff down */
streaming_queue_deinit(&ts->wr_queue);
for (i = 0; i < TIMESHIFT_BACKLOG_MAX; i++)
streaming_queue_clear(&ts->backlog[i]);

close(ts->rd_pipe.rd);
close(ts->rd_pipe.wr);
Expand All @@ -417,7 +366,6 @@ streaming_target_t *timeshift_create
(streaming_target_t *out, time_t max_time)
{
timeshift_t *ts = calloc(1, sizeof(timeshift_t));
int i;

/* Must hold global lock */
lock_assert(&global_lock);
Expand All @@ -435,7 +383,6 @@ streaming_target_t *timeshift_create
ts->ondemand = timeshift_conf.ondemand;
ts->dobuf = ts->ondemand ? 0 : 1;
ts->packet_mode= 1;
ts->last_time = 0;
ts->last_wr_time = 0;
ts->buf_time = 0;
ts->start_pts = 0;
Expand All @@ -444,8 +391,6 @@ streaming_target_t *timeshift_create
ts->seek.frame = NULL;
ts->ram_segments = 0;
ts->file_segments = 0;
for (i = 0; i < TIMESHIFT_BACKLOG_MAX; i++)
TAILQ_INIT(&ts->backlog[i]);
pthread_mutex_init(&ts->state_mutex, NULL);

/* Initialise output */
Expand Down
2 changes: 0 additions & 2 deletions src/timeshift/private.h
Expand Up @@ -101,12 +101,10 @@ typedef struct timeshift {
int ondemand; ///< Whether this is an on-demand timeshift
int packet_mode;///< Packet mode (otherwise MPEG-TS data mode)
int dobuf; ///< Buffer packets (store)
int64_t last_time; ///< Last time in us (PTS conversion)
int64_t last_wr_time;///< Last write time in us (PTS conversion)
int64_t start_pts; ///< Start time for packets (PTS)
int64_t ref_time; ///< Start time in us (monoclock)
int64_t buf_time; ///< Last buffered time in us (PTS conversion)
struct streaming_message_queue backlog[TIMESHIFT_BACKLOG_MAX]; ///< Queued packets for time sorting
int backlog_max;///< Maximum component index in backlog

enum {
Expand Down

0 comments on commit 196b1d9

Please sign in to comment.