switch_size_t reference;
switch_size_t start;
uint32_t roll;
+ uint32_t ready;
};
typedef struct timer_private timer_private_t;
timer->private_info = private_info;
private_info->start = private_info->reference = TIMER_MATRIX[timer->interval].tick;
private_info->roll = TIMER_MATRIX[timer->interval].roll;
+ private_info->ready = 1;
return SWITCH_STATUS_SUCCESS;
}
timer_private_t *private_info = timer->private_info;
uint64_t samples;
- if (globals.RUNNING != 1) {
+ if (globals.RUNNING != 1 || private_info->ready == 0) {
return SWITCH_STATUS_FALSE;
}
timer_step(timer);
- while (globals.RUNNING == 1 && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
+ while (globals.RUNNING == 1 && private_info->ready && TIMER_MATRIX[timer->interval].tick < private_info->reference) {
check_roll();
switch_yield(1000);
}
switch_status_t status = SWITCH_STATUS_SUCCESS;
switch_size_t diff;
- if (globals.RUNNING != 1) {
+ if (globals.RUNNING != 1 || !private_info->ready) {
return SWITCH_STATUS_SUCCESS;
}
static inline switch_status_t timer_destroy(switch_timer_t *timer)
{
+ timer_private_t *private_info = timer->private_info;
switch_mutex_lock(globals.mutex);
TIMER_MATRIX[timer->interval].count--;
if (TIMER_MATRIX[timer->interval].count == 0) {
TIMER_MATRIX[timer->interval].tick = 0;
}
switch_mutex_unlock(globals.mutex);
- timer->private_info = NULL;
+ private_info->ready = 0;
return SWITCH_STATUS_SUCCESS;
}
switch_core_timer_step(&rtp_session->timer);
}
- if (rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
- *flags |= SFF_CNG;
+ if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
+ return -1;
+ }
+
+ if (rtp_session->cng_pt && rtp_session->recv_msg.header.pt == rtp_session->cng_pt) {
+ continue;
}
if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_BREAK)) {
return 2 + rtp_header_len;
}
- if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO)) {
- return -1;
- }
-
if (bytes < 0) {
return (int)bytes;
} else if (bytes > 0 && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_SECURE)) {
uint8_t data[2] = {0};
switch_frame_flag_t flags = SFF_NONE;
data[0] = 127;
-
+ printf("WTF %u %u\n", rtp_session->timer.samplecount, (rtp_session->last_write_ts + (rtp_session->packet_size * 5)));
rtp_session->last_write_ts = rtp_session->timer.samplecount;
rtp_session->seq = ntohs(rtp_session->seq) + 1;
rtp_session->seq = htons(rtp_session->seq);
SWITCH_DECLARE(switch_size_t) switch_rtp_has_dtmf(switch_rtp_t *rtp_session)
{
- switch_size_t has;
+ switch_size_t has = 0;
- assert(rtp_session != NULL);
- switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
- has = switch_buffer_inuse(rtp_session->dtmf_data.dtmf_buffer);
- switch_mutex_unlock(rtp_session->dtmf_data.dtmf_mutex);
+ if (switch_rtp_ready(rtp_session)) {
+ switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
+ has = switch_buffer_inuse(rtp_session->dtmf_data.dtmf_buffer);
+ switch_mutex_unlock(rtp_session->dtmf_data.dtmf_mutex);
+ }
return has;
}
switch_size_t wr = 0;
char *p;
- assert(rtp_session != NULL);
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
SWITCH_DECLARE(switch_size_t) switch_rtp_dequeue_dtmf(switch_rtp_t *rtp_session, char *dtmf, switch_size_t len)
{
- switch_size_t bytes;
+ switch_size_t bytes = 0;
- assert(rtp_session != NULL);
+ if (!switch_rtp_ready(rtp_session)) {
+ return bytes;
+ }
switch_mutex_lock(rtp_session->dtmf_data.dtmf_mutex);
if ((bytes = switch_buffer_read(rtp_session->dtmf_data.dtmf_buffer, dtmf, len)) > 0) {
{
char *c;
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (!rtp_session->dtmf_data.dtmf_queue) {
switch_queue_create(&rtp_session->dtmf_data.dtmf_queue, 100, rtp_session->pool);
}
SWITCH_DECLARE(switch_status_t) switch_rtp_read(switch_rtp_t *rtp_session, void *data, uint32_t *datalen, switch_payload_t *payload_type, switch_frame_flag_t *flags)
{
+ int bytes = 0;
- int bytes = rtp_common_read(rtp_session, payload_type, flags);
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ bytes = rtp_common_read(rtp_session, payload_type, flags);
if (bytes < 0) {
*datalen = 0;
SWITCH_DECLARE(switch_status_t) switch_rtp_zerocopy_read_frame(switch_rtp_t *rtp_session, switch_frame_t *frame)
{
- int bytes = rtp_common_read(rtp_session, &frame->payload, &frame->flags);
+ int bytes = 0;
+
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ bytes = rtp_common_read(rtp_session, &frame->payload, &frame->flags);
frame->data = rtp_session->recv_msg.body;
frame->packet = &rtp_session->recv_msg;
switch_frame_flag_t *flags)
{
- int bytes = rtp_common_read(rtp_session, payload_type, flags);
+ int bytes = 0;
+
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ bytes = rtp_common_read(rtp_session, payload_type, flags);
*data = rtp_session->recv_msg.body;
if (bytes < 0) {
static int rtp_common_write(switch_rtp_t *rtp_session, void *data, uint32_t datalen, uint8_t m, switch_payload_t payload, switch_frame_flag_t *flags)
{
switch_size_t bytes;
- uint8_t fwd = (uint8_t)(!flags || (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)));
+ uint8_t fwd = 0;
rtp_msg_t *send_msg;
uint8_t send = 1;
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
+ fwd = (uint8_t)(!flags || (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && (*flags & SFF_RAW_RTP)));
+
if (fwd) {
bytes = datalen;
send_msg = (rtp_msg_t *) data;
SWITCH_DECLARE(switch_status_t) switch_rtp_disable_vad(switch_rtp_t *rtp_session)
{
+
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
return SWITCH_STATUS_GENERR;
}
SWITCH_DECLARE(switch_status_t) switch_rtp_enable_vad(switch_rtp_t *rtp_session, switch_core_session_t *session, switch_codec_t *codec, switch_vad_flag_t flags)
{
+
+ if (!switch_rtp_ready(rtp_session)) {
+ return SWITCH_STATUS_FALSE;
+ }
+
if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_VAD)) {
return SWITCH_STATUS_GENERR;
}
{
uint8_t mark = 0;
+ if (!switch_rtp_ready(rtp_session)) {
+ return -1;
+ }
+
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
return -1;
}
SWITCH_DECLARE(int) switch_rtp_write_frame(switch_rtp_t *rtp_session, switch_frame_t *frame, uint32_t ts)
{
- uint8_t fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
- uint8_t packetize = (rtp_session->packet_size > frame->datalen && (frame->payload == rtp_session->payload)) ? 1 : 0;
+ uint8_t fwd = 0;
+ uint8_t packetize = 0;
void *data;
uint32_t len;
uint8_t mark = 0;
switch_payload_t payload;
+
+ if (!switch_rtp_ready(rtp_session)) {
+ return -1;
+ }
+
+ fwd = (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_RAW_WRITE) && switch_test_flag(frame, SFF_RAW_RTP)) ? 1 : 0;
+ packetize = (rtp_session->packet_size > frame->datalen && (frame->payload == rtp_session->payload)) ? 1 : 0;
+
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
return -1;
}
{
rtp_msg_t send_msg = {{0}};
+ if (!switch_rtp_ready(rtp_session)) {
+ return -1;
+ }
+
if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_IO) || !rtp_session->remote_addr) {
return -1;
}