return ret;
}
-static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool use_mic)
+static int __build_rest_of_audiosrc(webrtc_s *webrtc, GstPad *src_pad, GstElement *audiosrc_element, webrtc_gst_slot_s *source)
{
int ret = WEBRTC_ERROR_NONE;
- const char *source_factory_name;
- GstElement *audiosrc;
+ GList *element_list = NULL;
GstElement *volume;
GstElement *capsfilter;
- GList *element_list = NULL;
- GstPad *src_pad;
const ini_item_media_source_s *ini_source;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(src_pad == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "src_pad is NULL");
+ RET_VAL_IF(audiosrc_element == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "audiosrc_element is NULL");
RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
- ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad);
- RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
-
- source->media_types = MEDIA_TYPE_AUDIO;
- source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
-
- source_factory_name = __get_source_element(webrtc, use_mic ? WEBRTC_MEDIA_SOURCE_TYPE_MIC : WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST);
- if (!(audiosrc = _create_element(source_factory_name, use_mic ? ELEMENT_NAME_MIC_SRC : NULL)))
- return WEBRTC_ERROR_INVALID_OPERATION;
- APPEND_ELEMENT(element_list, audiosrc);
+ APPEND_ELEMENT(element_list, audiosrc_element);
if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
LOG_ERROR("ini_source is NULL");
goto exit;
}
- _gst_set_element_properties(audiosrc, ini_source->source_element_properties);
+ _gst_set_element_properties(audiosrc_element, ini_source->source_element_properties);
if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
goto exit;
return ret;
}
+static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool use_mic)
+{
+ int ret;
+ const char *source_factory_name;
+ GstPad *src_pad;
+ GstElement *audiosrc;
+
+ RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
+ RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
+ RET_VAL_IF(source->bin == NULL, WEBRTC_ERROR_INVALID_OPERATION, "bin is NULL");
+
+ ret = _add_no_target_ghostpad_to_slot(source, true, &src_pad);
+ RET_VAL_IF(ret != WEBRTC_ERROR_NONE, ret, "failed to _add_no_target_ghostpad_to_slot()");
+
+ source->media_types = MEDIA_TYPE_AUDIO;
+ source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
+
+ source_factory_name = __get_source_element(webrtc, use_mic ? WEBRTC_MEDIA_SOURCE_TYPE_MIC : WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST);
+ if (!(audiosrc = _create_element(source_factory_name, use_mic ? ELEMENT_NAME_MIC_SRC : NULL)))
+ return WEBRTC_ERROR_INVALID_OPERATION;
+
+ return __build_rest_of_audiosrc(webrtc, src_pad, audiosrc, source);
+}
+
static int __build_videotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
{
int ret = WEBRTC_ERROR_NONE;
static int __build_custom_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
{
- int ret = WEBRTC_ERROR_NONE;
+ int ret;
const char *source_factory_name;
GstElement *custom_audiosrc;
- GstElement *volume;
- GstElement *capsfilter;
- GList *element_list = NULL;
GstPad *src_pad;
- const ini_item_media_source_s *ini_source;
RET_VAL_IF(webrtc == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "webrtc is NULL");
RET_VAL_IF(source == NULL, WEBRTC_ERROR_INVALID_PARAMETER, "source is NULL");
source_factory_name = __get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_CUSTOM_AUDIO);
if (!(custom_audiosrc = _create_element(source_factory_name, NULL)))
return WEBRTC_ERROR_INVALID_OPERATION;
- APPEND_ELEMENT(element_list, custom_audiosrc);
-
- if (!(ini_source = _ini_get_source_by_type(&webrtc->ini, source->type))) {
- LOG_ERROR("ini_source is NULL");
- goto exit;
- }
- _gst_set_element_properties(custom_audiosrc, ini_source->source_element_properties);
-
- if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
- goto exit;
- APPEND_ELEMENT(element_list, volume);
-
- source->av[AV_IDX_AUDIO].inbandfec = ini_source->use_inbandfec;
- source->av[AV_IDX_AUDIO].packet_loss_percentage = ini_source->packet_loss_percentage;
-
- if ((ret = __create_rest_of_elements(webrtc, source, true, &element_list, true)) != WEBRTC_ERROR_NONE)
- goto exit;
-
- if (!__add_elements_to_bin(source->bin, element_list)) {
- SAFE_G_LIST_FREE(element_list);
- return WEBRTC_ERROR_INVALID_OPERATION;
- }
- if (!__link_elements(element_list)) {
- ret = WEBRTC_ERROR_INVALID_OPERATION;
- goto exit_with_remove_from_bin;
- }
-
- if (!(capsfilter = gst_bin_get_by_name(source->bin, ELEMENT_NAME_RTP_CAPSFILTER))) {
- ret = WEBRTC_ERROR_INVALID_OPERATION;
- goto exit_with_remove_from_bin;
- }
- ret = _set_ghost_pad_target(src_pad, capsfilter, true);
- if (ret != WEBRTC_ERROR_NONE)
- goto exit_with_remove_from_bin;
-
- __add_probe_to_pad_for_pause(source, AV_IDX_AUDIO, src_pad, __payloaded_data_probe_cb);
-
- SAFE_G_LIST_FREE(element_list);
-
- return WEBRTC_ERROR_NONE;
-
-exit_with_remove_from_bin:
- __remove_elements_from_bin(source->bin, element_list);
- SAFE_G_LIST_FREE(element_list);
- return ret;
-exit:
- SAFE_G_LIST_FREE_FULL(element_list, gst_object_unref);
- return ret;
+ return __build_rest_of_audiosrc(webrtc, src_pad, custom_audiosrc, source);
}
static int __build_filesrc_bin(webrtc_gst_slot_s *source, media_type_e media_type)