webrtc_source_screen: remove screen mode parameter from webrtc_screen_source_set_crop() 77/279477/17 submit/tizen/20220830.005358
authorhj kim <backto.kim@samsung.com>
Wed, 10 Aug 2022 05:21:10 +0000 (14:21 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 26 Aug 2022 01:20:01 +0000 (10:20 +0900)
Check if the screen is rotated directly through the sensor.

[Version] 0.3.215
[Issue Type] Improvement

Change-Id: I3067c8ffe651a4b2ac7230ee8adeb91d2f39dc67

CMakeLists.txt
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_internal.c
src/webrtc_source.c
src/webrtc_source_screen.c
test/webrtc_test.c
test/webrtc_test_menu.c

index e78eae07b5e091d0f1ebdae0a40068590380c4a1..718e6cbd7fb153fb6a73f2f73e1d54733af6773c 100644 (file)
@@ -12,7 +12,7 @@ INCLUDE_DIRECTORIES(${INC_DIR})
 
 SET(dependents "dlog glib-2.0 gstreamer-1.0 gstreamer-webrtc-1.0 gstreamer-video-1.0 gstreamer-audio-1.0 \
                 gstreamer-allocators-1.0 libpulse json-glib-1.0 iniparser mm-common mm-display-interface capi-media-tool \
-                libtbm libwebsockets cynara-client libsmack capi-system-info libsoup-2.4 bundle capi-media-sound-manager mm-fileinfo")
+                libtbm libwebsockets cynara-client libsmack capi-system-info capi-system-sensor libsoup-2.4 bundle capi-media-sound-manager mm-fileinfo")
 IF(NOT TIZEN_PROFILE_TV)
     SET(dependents "${dependents} mm-resource-manager")
 ELSE()
index 41f1f6c09919f6dfcb7773ca96d04d68fd8026af..ac607c2681f753e735ae1176b97fff9269d8ee2f 100644 (file)
@@ -194,7 +194,6 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id
  * @brief Sets the crop coordinates of screen source.
  * @since_tizen 6.5
  * @remarks The base position is always the upper left conner of the UI coordinates.\n
- *          If the physical display is rotated and the UI is also rotated according to the rotation, @a portrait_mode and the cropping coordinates must be updated.\n
  *          The display resolution and video resolution of this screen source are different,
  *          this function uses the input parameters to crop the screen source based on the display resolution and it changes the video resolution of the screen source as a result.
  * @param[in] webrtc     WebRTC handle
@@ -205,7 +204,6 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id
  * @param[in] h          Height of UI for cropping
  * @param[out] width     Cropped video resolution width
  * @param[out] height    Cropped video resolution height
- * @param[in] portrait_mode  Screen is portrait mode or not (@c true = portrait mode, @c false = landscape mode)
  * @return @c 0 on success,
  *         otherwise a negative error value
  * @retval #WEBRTC_ERROR_NONE    Successful
@@ -216,7 +214,7 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id
  * @pre @a webrtc state must be set to #WEBRTC_STATE_NEGOTIATING or #WEBRTC_STATE_PLAYING.
  * @see webrtc_screen_source_unset_crop()
  */
-int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height);
+int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height);
 
 /**
  * @internal
index e947bbe0dbfe57cf34bc7e543475274c828ffd80..0159925fe42ba04f0809e6131216b506e9a19091 100644 (file)
@@ -689,7 +689,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_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height);
+int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source);
+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);
 
 /* source */
index b7b5b9a26ec64733f168687e8f3152ecdebb6b84..d7b5799924b6ede401f2d706a6ab3c54ea40cf40 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.214
+Version:    0.3.215
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
@@ -32,6 +32,7 @@ BuildRequires:  pkgconfig(libwebsockets)
 BuildRequires:  pkgconfig(cynara-client)
 BuildRequires:  pkgconfig(libsmack)
 BuildRequires:  pkgconfig(capi-system-info)
+BuildRequires:  pkgconfig(capi-system-sensor)
 BuildRequires:  pkgconfig(capi-media-sound-manager)
 BuildRequires:  pkgconfig(bundle)
 BuildRequires:  pkgconfig(mm-fileinfo)
index 95cfd99e24ba81ab86aee24bbaf213a7e3f9a0cd..40f7fa6ed2fd67c06b1bcddc79c53795d74e42c8 100644 (file)
@@ -123,7 +123,7 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id
        return WEBRTC_ERROR_NONE;
 }
 
