From: hj kim Date: Wed, 24 Aug 2022 06:38:07 +0000 (+0900) Subject: webrtc_source: crop and resolution change cannot be done at the same time X-Git-Tag: submit/tizen/20220901.010928~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F21%2F280121%2F10;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source: crop and resolution change cannot be done at the same time 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 --- diff --git a/include/webrtc_internal.h b/include/webrtc_internal.h index ac607c26..31a27609 100644 --- a/include/webrtc_internal.h +++ b/include/webrtc_internal.h @@ -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 diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 0159925f..bd011d67 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -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); diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index d7b57999..39f56322 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.215 +Version: 0.3.216 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index c506f9e4..4accf041 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -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; diff --git a/src/webrtc_source_screen.c b/src/webrtc_source_screen.c index 1e6ab34a..c5006f59 100644 --- a/src/webrtc_source_screen.c +++ b/src/webrtc_source_screen.c @@ -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