From: Sangchul Lee Date: Mon, 5 Sep 2022 07:47:47 +0000 (+0900) Subject: webrtc_source_screen: Check return values and release resource of sensor API X-Git-Tag: accepted/tizen/unified/20220908.124830~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=refs%2Fchanges%2F99%2F280799%2F2;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc_source_screen: Check return values and release resource of sensor API [Version] 0.3.232 [Issue Type] Coverity defect(CHECKED_RETURN) & bug fix Change-Id: Ic5f90f54c1bd070101da6e1433d186d5444dd305 Signed-off-by: Sangchul Lee --- diff --git a/include/webrtc_private.h b/include/webrtc_private.h index 860894b3..fb5da787 100644 --- a/include/webrtc_private.h +++ b/include/webrtc_private.h @@ -460,6 +460,12 @@ typedef struct _webrtc_negotiation_states_s { webrtc_ice_connection_state_e ice_connection_state; } webrtc_negotiation_states_s; +typedef struct _webrtc_rotate_info_s { + int rotated; + void *sensor; + void *sensor_listener; +} webrtc_rotate_info_s; + typedef enum _idle_cb_type_e { IDLE_CB_TYPE_STATE, IDLE_CB_TYPE_ERROR, @@ -523,8 +529,7 @@ typedef struct _webrtc_s { #ifndef TIZEN_TV webrtc_resource_s resource; #ifdef TIZEN_FEATURE_UI - int screen_rotated; - void *rotate_sensor_listener; + webrtc_rotate_info_s rotate_info; #endif #endif } webrtc_s; diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 33610965..629f46b7 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.231 +Version: 0.3.232 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index e2c0c576..e9398f00 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -162,7 +162,7 @@ int webrtc_destroy(webrtc_h webrtc) _unload_ini(_webrtc); #if !defined(TIZEN_TV) && defined(TIZEN_FEATURE_UI) - if (_webrtc->rotate_sensor_listener) + if (_webrtc->rotate_info.sensor || _webrtc->rotate_info.sensor_listener) _unset_screen_rotation_changed_cb(_webrtc); #endif diff --git a/src/webrtc_source.c b/src/webrtc_source.c index e972b022..ad4df969 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -143,7 +143,7 @@ static int __build_screensrc(webrtc_s *webrtc, webrtc_gst_slot_s *source) return WEBRTC_ERROR_INVALID_OPERATION; #if !defined(TIZEN_TV) && defined(TIZEN_FEATURE_UI) - if (!webrtc->rotate_sensor_listener) + if (!webrtc->rotate_info.sensor_listener) if ((ret = _set_screen_rotation_changed_cb(webrtc)) != WEBRTC_ERROR_NONE) return ret; #endif diff --git a/src/webrtc_source_screen.c b/src/webrtc_source_screen.c index 1d391871..9c4e230e 100644 --- a/src/webrtc_source_screen.c +++ b/src/webrtc_source_screen.c @@ -34,7 +34,7 @@ int _set_screen_source_crop(webrtc_s *webrtc, unsigned int source_id, int x, int float rw, rh; int left, right, top, bottom; #if !defined(TIZEN_TV) && defined(TIZEN_FEATURE_UI) - bool rotated = webrtc->screen_rotated; + bool rotated = webrtc->rotate_info.rotated; #else bool rotated = false; #endif @@ -209,9 +209,9 @@ static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[ g_mutex_lock(&webrtc->mutex); if (angle == 0 || angle == 180) - webrtc->screen_rotated = false; + webrtc->rotate_info.rotated = false; else - webrtc->screen_rotated = true; + webrtc->rotate_info.rotated = true; g_mutex_unlock(&webrtc->mutex); } @@ -219,46 +219,73 @@ static void __screen_rotation_changed_cb(sensor_h sensor, sensor_event_s events[ int _set_screen_rotation_changed_cb(webrtc_s *webrtc) { bool supported; - sensor_h *sh; + sensor_h *sh = NULL; int count; - sensor_listener_h lh; + sensor_listener_h lh = NULL; + int ret; RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(webrtc->rotate_info.sensor != NULL, WEBRTC_ERROR_INVALID_OPERATION, "sensor is already set"); + RET_VAL_IF(webrtc->rotate_info.sensor_listener != NULL, WEBRTC_ERROR_INVALID_OPERATION, "sensor_listener is already set"); - sensor_is_supported(AUTO_ROTATION_SENSOR, &supported); - + ret = sensor_is_supported(AUTO_ROTATION_SENSOR, &supported); + RET_VAL_IF(ret != SENSOR_ERROR_NONE, WEBRTC_ERROR_INVALID_OPERATION, "failed to sensor_is_supported()"); if (!supported) { LOG_INFO("AUTO_ROTATION_SENSOR is not supported"); return WEBRTC_ERROR_NONE; } - sensor_get_sensor_list(AUTO_ROTATION_SENSOR, &sh, &count); + ret = sensor_get_sensor_list(AUTO_ROTATION_SENSOR, &sh, &count); + if (ret != SENSOR_ERROR_NONE) { + LOG_ERROR("failed to sensor_get_sensor_list()"); + goto error; + } - sensor_create_listener(sh[0], &lh); + ret = sensor_create_listener(sh[0], &lh); + if (ret != SENSOR_ERROR_NONE) { + LOG_ERROR("failed to sensor_create_listener()"); + goto error; + } - 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); + ret = sensor_listener_set_events_cb(lh, __screen_rotation_changed_cb, webrtc); + ret |= sensor_listener_set_option(lh, SENSOR_OPTION_ALWAYS_ON); + ret |= sensor_listener_set_interval(lh, 100); + if (ret != SENSOR_ERROR_NONE) { + LOG_ERROR("failed to sensor listener setting"); + goto error; + } if (sensor_listener_start(lh) != SENSOR_ERROR_NONE) { LOG_ERROR("failed to sensor_listener_start()"); - sensor_destroy_listener(lh); - return WEBRTC_ERROR_INVALID_OPERATION; + goto error; } - webrtc->rotate_sensor_listener = (void *)lh; + webrtc->rotate_info.sensor = (void *)sh; + webrtc->rotate_info.sensor_listener = (void *)lh; LOG_INFO("AUTO_ROTATION_SENSOR is supported"); return WEBRTC_ERROR_NONE; + +error: + if (lh) + sensor_destroy_listener(lh); + if (sh) + free(sh); + return WEBRTC_ERROR_INVALID_OPERATION; } 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"); + RET_IF(webrtc->rotate_info.sensor == NULL, "rotate_info.sensor is NULL"); + RET_IF(webrtc->rotate_info.sensor_listener == NULL, "rotate_info.sensor_listener is NULL"); + + sensor_destroy_listener((sensor_listener_h)webrtc->rotate_info.sensor_listener); + free(webrtc->rotate_info.sensor); - sensor_destroy_listener((sensor_listener_h)webrtc->rotate_sensor_listener); + webrtc->rotate_info.sensor_listener = NULL; + webrtc->rotate_info.sensor = NULL; LOG_INFO("AUTO_ROTATION_SENSOR is destroyed"); }