From: Sangchul Lee Date: Thu, 2 Jun 2022 05:47:02 +0000 (+0900) Subject: webrtc: Remove unnecessary variables X-Git-Tag: submit/tizen/20220613.225802~7 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=064e5d90bee97f9166ab304dc1a43396bddd9840;p=platform%2Fcore%2Fapi%2Fwebrtc.git webrtc: Remove unnecessary variables Some codes have been changed to have an intention of removing a variable. - Some logs are moved to functions in webrtc_source.c. - in some cases, mutex locker is applied. [Version] 0.3.117 [Issue Type] Refactoring Change-Id: I020f82b8ff32364a69b5a2ac3a3291761499d749 Signed-off-by: Sangchul Lee --- diff --git a/packaging/capi-media-webrtc.spec b/packaging/capi-media-webrtc.spec index 381bef04..f14be079 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.116 +Version: 0.3.117 Release: 0 Group: Multimedia/API License: Apache-2.0 diff --git a/src/webrtc.c b/src/webrtc.c index 34ea1e41..b125ac14 100644 --- a/src/webrtc.c +++ b/src/webrtc.c @@ -277,7 +277,6 @@ int webrtc_get_state(webrtc_h webrtc, webrtc_state_e *state) int webrtc_add_media_source(webrtc_h webrtc, webrtc_media_source_type_e type, unsigned int *source_id) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -296,16 +295,11 @@ int webrtc_add_media_source(webrtc_h webrtc, webrtc_media_source_type_e type, un RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); - ret = _add_media_source(webrtc, type, source_id); - if (ret == WEBRTC_ERROR_NONE) - LOG_INFO("webrtc[%p] source_id[%u]", webrtc, *source_id); - - return ret; + return _add_media_source(webrtc, type, source_id); } int webrtc_remove_media_source(webrtc_h webrtc, unsigned int source_id) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -315,16 +309,11 @@ int webrtc_remove_media_source(webrtc_h webrtc, unsigned int source_id) RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); - ret = _remove_media_source(webrtc, source_id); - if (ret == WEBRTC_ERROR_NONE) - LOG_INFO("webrtc[%p] source_id[%u]", webrtc, source_id); - - return ret; + return _remove_media_source(webrtc, source_id); } int webrtc_media_source_set_transceiver_direction(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_direction_e direction) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -334,197 +323,136 @@ int webrtc_media_source_set_transceiver_direction(webrtc_h webrtc, unsigned int RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); - ret = _set_transceiver_direction(webrtc, source_id, media_type, direction); - if (ret == WEBRTC_ERROR_NONE) - LOG_INFO("webrtc[%p] source_id[%u] media_type[%d] direction[%d]", webrtc, source_id, media_type, direction); - - return ret; + return _set_transceiver_direction(webrtc, source_id, media_type, direction); } int webrtc_media_source_get_transceiver_direction(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, webrtc_transceiver_direction_e *direction) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(direction == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "direction is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _get_transceiver_direction(webrtc, source_id, media_type, direction); - if (ret == WEBRTC_ERROR_NONE) - LOG_INFO("webrtc[%p] source_id[%u] media_type[%d] direction[%d]", webrtc, source_id, media_type, *direction); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _get_transceiver_direction(webrtc, source_id, media_type, direction); } int webrtc_media_source_set_pause(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool pause) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _set_pause(webrtc, source_id, media_type, pause); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _set_pause(webrtc, source_id, media_type, pause); } int webrtc_media_source_get_pause(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool *paused) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(paused == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "paused is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _get_pause(webrtc, source_id, media_type, paused); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _get_pause(webrtc, source_id, media_type, paused); } int webrtc_media_source_set_mute(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool mute) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(media_type != WEBRTC_MEDIA_TYPE_AUDIO && media_type != WEBRTC_MEDIA_TYPE_VIDEO, + WEBRTC_ERROR_INVALID_PARAMETER, "invalid media_type(%d)", media_type); - g_mutex_lock(&_webrtc->mutex); - - switch (media_type) { - case WEBRTC_MEDIA_TYPE_AUDIO: - ret = _set_audio_mute(_webrtc, source_id, mute); - break; - - case WEBRTC_MEDIA_TYPE_VIDEO: - ret = _set_video_mute(_webrtc, source_id, mute); - break; - - default: - LOG_ERROR_IF_REACHED("media type(%d)", media_type); - ret = WEBRTC_ERROR_INVALID_PARAMETER; - break; - } - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return (media_type == WEBRTC_MEDIA_TYPE_AUDIO) ? + _set_audio_mute(_webrtc, source_id, mute) : + _set_video_mute(_webrtc, source_id, mute); } int webrtc_media_source_get_mute(webrtc_h webrtc, unsigned int source_id, webrtc_media_type_e media_type, bool *muted) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); + RET_VAL_IF(media_type != WEBRTC_MEDIA_TYPE_AUDIO && media_type != WEBRTC_MEDIA_TYPE_VIDEO, + WEBRTC_ERROR_INVALID_PARAMETER, "invalid media_type(%d)", media_type); RET_VAL_IF(muted == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "muted is NULL"); - g_mutex_lock(&_webrtc->mutex); - - switch (media_type) { - case WEBRTC_MEDIA_TYPE_AUDIO: - ret = _get_audio_mute(_webrtc, source_id, muted); - break; - - case WEBRTC_MEDIA_TYPE_VIDEO: - ret = _get_video_mute(_webrtc, source_id, muted); - break; - - default: - LOG_ERROR_IF_REACHED("media type(%d)", media_type); - ret = WEBRTC_ERROR_INVALID_PARAMETER; - break; - } - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return (media_type == WEBRTC_MEDIA_TYPE_AUDIO) ? + _get_audio_mute(_webrtc, source_id, muted) : + _get_video_mute(_webrtc, source_id, muted); } int webrtc_media_source_set_video_resolution(webrtc_h webrtc, unsigned int source_id, int width, int height) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(width <= 0, WEBRTC_ERROR_INVALID_PARAMETER, "width <= 0"); RET_VAL_IF(height <= 0, WEBRTC_ERROR_INVALID_PARAMETER, "height <= 0"); - g_mutex_lock(&_webrtc->mutex); - - ret = _set_video_resolution(webrtc, source_id, width, height); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _set_video_resolution(webrtc, source_id, width, height); } int webrtc_media_source_get_video_resolution(webrtc_h webrtc, unsigned int source_id, int *width, int *height) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(width == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "width is NULL"); RET_VAL_IF(height == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "height is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _get_video_resolution(webrtc, source_id, width, height); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _get_video_resolution(webrtc, source_id, width, height); } int webrtc_media_source_set_video_framerate(webrtc_h webrtc, unsigned int source_id, int framerate) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(framerate <= 0, WEBRTC_ERROR_INVALID_PARAMETER, "framerate <= 0"); - g_mutex_lock(&_webrtc->mutex); - - ret = _set_video_framerate(webrtc, source_id, framerate); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _set_video_framerate(webrtc, source_id, framerate); } int webrtc_media_source_get_video_framerate(webrtc_h webrtc, unsigned int source_id, int *framerate) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(framerate == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "framerate is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _get_video_framerate(webrtc, source_id, framerate); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _get_video_framerate(webrtc, source_id, framerate); } int webrtc_mic_source_set_sound_stream_info(webrtc_h webrtc, unsigned int source_id, sound_stream_info_h stream_info) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -535,9 +463,7 @@ int webrtc_mic_source_set_sound_stream_info(webrtc_h webrtc, unsigned int source RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); - ret = _set_sound_stream_info(webrtc, source_id, stream_info); - - return ret; + return _set_sound_stream_info(webrtc, source_id, stream_info); } int webrtc_media_packet_source_set_buffer_state_changed_cb(webrtc_h webrtc, unsigned int source_id, webrtc_media_packet_source_buffer_state_changed_cb callback, void *user_data) @@ -596,7 +522,6 @@ int webrtc_media_packet_source_unset_buffer_state_changed_cb(webrtc_h webrtc, un int webrtc_media_packet_source_set_format(webrtc_h webrtc, unsigned int source_id, media_format_h format) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -607,16 +532,11 @@ int webrtc_media_packet_source_set_format(webrtc_h webrtc, unsigned int source_i RET_VAL_IF(_webrtc->state != WEBRTC_STATE_IDLE, WEBRTC_ERROR_INVALID_STATE, "the state should be IDLE"); - ret = _set_media_format(_webrtc, source_id, format); - if (ret == WEBRTC_ERROR_NONE) - LOG_INFO("webrtc[%p] source_id[%u] format[%p]", webrtc, source_id, format); - - return ret; + return _set_media_format(_webrtc, source_id, format); } int webrtc_media_packet_source_push_packet(webrtc_h webrtc, unsigned int source_id, media_packet_h packet) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; webrtc_gst_slot_s *source; @@ -635,9 +555,7 @@ int webrtc_media_packet_source_push_packet(webrtc_h webrtc, unsigned int source_ RET_VAL_IF(source->buffer_state_changed_cb.callback == NULL, WEBRTC_ERROR_INVALID_OPERATION, "the buffer state changed callback should be set"); - ret = _push_media_packet(webrtc, source_id, packet); - - return ret; + return _push_media_packet(webrtc, source_id, packet); } int webrtc_file_source_set_path(webrtc_h webrtc, unsigned int source_id, const char *path) @@ -685,7 +603,6 @@ int webrtc_file_source_get_looping(webrtc_h webrtc, unsigned int source_id, bool int webrtc_set_sound_stream_info(webrtc_h webrtc, unsigned int track_id, sound_stream_info_h stream_info) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -700,14 +617,11 @@ int webrtc_set_sound_stream_info(webrtc_h webrtc, unsigned int track_id, sound_s RET_VAL_IF(!_is_owner_of_track_build_context(_webrtc, track_id), WEBRTC_ERROR_INVALID_OPERATION, "this function should be called within the track added callback"); - ret = _set_stream_info_to_sink(webrtc, track_id, stream_info); - - return ret; + return _set_stream_info_to_sink(webrtc, track_id, stream_info); } int webrtc_set_display(webrtc_h webrtc, unsigned int track_id, webrtc_display_type_e type, webrtc_display_h display) { - int ret = WEBRTC_ERROR_NONE; g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; @@ -723,92 +637,70 @@ int webrtc_set_display(webrtc_h webrtc, unsigned int track_id, webrtc_display_ty RET_VAL_IF(!_is_owner_of_track_build_context(_webrtc, track_id), WEBRTC_ERROR_INVALID_OPERATION, "this function should be called within the track added callback"); - ret = _set_display_to_sink(webrtc, track_id, (unsigned int)type, (void *)display); - - return ret; + return _set_display_to_sink(webrtc, track_id, (unsigned int)type, (void *)display); } int webrtc_set_display_mode(webrtc_h webrtc, unsigned int track_id, webrtc_display_mode_e mode) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0"); RET_VAL_IF(mode > WEBRTC_DISPLAY_MODE_FULL, WEBRTC_ERROR_INVALID_PARAMETER, "invalid display mode(%d)", mode); - g_mutex_lock(&_webrtc->mutex); - - if (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) - ret = _set_display_mode_to_sink(webrtc, track_id, mode); - else - ret = _set_display_mode_to_loopback(webrtc, track_id, mode); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) ? + _set_display_mode_to_sink(webrtc, track_id, mode) : + _set_display_mode_to_loopback(webrtc, track_id, mode); } int webrtc_get_display_mode(webrtc_h webrtc, unsigned int track_id, webrtc_display_mode_e *mode) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0"); RET_VAL_IF(mode == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "mode is NULL"); - g_mutex_lock(&_webrtc->mutex); - - if (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) - ret = _get_display_mode_from_sink(webrtc, track_id, mode); - else - ret = _get_display_mode_from_loopback(webrtc, track_id, mode); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) ? + _get_display_mode_from_sink(webrtc, track_id, mode) : + _get_display_mode_from_loopback(webrtc, track_id, mode); } int webrtc_set_display_visible(webrtc_h webrtc, unsigned int track_id, bool visible) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0"); - g_mutex_lock(&_webrtc->mutex); - - if (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) - ret = _set_display_visible_to_sink(webrtc, track_id, visible); - else - ret = _set_display_visible_to_loopback(webrtc, track_id, visible); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) ? + _set_display_visible_to_sink(webrtc, track_id, visible) : + _set_display_visible_to_loopback(webrtc, track_id, visible); } int webrtc_get_display_visible(webrtc_h webrtc, unsigned int track_id, bool *visible) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); RET_VAL_IF(track_id == 0, WEBRTC_ERROR_INVALID_PARAMETER, "track id is 0"); RET_VAL_IF(visible == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "visible is NULL"); - g_mutex_lock(&_webrtc->mutex); - - if (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) - ret = _get_display_visible_from_sink(webrtc, track_id, visible); - else - ret = _get_display_visible_from_loopback(webrtc, track_id, visible); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return (track_id < TRACK_ID_THRESHOLD_OF_LOOPBACK) ? + _get_display_visible_from_sink(webrtc, track_id, visible) : + _get_display_visible_from_loopback(webrtc, track_id, visible); } int webrtc_set_encoded_audio_frame_cb(webrtc_h webrtc, webrtc_encoded_frame_cb callback, void *user_data) @@ -899,20 +791,16 @@ int webrtc_unset_encoded_video_frame_cb(webrtc_h webrtc) int webrtc_media_source_set_audio_loopback(webrtc_h webrtc, unsigned int source_id, sound_stream_info_h stream_info, unsigned int *track_id) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; 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(stream_info == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "stream_info is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _set_audio_loopback(webrtc, source_id, stream_info, track_id); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _set_audio_loopback(webrtc, source_id, stream_info, track_id); } int webrtc_media_source_unset_audio_loopback(webrtc_h webrtc, unsigned int source_id) @@ -934,7 +822,7 @@ int webrtc_media_source_unset_audio_loopback(webrtc_h webrtc, unsigned int sourc int webrtc_media_source_set_video_loopback(webrtc_h webrtc, unsigned int source_id, webrtc_display_type_e type, webrtc_display_h display, unsigned int *track_id) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; RET_VAL_IF(_webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL"); @@ -942,30 +830,22 @@ int webrtc_media_source_set_video_loopback(webrtc_h webrtc, unsigned int source_ RET_VAL_IF(type > WEBRTC_DISPLAY_TYPE_EVAS, WEBRTC_ERROR_INVALID_PARAMETER, "invalid display type(%d)", type); RET_VAL_IF(display == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "display is NULL"); - g_mutex_lock(&_webrtc->mutex); - - ret = _set_video_loopback(webrtc, source_id, (unsigned int)type, (void *)display, track_id); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _set_video_loopback(webrtc, source_id, (unsigned int)type, (void *)display, track_id); } int webrtc_media_source_unset_video_loopback(webrtc_h webrtc, unsigned int source_id) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_s *_webrtc = (webrtc_s *)webrtc; 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"); - g_mutex_lock(&_webrtc->mutex); - - ret = _unset_video_loopback(webrtc, source_id); - - g_mutex_unlock(&_webrtc->mutex); + locker = g_mutex_locker_new(&_webrtc->mutex); - return ret; + return _unset_video_loopback(webrtc, source_id); } int webrtc_set_stun_server(webrtc_h webrtc, const char *stun_server) @@ -1866,25 +1746,21 @@ int webrtc_data_channel_unset_close_cb(webrtc_data_channel_h channel) int webrtc_data_channel_send_string(webrtc_data_channel_h channel, const char *string) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_data_channel_s *_channel = (webrtc_data_channel_s *)channel; RET_VAL_IF(_channel == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "channel is NULL"); RET_VAL_IF(string == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "string is NULL"); RET_VAL_IF(_channel->channel == NULL, WEBRTC_ERROR_INVALID_OPERATION, "data_channel is NULL"); - g_mutex_lock(&_channel->mutex); - - ret = _data_channel_send_string(channel, string); - - g_mutex_unlock(&_channel->mutex); + locker = g_mutex_locker_new(&_channel->mutex); - return ret; + return _data_channel_send_string(channel, string); } int webrtc_data_channel_send_bytes(webrtc_data_channel_h channel, const char *data, unsigned int size) { - int ret = WEBRTC_ERROR_NONE; + g_autoptr(GMutexLocker) locker = NULL; webrtc_data_channel_s *_channel = (webrtc_data_channel_s *)channel; RET_VAL_IF(_channel == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "channel is NULL"); @@ -1892,13 +1768,9 @@ int webrtc_data_channel_send_bytes(webrtc_data_channel_h channel, const char *da RET_VAL_IF(size == 0, WEBRTC_ERROR_INVALID_PARAMETER, "size is 0"); RET_VAL_IF(_channel->channel == NULL, WEBRTC_ERROR_INVALID_OPERATION, "data_channel is NULL"); - g_mutex_lock(&_channel->mutex); - - ret = _data_channel_send_bytes(channel, data, size); - - g_mutex_unlock(&_channel->mutex); + locker = g_mutex_locker_new(&_channel->mutex); - return ret; + return _data_channel_send_bytes(channel, data, size); } int webrtc_data_channel_get_label(webrtc_data_channel_h channel, char **label) diff --git a/src/webrtc_source.c b/src/webrtc_source.c index 239c4f07..b96d38d6 100644 --- a/src/webrtc_source.c +++ b/src/webrtc_source.c @@ -2666,7 +2666,7 @@ static int __add_media_source(webrtc_s *webrtc, int type, unsigned int *source_i *source_id = source->id; - LOG_INFO("added a source slot[%p, id:%u]", source, source->id); + LOG_INFO("webrtc[%p] source[%p, name:%s, id:%u]", webrtc, source, bin_name, *source_id); return WEBRTC_ERROR_NONE; @@ -2720,6 +2720,8 @@ int _remove_media_source(webrtc_s *webrtc, unsigned int source_id) ret = WEBRTC_ERROR_INVALID_PARAMETER; } + LOG_INFO("webrtc[%p] source[name:%s, id:%u]", webrtc, bin_name, source_id); + g_free(bin_name); return ret; @@ -2771,7 +2773,8 @@ int _set_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_ g_object_set(G_OBJECT(trans), "direction", __direction_info[direction].gst, NULL); - LOG_DEBUG("Set direction to transceiver[%p, direction:%s]", trans, __direction_info[direction].str); + LOG_INFO("webrtc[%p] source_id[%u] media_type[%d] transceiver[%p, direction:%s]", + webrtc, source_id, media_type, trans, __direction_info[direction].str); return WEBRTC_ERROR_NONE; } @@ -2811,8 +2814,9 @@ int _get_transceiver_direction(webrtc_s *webrtc, unsigned int source_id, webrtc_ NULL); ret = __convert_direction(gst_direction, direction); - if (ret == WEBRTC_ERROR_NONE) - LOG_DEBUG("transceiver[%p, mlineindex:%u, mid:%s, direction:%s]", trans, mlineindex, mid, __direction_info[*direction].str); + + LOG_INFO("webrtc[%p] source_id[%u] media_type[%d] transceiver[%p, mlineindex:%u, mid:%s, direction:%s]", + webrtc, source_id, media_type, trans, mlineindex, mid, __direction_info[*direction].str); return ret; } @@ -3074,6 +3078,8 @@ int _set_media_format(webrtc_s *webrtc, unsigned int source_id, media_format_h f if (ret != WEBRTC_ERROR_NONE) goto error; + LOG_INFO("webrtc[%p] source_id[%u] format[%p]", webrtc, source_id, format); + return ret; error: