From: Jaroslav Kysela Date: Fri, 13 Nov 2015 09:30:57 +0000 (+0100) Subject: tsdemux: move PCR extraction to mpegts input X-Git-Tag: v4.2.1~1557 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=654a14d13fc91860a3ed29eef738cafc21a375b9;p=thirdparty%2Ftvheadend.git tsdemux: move PCR extraction to mpegts input --- diff --git a/src/input/mpegts/mpegts_input.c b/src/input/mpegts/mpegts_input.c index 628352cd2..87132988b 100644 --- a/src/input/mpegts/mpegts_input.c +++ b/src/input/mpegts/mpegts_input.c @@ -926,6 +926,28 @@ mpegts_input_tuning_error ( mpegts_input_t *mi, mpegts_mux_t *mm ) * Data processing * *************************************************************************/ +static int inline +get_pcr ( const uint8_t *tsb, int64_t *rpcr ) +{ + int_fast64_t pcr; + + if (tsb[1] & 0x80) /* error bit */ + return 0; + + if ((tsb[3] & 0x20) == 0 || + tsb[4] <= 5 || + (tsb[5] & 0x10) == 0) + return 0; + + pcr = (uint64_t)tsb[6] << 25; + pcr |= (uint64_t)tsb[7] << 17; + pcr |= (uint64_t)tsb[8] << 9; + pcr |= (uint64_t)tsb[9] << 1; + pcr |= ((uint64_t)tsb[10] >> 7) & 0x01; + *rpcr = pcr; + return 1; +} + static int inline ts_sync_count ( const uint8_t *tsb, int len ) { @@ -982,14 +1004,16 @@ mpegts_input_recv_packets // without the potential need to buffer data (since that would // require per mmi buffers, where this is generally not required) - /* Extract PCR (used for tsfile playback) */ + /* Extract PCR on demand */ if (pcr && pcr_pid) { - uint8_t *tmp, *end; - for (tmp = tsb, end = tsb + len2; tmp < end; tmp += 188) { + uint8_t *tmp; + for (tmp = tsb + len2 - 188; tmp >= tsb; tmp -= 188) { uint16_t pid = ((tmp[1] & 0x1f) << 8) | tmp[2]; if (*pcr_pid == MPEGTS_PID_NONE || *pcr_pid == pid) { - ts_recv_packet1(NULL, tmp, 188, pcr, 0); - if (*pcr != PTS_UNSET) *pcr_pid = pid; + if (get_pcr(tmp, pcr)) { + if (*pcr != PTS_UNSET) *pcr_pid = pid; + break; + } } } } @@ -1232,7 +1256,7 @@ mpegts_input_process s = mps->mps_owner; f = (type & (MPS_TABLE|MPS_FTABLE)) || (pid == s->s_pmt_pid) || (pid == s->s_pcr_pid); - ts_recv_packet1((mpegts_service_t*)s, tsb, llen, NULL, f); + ts_recv_packet1((mpegts_service_t*)s, tsb, llen, f); } } else /* Stream table data */ @@ -1241,7 +1265,7 @@ mpegts_input_process if (s->s_type != STYPE_STD) continue; f = (type & (MPS_TABLE|MPS_FTABLE)) || (pid == s->s_pmt_pid) || (pid == s->s_pcr_pid); - ts_recv_packet1((mpegts_service_t*)s, tsb, llen, NULL, f); + ts_recv_packet1((mpegts_service_t*)s, tsb, llen, f); } } diff --git a/src/input/mpegts/tsdemux.c b/src/input/mpegts/tsdemux.c index 05dca2bb9..8913316d3 100644 --- a/src/input/mpegts/tsdemux.c +++ b/src/input/mpegts/tsdemux.c @@ -173,12 +173,11 @@ ts_recv_skipped0 */ int ts_recv_packet1 - (mpegts_service_t *t, const uint8_t *tsb, int len, int64_t *pcrp, int table) + (mpegts_service_t *t, const uint8_t *tsb, int len, int table) { elementary_stream_t *st; int pid, r; int error = 0; - int64_t pcr = PTS_UNSET; /* Error */ if (tsb[1] & 0x80) @@ -189,19 +188,6 @@ ts_recv_packet1 tsb[0], tsb[1], tsb[2], tsb[3], tsb[4], tsb[5]); #endif - /* Extract PCR (do this early for tsfile) */ - if((tsb[3] & 0x20) && (tsb[4] > 5) && (tsb[5] & 0x10) && !error) { - pcr = (uint64_t)tsb[6] << 25; - pcr |= (uint64_t)tsb[7] << 17; - pcr |= (uint64_t)tsb[8] << 9; - pcr |= (uint64_t)tsb[9] << 1; - pcr |= ((uint64_t)tsb[10] >> 7) & 0x01; - if (pcrp) *pcrp = pcr; - } - - /* Nothing - special case for tsfile to get PCR */ - if (!t) return 0; - /* Service inactive - ignore */ if(t->s_status != SERVICE_RUNNING) return 0; diff --git a/src/input/mpegts/tsdemux.h b/src/input/mpegts/tsdemux.h index da4e5a624..5fb82ac75 100644 --- a/src/input/mpegts/tsdemux.h +++ b/src/input/mpegts/tsdemux.h @@ -22,7 +22,7 @@ int ts_resync ( const uint8_t *tsb, int *len, int *idx ); int ts_recv_packet1 - (struct mpegts_service *t, const uint8_t *tsb, int len, int64_t *pcrp, int table); + (struct mpegts_service *t, const uint8_t *tsb, int len, int table); void ts_recv_packet2(struct mpegts_service *t, const uint8_t *tsb, int len);