diff options
author | Tim-Philipp Müller <tim@centricular.net> | 2006-05-15 15:18:50 +0000 |
---|---|---|
committer | Tim-Philipp Müller <tim@centricular.net> | 2006-05-15 15:18:50 +0000 |
commit | 07e9c41e1a0d9347f9f342bbf21b063378cf3f31 (patch) | |
tree | 93ac10ccf67d64615225ec3952a797ea6f31a5e9 | |
parent | f341ef39fafdd40641ee83e4c487651baf48bffe (diff) |
Update for 0.10. Turn into a super-simple command line player.
Original commit message from CVS:
* configure.ac:
* src/Makefile.am:
* src/gst-app.h:
* src/load.c:
* src/load.h:
* src/main.c: (handle_file_or_directory), (main):
* src/play.c: (play_uri):
* src/play.h:
Update for 0.10. Turn into a super-simple command line player.
m--------- | common | 0 | ||||
-rw-r--r-- | gst-app/ChangeLog | 12 | ||||
-rw-r--r-- | gst-app/configure.ac | 130 | ||||
-rw-r--r-- | gst-app/src/Makefile.am | 8 | ||||
-rw-r--r-- | gst-app/src/gst-app.h | 4 | ||||
-rw-r--r-- | gst-app/src/load.c | 78 | ||||
-rw-r--r-- | gst-app/src/main.c | 104 | ||||
-rw-r--r-- | gst-app/src/play.c | 181 | ||||
-rw-r--r-- | gst-app/src/play.h (renamed from gst-app/src/load.h) | 11 |
9 files changed, 388 insertions, 140 deletions
diff --git a/common b/common -Subproject a6710e67fd82147e32a18f1b63177583faffd49 +Subproject 3062df90281144cbdb55bd58ee9f0714ab346c2 diff --git a/gst-app/ChangeLog b/gst-app/ChangeLog index 4d50d6c..568cacf 100644 --- a/gst-app/ChangeLog +++ b/gst-app/ChangeLog @@ -1,3 +1,15 @@ +2006-05-15 Tim-Philipp Müller <tim at centricular dot net> + + * configure.ac: + * src/Makefile.am: + * src/gst-app.h: + * src/load.c: + * src/load.h: + * src/main.c: (handle_file_or_directory), (main): + * src/play.c: (play_uri): + * src/play.h: + Update for 0.10. Turn into a super-simple command line player. + 2004-04-03 Benjamin Otte <otte@gnome.org> * configure.ac: diff --git a/gst-app/configure.ac b/gst-app/configure.ac index 097dbdf..97844f7 100644 --- a/gst-app/configure.ac +++ b/gst-app/configure.ac @@ -28,45 +28,113 @@ fi dnl Now we're ready to ask for gstreamer libs and cflags dnl And we can also ask for the right version of gstreamer -GST_REQUIRED=0.6.0 - -dnl start with 0.6 -GST_MAJORMINOR=0.6 -PKG_CHECK_MODULES(GST, \ - gstreamer-$GST_MAJORMINOR >= $GST_REQUIRED \ - gstreamer-control-$GST_MAJORMINOR >= $GST_REQUIRED, - HAVE_GST=yes,HAVE_GST=no) - -dnl fail back to 0.8 -if test "x$HAVE_GST" = "xno"; then - GST_MAJORMINOR=0.8 - PKG_CHECK_MODULES(GST, \ - gstreamer-$GST_MAJORMINOR >= $GST_REQUIRED \ - gstreamer-control-$GST_MAJORMINOR >= $GST_REQUIRED, - HAVE_GST=yes,HAVE_GST=no) -fi +GST_MAJORMINOR=0.10 + +GSTCORE_REQUIRED=0.10.0 +GSTBASE_REQUIRED=0.10.0 + +dnl ======================================================================= +dnl We are checking for a lot of things from the GStreamer core that +dnl an app might possibly be interested in here. Your app might not need +dnl all of these, but it can't hurt to check for them either (and they +dnl should all be installed on development systems anyway) +dnl ======================================================================= + +PKG_CHECK_MODULES(GST, [ + gstreamer-$GST_MAJORMINOR >= $GSTCORE_REQUIRED + gstreamer-base-$GST_MAJORMINOR >= $GSTCORE_REQUIRED + gstreamer-controller-$GST_MAJORMINOR >= $GSTCORE_REQUIRED + ], [ + HAVE_GST=yes + ], [ + HAVE_GST=no + ]) -dnl Give error and exit if we don't have gstreamer -if test "x$HAVE_GST" = "xno"; then - AC_MSG_ERROR(you need gstreamer development packages installed !) +dnl ======================================================================= +dnl Give error and exit if couldn't find gstreamer development files +dnl ======================================================================= +if test "x$HAVE_GST" = "xno"; +then + AC_MSG_ERROR([ + Can't find the following GStreamer development packages: + + gstreamer-$GST_MAJORMINOR >= $GSTCORE_REQUIRED + gstreamer-base-$GST_MAJORMINOR >= $GSTCORE_REQUIRED + gstreamer-controller-$GST_MAJORMINOR >= $GSTCORE_REQUIRED + + Please make sure you have the necessary GStreamer-$GST_MAJORMINOR + development headers installed. + + On debian/Ubuntu systems you will probably need to install the + the 'libgstreamer$GST_MAJORMINOR-dev' package. + + On RPM-based systems you will probably need to install the + 'gstreamer-devel-$GST_MAJORMINOR' package. + ]) fi -dnl make GST_CFLAGS and GST_LIBS available +dnl ======================================================================= +dnl Make GST_CFLAGS and GST_LIBS available for use in Makefile.am files +dnl ======================================================================= + AC_SUBST(GST_CFLAGS) AC_SUBST(GST_LIBS) -dnl If we need them, we can also use the plugin libraries -PKG_CHECK_MODULES(GST_LIBS, gstreamer-libs-$GST_MAJORMINOR >= $GST_REQUIRED, - HAVE_GST_LIBS=yes, HAVE_GST_LIBS=no) -dnl Give a warning if we don't have gstreamer libs -if test "x$HAVE_GST_LIBS" = "xno"; then - AC_MSG_NOTICE(no GStreamer plugin libs found) + + + +dnl ======================================================================= +dnl OPTIONAL: +dnl Also check for extra stuff that is in gst-plugins-base, like additional +dnl tags for example. You might not need this. +dnl ======================================================================= + +PKG_CHECK_MODULES(GST_PLUGINS_BASE, [ + gstreamer-plugins-base-$GST_MAJORMINOR >= $GSTBASE_REQUIRED + ], [ + HAVE_GST_PLUGINS_BASE=yes + ], [ + HAVE_GST_PLUGINS_BASE=no + ]) + +dnl ======================================================================= +dnl Give a warning only if we don't find the gstreamer plugins base stuff +dnl ======================================================================= + +if test "x$HAVE_GST_PLUGINS_BASE" = "xno" +then + AC_MSG_NOTICE([ + Can't find the following GStreamer development packages: + + gstreamer-plugins-base-$GST_MAJORMINOR >= $GSTBASE_REQUIRED + + Please make sure you have the necessary GStreamer-$GST_MAJORMINOR + development headers installed. + + On debian/Ubuntu systems you will probably need to install the + the 'libgstreamer-plugins-base$GST_MAJORMINOR-dev' package. + + On RPM-based systems you will probably need to install the + 'gstreamer-plugins-base-devel-$GST_MAJORMINOR' package. + ]) + sleep 3 fi -dnl make GST_LIBS_CFLAGS and GST_LIBS_LIBS available -AC_SUBST(GST_LIBS_CFLAGS) -AC_SUBST(GST_LIBS_LIBS) +dnl ======================================================================= +dnl Make GST_CFLAGS and GST_LIBS available for use in Makefile.am files +dnl ======================================================================= + +AC_SUBST(GST_PLUGINS_BASE_CFLAGS) +AC_SUBST(GST_PLUGINS_BASE_LIBS) + + +dnl ======================================================================= +dnl Finally, create Makefiles in all directories +dnl ======================================================================= -AC_OUTPUT(Makefile src/Makefile) +AC_OUTPUT([ +Makefile +src/Makefile +]) diff --git a/gst-app/src/Makefile.am b/gst-app/src/Makefile.am index 8385fad..f5a4d6d 100644 --- a/gst-app/src/Makefile.am +++ b/gst-app/src/Makefile.am @@ -3,12 +3,12 @@ bin_PROGRAMS = gst-app # list of source files # the prefix is the name of the binary -gst_app_SOURCES = main.c load.c +gst_app_SOURCES = main.c play.c # list of headers we're not going to install -noinst_HEADERS = gst-app.h load.h +noinst_HEADERS = gst-app.h play.h # our CFLAGS and LDFLAGS used for compiling and linking # make sure you prefix these with the name of your binary -gst_app_CFLAGS = $(GST_CFLAGS) -gst_app_LDFLAGS = $(GST_LIBS) +gst_app_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) -Wall -g -O2 +gst_app_LDFLAGS = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) diff --git a/gst-app/src/gst-app.h b/gst-app/src/gst-app.h index e7cdfd4..3a11a63 100644 --- a/gst-app/src/gst-app.h +++ b/gst-app/src/gst-app.h @@ -1,7 +1,5 @@ /* Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> * - * load.h : load a pipeline from disk - * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -41,4 +39,4 @@ * Boston, MA 02111-1307, USA. */ -#include "load.h" +#include "play.h" diff --git a/gst-app/src/load.c b/gst-app/src/load.c deleted file mode 100644 index 0bbf99d..0000000 --- a/gst-app/src/load.c +++ /dev/null @@ -1,78 +0,0 @@ -/* Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> - * - * load.c : load a pipeline from disk - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER - * DEALINGS IN THE SOFTWARE. - * - * Alternatively, the contents of this file may be used under the - * GNU Lesser General Public License Version 2.1 (the "LGPL"), in - * which case the following provisions apply instead of the ones - * mentioned above: - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <gst/gst.h> - -/* - * load an xml pipeline description and parse it - * Returns: the top-level element, or NULL if unable to parse - */ - -GstElement * -gst_app_pipeline_load (const gchar *filename) -{ - GstXML *xml; - GList *l; - - xml = gst_xml_new (); - if (gst_xml_parse_file (xml, filename, NULL) != TRUE) - { - g_warning ("Error loading pipeline from file '%s'\n", filename); - return NULL; - } - - l = gst_xml_get_topelements (xml); - if (l == NULL) - { - g_warning ("No toplevel element in file '%s'\n", filename); - return NULL; - } - if (l->next != NULL) - { - g_warning ("More than one toplevel element in file '%s'\n", filename); - return NULL; - } - - return GST_ELEMENT (l->data); -} - diff --git a/gst-app/src/main.c b/gst-app/src/main.c index 92d4162..8970400 100644 --- a/gst-app/src/main.c +++ b/gst-app/src/main.c @@ -1,4 +1,4 @@ -/* Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> +/* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -39,32 +39,96 @@ * Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "gst-app.h" +static void +handle_file_or_directory (const gchar * filename) +{ + GError *err = NULL; + GDir *dir; + gchar *uri; + + if ((dir = g_dir_open (filename, 0, NULL))) { + const gchar *entry; + + while ((entry = g_dir_read_name (dir))) { + gchar *path; + + path = g_strconcat (filename, G_DIR_SEPARATOR_S, entry, NULL); + handle_file_or_directory (path); + g_free (path); + } + + g_dir_close (dir); + return; + } + + if (g_path_is_absolute (filename)) { + uri = g_filename_to_uri (filename, NULL, &err); + } else { + gchar *curdir, *absolute_path; + + curdir = g_get_current_dir (); + absolute_path = g_strconcat ( curdir, G_DIR_SEPARATOR_S, filename, NULL); + uri = g_filename_to_uri (absolute_path, NULL, &err); + g_free (absolute_path); + g_free (curdir); + } + + if (uri) { + /* great, we have a proper file:// URI, let's play it! */ + play_uri (uri); + } else { + g_warning ("Failed to convert filename '%s' to URI: %s", filename, + err->message); + g_error_free (err); + } + + g_free (uri); +} + int main (int argc, char *argv[]) { - gchar *filename; - GstElement *pipeline; - - gst_init (&argc, &argv); - - if (argc <= 1) - g_error ("Please supply an xml file describing a pipeline !\n"); - - filename = g_strdup_printf ("%s", argv[1]); - pipeline = gst_app_pipeline_load (filename); - if (pipeline == NULL) - { - g_warning ("Could not get a usable pipeline from file '%s'\n", filename); - return 1; + gchar **filenames = NULL; + const GOptionEntry entries[] = { + /* you can add your won command line options here */ + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &filenames, + "Special option that collects any remaining arguments for us" }, + { NULL, } + }; + GOptionContext *ctx; + GError *err = NULL; + gint i, num; + + ctx = g_option_context_new ("[FILE1] [FILE2] ..."); + g_option_context_add_group (ctx, gst_init_get_option_group ()); + g_option_context_add_main_entries (ctx, entries, NULL); + + if (!g_option_context_parse (ctx, &argc, &argv, &err)) { + g_print ("Error initializing: %s\n", GST_STR_NULL (err->message)); + return -1; + } + g_option_context_free (ctx); + + if (filenames == NULL || *filenames == NULL) { + g_print ("Please specify a file to play\n\n"); + return -1; + } + + + + num = g_strv_length (filenames); + + for (i = 0; i < num; ++i) { + handle_file_or_directory (filenames[i]); } - - gst_element_set_state (pipeline, GST_STATE_PLAYING); - while (gst_bin_iterate (GST_BIN (pipeline))) - g_print ("+"); - g_print ("\n"); + g_strfreev (filenames); return 0; } diff --git a/gst-app/src/play.c b/gst-app/src/play.c new file mode 100644 index 0000000..339ccab --- /dev/null +++ b/gst-app/src/play.c @@ -0,0 +1,181 @@ +/* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. + * + * Alternatively, the contents of this file may be used under the + * GNU Lesser General Public License Version 2.1 (the "LGPL"), in + * which case the following provisions apply instead of the ones + * mentioned above: + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the + * Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. + */ + +#include "play.h" + +void +play_uri (const gchar * uri) +{ + GstStateChangeReturn sret; + GstElement *playbin; + GstElement *audiosink; + GstElement *videosink; + GstMessage *msg = NULL; + GstBus *bus; + + g_print ("Trying to play %s ...\n", uri); + + playbin = gst_element_factory_make ("playbin", "playbin"); + if (playbin == NULL) + goto no_playbin; + + /* get playbin's bus - we'll watch it for messages */ + bus = gst_pipeline_get_bus (GST_PIPELINE (playbin)); + + /* set audio sink */ + audiosink = gst_element_factory_make ("autoaudiosink", "audiosink"); + if (audiosink == NULL) + goto no_autoaudiosink; + g_object_set (playbin, "audio-sink", audiosink, NULL); + + /* set video sink */ + videosink = gst_element_factory_make ("autovideosink", "videosink"); + if (videosink == NULL) + goto no_autovideosink; + g_object_set (playbin, "video-sink", videosink, NULL); + + /* set URI to play back */ + g_object_set (playbin, "uri", uri, NULL); + + /* and GO GO GO! */ + gst_element_set_state (GST_ELEMENT (playbin), GST_STATE_PLAYING); + + /* wait (blocks!) until state change either completes or fails */ + sret = gst_element_get_state (GST_ELEMENT (playbin), NULL, NULL, -1); + + switch (sret) { + case GST_STATE_CHANGE_FAILURE:{ + msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0); + goto got_error_message; + } + case GST_STATE_CHANGE_SUCCESS:{ + GstMessage *msg; + + g_print ("Playing ...\n"); + + while (1) { + GstFormat time_format; + gint64 dur, pos; + + time_format = GST_FORMAT_TIME; + if (gst_element_query_duration (playbin, &time_format, &dur) && + gst_element_query_position (playbin, &time_format, &pos)) { + g_print (" %" GST_TIME_FORMAT " / %" GST_TIME_FORMAT "\n", + GST_TIME_ARGS (pos), GST_TIME_ARGS (dur)); + } + + /* check if we finished or if there was an error, + * but don't wait/block if neither is the case */ + msg = gst_bus_poll (bus, GST_MESSAGE_EOS | GST_MESSAGE_ERROR, 0); + + if (msg && GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR) + goto got_error_message; + + if (msg && GST_MESSAGE_TYPE (msg) == GST_MESSAGE_EOS) { + g_print ("Finished.\n"); + break; + } + + /* sleep for one second */ + g_usleep (G_USEC_PER_SEC * 1); + } + break; + } + default: + g_assert_not_reached (); + } + + /* shut down and free everything */ + gst_element_set_state (playbin, GST_STATE_NULL); + gst_object_unref (playbin); + gst_object_unref (bus); + return; + +/* ERRORS */ +got_error_message: + { + if (msg) { + GError *err = NULL; + gchar *dbg_str = NULL; + + gst_message_parse_error (msg, &err, &dbg_str); + g_printerr ("FAILED to play %s: %s\n%s\n", uri, err->message, + (dbg_str) ? dbg_str : "(no debugging information)"); + g_error_free (err); + g_free (dbg_str); + gst_message_unref (msg); + } else { + g_printerr ("FAILED to play %s: unknown error\n", uri); + } + + /* shut down and free everything */ + gst_element_set_state (playbin, GST_STATE_NULL); + gst_object_unref (playbin); + gst_object_unref (bus); + return; + } + +no_playbin: + { + g_error ("Could not create GStreamer 'playbin' element. " + "Please install it"); + /* not reached, g_error aborts */ + return; + } + +no_autoaudiosink: + { + g_error ("Could not create GStreamer 'autoaudiosink' element. " + "Please install it"); + /* not reached, g_error aborts */ + return; + } + +no_autovideosink: + { + g_error ("Could not create GStreamer 'autovideosink' element. " + "Please install it"); + /* not reached, g_error aborts */ + return; + } +} + + diff --git a/gst-app/src/load.h b/gst-app/src/play.h index 811efd9..7b396f7 100644 --- a/gst-app/src/load.h +++ b/gst-app/src/play.h @@ -1,7 +1,5 @@ -/* Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org> +/* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net> * - * load.h : load a pipeline from disk - * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation @@ -41,7 +39,12 @@ * Boston, MA 02111-1307, USA. */ +#ifndef _MY_APP_PLAY_H_INCLUDED_ +#define _MY_APP_PLAY_H_INCLUDED_ + #include <gst/gst.h> -GstElement * gst_app_pipeline_load (const gchar *filename); +void play_uri (const gchar * uri); + +#endif /* _MY_APP_PLAY_H_INCLUDED_ */ |