diff --git a/Makefile b/Makefile index 5d7bfb1..b153f5b 100644 --- a/Makefile +++ b/Makefile @@ -29,7 +29,7 @@ PROG := $(BUILDDIR)/tvheadend CFLAGS += -Wall -Werror -Wwrite-strings -Wno-deprecated-declarations CFLAGS += -Wmissing-prototypes -fms-extensions -CFLAGS += -g -funsigned-char -O2 +CFLAGS += -g2 -funsigned-char -O2 CFLAGS += -D_FILE_OFFSET_BITS=64 CFLAGS += -I${BUILDDIR} -I${ROOTDIR}/src -I${ROOTDIR} LDFLAGS += -lrt -ldl -lpthread -lm diff --git a/src/input/mpegts/tsdemux.c b/src/input/mpegts/tsdemux.c index 7cb078d..d513d69 100644 --- a/src/input/mpegts/tsdemux.c +++ b/src/input/mpegts/tsdemux.c @@ -40,7 +40,9 @@ #include "parsers/parser_teletext.h" #include "tsdemux.h" -#define TS_REMUX_BUFSIZE (188 * 100) +#define TS_SYNC_BYTE 0x47 +#define TS_SIZE 188 +#define TS_REMUX_BUFSIZE (TS_SIZE * 100) static void ts_remux(mpegts_service_t *t, const uint8_t *tsb); @@ -66,8 +68,7 @@ static void ts_recv_packet0 (mpegts_service_t *t, elementary_stream_t *st, const uint8_t *tsb) { - int off, pusi, cc, error; - + int off, error, pusi, cc; service_set_streaming_status_flags((service_t*)t, TSS_MUX_PACKETS); if(streaming_pad_probe_type(&t->s_streaming_pad, SMT_MPEGTS)) @@ -80,19 +81,24 @@ ts_recv_packet0 pusi = !!(tsb[1] & 0x40); /* Check CC */ - if(tsb[3] & 0x10) { cc = tsb[3] & 0xf; if(st->es_cc_valid && cc != st->es_cc) { /* Incorrect CC */ - limitedlog(&st->es_loglimit_cc, "TS", service_component_nicename(st), - "Continuity counter error"); + char msg[128]; + sprintf(msg, "Continuity counter error: " + "expected %u got %u, PUSI bit=%u", + st->es_cc, cc, pusi); + limitedlog(&st->es_loglimit_cc, "TS", + service_component_nicename(st), msg); + //limitedlog(&st->es_loglimit_cc, "TS", service_component_nicename(st), + //"Continuity counter error"); avgstat_add(&t->s_cc_errors, 1, dispatch_clock); avgstat_add(&st->es_cc_errors, 1, dispatch_clock); // Mark as error if this is not the first packet of a payload - if(!pusi) - error |= 0x2; + //if(!pusi) + // error |= 0x2; } st->es_cc_valid = 1; st->es_cc = (cc + 1) & 0xf; @@ -115,11 +121,11 @@ ts_recv_packet0 if(st->es_type == SCT_TELETEXT) teletext_input(t, st, tsb); - if(off > 188) + if(off > TS_SIZE) break; if(t->s_status == SERVICE_RUNNING) - parse_mpeg_ts((service_t*)t, st, tsb + off, 188 - off, pusi, error); + parse_mpeg_ts((service_t*)t, st, tsb + off, TS_SIZE - off, pusi, error); break; } } @@ -177,7 +183,7 @@ ts_recv_packet1 th_descrambler_t *td; int error = 0; int64_t pcr = PTS_UNSET; - + /* Error */ if (tsb[1] & 0x80) error = 1; @@ -230,7 +236,7 @@ ts_recv_packet1 if(!error) service_set_streaming_status_flags((service_t*)t, TSS_INPUT_SERVICE); - avgstat_add(&t->s_rate, 188, dispatch_clock); + avgstat_add(&t->s_rate, TS_SIZE, dispatch_clock); if((tsb[3] & 0xc0) || (t->s_scrambled_seen && st && st->es_type != SCT_CA)) { @@ -297,7 +303,7 @@ ts_remux(mpegts_service_t *t, const uint8_t *src) pktbuf_t *pb; sbuf_t *sb = &t->s_tsbuf; - sbuf_append(sb, src, 188); + sbuf_append(sb, src, TS_SIZE); if(sb->sb_ptr < TS_REMUX_BUFSIZE) return; @@ -324,8 +330,8 @@ ts_resync ( const uint8_t *tsb, int *len, int *idx ) int err = 1; while (err && (*len > 376)) { (*idx)++; (*len)--; - err = (tsb[*idx] != 0x47) || (tsb[*idx+188] != 0x47) || - (tsb[*idx+376] != 0x47); + err = (tsb[*idx] != TS_SYNC_BYTE) || (tsb[*idx+TS_SIZE] != TS_SYNC_BYTE) || + (tsb[*idx+TS_SIZE+TS_SIZE] != TS_SYNC_BYTE); } return err; }