-int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height)
+int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height)
 {
        g_autoptr(GMutexLocker) locker = NULL;
        webrtc_s *_webrtc = (webrtc_s *)webrtc;
@@ -140,7 +140,7 @@ int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x
        locker = g_mutex_locker_new(&_webrtc->mutex);
 
 #ifdef TIZEN_FEATURE_UI
-       return _set_screen_source_crop(_webrtc, source_id, x, y, w, h, portrait_mode, width, height);
+       return _set_screen_source_crop(_webrtc, source_id, x, y, w, h, width, height);
 #else
        LOG_ERROR("TIZEN_FEATURE_UI is disabled, skip this function");
        return WEBRTC_ERROR_INVALID_OPERATION;
index c51b3e68fde4709e25b9f0602978eecd63a6d113..c506f9e4a1f96776d9902f00f8ccea06a46243ba 100644 (file)
@@ -204,6 +204,9 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
        if (!__set_default_video_info(source, ini_source))
                return WEBRTC_ERROR_INVALID_OPERATION;
 
+       if ((ret = _set_screen_rotation_changed_cb(source)) != WEBRTC_ERROR_NONE)
+               return ret;
+
        if (!(screensrc = _create_element(_get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_SCREEN), ELEMENT_NAME_SCREENSRC)))
                return WEBRTC_ERROR_INVALID_OPERATION;
        APPEND_ELEMENT(switch_src_list, screensrc);
@@ -1273,7 +1276,7 @@ int _set_transceiver_codec(webrtc_s *webrtc, unsigned int source_id, webrtc_medi
                if (source->av[av_idx].pt >= MIN_DYNAMIC_PAYLOAD_TYPE)
                        __return_payload_type(webrtc, source->av[av_idx].pt);
 
-               if((ret = _set_payload_type(webrtc, source, av_idx, payload_info->gst_media_type)) != WEBRTC_ERROR_NONE)
+               if ((ret = _set_payload_type(webrtc, source, av_idx, payload_info->gst_media_type)) != WEBRTC_ERROR_NONE)
                        return ret;
        }
 
index f4c897b81b837565dbad330c27b2c59e284748db..1e6ab34a6a151db7cf10d0fa08d73e3fd1b1709e 100644 (file)
 #include "webrtc_private.h"
 #include "webrtc_source_private.h"
 #include <Elementary.h>
+#include <sensor.h>
+#include <sensor-internal.h>
 
 //LCOV_EXCL_START
