* 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 )
{
// 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;
+ }
}
}
}
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 */
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);
}
}
*/
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)
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;
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);