struct media_helper mh;
switch_thread_t *media_thread;
+ switch_mutex_t *read_mutex;
} switch_rtp_engine_t;
switch_assert(engine->rtp_session != NULL);
engine->read_frame.datalen = 0;
+ if (switch_mutex_trylock(engine->read_mutex) != SWITCH_STATUS_SUCCESS) {
+ /* return CNG for now */
+ *frame = &engine->read_frame;
+ switch_set_flag((*frame), SFF_CNG);
+ (*frame)->datalen = engine->read_impl.encoded_bytes_per_packet;
+ memset((*frame)->data, 0, (*frame)->datalen);
+ return SWITCH_STATUS_SUCCESS;
+ }
+
while (smh->media_flags[SCMF_RUNNING] && engine->read_frame.datalen == 0) {
engine->read_frame.flags = SFF_NONE;
(*frame)->datalen = engine->read_impl.encoded_bytes_per_packet;
memset((*frame)->data, 0, (*frame)->datalen);
switch_channel_execute_on(session->channel, "execute_on_media_timeout");
- return SWITCH_STATUS_SUCCESS;
+ switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
switch_channel_hangup(session->channel, SWITCH_CAUSE_MEDIA_TIMEOUT);
}
- return status;
+ goto end;
}
/* Try to read an RTCP frame, if successful raise an event */
/* Fast PASS! */
if (switch_test_flag((&engine->read_frame), SFF_PROXY_PACKET)) {
*frame = &engine->read_frame;
- return SWITCH_STATUS_SUCCESS;
+ switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
if (switch_rtp_has_dtmf(engine->rtp_session)) {
if (!switch_test_flag((&engine->read_frame), SFF_CNG)) {
if (!engine->read_codec.implementation || !switch_core_codec_ready(&engine->read_codec)) {
*frame = NULL;
- return SWITCH_STATUS_GENERR;
+ switch_goto_status(SWITCH_STATUS_GENERR, end);
}
/* check for timing or codec issues */
if (switch_rtp_ready(engine->rtp_session)) {
if (switch_core_media_set_codec(session, 2, 0) != SWITCH_STATUS_SUCCESS) {
*frame = NULL;
- return SWITCH_STATUS_GENERR;
+ switch_goto_status(SWITCH_STATUS_GENERR, end);
}
if ((val = switch_channel_get_variable(session->channel, "rtp_timeout_sec"))) {
switch_set_flag((*frame), SFF_CNG);
(*frame)->datalen = engine->read_impl.encoded_bytes_per_packet;
memset((*frame)->data, 0, (*frame)->datalen);
- return SWITCH_STATUS_SUCCESS;
+ switch_goto_status(SWITCH_STATUS_SUCCESS, end);
}
}
*frame = &engine->read_frame;
- return SWITCH_STATUS_SUCCESS;
+ status = SWITCH_STATUS_SUCCESS;
+
+ end:
+
+ switch_mutex_unlock(engine->read_mutex);
+
+ return status;
}
//?
uint8_t inb = switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND;
const char *ssrc;
+ switch_mutex_init(&a_engine->read_mutex, SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+
//switch_core_media_set_rtp_session(session, SWITCH_MEDIA_TYPE_AUDIO, a_engine->rtp_session);
if ((ssrc = switch_channel_get_variable(session->channel, "rtp_use_ssrc"))) {
switch_thread_cond_create(&v_engine->mh.cond, pool);
switch_mutex_init(&v_engine->mh.cond_mutex, SWITCH_MUTEX_NESTED, pool);
+ switch_mutex_init(&v_engine->read_mutex, SWITCH_MUTEX_NESTED, pool);
switch_thread_create(&v_engine->media_thread, thd_attr, video_helper_thread, &v_engine->mh, switch_core_session_get_pool(session));
}