FS-7513 refactor

This commit is contained in:
Anthony Minessale 2015-05-27 03:24:16 -05:00 committed by Michael Jerris
parent 2188358832
commit 76fc6940df
1 changed files with 78 additions and 44 deletions

View File

@ -686,6 +686,8 @@ struct conference_member {
int managed_kps; int managed_kps;
int blackouts; int blackouts;
int good_img; int good_img;
int auto_avatar;
int avatar_patched;
}; };
typedef enum { typedef enum {
@ -1201,6 +1203,7 @@ static void detach_video_layer(conference_member_t *member)
reset_layer(member->conference->canvas, layer); reset_layer(member->conference->canvas, layer);
layer->member_id = 0; layer->member_id = 0;
member->video_layer_id = -1; member->video_layer_id = -1;
member->avatar_patched = 0;
check_used_layers(member->conference); check_used_layers(member->conference);
switch_mutex_unlock(member->conference->canvas->mutex); switch_mutex_unlock(member->conference->canvas->mutex);
} }
@ -1463,6 +1466,8 @@ static switch_status_t attach_video_layer(conference_member_t *member, int idx)
reset_layer(member->conference->canvas, layer); reset_layer(member->conference->canvas, layer);
switch_img_free(&layer->mute_img); switch_img_free(&layer->mute_img);
member->avatar_patched = 0;
if (member->avatar_png_img) { if (member->avatar_png_img) {
layer->is_avatar = 1; layer->is_avatar = 1;
} }
@ -1844,6 +1849,8 @@ static void check_avatar(conference_member_t *member, switch_bool_t force)
switch_mutex_lock(member->conference->canvas->mutex); switch_mutex_lock(member->conference->canvas->mutex);
} }
member->avatar_patched = 0;
if (!force && switch_channel_test_flag(member->channel, CF_VIDEO) && member->video_flow != SWITCH_MEDIA_FLOW_SENDONLY) { if (!force && switch_channel_test_flag(member->channel, CF_VIDEO) && member->video_flow != SWITCH_MEDIA_FLOW_SENDONLY) {
switch_set_flag_locked(member, MFLAG_ACK_VIDEO); switch_set_flag_locked(member, MFLAG_ACK_VIDEO);
} else { } else {
@ -2039,29 +2046,36 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
if (imember->blanks == conference->video_fps.fps * 5) { if (imember->blanks == conference->video_fps.fps * 5) {
imember->blackouts++; imember->blackouts++;
check_avatar(imember, SWITCH_TRUE); check_avatar(imember, SWITCH_TRUE);
if (layer && imember->avatar_png_img) {
layer->is_avatar = 1;
}
imember->managed_kps = 0; imember->managed_kps = 0;
if (imember->avatar_png_img) {
//if (layer) {
//layer->is_avatar = 1;
//}
imember->auto_avatar = 1;
}
} }
} }
} }
} else { } else {
int flushed = flush_video_queue(imember->video_queue); int flushed = flush_video_queue(imember->video_queue);
if (flushed && imember->blanks) { if (flushed && imember->auto_avatar) {
switch_img_free(&imember->avatar_png_img); switch_img_free(&imember->avatar_png_img);
imember->avatar_patched = 0;
reset_video_bitrate_counters(imember); reset_video_bitrate_counters(imember);
if (layer) { if (layer) {
layer->is_avatar = 0; layer->is_avatar = 0;
imember->auto_avatar = 0;
} }
imember->blanks = 0; imember->blanks = 0;
//switch_channel_video_sync(imember->channel); //switch_channel_video_sync(imember->channel);
} } else {
img = imember->avatar_png_img; }
} }
layer = NULL; layer = NULL;
@ -2078,11 +2092,25 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
} }
} }
if (imember->avatar_png_img) {
if (layer) {
if (!imember->avatar_patched || !layer->cur_img) {
layer->tagged = 1;
//layer->is_avatar = 1;
switch_img_free(&layer->cur_img);
switch_img_copy(imember->avatar_png_img, &layer->cur_img);
imember->avatar_patched = 1;
}
}
switch_img_free(&img);
}
avatar_layers = 0; avatar_layers = 0;
for (i = 0; i < conference->canvas->total_layers; i++) { for (i = 0; i < conference->canvas->total_layers; i++) {
mcu_layer_t *xlayer = &conference->canvas->layers[i]; mcu_layer_t *xlayer = &conference->canvas->layers[i];
if (xlayer->is_avatar && xlayer->member_id != conference->video_floor_holder && !switch_test_flag(imember, MFLAG_MOD)) { if (xlayer->is_avatar && xlayer->member_id != conference->video_floor_holder) {
avatar_layers++; avatar_layers++;
} }
} }
@ -2123,22 +2151,30 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
} }
} }
if (layer) {
if (switch_test_flag(imember->conference, CFLAG_MANAGE_INBOUND_VIDEO_BITRATE) && !imember->managed_kps) { if (switch_test_flag(imember->conference, CFLAG_MANAGE_INBOUND_VIDEO_BITRATE) && !imember->managed_kps) {
switch_core_session_message_t msg = { 0 }; switch_core_session_message_t msg = { 0 };
int kps; int kps;
int w = 320;
int h = 240;
//if (!layer || !switch_test_flag(imember, MFLAG_CAN_BE_SEEN) || imember->avatar_png_img) { if (layer) {
// kps = switch_calc_bitrate(320, 240, 2, imember->conference->video_fps.fps); if (layer->screen_w > 320 && layer->screen_h > 240) {
w = layer->screen_w;
h = layer->screen_h;
}
}
// 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);
if (!layer || !switch_test_flag(imember, MFLAG_CAN_BE_SEEN) || imember->avatar_png_img) {
kps = 200;
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(w, 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_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); switch_channel_get_name(imember->channel), kps, layer->screen_w, layer->screen_h);
//} }
msg.message_id = SWITCH_MESSAGE_INDICATE_BITRATE_REQ; msg.message_id = SWITCH_MESSAGE_INDICATE_BITRATE_REQ;
msg.numeric_arg = kps * 1024; msg.numeric_arg = kps * 1024;
@ -2148,9 +2184,12 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
imember->managed_kps = kps; imember->managed_kps = kps;
} }
if (layer->cur_img && layer->cur_img != imember->avatar_png_img) {
switch_img_free(&layer->cur_img); if (layer) {
}
//if (layer->cur_img && layer->cur_img != imember->avatar_png_img) {
// switch_img_free(&layer->cur_img);
//}
if (switch_test_flag(imember, MFLAG_CAN_BE_SEEN)) { if (switch_test_flag(imember, MFLAG_CAN_BE_SEEN)) {
layer->mute_patched = 0; layer->mute_patched = 0;
@ -2185,22 +2224,15 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
} }
} }
if (img) { if (img) {
if (imember->avatar_png_img) {
if (!layer->cur_img) {
switch_img_copy(imember->avatar_png_img, &layer->cur_img);
}
if (img != imember->avatar_png_img) { if (img != layer->cur_img) {
switch_img_free(&img); switch_img_free(&layer->cur_img);
}
}
if (img && !layer->cur_img) {
layer->cur_img = img; layer->cur_img = img;
} }
img = NULL; img = NULL;
layer->tagged = 1; layer->tagged = 1;
@ -2250,6 +2282,7 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
layer->tagged = 0; layer->tagged = 0;
} }
layer->bugged = 0; layer->bugged = 0;
} }
} }
@ -4651,6 +4684,7 @@ static switch_status_t conference_del_member(conference_obj_t *conference, confe
switch_ivr_dmachine_destroy(&member->dmachine); switch_ivr_dmachine_destroy(&member->dmachine);
} }
member->avatar_patched = 0;
switch_img_free(&member->avatar_png_img); switch_img_free(&member->avatar_png_img);
switch_img_free(&member->video_mute_img); switch_img_free(&member->video_mute_img);