const gchar *klass = gst_element_factory_get_metadata(factory, GST_ELEMENT_METADATA_KLASS);
if (g_strrstr(klass, "Codec/Decoder")) {
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+ const gchar *media_type = gst_structure_get_name(gst_caps_get_structure(caps, 0));
+ RET_VAL_IF(media_type == NULL, GST_AUTOPLUG_SELECT_TRY, "media_type is NULL");
+
+ if (g_strrstr(media_type, "audio")) {
+ GstElement *payloader = __create_payloader_for_filesrc_pipeline(pad, true);
+ if (!payloader) {
+ LOG_INFO("failed to find payloader. decode it");
+ return GST_AUTOPLUG_SELECT_TRY;
+ }
+
+ gst_object_unref(payloader);
+ }
+#endif
LOG_INFO("expose [%s]", klass);
+
return GST_AUTOPLUG_SELECT_EXPOSE;
}
return WEBRTC_ERROR_NONE;
}
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+static int __create_rest_of_raw_audio_elements_for_filesrc_pipeline(webrtc_s *webrtc, webrtc_gst_slot_s *source, GList **element_list)
+{
+ GstElement *queue = NULL;
+ GstElement *resample = NULL;
+ GstElement *conv = NULL;
+ GstElement *fakesink = NULL;
+ GList *_element_list = 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->filesrc_pipeline == NULL, WEBRTC_ERROR_INVALID_OPERATION, "filesrc_pipeline is NULL");
+
+ if (!(queue = _create_element(DEFAULT_ELEMENT_QUEUE, _get_element_name(GET_AV_IDX(true), ELEMENT_QUEUE))))
+ return WEBRTC_ERROR_INVALID_OPERATION;
+ APPEND_ELEMENT(_element_list, queue);
+
+ if (!(resample = _create_element(DEFAULT_ELEMENT_AUDIORESAMPLE, NULL)))
+ goto exit;
+ APPEND_ELEMENT(_element_list, resample);
+
+ if (!(conv = _create_element(DEFAULT_ELEMENT_AUDIOCONVERT, NULL)))
+ goto exit;
+ APPEND_ELEMENT(_element_list, conv);
+
+ if (_create_rest_of_elements(webrtc, source, false, &_element_list, true) != WEBRTC_ERROR_NONE)
+ goto exit;
+
+ if(!(fakesink = __prepare_fakesink_for_filesrc_pipeline(source, true)))
+ goto exit;
+ APPEND_ELEMENT(_element_list, fakesink);
+
+ if (!_add_elements_to_bin(GST_BIN(source->filesrc_pipeline), _element_list))
+ goto exit;
+
+ if (!_link_elements(_element_list))
+ goto exit_with_remove_from_bin;
+
+ if (!_sync_elements_state_with_parent(_element_list))
+ goto exit_with_remove_from_bin;
+
+ *element_list = _element_list;
+
+ return WEBRTC_ERROR_NONE;
+
+exit_with_remove_from_bin:
+ _remove_elements_from_bin(GST_BIN(source->filesrc_pipeline), _element_list);
+ SAFE_G_LIST_FREE(_element_list);
+ return WEBRTC_ERROR_INVALID_OPERATION;
+
+exit:
+ SAFE_G_LIST_FREE_FULL(_element_list, gst_object_unref);
+ return WEBRTC_ERROR_INVALID_OPERATION;
+}
+#endif
+
static void __filesrc_pipeline_decodebin_pad_added_cb(GstElement *element, GstPad *pad, gpointer data)
{
int ret = WEBRTC_ERROR_NONE;
GList *filesrc_element_list = NULL;
GList *bin_element_list = NULL;
GstElement *queue = NULL;
+ bool need_decoding = true;
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+ GList *audio_pipeline_element_list = NULL;
+#endif
RET_IF(source == NULL, "source is NULL");
RET_IF(source->filesrc_pipeline == NULL, "filesrc_pipeline is NULL");
is_audio = _is_audio_media_type(media_type);
av_idx = GET_AV_IDX(is_audio);
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+ if (is_audio && g_strrstr(media_type, "raw")) {
+ need_decoding = false;
+
+ const ini_item_media_source_s *ini_source = _ini_get_source_by_type(&source->webrtc->ini, source->type);
+ if (ini_source == NULL)
+ ini_source = &(source->webrtc->ini.media_source);
+
+ source->av[AV_IDX_AUDIO].codec = ini_source->a_codecs[0];
+ }
+#endif
g_free(media_type);
if (source->av[av_idx].src_pad_probe_id > 0) {
return;
}
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+ if (need_decoding)
+ ret = __create_rest_of_elements_for_filesrc_pipeline(source, pad, &filesrc_element_list, is_audio);
+ else
+ ret = __create_rest_of_raw_audio_elements_for_filesrc_pipeline(source->webrtc, source, &audio_pipeline_element_list);
+#else
ret = __create_rest_of_elements_for_filesrc_pipeline(source, pad, &filesrc_element_list, is_audio);
+#endif
if (ret != WEBRTC_ERROR_NONE) {
LOG_ERROR("failed to __create_rest_of_elements_for_filesrc_pipeline()");
return;
goto exit_with_remove_from_bin;
}
- source->av[av_idx].render.need_decoding = true;
+ source->av[av_idx].render.need_decoding = need_decoding;
source->av[av_idx].render.appsrc_caps = gst_pad_get_current_caps(pad);
_add_probe_to_pad_for_render(source, av_idx, gst_element_get_static_pad(queue, "src"), _source_data_probe_cb);
SAFE_G_LIST_FREE(filesrc_element_list);
SAFE_G_LIST_FREE(bin_element_list);
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+ SAFE_G_LIST_FREE(audio_pipeline_element_list);
+#endif
GENERATE_DOT(source->webrtc, source->filesrc_pipeline, "%s.%s-%s",
GST_ELEMENT_NAME(source->filesrc_pipeline), GST_ELEMENT_NAME(element), GST_PAD_NAME(pad));
_remove_elements_from_bin(GST_BIN(source->bin), bin_element_list);
SAFE_G_LIST_FREE(bin_element_list);
exit:
+#ifdef SUPPORT_FILESRC_AUDIO_FORMAT_CHANGE
+ if (filesrc_element_list)
+ _remove_elements_from_bin(GST_BIN(source->filesrc_pipeline), filesrc_element_list);
+ SAFE_G_LIST_FREE(filesrc_element_list);
+
+ if (audio_pipeline_element_list)
+ _remove_elements_from_bin(GST_BIN(source->filesrc_pipeline), audio_pipeline_element_list);
+ SAFE_G_LIST_FREE(audio_pipeline_element_list);
+#else
_remove_elements_from_bin(GST_BIN(source->filesrc_pipeline), filesrc_element_list);
SAFE_G_LIST_FREE(filesrc_element_list);
+#endif
return;
}