-int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, bool portrait_mode, int *width, int *height)
+int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int w, int h, int *width, int *height)
 {
        webrtc_gst_slot_s *source = NULL;
        GstElement *screen_source = NULL;
@@ -28,6 +30,7 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int
        int mirroring_x, mirroring_y, mirroring_width, mirroring_height;
        float rw, rh;
        int left, right, top, bottom;
+       bool portrait_mode = true;
 
        RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
        RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0");
@@ -44,6 +47,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)
+               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");
 
        g_object_get(G_OBJECT(screen_source),
@@ -64,9 +70,8 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int
        top = mirroring_y + ((float)y /rh);
        bottom = output_height - (top + (float)h / rh);
 
-       LOG_INFO("Screen source info: source[width:%d, height:%d], output[width:%d, height:%d]"
-               "mirroring[x:%d y:%d width:%d, height:%d", src_width, src_height, output_width,
-               output_height, mirroring_x, mirroring_y, mirroring_width, mirroring_height);
+       LOG_INFO("Screen source info: source[width:%d, height:%d], output[width:%d, height:%d] mirroring[x:%d y:%d width:%d, height:%d]",
+                       src_width, src_height, output_width, output_height, mirroring_x, mirroring_y, mirroring_width, mirroring_height);
 
        g_object_set(G_OBJECT(videocrop),
                "left", left,
@@ -134,6 +139,8 @@ int _get_screen_resolution(int *width, int *height)
        RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL");
        RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height is NULL");
 
+       /* This function returns the resolution when the device rotation angle is "0" regardless of the actual rotation direction of the device. */
+
        eo = elm_win_add(NULL, "screen_source", ELM_WIN_BASIC);
        if (!eo) {
                LOG_ERROR("failed to elm_win_add()");
@@ -149,4 +156,89 @@ int _get_screen_resolution(int *width, int *height)
        return WEBRTC_ERROR_NONE;
 }
 
-//LCOV_EXCL_STOP
\ No newline at end of file
+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;
+       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);
+
+       sensor_get_type(sensor, &type);
+       if (type != AUTO_ROTATION_SENSOR)
+               return;
+
+       event = (int)events->values[0];
+
+       switch (event) {
+       case AUTO_ROTATION_DEGREE_0:
+               angle = 0;
+               break;
+       case AUTO_ROTATION_DEGREE_90:
+               angle = 90;
+               break;
+       case AUTO_ROTATION_DEGREE_180:
+               angle = 180;
+               break;
+       case AUTO_ROTATION_DEGREE_270:
+               angle = 270;
+               break;
+       default:
+               LOG_ERROR("invalid event [%d]", event);
+               return;
+       }
+
+       LOG_DEBUG("screen rotation changed [%d]", angle);
+
+       if (_get_screen_resolution(&width, &height) != WEBRTC_ERROR_NONE)
+               return;
+
+       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);
+}
+
+int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source)
+{
+       bool supported;
+       sensor_h *sh;
+       int count;
+       sensor_listener_h lh;
+
+       RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+
+       sensor_is_supported(AUTO_ROTATION_SENSOR, &supported);
+
+       if (!supported) {
+               LOG_INFO("AUTO_ROTATION_SENSOR is not supported");
+               return WEBRTC_ERROR_NONE;
+       }
+
+       sensor_get_sensor_list(AUTO_ROTATION_SENSOR, &sh, &count);
+
+       sensor_create_listener(sh[0], &lh);
+
+       sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, source);
+       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()");
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
+
+       LOG_INFO("AUTO_ROTATION_SENSOR is supported");
+
+       return WEBRTC_ERROR_NONE;
+}
+//LCOV_EXCL_STOP
index fa8d1bc9174a62c8b9ed2abafae4c73945a18fd2..1fb99e17cd14939c7900a064af9a59ff1c99712c 100644 (file)
@@ -1049,11 +1049,11 @@ static void _webrtc_media_source_get_encoder_bitrate(int index, unsigned int sou
                source_id, g_webrtc_media_type_str[media_type], bitrate);
 }
 
-static void _webrtc_screen_source_set_crop(int index, unsigned int source_id, int x, int y, int w, int h, int is_vertical, int *width, int *height)
+static void _webrtc_screen_source_set_crop(int index, unsigned int source_id, int x, int y, int w, int h, int *width, int *height)
 {
        int ret = WEBRTC_ERROR_NONE;
 
-       ret = webrtc_screen_source_set_crop(g_ad.conns[index].webrtc, source_id, x, y, w, h, is_vertical, width, height);
+       ret = webrtc_screen_source_set_crop(g_ad.conns[index].webrtc, source_id, x, y, w, h, width, height);
        if (ret != WEBRTC_ERROR_NONE)
                g_print("failed to webrtc_screen_source_set_crop(), source_id[%d], ret[0x%x]\n", source_id, ret);
 
@@ -3441,7 +3441,6 @@ static void test_webrtc_media_source(char *cmd)
        case CURRENT_STATUS_SCREEN_SOURCE_SET_CROP: {
                static unsigned int id;
                static int x, y, w, h;
-               static int is_vertical;
 
                switch (g_ad.input_count) {
                case 0:
@@ -3462,13 +3461,9 @@ static void test_webrtc_media_source(char *cmd)
                        return;
                case 4:
                        h = value;
-                       g_ad.input_count++;
-                       return;
-               case 5:
-                       is_vertical = value;
                        int width, height;
-                       _webrtc_screen_source_set_crop(0, id, x, y, w, h, is_vertical, &width, &height);
-                       x = y = w = h = is_vertical = 0;
+                       _webrtc_screen_source_set_crop(0, id, x, y, w, h, &width, &height);
+                       x = y = w = h = 0;
                        g_ad.input_count = 0;
                        break;
                }
index 8792bd361a5c6a08e992db6ebad92f21a73d5a6a..a535a8bcc4814f57aed43adee0821d3223c8b8f7 100644 (file)
@@ -483,8 +483,6 @@ void display_menu_webrtc_media_source(void)
                        g_print("*** input width.\n");
                else if (get_appdata()->input_count == 4)
                        g_print("*** input height.\n");
-               else if (get_appdata()->input_count == 5)
-                       g_print("*** input whether screen rotates (0: horizontal, 1: vertical).\n");
                break;
        case CURRENT_STATUS_SCREEN_SOURCE_UNSET_CROP:
                if (get_appdata()->input_count == 0)