Browse Source

Protect against namespace collisions after the bitstream import

pull/135/head
Sergio Ammirata 6 years ago
committed by Pierre Ynard
parent
commit
f2789e08d8
  1. 102
      modules/access/rist.c
  2. 96
      modules/access/rist.h
  3. 92
      modules/access_output/rist.c

102
modules/access/rist.c

@ -230,27 +230,27 @@ static void send_rtcp_feedback(stream_t *p_access, struct rist_flow *flow)
if ((namelen - 2) & 0x3)
namelen = ((((namelen - 2) >> 2) + 1) << 2) + 2;
int rtcp_feedback_size = RTCP_EMPTY_RR_SIZE + RTCP_SDES_SIZE + namelen;
int rtcp_feedback_size = RTCP_EMPTY_RR_SIZE + RIST_RTCP_SDES_SIZE + namelen;
uint8_t *buf = malloc(rtcp_feedback_size);
if ( unlikely( buf == NULL ) )
return;
/* Populate RR */
uint8_t *rr = buf;
rtp_set_hdr(rr);
rtcp_rr_set_pt(rr);
rtcp_set_length(rr, 1);
rtcp_fb_set_int_ssrc_pkt_sender(rr, 0);
rist_rtp_set_hdr(rr);
rist_rtcp_rr_set_pt(rr);
rist_rtcp_set_length(rr, 1);
rist_rtcp_fb_set_int_ssrc_pkt_sender(rr, 0);
/* Populate SDES */
uint8_t *p_sdes = (buf + RTCP_EMPTY_RR_SIZE);
rtp_set_hdr(p_sdes);
rtp_set_cc(p_sdes, 1); /* Actually it is source count in this case */
rtcp_sdes_set_pt(p_sdes);
rtcp_set_length(p_sdes, (namelen >> 2) + 2);
rtcp_sdes_set_cname(p_sdes, 1);
rtcp_sdes_set_name_length(p_sdes, strlen(flow->cname));
uint8_t *p_sdes_name = (buf + RTCP_EMPTY_RR_SIZE + RTCP_SDES_SIZE);
rist_rtp_set_hdr(p_sdes);
rist_rtp_set_cc(p_sdes, 1); /* Actually it is source count in this case */
rist_rtcp_sdes_set_pt(p_sdes);
rist_rtcp_set_length(p_sdes, (namelen >> 2) + 2);
rist_rtcp_sdes_set_cname(p_sdes, 1);
rist_rtcp_sdes_set_name_length(p_sdes, strlen(flow->cname));
uint8_t *p_sdes_name = (buf + RTCP_EMPTY_RR_SIZE + RIST_RTCP_SDES_SIZE);
strlcpy((char *)p_sdes_name, flow->cname, namelen);
/* Write to Socket */
@ -266,30 +266,30 @@ static void send_bbnack(stream_t *p_access, int fd_nack, block_t *pkt_nacks, uin
struct rist_flow *flow = p_sys->flow;
int len = 0;
int bbnack_bufsize = RTCP_FB_HEADER_SIZE +
RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
int bbnack_bufsize = RIST_RTCP_FB_HEADER_SIZE +
RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
uint8_t *buf = malloc(bbnack_bufsize);
if ( unlikely( buf == NULL ) )
return;
/* Populate NACKS */
uint8_t *nack = buf;
rtp_set_hdr(nack);
rtcp_fb_set_fmt(nack, NACK_FMT_BITMASK);
rtcp_set_pt(nack, RTCP_PT_RTPFB);
rtcp_set_length(nack, 2 + nack_count);
rist_rtp_set_hdr(nack);
rist_rtcp_fb_set_fmt(nack, NACK_FMT_BITMASK);
rist_rtcp_set_pt(nack, RIST_RTCP_PT_RTPFB);
rist_rtcp_set_length(nack, 2 + nack_count);
/*uint8_t name[4] = "RIST";*/
/*rtcp_fb_set_ssrc_media_src(nack, name);*/
len += RTCP_FB_HEADER_SIZE;
/*rist_rtcp_fb_set_ssrc_media_src(nack, name);*/
len += RIST_RTCP_FB_HEADER_SIZE;
/* TODO : group together */
uint16_t nacks[MAX_NACKS];
memcpy(nacks, pkt_nacks->p_buffer, pkt_nacks->i_buffer);
for (int i = 0; i < nack_count; i++) {
uint8_t *nack_record = buf + len + RTCP_FB_FCI_GENERIC_NACK_SIZE*i;
rtcp_fb_nack_set_packet_id(nack_record, nacks[i]);
rtcp_fb_nack_set_bitmask_lost(nack_record, 0);
uint8_t *nack_record = buf + len + RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE*i;
rist_rtcp_fb_nack_set_packet_id(nack_record, nacks[i]);
rist_rtcp_fb_nack_set_bitmask_lost(nack_record, 0);
}
len += RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
len += RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
/* Write to Socket */
if (p_sys->b_sendnacks && p_sys->b_disablenacks == false)
@ -305,31 +305,31 @@ static void send_rbnack(stream_t *p_access, int fd_nack, block_t *pkt_nacks, uin
struct rist_flow *flow = p_sys->flow;
int len = 0;
int rbnack_bufsize = RTCP_FB_HEADER_SIZE +
RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
int rbnack_bufsize = RIST_RTCP_FB_HEADER_SIZE +
RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
uint8_t *buf = malloc(rbnack_bufsize);
if ( unlikely( buf == NULL ) )
return;
/* Populate NACKS */
uint8_t *nack = buf;
rtp_set_hdr(nack);
rtcp_fb_set_fmt(nack, NACK_FMT_RANGE);
rtcp_set_pt(nack, RTCP_PT_RTPFR);
rtcp_set_length(nack, 2 + nack_count);
rist_rtp_set_hdr(nack);
rist_rtcp_fb_set_fmt(nack, NACK_FMT_RANGE);
rist_rtcp_set_pt(nack, RTCP_PT_RTPFR);
rist_rtcp_set_length(nack, 2 + nack_count);
uint8_t name[4] = "RIST";
rtcp_fb_set_ssrc_media_src(nack, name);
len += RTCP_FB_HEADER_SIZE;
rist_rtcp_fb_set_ssrc_media_src(nack, name);
len += RIST_RTCP_FB_HEADER_SIZE;
/* TODO : group together */
uint16_t nacks[MAX_NACKS];
memcpy(nacks, pkt_nacks->p_buffer, pkt_nacks->i_buffer);
for (int i = 0; i < nack_count; i++)
{
uint8_t *nack_record = buf + len + RTCP_FB_FCI_GENERIC_NACK_SIZE*i;
uint8_t *nack_record = buf + len + RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE*i;
rtcp_fb_nack_set_range_start(nack_record, nacks[i]);
rtcp_fb_nack_set_range_extra(nack_record, 0);
}
len += RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
len += RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE * nack_count;
/* Write to Socket */
if (p_sys->b_sendnacks && p_sys->b_disablenacks == false)
@ -489,40 +489,40 @@ static void rtcp_input(stream_t *p_access, struct rist_flow *flow, uint8_t *buf_
bytes_left);
return;
}
else if (!rtp_check_hdr(buf))
else if (!rist_rtp_check_hdr(buf))
{
/* check for a valid rtp header */
msg_Err(p_access, "Malformed rtcp packet starting with %02x, ignoring.", buf[0]);
return;
}
ptype = rtcp_get_pt(buf);
records = rtcp_get_length(buf);
ptype = rist_rtcp_get_pt(buf);
records = rist_rtcp_get_length(buf);
uint16_t bytes = (uint16_t)(4 * (1 + records));
if (bytes > bytes_left)
{
/* check for a sane number of bytes */
msg_Err(p_access, "Malformed rtcp packet, wrong len %d, expecting %u bytes in the " \
"packet, got a buffer of %u bytes.", rtcp_get_length(buf), bytes, bytes_left);
"packet, got a buffer of %u bytes.", rist_rtcp_get_length(buf), bytes, bytes_left);
return;
}
switch(ptype) {
case RTCP_PT_RTPFR:
case RTCP_PT_RTPFB:
case RIST_RTCP_PT_RTPFB:
break;
case RTCP_PT_RR:
case RIST_RTCP_PT_RR:
break;
case RTCP_PT_SDES:
case RIST_RTCP_PT_SDES:
{
if (p_sys->b_sendnacks == false)
p_sys->b_sendnacks = true;
if (p_sys->b_ismulticast)
return;
/* Check for changes in source IP address or port */
int8_t name_length = rtcp_sdes_get_name_length(buf);
int8_t name_length = rist_rtcp_sdes_get_name_length(buf);
if (name_length > bytes_left || name_length <= 0 ||
(size_t)name_length > sizeof(new_sender_name))
{
@ -549,7 +549,7 @@ static void rtcp_input(stream_t *p_access, struct rist_flow *flow, uint8_t *buf_
/* Check for changes in cname */
bool peer_name_changed = false;
memset(new_sender_name, 0, MAX_CNAME);
memcpy(new_sender_name, buf + RTCP_SDES_SIZE, name_length);
memcpy(new_sender_name, buf + RIST_RTCP_SDES_SIZE, name_length);
if (memcmp(new_sender_name, p_sys->sender_name, name_length) != 0)
{
peer_name_changed = true;
@ -559,7 +559,7 @@ static void rtcp_input(stream_t *p_access, struct rist_flow *flow, uint8_t *buf_
msg_Info(p_access, "Peer Name change detected: old Name: %s, new " \
"Name: %s", p_sys->sender_name, new_sender_name);
memset(p_sys->sender_name, 0, MAX_CNAME);
memcpy(p_sys->sender_name, buf + RTCP_SDES_SIZE, name_length);
memcpy(p_sys->sender_name, buf + RIST_RTCP_SDES_SIZE, name_length);
}
/* Reset the buffer as the source must have been restarted */
@ -571,7 +571,7 @@ static void rtcp_input(stream_t *p_access, struct rist_flow *flow, uint8_t *buf_
}
break;
case RTCP_PT_SR:
case RIST_RTCP_PT_SR:
if (p_sys->b_sendnacks == false)
p_sys->b_sendnacks = true;
if (p_sys->b_ismulticast)
@ -590,21 +590,21 @@ static bool rist_input(stream_t *p_access, struct rist_flow *flow, uint8_t *buf,
stream_sys_t *p_sys = p_access->p_sys;
/* safety checks */
if ( len < RTP_HEADER_SIZE )
if ( len < RIST_RTP_HEADER_SIZE )
{
/* check if packet size >= rtp header size */
msg_Err(p_access, "Rist rtp packet must have at least 12 bytes, we have %zu", len);
return false;
}
else if (!rtp_check_hdr(buf))
else if (!rist_rtp_check_hdr(buf))
{
/* check for a valid rtp header */
msg_Err(p_access, "Malformed rtp packet header starting with %02x, ignoring.", buf[0]);
return false;
}
uint16_t idx = rtp_get_seqnum(buf);
uint32_t pkt_ts = rtp_get_timestamp(buf);
uint16_t idx = rist_rtp_get_seqnum(buf);
uint32_t pkt_ts = rist_rtp_get_timestamp(buf);
bool retrasnmitted = false;
bool success = true;
@ -734,12 +734,12 @@ static block_t *rist_dequeue(stream_t *p_access, struct rist_flow *flow)
if (flow->hi_timestamp > (uint32_t)(pkt->rtp_ts + flow->rtp_latency))
{
/* Populate output packet now but remove rtp header from source */
int newSize = pkt->buffer->i_buffer - RTP_HEADER_SIZE;
int newSize = pkt->buffer->i_buffer - RIST_RTP_HEADER_SIZE;
pktout = block_Alloc(newSize);
if (pktout)
{
pktout->i_buffer = newSize;
memcpy(pktout->p_buffer, pkt->buffer->p_buffer + RTP_HEADER_SIZE, newSize);
memcpy(pktout->p_buffer, pkt->buffer->p_buffer + RIST_RTP_HEADER_SIZE, newSize);
/* free the buffer and increase the read index */
flow->ri = idx;
/* TODO: calculate average duration using buffer average (bring from sender) */

96
modules/access/rist.h

@ -369,22 +369,22 @@ static bool is_multicast_address(char *psz_dst_server)
}
// imported from bitstream
#define RTP_HEADER_SIZE 12
#define RTCP_SR_SIZE 28
#define RTCP_SDES_SIZE 10
#define RTCP_FB_HEADER_SIZE 12
#define RTCP_FB_FCI_GENERIC_NACK_SIZE 4
#define RTCP_PT_SR 200
#define RTCP_PT_RR 201
#define RTCP_PT_SDES 202
#define RTCP_PT_RTPFB 205
static inline uint32_t rtp_get_timestamp(const uint8_t *p_rtp)
#define RIST_RTP_HEADER_SIZE 12
#define RIST_RTCP_SR_SIZE 28
#define RIST_RTCP_SDES_SIZE 10
#define RIST_RTCP_FB_HEADER_SIZE 12
#define RIST_RTCP_FB_FCI_GENERIC_NACK_SIZE 4
#define RIST_RTCP_PT_SR 200
#define RIST_RTCP_PT_RR 201
#define RIST_RTCP_PT_SDES 202
#define RIST_RTCP_PT_RTPFB 205
static inline uint32_t rist_rtp_get_timestamp(const uint8_t *p_rtp)
{
return (p_rtp[4] << 24) | (p_rtp[5] << 16) | (p_rtp[6] << 8) | p_rtp[7];
}
static inline void rtp_set_timestamp(uint8_t *p_rtp, uint32_t i_timestamp)
static inline void rist_rtp_set_timestamp(uint8_t *p_rtp, uint32_t i_timestamp)
{
p_rtp[4] = (i_timestamp >> 24) & 0xff;
p_rtp[5] = (i_timestamp >> 16) & 0xff;
@ -392,60 +392,60 @@ static inline void rtp_set_timestamp(uint8_t *p_rtp, uint32_t i_timestamp)
p_rtp[7] = i_timestamp & 0xff;
}
static inline uint16_t rtp_get_seqnum(const uint8_t *p_rtp)
static inline uint16_t rist_rtp_get_seqnum(const uint8_t *p_rtp)
{
return (p_rtp[2] << 8) | p_rtp[3];
}
static inline void rtp_set_seqnum(uint8_t *p_rtp, uint16_t i_seqnum)
static inline void rist_rtp_set_seqnum(uint8_t *p_rtp, uint16_t i_seqnum)
{
p_rtp[2] = i_seqnum >> 8;
p_rtp[3] = i_seqnum & 0xff;
}
static inline int8_t rtcp_sdes_get_name_length(const uint8_t *p_rtcp_sdes)
static inline int8_t rist_rtcp_sdes_get_name_length(const uint8_t *p_rtcp_sdes)
{
return p_rtcp_sdes[9];
}
static inline uint16_t rtcp_get_length(const uint8_t *p_rtcp)
static inline uint16_t rist_rtcp_get_length(const uint8_t *p_rtcp)
{
return (p_rtcp[2] << 8) | p_rtcp[3];
}
static inline void rtcp_set_length(uint8_t *p_rtcp,
static inline void rist_rtcp_set_length(uint8_t *p_rtcp,
uint16_t length)
{
p_rtcp[2] = length >> 8;
p_rtcp[3] = length & 0xff;
}
static inline uint8_t rtcp_get_pt(const uint8_t *p_rtcp)
static inline uint8_t rist_rtcp_get_pt(const uint8_t *p_rtcp)
{
return p_rtcp[1];
}
static inline void rtcp_set_pt(uint8_t *p_rtcp, uint8_t pt)
static inline void rist_rtcp_set_pt(uint8_t *p_rtcp, uint8_t pt)
{
p_rtcp[1] = pt;
}
static inline bool rtp_check_hdr(const uint8_t *p_rtp)
static inline bool rist_rtp_check_hdr(const uint8_t *p_rtp)
{
return (p_rtp[0] & 0xc0) == 0x80;
}
static inline void rtp_set_hdr(uint8_t *p_rtp)
static inline void rist_rtp_set_hdr(uint8_t *p_rtp)
{
p_rtp[0] = 0x80;
}
static inline void rtcp_rr_set_pt(uint8_t *p_rtcp_rr)
static inline void rist_rtcp_rr_set_pt(uint8_t *p_rtcp_rr)
{
rtcp_set_pt(p_rtcp_rr, RTCP_PT_RR);
rist_rtcp_set_pt(p_rtcp_rr, RIST_RTCP_PT_RR);
}
static inline void rtcp_fb_set_int_ssrc_pkt_sender(uint8_t *p_rtcp_fb, uint32_t i_ssrc)
static inline void rist_rtcp_fb_set_int_ssrc_pkt_sender(uint8_t *p_rtcp_fb, uint32_t i_ssrc)
{
p_rtcp_fb[4] = (i_ssrc >> 24) & 0xff;
p_rtcp_fb[5] = (i_ssrc >> 16) & 0xff;
@ -453,63 +453,63 @@ static inline void rtcp_fb_set_int_ssrc_pkt_sender(uint8_t *p_rtcp_fb, uint32_t
p_rtcp_fb[7] = i_ssrc & 0xff;
}
static inline void rtp_set_cc(uint8_t *p_rtp, uint8_t i_cc)
static inline void rist_rtp_set_cc(uint8_t *p_rtp, uint8_t i_cc)
{
p_rtp[0] &= 0xf0;
p_rtp[0] |= i_cc & 0xf;
}
static inline void rtcp_sdes_set_pt(uint8_t *p_rtcp_rr)
static inline void rist_rtcp_sdes_set_pt(uint8_t *p_rtcp_rr)
{
rtcp_set_pt(p_rtcp_rr, RTCP_PT_SDES);
rist_rtcp_set_pt(p_rtcp_rr, RIST_RTCP_PT_SDES);
}
static inline void rtcp_sdes_set_cname(uint8_t *p_rtcp_sdes, uint8_t cname)
static inline void rist_rtcp_sdes_set_cname(uint8_t *p_rtcp_sdes, uint8_t cname)
{
p_rtcp_sdes[8] = cname;
}
static inline void rtcp_sdes_set_name_length(uint8_t *p_rtcp_sdes,
static inline void rist_rtcp_sdes_set_name_length(uint8_t *p_rtcp_sdes,
int8_t name_length)
{
p_rtcp_sdes[9] = name_length;
}
static inline uint8_t rtcp_fb_get_fmt(const uint8_t *p_rtcp)
static inline uint8_t rist_rtcp_fb_get_fmt(const uint8_t *p_rtcp)
{
return p_rtcp[0] & 0x1f;
}
static inline void rtcp_fb_set_fmt(uint8_t *p_rtcp, uint8_t fmt)
static inline void rist_rtcp_fb_set_fmt(uint8_t *p_rtcp, uint8_t fmt)
{
p_rtcp[0] |= fmt & 0x1f;
}
static inline uint16_t rtcp_fb_nack_get_packet_id(const uint8_t *p_rtcp_fb_nack)
static inline uint16_t rist_rtcp_fb_nack_get_packet_id(const uint8_t *p_rtcp_fb_nack)
{
return (p_rtcp_fb_nack[0] << 8) | p_rtcp_fb_nack[1];
}
static inline void rtcp_fb_nack_set_packet_id(uint8_t *p_rtcp_fb_nack,
static inline void rist_rtcp_fb_nack_set_packet_id(uint8_t *p_rtcp_fb_nack,
uint16_t packet_id)
{
p_rtcp_fb_nack[0] = (packet_id >> 8) & 0xff;
p_rtcp_fb_nack[1] = packet_id & 0xff;
}
static inline uint16_t rtcp_fb_nack_get_bitmask_lost(const uint8_t *p_rtcp_fb_nack)
static inline uint16_t rist_rtcp_fb_nack_get_bitmask_lost(const uint8_t *p_rtcp_fb_nack)
{
return (p_rtcp_fb_nack[2] << 8) | p_rtcp_fb_nack[3];
}
static inline void rtcp_fb_nack_set_bitmask_lost(uint8_t *p_rtcp_fb_nack,
static inline void rist_rtcp_fb_nack_set_bitmask_lost(uint8_t *p_rtcp_fb_nack,
uint16_t bitmask)
{
p_rtcp_fb_nack[2] = (bitmask >> 8) & 0xff;
p_rtcp_fb_nack[3] = bitmask & 0xff;
}
static inline void rtcp_fb_get_ssrc_media_src(const uint8_t *p_rtcp_fb,
static inline void rist_rtcp_fb_get_ssrc_media_src(const uint8_t *p_rtcp_fb,
uint8_t pi_ssrc[4])
{
pi_ssrc[0] = p_rtcp_fb[8];
@ -518,7 +518,7 @@ static inline void rtcp_fb_get_ssrc_media_src(const uint8_t *p_rtcp_fb,
pi_ssrc[3] = p_rtcp_fb[11];
}
static inline void rtcp_fb_set_ssrc_media_src(uint8_t *p_rtcp_fb,
static inline void rist_rtcp_fb_set_ssrc_media_src(uint8_t *p_rtcp_fb,
const uint8_t pi_ssrc[4])
{
p_rtcp_fb[8] = pi_ssrc[0];
@ -527,18 +527,18 @@ static inline void rtcp_fb_set_ssrc_media_src(uint8_t *p_rtcp_fb,
p_rtcp_fb[11] = pi_ssrc[3];
}
static inline void rtcp_sr_set_pt(uint8_t *p_rtcp_sr)
static inline void rist_rtcp_sr_set_pt(uint8_t *p_rtcp_sr)
{
rtcp_set_pt(p_rtcp_sr, RTCP_PT_SR);
rist_rtcp_set_pt(p_rtcp_sr, RIST_RTCP_PT_SR);
}
static inline void rtcp_sr_set_length(uint8_t *p_rtcp_sr,
static inline void rist_rtcp_sr_set_length(uint8_t *p_rtcp_sr,
uint16_t length)
{
rtcp_set_length(p_rtcp_sr, length);
rist_rtcp_set_length(p_rtcp_sr, length);
}
static inline void rtcp_sr_set_ntp_time_msw(uint8_t *p_rtcp_sr,
static inline void rist_rtcp_sr_set_ntp_time_msw(uint8_t *p_rtcp_sr,
uint32_t ntp_time_msw)
{
p_rtcp_sr[8] = (ntp_time_msw >> 24) & 0xff;
@ -547,7 +547,7 @@ static inline void rtcp_sr_set_ntp_time_msw(uint8_t *p_rtcp_sr,
p_rtcp_sr[11] = ntp_time_msw & 0xff;
}
static inline void rtcp_sr_set_ntp_time_lsw(uint8_t *p_rtcp_sr,
static inline void rist_rtcp_sr_set_ntp_time_lsw(uint8_t *p_rtcp_sr,
uint32_t ntp_time_lsw)
{
p_rtcp_sr[12] = (ntp_time_lsw >> 24) & 0xff;
@ -556,7 +556,7 @@ static inline void rtcp_sr_set_ntp_time_lsw(uint8_t *p_rtcp_sr,
p_rtcp_sr[15] = ntp_time_lsw & 0xff;
}
static inline void rtcp_sr_set_rtp_time(uint8_t *p_rtcp_sr,
static inline void rist_rtcp_sr_set_rtp_time(uint8_t *p_rtcp_sr,
uint32_t rtp_time)
{
p_rtcp_sr[16] = (rtp_time >> 24) & 0xff;
@ -565,7 +565,7 @@ static inline void rtcp_sr_set_rtp_time(uint8_t *p_rtcp_sr,
p_rtcp_sr[19] = rtp_time & 0xff;
}
static inline void rtcp_sr_set_packet_count(uint8_t *p_rtcp_sr,
static inline void rist_rtcp_sr_set_packet_count(uint8_t *p_rtcp_sr,
uint32_t packet_count)
{
p_rtcp_sr[20] = (packet_count >> 24) & 0xff;
@ -574,7 +574,7 @@ static inline void rtcp_sr_set_packet_count(uint8_t *p_rtcp_sr,
p_rtcp_sr[23] = packet_count & 0xff;
}
static inline void rtcp_sr_set_octet_count(uint8_t *p_rtcp_sr,
static inline void rist_rtcp_sr_set_octet_count(uint8_t *p_rtcp_sr,
uint32_t octet_count)
{
p_rtcp_sr[24] = (octet_count >> 24) & 0xff;
@ -583,12 +583,12 @@ static inline void rtcp_sr_set_octet_count(uint8_t *p_rtcp_sr,
p_rtcp_sr[27] = octet_count & 0xff;
}
static inline void rtp_set_type(uint8_t *p_rtp, uint8_t i_type)
static inline void rist_rtp_set_type(uint8_t *p_rtp, uint8_t i_type)
{
p_rtp[1] = i_type & 0x7f;
}
static inline void rtp_set_int_ssrc(uint8_t *p_rtp, uint32_t i_ssrc)
static inline void rist_rtp_set_int_ssrc(uint8_t *p_rtp, uint32_t i_ssrc)
{
p_rtp[8] = (i_ssrc >> 24) & 0xff;
p_rtp[9] = (i_ssrc >> 16) & 0xff;

92
modules/access_output/rist.c

@ -222,7 +222,7 @@ static void process_nack(sout_access_out_t *p_access, uint8_t ptype, uint16_t n
if (ptype == RTCP_PT_RTPFR)
{
uint8_t pi_ssrc[4];
rtcp_fb_get_ssrc_media_src(pkt, pi_ssrc);
rist_rtcp_fb_get_ssrc_media_src(pkt, pi_ssrc);
if (memcmp(pi_ssrc, "RIST", 4) != 0)
{
msg_Info(p_access, " Ignoring Nack with name %s", pi_ssrc);
@ -244,14 +244,14 @@ static void process_nack(sout_access_out_t *p_access, uint8_t ptype, uint16_t n
vlc_mutex_unlock( &p_sys->lock );
}
}
else if (ptype == RTCP_PT_RTPFB)
else if (ptype == RIST_RTCP_PT_RTPFB)
{
for (i = 0; i < (nrecords-2); i++) {
uint16_t missing;
uint16_t bitmask;
uint8_t *rtp_nack_record = (pkt + 12 + i * 4);
missing = rtcp_fb_nack_get_packet_id(rtp_nack_record);
bitmask = rtcp_fb_nack_get_bitmask_lost(rtp_nack_record);
missing = rist_rtcp_fb_nack_get_packet_id(rtp_nack_record);
bitmask = rist_rtcp_fb_nack_get_bitmask_lost(rtp_nack_record);
/*msg_Info(p_access, " Nack (Bitmask), %d, current seq is: [%d]", missing, flow->wi);*/
vlc_mutex_lock( &p_sys->lock );
rist_retransmit(p_access, flow, missing);
@ -266,7 +266,7 @@ static void process_nack(sout_access_out_t *p_access, uint8_t ptype, uint16_t n
else
{
msg_Err(p_access, " !!! Wrong feedback. Ptype is %02x!=%02x, FMT: %02x", ptype,
RTCP_PT_RTPFR, rtcp_fb_get_fmt(pkt));
RTCP_PT_RTPFR, rist_rtcp_fb_get_fmt(pkt));
}
}
@ -290,43 +290,43 @@ static void rist_rtcp_recv(sout_access_out_t *p_access, struct rist_flow *flow,
bytes_left);
return;
}
else if (!rtp_check_hdr(pkt))
else if (!rist_rtp_check_hdr(pkt))
{
/* check for a valid rtp header */
msg_Err(p_access, "Malformed feedback packet starting with %02x, ignoring.", pkt[0]);
return;
}
ptype = rtcp_get_pt(pkt);
records = rtcp_get_length(pkt);
ptype = rist_rtcp_get_pt(pkt);
records = rist_rtcp_get_length(pkt);
uint16_t bytes = (uint16_t)(4 * (1 + records));
if (bytes > bytes_left)
{
/* check for a sane number of bytes */
msg_Err(p_access, "Malformed feedback packet, wrong len %d, expecting %u bytes in the" \
" packet, got a buffer of %u bytes. ptype = %d", rtcp_get_length(pkt), bytes,
" packet, got a buffer of %u bytes. ptype = %d", rist_rtcp_get_length(pkt), bytes,
bytes_left, ptype);
return;
}
switch(ptype) {
case RTCP_PT_RTPFR:
case RTCP_PT_RTPFB:
case RIST_RTCP_PT_RTPFB:
process_nack(p_access, ptype, records, flow, pkt);
break;
case RTCP_PT_RR:
case RIST_RTCP_PT_RR:
/*
if (p_sys->b_ismulticast == false)
process_rr(f, pkt, len);
*/
break;
case RTCP_PT_SDES:
case RIST_RTCP_PT_SDES:
{
if (p_sys->b_ismulticast == false)
{
int8_t name_length = rtcp_sdes_get_name_length(pkt);
int8_t name_length = rist_rtcp_sdes_get_name_length(pkt);
if (name_length > bytes_left)
{
/* check for a sane number of bytes */
@ -334,16 +334,16 @@ static void rist_rtcp_recv(sout_access_out_t *p_access, struct rist_flow *flow,
"buffer of %u bytes.", name_length, bytes_left);
return;
}
if (memcmp(pkt + RTCP_SDES_SIZE, p_sys->receiver_name, name_length) != 0)
if (memcmp(pkt + RIST_RTCP_SDES_SIZE, p_sys->receiver_name, name_length) != 0)
{
memcpy(p_sys->receiver_name, pkt + RTCP_SDES_SIZE, name_length);
memcpy(p_sys->receiver_name, pkt + RIST_RTCP_SDES_SIZE, name_length);
msg_Info(p_access, "Receiver name: %s", p_sys->receiver_name);
}
}
}
break;
case RTCP_PT_SR:
case RIST_RTCP_PT_SR:
break;
default:
@ -357,7 +357,7 @@ static void rist_rtcp_send(sout_access_out_t *p_access)
{
sout_access_out_sys_t *p_sys = p_access->p_sys;
struct rist_flow *flow = p_sys->flow;
uint8_t rtcp_buf[RTCP_SR_SIZE + RTCP_SDES_SIZE + MAX_CNAME] = { };
uint8_t rtcp_buf[RIST_RTCP_SR_SIZE + RIST_RTCP_SDES_SIZE + MAX_CNAME] = { };
struct timeval tv;
int r;
uint64_t fractions;
@ -366,37 +366,37 @@ static void rist_rtcp_send(sout_access_out_t *p_access)
/* Populate SR for sender report */
uint8_t *p_sr = rtcp_buf;
rtp_set_hdr(p_sr);
rtcp_sr_set_pt(p_sr);
rtcp_sr_set_length(p_sr, 6);
rtcp_fb_set_int_ssrc_pkt_sender(p_sr, p_sys->ssrc);
rtcp_sr_set_ntp_time_msw(p_sr, tv.tv_sec + SEVENTY_YEARS_OFFSET);
rist_rtp_set_hdr(p_sr);
rist_rtcp_sr_set_pt(p_sr);
rist_rtcp_sr_set_length(p_sr, 6);
rist_rtcp_fb_set_int_ssrc_pkt_sender(p_sr, p_sys->ssrc);
rist_rtcp_sr_set_ntp_time_msw(p_sr, tv.tv_sec + SEVENTY_YEARS_OFFSET);
fractions = (uint64_t)tv.tv_usec;
fractions <<= 32ULL;
fractions /= 1000000ULL;
rtcp_sr_set_ntp_time_lsw(p_sr, (uint32_t)fractions);
rtcp_sr_set_rtp_time(p_sr, rtp_get_ts(mdate()));
rist_rtcp_sr_set_ntp_time_lsw(p_sr, (uint32_t)fractions);
rist_rtcp_sr_set_rtp_time(p_sr, rtp_get_ts(mdate()));
vlc_mutex_lock( &p_sys->lock );
rtcp_sr_set_packet_count(p_sr, flow->packets_count);
rtcp_sr_set_octet_count(p_sr, flow->bytes_count);
rist_rtcp_sr_set_packet_count(p_sr, flow->packets_count);
rist_rtcp_sr_set_octet_count(p_sr, flow->bytes_count);
vlc_mutex_unlock( &p_sys->lock );
/* Populate SDES for sender description */
uint8_t *p_sdes = (rtcp_buf + RTCP_SR_SIZE);
uint8_t *p_sdes = (rtcp_buf + RIST_RTCP_SR_SIZE);
/* we need to make sure it is a multiple of 4, pad if necessary */
if ((namelen - 2) & 0x3)
namelen = ((((namelen - 2) >> 2) + 1) << 2) + 2;
rtp_set_hdr(p_sdes);
rtp_set_cc(p_sdes, 1); /* Actually it is source count in this case */
rtcp_sdes_set_pt(p_sdes);
rtcp_set_length(p_sdes, (namelen >> 2) + 2);
rtcp_sdes_set_cname(p_sdes, 1);
rtcp_sdes_set_name_length(p_sdes, strlen(flow->cname));
p_sdes += RTCP_SDES_SIZE;
rist_rtp_set_hdr(p_sdes);
rist_rtp_set_cc(p_sdes, 1); /* Actually it is source count in this case */
rist_rtcp_sdes_set_pt(p_sdes);
rist_rtcp_set_length(p_sdes, (namelen >> 2) + 2);
rist_rtcp_sdes_set_cname(p_sdes, 1);
rist_rtcp_sdes_set_name_length(p_sdes, strlen(flow->cname));
p_sdes += RIST_RTCP_SDES_SIZE;
strlcpy((char *)p_sdes, flow->cname, namelen);
/* Send the rtcp message */
r = send(flow->fd_rtcp, rtcp_buf, RTCP_SR_SIZE + RTCP_SDES_SIZE + namelen, 0);
r = send(flow->fd_rtcp, rtcp_buf, RIST_RTCP_SR_SIZE + RIST_RTCP_SDES_SIZE + namelen, 0);
(void)r;
}
@ -494,8 +494,8 @@ static void* ThreadSend( void *data )
len = out->i_buffer;
int canc = vlc_savecancel();
seq = rtp_get_seqnum(out->p_buffer);
pkt_ts = rtp_get_timestamp(out->p_buffer);
seq = rist_rtp_get_seqnum(out->p_buffer);
pkt_ts = rist_rtp_get_timestamp(out->p_buffer);
vlc_mutex_lock( &p_sys->fd_lock );
#ifdef TEST_PACKET_LOSS
@ -575,12 +575,12 @@ static void SendtoFIFO( sout_access_out_t *p_access, block_t *buffer )
/* Set fresh rtp header data */
uint8_t *bufhdr = buffer->p_buffer;
rtp_set_hdr(bufhdr);
rtp_set_type(bufhdr, MPEG_II_TRANSPORT_STREAM);
rtp_set_seqnum(bufhdr, seq);
rtp_set_int_ssrc(bufhdr, p_sys->ssrc);
rist_rtp_set_hdr(bufhdr);
rist_rtp_set_type(bufhdr, MPEG_II_TRANSPORT_STREAM);
rist_rtp_set_seqnum(bufhdr, seq);
rist_rtp_set_int_ssrc(bufhdr, p_sys->ssrc);
uint32_t pkt_ts = rtp_get_ts(buffer->i_dts);
rtp_set_timestamp(bufhdr, pkt_ts);
rist_rtp_set_timestamp(bufhdr, pkt_ts);
block_t *pkt = block_Duplicate(buffer);
block_FifoPut( p_sys->p_fifo, pkt );
@ -608,7 +608,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
if( p_sys->p_pktbuffer->i_buffer + p_buffer->i_buffer > p_sys->i_packet_size )
{
SendtoFIFO(p_access, p_sys->p_pktbuffer);
p_sys->p_pktbuffer->i_buffer = RTP_HEADER_SIZE;
p_sys->p_pktbuffer->i_buffer = RIST_RTP_HEADER_SIZE;
}
i_len += p_buffer->i_buffer;
@ -620,7 +620,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
i_block_split++;
if( p_sys->p_pktbuffer->i_buffer == RTP_HEADER_SIZE )
if( p_sys->p_pktbuffer->i_buffer == RIST_RTP_HEADER_SIZE )
{
p_sys->p_pktbuffer->i_dts = p_buffer->i_dts;
}
@ -638,7 +638,7 @@ static ssize_t Write( sout_access_out_t *p_access, block_t *p_buffer )
if( p_sys->p_pktbuffer->i_buffer == p_sys->i_packet_size || i_block_split > 1 )
{
SendtoFIFO(p_access, p_sys->p_pktbuffer);
p_sys->p_pktbuffer->i_buffer = RTP_HEADER_SIZE;
p_sys->p_pktbuffer->i_buffer = RIST_RTP_HEADER_SIZE;
}
}
@ -792,7 +792,7 @@ static int Open( vlc_object_t *p_this )
if( unlikely(p_sys->p_pktbuffer == NULL) )
goto failed;
p_sys->p_pktbuffer->i_buffer = RTP_HEADER_SIZE;
p_sys->p_pktbuffer->i_buffer = RIST_RTP_HEADER_SIZE;
p_access->p_sys = p_sys;

Loading…
Cancel
Save