From 43612cc46d9c9a31b5de095462a3a04ac2e4a3e1 Mon Sep 17 00:00:00 2001 From: hj kim Date: Thu, 1 Sep 2022 15:37:22 +0900 Subject: [PATCH] Make internal APIs for crop screen source public Below functions are moved and have platform privilege. - webrtc_screen_source_set_crop() - webrtc_screen_source_unset_crop() [Version] 0.3.247 [Issue Type] API Change-Id: Iad8d3b9842db4c033052e62596c5a79610de22b1 --- include/webrtc.h | 50 ++++++++++++++++++++++++++++++++ include/webrtc_internal.h | 47 ------------------------------ include/webrtc_private.h | 2 +- packaging/capi-media-webrtc.spec | 2 +- src/webrtc.c | 46 +++++++++++++++++++++++++++++ src/webrtc_internal.c | 43 --------------------------- src/webrtc_source_screen.c | 19 +++++------- test/webrtc_test.c | 9 ++---- 8 files changed, 108 insertions(+), 110 deletions(-) diff --git a/include/webrtc.h b/include/webrtc.h index 6c32c8c7..a3ce3a76 100644 --- a/include/webrtc.h +++ b/include/webrtc.h @@ -1587,6 +1587,56 @@ int webrtc_file_source_set_looping(webrtc_h webrtc, unsigned int source_id, bool */ int webrtc_file_source_get_looping(webrtc_h webrtc, unsigned int source_id, bool *looping); +/** + * @platform + * @brief Sets the crop coordinates of a screen source. + * @since_tizen 7.0 + * @remarks The coordinates are in UI (screen) units, and the start coordinate refers to the upper left corner of the video display area on the screen.\n + * If we give a rectangle within that area (described by x, y, width, height) then this sub-area will be sent to peer and \n + * it changes the video resolution. + * The changed resolution can be checked through webrtc_media_source_get_video_resolution().\n + * Even when the crop area is reset, the rectangle coordinates are based on the original UI (screen) as in the first setting.\n + * If the video resolution is changed by webrtc_media_source_set_video_resolution(), then crop cannot be performed.\n + * Crop and resolution change cannot be done at the same time. + * @param[in] webrtc WebRTC handle + * @param[in] source_id The screen source id + * @param[in] x The start X coordinate of the UI for cropping + * @param[in] y The start Y coordinate of the UI for cropping + * @param[in] width Width of the UI for cropping + * @param[in] height Height of the UI for cropping + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_PERMISSION_DENIED Permission denied + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation + * @retval #WEBRTC_ERROR_INVALID_STATE Invalid state + * @pre Add screen source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). + * @pre @a webrtc state must be set to #WEBRTC_STATE_NEGOTIATING or #WEBRTC_STATE_PLAYING. + * @see webrtc_screen_source_unset_crop() + * @see webrtc_media_source_get_video_resolution() + */ +int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int width, int height); + +/** + * @platform + * @brief Unsets the crop coordinates of a screen source. + * @since_tizen 7.0 + * @param[in] webrtc WebRTC handle + * @param[in] source_id The screen source id + * @return @c 0 on success, + * otherwise a negative error value + * @retval #WEBRTC_ERROR_NONE Successful + * @retval #WEBRTC_ERROR_PERMISSION_DENIED Permission denied + * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation + * @retval #WEBRTC_ERROR_INVALID_STATE Invalid state + * @pre Add screen source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). + * @pre @a webrtc state must be set to #WEBRTC_STATE_NEGOTIATING or #WEBRTC_STATE_PLAYING. + * @see webrtc_screen_source_set_crop() + */ +int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id); + /** * @} */ diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index 31a27609..d05906fc 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -189,53 +189,6 @@ int webrtc_media_source_set_payload_type(webrtc_h webrtc, unsigned int source_id */ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, unsigned int *pt); -/** - * @internal - * @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 - * 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.\n - * If the video resolution is changed by webrtc_media_source_set_video_resolution(), then crop cannot be performed.\n - * Crop and resolution change cannot be done at the same time. - * @param[in] webrtc WebRTC handle - * @param[in] source_id The file source id - * @param[in] x X coordinate of the upper left conner of the result area - * @param[in] y Y coordinate of the upper left conner of the result area - * @param[in] w Width of UI for cropping - * @param[in] h Height of UI for cropping - * @param[out] width Cropped video resolution width - * @param[out] height Cropped video resolution height - * @return @c 0 on success, - * otherwise a negative error value - * @retval #WEBRTC_ERROR_NONE Successful - * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation - * @retval #WEBRTC_ERROR_INVALID_STATE Invalid state - * @pre Add screen source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). - * @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, int *width, int *height); - -/** - * @internal - * @brief Unsets the crop coordinates of screen source. - * @since_tizen 6.5 - * @param[in] webrtc WebRTC handle - * @param[in] source_id The file source id - * @return @c 0 on success, - * otherwise a negative error value - * @retval #WEBRTC_ERROR_NONE Successful - * @retval #WEBRTC_ERROR_INVALID_PARAMETER Invalid parameter - * @retval #WEBRTC_ERROR_INVALID_OPERATION Invalid operation - * @retval #WEBRTC_ERROR_INVALID_STATE Invalid state - * @pre Add screen source to @a webrtc to get @a source_id by calling webrtc_add_media_source(). - * @pre @a webrtc state must be set to #WEBRTC_STATE_NEGOTIATING or #WEBRTC_STATE_PLAYING. - * @see webrtc_screen_source_set_crop() - */ -int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id); - /** * @internal * @brief Sets the probability of RTP packet dropping. diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 51c4fd6a..b7311236 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -698,7 +698,7 @@ int _update_pt_if_media_packet_source(webrtc_s *webrtc, webrtc_gst_slot_s *sourc int _get_screen_resolution(int *width, int *height); 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 _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, 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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 4860534f..15d8b1fa 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.246 +Version: 0.3.247 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index 145b4b59..d93f98c5 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -708,6 +708,52 @@ int webrtc_file_source_get_looping(webrtc_h webrtc, unsigned int source_id, bool return _get_filesrc_looping(_webrtc, source_id, looping); } +//LCOV_EXCL_START +int webrtc_screen_source_set_crop(webrtc_h webrtc, unsigned int source_id, int x, int y, int width, int height) +{ + g_autoptr(GMutexLocker) locker = NULL; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + + 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"); + RET_VAL_IF(x < 0, WEBRTC_ERROR_INVALID_PARAMETER, "x < 0"); + RET_VAL_IF(y < 0, WEBRTC_ERROR_INVALID_PARAMETER, "y < 0"); + RET_VAL_IF(width == 0, WEBRTC_ERROR_INVALID_PARAMETER, "width is 0"); + RET_VAL_IF(height == 0, WEBRTC_ERROR_INVALID_PARAMETER, "height is 0"); + RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE"); + RET_ERR_IF_PRIVILEGE_IS_NOT_ALLOWED(_WEBRTC_PRIVILEGE_PLATFORM); + + locker = g_mutex_locker_new(&_webrtc->mutex); + +#ifdef TIZEN_FEATURE_UI + return _set_screen_source_crop(_webrtc, source_id, x, y, width, height); +#else + LOG_ERROR("TIZEN_FEATURE_UI is disabled, skip this function"); + return WEBRTC_ERROR_INVALID_OPERATION; +#endif +} + +int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id) +{ + g_autoptr(GMutexLocker) locker = NULL; + webrtc_s *_webrtc = (webrtc_s *)webrtc; + + 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"); + RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE"); + RET_ERR_IF_PRIVILEGE_IS_NOT_ALLOWED(_WEBRTC_PRIVILEGE_PLATFORM); + + locker = g_mutex_locker_new(&_webrtc->mutex); + +#ifdef TIZEN_FEATURE_UI + return _unset_screen_source_crop(_webrtc, source_id); +#else + LOG_ERROR("TIZEN_FEATURE_UI is disabled, skip this function"); + return WEBRTC_ERROR_INVALID_OPERATION; +#endif +} +//LCOV_EXCL_STOP + int webrtc_set_sound_stream_info(webrtc_h webrtc, unsigned int track_id, sound_stream_info_h stream_info) { g_autoptr(GMutexLocker) locker = NULL; diff --git a/src/webrtc_internal.c b/src/webrtc_internal.c index 47735368..d7dc3529 100644 --- a/src/webrtc_internal.c +++ b/src/webrtc_internal.c @@ -142,49 +142,6 @@ 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, int *width, int *height) -{ - g_autoptr(GMutexLocker) locker = NULL; - webrtc_s *_webrtc = (webrtc_s *)webrtc; - - 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"); - /* FIXME: need to check x, y? */ - RET_VAL_IF(w == 0, WEBRTC_ERROR_INVALID_PARAMETER, "w is 0"); - RET_VAL_IF(h == 0, WEBRTC_ERROR_INVALID_PARAMETER, "h is 0"); - RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL"); - RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height is NULL"); - RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE"); - - locker = g_mutex_locker_new(&_webrtc->mutex); - -#ifdef TIZEN_FEATURE_UI - 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; -#endif -} - -int webrtc_screen_source_unset_crop(webrtc_h webrtc, unsigned int source_id) -{ - g_autoptr(GMutexLocker) locker = NULL; - webrtc_s *_webrtc = (webrtc_s *)webrtc; - - 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"); - RET_VAL_IF(_webrtc->state == WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should not be IDLE"); - - locker = g_mutex_locker_new(&_webrtc->mutex); - -#ifdef TIZEN_FEATURE_UI - return _unset_screen_source_crop(_webrtc, source_id); -#else - LOG_ERROR("TIZEN_FEATURE_UI is disabled, skip this function"); - return WEBRTC_ERROR_INVALID_OPERATION; -#endif -} - int webrtc_set_rtp_packet_drop_probability(webrtc_h webrtc, bool sender, float probability) { webrtc_s *_webrtc = (webrtc_s *)webrtc; diff --git a/src/webrtc_source_screen.c b/src/webrtc_source_screen.c index 5f64e9c9..51ced855 100644 --- a/src/webrtc_source_screen.c +++ b/src/webrtc_source_screen.c @@ -23,7 +23,7 @@ #endif //LCOV_EXCL_START -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 _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int y, int width, int height) { webrtc_gst_slot_s *source = NULL; GstElement *screen_source = NULL; @@ -45,10 +45,8 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int RET_VAL_IF(source_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "source_id is 0"); RET_VAL_IF((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, WEBRTC_ERROR_INVALID_PARAMETER, "source type is not screen"); - RET_VAL_IF(w == 0, WEBRTC_ERROR_INVALID_PARAMETER, "w is 0"); - RET_VAL_IF(h == 0, WEBRTC_ERROR_INVALID_PARAMETER, "h is 0"); - RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL"); - RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height is NULL"); + RET_VAL_IF(width == 0, WEBRTC_ERROR_INVALID_PARAMETER, "width is 0"); + RET_VAL_IF(height == 0, WEBRTC_ERROR_INVALID_PARAMETER, "height is 0"); if ((!_is_screen_source_cropped(source)) && ((source->video_info.origin_width != source->video_info.width) || (source->video_info.origin_height != source->video_info.height))) { @@ -67,7 +65,7 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int else if (!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"); + LOG_INFO("set source crop x:%d, y:%d, width:%d, height:%d, mode:%s", x, y, width, height, (portrait_mode) ? "portrait" : "landscape"); g_object_get(G_OBJECT(screen_source), portrait_mode ? "mirroring-v-src-width" : "mirroring-h-src-width", &src_width, @@ -83,9 +81,9 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int rw = (float)src_width / mirroring_width; rh = (float)src_height / mirroring_height; left = mirroring_x + ((float)x / rw); - right = output_width - (left + (float)w / rw); + right = output_width - (left + (float)width / rw); top = mirroring_y + ((float)y /rh); - bottom = output_height - (top + (float)h / rh); + bottom = output_height - (top + (float)height / 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); @@ -107,10 +105,7 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int _set_video_src_resolution(source, _width, _height); - *width = _width; - *height = _height; - - LOG_INFO("source_id[%u], video resolution is changed [%dx%d] ==> [%dx%d]", source_id, output_width, output_height, *width, *height); + LOG_INFO("source_id[%u], video resolution is changed [%dx%d] ==> [%dx%d]", source_id, output_width, output_height, _width, _height); return WEBRTC_ERROR_NONE; } diff --git a/test/webrtc_test.c b/test/webrtc_test.c index 1c78293d..0b12ffbf 100644 --- a/test/webrtc_test.c +++ b/test/webrtc_test.c @@ -1049,15 +1049,13 @@ 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 *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 ret = WEBRTC_ERROR_NONE; - ret = webrtc_screen_source_set_crop(g_ad.conns[index].webrtc, source_id, x, y, w, h, width, height); + ret = webrtc_screen_source_set_crop(g_ad.conns[index].webrtc, source_id, x, y, w, h); if (ret != WEBRTC_ERROR_NONE) g_print("failed to webrtc_screen_source_set_crop(), source_id[%d], ret[0x%x]\n", source_id, ret); - - g_print("cropped video resolution[%dx%d]\n", *width, *height); } static void _webrtc_screen_source_unset_crop(int index, unsigned int source_id) @@ -3458,8 +3456,7 @@ static void test_webrtc_media_source(char *cmd) return; case 4: h = value; - int width, height; - _webrtc_screen_source_set_crop(0, id, x, y, w, h, &width, &height); + _webrtc_screen_source_set_crop(0, id, x, y, w, h); x = y = w = h = 0; g_ad.input_count = 0; break; -- 2.34.1