From ca68f94304a66723ff2267bad181b41ed6f7691f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20T=C3=B6rnblom?= Date: Sun, 6 Jan 2013 18:49:40 +0100 Subject: [PATCH] mkv: make sure the first cluster timecode is 'close to zero'. when recording to disk, the subscription is started ~30s before the scheduled event actually starts. This causes the pts time stamps to have an offset of about 30s. This patch moves the start time filter condition from the end of the pipeline to be a configurable property of the tsfix pipe. --- src/dvr/dvr_rec.c | 5 ++--- src/plumbing/tsfix.c | 16 ++++++++++++++-- src/plumbing/tsfix.h | 2 ++ 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/dvr/dvr_rec.c b/src/dvr/dvr_rec.c index 6dc560dd..9fbf1e58 100755 --- a/src/dvr/dvr_rec.c +++ b/src/dvr/dvr_rec.c @@ -81,6 +81,7 @@ dvr_rec_subscribe(dvr_entry_t *de) streaming_queue_init(&de->de_sq, 0); de->de_gh = globalheaders_create(&de->de_sq.sq_st); de->de_tsfix = tsfix_create(de->de_gh); + tsfix_set_start_time(de->de_tsfix, de->de_start - (60 * de->de_start_extra)); st = de->de_tsfix; flags = 0; } @@ -419,10 +420,8 @@ dvr_thread(void *aux) switch(sm->sm_type) { case SMT_MPEGTS: case SMT_PACKET: - if(started && - dispatch_clock > de->de_start - (60 * de->de_start_extra)) { + if(started) { dvr_rec_set_state(de, DVR_RS_RUNNING, 0); - muxer_write_pkt(de->de_mux, sm->sm_type, sm->sm_data); sm->sm_data = NULL; } diff --git a/src/plumbing/tsfix.c b/src/plumbing/tsfix.c index dfab483c..5fb1febf 100644 --- a/src/plumbing/tsfix.c +++ b/src/plumbing/tsfix.c @@ -55,6 +55,7 @@ typedef struct tsfix { struct tfstream_list tf_streams; int tf_hasvideo; int64_t tf_tsref; + time_t tf_start_time; struct th_pktref_queue tf_ptsq; @@ -309,12 +310,11 @@ tsfix_input_packet(tsfix_t *tf, streaming_message_t *sm) tfstream_t *tfs = tfs_find(tf, pkt); streaming_msg_free(sm); - if(tfs == NULL) { + if(tfs == NULL || dispatch_clock < tf->tf_start_time) { pkt_ref_dec(pkt); return; } - if(tf->tf_tsref == PTS_UNSET && (!tf->tf_hasvideo || (SCT_ISVIDEO(tfs->tfs_type) && pkt->pkt_frametype == PKT_I_FRAME))) { @@ -387,10 +387,22 @@ tsfix_create(streaming_target_t *output) TAILQ_INIT(&tf->tf_ptsq); tf->tf_output = output; + tf->tf_start_time = dispatch_clock; + streaming_target_init(&tf->tf_input, tsfix_input, tf, 0); return &tf->tf_input; } +/** + * + */ +void tsfix_set_start_time(streaming_target_t *pad, time_t start) +{ + tsfix_t *tf = (tsfix_t *)pad; + + tf->tf_start_time = start; +} + /** * diff --git a/src/plumbing/tsfix.h b/src/plumbing/tsfix.h index 7e6f7bd0..156284fe 100644 --- a/src/plumbing/tsfix.h +++ b/src/plumbing/tsfix.h @@ -23,6 +23,8 @@ streaming_target_t *tsfix_create(streaming_target_t *output); +void tsfix_set_start_time(streaming_target_t *pad, time_t start); + void tsfix_destroy(streaming_target_t *gh);