Commit 07e9c41e authored by Tim-Philipp Müller's avatar Tim-Philipp Müller 🐠

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.
parent f341ef39
common @ 3062df90
Subproject commit a6710e67fd82147e32a18f1b63177583faffd498
Subproject commit 3062df90281144cbdb55bd58ee9f0714ab346c23
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:
......
......@@ -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
])
......@@ -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)
/* 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"
/* 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;
}
/* Copyright 2005 Thomas Vander Stichele <thomas@apestaart.org>
/* Copyright (C) 2006 Tim-Philipp Müller <tim centricular net>
*
* 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
......@@ -41,38 +39,143 @@
* Boston, MA 02111-1307, USA.
*/
#include <gst/gst.h>
#include "play.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)
void
play_uri (const gchar * uri)
{
GstXML *xml;
GList *l;
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;
xml = gst_xml_new ();
if (gst_xml_parse_file (xml, filename, NULL) != TRUE)
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:
{
g_warning ("Error loading pipeline from file '%s'\n", filename);
return NULL;
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;
}
l = gst_xml_get_topelements (xml);
if (l == NULL)
no_playbin:
{
g_warning ("No toplevel element in file '%s'\n", filename);
return NULL;
g_error ("Could not create GStreamer 'playbin' element. "
"Please install it");
/* not reached, g_error aborts */
return;
}
if (l->next != NULL)
no_autoaudiosink:
{
g_warning ("More than one toplevel element in file '%s'\n", filename);
return NULL;
g_error ("Could not create GStreamer 'autoaudiosink' element. "
"Please install it");
/* not reached, g_error aborts */
return;
}
return GST_ELEMENT (l->data);
no_autovideosink:
{
g_error ("Could not create GStreamer 'autovideosink' element. "
"Please install it");
/* not reached, g_error aborts */
return;
}
}
/* 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_ */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment