core/audio: Build up the rest of the pipeline
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
9c6a9f7759
commit
76e400e156
53
core/audio.c
53
core/audio.c
|
@ -16,10 +16,13 @@ static int audio_pause_count = -1;
|
||||||
static GstElement *audio_player = NULL;
|
static GstElement *audio_player = NULL;
|
||||||
static guint audio_old_id = 0;
|
static guint audio_old_id = 0;
|
||||||
|
|
||||||
static GstElement *audio_pipeline = NULL;
|
static GstElement *audio_pipeline = NULL;
|
||||||
static GstElement *audio_source = NULL;
|
static GstElement *audio_source = NULL;
|
||||||
static GstElement *audio_decoder = NULL;
|
static GstElement *audio_decoder = NULL;
|
||||||
static guint audio_bus_id = 0;
|
static GstElement *audio_converter = NULL;
|
||||||
|
static GstElement *audio_volume = NULL;
|
||||||
|
static GstElement *audio_sink = NULL;
|
||||||
|
static guint audio_bus_id = 0;
|
||||||
|
|
||||||
static struct audio_callbacks *audio_cb = NULL;
|
static struct audio_callbacks *audio_cb = NULL;
|
||||||
|
|
||||||
|
@ -47,6 +50,7 @@ static void __audio_gst_load(struct track *track, GstState state)
|
||||||
gst_element_set_state(audio_player, GST_STATE_NULL);
|
gst_element_set_state(audio_player, GST_STATE_NULL);
|
||||||
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
|
g_object_set(G_OBJECT(audio_player), "uri", uri, NULL);
|
||||||
|
|
||||||
|
gst_element_set_state(audio_pipeline, GST_STATE_READY);
|
||||||
g_object_set(G_OBJECT(audio_source), "location", path, NULL);
|
g_object_set(G_OBJECT(audio_source), "location", path, NULL);
|
||||||
|
|
||||||
__audio_change_state(state);
|
__audio_change_state(state);
|
||||||
|
@ -87,6 +91,15 @@ static struct track *__audio_next(GstState state)
|
||||||
return __audio_load(playlist_next(), state);
|
return __audio_load(playlist_next(), state);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void __audio_pad_added(GstElement *element, GstPad *pad, gpointer data)
|
||||||
|
{
|
||||||
|
GstPad *sink = gst_element_get_static_pad(audio_decoder, "sink");
|
||||||
|
|
||||||
|
gst_element_link(element, audio_converter);
|
||||||
|
gst_pad_link(pad, sink);
|
||||||
|
gst_object_unref(sink);
|
||||||
|
}
|
||||||
|
|
||||||
static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data)
|
static gboolean __audio_message(GstBus *bus, GstMessage *message, gpointer data)
|
||||||
{
|
{
|
||||||
switch (GST_MESSAGE_TYPE(message)) {
|
switch (GST_MESSAGE_TYPE(message)) {
|
||||||
|
@ -133,14 +146,21 @@ void audio_init(int *argc, char ***argv, struct audio_callbacks *callbacks)
|
||||||
audio_old_id = gst_bus_add_watch(bus, __audio_message, NULL);
|
audio_old_id = gst_bus_add_watch(bus, __audio_message, NULL);
|
||||||
gst_object_unref(bus);
|
gst_object_unref(bus);
|
||||||
|
|
||||||
audio_pipeline = gst_pipeline_new("pipeline");
|
audio_pipeline = gst_pipeline_new("pipeline");
|
||||||
audio_source = gst_element_factory_make("filesrc", "source");
|
audio_source = gst_element_factory_make("filesrc", "source");
|
||||||
audio_decoder = gst_element_factory_make("decodebin", "decoder");
|
audio_decoder = gst_element_factory_make("decodebin", "decoder");
|
||||||
bus = gst_pipeline_get_bus(GST_PIPELINE(audio_pipeline));
|
audio_converter = gst_element_factory_make("audioconvert", "converter");
|
||||||
audio_bus_id = gst_bus_add_watch(bus, __audio_message, NULL);
|
audio_volume = gst_element_factory_make("volume", "volume");
|
||||||
|
audio_sink = gst_element_factory_make("autoaudiosink", "sink");
|
||||||
|
bus = gst_pipeline_get_bus(GST_PIPELINE(audio_pipeline));
|
||||||
|
audio_bus_id = gst_bus_add_watch(bus, __audio_message, NULL);
|
||||||
|
|
||||||
gst_bin_add_many(GST_BIN(audio_pipeline), audio_source, audio_decoder, NULL);
|
gst_bin_add_many(GST_BIN(audio_pipeline), audio_source, audio_decoder,
|
||||||
|
audio_converter, audio_volume,
|
||||||
|
audio_sink, NULL);
|
||||||
gst_element_link(audio_source, audio_decoder);
|
gst_element_link(audio_source, audio_decoder);
|
||||||
|
gst_element_link_many(audio_converter, audio_volume, audio_sink, NULL);
|
||||||
|
g_signal_connect(audio_decoder, "pad-added", G_CALLBACK(__audio_pad_added), NULL);
|
||||||
gst_object_unref(bus);
|
gst_object_unref(bus);
|
||||||
|
|
||||||
if (settings_has(SETTINGS_VOLUME))
|
if (settings_has(SETTINGS_VOLUME))
|
||||||
|
@ -160,11 +180,14 @@ void audio_deinit()
|
||||||
gst_object_unref(GST_ELEMENT(audio_pipeline));
|
gst_object_unref(GST_ELEMENT(audio_pipeline));
|
||||||
g_source_remove(audio_bus_id);
|
g_source_remove(audio_bus_id);
|
||||||
|
|
||||||
audio_player = NULL;
|
audio_player = NULL;
|
||||||
audio_pipeline = NULL;
|
audio_pipeline = NULL;
|
||||||
audio_source = NULL;
|
audio_source = NULL;
|
||||||
audio_decoder = NULL;
|
audio_decoder = NULL;
|
||||||
audio_track = NULL;
|
audio_converter = NULL;
|
||||||
|
audio_volume = NULL;
|
||||||
|
audio_sink = NULL;
|
||||||
|
audio_track = NULL;
|
||||||
|
|
||||||
gst_deinit();
|
gst_deinit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue