Make internal APIs for crop screen source public 07/280607/20
authorhj kim <backto.kim@samsung.com>
Thu, 1 Sep 2022 06:37:22 +0000 (15:37 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 23 Sep 2022 05:25:34 +0000 (14:25 +0900)
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
include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc.c
src/webrtc_internal.c
src/webrtc_source_screen.c
test/webrtc_test.c

index 6c32c8c775582d2549e41233e145c4862b02d1af..a3ce3a76bd8e510da8b0b48ae4675ccdbcd35ed8 100644 (file)
@@ -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);
+
 /**
  * @}
  */
index 31a27609dd47814bb982a281672a1840ce62ad47..d05906fc5b9c0b1c2c6afa8c164479071462da78 100644 (file)
@@ -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.
index 51c4fd6ac50e551df1c354014f744f9445003206..b731123621f495adaefc5650d70525977c256f1d 100644 (file)
@@ -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);
 
index 4860534f2b4a2389fe630f205b51a7612f5bcb80..15d8b1fa4ca301c69594c8e50bfeab5557bb0ece 100644 (file)
@@ -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
index 145b4b5926e03849938b81b516ca01f52c8d6c91..d93f98c50b5de6660f97fe6b5a0d3397a39a95b4 100644 (file)
@@ -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;
index 4773536849f8219d4c70067e91600f73287b4195..d7dc35296a3dd26aac9d5b67e14cc9d4e4f6173c 100644 (file)
@@ -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;
index 5f64e9c90a78cb96ddb4749cdc1f55dd5ba92bd1..51ced855fa31377bd09177872f0f02f0a48ed238 100644 (file)
@@ -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;
 }
index 1c78293d68a579f6329667f74763c1307758773f..0b12ffbfa8fcb383b531c943c665536caba8a45b 100644 (file)
@@ -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;