Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
IPTV: Add RTP sequence checks
  • Loading branch information
perexg committed Jun 24, 2015
1 parent 8ad9f08 commit 8cc9b71
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/input/mpegts/iptv/iptv.c
Expand Up @@ -410,6 +410,7 @@ iptv_input_mux_started ( iptv_mux_t *im )
{
/* Allocate input buffer */
sbuf_init_fixed(&im->mm_iptv_buffer, IPTV_BUF_SIZE);
im->mm_iptv_rtp_seq = -1;

if (iptv_input_fd_started(im))
return;
Expand Down
2 changes: 2 additions & 0 deletions src/input/mpegts/iptv/iptv_private.h
Expand Up @@ -98,6 +98,8 @@ struct iptv_mux
time_t mm_iptv_respawn_last;
char *mm_iptv_env;

uint32_t mm_iptv_rtp_seq;

sbuf_t mm_iptv_buffer;

iptv_handler_t *im_handler;
Expand Down
20 changes: 19 additions & 1 deletion src/input/mpegts/iptv/iptv_udp.c
Expand Up @@ -99,13 +99,16 @@ iptv_rtp_read ( iptv_mux_t *im, udp_multirecv_t *um,
ssize_t len, hlen;
uint8_t *rtp;
int i, n;
uint32_t seq, nseq, unc = 0;
struct iovec *iovec;
ssize_t res = 0;

n = udp_multirecv_read(um, im->mm_iptv_fd, IPTV_PKTS, &iovec);
if (n < 0)
return -1;

seq = im->mm_iptv_rtp_seq;

for (i = 0; i < n; i++, iovec++) {

/* Raw packet */
Expand Down Expand Up @@ -138,13 +141,28 @@ iptv_rtp_read ( iptv_mux_t *im, udp_multirecv_t *um,
if (len < hlen || ((len - hlen) % 188) != 0)
continue;

/* Move data */
len -= hlen;

/* Use uncorrectable value to notify RTP delivery issues */
nseq = (rtp[2] << 8) | rtp[3];
if (seq == -1)
seq = nseq;
else if (((seq + 1) & 0xffff) != nseq) {
unc += (len / 188) * (uint32_t)((uint16_t)nseq-(uint16_t)(seq+1));
tvhtrace("iptv", "RTP discontinuity (%i != %i)", seq + 1, nseq);
}
seq = nseq;

/* Move data */
tsdebug_write((mpegts_mux_t *)im, rtp + hlen, len);
sbuf_append(&im->mm_iptv_buffer, rtp + hlen, len);
res += len;
}

im->mm_iptv_rtp_seq = seq;
if (im->mm_active)
im->mm_active->tii_stats.unc += unc;

return res;
}

Expand Down

0 comments on commit 8cc9b71

Please sign in to comment.