From: hj kim Date: Fri, 23 Sep 2022 06:59:28 +0000 (+0900) Subject: webrtc_source_screen: move screen source related code to webrtc_source_screen.c X-Git-Tag: accepted/tizen/unified/20220928.020833~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=08d61762c96eda4b09ee6c3361717339dec92628;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source_screen: move screen source related code to webrtc_source_screen.c [Version] 0.3.250 [Issue Type] Refactoring Change-Id: Ib1f9d05448de4e0f26a705195323125fd4bd9cd6 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index b7311236..ede9a75e 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -695,8 +695,8 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f int _update_pt_if_media_packet_source(webrtc_s *webrtc, webrtc_gst_slot_s *source); /* screen source */ +int _build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source); 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 width, int height); int _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id); diff --git a/include/webrtc_source_private.h b/include/webrtc_source_private.h index 27eca6d2..40ec5b2a 100644 --- a/include/webrtc_source_private.h +++ b/include/webrtc_source_private.h @@ -92,5 +92,6 @@ int _get_encoder_element_bitrate(GstElement *encoder, int *target_bitrate); void _set_video_src_resolution(webrtc_gst_slot_s *source, int width, int height); GstCaps *_make_video_raw_caps_with_resolution(webrtc_gst_slot_s *source, webrtc_ini_s *ini, int width, int height); void _release_request_pad(webrtc_gst_slot_s *source); +bool _set_default_video_info(webrtc_gst_slot_s *source, const ini_item_media_source_s *ini_source); #endif /* __TIZEN_MEDIA_WEBRTC_SOURCE_COMMON_H__ */ diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 84bf91cf..894622d2 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.249 +Version: 0.3.250 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc_source.c b/src/webrtc_source.c index ef0374ac..6734de9b 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -26,61 +26,6 @@ static GstPadProbeReturn __camerasrc_probe_cb(GstPad *pad, GstPadProbeInfo *info, gpointer u_data); -//LCOV_EXCL_START -static bool __link_switch_srcs(GstElement *switch_element, GList *switch_src_list) -{ - GstElement *element; - GList *list; - - RET_VAL_IF(switch_element == NULL, false, "switch_element is NULL"); - RET_VAL_IF(switch_src_list == NULL, false, "switch_src_list is NULL"); - - for (list = switch_src_list; list; list = g_list_next(list)) { - element = GST_ELEMENT_CAST(list->data); - RET_VAL_IF(!gst_element_link(element, switch_element), false, - "failed to gst_element_link(), [%s] - [%s]", GST_ELEMENT_NAME(element), GST_ELEMENT_NAME(switch_element)); - - LOG_DEBUG("[%s] - [%s]", GST_ELEMENT_NAME(element), GST_ELEMENT_NAME(switch_element)); - } - - return true; -} -//LCOV_EXCL_STOP - -static bool __set_default_video_info(webrtc_gst_slot_s *source, const ini_item_media_source_s *ini_source) -{ - RET_VAL_IF(source == NULL, false, "source is NULL"); - RET_VAL_IF(ini_source == NULL, false, "ini_source is NULL"); - - source->video_info.origin_framerate = ini_source->v_framerate; - source->video_info.framerate = ini_source->v_framerate; - - source->video_info.origin_width = ini_source->v_width; - source->video_info.origin_height = ini_source->v_height; - _set_video_src_resolution(source, ini_source->v_width, ini_source->v_height); - - if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_SCREEN) { -#ifdef TIZEN_FEATURE_UI - int width = 0; - int height = 0; - - if (_get_screen_resolution(&width, &height) != WEBRTC_ERROR_NONE) { - if (width == 0 || height == 0) { - LOG_WARNING("failed to _get_screen_resolution(). use values of ini"); - return true; - } - } - - source->video_info.origin_width = width; - source->video_info.origin_height = height; - _set_video_src_resolution(source, width, height); -#else - LOG_WARNING("TIZEN_FEATURE_UI is disabled, skip this function, use values of ini"); -#endif - } - return true; -} - static int __build_src_check_params_and_get_ini_source(webrtc_s *webrtc, webrtc_gst_slot_s *source, const ini_item_media_source_s **ini_source) { RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); @@ -97,79 +42,6 @@ static int __build_src_check_params_and_get_ini_source(webrtc_s *webrtc, webrtc_ } //LCOV_EXCL_START -static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) -{ - int ret; - GList *switch_src_list = NULL; - GstElement *screensrc = NULL; - GstElement *videotestsrc = NULL; - GstElement *videoswitch = NULL; - const ini_item_media_source_s *ini_source; - - ret = __build_src_check_params_and_get_ini_source(webrtc, source, &ini_source); - RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to __build_src_check_params_and_get_ini_source()"); - - ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad); - RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); - - source->media_types = MEDIA_TYPE_VIDEO; - source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types); - source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format); - source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0]; - - if (!__set_default_video_info(source, ini_source)) - return WEBRTC_ERROR_INVALID_OPERATION; - -#if !defined(TIZEN_TV) && defined(TIZEN_FEATURE_UI) - if (!webrtc->rotate_info.sensor_listener) - if ((ret = _set_screen_rotation_changed_cb(webrtc)) != WEBRTC_ERROR_NONE) - return ret; -#endif - 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); - - _gst_set_element_properties(screensrc, ini_source->source_element_properties); - - if (!(videotestsrc = _create_element(DEFAULT_ELEMENT_VIDEOTESTSRC, ELEMENT_NAME_VIDEO_MUTE_SRC))) - goto exit; - APPEND_ELEMENT(switch_src_list, videotestsrc); - - g_object_set(G_OBJECT(videotestsrc), - "is-live", TRUE, - "pattern", 2, /* black */ - NULL); - - if (!_add_elements_to_bin(source->bin, switch_src_list)) { - SAFE_G_LIST_FREE(switch_src_list); - return WEBRTC_ERROR_INVALID_OPERATION; - } - - if (!(videoswitch = _create_element(DEFAULT_ELEMENT_INPUT_SELECTOR, ELEMENT_NAME_VIDEO_SWITCH))) - goto exit_with_remove_from_bin; - - if (!gst_bin_add(source->bin, videoswitch)) { - LOG_ERROR("failed to gst_bin_add(), bin[%s], videoswitch[%s]", GST_ELEMENT_NAME(source->bin), GST_ELEMENT_NAME(videoswitch)); - SAFE_GST_OBJECT_UNREF(videoswitch); - goto exit_with_remove_from_bin; - } - - if (!__link_switch_srcs(videoswitch, switch_src_list)) { - SAFE_GST_OBJECT_UNREF(videoswitch); - goto exit_with_remove_from_bin; - } - - return WEBRTC_ERROR_NONE; - -exit_with_remove_from_bin: - _remove_elements_from_bin(source->bin, switch_src_list); - SAFE_G_LIST_FREE(switch_src_list); - return WEBRTC_ERROR_INVALID_OPERATION; -exit: - SAFE_G_LIST_FREE_FULL(switch_src_list, gst_object_unref); - return WEBRTC_ERROR_INVALID_OPERATION; -} - static int __mute_by_changing_property(webrtc_gst_slot_s *source, GstElement *videotestsrc, bool mute) { RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); @@ -347,7 +219,7 @@ static int __build_camerasrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format); source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0]; - if (!__set_default_video_info(source, ini_source)) + if (!_set_default_video_info(source, ini_source)) return WEBRTC_ERROR_INVALID_OPERATION; #ifndef TIZEN_TV @@ -526,7 +398,7 @@ static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format); source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0]; - if (!__set_default_video_info(source, ini_source)) + if (!_set_default_video_info(source, ini_source)) return WEBRTC_ERROR_INVALID_OPERATION; if (!(videotestsrc = _create_element(_get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST), ELEMENT_NAME_VIDEO_SRC))) @@ -560,7 +432,7 @@ static int __build_custom_videosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types); source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0]; - if (!__set_default_video_info(source, ini_source)) + if (!_set_default_video_info(source, ini_source)) return WEBRTC_ERROR_INVALID_OPERATION; if (!(custom_videosrc = _create_element(_get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_VIDEO), ELEMENT_NAME_VIDEO_SRC))) @@ -630,7 +502,12 @@ static int __build_source_bin(webrtc_s *webrtc, webrtc_gst_slot_s *source) return __build_camerasrc(webrtc, source); //LCOV_EXCL_START case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN: - return __build_screensrc(webrtc, source); +#ifdef TIZEN_FEATURE_UI + return _build_screensrc(webrtc, source); +#else + LOG_ERROR("TIZEN_FEATURE_UI is disabled, skip this function"); + return WEBRTC_ERROR_INVALID_OPERATION; +#endif //LCOV_EXCL_STOP case WEBRTC_MEDIA_SOURCE_TYPE_FILE: return _build_filesrc_pipeline(webrtc, source); diff --git a/src/webrtc_source_private.c b/src/webrtc_source_private.c index 90f4aa70..dad638d6 100644 --- a/src/webrtc_source_private.c +++ b/src/webrtc_source_private.c @@ -976,3 +976,37 @@ void _release_request_pad(webrtc_gst_slot_s *source) gst_element_foreach_src_pad(GST_ELEMENT(source->bin), __foreach_src_pad_cb, source); } + +bool _set_default_video_info(webrtc_gst_slot_s *source, const ini_item_media_source_s *ini_source) +{ + RET_VAL_IF(source == NULL, false, "source is NULL"); + RET_VAL_IF(ini_source == NULL, false, "ini_source is NULL"); + + source->video_info.origin_framerate = ini_source->v_framerate; + source->video_info.framerate = ini_source->v_framerate; + + source->video_info.origin_width = ini_source->v_width; + source->video_info.origin_height = ini_source->v_height; + _set_video_src_resolution(source, ini_source->v_width, ini_source->v_height); + + if (source->type == WEBRTC_MEDIA_SOURCE_TYPE_SCREEN) { +#ifdef TIZEN_FEATURE_UI + int width = 0; + int height = 0; + + if (_get_screen_resolution(&width, &height) != WEBRTC_ERROR_NONE) { + if (width == 0 || height == 0) { + LOG_WARNING("failed to _get_screen_resolution(). use values of ini"); + return true; + } + } + + source->video_info.origin_width = width; + source->video_info.origin_height = height; + _set_video_src_resolution(source, width, height); +#else + LOG_WARNING("TIZEN_FEATURE_UI is disabled, skip this function, use values of ini"); +#endif + } + return true; +} diff --git a/src/webrtc_source_screen.c b/src/webrtc_source_screen.c index 51ced855..a8204139 100644 --- a/src/webrtc_source_screen.c +++ b/src/webrtc_source_screen.c @@ -33,7 +33,7 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int int _width, _height; float rw, rh; int left, right, top, bottom; -#if !defined(TIZEN_TV) && defined(TIZEN_FEATURE_UI) +#ifndef TIZEN_TV bool rotated = webrtc->rotate_info.rotated; #else bool rotated = false; @@ -208,7 +208,7 @@ static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[ g_mutex_unlock(&webrtc->mutex); } -int _set_screen_rotation_changed_cb(webrtc_s *webrtc) +static int __set_screen_rotation_changed_cb(webrtc_s *webrtc) { bool supported; sensor_h *sh = NULL; @@ -283,6 +283,104 @@ void _unset_screen_rotation_changed_cb(webrtc_s *webrtc) } #endif +static bool __link_switch_srcs(GstElement *switch_element, GList *switch_src_list) +{ + GstElement *element; + GList *list; + + RET_VAL_IF(switch_element == NULL, false, "switch_element is NULL"); + RET_VAL_IF(switch_src_list == NULL, false, "switch_src_list is NULL"); + + for (list = switch_src_list; list; list = g_list_next(list)) { + element = GST_ELEMENT_CAST(list->data); + RET_VAL_IF(!gst_element_link(element, switch_element), false, + "failed to gst_element_link(), [%s] - [%s]", GST_ELEMENT_NAME(element), GST_ELEMENT_NAME(switch_element)); + + LOG_DEBUG("[%s] - [%s]", GST_ELEMENT_NAME(element), GST_ELEMENT_NAME(switch_element)); + } + + return true; +} + +int _build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) +{ + int ret; + GList *switch_src_list = NULL; + GstElement *screensrc = NULL; + GstElement *videotestsrc = NULL; + GstElement *videoswitch = NULL; + const ini_item_media_source_s *ini_source; + + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL"); + + if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) { + LOG_ERROR("ini_source is NULL"); + return WEBRTC_ERROR_INVALID_OPERATION; + } + + ret = _add_no_target_ghostpad_to_slot(source, true, &source->av[AV_IDX_VIDEO].src_pad); + RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()"); + + source->media_types = MEDIA_TYPE_VIDEO; + source->zerocopy_enabled = _is_hw_encoder_used(webrtc, source->type, source->media_types); + source->av[AV_IDX_VIDEO].raw_format = g_strdup(ini_source->v_raw_format); + source->av[AV_IDX_VIDEO].codec = ini_source->v_codecs[0]; + + if (!_set_default_video_info(source, ini_source)) + return WEBRTC_ERROR_INVALID_OPERATION; + +#ifndef TIZEN_TV + if (!webrtc->rotate_info.sensor_listener) + if ((ret = __set_screen_rotation_changed_cb(webrtc)) != WEBRTC_ERROR_NONE) + return ret; +#endif + 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); + + _gst_set_element_properties(screensrc, ini_source->source_element_properties); + + if (!(videotestsrc = _create_element(DEFAULT_ELEMENT_VIDEOTESTSRC, ELEMENT_NAME_VIDEO_MUTE_SRC))) + goto exit; + APPEND_ELEMENT(switch_src_list, videotestsrc); + + g_object_set(G_OBJECT(videotestsrc), + "is-live", TRUE, + "pattern", 2, /* black */ + NULL); + + if (!_add_elements_to_bin(source->bin, switch_src_list)) { + SAFE_G_LIST_FREE(switch_src_list); + return WEBRTC_ERROR_INVALID_OPERATION; + } + + if (!(videoswitch = _create_element(DEFAULT_ELEMENT_INPUT_SELECTOR, ELEMENT_NAME_VIDEO_SWITCH))) + goto exit_with_remove_from_bin; + + if (!gst_bin_add(source->bin, videoswitch)) { + LOG_ERROR("failed to gst_bin_add(), bin[%s], videoswitch[%s]", GST_ELEMENT_NAME(source->bin), GST_ELEMENT_NAME(videoswitch)); + SAFE_GST_OBJECT_UNREF(videoswitch); + goto exit_with_remove_from_bin; + } + + if (!__link_switch_srcs(videoswitch, switch_src_list)) { + SAFE_GST_OBJECT_UNREF(videoswitch); + goto exit_with_remove_from_bin; + } + + return WEBRTC_ERROR_NONE; + +exit_with_remove_from_bin: + _remove_elements_from_bin(source->bin, switch_src_list); + SAFE_G_LIST_FREE(switch_src_list); + return WEBRTC_ERROR_INVALID_OPERATION; +exit: + SAFE_G_LIST_FREE_FULL(switch_src_list, gst_object_unref); + return WEBRTC_ERROR_INVALID_OPERATION; +} + bool _is_screen_source_cropped(webrtc_gst_slot_s *source) { GstElement *videocrop;