40 |
40 |
#include "parsers/parser_teletext.h"
|
41 |
41 |
#include "tsdemux.h"
|
42 |
42 |
|
43 |
|
#define TS_REMUX_BUFSIZE (188 * 100)
|
|
43 |
#define TS_SYNC_BYTE 0x47
|
|
44 |
#define TS_SIZE 188
|
|
45 |
#define TS_REMUX_BUFSIZE (TS_SIZE * 100)
|
44 |
46 |
|
45 |
47 |
static void ts_remux(mpegts_service_t *t, const uint8_t *tsb);
|
46 |
48 |
|
... | ... | |
66 |
68 |
ts_recv_packet0
|
67 |
69 |
(mpegts_service_t *t, elementary_stream_t *st, const uint8_t *tsb)
|
68 |
70 |
{
|
69 |
|
int off, pusi, cc, error;
|
70 |
|
|
|
71 |
int off, error, pusi, cc;
|
71 |
72 |
service_set_streaming_status_flags((service_t*)t, TSS_MUX_PACKETS);
|
72 |
73 |
|
73 |
74 |
if(streaming_pad_probe_type(&t->s_streaming_pad, SMT_MPEGTS))
|
... | ... | |
80 |
81 |
pusi = !!(tsb[1] & 0x40);
|
81 |
82 |
|
82 |
83 |
/* Check CC */
|
83 |
|
|
84 |
84 |
if(tsb[3] & 0x10) {
|
85 |
85 |
cc = tsb[3] & 0xf;
|
86 |
86 |
if(st->es_cc_valid && cc != st->es_cc) {
|
87 |
87 |
/* Incorrect CC */
|
88 |
|
limitedlog(&st->es_loglimit_cc, "TS", service_component_nicename(st),
|
89 |
|
"Continuity counter error");
|
|
88 |
char msg[128];
|
|
89 |
sprintf(msg, "Continuity counter error: "
|
|
90 |
"expected %u got %u, PUSI bit=%u",
|
|
91 |
st->es_cc, cc, pusi);
|
|
92 |
limitedlog(&st->es_loglimit_cc, "TS",
|
|
93 |
service_component_nicename(st), msg);
|
|
94 |
//limitedlog(&st->es_loglimit_cc, "TS", service_component_nicename(st),
|
|
95 |
//"Continuity counter error");
|
90 |
96 |
avgstat_add(&t->s_cc_errors, 1, dispatch_clock);
|
91 |
97 |
avgstat_add(&st->es_cc_errors, 1, dispatch_clock);
|
92 |
98 |
|
93 |
99 |
// Mark as error if this is not the first packet of a payload
|
94 |
|
if(!pusi)
|
95 |
|
error |= 0x2;
|
|
100 |
//if(!pusi)
|
|
101 |
// error |= 0x2;
|
96 |
102 |
}
|
97 |
103 |
st->es_cc_valid = 1;
|
98 |
104 |
st->es_cc = (cc + 1) & 0xf;
|
... | ... | |
115 |
121 |
if(st->es_type == SCT_TELETEXT)
|
116 |
122 |
teletext_input(t, st, tsb);
|
117 |
123 |
|
118 |
|
if(off > 188)
|
|
124 |
if(off > TS_SIZE)
|
119 |
125 |
break;
|
120 |
126 |
|
121 |
127 |
if(t->s_status == SERVICE_RUNNING)
|
122 |
|
parse_mpeg_ts((service_t*)t, st, tsb + off, 188 - off, pusi, error);
|
|
128 |
parse_mpeg_ts((service_t*)t, st, tsb + off, TS_SIZE - off, pusi, error);
|
123 |
129 |
break;
|
124 |
130 |
}
|
125 |
131 |
}
|
... | ... | |
177 |
183 |
th_descrambler_t *td;
|
178 |
184 |
int error = 0;
|
179 |
185 |
int64_t pcr = PTS_UNSET;
|
180 |
|
|
|
186 |
|
181 |
187 |
/* Error */
|
182 |
188 |
if (tsb[1] & 0x80)
|
183 |
189 |
error = 1;
|
... | ... | |
230 |
236 |
if(!error)
|
231 |
237 |
service_set_streaming_status_flags((service_t*)t, TSS_INPUT_SERVICE);
|
232 |
238 |
|
233 |
|
avgstat_add(&t->s_rate, 188, dispatch_clock);
|
|
239 |
avgstat_add(&t->s_rate, TS_SIZE, dispatch_clock);
|
234 |
240 |
|
235 |
241 |
if((tsb[3] & 0xc0) ||
|
236 |
242 |
(t->s_scrambled_seen && st && st->es_type != SCT_CA)) {
|
... | ... | |
297 |
303 |
pktbuf_t *pb;
|
298 |
304 |
sbuf_t *sb = &t->s_tsbuf;
|
299 |
305 |
|
300 |
|
sbuf_append(sb, src, 188);
|
|
306 |
sbuf_append(sb, src, TS_SIZE);
|
301 |
307 |
|
302 |
308 |
if(sb->sb_ptr < TS_REMUX_BUFSIZE)
|
303 |
309 |
return;
|
... | ... | |
324 |
330 |
int err = 1;
|
325 |
331 |
while (err && (*len > 376)) {
|
326 |
332 |
(*idx)++; (*len)--;
|
327 |
|
err = (tsb[*idx] != 0x47) || (tsb[*idx+188] != 0x47) ||
|
328 |
|
(tsb[*idx+376] != 0x47);
|
|
333 |
err = (tsb[*idx] != TS_SYNC_BYTE) || (tsb[*idx+TS_SIZE] != TS_SYNC_BYTE) ||
|
|
334 |
(tsb[*idx+TS_SIZE+TS_SIZE] != TS_SYNC_BYTE);
|
329 |
335 |
}
|
330 |
336 |
return err;
|
331 |
337 |
}
|