return ret;
}
-static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
+static int __build_audiosrc(webrtc_s *webrtc, webrtc_gst_slot_s *source, bool is_mic)
{
int ret = WEBRTC_ERROR_NONE;
+ const char *source_factory_name;
GstElement *audiosrc;
GstElement *volume = NULL;
GstElement *capsfilter = NULL;
source->media_types = MEDIA_TYPE_AUDIO;
source->zerocopy_enabled = __is_hw_encoder_used(webrtc, source->type, source->media_types);
- if (!(audiosrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_MIC), NULL)))
+ source_factory_name = __get_source_element(webrtc, is_mic ? WEBRTC_MEDIA_SOURCE_TYPE_MIC : WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST);
+ if (!(audiosrc = _create_element(source_factory_name, NULL)))
return WEBRTC_ERROR_INVALID_OPERATION;
+ if (!is_mic)
+ g_object_set(G_OBJECT(audiosrc), "is-live", TRUE, NULL);
+
if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
goto exit;
return ret;
}
-static int __build_audiotestsrc(webrtc_s *webrtc, webrtc_gst_slot_s *source)
-{
- int ret = WEBRTC_ERROR_NONE;
- GstElement *audiotestsrc;
- GstElement *volume = NULL;
- GstElement *capsfilter = NULL;
- GstElement *audioenc = NULL;
- GstElement *audiopay = NULL;
- GstElement *queue = NULL;
- GstElement *capsfilter2 = NULL;
-
- 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, &source->av[AV_IDX_AUDIO].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);
-
- if (!(audiotestsrc = _create_element(__get_source_element(webrtc, WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST), NULL)))
- return WEBRTC_ERROR_INVALID_OPERATION;
-
- g_object_set(G_OBJECT(audiotestsrc), "is-live", TRUE, NULL);
-
- if (!(volume = _create_element(DEFAULT_ELEMENT_VOLUME, ELEMENT_NAME_VOLUME)))
- goto exit;
-
- if ((ret = __create_rest_of_elements(webrtc, source, &capsfilter, &audioenc, &audiopay, &queue, &capsfilter2)) != WEBRTC_ERROR_NONE)
- goto exit;
-
- gst_bin_add_many(source->bin, audiotestsrc, volume, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL);
- if (!gst_element_link_many(audiotestsrc, volume, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL)) {
- LOG_ERROR("failed to gst_element_link_many()");
- ret = WEBRTC_ERROR_INVALID_OPERATION;
- goto exit_with_remove_from_bin;
- }
-
- ret = _set_ghost_pad_target(source->av[AV_IDX_AUDIO].src_pad, capsfilter2, true);
- if (ret != WEBRTC_ERROR_NONE)
- goto exit_with_remove_from_bin;
-
- __add_probe_to_pad(source->av[AV_IDX_AUDIO].src_pad, MEDIA_TYPE_AUDIO, source);
-
- return WEBRTC_ERROR_NONE;
-
-exit_with_remove_from_bin:
- /* elements will be dereferenced */
- gst_bin_remove_many(source->bin, audiotestsrc, volume, capsfilter, audioenc, audiopay, queue, capsfilter2, NULL);
- return ret;
-exit:
- SAFE_GST_OBJECT_UNREF(audiotestsrc);
- SAFE_GST_OBJECT_UNREF(volume);
- SAFE_GST_OBJECT_UNREF(capsfilter);
- SAFE_GST_OBJECT_UNREF(audioenc);
- SAFE_GST_OBJECT_UNREF(audiopay);
- SAFE_GST_OBJECT_UNREF(queue);
- SAFE_GST_OBJECT_UNREF(capsfilter2);
- return ret;
-}
-
static void _appsrc_need_data_cb(GstElement *appsrc, guint size, gpointer data)
{
webrtc_gst_slot_s *source = (webrtc_gst_slot_s*)data;
return __build_camerasrc(webrtc, source);
case WEBRTC_MEDIA_SOURCE_TYPE_MIC:
- return __build_audiosrc(webrtc, source);
+ return __build_audiosrc(webrtc, source, true);
case WEBRTC_MEDIA_SOURCE_TYPE_VIDEOTEST:
return __build_videotestsrc(webrtc, source);
case WEBRTC_MEDIA_SOURCE_TYPE_AUDIOTEST:
- return __build_audiotestsrc(webrtc, source);
+ return __build_audiosrc(webrtc, source, false);
case WEBRTC_MEDIA_SOURCE_TYPE_MEDIA_PACKET:
return __build_mediapacketsrc(webrtc, source);