return WEBRTC_ERROR_NONE;
}
-int _set_video_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
+static int __validate_video_source_for_mute(webrtc_s *webrtc, unsigned int source_id, webrtc_gst_slot_s **source)
{
- int ret = WEBRTC_ERROR_NONE;
- webrtc_gst_slot_s *source = NULL;
+ webrtc_gst_slot_s *_source;
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((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
+ RET_VAL_IF((_source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
- if (!(source->media_types & MEDIA_TYPE_VIDEO)) {
- LOG_ERROR("invalid media_type for source[media_types:0x%x, id:%u]", source->media_types, source_id);
+ if (!(_source->media_types & MEDIA_TYPE_VIDEO)) {
+ LOG_ERROR("invalid media_type for source[media_types:0x%x, id:%u]", _source->media_types, source_id);
return WEBRTC_ERROR_INVALID_PARAMETER;
}
- LOG_DEBUG("webrtc[%p] source_id[%u] mute[%d]", webrtc, source_id, mute);
+ if (_source->type != WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST &&
+ _source->type != WEBRTC_MEDIA_SOURCE_TYPE_CAMERA &&
+ _source->type != WEBRTC_MEDIA_SOURCE_TYPE_SCREEN) {
+ LOG_ERROR_IF_REACHED("type(%d)", _source->type);
+ return WEBRTC_ERROR_INVALID_PARAMETER;
+ }
- switch (source->type) {
- case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
- ret = __mute_videotestsrc(source, mute);
- break;
+ if (source)
+ *source = _source;
- case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
- ret = __mute_camerasrc(source, mute);
- break;
+ return WEBRTC_ERROR_NONE;
+}
- case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
- ret = __mute_videosrc(source, mute);
- break;
+typedef int (*videosrc_mute_func)(webrtc_gst_slot_s *source, bool mute);
- default:
- LOG_ERROR_IF_REACHED("type(%d)", source->type);
- return WEBRTC_ERROR_INVALID_PARAMETER;
- }
+static videosrc_mute_func videosrc_mute_funcs[] = {
+ [WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST] = __mute_videotestsrc,
+ [WEBRTC_MEDIA_SOURCE_TYPE_CAMERA] = __mute_camerasrc,
+ [WEBRTC_MEDIA_SOURCE_TYPE_SCREEN] = __mute_videosrc
+};
- if (ret == WEBRTC_ERROR_NONE)
+int _set_video_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
+{
+ int ret;
+ webrtc_gst_slot_s *source;
+
+ 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");
+ if ((ret = __validate_video_source_for_mute(webrtc, source_id, &source)) != WEBRTC_ERROR_NONE)
+ return ret;
+
+ LOG_DEBUG("webrtc[%p] source_id[%u] mute[%d]", webrtc, source_id, mute);
+
+ if ((ret = (videosrc_mute_funcs[source->type])(source, mute)) == WEBRTC_ERROR_NONE)
source->video_muted = mute;
return ret;
}
//LCOV_EXCL_START
-int _set_audio_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
+static int __validate_audio_source_for_mute(webrtc_s *webrtc, unsigned int source_id, webrtc_gst_slot_s **source)
{
- webrtc_gst_slot_s *source = NULL;
- GstElement *volume = NULL;
+ webrtc_gst_slot_s *_source;
+ GstElement *volume;
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((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
+ RET_VAL_IF((_source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
- if (!(source->media_types & MEDIA_TYPE_AUDIO)) {
- LOG_ERROR("invalid media_type for source[media_types:0x%x, id:%u]", source->media_types, source_id);
+ if (!(_source->media_types & MEDIA_TYPE_AUDIO)) {
+ LOG_ERROR("invalid media_type for source[media_types:0x%x, id:%u]", _source->media_types, source_id);
return WEBRTC_ERROR_INVALID_PARAMETER;
}
- switch (source->type) {
- case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
- case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
- volume = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VOLUME);
- RET_VAL_IF(volume == NULL, WEBRTC_ERROR_INVALID_OPERATION, "volume is NULL");
-
- if (!g_object_class_find_property(G_OBJECT_GET_CLASS(volume), "mute")) {
- LOG_ERROR("there is no mute property");
- return WEBRTC_ERROR_INVALID_OPERATION;
- }
+ if (_source->type != WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST &&
+ _source->type != WEBRTC_MEDIA_SOURCE_TYPE_MIC) {
+ LOG_ERROR_IF_REACHED("type(%d)", _source->type);
+ return WEBRTC_ERROR_INVALID_PARAMETER;
+ }
- g_object_set(G_OBJECT(volume), "mute", mute, NULL);
- break;
+ volume = gst_bin_get_by_name(_source->bin, ELEMENT_NAME_VOLUME);
+ RET_VAL_IF(volume == NULL, WEBRTC_ERROR_INVALID_OPERATION, "volume is NULL");
- default:
- LOG_ERROR_IF_REACHED("type(%d)", source->type);
- return WEBRTC_ERROR_INVALID_PARAMETER;
+ if (!g_object_class_find_property(G_OBJECT_GET_CLASS(volume), "mute")) {
+ LOG_ERROR("there is no mute property");
+ return WEBRTC_ERROR_INVALID_OPERATION;
}
+ if (source)
+ *source = _source;
+
+ return WEBRTC_ERROR_NONE;
+}
+
+int _set_audio_mute(webrtc_s *webrtc, unsigned int source_id, bool mute)
+{
+ int ret;
+ webrtc_gst_slot_s *source;
+
+ 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");
+ if ((ret = __validate_audio_source_for_mute(webrtc, source_id, &source)) != WEBRTC_ERROR_NONE)
+ return ret;
+
+ g_object_set(gst_bin_get_by_name(source->bin, ELEMENT_NAME_VOLUME), "mute", mute, NULL);
+
LOG_INFO("webrtc[%p] source_id[%u] mute[%d]", webrtc, source_id, mute);
return WEBRTC_ERROR_NONE;
int _get_video_mute(webrtc_s *webrtc, unsigned int source_id, bool *muted)
{
- const webrtc_gst_slot_s *source;
+ int ret;
+ webrtc_gst_slot_s *source = NULL;
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((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
-
- if (!(source->media_types & MEDIA_TYPE_VIDEO)) {
- LOG_ERROR("invalid media_type for source[media_types:0x%x, id:%u]", source->media_types, source_id);
- return WEBRTC_ERROR_INVALID_PARAMETER;
- }
+ RET_VAL_IF(muted == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "muted is NULL");
+ if ((ret = __validate_video_source_for_mute(webrtc, source_id, &source)) != WEBRTC_ERROR_NONE)
+ return ret;
- switch (source->type) {
- case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
- case WEBRTC_MEDIA_SOURCE_TYPE_CAMERA:
- case WEBRTC_MEDIA_SOURCE_TYPE_SCREEN:
- *muted = source->video_muted;
- break;
-
- default:
- LOG_ERROR_IF_REACHED("type(%d)", source->type);
- return WEBRTC_ERROR_INVALID_PARAMETER;
- }
+ *muted = source->video_muted;
LOG_INFO("webrtc[%p] source_id[%u] muted[%d]", webrtc, source_id, *muted);
//LCOV_EXCL_START
int _get_audio_mute(webrtc_s *webrtc, unsigned int source_id, bool *muted)
{
- const webrtc_gst_slot_s *source;
- GstElement *volume = NULL;
+ int ret;
+ webrtc_gst_slot_s *source;
+ gboolean _muted;
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((source = _get_slot_by_id(webrtc->gst.source_slots, source_id)) == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "could not find source");
-
- if (!(source->media_types & MEDIA_TYPE_AUDIO)) {
- LOG_ERROR("invalid media_type for source[media_types:0x%x, id:%u]", source->media_types, source_id);
- return WEBRTC_ERROR_INVALID_PARAMETER;
- }
-
- switch (source->type) {
- case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
- case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
- volume = gst_bin_get_by_name(source->bin, ELEMENT_NAME_VOLUME);
- RET_VAL_IF(volume == NULL, WEBRTC_ERROR_INVALID_OPERATION, "volume is NULL");
-
- if (!g_object_class_find_property(G_OBJECT_GET_CLASS(volume), "mute")) {
- LOG_ERROR("there is no mute property");
- return WEBRTC_ERROR_INVALID_OPERATION;
- }
+ RET_VAL_IF(muted == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "muted is NULL");
+ if ((ret = __validate_audio_source_for_mute(webrtc, source_id, &source)) != WEBRTC_ERROR_NONE)
+ return ret;
- g_object_get(G_OBJECT(volume), "mute", muted, NULL);
- break;
+ g_object_get(gst_bin_get_by_name(source->bin, ELEMENT_NAME_VOLUME), "mute", &_muted, NULL);
- default:
- LOG_ERROR_IF_REACHED("type(%d)", source->type);
- return WEBRTC_ERROR_INVALID_PARAMETER;
- }
+ *muted = (bool)_muted;
- LOG_DEBUG("webrtc[%p] source_id[%u] muted[%d]", webrtc, source_id, *muted);
+ LOG_INFO("webrtc[%p] source_id[%u] muted[%d]", webrtc, source_id, *muted);
return WEBRTC_ERROR_NONE;
}