static void *SWITCH_THREAD_FUNC camp_music_thread(switch_thread_t *thread, void *obj)
{
struct camping_stake *stake = (struct camping_stake *) obj;
- switch_core_session_t *session = stake->session;
- switch_channel_t *channel = switch_core_session_get_channel(stake->session);
+ switch_core_session_t *session;
+ switch_channel_t *channel;
const char *moh = stake->moh, *greet = NULL;
switch_input_args_t args = { 0 };
char dbuf[2] = "";
switch_status_t status = SWITCH_STATUS_FALSE;
const char *stop;
+ session = stake->session;
+
+ if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+ return NULL;
+ }
+
+ channel = switch_core_session_get_channel(stake->session);
+
if ((stop = switch_channel_get_variable(channel, "campon_stop_key"))) {
*dbuf = *stop;
}
args.buf = dbuf;
args.buflen = sizeof(dbuf);
- switch_core_session_read_lock(session);
-
/* don't set this to a local_stream:// or you will not be happy */
if ((greet = switch_channel_get_variable(channel, "campon_announce_sound"))) {
status = switch_ivr_play_file(session, NULL, greet, &args);
switch_mutex_t *file_read_mutex;
switch_mutex_t *file_write_mutex;
int up;
+ int ready;
};
typedef enum {
static void *SWITCH_THREAD_FUNC text_helper_thread(switch_thread_t *thread, void *obj)
{
struct media_helper *mh = obj;
- switch_core_session_t *session = mh->session;
- switch_channel_t *channel = switch_core_session_get_channel(session);
+ switch_core_session_t *session;
+ switch_channel_t *channel;
switch_status_t status;
switch_frame_t *read_frame = NULL;
switch_media_handle_t *smh;
unsigned char CR[] = TEXT_UNICODE_LINEFEED;
switch_frame_t cr_frame = { 0 };
+
+ session = mh->session;
+
+ if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+ mh->ready = -1;
+ return NULL;
+ }
+
+ mh->ready = 1;
+
if (!(smh = session->media_handle)) {
return NULL;
}
+ channel = switch_core_session_get_channel(session);
+
if (switch_channel_var_true(session->channel, "fire_text_events")) {
switch_channel_set_flag(session->channel, CF_FIRE_TEXT_EVENTS);
}
t_engine = &smh->engines[SWITCH_MEDIA_TYPE_TEXT];
t_engine->thread_id = switch_thread_self();
- switch_core_session_read_lock(session);
-
mh->up = 1;
switch_core_media_check_dtls(session, SWITCH_MEDIA_TYPE_TEXT);
//switch_mutex_init(&t_engine->mh.file_write_mutex, SWITCH_MUTEX_NESTED, pool);
//switch_mutex_init(&smh->read_mutex[SWITCH_MEDIA_TYPE_TEXT], SWITCH_MUTEX_NESTED, pool);
//switch_mutex_init(&smh->write_mutex[SWITCH_MEDIA_TYPE_TEXT], SWITCH_MUTEX_NESTED, pool);
- switch_thread_create(&t_engine->media_thread, thd_attr, text_helper_thread, &t_engine->mh, switch_core_session_get_pool(session));
+
+ t_engine->mh.ready = 0;
+
+ if (switch_thread_create(&t_engine->media_thread, thd_attr, text_helper_thread, &t_engine->mh,
+ switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
+ while(!t_engine->mh.ready) {
+ switch_cond_next();
+ }
+ }
switch_mutex_unlock(smh->control_mutex);
return SWITCH_STATUS_SUCCESS;
static void *SWITCH_THREAD_FUNC video_helper_thread(switch_thread_t *thread, void *obj)
{
struct media_helper *mh = obj;
- switch_core_session_t *session = mh->session;
- switch_channel_t *channel = switch_core_session_get_channel(session);
+ switch_core_session_t *session;
+ switch_channel_t *channel;
switch_status_t status;
switch_frame_t *read_frame = NULL;
switch_media_handle_t *smh;
int buflen = SWITCH_RTP_MAX_BUF_LEN;
int blank_enabled = 1;
+ session = mh->session;
+
+ if (switch_core_session_read_lock(session) != SWITCH_STATUS_SUCCESS) {
+ mh->ready = -1;
+ return NULL;
+ }
+
+ mh->ready = 1;
+
if (!(smh = session->media_handle)) {
return NULL;
}
+ channel = switch_core_session_get_channel(session);
+
switch_core_autobind_cpu();
if ((var = switch_channel_get_variable(session->channel, "core_video_blank_image"))) {
v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
v_engine->thread_id = switch_thread_self();
- switch_core_session_read_lock(session);
-
mh->up = 1;
switch_mutex_lock(mh->cond_mutex);
switch_mutex_init(&v_engine->mh.file_write_mutex, 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));
+ v_engine->mh.ready = 0;
+
+ if (switch_thread_create(&v_engine->media_thread, thd_attr, video_helper_thread, &v_engine->mh,
+ switch_core_session_get_pool(session)) == SWITCH_STATUS_SUCCESS) {
+ while(!v_engine->mh.ready) {
+ switch_cond_next();
+ }
+ }
switch_mutex_unlock(smh->control_mutex);
return SWITCH_STATUS_SUCCESS;