Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added noise data generators to mpegts_input and parser input
  • Loading branch information
perexg committed Dec 7, 2015
1 parent 637d1f3 commit 717d561
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/input/mpegts/mpegts_input.c
Expand Up @@ -946,6 +946,36 @@ mpegts_input_tuning_error ( mpegts_input_t *mi, mpegts_mux_t *mm )
* Data processing
* *************************************************************************/

#if 0
static int data_noise ( mpegts_packet_t *mp )
{
static uint64_t off = 0, win = 4096, limit = 2*1024*1024;
uint8_t *data = mp->mp_data;
uint32_t i, p, s, len = mp->mp_len;
for (p = 0; p < len; p += 188) {
off += 188;
if (off >= limit && off < limit + win) {
if ((off & 3) == 1) {
memmove(data + p, data + p + 188, len - (p + 188));
p -= 188;
mp->mp_len -= 188;
return 1;
}
s = ((data[2] + data[3] + data[4]) & 3) + 1;
for (i = 0; i < 188; i += s)
((char *)data)[p+i] ^= data[10] + data[12] + data[i];
} else if (off >= limit + win) {
off = 0;
limit = (uint64_t)data[15] * 4 * 1024;
win = (uint64_t)data[16] * 16;
}
}
return 0;
}
#else
static inline int data_noise( mpegts_packet_t *mp ) { return 0; }
#endif

static int inline
get_pcr ( const uint8_t *tsb, int64_t *rpcr )
{
Expand Down Expand Up @@ -1061,6 +1091,11 @@ mpegts_input_recv_packets
len -= len2;
off += len2;

if ((flags & MPEGTS_DATA_CC_RESTART) == 0 && data_noise(mp)) {
free(mp);
goto end;
}

pthread_mutex_lock(&mi->mi_input_lock);
if (mmi->mmi_mux->mm_active == mmi) {
TAILQ_INSERT_TAIL(&mi->mi_input_queue, mp, mp_link);
Expand All @@ -1072,6 +1107,7 @@ mpegts_input_recv_packets
}

/* Adjust buffer */
end:
if (len && (flags & MPEGTS_DATA_CC_RESTART) == 0)
sbuf_cut(sb, off); // cut off the bottom
else
Expand Down
28 changes: 28 additions & 0 deletions src/parsers/parsers.c
Expand Up @@ -133,6 +133,31 @@ static void parser_do_backlog(service_t *t, elementary_stream_t *st,
void (*pkt_cb)(service_t *t, elementary_stream_t *st, th_pkt_t *pkt),
pktbuf_t *meta);

/**
* for debugging
*/
#if 0
static int data_noise(const uint8_t *data, int len)
{
static uint64_t off = 0, win = 4096, limit = 1024*1024;
uint32_t i;
off += len;
if (off >= limit && off < limit + win) {
if ((off & 3) == 1)
return 1;
for (i = 0; i < len; i += 3)
((char *)data)[i] ^= 0xa5;
} else if (off >= limit + win) {
off = 0;
limit = (uint64_t)data[15] * 4 * 1024;
win = (uint64_t)data[16] * 4;
}
return 0;
}
#else
static inline int data_noise(const uint8_t *data, int len) { return 0; }
#endif

/**
* Parse raw mpeg data
*/
Expand All @@ -146,6 +171,9 @@ parse_mpeg_ts(service_t *t, elementary_stream_t *st, const uint8_t *data,
sbuf_err(&st->es_buf, 1);
}

if (data_noise(data, len))
return;

switch(st->es_type) {
case SCT_MPEG2VIDEO:
parse_pes(t, st, data, len, start, parse_mpeg2video);
Expand Down

0 comments on commit 717d561

Please sign in to comment.