From 476cdb3904e3d3b91a46b876f6aff4ac76f4ece3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Fri, 26 Jan 2007 18:24:56 +0000 Subject: [PATCH] docs/pwg/building-testapp.xml: Add some audioconverts and audioresample to the pipeline, and some more comments and e... Original commit message from CVS: * docs/pwg/building-testapp.xml: Add some audioconverts and audioresample to the pipeline, and some more comments and error handling. --- ChangeLog | 6 +++ docs/pwg/building-testapp.xml | 76 +++++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index be5831cf35..4cbf91eab5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-01-26 Tim-Philipp Müller + + * docs/pwg/building-testapp.xml: + Add some audioconverts and audioresample to the pipeline, and some + more comments and error handling. + 2007-01-26 Tim-Philipp Müller * docs/manual/manual.xml: diff --git a/docs/pwg/building-testapp.xml b/docs/pwg/building-testapp.xml index 528bbbd662..cdc3947f10 100644 --- a/docs/pwg/building-testapp.xml +++ b/docs/pwg/building-testapp.xml @@ -79,15 +79,19 @@ bus_call (GstBus *bus, g_main_loop_quit (loop); break; case GST_MESSAGE_ERROR: { - gchar *debug; - GError *err; + gchar *debug = NULL; + GError *err = NULL; gst_message_parse_error (msg, &err, &debug); - g_free (debug); g_print ("Error: %s\n", err->message); g_error_free (err); + if (debug) { + g_print ("Debug deails: %s\n", debug); + g_free (debug); + } + g_main_loop_quit (loop); break; } @@ -102,8 +106,11 @@ gint main (gint argc, gchar *argv[]) { + GstStateChangeReturn ret; GstElement *pipeline, *filesrc, *decoder, *filter, *sink; + GstElement *convert1, *convert2, *resample; GMainLoop *loop; + GstBus *bus; /* initialization */ gst_init (&argc, &argv); @@ -115,37 +122,82 @@ main (gint argc, /* create elements */ pipeline = gst_pipeline_new ("my_pipeline"); - gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)), - bus_call, loop); + + /* watch for messages on the pipeline's bus (note that this will only + * work like this when a GLib main loop is running) */ + bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline)); + gst_bus_add_watch (bus, bus_call, loop); + gst_object_unref (bus); filesrc = gst_element_factory_make ("filesrc", "my_filesource"); decoder = gst_element_factory_make ("mad", "my_decoder"); + + /* putting an audioconvert element here to convert the output of the + * decoder into a format that my_filter can handle (we are assuming it + * will handle any sample rate here though) */ + convert1 = gst_element_factory_make ("audioconvert", "audioconvert1"); + + /* use "identity" here for a filter that does nothing */ filter = gst_element_factory_make ("my_filter", "my_filter"); + + /* there should always be audioconvert and audioresample elements before + * the audio sink, since the capabilities of the audio sink usually vary + * depending on the environment (output used, sound card, driver etc.) */ + convert2 = gst_element_factory_make ("audioconvert", "audioconvert2"); + resample = gst_element_factory_make ("audioresample", "audioresample"); sink = gst_element_factory_make ("osssink", "audiosink"); + if (!sink || !decoder) { g_print ("Decoder or output could not be found - check your install\n"); return -1; + } else if (!convert1 || !convert2 || !resample) { + g_print ("Could not create audioconvert or audioresample element, " + "check your installation\n"); + return -1; } else if (!filter) { g_print ("Your self-written filter could not be found. Make sure it " - "is installed correctly in $(libdir)/gstreamer-0.9/ and that " - "you've ran gst-register-0.9 to register it. Check availability " - "of the plugin afterwards using \"gst-inspect-0.9 my_filter\""); + "is installed correctly in $(libdir)/gstreamer-0.10/ or " + "~/.gstreamer-0.10/plugins/ and that gst-inspect-0.10 lists it. " + "If it doesn't, check with 'GST_DEBUG=*:2 gst-inspect-0.10' for " + "the reason why it is not being loaded."); return -1; } g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL); + gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, convert1, filter, + convert2, resample, sink, NULL); + /* link everything together */ - gst_element_link_many (filesrc, decoder, filter, sink, NULL); - gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, filter, sink, NULL); + if (!gst_element_link_many (filesrc, decoder, convert1, filter, convert2, + resample, sink, NULL)) { + g_print ("Failed to link one or more elements!\n"); + return -1; + } /* run */ - gst_element_set_state (pipeline, GST_STATE_PLAYING); + ret = gst_element_set_state (pipeline, GST_STATE_PLAYING); + if (ret == GST_STATE_CHANGE_FAILURE) { + g_print ("Failed to start up pipeline!\n"); + + /* check if there is an error message with details on the bus */ + msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); + if (msg) { + GError *err = NULL; + + gst_message_parse_error (msg, &err, NULL); + g_print ("ERROR: %s\n", err->message); + g_error_free (err); + gst_message_unref (msg); + } + return -1; + } + g_main_loop_run (loop); /* clean up */ gst_element_set_state (pipeline, GST_STATE_NULL); - gst_object_unref (GST_OBJECT (pipeline)); + gst_object_unref (pipeline); return 0; }