fixup! webrtc_sorce_screen: Destroy rotate sensor listener handle 04/280504/6
authorhj kim <backto.kim@samsung.com>
Wed, 31 Aug 2022 05:02:23 +0000 (14:02 +0900)
committerhj kim <backto.kim@samsung.com>
Wed, 31 Aug 2022 23:55:08 +0000 (08:55 +0900)
Rotate sensor listener handle must be destroyed before destroying webrtc.

Change-Id: I0537f37ba387aa3a6fec08eb39afd94069d23c26

include/webrtc_private.h
src/webrtc.c
src/webrtc_source.c
src/webrtc_source_screen.c

index 6fd900b8476576d6a1eedb56d276b1c577820619..07ad074430ea22078faa0ab9b00cf7ecb419966c 100644 (file)
@@ -521,6 +521,10 @@ typedef struct _webrtc_s {
 #ifndef TIZEN_TV
        webrtc_resource_s resource;
 #endif
+#ifdef TIZEN_FEATURE_UI
+       void *rotate_sensor_listener;
+       int screen_rotated;
+#endif
 } webrtc_s;
 
 /* FIXME: divide into two slot types or use union */
@@ -689,7 +693,8 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f
 
 /* screen source */
 int _get_screen_resolution(int *width, int *height);
-int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source);
+int _set_screen_rotation_changed_cb(webrtc_s *webrtc);
+void _unset_screen_rotation_changed_cb(webrtc_s *webrtc);
 int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height);
 int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id);
 bool _is_screen_source_cropped(webrtc_gst_slot_s *source);
index 7703a0fe6884a3c41f38b82cbace2be59eef9db2..dd43140fa39e502c0c5d0d7fbdfc6ec9cc888744 100644 (file)
@@ -161,6 +161,11 @@ int webrtc_destroy(webrtc_h webrtc)
        _gst_destroy_pipeline(_webrtc);
        _unload_ini(_webrtc);
 
+#ifdef TIZEN_FEATURE_UI
+       if (_webrtc->rotate_sensor_listener)
+               _unset_screen_rotation_changed_cb(_webrtc);
+#endif
+
        g_cond_clear(&_webrtc->stats_cond);
        g_mutex_clear(&_webrtc->stats_mutex);
        g_cond_clear(&_webrtc->desc_cond);
index 3b54adefec75c85349b98a3c066a4e833ac37312..8c55a09484023319c4f8b74d31d50f52823c6b93 100644 (file)
@@ -173,9 +173,9 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
                return WEBRTC_ERROR_INVALID_OPERATION;
 
 #ifdef TIZEN_FEATURE_UI
-       if ((ret = _set_screen_rotation_changed_cb(source)) != WEBRTC_ERROR_NONE)
-               return ret;
-
+       if (!webrtc->rotate_sensor_listener)
+               if ((ret = _set_screen_rotation_changed_cb(webrtc)) != WEBRTC_ERROR_NONE)
+                       return ret;
 #endif
        if (!(screensrc = _create_element(_get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_SCREEN), ELEMENT_NAME_SCREENSRC)))
                return WEBRTC_ERROR_INVALID_OPERATION;
index f8d14fac1ee9b792236ba4adf9bad9151406082d..019247466316425e31538d60a8039f7204e81672 100644 (file)
@@ -55,7 +55,9 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int
        videocrop = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEOCROP);
        RET_VAL_IF(videocrop == NULL, WEBRTC_ERROR_INVALID_OPERATION, "videocrop is NULL");
 
-       if (source->video_info.origin_width > source->video_info.origin_height)
+       if ((webrtc->screen_rotated) && (source->video_info.origin_width < source->video_info.origin_height))
+               portrait_mode = false;
+       else if ((!webrtc->screen_rotated) && (source->video_info.origin_width > source->video_info.origin_height))
                portrait_mode = false;
 
        LOG_INFO("set source crop x:%d, y:%d, width:%d, height:%d, mode:%s", x, y, w, h, (portrait_mode) ? "portrait" : "landscape");
@@ -168,15 +170,12 @@ int _get_screen_resolution(int *width, int *height)
 
 static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data)
 {
-       webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)user_data;
-       int width;
-       int height;
+       webrtc_s *webrtc = (webrtc_s *)user_data;
        int type;
        int event;
        int angle;
 
-       RET_IF(source == NULL, "source is NULL");
-       RET_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, "invalid source type [%d]", source->type);
+       RET_IF(webrtc == NULL, "webrtc is NULL");
 
        sensor_get_type(sensor, &type);
        if (type != AUTO_ROTATION_SENSOR)
@@ -204,28 +203,23 @@ static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[
 
        LOG_DEBUG("screen rotation changed [%d]", angle);
 
-       if (_get_screen_resolution(&width, &height) != WEBRTC_ERROR_NONE)
-               return;
+       g_mutex_lock(&webrtc->mutex);
+       if (angle == 0 || angle == 180)
+               webrtc->screen_rotated = false;
+       else
+               webrtc->screen_rotated = true;
 
-       g_mutex_lock(&source->webrtc->mutex);
-       if (angle == 0 || angle == 180) {
-               source->video_info.origin_width = width;
-               source->video_info.origin_height = height;
-       } else {
-               source->video_info.origin_width = height;
-               source->video_info.origin_height = width;
-       }
-       g_mutex_unlock(&source->webrtc->mutex);
+       g_mutex_unlock(&webrtc->mutex);
 }
 
-int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source)
+int _set_screen_rotation_changed_cb(webrtc_s *webrtc)
 {
        bool supported;
        sensor_h *sh;
        int count;
        sensor_listener_h lh;
 
-       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+       RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
 
        sensor_is_supported(AUTO_ROTATION_SENSOR, &supported);
 
@@ -238,20 +232,33 @@ int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source)
 
        sensor_create_listener(sh[0], &lh);
 
-       sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, source);
+       sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, webrtc);
        sensor_listener_set_option(lh, SENSOR_OPTION_ALWAYS_ON);
        sensor_listener_set_interval(lh, 100);
 
        if (sensor_listener_start(lh) != SENSOR_ERROR_NONE) {
                LOG_ERROR("failed to sensor_listener_start()");
+               sensor_destroy_listener(lh);
                return WEBRTC_ERROR_INVALID_OPERATION;
        }
 
+       webrtc->rotate_sensor_listener = (void *)lh;
+
        LOG_INFO("AUTO_ROTATION_SENSOR is supported");
 
        return WEBRTC_ERROR_NONE;
 }
 
+void _unset_screen_rotation_changed_cb(webrtc_s *webrtc)
+{
+       RET_IF(webrtc == NULL, "webrtc is NULL");
+       RET_IF(webrtc->rotate_sensor_listener == NULL, "rotate_sensor_listener is NULL");
+
+       sensor_destroy_listener((sensor_listener_h)webrtc->rotate_sensor_listener);
+
+       LOG_INFO("AUTO_ROTATION_SENSOR is destroyed");
+}
+
 bool _is_screen_source_cropped(webrtc_gst_slot_s *source)
 {
        GstElement *videocrop;