From: Christian Pointner Date: Thu, 30 Jun 2011 23:23:04 +0000 (+0000) Subject: some cleanup X-Git-Url: https://git.realraum.at/?a=commitdiff_plain;h=b3b721868a13086c8aa53e3aad708921e952d14a;p=svn42.git some cleanup --- diff --git a/dart-sounds/src/dart-sounds.c b/dart-sounds/src/dart-sounds.c index 1ec692c..075ca75 100644 --- a/dart-sounds/src/dart-sounds.c +++ b/dart-sounds/src/dart-sounds.c @@ -24,28 +24,28 @@ #include #include -static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data) +static gboolean bus_call(GstBus *bus, GstMessage *msg, gpointer data) { GMainLoop *loop = (GMainLoop *) data; - switch (GST_MESSAGE_TYPE (msg)) + switch(GST_MESSAGE_TYPE(msg)) { case GST_MESSAGE_EOS: - g_print ("End of stream\n"); - g_main_loop_quit (loop); + g_print("End of stream\n"); + g_main_loop_quit(loop); break; case GST_MESSAGE_ERROR: { gchar *debug; GError *error; - gst_message_parse_error (msg, &error, &debug); - g_free (debug); + gst_message_parse_error(msg, &error, &debug); + g_free(debug); - g_printerr ("Error: %s\n", error->message); - g_error_free (error); + g_printerr("Error: %s\n", error->message); + g_error_free(error); - g_main_loop_quit (loop); + g_main_loop_quit(loop); break; } default: @@ -55,71 +55,66 @@ static gboolean bus_call (GstBus *bus, GstMessage *msg, gpointer data) return TRUE; } -static void on_pad_added (GstElement *element, GstPad *pad, gpointer data) +static void on_pad_added(GstElement *element, GstPad *pad, gpointer data) { GstPad *sinkpad; GstElement *decoder = (GstElement *) data; - g_print ("Dynamic pad created, linking demuxer/decoder\n"); - - sinkpad = gst_element_get_static_pad (decoder, "sink"); - gst_pad_link (pad, sinkpad); - gst_object_unref (sinkpad); + sinkpad = gst_element_get_static_pad(decoder, "sink"); + gst_pad_link(pad, sinkpad); + gst_object_unref(sinkpad); } -int main (int argc, char *argv[]) +GstElement* init(GMainLoop *loop, int pipe_out) { - GMainLoop *loop; + GstElement *pipeline = gst_pipeline_new("dart-sounds"); + GstElement *source = gst_element_factory_make("filesrc", "source"); + GstElement *demuxer = gst_element_factory_make("oggdemux", "demuxer"); + GstElement *decoder = gst_element_factory_make("vorbisdec", "decoder"); + GstElement *conv = gst_element_factory_make("audioconvert", "converter"); + GstElement *sink = gst_element_factory_make("autoaudiosink", "sink"); - GstElement *pipeline, *source, *demuxer, *decoder, *conv, *sink; - GstBus *bus; + if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) { + g_printerr ("One element could not be created. Exiting.\n"); + return NULL; + } - gst_init (&argc, &argv); + g_object_set(G_OBJECT(source), "location", "../media/bull.ogg", NULL); - loop = g_main_loop_new (NULL, FALSE); + GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline)); + gst_bus_add_watch(bus, bus_call, loop); + gst_object_unref(bus); - /* Check input arguments */ - if (argc != 2) { - g_printerr ("Usage: %s \n", argv[0]); - return -1; - } + gst_bin_add_many(GST_BIN(pipeline), source, demuxer, decoder, conv, sink, NULL); - pipeline = gst_pipeline_new ("audio-player"); - source = gst_element_factory_make ("filesrc", "file-source"); - demuxer = gst_element_factory_make ("oggdemux", "ogg-demuxer"); - decoder = gst_element_factory_make ("vorbisdec", "vorbis-decoder"); - conv = gst_element_factory_make ("audioconvert", "converter"); - sink = gst_element_factory_make ("autoaudiosink", "audio-output"); + gst_element_link(source, demuxer); + gst_element_link_many(decoder, conv, sink, NULL); + g_signal_connect(demuxer, "pad-added", G_CALLBACK(on_pad_added), decoder); - if (!pipeline || !source || !demuxer || !decoder || !conv || !sink) { - g_printerr ("One element could not be created. Exiting.\n"); - return -1; - } + gst_element_set_state(pipeline, GST_STATE_PLAYING); - g_object_set (G_OBJECT (source), "location", argv[1], NULL); + return pipeline; +} - bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); - gst_bus_add_watch (bus, bus_call, loop); - gst_object_unref (bus); +int main(int argc, char *argv[]) +{ + gst_init(&argc, &argv); - gst_bin_add_many (GST_BIN (pipeline), - source, demuxer, decoder, conv, sink, NULL); + GMainLoop *loop = g_main_loop_new(NULL, FALSE); - gst_element_link (source, demuxer); - gst_element_link_many (decoder, conv, sink, NULL); - g_signal_connect (demuxer, "pad-added", G_CALLBACK (on_pad_added), decoder); + GstElement *pipeline = init(loop, 0); + if(!pipeline) return 1; - g_print ("Now playing: %s\n", argv[1]); - gst_element_set_state (pipeline, GST_STATE_PLAYING); + GMainContext *ctx = g_main_loop_get_context(loop); - g_print ("Running...\n"); - g_main_loop_run (loop); + g_print("Running...\n"); + g_main_loop_run(loop); - g_print ("Returned, stopping playback\n"); - gst_element_set_state (pipeline, GST_STATE_NULL); + g_print("finished, stopping playback\n"); + gst_element_set_state(pipeline, GST_STATE_NULL); - g_print ("Deleting pipeline\n"); - gst_object_unref (GST_OBJECT (pipeline)); + g_print("Deleting pipeline\n"); + gst_object_unref(GST_OBJECT (pipeline)); return 0; }