From: hj kim Date: Wed, 10 Aug 2022 05:21:10 +0000 (+0900) Subject: webrtc_source_screen: remove screen mode parameter from webrtc_screen_source_set_crop() X-Git-Tag: submit/tizen/20220830.005358^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8537064b06d18d333971b5de62dd29c79fb9ba1d;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source_screen: remove screen mode parameter from webrtc_screen_source_set_crop() Check if the screen is rotated directly through the sensor. [Version] 0.3.215 [Issue Type] Improvement Change-Id: I3067c8ffe651a4b2ac7230ee8adeb91d2f39dc67 --- diff --git a/CMakeLists.txt b/CMakeLists.txt index e78eae07..718e6cbd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 41f1f6c0..ac607c26 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -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 diff --git a/include/webrtc_private.h b/include/webrtc_private.h index e947bbe0..0159925f 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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 */ diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index b7b5b9a2..d7b57999 100644 --- a/packaging/capi-media-webrtc.spec +++ b/packaging/capi-media-webrtc.spec @@ -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) diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 95cfd99e..40f7fa6e 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -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; diff --git a/src/webrtc_source.c b/src/webrtc_source.c index c51b3e68..c506f9e4 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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; } diff --git a/src/webrtc_source_screen.c b/src/webrtc_source_screen.c index f4c897b8..1e6ab34a 100644 --- a/src/webrtc_source_screen.c +++ b/src/webrtc_source_screen.c @@ -17,9 +17,11 @@ #include "webrtc_private.h" #include "webrtc_source_private.h" #include +#include +#include //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 diff --git a/test/webrtc_test.c b/test/webrtc_test.c index fa8d1bc9..1fb99e17 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -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; } diff --git a/test/webrtc_test_menu.c b/test/webrtc_test_menu.c index 8792bd36..a535a8bc 100644 --- a/test/webrtc_test_menu.c +++ b/test/webrtc_test_menu.c @@ -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)