struct media_helper mh;
switch_thread_t *media_thread;
- switch_mutex_t *read_mutex[2];
+
uint8_t reset_codec;
uint8_t codec_negotiated;
switch_core_media_flag_t media_flags[SCMF_MAX];
smh_flag_t flags;
switch_rtp_engine_t engines[SWITCH_MEDIA_TYPE_TOTAL];
-
+ switch_mutex_t *read_mutex[2];
+ switch_mutex_t *write_mutex[2];
char *codec_order[SWITCH_MAX_CODECS];
int codec_order_last;
const switch_codec_implementation_t *codecs[SWITCH_MAX_CODECS];
}
if (lock) {
- if (engine->read_mutex[type] && switch_mutex_trylock(engine->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
+ if (smh->read_mutex[type] && switch_mutex_trylock(smh->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
/* return CNG, another thread is already reading */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being read for %s\n",
switch_channel_get_name(session->channel), type2str(type));
return SWITCH_STATUS_INUSE;
}
} else {
- switch_mutex_unlock(engine->read_mutex[type]);
+ switch_mutex_unlock(smh->read_mutex[type]);
}
return SWITCH_STATUS_SUCCESS;
return SWITCH_STATUS_FALSE;
}
- if (engine->read_mutex[type] && switch_mutex_trylock(engine->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
+ if (smh->read_mutex[type] && switch_mutex_trylock(smh->read_mutex[type]) != SWITCH_STATUS_SUCCESS) {
/* return CNG, another thread is already reading */
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being read for %s\n",
switch_channel_get_name(session->channel), type2str(type));
end:
- if (engine->read_mutex[type]) {
- switch_mutex_unlock(engine->read_mutex[type]);
+ if (smh->read_mutex[type]) {
+ switch_mutex_unlock(smh->read_mutex[type]);
}
return status;
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->mh.file_mutex, SWITCH_MUTEX_NESTED, pool);
- switch_mutex_init(&v_engine->read_mutex[SWITCH_MEDIA_TYPE_VIDEO], SWITCH_MUTEX_NESTED, pool);
+ switch_mutex_init(&smh->read_mutex[SWITCH_MEDIA_TYPE_VIDEO], SWITCH_MUTEX_NESTED, pool);
+ switch_mutex_init(&smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO], 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));
return SWITCH_STATUS_SUCCESS;
uint8_t inb = switch_channel_direction(session->channel) == SWITCH_CALL_DIRECTION_INBOUND;
const char *ssrc;
- switch_mutex_init(&a_engine->read_mutex[SWITCH_MEDIA_TYPE_AUDIO], SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_mutex_init(&smh->read_mutex[SWITCH_MEDIA_TYPE_AUDIO], SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
+ switch_mutex_init(&smh->write_mutex[SWITCH_MEDIA_TYPE_AUDIO], SWITCH_MUTEX_NESTED, switch_core_session_get_pool(session));
//switch_core_media_set_rtp_session(session, SWITCH_MEDIA_TYPE_AUDIO, a_engine->rtp_session);
switch_image_t *img = frame->img;
switch_status_t encode_status;
switch_frame_t write_frame = {0};
+ //switch_rtp_engine_t *v_engine;
switch_assert(session);
return SWITCH_STATUS_SUCCESS;
}
+ //v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
+ if (smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO] && switch_mutex_lock(smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO]) != SWITCH_STATUS_SUCCESS) {
+ /* return CNG, another thread is already writing */
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG1, "%s is already being written to for %s\n",
+ switch_channel_get_name(session->channel), type2str(SWITCH_MEDIA_TYPE_VIDEO));
+ return SWITCH_STATUS_INUSE;
+ }
+
if (!smh->video_init && smh->mparams->video_key_first && (now - smh->video_last_key_time) > smh->mparams->video_key_first) {
switch_core_media_gen_key_frame(session);
}
if (!img) {
- return switch_core_session_write_encoded_video_frame(session, frame, flags, stream_id);
+ switch_status_t vstatus = switch_core_session_write_encoded_video_frame(session, frame, flags, stream_id);
+ switch_goto_status(vstatus, done);
}
write_frame = *frame;
} while(status == SWITCH_STATUS_SUCCESS && encode_status == SWITCH_STATUS_MORE_DATA);
+ done:
+
+ if (smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO]) {
+ switch_mutex_unlock(smh->write_mutex[SWITCH_MEDIA_TYPE_VIDEO]);
+ }
return status;
}