Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENGDESK-36728: Support configuring the RTP Sequence Range #347

Open
wants to merge 2 commits into
base: telnyx/telephony/development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/include/switch_rtp.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,26 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_set_remote_ssrc(switch_rtp_t *rtp_ses
*/
SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port);

/*!
\brief Set/Get RTP start sequence
\param port new value (if > 0)
dev-ryanc marked this conversation as resolved.
Show resolved Hide resolved
\return the current RTP start sequence
*/
SWITCH_DECLARE(uint16_t) switch_rtp_set_start_sequence(uint16_t sequence);

/*!
\brief Set/Get RTP end sequence
\param port new value (if > 0)
dev-ryanc marked this conversation as resolved.
Show resolved Hide resolved
\return the current RTP end sequence
*/
SWITCH_DECLARE(uint16_t) switch_rtp_set_end_sequence(uint16_t sequence);

/*!
\brief Request a new start sequence to be used for RTP packet
\return the new random sequence
*/
SWITCH_DECLARE(uint16_t) switch_rtp_request_sequence();

/*!
\brief Set/Get RTP packet penalty for packet loss
\param port new value (if > 0)
Expand Down
4 changes: 4 additions & 0 deletions src/switch_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,10 @@ static void switch_load_core_config(const char *file)
switch_rtp_set_start_port((switch_port_t) atoi(val));
} else if (!strcasecmp(var, "rtp-end-port") && !zstr(val)) {
switch_rtp_set_end_port((switch_port_t) atoi(val));
} else if (!strcasecmp(var, "rtp-start-seq") && !zstr(val)) {
switch_rtp_set_start_sequence(atoi(val));
} else if (!strcasecmp(var, "rtp-end-seq") && !zstr(val)) {
switch_rtp_set_end_sequence(atoi(val));
} else if (!strcasecmp(var, "rtp-mos-packet-loss-penalty") && !zstr(val)) {
switch_rtp_set_mos_packet_loss_penalty(atof(val));
} else if (!strcasecmp(var, "rtp-mos-jitter-penalty") && !zstr(val)) {
Expand Down
27 changes: 26 additions & 1 deletion src/switch_rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
#define rtp_header_len 12
#define RTP_START_PORT 16384
#define RTP_END_PORT 32768
#define RTP_START_SEQUENCE 0
#define RTP_END_SEQUENCE 64000
#define MASTER_KEY_LEN 30
#define RTP_MAGIC_NUMBER 42
#define WARN_SRTP_ERRS 10
Expand All @@ -102,6 +104,8 @@ static const switch_payload_t INVALID_PT = 255;

static switch_port_t START_PORT = RTP_START_PORT;
static switch_port_t END_PORT = RTP_END_PORT;
static uint16_t START_SEQUENCE = RTP_START_SEQUENCE;
static uint16_t END_SEQUENCE = RTP_END_SEQUENCE;
static switch_mutex_t *port_lock = NULL;
static switch_size_t do_flush(switch_rtp_t *rtp_session, int force, switch_size_t bytes_in);
static rtp_create_probe_func create_probe = 0;
Expand Down Expand Up @@ -2920,6 +2924,27 @@ SWITCH_DECLARE(switch_port_t) switch_rtp_set_end_port(switch_port_t port)
return END_PORT;
}

SWITCH_DECLARE(uint16_t) switch_rtp_set_start_sequence(uint16_t sequence)
{
if (sequence) {
START_SEQUENCE = sequence;
}
return START_SEQUENCE;
}

SWITCH_DECLARE(uint16_t) switch_rtp_set_end_sequence(uint16_t sequence)
{
if (sequence) {
END_SEQUENCE = sequence;
}
return END_SEQUENCE;
}

SWITCH_DECLARE(uint16_t) switch_rtp_request_sequence()
{
return (((uint16_t)rand()) % (END_SEQUENCE - START_SEQUENCE + 1) + START_SEQUENCE);
}

SWITCH_DECLARE(double) switch_rtp_set_mos_packet_loss_penalty(double penalty)
{
if (penalty) {
Expand Down Expand Up @@ -5098,7 +5123,7 @@ SWITCH_DECLARE(switch_status_t) switch_rtp_create(switch_rtp_t **new_rtp_session
if (rtp_session->flags[SWITCH_RTP_FLAG_ENABLE_RTCP]) {
switch_sockaddr_create(&rtp_session->rtcp_from_addr, pool);
}
rtp_session->seq = (uint16_t) rand();
rtp_session->seq = switch_rtp_request_sequence();
rtp_session->ssrc = (uint32_t) ((intptr_t) rtp_session + (uint32_t) switch_epoch_time_now(NULL));
#ifdef DEBUG_TS_ROLLOVER
rtp_session->last_write_ts = TS_ROLLOVER_START;
Expand Down