diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index 209292b731..660b7475bd 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1413,16 +1413,18 @@ switch_status_t sofia_glue_activate_rtp(private_object_t *tech_pvt, switch_rtp_f sofia_glue_check_video_codecs(tech_pvt); if (switch_test_flag(tech_pvt, TFLAG_VIDEO) && tech_pvt->video_rm_encoding) { - flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_AUTOADJ | SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_NOBLOCK | SWITCH_RTP_FLAG_RAW_WRITE); + flags = (switch_rtp_flag_t) (SWITCH_RTP_FLAG_USE_TIMER | SWITCH_RTP_FLAG_AUTOADJ | + SWITCH_RTP_FLAG_DATAWAIT | SWITCH_RTP_FLAG_NOBLOCK | SWITCH_RTP_FLAG_RAW_WRITE); sofia_glue_tech_set_video_codec(tech_pvt, 0); + /* set video timer to 10ms so it can co-exist with audio */ tech_pvt->video_rtp_session = switch_rtp_new(tech_pvt->local_sdp_audio_ip, tech_pvt->local_sdp_video_port, tech_pvt->remote_sdp_video_ip, tech_pvt->remote_sdp_video_port, tech_pvt->video_agreed_pt, - tech_pvt->video_read_codec.implementation->samples_per_frame, - 0, + 1, + 10000, (switch_rtp_flag_t) flags, NULL, &err, diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index 396ed2d052..9123633638 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -33,6 +33,7 @@ #include +#ifdef SWITCH_VIDEO_IN_THREADS struct echo_helper { switch_core_session_t *session; int up; @@ -54,24 +55,32 @@ static void *SWITCH_THREAD_FUNC echo_video_thread(switch_thread_t *thread, void break; } + if (switch_test_flag(read_frame, SFF_CNG)) { + continue; + } + switch_core_session_write_video_frame(session, read_frame, -1, 0); } eh->up = 0; return NULL; } +#endif SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session) { switch_status_t status; switch_frame_t *read_frame; - struct echo_helper eh = {0}; switch_channel_t *channel = switch_core_session_get_channel(session); +#ifdef SWITCH_VIDEO_IN_THREADS + struct echo_helper eh = {0}; switch_thread_t *thread; switch_threadattr_t *thd_attr = NULL; +#endif switch_channel_pre_answer(channel); - + +#ifdef SWITCH_VIDEO_IN_THREADS if (switch_channel_test_flag(channel, CF_VIDEO)) { eh.session = session; switch_threadattr_create(&thd_attr, switch_core_session_get_pool(session)); @@ -79,6 +88,7 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session) switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_thread_create(&thread, thd_attr, echo_video_thread, &eh, switch_core_session_get_pool(session)); } +#endif while(switch_channel_ready(channel)) { status = switch_core_session_read_frame(session, &read_frame, -1, 0); @@ -86,13 +96,31 @@ SWITCH_DECLARE(void) switch_ivr_session_echo(switch_core_session_t *session) break; } switch_core_session_write_frame(session, read_frame, -1, 0); + +#ifndef SWITCH_VIDEO_IN_THREADS + status = switch_core_session_read_video_frame(session, &read_frame, -1, 0); + + if (!SWITCH_READ_ACCEPTABLE(status)) { + break; + } + + if (switch_test_flag(read_frame, SFF_CNG)) { + continue; + } + + switch_core_session_write_video_frame(session, read_frame, -1, 0); +#endif + } +#ifdef SWITCH_VIDEO_IN_THREADS if (eh.up) { while(eh.up) { switch_yield(1000); } } +#endif + } typedef struct { diff --git a/src/switch_ivr_bridge.c b/src/switch_ivr_bridge.c index 5653c9ace5..0daa4eaa8f 100644 --- a/src/switch_ivr_bridge.c +++ b/src/switch_ivr_bridge.c @@ -36,6 +36,7 @@ static const switch_state_handler_table_t audio_bridge_peer_state_handlers; /* Bridge Related Stuff*/ /*********************************************************************************/ +#ifdef SWITCH_VIDEO_IN_THREADS struct vid_helper { switch_core_session_t *session_a; switch_core_session_t *session_b; @@ -52,7 +53,7 @@ static void *SWITCH_THREAD_FUNC video_bridge_thread(switch_thread_t *thread, voi vh->up = 1; while(switch_channel_ready(channel) && vh->up == 1) { status = switch_core_session_read_video_frame(vh->session_a, &read_frame, -1, 0); - + if (!SWITCH_READ_ACCEPTABLE(status)) { break; } @@ -64,7 +65,6 @@ static void *SWITCH_THREAD_FUNC video_bridge_thread(switch_thread_t *thread, voi return NULL; } - static void launch_video(struct vid_helper *vh) { switch_thread_t *thread; @@ -75,7 +75,7 @@ static void launch_video(struct vid_helper *vh) switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE); switch_thread_create(&thread, thd_attr, video_bridge_thread, vh, switch_core_session_get_pool(vh->session_a)); } - +#endif struct switch_ivr_bridge_data { switch_core_session_t *session; @@ -96,9 +96,12 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) switch_channel_t *chan_a, *chan_b; switch_frame_t *read_frame; switch_core_session_t *session_a, *session_b; - uint32_t loop_count = 0, vid_launch = 0; + uint32_t loop_count = 0; const char *app_name = NULL, *app_arg = NULL; +#ifdef SWITCH_VIDEO_IN_THREADS struct vid_helper vh = { 0 }; + uint32_t vid_launch = 0; +#endif session_a = data->session; if (!(session_b = switch_core_session_locate(data->b_uuid))) { @@ -157,12 +160,14 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) continue; } +#ifdef SWITCH_VIDEO_IN_THREADS if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO) && !vid_launch) { vid_launch++; vh.session_a = session_a; vh.session_b = session_b; launch_video(&vh); } +#endif /* if 1 channel has DTMF pass it to the other */ while (switch_channel_has_dtmf(chan_a)) { @@ -216,6 +221,19 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) } } +#ifndef SWITCH_VIDEO_IN_THREADS + if (switch_channel_test_flag(chan_a, CF_VIDEO) && switch_channel_test_flag(chan_b, CF_VIDEO)) { + /* read video from 1 channel and write it to the other */ + status = switch_core_session_read_video_frame(session_a, &read_frame, -1, 0); + + if (!SWITCH_READ_ACCEPTABLE(status)) { + break; + } + + switch_core_session_write_video_frame(session_b, read_frame, -1, 0); + } +#endif + /* read audio from 1 channel and write it to the other */ status = switch_core_session_read_frame(session_a, &read_frame, -1, stream_id); @@ -237,6 +255,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) } } +#ifdef SWITCH_VIDEO_IN_THREADS if (vh.up) { vh.up = -1; switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Ending video thread.\n"); @@ -244,6 +263,7 @@ static void *audio_bridge_thread(switch_thread_t * thread, void *obj) switch_yield(100000); } } +#endif if (switch_channel_get_state(chan_b) >= CS_HANGUP) { diff --git a/src/switch_rtp.c b/src/switch_rtp.c index ad267d35b8..805ab36d38 100644 --- a/src/switch_rtp.c +++ b/src/switch_rtp.c @@ -1040,7 +1040,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ while (switch_rtp_ready(rtp_session)) { bytes = sizeof(rtp_msg_t); status = switch_socket_recvfrom(rtp_session->from_addr, rtp_session->sock, 0, (void *) &rtp_session->recv_msg, &bytes); - + if (!SWITCH_STATUS_IS_BREAK(status) && rtp_session->timer.interval) { switch_core_timer_step(&rtp_session->timer); } @@ -1151,7 +1151,7 @@ static int rtp_common_read(switch_rtp_t *rtp_session, switch_payload_t *payload_ } bytes = jb_frame->dlen + rtp_header_len; rtp_session->recv_msg.header.ts = htonl(jb_frame->ts); - } else if (switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { /* We're late! We're Late! */ + } else if (!bytes && switch_test_flag(rtp_session, SWITCH_RTP_FLAG_USE_TIMER)) { /* We're late! We're Late! */ uint8_t *data = (uint8_t *) rtp_session->recv_msg.body; if (!switch_test_flag(rtp_session, SWITCH_RTP_FLAG_NOBLOCK) && status == SWITCH_STATUS_BREAK) {