]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9742
authorAnthony Minessale <anthm@freeswitch.org>
Thu, 17 Nov 2016 01:15:41 +0000 (19:15 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Thu, 17 Nov 2016 01:15:41 +0000 (19:15 -0600)
src/mod/applications/mod_conference/conference_video.c
src/mod/applications/mod_conference/mod_conference.h
src/mod/applications/mod_cv/mod_cv.cpp

index 7363cbcfc09d675a62ccba52bb4ff7bd58736998..3450c3c00d7a5afda2e3908cedde1aa1dbf866fb 100644 (file)
@@ -365,6 +365,33 @@ void conference_video_reset_layer(mcu_layer_t *layer)
        switch_img_free(&layer->cur_img);
 }
 
+static void set_pan(mcu_layer_t *layer, int crop_point, int max_width)
+{
+       if (layer->crop_point <= 0 || layer->crop_point > max_width) {
+               layer->crop_point = crop_point;
+       } else if (crop_point > layer->crop_point) {
+               if (crop_point - layer->crop_point > 25) {
+                       layer->crop_point += 5;
+               } else {
+                       layer->crop_point++;
+               }
+
+               if (crop_point < layer->crop_point) {
+                       layer->crop_point = crop_point;
+               }
+       } else if (crop_point < layer->crop_point) {
+               if (layer->crop_point - crop_point > 25) {
+                       layer->crop_point -= 5;
+               } else {
+                       layer->crop_point--;
+               }
+
+               if (crop_point > layer->crop_point) {
+                       layer->crop_point = crop_point;
+               }
+       }
+}
+
 void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg, switch_bool_t freeze)
 {
        switch_image_t *IMG, *img;
@@ -421,7 +448,7 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
 
                if (layer->last_img_addr != img_addr && layer->geometry.zoom) {
                        uint32_t new_w = 0, new_h = 0;
-                       int cropsize = 0;
+                       int crop_point = 0;
                        double scale = 1;
 
                        if (screen_aspect < img_aspect) {
@@ -434,19 +461,23 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
                                new_h = (uint32_t)((double)layer->screen_h / scale);
 
                                if (layer->bug_frame.geometry.w) {
-                                       cropsize = layer->bug_frame.geometry.x - (new_w / 2);
+                                       //new_w = layer->bug_frame.geometry.w * 2;
+                                       //new_h = new_w / screen_aspect;
+                                       crop_point = switch_round_to_step(layer->bug_frame.geometry.x - (new_w / 2), 25);
                                } else {
-                                       cropsize = (img->d_w - new_w) / 2;
+                                       crop_point = (img->d_w - new_w) / 2;
                                }
 
-                               if (cropsize < 1) {
-                                       cropsize = 1;
-                               } else if (cropsize > img->d_w - new_w) {
-                                       cropsize = img->d_w - new_w;
+                               if (crop_point < 1) {
+                                       crop_point = 1;
+                               } else if (crop_point > img->d_w - new_w) {
+                                       crop_point = img->d_w - new_w;
                                }
-                               
-                               if (cropsize > 0) {
-                                       switch_img_set_rect(img, cropsize, 0, new_w, new_h);
+
+                               set_pan(layer, crop_point, img->d_w - new_w);
+
+                               if (layer->crop_point > 0) {
+                                       switch_img_set_rect(img, layer->crop_point, 0, new_w, new_h);
                                        img_aspect = (double) img->d_w / img->d_h;
                                }
 
@@ -460,20 +491,22 @@ void conference_video_scale_and_patch(mcu_layer_t *layer, switch_image_t *ximg,
                                new_w = (uint32_t)((double)layer->screen_w / scale);
                                new_h = (uint32_t)((double)layer->screen_h / scale);
 
-                               if (layer->bug_frame.geometry.y) {
-                                       cropsize = layer->bug_frame.geometry.y - (new_h / 2);
+                               if (layer->bug_frame.geometry.w) {
+                                       crop_point = layer->bug_frame.geometry.y - (new_h / 2);
                                } else {
-                                       cropsize = (img->d_h - new_h) / 2;
+                                       crop_point = (img->d_h - new_h) / 2;
                                }
 
-                               if (cropsize < 1) {
-                                       cropsize = 1;
-                               } else if (cropsize > img->d_h - new_h) {
-                                       cropsize = img->d_h - new_h;
+                               if (crop_point < 1) {
+                                       crop_point = 1;
+                               } else if (crop_point > img->d_h - new_h) {
+                                       crop_point = img->d_h - new_h;
                                }
 
-                               if (cropsize > 0) {
-                                       switch_img_set_rect(img, 0, cropsize, (unsigned int)(layer->screen_w/scale), (unsigned int)(layer->screen_h/scale));
+                               set_pan(layer, crop_point, img->d_h - new_h);
+
+                               if (crop_point > 0) {
+                                       switch_img_set_rect(img, 0, crop_point, (unsigned int)(layer->screen_w/scale), (unsigned int)(layer->screen_h/scale));
                                        img_aspect = (double) img->d_w / img->d_h;
                                }
                        }
index cb5c0442373601334fddc4d3a6ca3ad4d11cbe21..8a03a928e31832d0c0d7bfcbb75dbd7a4c15dd87 100644 (file)
@@ -446,6 +446,7 @@ typedef struct mcu_layer_s {
        int refresh;
        int clear;
        int is_avatar;
+       int crop_point;
        switch_size_t last_img_addr;
        switch_img_position_t logo_pos;
        switch_image_t *img;
index bf2aab30d45029061f76d54336d6b4ae32bf700f..42b826e9a8b624dcaf0dea9bd787da93983b4e12 100644 (file)
@@ -693,7 +693,6 @@ void detectAndDraw(cv_context_t *context)
     switch_mutex_unlock(context->mutex);
 }
 
-
 static switch_status_t video_thread_callback(switch_core_session_t *session, switch_frame_t *frame, void *user_data)
 {
     cv_context_t *context = (cv_context_t *) user_data;
@@ -730,10 +729,27 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
         switch_img_to_raw(frame->img, context->rawImage->imageData, context->rawImage->widthStep, SWITCH_IMG_FMT_RGB24);
         detectAndDraw(context);
                
-               if (context->detect_event && context->shape_idx &&
-                       abs(context->shape[0].cx - context->last_shape[0].cx) > 200 || abs(context->shape[0].w - context->last_shape[0].w) > 200) {
-                       context->detected.simo_count = 0;
-                       context->detected.simo_miss_count = context->confidence_level;
+               if (context->shape_idx && context->shape[0].w && context->last_shape[0].w) {
+                       int max, min;
+                       int pct;
+                       
+                       if (context->shape[0].w > context->last_shape[0].w) {
+                               max = context->shape[0].w;
+                               min = context->last_shape[0].w;
+                       } else {
+                               max = context->last_shape[0].w;
+                               min = context->shape[0].w;
+                       }
+
+                       pct = 100 - (((double)min / (double)max) * 100.0f );
+                       
+                       if (pct > 25) {
+                               context->detected.simo_count = 0;
+                               memset(context->last_shape, 0, sizeof(context->last_shape[0]) * MAX_SHAPES);
+                               if (context->detect_event) {
+                                       context->detected.simo_miss_count = context->confidence_level;
+                               }
+                       }
                }
 
         if (context->detected.simo_count > context->confidence_level) {
@@ -772,6 +788,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
 
 
                     memset(context->shape, 0, sizeof(context->shape[0]) * MAX_SHAPES);
+                    memset(context->last_shape, 0, sizeof(context->last_shape[0]) * MAX_SHAPES);
 
                     switch_channel_execute_on(channel, "execute_on_cv_detect_off_primary");
                     reset_stats(&context->nestDetected);