}
}
- if (switch_test_flag(imember->conference, CFLAG_MANAGE_INBOUND_VIDEO_BITRATE) && !imember->managed_kps) {
- switch_core_session_message_t msg = { 0 };
- int kps;
+ if (layer) {
+ if (switch_test_flag(imember->conference, CFLAG_MANAGE_INBOUND_VIDEO_BITRATE) && !imember->managed_kps) {
+ switch_core_session_message_t msg = { 0 };
+ int kps;
- //if (!layer || !switch_test_flag(imember, MFLAG_CAN_BE_SEEN) || imember->avatar_png_img) {
- // kps = switch_calc_bitrate(320, 240, 2, imember->conference->video_fps.fps);
+ //if (!layer || !switch_test_flag(imember, MFLAG_CAN_BE_SEEN) || imember->avatar_png_img) {
+ // kps = switch_calc_bitrate(320, 240, 2, imember->conference->video_fps.fps);
- // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "%s auto-setting bitrate to %dkps because user's image is not visible\n",
- // switch_channel_get_name(imember->channel), kps);
- //} else {
+ // switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "%s auto-setting bitrate to %dkps because user's image is not visible\n",
+ // switch_channel_get_name(imember->channel), kps);
+ //} else {
kps = switch_calc_bitrate(layer->screen_w, layer->screen_h, 2, imember->conference->video_fps.fps);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "%s auto-setting bitrate to %dkps to accomodate %dx%d resolution\n",
switch_channel_get_name(imember->channel), kps, layer->screen_w, layer->screen_h);
//}
- msg.message_id = SWITCH_MESSAGE_INDICATE_BITRATE_REQ;
- msg.numeric_arg = kps * 1024;
- msg.from = __FILE__;
+ msg.message_id = SWITCH_MESSAGE_INDICATE_BITRATE_REQ;
+ msg.numeric_arg = kps * 1024;
+ msg.from = __FILE__;
- switch_core_session_receive_message(imember->session, &msg);
- imember->managed_kps = kps;
- }
+ switch_core_session_receive_message(imember->session, &msg);
+ imember->managed_kps = kps;
+ }
- if (layer) {
if (layer->cur_img && layer->cur_img != imember->avatar_png_img) {
switch_img_free(&layer->cur_img);
}
switch_assert(conference != NULL);
switch_assert(member != NULL);
- if (member->session && switch_test_flag(conference, CFLAG_TRANSCODE_VIDEO)) {
- switch_channel_set_flag(member->channel, CF_VIDEO_DECODED_READ);
- switch_core_media_gen_key_frame(member->session);
- }
-
switch_mutex_lock(conference->mutex);
switch_mutex_lock(member->audio_in_mutex);
switch_mutex_lock(member->audio_out_mutex);
msg.message_id = SWITCH_MESSAGE_INDICATE_BRIDGE;
switch_core_session_receive_message(session, &msg);
+ if (switch_test_flag(conference, CFLAG_TRANSCODE_VIDEO)) {
+ switch_channel_set_flag(channel, CF_VIDEO_DECODED_READ);
+ switch_core_media_gen_key_frame(session);
+ }
+
/* Chime in the core video thread */
switch_core_session_set_video_read_callback(session, video_thread_callback, (void *)&member);
};
+static switch_bool_t check_dtls(switch_core_session_t *session);
static switch_srtp_crypto_suite_t SUITES[CRYPTO_INVALID] = {
{ "AEAD_AES_256_GCM_8", AEAD_AES_256_GCM_8, 44},
if (!smh->mparams->remote_ip) {
smh->mparams->remote_ip = engine->cur_payload_map->remote_sdp_ip;
}
-
+
if (engine->remote_rtcp_port) {
engine->remote_rtcp_port = engine->cur_payload_map->remote_sdp_port;
}
v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
- if (!v_engine->media_thread) {
- return SWITCH_STATUS_FALSE;
- }
+ switch_core_session_start_video_thread(session);
+
+ //if (!v_engine->media_thread) {
+ // return SWITCH_STATUS_FALSE;
+ //}
switch_mutex_lock(v_engine->mh.file_mutex);
smh->video_write_fh = fh;
}
+ if (!fh) switch_channel_video_sync(session->channel);
+
+ switch_core_session_wake_video_thread(session);
switch_mutex_unlock(v_engine->mh.file_mutex);
-
- switch_core_session_start_video_thread(session);
return SWITCH_STATUS_SUCCESS;
}
switch_image_t *blank_img = NULL;
switch_rgb_color_t bgcolor;
switch_rtp_engine_t *v_engine = NULL;
+
const char *var;
if (!(smh = session->media_handle)) {
int send_blank = 0;
if (!switch_channel_test_flag(channel, CF_VIDEO)) {
- if ((++loops % 100) == 0) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Waiting for video......\n");
+ if ((++loops % 100) == 0) switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG1, "Waiting for video......\n");
switch_yield(20000);
continue;
}
- if (switch_core_session_media_flow(session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_SENDONLY) {
- do_sleep = (++xloops > 20);
+ if (!smh->video_write_fh && !smh->video_read_fh && switch_core_session_media_flow(session, SWITCH_MEDIA_TYPE_VIDEO) == SWITCH_MEDIA_FLOW_SENDONLY) {
+ do_sleep = 1;
} else {
xloops = 0;
}
if (v_engine->smode == SWITCH_MEDIA_FLOW_SENDONLY) {
switch_channel_set_flag(channel, CF_VIDEO_READY);
- }
+ } else {
- if (!smh->video_write_fh || !switch_channel_test_flag(channel, CF_VIDEO_READY)) {
+ //if (!smh->video_write_fh || !switch_channel_test_flag(channel, CF_VIDEO_READY)) {
status = switch_core_session_read_video_frame(session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
if (!SWITCH_READ_ACCEPTABLE(status)) {
continue;
}
- if (switch_test_flag(read_frame, SFF_CNG)) {
- continue;
- }
- }
+ //if (switch_test_flag(read_frame, SFF_CNG)) {
+ // continue;
+ //}
+ //}
+
+ //if (vloops < 300 && (vloops % 100) == 0) {
+ // switch_core_media_gen_key_frame(session);
+ //switch_core_session_request_video_refresh(session);
+ //}
- if (vloops < 300 && (vloops % 100) == 0) {
- switch_core_media_gen_key_frame(session);
- switch_core_session_request_video_refresh(session);
}
vloops++;
if (switch_channel_test_flag(channel, CF_VIDEO_READY)) {
switch_mutex_lock(mh->file_mutex);
- if (smh->video_write_fh &&
- switch_channel_ready(session->channel) && switch_test_flag(smh->video_write_fh, SWITCH_FILE_OPEN) &&
- switch_core_file_read_video(smh->video_write_fh, &fr, SVR_BLOCK) == SWITCH_STATUS_SUCCESS) {
- switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_NONE, 0);
- switch_img_free(&fr.img);
+ if (smh->video_write_fh && switch_channel_ready(session->channel) && switch_test_flag(smh->video_write_fh, SWITCH_FILE_OPEN)) {
+ switch_status_t wstatus = switch_core_file_read_video(smh->video_write_fh, &fr, SVR_BLOCK|SVR_FLUSH);
+ if (wstatus == SWITCH_STATUS_SUCCESS) {
+ switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_NONE, 0);
+ switch_img_free(&fr.img);
+ } else if (wstatus != SWITCH_STATUS_BREAK) {
+ smh->video_write_fh = NULL;
+ }
} else if (smh->video_read_fh && switch_test_flag(smh->video_read_fh, SWITCH_FILE_OPEN) && read_frame->img) {
switch_core_file_write_video(smh->video_read_fh, read_frame);
}
} else if (switch_channel_test_flag(channel, CF_VIDEO_DECODED_READ)) {
send_blank = 1;
}
-
+
if ((send_blank || switch_channel_test_flag(channel, CF_VIDEO_BLANK)) &&
!session->video_read_callback && !switch_channel_test_flag(session->channel, CF_BRIDGED)) {
fr.img = blank_img;
- switch_yield(100000);
+ switch_yield(10000);
switch_core_session_write_video_frame(session, &fr, SWITCH_IO_FLAG_NONE, SWITCH_IO_FLAG_FORCE);
} else if (read_frame && (switch_channel_test_flag(channel, CF_VIDEO_ECHO))) {
switch_core_session_write_video_frame(session, read_frame, SWITCH_IO_FLAG_NONE, 0);
switch_rtp_engine_t *v_engine = NULL;
switch_media_handle_t *smh;
+ if (!switch_channel_test_flag(session->channel, CF_VIDEO)) {
+ return SWITCH_STATUS_NOTIMPL;
+ }
+
if (!(smh = session->media_handle)) {
return SWITCH_STATUS_FALSE;
}
v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
+ switch_mutex_lock(smh->control_mutex);
+
if (v_engine->media_thread) {
+ switch_mutex_unlock(smh->control_mutex);
return SWITCH_STATUS_FALSE;
}
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));
+ switch_mutex_unlock(smh->control_mutex);
return SWITCH_STATUS_SUCCESS;
}
return;
}
+ switch_core_session_start_video_thread(session);
+
switch_mutex_lock(smh->control_mutex);
if (!smh->video_function_running) {
smh->video_function = video_function;
}
switch_rtp_set_payload_map(v_engine->rtp_session, &v_engine->payload_map);
- //switch_core_session_start_video_thread(session);
switch_channel_set_flag(session->channel, CF_VIDEO);
+ switch_core_session_start_video_thread(session);
if ((ssrc = switch_channel_get_variable(session->channel, "rtp_use_video_ssrc"))) {
uint32_t ssrc_ul = (uint32_t) strtoul(ssrc, NULL, 10);
"Invalid rtcp interval spec [%d] must be between 100 and 500000\n", interval);
interval = 5000;
}
- switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO, "Activating VIDEO RTCP PORT %d interval %d mux %d\n", remote_port, interval, v_engine->rtcp_mux);
+ switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_INFO,
+ "Activating VIDEO RTCP PORT %d interval %d mux %d\n", remote_port, interval, v_engine->rtcp_mux);
switch_rtp_activate_rtcp(v_engine->rtp_session, interval, remote_port, v_engine->rtcp_mux > 0);
}
if (!zstr(a_engine->local_dtls_fingerprint.type)) {
- switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\na=mid:audio\n",
+ switch_snprintf(buf + strlen(buf), SDPBUFLEN - strlen(buf), "a=fingerprint:%s %s\na=setup:%s\n",
a_engine->local_dtls_fingerprint.type,
a_engine->local_dtls_fingerprint.str, get_setup(session));
}
int flags = 0;
switch_status_t status;
- if (dtls_state == DS_OFF || dtls_state == DS_READY || dtls_state >= DS_FAIL) return 0;
+ if (dtls_state == DS_READY || dtls_state >= DS_FAIL) return 0;
status = switch_rtp_zerocopy_read_frame(engine->rtp_session, &engine->read_frame, flags);
return 1;
}
-static void check_dtls(switch_core_session_t *session)
+static switch_bool_t check_dtls(switch_core_session_t *session)
{
switch_media_handle_t *smh;
switch_rtp_engine_t *a_engine, *v_engine;
switch_assert(session);
if (!(smh = session->media_handle)) {
- return;
+ return SWITCH_FALSE;
}
if (switch_channel_down(session->channel)) {
- return;
+ return SWITCH_FALSE;
}
+ if (!switch_channel_test_flag(session->channel, CF_DTLS)) {
+ return SWITCH_TRUE;
+ }
+
a_engine = &smh->engines[SWITCH_MEDIA_TYPE_AUDIO];
v_engine = &smh->engines[SWITCH_MEDIA_TYPE_VIDEO];
if (a_engine->rtp_session) audio_checking = check_engine(a_engine);
if (v_engine->rtp_session) check_engine(v_engine);
} while (switch_channel_ready(session->channel) && (audio_checking || video_checking));
+
+ if (!audio_checking && !video_checking) {
+ return SWITCH_TRUE;
+ }
+
+ return SWITCH_FALSE;
}
}
}
break;
-
+
case SWITCH_MESSAGE_INDICATE_ANSWER:
case SWITCH_MESSAGE_INDICATE_PROGRESS:
+ case SWITCH_MESSAGE_ANSWER_EVENT:
+ case SWITCH_MESSAGE_PROGRESS_EVENT:
{
check_dtls(session);
}
switch_io_event_hook_video_read_frame_t *ptr;
uint32_t loops = 0;
switch_media_handle_t *smh;
-
+
switch_assert(session != NULL);
if (!(smh = session->media_handle)) {
return SWITCH_STATUS_FALSE;
}
-
top:
loops++;
session->video_read_callback = func;
session->video_read_user_data = user_data;
}
+
+ switch_core_session_start_video_thread(session);
switch_mutex_unlock(smh->control_mutex);
return status;
ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_addr = switch_core_strdup(rtp_session->pool, host);
ice->ice_params->cands[ice->ice_params->chosen[ice->proto]][ice->proto].con_port = port;
ice->missed_count = 0;
-
- switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
-
- if (!is_rtcp || rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
- switch_rtp_set_remote_address(rtp_session, host, port, 0, SWITCH_FALSE, &err);
- }
- if (is_rtcp || rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
- rtp_session->remote_rtcp_port = port;
- rtp_session->eff_remote_host_str = switch_core_strdup(rtp_session->pool, host);
+ if (is_rtcp) {
+ ice->addr = rtp_session->rtcp_remote_addr;
+ } else {
+ switch_rtp_set_remote_address(rtp_session, host, port, 0, SWITCH_FALSE, &err);
if (rtp_session->flags[SWITCH_RTP_FLAG_RTCP_MUX]) {
- rtp_session->rtcp_remote_addr = rtp_session->remote_addr;
- } else {
- switch_sockaddr_info_get(&rtp_session->rtcp_remote_addr,
- rtp_session->eff_remote_host_str, SWITCH_UNSPEC, rtp_session->remote_rtcp_port, 0, rtp_session->pool);
+ ice->addr = rtp_session->remote_addr;
}
-
}
}
ice = icep[j];
ok = 1;
-
+
if (j != IPR_RTP) {
break;
}
}
- //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
+ //if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] || 1) {
// switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_WARNING, "WTF OK %s %d\n", rtp_type(rtp_session), ok);
//}
if (!ice->ready) {
ice->ready = 1;
- if (rtp_session->flags[SWITCH_RTP_FLAG_VIDEO]) {
- switch_core_session_video_reinit(rtp_session->session);
- }
}
memset(stunbuf, 0, sizeof(stunbuf));
}
if (hosts_set) {
- switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
+ //switch_sockaddr_info_get(&ice->addr, host, SWITCH_UNSPEC, port, 0, rtp_session->pool);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE,
- "Auto Changing stun/%s/dtls port from %s:%u to %s:%u\n", is_rtcp ? "rtcp" : "rtp",
+ "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u\n", rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp",
host2, port2,
host, port);
}
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_NOTICE,
- "Auto Changing stun/%s/dtls port from %s:%u to %s:%u\n", is_rtcp ? "rtcp" : "rtp",
+ "Auto Changing %s stun/%s/dtls port from %s:%u to %s:%u\n", rtp_type(rtp_session), is_rtcp ? "rtcp" : "rtp",
host2, port2,
host, port);
old_host = switch_get_addr(bufb, sizeof(bufb), rtp_session->rtcp_remote_addr);
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(rtp_session->session), SWITCH_LOG_CRIT, "%s SEND %s RTCP %s:%d %ld\n",
rtp_session_name(rtp_session),
- rtp_session->flags[SWITCH_RTP_FLAG_VIDEO] ? "video" : "audio",
+ rtp_type(rtp_session),
old_host,
switch_sockaddr_get_port(rtp_session->rtcp_remote_addr),
rtcp_bytes);
ice = &rtp_session->ice;
rtp_session->flags[SWITCH_RTP_FLAG_PAUSE] = 0;
rtp_session->flags[SWITCH_RTP_FLAG_MUTE] = 0;
- switch_core_session_video_reinit(rtp_session->session);
} else {
ice = &rtp_session->rtcp_ice;
}