Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
tsdemux: move PCR extraction to mpegts input
  • Loading branch information
perexg committed Nov 13, 2015
1 parent 8511bd0 commit 654a14d
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 23 deletions.
38 changes: 31 additions & 7 deletions src/input/mpegts/mpegts_input.c
Expand Up @@ -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 )
{
Expand Down Expand Up @@ -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;
}
}
}
}
Expand Down Expand Up @@ -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 */
Expand All @@ -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);
}
}

Expand Down
16 changes: 1 addition & 15 deletions src/input/mpegts/tsdemux.c
Expand Up @@ -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)
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/input/mpegts/tsdemux.h
Expand Up @@ -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);

Expand Down

0 comments on commit 654a14d

Please sign in to comment.