added simple audio file play utility
This commit is contained in:
parent
d178e61d8d
commit
562b2ee49f
3 changed files with 201 additions and 1 deletions
64
livesupport/modules/gstreamerElements/bin/play.sh
Executable file
64
livesupport/modules/gstreamerElements/bin/play.sh
Executable file
|
@ -0,0 +1,64 @@
|
||||||
|
#!/bin/sh
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
#
|
||||||
|
# This file is part of the LiveSupport project.
|
||||||
|
# http://livesupport.campware.org/
|
||||||
|
# To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
#
|
||||||
|
# LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# LiveSupport 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 General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with LiveSupport; if not, write to the Free Software
|
||||||
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Author : $Author: maroy $
|
||||||
|
# Version : $Revision: 1.1 $
|
||||||
|
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/bin/play.sh,v $
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
# Play an audio file by using gstreamer and autoplugging.
|
||||||
|
#-------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# assume we're in $basedir/bin
|
||||||
|
reldir=`dirname $0`/..
|
||||||
|
basedir=`cd $reldir; pwd;`
|
||||||
|
test -z "$basedir" && basedir=.
|
||||||
|
usrdir=`cd $basedir/../../usr; pwd;`
|
||||||
|
|
||||||
|
bindir=$basedir/bin
|
||||||
|
etcdir=$basedir/etc
|
||||||
|
libdir=$basedir/lib
|
||||||
|
tmpdir=$basedir/tmp
|
||||||
|
|
||||||
|
play=$tmpdir/play
|
||||||
|
|
||||||
|
|
||||||
|
export CPPFLAGS="-I$usrdir/include"
|
||||||
|
export LDFLAGS="-L$usrdir/lib"
|
||||||
|
export PKG_CONFIG_PATH="$usrdir/lib/pkgconfig"
|
||||||
|
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$usrdir/lib"
|
||||||
|
export GST_PLUGIN_PATH="$libdir"
|
||||||
|
|
||||||
|
|
||||||
|
if [ ! -f $play ]; then
|
||||||
|
echo "first build the play executable by issuing the following command:";
|
||||||
|
echo "";
|
||||||
|
echo "make all";
|
||||||
|
|
||||||
|
exit -1;
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
$play "$*"
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Author : $Author: maroy $
|
# Author : $Author: maroy $
|
||||||
# Version : $Revision: 1.7 $
|
# Version : $Revision: 1.8 $
|
||||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/etc/Makefile.in,v $
|
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/etc/Makefile.in,v $
|
||||||
#
|
#
|
||||||
# @configure_input@
|
# @configure_input@
|
||||||
|
@ -92,6 +92,7 @@ SWITCHER_LIB = livesupport_switcher
|
||||||
SWITCHER_LIB_FILE = ${LIB_DIR}/lib${SWITCHER_LIB}.so
|
SWITCHER_LIB_FILE = ${LIB_DIR}/lib${SWITCHER_LIB}.so
|
||||||
|
|
||||||
TEST_RUNNER = ${TMP_DIR}/testRunner
|
TEST_RUNNER = ${TMP_DIR}/testRunner
|
||||||
|
PLAY = ${TMP_DIR}/play
|
||||||
|
|
||||||
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
|
||||||
|
|
||||||
|
@ -154,6 +155,10 @@ TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
|
||||||
TEST_RUNNER_LIBS = -l${GSTREAMER_ELEMENTS_LIB} -l${CORE_LIB} \
|
TEST_RUNNER_LIBS = -l${GSTREAMER_ELEMENTS_LIB} -l${CORE_LIB} \
|
||||||
-lcppunit -ldl -lxmlrpc++
|
-lcppunit -ldl -lxmlrpc++
|
||||||
|
|
||||||
|
PLAY_OBJS = ${TMP_DIR}/play.o
|
||||||
|
|
||||||
|
PLAY_LIBS = -l${GSTREAMER_ELEMENTS_LIB} -l${CORE_LIB}
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------
|
||||||
# Targets
|
# Targets
|
||||||
|
@ -165,6 +170,7 @@ all: dir_setup ${GSTREAMER_ELEMENTS_LIB_FILE} \
|
||||||
${MINIMAL_AUDIO_SMIL_LIB_FILE} \
|
${MINIMAL_AUDIO_SMIL_LIB_FILE} \
|
||||||
${PARTIAL_PLAY_LIB_FILE} \
|
${PARTIAL_PLAY_LIB_FILE} \
|
||||||
${SWITCHER_LIB_FILE} \
|
${SWITCHER_LIB_FILE} \
|
||||||
|
${PLAY} \
|
||||||
gst_register
|
gst_register
|
||||||
|
|
||||||
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
|
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
|
||||||
|
@ -183,6 +189,7 @@ clean:
|
||||||
${RM} ${PARTIAL_PLAY_LIB_OBJS} ${PARTIAL_PLAY_LIB_FILE}
|
${RM} ${PARTIAL_PLAY_LIB_OBJS} ${PARTIAL_PLAY_LIB_FILE}
|
||||||
${RM} ${SWITCHER_LIB_OBJS} ${SWITCHER_LIB_FILE}
|
${RM} ${SWITCHER_LIB_OBJS} ${SWITCHER_LIB_FILE}
|
||||||
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER_RES} ${TEST_RUNNER}
|
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER_RES} ${TEST_RUNNER}
|
||||||
|
${RM} ${PLAY_OBJS} ${PLAY}
|
||||||
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
|
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
|
||||||
|
|
||||||
docclean:
|
docclean:
|
||||||
|
@ -231,6 +238,9 @@ ${TEST_RUNNER}: ${CORE_LIB_FILE} ${GSTREAMER_ELEMENTS_LIB_FILE} \
|
||||||
${TEST_RUNNER_OBJS}
|
${TEST_RUNNER_OBJS}
|
||||||
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
|
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
|
||||||
|
|
||||||
|
${PLAY}: ${CORE_LIB_FILE} ${GSTREAMER_ELEMENTS_LIB_FILE} ${PLAY_OBJS}
|
||||||
|
${CXX} ${LDFLAGS} -o $@ ${PLAY_OBJS} ${PLAY_LIBS}
|
||||||
|
|
||||||
${CORE_LIB_FILE}:
|
${CORE_LIB_FILE}:
|
||||||
${MAKE} -C ${CORE_DIR}
|
${MAKE} -C ${CORE_DIR}
|
||||||
|
|
||||||
|
|
126
livesupport/modules/gstreamerElements/src/play.c
Normal file
126
livesupport/modules/gstreamerElements/src/play.c
Normal file
|
@ -0,0 +1,126 @@
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
Copyright (c) 2004 Media Development Loan Fund
|
||||||
|
|
||||||
|
This file is part of the LiveSupport project.
|
||||||
|
http://livesupport.campware.org/
|
||||||
|
To report bugs, send an e-mail to bugs@campware.org
|
||||||
|
|
||||||
|
LiveSupport is free software; you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation; either version 2 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
LiveSupport 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 General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with LiveSupport; if not, write to the Free Software
|
||||||
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
|
|
||||||
|
|
||||||
|
Author : $Author: maroy $
|
||||||
|
Version : $Revision: 1.1 $
|
||||||
|
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/src/play.c,v $
|
||||||
|
|
||||||
|
------------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
/* ============================================================ include files */
|
||||||
|
|
||||||
|
#ifdef HAVE_CONFIG_H
|
||||||
|
#include "configure.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <gst/gst.h>
|
||||||
|
|
||||||
|
#include "LiveSupport/GstreamerElements/autoplug.h"
|
||||||
|
|
||||||
|
|
||||||
|
/* =================================================== local data structures */
|
||||||
|
|
||||||
|
|
||||||
|
/* ================================================ local constants & macros */
|
||||||
|
|
||||||
|
|
||||||
|
/* =============================================== local function prototypes */
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Program entry point.
|
||||||
|
*
|
||||||
|
* @param argc the number of command line arguments.
|
||||||
|
* @param argv the command line argument array.
|
||||||
|
* @return 0 on success, non-0 on failure.
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
main(int argc,
|
||||||
|
char ** argv);
|
||||||
|
|
||||||
|
|
||||||
|
/* ============================================================= module code */
|
||||||
|
|
||||||
|
/*------------------------------------------------------------------------------
|
||||||
|
* Program entry point.
|
||||||
|
*----------------------------------------------------------------------------*/
|
||||||
|
int
|
||||||
|
main(int argc,
|
||||||
|
char ** argv)
|
||||||
|
{
|
||||||
|
GstElement * pipeline;
|
||||||
|
GstElement * source;
|
||||||
|
GstElement * decoder;
|
||||||
|
GstElement * sink;
|
||||||
|
GstFormat format;
|
||||||
|
gint64 timePlayed;
|
||||||
|
|
||||||
|
/* initialize GStreamer */
|
||||||
|
gst_init(&argc, &argv);
|
||||||
|
|
||||||
|
if (argc != 2) {
|
||||||
|
g_print("Usage: %s <audio filename>\n", argv[0]);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* create elements */
|
||||||
|
pipeline = gst_pipeline_new("audio-player");
|
||||||
|
source = gst_element_factory_make("filesrc", "source");
|
||||||
|
sink = gst_element_factory_make("alsasink", "alsa-output");
|
||||||
|
|
||||||
|
g_object_set(G_OBJECT(source), "location", argv[1], NULL);
|
||||||
|
|
||||||
|
decoder = ls_gst_autoplug_plug_source(source, "decoder");
|
||||||
|
|
||||||
|
if (!decoder) {
|
||||||
|
gst_object_unref(GST_OBJECT(sink));
|
||||||
|
gst_object_unref(GST_OBJECT(source));
|
||||||
|
gst_object_unref(GST_OBJECT(pipeline));
|
||||||
|
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
gst_element_link(decoder, sink);
|
||||||
|
gst_bin_add_many(GST_BIN(pipeline), source, decoder, sink, NULL);
|
||||||
|
|
||||||
|
gst_element_set_state(source, GST_STATE_PAUSED);
|
||||||
|
gst_element_set_state(decoder, GST_STATE_PAUSED);
|
||||||
|
gst_element_set_state(sink, GST_STATE_PAUSED);
|
||||||
|
gst_element_set_state(pipeline, GST_STATE_PLAYING);
|
||||||
|
|
||||||
|
// iterate until playTo is reached
|
||||||
|
while (gst_bin_iterate(GST_BIN(pipeline)));
|
||||||
|
|
||||||
|
/* FIXME: query the decoder, as for some reason, the sink will return
|
||||||
|
* unreal numbers, when playing back mp3s only! */
|
||||||
|
format = GST_FORMAT_TIME;
|
||||||
|
gst_element_query(decoder, GST_QUERY_POSITION, &format, &timePlayed);
|
||||||
|
|
||||||
|
g_print("time played: %" G_GINT64_FORMAT " ns\n", timePlayed);
|
||||||
|
|
||||||
|
/* clean up nicely */
|
||||||
|
gst_element_set_state(pipeline, GST_STATE_NULL);
|
||||||
|
gst_object_unref(GST_OBJECT(pipeline));
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue