From: hj kim Date: Wed, 31 Aug 2022 05:02:23 +0000 (+0900) Subject: fixup! webrtc_sorce_screen: Destroy rotate sensor listener handle X-Git-Tag: submit/tizen/20220902.031026~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F04%2F280504%2F6;p=platform%2Fcore%2Fapi%2Fwebrtc.git fixup! webrtc_sorce_screen: Destroy rotate sensor listener handle Rotate sensor listener handle must be destroyed before destroying webrtc. Change-Id: I0537f37ba387aa3a6fec08eb39afd94069d23c26 --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 6fd900b8..07ad0744 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -521,6 +521,10 @@ typedef struct _webrtc_s { #ifndef TIZEN_TV webrtc_resource_s resource; #endif +#ifdef TIZEN_FEATURE_UI + void *rotate_sensor_listener; + int screen_rotated; +#endif } webrtc_s; /* FIXME: divide into two slot types or use union */ @@ -689,7 +693,8 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f /* screen source */ int _get_screen_resolution(int *width, int *height); -int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source); +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 _unset_screen_source_crop(webrtc_s *webrtc, unsigned int source_id); bool _is_screen_source_cropped(webrtc_gst_slot_s *source); diff --git a/src/webrtc.c b/src/webrtc.c index 7703a0fe..dd43140f 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -161,6 +161,11 @@ int webrtc_destroy(webrtc_h webrtc) _gst_destroy_pipeline(_webrtc); _unload_ini(_webrtc); +#ifdef TIZEN_FEATURE_UI + if (_webrtc->rotate_sensor_listener) + _unset_screen_rotation_changed_cb(_webrtc); +#endif + g_cond_clear(&_webrtc->stats_cond); g_mutex_clear(&_webrtc->stats_mutex); g_cond_clear(&_webrtc->desc_cond); diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 3b54adef..8c55a094 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -173,9 +173,9 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) return WEBRTC_ERROR_INVALID_OPERATION; #ifdef TIZEN_FEATURE_UI - if ((ret = _set_screen_rotation_changed_cb(source)) != WEBRTC_ERROR_NONE) - return ret; - + if (!webrtc->rotate_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; diff --git a/src/webrtc_source_screen.c b/src/webrtc_source_screen.c index f8d14fac..01924746 100644 --- a/src/webrtc_source_screen.c +++ b/src/webrtc_source_screen.c @@ -55,7 +55,9 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int videocrop = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VIDEOCROP); RET_VAL_IF(videocrop == NULL, WEBRTC_ERROR_INVALID_OPERATION, "videocrop is NULL"); - if (source->video_info.origin_width > source->video_info.origin_height) + if ((webrtc->screen_rotated) && (source->video_info.origin_width < source->video_info.origin_height)) + portrait_mode = false; + else if ((!webrtc->screen_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"); @@ -168,15 +170,12 @@ int _get_screen_resolution(int *width, int *height) static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[], int events_count, void *user_data) { - webrtc_gst_slot_s *source = (webrtc_gst_slot_s *)user_data; - int width; - int height; + webrtc_s *webrtc = (webrtc_s *)user_data; int type; int event; int angle; - RET_IF(source == NULL, "source is NULL"); - RET_IF(source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN, "invalid source type [%d]", source->type); + RET_IF(webrtc == NULL, "webrtc is NULL"); sensor_get_type(sensor, &type); if (type != AUTO_ROTATION_SENSOR) @@ -204,28 +203,23 @@ static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[ LOG_DEBUG("screen rotation changed [%d]", angle); - if (_get_screen_resolution(&width, &height) != WEBRTC_ERROR_NONE) - return; + g_mutex_lock(&webrtc->mutex); + if (angle == 0 || angle == 180) + webrtc->screen_rotated = false; + else + webrtc->screen_rotated = true; - g_mutex_lock(&source->webrtc->mutex); - if (angle == 0 || angle == 180) { - source->video_info.origin_width = width; - source->video_info.origin_height = height; - } else { - source->video_info.origin_width = height; - source->video_info.origin_height = width; - } - g_mutex_unlock(&source->webrtc->mutex); + g_mutex_unlock(&webrtc->mutex); } -int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source) +int _set_screen_rotation_changed_cb(webrtc_s *webrtc) { bool supported; sensor_h *sh; int count; sensor_listener_h lh; - RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL"); + RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); sensor_is_supported(AUTO_ROTATION_SENSOR, &supported); @@ -238,20 +232,33 @@ int _set_screen_rotation_changed_cb(webrtc_gst_slot_s *source) sensor_create_listener(sh[0], &lh); - sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, source); + sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, webrtc); sensor_listener_set_option(lh, SENSOR_OPTION_ALWAYS_ON); sensor_listener_set_interval(lh, 100); if (sensor_listener_start(lh) != SENSOR_ERROR_NONE) { LOG_ERROR("failed to sensor_listener_start()"); + sensor_destroy_listener(lh); return WEBRTC_ERROR_INVALID_OPERATION; } + webrtc->rotate_sensor_listener = (void *)lh; + LOG_INFO("AUTO_ROTATION_SENSOR is supported"); return WEBRTC_ERROR_NONE; } +void _unset_screen_rotation_changed_cb(webrtc_s *webrtc) +{ + RET_IF(webrtc == NULL, "webrtc is NULL"); + RET_IF(webrtc->rotate_sensor_listener == NULL, "rotate_sensor_listener is NULL"); + + sensor_destroy_listener((sensor_listener_h)webrtc->rotate_sensor_listener); + + LOG_INFO("AUTO_ROTATION_SENSOR is destroyed"); +} + bool _is_screen_source_cropped(webrtc_gst_slot_s *source) { GstElement *videocrop;