FS-10472: [mod_conference] Crash due to hangup race in conference personal canvas mode -- the saga continues

This commit is contained in:
Anthony Minessale 2017-07-19 23:06:19 -05:00
parent 03d9a29401
commit 2673e4e768
2 changed files with 64 additions and 31 deletions

View File

@ -501,7 +501,7 @@ static void set_bounds(int *x, int *y, int img_w, int img_h, int crop_w, int cro
void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, switch_bool_t freeze) void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, switch_bool_t freeze)
{ {
switch_image_t *IMG, *img; switch_image_t *IMG, *img;
int img_changed = 0; int img_changed = 0, want_w = 0, want_h = 0;
switch_mutex_lock(layer->canvas->mutex); switch_mutex_lock(layer->canvas->mutex);
@ -817,10 +817,19 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
y_pos += (layer->screen_h - img_h) / 2; y_pos += (layer->screen_h - img_h) / 2;
} }
if (layer->img && (layer->img->d_w != img_w || layer->img->d_h != img_h)) { if (layer->img) {
if (layer->banner_img) {
want_h = img_h - layer->banner_img->d_h;
} else {
want_h = layer->img->d_h;
}
want_w = layer->img->d_w;
if (want_w != layer->img->d_w || want_h != layer->img->d_h) {
switch_img_free(&layer->img); switch_img_free(&layer->img);
layer->banner_patched = 0; layer->banner_patched = 0;
conference_video_clear_layer(layer); }
} }
switch_mutex_lock(layer->overlay_mutex); switch_mutex_lock(layer->overlay_mutex);
@ -829,18 +838,6 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
} }
switch_mutex_unlock(layer->overlay_mutex); switch_mutex_unlock(layer->overlay_mutex);
if (layer->banner_img && !layer->banner_patched) {
switch_img_fill(layer->canvas->img, layer->x_pos + layer->geometry.border, layer->y_pos + layer->geometry.border, layer->screen_w, layer->screen_h, &layer->canvas->letterbox_bgcolor);
switch_img_fit(&layer->banner_img, layer->screen_w, layer->screen_h, SWITCH_FIT_SIZE);
switch_img_patch(IMG, layer->banner_img, layer->x_pos + layer->geometry.border, layer->y_pos + (layer->screen_h - layer->banner_img->d_h) + layer->geometry.border);
if (!freeze) {
switch_img_set_rect(layer->img, 0, 0, layer->img->d_w, layer->img->d_h - layer->banner_img->d_h);
}
layer->banner_patched = 1;
}
switch_assert(layer->img); switch_assert(layer->img);
if (layer->geometry.border) { if (layer->geometry.border) {
@ -854,7 +851,6 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
switch_img_scale(img, &layer->img, img_w, img_h); switch_img_scale(img, &layer->img, img_w, img_h);
if (layer->logo_img) { if (layer->logo_img) {
//int ew = layer->screen_w - (layer->geometry.border * 2), eh = layer->screen_h - (layer->banner_img ? layer->banner_img->d_h : 0) - (layer->geometry.border * 2); //int ew = layer->screen_w - (layer->geometry.border * 2), eh = layer->screen_h - (layer->banner_img ? layer->banner_img->d_h : 0) - (layer->geometry.border * 2);
int ew = layer->img->d_w, eh = layer->img->d_h; int ew = layer->img->d_w, eh = layer->img->d_h;
@ -868,6 +864,20 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
//switch_img_patch(IMG, layer->logo_img, layer->x_pos + ex + layer->geometry.border, layer->y_pos + ey + layer->geometry.border); //switch_img_patch(IMG, layer->logo_img, layer->x_pos + ex + layer->geometry.border, layer->y_pos + ey + layer->geometry.border);
} }
if (layer->banner_img && !layer->banner_patched) {
int ew = layer->img->d_w, eh = layer->img->d_h;
int ex = 0, ey = 0;
switch_img_fit(&layer->banner_img, layer->screen_w, layer->screen_h, SWITCH_FIT_SIZE);
switch_img_find_position(POS_LEFT_BOT, ew, eh, layer->banner_img->d_w, layer->banner_img->d_h, &ex, &ey);
switch_img_patch(layer->img, layer->banner_img, ex, ey);
layer->banner_patched = 1;
}
if (layer->img) { if (layer->img) {
//switch_img_copy(img, &layer->img); //switch_img_copy(img, &layer->img);
@ -1291,6 +1301,7 @@ void conference_video_layer_set_banner(conference_member_t *member, mcu_layer_t
switch_img_free(&layer->banner_img); switch_img_free(&layer->banner_img);
//switch_img_free(&layer->logo_img); //switch_img_free(&layer->logo_img);
layer->banner_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, layer->screen_w, font_size * 2, 1); layer->banner_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, layer->screen_w, font_size * 2, 1);
conference_video_reset_image(layer->banner_img, &bgcolor); conference_video_reset_image(layer->banner_img, &bgcolor);
switch_img_txt_handle_render(layer->txthandle, layer->banner_img, font_size / 2, font_size / 2, text, NULL, fg, bg, 0, 0); switch_img_txt_handle_render(layer->txthandle, layer->banner_img, font_size / 2, font_size / 2, text, NULL, fg, bg, 0, 0);
@ -2072,7 +2083,9 @@ void *SWITCH_THREAD_FUNC conference_video_layer_thread_run(switch_thread_t *thre
mcu_layer_t *layer = NULL; mcu_layer_t *layer = NULL;
mcu_canvas_t *canvas = NULL; mcu_canvas_t *canvas = NULL;
switch_mutex_lock(member->layer_cond2_mutex);
switch_thread_cond_wait(member->layer_cond, member->layer_cond_mutex); switch_thread_cond_wait(member->layer_cond, member->layer_cond_mutex);
switch_mutex_unlock(member->layer_cond2_mutex);
if (!conference_utils_member_test_flag(member, MFLAG_RUNNING)) { if (!conference_utils_member_test_flag(member, MFLAG_RUNNING)) {
break; break;
@ -2106,12 +2119,30 @@ void *SWITCH_THREAD_FUNC conference_video_layer_thread_run(switch_thread_t *thre
void conference_video_wake_layer_thread(conference_member_t *member) void conference_video_wake_layer_thread(conference_member_t *member)
{ {
if (member->layer_cond) { if (member->layer_cond) {
if (switch_mutex_trylock(member->layer_cond_mutex) == SWITCH_STATUS_SUCCESS) { switch_status_t status;
int tries = 0;
top:
status = switch_mutex_trylock(member->layer_cond_mutex);
if (status == SWITCH_STATUS_SUCCESS) {
switch_thread_cond_signal(member->layer_cond); switch_thread_cond_signal(member->layer_cond);
switch_mutex_unlock(member->layer_cond_mutex); switch_mutex_unlock(member->layer_cond_mutex);
return;
} else {
if (switch_mutex_trylock(member->layer_cond2_mutex) == SWITCH_STATUS_SUCCESS) {
switch_mutex_unlock(member->layer_cond2_mutex);
} else {
if (++tries < 10) {
switch_cond_next();
goto top;
} }
} }
} }
}
}
void conference_video_launch_layer_thread(conference_member_t *member) void conference_video_launch_layer_thread(conference_member_t *member)
{ {
@ -2124,6 +2155,7 @@ void conference_video_launch_layer_thread(conference_member_t *member)
if (!member->layer_cond) { if (!member->layer_cond) {
switch_thread_cond_create(&member->layer_cond, member->pool); switch_thread_cond_create(&member->layer_cond, member->pool);
switch_mutex_init(&member->layer_cond_mutex, SWITCH_MUTEX_NESTED, member->pool); switch_mutex_init(&member->layer_cond_mutex, SWITCH_MUTEX_NESTED, member->pool);
switch_mutex_init(&member->layer_cond2_mutex, SWITCH_MUTEX_NESTED, member->pool);
} }
switch_mutex_lock(conference_globals.hash_mutex); switch_mutex_lock(conference_globals.hash_mutex);
@ -3489,14 +3521,7 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread_t *thr
} }
if (imember->session && switch_core_session_media_flow(imember->session, SWITCH_MEDIA_TYPE_VIDEO) != SWITCH_MEDIA_FLOW_SENDONLY && switch_core_session_media_flow(imember->session, SWITCH_MEDIA_TYPE_VIDEO) != SWITCH_MEDIA_FLOW_INACTIVE) { if (imember->session && switch_core_session_media_flow(imember->session, SWITCH_MEDIA_TYPE_VIDEO) != SWITCH_MEDIA_FLOW_SENDONLY && switch_core_session_media_flow(imember->session, SWITCH_MEDIA_TYPE_VIDEO) != SWITCH_MEDIA_FLOW_INACTIVE) {
switch_image_t *next_img = NULL; conference_video_pop_next_image(imember, &imember->pcanvas_img);
conference_video_pop_next_image(imember, &next_img);
if (next_img) {
switch_img_free(&imember->pcanvas_img);
imember->pcanvas_img = next_img;
}
} }
if (imember->session) { if (imember->session) {
@ -3658,8 +3683,13 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread_t *thr
} }
if (layer && use_img) { if (layer && use_img) {
conference_video_scale_and_patch(layer, use_img, SWITCH_FALSE); switch_img_copy(use_img, &layer->cur_img);
} }
if (layer) {
conference_video_scale_and_patch(layer, NULL, SWITCH_FALSE);
}
} }
} }
@ -3739,6 +3769,8 @@ void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread_t *thr
} }
} }
switch_img_free(&imember->pcanvas_img);
if (imember->session) { if (imember->session) {
switch_core_session_rwunlock(imember->session); switch_core_session_rwunlock(imember->session);
} }

View File

@ -848,6 +848,7 @@ struct conference_member {
switch_thread_t *input_thread; switch_thread_t *input_thread;
switch_thread_cond_t *layer_cond; switch_thread_cond_t *layer_cond;
switch_mutex_t *layer_cond_mutex; switch_mutex_t *layer_cond_mutex;
switch_mutex_t *layer_cond2_mutex;
cJSON *json; cJSON *json;
cJSON *status_field; cJSON *status_field;
uint8_t loop_loop; uint8_t loop_loop;