From 28333981bb89fd1b9f4a97090d8a53ab4f2b687b Mon Sep 17 00:00:00 2001 From: Kieran Kunhya Date: Tue, 28 Jan 2014 18:24:23 +0000 Subject: [PATCH] Attempt to improve PSI transmission --- libmpegts.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/libmpegts.c b/libmpegts.c index e4cfea8..53e2f29 100644 --- a/libmpegts.c +++ b/libmpegts.c @@ -641,11 +641,11 @@ static int write_pmt( ts_writer_t *w, ts_int_program_t *program ) return 0; } -static void retransmit_psi_and_si( ts_writer_t *w, ts_int_program_t *program, int first ) +static void retransmit_psi_and_si( ts_writer_t *w, ts_int_program_t *program ) { // TODO make this work with multiple programs int64_t cur_pcr = get_pcr_int( w, 0 ); - if( cur_pcr - w->last_pat >= w->pat_period * 27000LL || first ) + if( cur_pcr - w->last_pat >= w->pat_period * 27000LL || !w->last_pat ) { /* Although it is not in line with the mux strategy it is good practice to write PAT and PMT together */ w->last_pat = cur_pcr; @@ -655,7 +655,7 @@ static void retransmit_psi_and_si( ts_writer_t *w, ts_int_program_t *program, in cur_pcr = get_pcr_int( w, 0 ); - if( w->sdt && ( cur_pcr - w->last_sdt >= w->sdt_period * 27000LL || first ) ) + if( w->sdt && ( cur_pcr - w->last_sdt >= w->sdt_period * 27000LL || !w->last_sdt ) ) { w->last_sdt = cur_pcr; write_sdt( w ); @@ -1667,7 +1667,6 @@ int ts_write_frames( ts_writer_t *w, ts_frame_t *frames, int num_frames, uint8_t { if( write_pcr_empty( w, program, 1 ) < 0 ) return -1; - retransmit_psi_and_si( w, program, 1 ); w->first_input = 1; } @@ -1717,6 +1716,8 @@ int ts_write_frames( ts_writer_t *w, ts_frame_t *frames, int num_frames, uint8_t /* Check all the non-video packets first */ if( !need_pcr ) { + retransmit_psi_and_si( w, program ); + for( int i = 0; i < w->num_buffered_frames; i++ ) { stream = queued_pes[i]->stream; @@ -1872,8 +1873,6 @@ int ts_write_frames( ts_writer_t *w, ts_frame_t *frames, int num_frames, uint8_t free( pes->data ); free( pes ); } - - retransmit_psi_and_si( w, program, 0 ); } else /* no packets can be written */ {