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;
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;
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;
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;
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)
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;
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;
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)
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;
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;
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)
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)
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");
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)
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");
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)