webrtc_source: crop and resolution change cannot be done at the same time 21/280121/10
authorhj kim <backto.kim@samsung.com>
Wed, 24 Aug 2022 06:38:07 +0000 (15:38 +0900)
committerhj kim <backto.kim@samsung.com>
Fri, 26 Aug 2022 05:32:12 +0000 (14:32 +0900)
The results can vary depending on the order of resolution change and crop.
Therefore, those cannot be set at the same time.

[Version] 0.3.216
[Issue Type] Improvement

Change-Id: I305e1f9e72ce43629d733e31ec5d18cb005b1a9e

include/webrtc_internal.h
include/webrtc_private.h
packaging/capi-media-webrtc.spec
src/webrtc_source.c
src/webrtc_source_screen.c

index ac607c2681f753e735ae1176b97fff9269d8ee2f..31a27609dd47814bb982a281672a1840ce62ad47 100644 (file)
@@ -195,7 +195,9 @@ int webrtc_media_source_get_payload_type(webrtc_h webrtc, unsigned int source_id
  * @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.
+ *          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
index 0159925fe42ba04f0809e6131216b506e9a19091..bd011d67d6177ffc07cf7f6c54595dd149cee781 100644 (file)
@@ -692,6 +692,7 @@ int _get_screen_resolution(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);
+bool _is_screen_source_cropped(webrtc_gst_slot_s *source);
 
 /* source */
 int _complete_sources(webrtc_s *webrtc);
index d7b5799924b6ede401f2d706a6ab3c54ea40cf40..39f5632269485c7f27cd1615e41828a4abc6f867 100644 (file)
@@ -1,6 +1,6 @@
 Name:       capi-media-webrtc
 Summary:    A WebRTC library in Tizen Native API
-Version:    0.3.215
+Version:    0.3.216
 Release:    0
 Group:      Multimedia/API
 License:    Apache-2.0
index c506f9e4a1f96776d9902f00f8ccea06a46243ba..4accf041f16cad2761fbea2a7f840dd2426780e9 100644 (file)
@@ -1399,6 +1399,12 @@ int _set_video_resolution(webrtc_s *webrtc, unsigned int source_id, int width, i
        RET_VAL_IF((source->type == WEBRTC_MEDIA_SOURCE_TYPE_NULL), WEBRTC_ERROR_INVALID_PARAMETER, "this API does not support the null source");
 
        if (webrtc->state != WEBRTC_STATE_IDLE) {
+#ifdef TIZEN_FEATURE_UI
+               if ((source->type == WEBRTC_MEDIA_SOURCE_TYPE_SCREEN) && _is_screen_source_cropped(source)) {
+                       LOG_ERROR("It is already cropped. crop and resolution change cannot be done at the same time.");
+                       return WEBRTC_ERROR_INVALID_OPERATION;
+               }
+#endif
                const ini_item_media_source_s *ini_source = _ini_get_source_by_type(&webrtc->ini, source->type);
                if (ini_source == NULL)
                        ini_source = &webrtc->ini.media_source;
index 1e6ab34a6a151db7cf10d0fa08d73e3fd1b1709e..c5006f59666f8f18faccd58b24c931695ec6a46c 100644 (file)
@@ -41,6 +41,12 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int
        RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL");
        RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height is NULL");
 
+       if ((!_is_screen_source_cropped(source)) &&
+               ((source->video_info.origin_width != source->video_info.width) || (source->video_info.origin_height != source->video_info.height))) {
+               LOG_ERROR("resolution is already changed. crop and resolution change cannot be done at the same time.");
+               return WEBRTC_ERROR_INVALID_OPERATION;
+       }
+
        screen_source = gst_bin_get_by_name(source->bin, ELEMENT_NAME_SCREENSRC);
        RET_VAL_IF(screen_source == NULL, WEBRTC_ERROR_INVALID_OPERATION, "sreen_source is NULL");
 
@@ -97,12 +103,12 @@ int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id)
        webrtc_gst_slot_s *source = NULL;
        GstElement *videocrop = NULL;
        GstElement *screen_source = NULL;
-       int left, right, top, bottom;
 
        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((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(!_is_screen_source_cropped(source), WEBRTC_ERROR_INVALID_OPERATION, "source is not cropped");
 
        screen_source = gst_bin_get_by_name(source->bin, ELEMENT_NAME_SCREENSRC);
        RET_VAL_IF(screen_source == NULL, WEBRTC_ERROR_INVALID_OPERATION, "sreen_source is NULL");
@@ -110,14 +116,6 @@ int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id)
        videocrop = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEOCROP);
        RET_VAL_IF(videocrop == NULL, WEBRTC_ERROR_INVALID_OPERATION, "videocrop is NULL");
 
-       g_object_get(G_OBJECT(videocrop),
-               "left", &left,
-               "right", &right,
-               "top", &top,
-               "bottom", &bottom,
-               NULL);
-       RET_VAL_IF(left == 0 && right == 0 && top == 0 && bottom == 0, WEBRTC_ERROR_INVALID_OPERATION, "webrtc_screen_source_set_crop was not set");
-
        g_object_set(G_OBJECT(videocrop),
                "left", 0,
                "right", 0,
@@ -241,4 +239,32 @@ int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source)
 
        return WEBRTC_ERROR_NONE;
 }
+
+bool _is_screen_source_cropped(webrtc_gst_slot_s *source)
+{
+       GstElement *videocrop;
+       int left, right, top, bottom;
+
+       RET_VAL_IF(source == NULL, false, "source is NULL");
+       RET_VAL_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, false, "invalid source type [%d]", source->type);
+
+       videocrop = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEOCROP);
+       RET_VAL_IF(videocrop == NULL, false, "videocrop is NULL");
+
+       g_object_get(G_OBJECT(videocrop),
+               "left", &left,
+               "right", &right,
+               "top", &top,
+               "bottom", &bottom,
+               NULL);
+
+       if (left == 0 && right == 0 && top == 0 && bottom == 0) {
+               LOG_DEBUG("source is not cropped");
+               return false;
+       }
+
+       LOG_DEBUG("source is cropped");
+
+       return true;
+}
 //LCOV_EXCL_STOP