Skip to content
This repository was archived by the owner on Jan 16, 2024. It is now read-only.

Commit b45fad1

Browse files
committed
GStreamerMediaPlayer: accept full GstBin descriptions in "audioSink"
Rather than only accept a sink element type in SampleApp config's gstreamerMediaPlayer -> audioSink setting (like "alsasink" or "pulsesink"), let the user specify the name plus any parameters and even multiple subelements to go at the end of the pipeline if needed. The following is a useful example: "audioSink":"pulsesink stream-properties=\"props,media.role=announce\"" in combination with the pulseaudio "module-role-ducking" module to enable attenuating music and other audio during Alexa announcements.
1 parent 352bc15 commit b45fad1

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

MediaPlayer/GStreamerMediaPlayer/src/MediaPlayer.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -677,26 +677,34 @@ bool MediaPlayer::setupPipeline() {
677677
}
678678
}
679679

680-
std::string audioSinkElement;
680+
std::string audioSinkDescription;
681681
ConfigurationNode::getRoot()[MEDIAPLAYER_CONFIGURATION_ROOT_KEY].getString(
682-
MEDIAPLAYER_AUDIO_SINK_KEY, &audioSinkElement, "autoaudiosink");
683-
m_pipeline.audioSink = gst_element_factory_make(audioSinkElement.c_str(), "audio_sink");
684-
685-
/// If the sink is a fakesink, set sync to true so that it uses system clock for consuming the buffer
686-
/// instead of the default behavior, which is to consume the buffer as fast as possible.
687-
if (audioSinkElement == "fakesink") {
688-
m_isFakeSink = true;
689-
g_object_set(m_pipeline.audioSink, "sync", true, NULL);
690-
}
682+
MEDIAPLAYER_AUDIO_SINK_KEY, &audioSinkDescription, "autoaudiosink");
683+
GError* error = NULL;
684+
m_pipeline.audioSink = gst_parse_bin_from_description_full(
685+
audioSinkDescription.c_str(),
686+
TRUE,
687+
NULL,
688+
static_cast<GstParseFlags>(GST_PARSE_FLAG_FATAL_ERRORS | GST_PARSE_FLAG_NO_SINGLE_ELEMENT_BINS),
689+
&error);
691690

692691
if (!m_pipeline.audioSink) {
693692
ACSDK_ERROR(LX("setupPipelineFailed")
694693
.d("name", RequiresShutdown::name())
695694
.d("reason", "createAudioSinkElementFailed")
696-
.d("audioSinkElement", audioSinkElement));
695+
.d("errorMessage", error->message)
696+
.d("audioSinkDescription", audioSinkDescription));
697+
g_error_free(error);
697698
return false;
698699
}
699700

701+
/// If the sink is a fakesink, set sync to true so that it uses system clock for consuming the buffer
702+
/// instead of the default behavior, which is to consume the buffer as fast as possible.
703+
if (audioSinkDescription == "fakesink") {
704+
m_isFakeSink = true;
705+
g_object_set(m_pipeline.audioSink, "sync", true, NULL);
706+
}
707+
700708
GstCaps* caps = gst_caps_new_empty_simple("audio/x-raw");
701709
if (!caps) {
702710
ACSDK_ERROR(

0 commit comments

Comments
 (0)