initial version of our gstreamer elements

This commit is contained in:
maroy 2005-06-17 19:45:06 +00:00
parent 44a7024af4
commit 73a30b108b
33 changed files with 6543 additions and 0 deletions

View file

@ -0,0 +1,94 @@
#!/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/autogen.sh,v $
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# Run this to set up the build system: configure, makefiles, etc.
# (based on the version in enlightenment's cvs)
#-------------------------------------------------------------------------------
package="GstreamerElements"
# 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
tmpdir=$basedir/tmp
cd "$tmpdir"
DIE=0
(autoheader --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
(autoconf --version) < /dev/null > /dev/null 2>&1 || {
echo
echo "You must have autoconf installed to compile $package."
echo "Download the appropriate package for your distribution,"
echo "or get the source tarball at ftp://ftp.gnu.org/pub/gnu/"
DIE=1
}
if test "$DIE" -eq 1; then
exit 1
fi
if test -z "$*"; then
echo "I am going to run ./configure with no arguments - if you wish "
echo "to pass any to it, please specify them on the $0 command line."
fi
echo "Generating configuration files for $package, please wait...."
configure_ac=${etcdir}/configure.ac
configure=${tmpdir}/configure
aclocal_m4=${tmpdir}/aclocal.m4
# run aclocal in etc, as it's blind, only sees files in the current directory
ACLOCAL_FLAGS="--output=${aclocal_m4}"
echo " aclocal $ACLOCAL_FLAGS"
cd ${etcdir} && aclocal $ACLOCAL_FLAGS ; cd ${tmpdir}
echo " autoheader ${configure_ac}"
autoheader ${configure_ac}
echo " autoconf -I ${tmpdir} -o ${configure} ${configure_ac}"
autoconf -I ${tmpdir} -o ${configure} ${configure_ac}
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"
${configure} "$@" && echo

View file

@ -0,0 +1,80 @@
#!/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/gen_coverage_data.sh,v $
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# This script generates code coverage data for the module
#-------------------------------------------------------------------------------
module="LiveSupport GstreamerElements"
reldir=`dirname $0`/..
basedir=`cd $reldir; pwd;`
bindir=$basedir/bin
docdir=$basedir/doc
tmpdir=$basedir/tmp
usrdir=`cd $basedir/../../usr; pwd;`
coverage_report_dir=$docdir/coverage
raw_coverage_file=$tmpdir/raw_coverage.info
coverage_file=$tmpdir/coverage.info
lcov=$usrdir/bin/lcov
genhtml=$usrdir/bin/genhtml
cd $basedir
#-------------------------------------------------------------------------------
# Re-configure with covarege collection enabled, compile and run the tests
#-------------------------------------------------------------------------------
$bindir/autogen.sh --enable-coverage
make clean
make check
#-------------------------------------------------------------------------------
# Generate some symlinks so that the sources are visible from tmpdir
#-------------------------------------------------------------------------------
ln -s $basedir/include $tmpdir/include
ln -s $basedir/src $tmpdir/src
#-------------------------------------------------------------------------------
# Use lcov to generate an HTML report on the coverage data
#-------------------------------------------------------------------------------
$lcov -d $tmpdir -c > $raw_coverage_file
$lcov -e $raw_coverage_file "$tmpdir/*" > $coverage_file
rm -rf $coverage_report_dir
mkdir -p $coverage_report_dir
$genhtml -t "$module" -o $coverage_report_dir $coverage_file
#-------------------------------------------------------------------------------
# Clean up
#-------------------------------------------------------------------------------
rm -f $tmpdir/include
rm -f $tmpdir/src

View file

@ -0,0 +1 @@
keep me

View file

@ -0,0 +1,224 @@
#-------------------------------------------------------------------------------
# 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/etc/Makefile.in,v $
#
# @configure_input@
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
# General command definitions
#-------------------------------------------------------------------------------
MKDIR = mkdir -p
RM = rm -f
RMDIR = rm -rf
DOXYGEN = doxygen
#-------------------------------------------------------------------------------
# Basic directory and file definitions
#-------------------------------------------------------------------------------
PACKAGE_NAME = @PACKAGE_NAME@
BASE_DIR = @builddir@
DOC_DIR = ${BASE_DIR}/doc
DOXYGEN_DIR = ${DOC_DIR}/doxygen
COVERAGE_DIR = ${DOC_DIR}/coverage
ETC_DIR = ${BASE_DIR}/etc
INCLUDE_DIR = ${BASE_DIR}/include
LIB_DIR = ${BASE_DIR}/lib
SRC_DIR = ${BASE_DIR}/src
TMP_DIR = ${BASE_DIR}/tmp
VAR_DIR = ${BASE_DIR}/var
USR_DIR = ${BASE_DIR}/../../usr
USR_INCLUDE_DIR = ${USR_DIR}/include
USR_BIN_DIR = ${USR_DIR}/bin
USR_LIB_DIR = ${USR_DIR}/lib
BOOST_INCLUDE_DIR = ${USR_INCLUDE_DIR}/boost-1_31
MODULES_DIR = ${BASE_DIR}/..
CORE_DIR = ${MODULES_DIR}/core
CORE_INCLUDE_DIR = ${CORE_DIR}/include
CORE_LIB_DIR = ${CORE_DIR}/lib
CORE_LIB = livesupport_core
CORE_LIB_FILE = ${CORE_LIB_DIR}/lib${CORE_LIB}.a
VPATH = ${SRC_DIR}
GSTREAMER_CFLAGS=@GSTREAMER_CFLAGS@
GSTREAMER_LIBS=@GSTREAMER_LIBS@
GST_REGISTER=${USR_BIN_DIR}/gst-register
TEST_RESULTS = ${DOC_DIR}/testResults.xml
# the text result XSLT has to be relative to the test result file, e.g. TMP_DIR
TEST_XSLT = ../etc/testResultToHtml.xsl
ONESHOT_READER_LIB = livesupport_oneshotreader
ONESHOT_READER_LIB_FILE = ${LIB_DIR}/lib${ONESHOT_READER_LIB}.so
MINIMAL_AUDIO_SMIL_LIB = livesupport_minimalaudiosmil
MINIMAL_AUDIO_SMIL_LIB_FILE = ${LIB_DIR}/lib${MINIMAL_AUDIO_SMIL_LIB}.so
PARTIAL_PLAY_LIB = livesupport_partialplay
PARTIAL_PLAY_LIB_FILE = ${LIB_DIR}/lib${PARTIAL_PLAY_LIB}.so
SWITCHER_LIB = livesupport_switcher
SWITCHER_LIB_FILE = ${LIB_DIR}/lib${SWITCHER_LIB}.so
TEST_RUNNER = ${TMP_DIR}/testRunner
DOXYGEN_CONFIG = ${ETC_DIR}/doxygen.config
export LD_LIBRARY_PATH:=${LD_LIBRARY_PATH}:${USR_LIB_DIR}
export GST_PLUGIN_PATH=${LIB_DIR}
#-------------------------------------------------------------------------------
# Configuration parameters
#-------------------------------------------------------------------------------
CPPFLAGS = @CPPFLAGS@
CFLAGS = @CFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ -pthread \
-pedantic -Wall -std=c99 -Wno-long-long \
-fPIC -DPIC \
${GSTREAMER_CFLAGS} \
-I${USR_INCLUDE_DIR} \
-I${INCLUDE_DIR} -I${TMP_DIR}
CXXFLAGS = @CXXFLAGS@ @DEFS@ @COVERAGE_CXXFLAGS@ -pthread \
-Wall -Wno-long-long \
${GSTREAMER_CFLAGS} \
-I${USR_INCLUDE_DIR} \
-I${BOOST_INCLUDE_DIR} \
-I${CORE_INCLUDE_DIR} \
-I${INCLUDE_DIR} -I${TMP_DIR}
GST_LDFLAGS = @LDFLAGS@ ${GSTREAMER_LIBS} \
-L${USR_LIB_DIR} \
-L${LIB_DIR}
LDFLAGS = @LDFLAGS@ ${GSTREAMER_LIBS} \
-L${USR_LIB_DIR} \
-L${CORE_LIB_DIR} \
-L${LIB_DIR}
#-------------------------------------------------------------------------------
# Dependencies
#-------------------------------------------------------------------------------
ONESHOT_READER_LIB_OBJS = ${TMP_DIR}/oneshot-reader.o
MINIMAL_AUDIO_SMIL_LIB_OBJS = ${TMP_DIR}/seek.o \
${TMP_DIR}/seek-pack.o\
${TMP_DIR}/minimal-audio-smil.o
PARTIAL_PLAY_LIB_OBJS = ${TMP_DIR}/seek.o \
${TMP_DIR}/seek-pack.o \
${TMP_DIR}/smil-util.o \
${TMP_DIR}/partial-play.o
SWITCHER_LIB_OBJS = ${TMP_DIR}/smil-util.o \
${TMP_DIR}/switcher.o
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/PartialPlayTest.o \
${TMP_DIR}/OneshotReaderTest.o \
${TMP_DIR}/MinimalAudioSmilTest.o
TEST_RUNNER_LIBS = -l${CORE_LIB} -lcppunit -ldl -lxmlrpc++
#-------------------------------------------------------------------------------
# Targets
#-------------------------------------------------------------------------------
.PHONY: all dir_setup doc clean docclean depclean distclean
all: dir_setup ${ONESHOT_READER_LIB_FILE} \
${MINIMAL_AUDIO_SMIL_LIB_FILE} \
${PARTIAL_PLAY_LIB_FILE} \
${SWITCHER_LIB_FILE} \
gst_register
dir_setup: ${TMP_DIR} ${DOXYGEN_DIR}
gst_register:
${GST_REGISTER} > /dev/null 2>&1
doc:
${DOXYGEN} ${DOXYGEN_CONFIG}
clean:
${RM} ${ONESHOT_READER_LIB_OBJS} ${ONESHOT_READER_LIB_FILE}
${RM} ${MINIMAL_AUDIO_SMIL_LIB_OBJS} ${MINIMAL_AUDIO_SMIL_LIB_FILE}
${RM} ${PARTIAL_PLAY_LIB_OBJS} ${PARTIAL_PLAY_LIB_FILE}
${RM} ${SWITCHER_LIB_OBJS} ${SWITCHER_LIB_FILE}
${RM} ${TEST_RUNNER_OBJS} ${TEST_RUNNER_RES} ${TEST_RUNNER}
${RM} ${TMP_DIR}/*.bb ${TMP_DIR}/*.bbg ${TMP_DIR}/*.da ${TMP_DIR}/*.info
docclean:
${RMDIR} ${DOXYGEN_DIR}/html
${RMDIR} ${COVERAGE_DIR}/*
${RM} ${TEST_RESULTS}
depclean: clean
distclean: clean docclean
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
check: all ${TEST_RUNNER}
${TEST_RUNNER} -o ${TEST_RESULTS} -s ${TEST_XSLT}
#-------------------------------------------------------------------------------
# Specific targets
#-------------------------------------------------------------------------------
${ONESHOT_READER_LIB_FILE}: ${ONESHOT_READER_LIB_OBJS}
${CC} -shared -o $@ $^ ${GST_LDFLAGS}
${MINIMAL_AUDIO_SMIL_LIB_FILE}: ${MINIMAL_AUDIO_SMIL_LIB_OBJS}
${CC} -shared ${GST_LDFLAGS} -o $@ $^
${PARTIAL_PLAY_LIB_FILE}: ${PARTIAL_PLAY_LIB_OBJS}
${CC} -shared ${GST_LDFLAGS} -o $@ $^
${SWITCHER_LIB_FILE}: ${SWITCHER_LIB_OBJS}
${CC} -shared ${GST_LDFLAGS} -o $@ $^
${TMP_DIR}:
${MKDIR} ${TMP_DIR}
${DOXYGEN_DIR}:
${MKDIR} ${DOXYGEN_DIR}
${TEST_RUNNER}: ${CORE_LIB_FILE} ${TEST_RUNNER_OBJS}
${CXX} ${LDFLAGS} -o $@ ${TEST_RUNNER_OBJS} ${TEST_RUNNER_LIBS}
${CORE_LIB_FILE}:
${MAKE} -C ${CORE_DIR}
#-------------------------------------------------------------------------------
# Pattern rules
#-------------------------------------------------------------------------------
${TMP_DIR}/%.o : ${SRC_DIR}/%.c
${CC} ${CPPFLAGS} ${CFLAGS} -c -o $@ $<
${TMP_DIR}/%.o : ${SRC_DIR}/%.cxx
${CXX} ${CPPFLAGS} ${CXXFLAGS} -c -o $@ $<

View file

@ -0,0 +1,92 @@
dnl-----------------------------------------------------------------------------
dnl Copyright (c) 2004 Media Development Loan Fund
dnl
dnl This file is part of the LiveSupport project.
dnl http://livesupport.campware.org/
dnl To report bugs, send an e-mail to bugs@campware.org
dnl
dnl LiveSupport is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl LiveSupport is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with LiveSupport; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
dnl
dnl Author : $Author: maroy $
dnl Version : $Revision: 1.1 $
dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/etc/acinclude.m4,v $
dnl-----------------------------------------------------------------------------
dnl-----------------------------------------------------------------------------
dnl Macro to check for available modules using pkg-conf
dnl
dnl usage:
dnl PKG_CHECK_MODULES(GSTUFF,[gtk+-2.0 >= 1.3], action-if, action-not)
dnl
dnl defines GSTUFF_LIBS, GSTUFF_CFLAGS, see pkg-config man page
dnl also defines GSTUFF_PKG_ERRORS on error
dnl
dnl This function was taken from the glade-- project
dnl-----------------------------------------------------------------------------
AC_DEFUN([PKG_CHECK_MODULES], [
succeeded=no
if test -z "$PKG_CONFIG"; then
AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
fi
if test "$PKG_CONFIG" = "no" ; then
echo "*** The pkg-config script could not be found. Make sure it is"
echo "*** in your path, or set the PKG_CONFIG environment variable"
echo "*** to the full path to pkg-config."
echo "*** Or see http://www.freedesktop.org/software/pkgconfig to get pkg-config."
else
PKG_CONFIG_MIN_VERSION=0.9.0
if $PKG_CONFIG --atleast-pkgconfig-version $PKG_CONFIG_MIN_VERSION; then
AC_MSG_CHECKING(for $2)
if $PKG_CONFIG --exists "$2" ; then
AC_MSG_RESULT(yes)
succeeded=yes
AC_MSG_CHECKING($1_CFLAGS)
$1_CFLAGS=`$PKG_CONFIG --cflags "$2"`
AC_MSG_RESULT($$1_CFLAGS)
AC_MSG_CHECKING($1_LIBS)
$1_LIBS=`$PKG_CONFIG --libs "$2"`
AC_MSG_RESULT($$1_LIBS)
else
$1_CFLAGS=""
$1_LIBS=""
## If we have a custom action on failure, don't print errors, but
## do set a variable so people can do so.
$1_PKG_ERRORS=`$PKG_CONFIG --errors-to-stdout --print-errors "$2"`
ifelse([$4], ,echo $$1_PKG_ERRORS,)
fi
AC_SUBST($1_CFLAGS)
AC_SUBST($1_LIBS)
else
echo "*** Your version of pkg-config is too old. You need version $PKG_CONFIG_MIN_VERSION or newer."
echo "*** See http://www.freedesktop.org/software/pkgconfig"
fi
fi
if test $succeeded = yes; then
ifelse([$3], , :, [$3])
else
ifelse([$4], , AC_MSG_ERROR([Library requirements ($2) not met; consider adjusting the PKG_CONFIG_PATH environment variable if your libraries are in a nonstandard prefix so pkg-config can find them.]), [$4])
fi
])

View file

@ -0,0 +1,71 @@
dnl-----------------------------------------------------------------------------
dnl Copyright (c) 2004 Media Development Loan Fund
dnl
dnl This file is part of the LiveSupport project.
dnl http://livesupport.campware.org/
dnl To report bugs, send an e-mail to bugs@campware.org
dnl
dnl LiveSupport is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl LiveSupport is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with LiveSupport; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dnl
dnl
dnl Author : $Author: maroy $
dnl Version : $Revision: 1.1 $
dnl Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/gstreamerElements/etc/configure.ac,v $
dnl-----------------------------------------------------------------------------
dnl-----------------------------------------------------------------------------
dnl NOTE: Run all configure related scripts from the tmp directory of the
dnl project.
dnl This is due to the fact that configure spreads a lot of trash around,
dnl like atom4te cache directories, config.* files, etc. into the directory
dnl it is being run from. We clearly don't want these in our base directory.
dnl-----------------------------------------------------------------------------
AC_INIT(GstreamerElements, 1.0, bugs@campware.org)
AC_PREREQ(2.59)
AC_COPYRIGHT([Copyright (c) 2004 Media Development Loan Fund under the GNU GPL])
AC_REVISION($Revision: 1.1 $)
AC_CONFIG_SRCDIR(../src/oneshot-reader.c)
AC_CONFIG_HEADERS(configure.h)
AC_PROG_CC()
AC_PROG_CXX()
AC_CHECK_HEADERS(string.h getopt.h)
PKG_CHECK_MODULES(GSTREAMER,[gstreamer-0.8 >= 0.8])
AC_SUBST(GSTREAMER_CFLAGS)
AC_SUBST(GSTREAMER_LIBS)
dnl-----------------------------------------------------------------------------
dnl enable compilaton for code coverage data
dnl-----------------------------------------------------------------------------
AC_SUBST(COVERAGE_CXXFLAGS)
AC_ARG_ENABLE( coverage,
[ --enable-coverage enable code coverage data generaton (no) ],
ENABLE_COVERAGE=${enableval}, ENABLE_COVERAGE="no" )
if test "x${ENABLE_COVERAGE}" == "xyes" ; then
COVERAGE_CXXFLAGS="-fprofile-arcs -ftest-coverage"
AC_MSG_RESULT([compiling in code coverage mode])
else
AC_MSG_RESULT([not compiling in code coverage mode])
fi
AC_CONFIG_FILES(../Makefile:../etc/Makefile.in)
AC_OUTPUT()

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1 @@
keep me

View file

@ -0,0 +1,121 @@
/*------------------------------------------------------------------------------
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/MinimalAudioSmilTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include <string>
#include <iostream>
#include <gst/gst.h>
#include "MinimalAudioSmilTest.h"
using namespace LiveSupport::GstreamerElements;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(MinimalAudioSmilTest);
static const char * testFile = "var/simple.smil";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
MinimalAudioSmilTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
MinimalAudioSmilTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
MinimalAudioSmilTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
GstElement * pipeline;
GstElement * filesrc;
GstElement * smil;
GstElement * sink;
/* initialization */
gst_init(0, 0);
/* create elements */
pipeline = gst_pipeline_new("my_pipeline");
filesrc = gst_element_factory_make("filesrc", "my_filesource");
smil = gst_element_factory_make("minimalaudiosmil", "my_smil");
sink = gst_element_factory_make("alsasink", "audiosink");
g_object_set(G_OBJECT(filesrc), "location", testFile, NULL);
/* link everything together */
gst_element_link_many(filesrc, smil, sink, NULL);
gst_bin_add_many(GST_BIN(pipeline), filesrc, smil, sink, NULL);
/* run */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
while (gst_bin_iterate(GST_BIN(pipeline)));
/* clean up */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
}

View file

@ -0,0 +1,106 @@
/*------------------------------------------------------------------------------
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/MinimalAudioSmilTest.h,v $
------------------------------------------------------------------------------*/
#ifndef MinimalAudioSmilTest_h
#define MinimalAudioSmilTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace GstreamerElements {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the partialplay gstreamer element.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class MinimalAudioSmilTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(MinimalAudioSmilTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace GstreamerElements
} // namespace LiveSupport
#endif // MinimalAudioSmilTest_h

View file

@ -0,0 +1,147 @@
/*------------------------------------------------------------------------------
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/OneshotReaderTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include <string>
#include <iostream>
#include <fstream>
#include <gst/gst.h>
#include "OneshotReaderTest.h"
using namespace LiveSupport::GstreamerElements;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(OneshotReaderTest);
static const char * testFile = "var/oneshotReader.input";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
OneshotReaderTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
OneshotReaderTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
OneshotReaderTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
GstElement * pipeline;
GstElement * filesrc;
GstElement * oneshot;
GstElement * bin;
guint8 * contents;
guint length;
char * verifyContents;
std::ifstream ifs;
/* initialize GStreamer */
gst_init(0, 0);
/* create elements */
pipeline = gst_pipeline_new ("my_pipeline");
filesrc = gst_element_factory_make("filesrc", "my_filesource");
oneshot = gst_element_factory_make("oneshotreader", "oneshot");
bin = gst_bin_new("bin");
g_object_set(G_OBJECT(filesrc), "location", testFile, NULL);
gst_bin_add(GST_BIN(bin), oneshot);
gst_element_add_ghost_pad(bin,
gst_element_get_pad(oneshot, "sink"),
"sink");
/* link everything together */
gst_element_link_many(filesrc, bin, NULL);
gst_bin_add_many(GST_BIN(pipeline), filesrc, bin, NULL);
/* run */
gst_element_set_state(pipeline, GST_STATE_PLAYING);
// well, actually don't run, by setting to state PLAYING,
// we already have what we're looking for.
//while (gst_bin_iterate (GST_BIN (pipeline)));
g_object_get(G_OBJECT(oneshot), "contents", &contents, NULL);
g_object_get(G_OBJECT(oneshot), "length", &length, NULL);
// read in the file contents with an ifstream, and see if
// we get the same
verifyContents = new char[length];
ifs.open(testFile);
CPPUNIT_ASSERT(ifs.good());
// read length - 1, as oneshotreader appends an extra NULL character
ifs.read(verifyContents, length);
CPPUNIT_ASSERT(!memcmp(contents, verifyContents, length));
/* clean up */
delete[] verifyContents;
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT(pipeline));
}

View file

@ -0,0 +1,106 @@
/*------------------------------------------------------------------------------
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/OneshotReaderTest.h,v $
------------------------------------------------------------------------------*/
#ifndef OneshotReaderTest_h
#define OneshotReaderTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace GstreamerElements {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the partialplay gstreamer element.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class OneshotReaderTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(OneshotReaderTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace GstreamerElements
} // namespace LiveSupport
#endif // OneshotReaderTest_h

View file

@ -0,0 +1,119 @@
/*------------------------------------------------------------------------------
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/PartialPlayTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <string>
#include <iostream>
#include <gst/gst.h>
#include "PartialPlayTest.h"
using namespace LiveSupport::GstreamerElements;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(PartialPlayTest);
static const char * testFile = "var/1minutecounter.mp3";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
PartialPlayTest :: setUp(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
PartialPlayTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* A simple smoke test.
*----------------------------------------------------------------------------*/
void
PartialPlayTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
GstElement * pipeline;
GstElement * filter;
GstElement * sink;
/* initialize GStreamer */
gst_init(0, 0);
/* create elements */
pipeline = gst_pipeline_new("audio-player");
filter = gst_element_factory_make("partialplay", "partialplay");
sink = gst_element_factory_make("alsasink", "alsa-output");
/* set filename property on the file source */
g_object_set(G_OBJECT(filter), "location", testFile, NULL);
g_object_set(G_OBJECT(filter), "config", "3s;10s-17s", NULL);
gst_element_link(filter, sink);
gst_bin_add_many(GST_BIN(pipeline), filter, sink, NULL);
gst_element_set_state(filter, GST_STATE_READY);
gst_element_set_state(sink, GST_STATE_READY);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
// TODO: actually run the test
// unfortunately currently partialplay does get into EOS state
// when needed
//while (gst_bin_iterate(GST_BIN(pipeline)));
/* clean up nicely */
gst_element_set_state(pipeline, GST_STATE_NULL);
gst_object_unref(GST_OBJECT (pipeline));
}

View file

@ -0,0 +1,106 @@
/*------------------------------------------------------------------------------
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/PartialPlayTest.h,v $
------------------------------------------------------------------------------*/
#ifndef PartialPlayTest_h
#define PartialPlayTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace GstreamerElements {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the partialplay gstreamer element.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class PartialPlayTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(PartialPlayTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple smoke test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
public:
/**
* Set up the environment for the test case.
*/
void
setUp(void) throw ();
/**
* Clean up the environment after the test case.
*/
void
tearDown(void) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace GstreamerElements
} // namespace LiveSupport
#endif // PartialPlayTest_h

View file

@ -0,0 +1,281 @@
/*------------------------------------------------------------------------------
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/TestRunner.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#if HAVE_GETOPT_H
#include <getopt.h>
#else
#error "Need getopt.h"
#endif
#include <fstream>
#include <cppunit/BriefTestProgressListener.h>
#include <cppunit/CompilerOutputter.h>
#include <cppunit/XmlOutputter.h>
#include <cppunit/extensions/TestFactoryRegistry.h>
#include <cppunit/TestResult.h>
#include <cppunit/TestResultCollector.h>
#include <cppunit/TestRunner.h>
#include "LiveSupport/Core/Ptr.h"
using namespace LiveSupport::Core;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/**
* Our copyright notice, should be at most 80 columns
*/
static const char copyrightNotice[] =
"Copyright (c) 2004 Media Development Loan Fund under the GNU GPL";
/**
* String describing the short options.
*/
static const char options[] = "ho:s:v";
/**
* Structure describing the long options
*/
static const struct option longOptions[] = {
{ "help", no_argument, 0, 'h' },
{ "output", required_argument, 0, 'o' },
{ "stylesheet", required_argument, 0, 's' },
{ "version", no_argument, 0, 'v' },
{ 0, 0, 0, 0 }
};
/**
* The encoding to use for the output file.
*/
static const std::string encoding = "utf-8";
/**
* The output XML file name.
*/
static Ptr<std::string>::Ref xmlOutFileName;
/**
* The XSLT attached to the output file.
*/
static Ptr<std::string>::Ref xsltFileName;
/* =============================================== local function prototypes */
/**
* Print program version.
*
* @param os the std::ostream to print to.
*/
static void
printVersion ( std::ostream & os );
/**
* Print program usage information.
*
* @param invocation the command line command used to invoke this program.
* @param os the std::ostream to print to.
*/
static void
printUsage ( const char invocation[],
std::ostream & os );
/**
* Process command line arguments.
*
* @param argc the number of arguments.
* @param argv the arguments themselves.
* @return true of all went well, false in case the program should exit
* after this call.
*/
static bool
processArguments(int argc, char *argv[]);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Run all tests
*----------------------------------------------------------------------------*/
int
main( int argc,
char * argv[] ) throw ()
{
if (!processArguments(argc, argv)) {
return 0;
}
// Create the event manager and test controller
CPPUNIT_NS::TestResult controller;
// Add a listener that colllects test result
CPPUNIT_NS::TestResultCollector result;
controller.addListener( &result );
// Add a listener that print dots as test run.
CPPUNIT_NS::BriefTestProgressListener progress;
controller.addListener( &progress );
// Add the top suite to the test runner
CPPUNIT_NS::TestRunner runner;
runner.addTest( CPPUNIT_NS::TestFactoryRegistry::getRegistry().makeTest() );
runner.run( controller );
// Print test in a compiler compatible format.
CPPUNIT_NS::CompilerOutputter outputter( &result, std::cerr );
outputter.setLocationFormat("%p:%l:");
outputter.write();
// also generate an XML document as an output
std::ofstream xmlOutFile(xmlOutFileName->c_str());
CPPUNIT_NS::XmlOutputter xmlOutputter(&result, xmlOutFile, encoding);
xmlOutputter.setStandalone(false);
if (xsltFileName) {
xmlOutputter.setStyleSheet(*xsltFileName);
}
xmlOutputter.write();
xmlOutFile.flush();
xmlOutFile.close();
return result.wasSuccessful() ? 0 : 1;
}
/*------------------------------------------------------------------------------
* Process command line arguments.
*----------------------------------------------------------------------------*/
static bool
processArguments(int argc, char *argv[])
{
int i;
while ((i = getopt_long(argc, argv, options, longOptions, 0)) != -1) {
switch (i) {
case 'h':
printUsage(argv[0], std::cout);
return false;
case 'o':
xmlOutFileName.reset(new std::string(optarg));
break;
case 's':
xsltFileName.reset(new std::string(optarg));
break;
case 'v':
printVersion(std::cout);
return false;
default:
printUsage(argv[0], std::cout);
return false;
}
}
if (optind < argc) {
std::cerr << "error processing command line arguments" << std::endl;
printUsage(argv[0], std::cout);
return false;
}
if (!xmlOutFileName) {
std::cerr << "mandatory option output file name not specified"
<< std::endl;
printUsage(argv[0], std::cout);
return false;
}
std::cerr << "writing output to '" << *xmlOutFileName << '\'' << std::endl;
if (xsltFileName) {
std::cerr << "using XSLT file '" << *xsltFileName << '\'' << std::endl;
}
return true;
}
/*------------------------------------------------------------------------------
* Print program version.
*----------------------------------------------------------------------------*/
static void
printVersion ( std::ostream & os )
{
os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl
<< "Unit test runner" << std::endl
<< copyrightNotice << std::endl;
}
/*------------------------------------------------------------------------------
* Print program usage.
*----------------------------------------------------------------------------*/
static void
printUsage ( const char invocation[],
std::ostream & os )
{
os << PACKAGE_NAME << ' ' << PACKAGE_VERSION << std::endl
<< "Unit test runner" << std::endl
<< std::endl
<< "Usage: " << invocation << " [OPTION]"
<< std::endl
<< " mandatory options:" << std::endl
<< " -o, --output=file.name write test results into this XML file"
<< std::endl
<< " optional options:" << std::endl
<< " -s, --stylesheet specify this XSLT for the output file"
<< std::endl
<< " this is either an absolute URI, or a"
<< std::endl
<< " relative path for the output document"
<< std::endl
<< " -h, --help display this help and exit" << std::endl
<< " -v, --version display version information and exit"
<< std::endl
<< std::endl
<< "Report bugs to " << PACKAGE_BUGREPORT << std::endl;
}

View file

@ -0,0 +1,686 @@
/*------------------------------------------------------------------------------
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/minimal-audio-smil.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include <gst/bytestream/bytestream.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include "minimal-audio-smil.h"
/* =================================================== local data structures */
/**
* ElementFactory information
*/
static GstElementDetails livesupport_minimal_audio_smil_details =
GST_ELEMENT_DETAILS("MinimalAudioSmil",
"Generic",
"A minimal SMIL payer, supporting only audio",
"Akos Maroy <maroy@campware.org>");
/**
* The parent class.
*/
static GstBinClass * parent_class = NULL;
/**
* Declaration of the sink pad factory.
*/
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE (
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS("application/smil"));
/**
* Declaration of the source pad factory.
*/
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE (
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS("audio/x-raw-int, "
"width = (int) 16, "
"depth = (int) 16, "
"endianness = (int) BYTE_ORDER, "
"channels = (int) { 1, 2 }, "
"rate = (int) [ 8000, 96000 ]"));
/* ================================================ local constants & macros */
#define UNREF_IF_NOT_NULL(gst_object) \
{ \
if ((gst_object)) { \
gst_object_unref(GST_OBJECT(gst_object)); \
} \
}
/**
* The debug definition.
*/
GST_DEBUG_CATEGORY_STATIC(minimal_audio_smil_debug);
/**
* The plugin definition.
*/
GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"minimalaudiosmil",
"Minimal Audio-only SMIL",
plugin_init,
"$Revision: 1.1 $",
"GPL",
"LiveSupport",
"http://livesupport.campware.org/")
/* =============================================== local function prototypes */
/**
* Read the sink stream into memory, using a oneshotreader element.
*
* @param smil a MinimalAudioSmil object.
* @param outbuffer the buffer containing the contents of the sink stream.
* (out parameter). must be freed by g_free() after no longer needed.
* @param outlength the length of outbuffer (an out parameter).
*/
static void
read_stream_into_memory(LivesupportMinimalAudioSmil * smil,
guint8 ** outbuffer,
guint32 * outlength);
/**
* Return the the first "<body>" element of an XML document.
*
* @param document the XML document to return the root element for.
* @return the "<body>" element closes to the document root,
* or NULL if no "<body>" element found.
*/
static xmlNode *
get_body_element(xmlDocPtr document);
/**
* Handle an "<audio>" SMIL element.
*
* @param smil a MinimalAudioSmil object.
* @param audio an "<audio>" SMIL element.
* @param index the index of the "<audio>" element with respect to it's
* containing element.
* @return a gstreamer element that will play audio as described by the
* "<audio>" SMIL element. the element will be named using the
* supplied index, thus is will be uniquely named with respect
* to it's parent.
*/
static GstElement *
handle_audio_element(LivesupportMinimalAudioSmil * smil,
xmlNode * audio,
int index);
/**
* Handle a "<par>" SMIL element.
*
* @param smil a MinimalAudioSmil object.
* @param par a "<par>" SMIL element.
* @return a gstreamer element that will play audio as described by the
* supplied "<par>" element.
*/
static GstElement *
handle_par_element(LivesupportMinimalAudioSmil * smil,
xmlNode * par);
/**
* Process the sink input as a SMIL file.
* The bin container inside the MinimalAudioSmil object will be filled
* with gstreamer elements, playing audio as described by the SMIL file.
*
* @para smil a MinimalAudioSmil object.
* @return TRUE if processing was successful, FALSE otherwise.
*/
static gboolean
process_smil_file(LivesupportMinimalAudioSmil * smil);
/**
* Handle state change for a MinimalAudioSmil object.
*
* @param element a MinimalAudioSmil object.
* @return the success or failure status of the state change.
*/
static GstElementStateReturn
livesupport_minimal_audio_smil_change_state(GstElement * element);
/**
* Destroy a MinimalAudioSmil object.
*
* @param object the MinimalAudioSmil object to destroy.
*/
static void
livesupport_minimal_audio_smil_dispose(GObject * object);
/**
* Initialize a MinimalAudioSmil object.
*
* @param smil the MinimalAudioSmil object to initialie.
*/
static void
livesupport_minimal_audio_smil_init(LivesupportMinimalAudioSmil * smil);
/**
* Do base-initialization for a MinimalAudioSmil object.
*
* @param g_class a MinimalAudioSmil class.
*/
static void
livesupport_minimal_audio_smil_base_init(gpointer g_class);
/**
* Initialize the MinimalAudioSmil class.
*
* @param klass a MinimalAudioSmil class.
*/
static void
livesupport_minimal_audio_smil_class_init(
LivesupportMinimalAudioSmilClass * klass);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Read the sink stream into memory, using a oneshotreader element.
*----------------------------------------------------------------------------*/
static void
read_stream_into_memory(LivesupportMinimalAudioSmil * smil,
guint8 ** outbuffer,
guint32 * outlength)
{
guint32 length;
guint8 * buffer;
GstElementState oldState;
*outbuffer = 0;
*outlength = 0;
oldState = gst_element_get_state(smil->oneshotReader);
gst_element_set_state(smil->oneshotReader, GST_STATE_PLAYING);
g_object_get(G_OBJECT(smil->oneshotReader), "length", &length, NULL);
g_object_get(G_OBJECT(smil->oneshotReader), "contents", &buffer, NULL);
gst_element_set_state(smil->oneshotReader, oldState);
*outbuffer = buffer;
*outlength = length;
}
/*------------------------------------------------------------------------------
* Return the the first "<body>" element of an XML document.
*----------------------------------------------------------------------------*/
static xmlNode *
get_body_element(xmlDocPtr document)
{
xmlNode * node = document->children;
if (!node || strcmp(node->name, "smil")) {
return 0;
}
for (node = node->children; node; node = node->next) {
if (node->type == XML_ELEMENT_NODE
&& !strcmp(node->name, "body")) {
return node;
}
}
return 0;
}
/*------------------------------------------------------------------------------
* Handle an "<audio>" SMIL element.
*----------------------------------------------------------------------------*/
static GstElement *
handle_audio_element(LivesupportMinimalAudioSmil * smil,
xmlNode * audio,
int index)
{
xmlAttribute * attr;
gchar * src = 0;
gchar * begin = 0;
gchar * clipBegin = 0;
gchar * clipEnd = 0;
gchar * str;
guint len;
GstElement * pplay;
for (attr = ((xmlElement*)audio)->attributes;
attr;
attr = (xmlAttribute*) attr->next) {
xmlNode * node;
/* TODO: support attribute values that are represented with
* more than one text node, in all content assignments below */
if (!strcmp(attr->name, "src")) {
if ((node = attr->children) && node->type == XML_TEXT_NODE) {
src = (gchar*) node->content;
}
} else if (!strcmp(attr->name, "begin")) {
if ((node = attr->children) && node->type == XML_TEXT_NODE) {
begin = (gchar*) node->content;
}
} else if (!strcmp(attr->name, "clipBegin")) {
if ((node = attr->children) && node->type == XML_TEXT_NODE) {
clipBegin = (gchar*) node->content;
}
} else if (!strcmp(attr->name, "clipEnd")) {
if ((node = attr->children) && node->type == XML_TEXT_NODE) {
clipEnd = (gchar*) node->content;
}
} else {
GST_WARNING("unsupported SMIL audio element attribute: %s",
attr->name);
}
}
if (!src) {
GST_WARNING("required SMIL audio element attribute src missing");
return 0;
}
if (!begin) {
begin = "0s";
}
if (!clipBegin) {
clipBegin = "0s";
}
/* we only support file: URLs at the moment */
if (!g_str_has_prefix(src, "file:")) {
GST_WARNING("SMIL audio element src attribute with unsupported "
"protocol: %s", src);
return 0;
}
src += g_str_has_prefix(src, "file://") ? 7 : 5;
/* now create a partial play element */
len = strlen("partialplay_XXXXXXXXXX") + 1;
str = g_malloc(len);
g_snprintf(str, len, "partialplay_%d", index);
if (!(pplay = gst_element_factory_make("partialplay", str))) {
GST_WARNING("can't create a required gstreamer element");
g_free(str);
return 0;
}
g_free(str);
g_object_set(G_OBJECT(pplay), "location", src, NULL);
len = strlen(begin)
+ strlen(clipBegin)
+ (clipEnd ? strlen(clipEnd) : 0)
+ 3;
str = g_malloc(sizeof(gchar) * len);
g_snprintf(str, len, "%s;%s-%s",
begin, clipBegin, clipEnd ? clipEnd : "");
g_object_set(G_OBJECT(pplay), "config", str, NULL);
g_free(str);
return pplay;
}
/*------------------------------------------------------------------------------
* Handle a "<par>" SMIL element.
*----------------------------------------------------------------------------*/
static GstElement *
handle_par_element(LivesupportMinimalAudioSmil * smil,
xmlNode * par)
{
xmlNode * node;
GstElement * pipeline;
GstElement * adder;
int index;
GValue gvalue = { 0 };
/* TODO: create unique name for pipeline */
pipeline = gst_bin_new("par_bin");
adder = gst_element_factory_make("adder", "adder");
if (!pipeline || !adder) {
GST_WARNING("can't create a required gstreamer element");
UNREF_IF_NOT_NULL(pipeline);
UNREF_IF_NOT_NULL(adder);
return 0;
}
g_value_init(&gvalue, G_TYPE_BOOLEAN);
g_value_set_boolean(&gvalue, TRUE);
gst_element_set_property(adder, "eos", &gvalue);
for (index = 0, node = par->children; node; node = node->next, ++index) {
if (node->type == XML_ELEMENT_NODE) {
GstElement * element = 0;
if (!strcmp(node->name, "audio")) {
element = handle_audio_element(smil, node, index);
} else {
GST_WARNING("unsupported SMIL element %s found inside a par",
node->name);
}
if (element) {
if (!gst_element_link(element, adder)) {
GST_WARNING("can't link par child to adder");
}
gst_bin_add(GST_BIN(pipeline), element);
}
}
}
gst_bin_add(GST_BIN(pipeline), adder);
gst_element_add_ghost_pad(GST_ELEMENT(pipeline),
gst_element_get_pad(adder, "src"),
"src");
return pipeline;
}
/*------------------------------------------------------------------------------
* Process the sink input as a SMIL file.
*----------------------------------------------------------------------------*/
static gboolean
process_smil_file(LivesupportMinimalAudioSmil * smil)
{
guint32 length;
guint8 * buffer;
xmlDocPtr document;
xmlNode * node;
/* read the source document into memory */
read_stream_into_memory(smil, &buffer, &length);
if (!buffer) {
return FALSE;
}
/* parse the XML files */
document = xmlReadMemory((const char *) buffer,
length, "noname.xml", NULL, 0);
if (!document
|| !(node = get_body_element(document))) {
GST_ELEMENT_ERROR(GST_ELEMENT(smil),
STREAM,
WRONG_TYPE,
("SMIL input does not seem to be an XML file"),
(NULL));
return FALSE;
}
for (node = node->children; node; node = node->next) {
if (node->type == XML_ELEMENT_NODE) {
GstElement * element = 0;
if (!strcmp(node->name, "par")) {
element = handle_par_element(smil, node);
} else {
GST_WARNING("unsupported SMIL element %s found",
node->name);
}
if (element) {
gst_bin_add(GST_BIN(smil->bin), element);
if (!gst_element_link(element, smil->finalAdder)) {
GST_WARNING("couldn't link par element to final adder");
}
}
}
}
/* free the XML document */
xmlFreeDoc(document);
gst_bin_sync_children_state(GST_BIN(smil->bin));
return TRUE;
}
/*------------------------------------------------------------------------------
* Handle state change for the MinimalAudioSmil element.
*----------------------------------------------------------------------------*/
static GstElementStateReturn
livesupport_minimal_audio_smil_change_state(GstElement * element)
{
LivesupportMinimalAudioSmil * smil;
smil = LIVESUPPORT_MINIMAL_AUDIO_SMIL(element);
switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY:
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_READY);
break;
case GST_STATE_READY_TO_PAUSED:
if (!smil->fileProcessed) {
/* set to true, in case of multiple change events */
smil->fileProcessed = TRUE;
if (!(smil->fileProcessed = process_smil_file(smil))) {
GST_ELEMENT_ERROR(GST_ELEMENT(smil),
STREAM,
WRONG_TYPE,
("unable to process SMIL file"),
(NULL));
}
}
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_PAUSED);
break;
case GST_STATE_PAUSED_TO_PLAYING:
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_PLAYING);
break;
case GST_STATE_PLAYING_TO_PAUSED:
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_PAUSED);
break;
case GST_STATE_PAUSED_TO_READY:
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_READY);
break;
case GST_STATE_READY_TO_NULL:
gst_element_set_state(GST_ELEMENT(smil->bin), GST_STATE_NULL);
break;
default:
break;
}
if (GST_ELEMENT_CLASS(parent_class)->change_state) {
return GST_ELEMENT_CLASS(parent_class)->change_state(element);
}
return GST_STATE_SUCCESS;
}
/*------------------------------------------------------------------------------
* Destroy a MinimalAudioSmil object.
*----------------------------------------------------------------------------*/
static void
livesupport_minimal_audio_smil_dispose(GObject * object)
{
LivesupportMinimalAudioSmil * smil = LIVESUPPORT_MINIMAL_AUDIO_SMIL(object);
g_return_if_fail(LIVESUPPORT_IS_MINIMAL_AUDIO_SMIL(smil));
xmlCleanupParser();
G_OBJECT_CLASS(parent_class)->dispose(object);
}
/*------------------------------------------------------------------------------
* Initialize a MinimalAudioSmil object.
*----------------------------------------------------------------------------*/
static void
livesupport_minimal_audio_smil_init(LivesupportMinimalAudioSmil * smil)
{
GValue gvalue = { 0 };
smil->bin = GST_BIN(gst_bin_new("smilbin"));
smil->finalAdder = gst_element_factory_make("adder", "finalAdder");
g_value_init(&gvalue, G_TYPE_BOOLEAN);
g_value_set_boolean(&gvalue, TRUE);
gst_element_set_property(smil->finalAdder, "eos", &gvalue);
gst_bin_add(smil->bin, smil->finalAdder);
/* create and attach an adder to the src pad, so that the bin
* actually has a src pad, that we can attach to ourselves below */
gst_element_add_ghost_pad(GST_ELEMENT(smil->bin),
gst_element_get_pad(smil->finalAdder, "src"),
"src");
gst_bin_add(GST_BIN(smil), GST_ELEMENT(smil->bin));
smil->srcpad = gst_element_add_ghost_pad(GST_ELEMENT(smil),
gst_element_get_pad(GST_ELEMENT(smil->bin), "src"),
"src");
smil->oneshotReader = gst_element_factory_make("oneshotreader", "oneshot");
smil->oneshotReaderSink = gst_element_get_pad(smil->oneshotReader, "sink");
gst_bin_add(GST_BIN(smil), smil->oneshotReader);
smil->sinkpad = gst_element_add_ghost_pad(GST_ELEMENT(smil),
smil->oneshotReaderSink,
"sink");
smil->fileProcessed = FALSE;
}
/*------------------------------------------------------------------------------
* Do base-initialization for a MinimalAudioSmil object.
*----------------------------------------------------------------------------*/
static void
livesupport_minimal_audio_smil_base_init(gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
gst_element_class_set_details(element_class,
&livesupport_minimal_audio_smil_details);
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&src_factory));
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&sink_factory));
}
/*------------------------------------------------------------------------------
* Initialize a MinimalAudioSmil class.
*----------------------------------------------------------------------------*/
static void
livesupport_minimal_audio_smil_class_init(
LivesupportMinimalAudioSmilClass * klass)
{
GObjectClass * gobject_class;
GstElementClass * gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref(GST_TYPE_BIN);
gobject_class->dispose = livesupport_minimal_audio_smil_dispose;
gstelement_class->change_state =
livesupport_minimal_audio_smil_change_state;
/* check for the libxml version */
LIBXML_TEST_VERSION
}
/*------------------------------------------------------------------------------
* Return the type structure for the plugin.
*----------------------------------------------------------------------------*/
GType
livesupport_minimal_audio_smil_get_type(void)
{
static GType minimal_audio_smil_type = 0;
if (!minimal_audio_smil_type) {
static const GTypeInfo minimal_audio_smil_info = {
sizeof (LivesupportMinimalAudioSmilClass),
livesupport_minimal_audio_smil_base_init,
NULL,
(GClassInitFunc) livesupport_minimal_audio_smil_class_init,
NULL,
NULL,
sizeof (LivesupportMinimalAudioSmil),
0,
(GInstanceInitFunc) livesupport_minimal_audio_smil_init,
};
minimal_audio_smil_type = g_type_register_static(GST_TYPE_BIN,
"LivesupportMinimalAudioSmil",
&minimal_audio_smil_info,
0);
GST_DEBUG_CATEGORY_INIT(minimal_audio_smil_debug,
"minimalaudiosmil",
0,
"minimal audio-only SMIL element");
}
return minimal_audio_smil_type;
}
/*------------------------------------------------------------------------------
* Initialize the plugin
*----------------------------------------------------------------------------*/
static gboolean
plugin_init (GstPlugin * plugin)
{
return gst_element_register(plugin,
"minimalaudiosmil",
GST_RANK_NONE,
LIVESUPPORT_TYPE_MINIMAL_AUDIO_SMIL);
}

View file

@ -0,0 +1,130 @@
/*------------------------------------------------------------------------------
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/minimal-audio-smil.h,v $
------------------------------------------------------------------------------*/
#ifndef LivesSupport_GstreamerElements_MinimalAudioSmil_h
#define LivesSupport_GstreamerElements_MinimalAudioSmil_h
/**
* @file
* A gstreamer element that plays SMIL files referencing audio content.
* Only a small subset of SMIL is supported.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see http://www.w3.org/TR/SMIL2/
*/
/* ============================================================ include files */
#include <gst/gst.h>
/* =================================================================== macros */
G_BEGIN_DECLS
#define LIVESUPPORT_TYPE_MINIMAL_AUDIO_SMIL \
(livesupport_minimal_audio_smil_get_type())
#define LIVESUPPORT_MINIMAL_AUDIO_SMIL(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
LIVESUPPORT_TYPE_MINIMAL_AUDIO_SMIL, \
LivesupportMinimalAudioSmil))
#define LIVESUPPORT_MINIMAL_AUDIO_SMIL_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
LIVESUPPORT_TYPE_MINIMAL_AUDIO_SMIL, \
LivesupportMinimalAudioSmil))
#define LIVESUPPORT_IS_MINIMAL_AUDIO_SMIL(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
LIVESUPPORT_TYPE_MINIMAL_AUDIO_SMIL))
#define LIVESUPPORT_IS_MINIMAL_AUDIO_SMIL_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass), \
LIVESUPPORT_TYPE_MINIMAL_AUDIO_SMIL))
/* =============================================================== data types */
typedef struct _LivesupportMinimalAudioSmil LivesupportMinimalAudioSmil;
typedef struct _LivesupportMinimalAudioSmilClass
LivesupportMinimalAudioSmilClass;
/**
* The MinimalAudioSmil object structure.
*/
struct _LivesupportMinimalAudioSmil {
GstBin parent;
GstPad * sinkpad;
GstPad * srcpad;
GstElement * oneshotReader;
GstPad * oneshotReaderSink;
gboolean fileProcessed;
GstBin * bin;
GstElement * finalAdder;
};
/**
* The MinimalAudioSmil class.
*/
struct _LivesupportMinimalAudioSmilClass {
GstBinClass parent_class;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
/**
* Return the appropriate type for the element.
*
* @return the type structure of the element.
*/
GType
livesupport_minimal_audio_smil_get_type(void);
/**
* The plugin initialization function.
*
* @param plugin the plugin itself.
* @return TRUE if initialization was successful, FALSE otherwise.
*/
static gboolean
plugin_init (GstPlugin * plugin);
G_END_DECLS
#endif /* LivesSupport_GstreamerElements_MinimalAudioSmil_h */

View file

@ -0,0 +1,516 @@
/*------------------------------------------------------------------------------
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/oneshot-reader.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include "oneshot-reader.h"
/* =================================================== local data structures */
/**
* The arguments this element supports.
*/
enum {
ARG_0,
ARG_CONTENTS,
ARG_LENGTH
};
/**
* Element details.
*/
static GstElementDetails livesupport_one_shot_reader_details =
GST_ELEMENT_DETAILS("OneShotReader",
"Generic",
"A reader, reading the contents in one shot",
"Akos Maroy <maroy@campware.org>");
/**
* The parent class.
*/
static GstElementClass * parent_class = NULL;
/**
* The sink factory template.
*/
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE (
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS_ANY);
/* ================================================ local constants & macros */
/**
* Debug category definition.
*/
GST_DEBUG_CATEGORY_STATIC(one_shot_reader_debug);
/**
* The plugin definition.
*/
GST_PLUGIN_DEFINE(GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"oneshotreaderplugin",
"A reader that reads all of the input on one go",
plugin_init,
"$Revision: 1.1 $",
"GPL",
"LiveSupport",
"http://livesupport.campware.org/")
/* =============================================== local function prototypes */
/**
* Get a specific property.
*
* @param object the object to get the property from (a oneshotreader)
* @param propId the ID of the property
* @param value the value to return the property in (out parameter)
* @param pspec the parameter spec
*/
static void
get_property(GObject * object,
guint propId,
GValue * value,
GParamSpec * pspec);
/**
* Read a stream into memory.
*
* @param read the OneShotReader to read from.
* @param outbuffer the buffer to return the whole stream in, plus
* an extra terminating NULL character.
* must be freed after it's not needed.
* @param outlength the length of the returned buffer.
*/
static void
read_stream_into_memory(LivesupportOneShotReader * reader,
guint8 ** outbuffer,
guint32 * outlength);
/**
* The main loop function of the element.
*
* @param element a OneShotReader element to loop on.
*/
static void
livesupport_one_shot_reader_loop(GstElement * element);
/**
* The state change function of the element.
*
* @param element a OneShotReader element to change the state for.
*/
static GstElementStateReturn
livesupport_one_shot_reader_change_state(GstElement * element);
/**
* The dispose function of the element.
*
* @param object a OneShotReader element to dispose of.
*/
static void
livesupport_one_shot_reader_dispose(GObject * object);
/**
* Initialize a OneShotReader element.
*
* @param reader the OneShotReader element to initialzie.
*/
static void
livesupport_one_shot_reader_init(LivesupportOneShotReader * reader);
/**
* Do base initialization on the element's class.
*
* @param g_class the element's class.
*/
static void
livesupport_one_shot_reader_base_init(gpointer g_class);
/**
* Initialize the element's class.
*
* @param klass the element's class.
*/
static void
livesupport_one_shot_reader_class_init(LivesupportOneShotReaderClass * klass);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Get a specific property.
*----------------------------------------------------------------------------*/
static void
get_property(GObject * object,
guint propId,
GValue * value,
GParamSpec * pspec)
{
LivesupportOneShotReader * reader = LIVESUPPORT_ONE_SHOT_READER(object);
switch (propId) {
case ARG_CONTENTS:
g_value_set_pointer(value, reader->contents);
break;
case ARG_LENGTH:
g_value_set_uint(value, reader->length);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propId, pspec);
break;
}
}
/*------------------------------------------------------------------------------
* Read the whole stream into memory.
*----------------------------------------------------------------------------*/
static void
read_stream_into_memory(LivesupportOneShotReader * reader,
guint8 ** outbuffer,
guint32 * outlength)
{
guint32 length;
guint32 read;
guint8 * buffer;
*outbuffer = 0;
*outlength = 0;
if (!reader->bytestream) {
GST_ELEMENT_ERROR(GST_ELEMENT(reader),
CORE,
PAD,
("missing bytestream"),
(NULL));
return;
}
length = (guint32) gst_bytestream_length(reader->bytestream);
buffer = g_malloc(length + 1);
read = 0;
while (read < length) {
guint32 r;
guint8 * buf;
GstEvent * event;
/* look if we've reached eos, and exit the loop if so */
gst_bytestream_get_status(reader->bytestream, &r, &event);
if (event) {
if (GST_EVENT_TYPE(event) == GST_EVENT_EOS) {
gst_event_unref(event);
break;
}
gst_event_unref(event);
}
r = gst_bytestream_peek_bytes(reader->bytestream, &buf, length - read);
memcpy(buffer + read, buf, r);
read += r;
}
/* check if we could read everything */
if (read < length) {
g_free(buffer);
GST_ELEMENT_ERROR(GST_ELEMENT(reader),
RESOURCE,
READ,
("couldn't read the whole of the input"),
(NULL));
return;
}
/* flush the bytestream, as we've read all from it anyway */
gst_bytestream_flush_fast(reader->bytestream, length);
/* put a 0 character at the end of the buffer */
buffer[length] = '\0';
*outbuffer = buffer;
*outlength = length;
}
/*------------------------------------------------------------------------------
* The loop function of the reader.
*----------------------------------------------------------------------------*/
static void
livesupport_one_shot_reader_loop(GstElement * element)
{
LivesupportOneShotReader * reader;
g_return_if_fail(element != NULL);
g_return_if_fail(GST_IS_ONE_SHOT_READER(element));
reader = LIVESUPPORT_ONE_SHOT_READER(element);
if (!reader->processed) {
/* read the source document into memory */
read_stream_into_memory(reader, &reader->contents, &reader->length);
if (!reader->contents) {
GST_ELEMENT_ERROR(GST_ELEMENT(reader),
STREAM,
WRONG_TYPE,
("unable to process input"),
(NULL));
}
reader->processed = TRUE;
}
gst_element_set_eos(element);
}
/*------------------------------------------------------------------------------
* The state change function of the element.
*----------------------------------------------------------------------------*/
static GstElementStateReturn
livesupport_one_shot_reader_change_state(GstElement * element)
{
LivesupportOneShotReader * reader;
reader = LIVESUPPORT_ONE_SHOT_READER(element);
switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY:
break;
case GST_STATE_READY_TO_PAUSED:
reader->bytestream = gst_bytestream_new(reader->sinkpad);
break;
case GST_STATE_PAUSED_TO_PLAYING:
if (!reader->processed) {
/* read the source document into memory */
read_stream_into_memory(reader,
&reader->contents,
&reader->length);
if (!reader->contents) {
GST_ELEMENT_ERROR(GST_ELEMENT(reader),
STREAM,
WRONG_TYPE,
("unable to process input"),
(NULL));
}
reader->processed = TRUE;
}
break;
case GST_STATE_PLAYING_TO_PAUSED:
break;
case GST_STATE_PAUSED_TO_READY:
if (reader->bytestream) {
gst_bytestream_destroy(reader->bytestream);
reader->bytestream = 0;
}
break;
case GST_STATE_READY_TO_NULL:
break;
default:
break;
}
if (GST_ELEMENT_CLASS(parent_class)->change_state) {
return GST_ELEMENT_CLASS(parent_class)->change_state(element);
}
return GST_STATE_SUCCESS;
}
/*------------------------------------------------------------------------------
* The dispose function.
*----------------------------------------------------------------------------*/
static void
livesupport_one_shot_reader_dispose(GObject * object)
{
LivesupportOneShotReader * reader = LIVESUPPORT_ONE_SHOT_READER(object);
if (reader->bytestream) {
gst_bytestream_destroy(reader->bytestream);
}
if (reader->contents) {
g_free(reader->contents);
}
G_OBJECT_CLASS(parent_class)->dispose(object);
}
/*------------------------------------------------------------------------------
* Initialize a OneShotReader element.
*----------------------------------------------------------------------------*/
static void
livesupport_one_shot_reader_init(LivesupportOneShotReader * reader)
{
reader->sinkpad = gst_pad_new("sink", GST_PAD_SINK);
gst_element_add_pad(GST_ELEMENT(reader), reader->sinkpad);
gst_pad_set_link_function(reader->sinkpad,
GST_DEBUG_FUNCPTR(gst_pad_proxy_pad_link));
gst_pad_set_getcaps_function(reader->sinkpad,
GST_DEBUG_FUNCPTR(gst_pad_proxy_getcaps));
gst_element_set_loop_function(GST_ELEMENT(reader),
livesupport_one_shot_reader_loop);
reader->bytestream = 0;
reader->contents = 0;
reader->length = 0L;
}
/*------------------------------------------------------------------------------
* Do base initialization on the element's class.
*----------------------------------------------------------------------------*/
static void
livesupport_one_shot_reader_base_init(gpointer g_class)
{
GstElementClass *element_class = GST_ELEMENT_CLASS(g_class);
gst_element_class_set_details(element_class,
&livesupport_one_shot_reader_details);
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&sink_factory));
}
/*------------------------------------------------------------------------------
* Initialize the element's class.
*----------------------------------------------------------------------------*/
static void
livesupport_one_shot_reader_class_init(LivesupportOneShotReaderClass * klass)
{
GObjectClass * gobject_class;
GstElementClass * gstelement_class;
gobject_class = (GObjectClass *) klass;
gstelement_class = (GstElementClass *) klass;
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
gobject_class->dispose = livesupport_one_shot_reader_dispose;
gstelement_class->change_state = livesupport_one_shot_reader_change_state;
g_object_class_install_property(gobject_class,
ARG_CONTENTS,
g_param_spec_pointer("contents",
"contents",
"the contents read "
", a 0-terminated array",
G_PARAM_READABLE));
g_object_class_install_property(gobject_class,
ARG_LENGTH,
g_param_spec_uint("length",
"length",
"the length of the contents read",
0,
G_MAXUINT,
0,
G_PARAM_READABLE));
gobject_class->get_property = get_property;
}
/*------------------------------------------------------------------------------
* Return the appropriate type for the element.
*----------------------------------------------------------------------------*/
GType
livesupport_one_shot_reader_get_type(void)
{
static GType one_shot_reader_type = 0;
if (!one_shot_reader_type) {
static const GTypeInfo one_shot_reader_info = {
sizeof (LivesupportOneShotReaderClass),
livesupport_one_shot_reader_base_init,
NULL,
(GClassInitFunc) livesupport_one_shot_reader_class_init,
NULL,
NULL,
sizeof (LivesupportOneShotReader),
0,
(GInstanceInitFunc) livesupport_one_shot_reader_init,
};
one_shot_reader_type = g_type_register_static(GST_TYPE_ELEMENT,
"LivesupportOneShotReader",
&one_shot_reader_info,
0);
GST_DEBUG_CATEGORY_INIT(one_shot_reader_debug,
"oneshotreader",
0,
"a one-shot reader");
}
return one_shot_reader_type;
}
/*------------------------------------------------------------------------------
* The plugin initialization function.
*----------------------------------------------------------------------------*/
static gboolean
plugin_init(GstPlugin * plugin)
{
if (!gst_library_load("gstbytestream")) {
return FALSE;
}
return gst_element_register(plugin,
"oneshotreader",
GST_RANK_NONE,
LIVESUPPORT_TYPE_ONE_SHOT_READER);
}

View file

@ -0,0 +1,127 @@
/*------------------------------------------------------------------------------
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/oneshot-reader.h,v $
------------------------------------------------------------------------------*/
#ifndef LivesSupport_GstreamerElements_OneShotReader_h
#define LivesSupport_GstreamerElements_OneShotReader_h
/**
* @file
* A gstreamer element that reads all input from it's sink pad, and
* returns it in one byte array.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
/* ============================================================ include files */
#include <gst/gst.h>
#include <gst/bytestream/bytestream.h>
/* ================================================================ constants */
/* =================================================================== macros */
G_BEGIN_DECLS
#define LIVESUPPORT_TYPE_ONE_SHOT_READER \
(livesupport_one_shot_reader_get_type())
#define LIVESUPPORT_ONE_SHOT_READER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
LIVESUPPORT_TYPE_ONE_SHOT_READER, \
LivesupportOneShotReader))
#define LIVESUPPORT_ONE_SHOT_READER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
LIVESUPPORT_TYPE_ONE_SHOT_READER, \
LivesupportOneShotReader))
#define GST_IS_ONE_SHOT_READER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), LIVESUPPORT_TYPE_ONE_SHOT_READER))
#define GST_IS_ONE_SHOT_READER_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass), LIVESUPPORT_TYPE_ONE_SHOT_READER))
/* =============================================================== data types */
typedef struct _LivesupportOneShotReader LivesupportOneShotReader;
typedef struct _LivesupportOneShotReaderClass LivesupportOneShotReaderClass;
/**
* The OneShotReader structure.
*/
struct _LivesupportOneShotReader {
GstElement parent;
GstPad * sinkpad;
GstByteStream * bytestream;
gboolean processed;
guint8 * contents;
guint32 length;
};
/**
* The class of the OneShotReader.
*/
struct _LivesupportOneShotReaderClass {
GstElementClass parent_class;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
/**
* The plugin initialization function.
*
* @param plugin the plugin itself.
* @return TRUE if initialization was successful, FALSE otherwise.
*/
static gboolean
plugin_init(GstPlugin * plugin);
/**
* Return the appropriate type for the element.
*
* @return the type structure of the element.
*/
GType
livesupport_one_shot_reader_get_type(void);
G_END_DECLS
#endif /* LivesSupport_GstreamerElements_OneShotReader_h */

View file

@ -0,0 +1,462 @@
/*------------------------------------------------------------------------------
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/partial-play.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include <gst/gst.h>
#include "partial-play.h"
#include "smil-util.h"
/* =================================================== local data structures */
/**
* The arguments this element supports.
*/
enum {
ARG_0,
ARG_LOCATION,
ARG_CONFIG
};
/**
* The factory for the source pad.
*/
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE (
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS("audio/x-raw-int, "
"width = (int) 16, "
"depth = (int) 16, "
"endianness = (int) BYTE_ORDER, "
"channels = (int) { 1, 2 }, "
"rate = (int) [ 8000, 96000 ]")
);
/**
* The parent class of PartialPlay.
*/
static GstBinClass * parent_class = NULL;
/**
* The plugin definition structure.
*/
GST_PLUGIN_DEFINE (
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"partialplay",
"Partial play",
plugin_init,
"$Revision: 1.1 $",
"GPL",
"LiveSupport",
"http://livesupport.campware.org/"
)
/* ================================================ local constants & macros */
/* =============================================== local function prototypes */
/**
* Initializer function for the PartialPlay class.
*
* @para klass the class to initialize.
*/
static void
livesupport_partial_play_class_init(LivesupportPartialPlayClass * klass);
/**
* Base initializer for the PartialPlay plugin.
*
* @param klass the PartialPlay class.
*/
static void
livesupport_partial_play_base_init(LivesupportPartialPlayClass * klass);
/**
* PartialPlay instance initializer.
*
* @param pplay the PartialPlay object to initialize.
*/
static void
livesupport_partial_play_init(LivesupportPartialPlay * pplay);
/**
* Set a property for a PartialPlay object.
*
* @param object the PartialPlay object.
* @param prop_id the property id.
* @param value the value to set.
* @param pspec the property specification
*/
static void
livesupport_partial_play_set_property(GObject * object,
guint prop_id,
const GValue * value,
GParamSpec * pspec);
/**
* Get a property from a PartialPlay object.
*
* @param object the PartialPlay object.
* @param prop_id the property id.
* @param value the value to return the property in (out parameter).
* @param pspec the property specification.
*/
static void
livesupport_partial_play_get_property(GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec);
/**
* Return the type structure for the PartialPlay plugin.
*
* @return the type structure for the PartialPlay plugin.
*/
GType
livesupport_partial_play_get_type(void);
/**
* Handle the state change on a PartialPlay object.
*
* @param element the PartialPlay object.
* @return GST_STATE_SUCCES if the state change was successful,
* GST_STATE_FAILURE on failure.
*/
static GstElementStateReturn
livesupport_partial_play_change_state(GstElement * element);
/**
* Update the source configration for a PartialPlay object.
* This should be called after each update to the config string.
*
* @param pplay the partial play object.
*/
static void
update_source_config(LivesupportPartialPlay * pplay);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Return the type structure for the PartialPlay plugin.
*----------------------------------------------------------------------------*/
GType
livesupport_partial_play_get_type(void)
{
static GType plugin_type = 0;
if (!plugin_type) {
static const GTypeInfo plugin_info = {
sizeof (LivesupportPartialPlayClass),
(GBaseInitFunc) livesupport_partial_play_base_init,
NULL,
(GClassInitFunc) livesupport_partial_play_class_init,
NULL,
NULL,
sizeof (LivesupportPartialPlay),
0,
(GInstanceInitFunc) livesupport_partial_play_init,
};
plugin_type = g_type_register_static(GST_TYPE_BIN,
"LivesupportPartialPlay",
&plugin_info, 0);
}
return plugin_type;
}
/*------------------------------------------------------------------------------
* Handle the state change for a partial play object.
*----------------------------------------------------------------------------*/
static GstElementStateReturn
livesupport_partial_play_change_state(GstElement * element)
{
LivesupportPartialPlay * pplay;
pplay = LIVESUPPORT_PARTIAL_PLAY(element);
switch (GST_STATE_TRANSITION (element)) {
case GST_STATE_NULL_TO_READY:
break;
case GST_STATE_READY_TO_PAUSED:
livesupport_seek_pack_set_state(pplay->seekPack, GST_STATE_PAUSED);
break;
case GST_STATE_PAUSED_TO_PLAYING:
if (!pplay->seekPackInited) {
pplay->seekPackInited = TRUE;
if (pplay->source) {
g_object_unref(pplay->source);
}
/* TODO: check for NULL returns here */
pplay->source = gst_element_factory_make("filesrc", "source");
g_object_set(G_OBJECT(pplay->source),
"location",
pplay->location,
NULL);
livesupport_seek_pack_init(pplay->seekPack,
pplay->source,
pplay->silenceDuration,
pplay->playFrom,
pplay->playTo);
}
livesupport_seek_pack_set_state(pplay->seekPack, GST_STATE_PLAYING);
break;
case GST_STATE_PLAYING_TO_PAUSED:
livesupport_seek_pack_set_state(pplay->seekPack, GST_STATE_PAUSED);
break;
case GST_STATE_PAUSED_TO_READY:
livesupport_seek_pack_set_state(pplay->seekPack, GST_STATE_READY);
/* TODO: maybe de-init seekPack somehow? */
break;
case GST_STATE_READY_TO_NULL:
break;
default:
break;
}
if (GST_ELEMENT_CLASS(parent_class)->change_state) {
return GST_ELEMENT_CLASS(parent_class)->change_state(element);
}
return GST_STATE_SUCCESS;
}
/*------------------------------------------------------------------------------
* Do base initialization.
*----------------------------------------------------------------------------*/
static void
livesupport_partial_play_base_init(LivesupportPartialPlayClass * klass)
{
static GstElementDetails plugin_details = {
"PartialPlay",
"Audio/PartialPlay",
"A filter that plays an audio source partially",
"Akos Maroy <maroy@campware.org>"
};
GstElementClass * element_class = GST_ELEMENT_CLASS(klass);
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&src_factory));
gst_element_class_set_details(element_class, &plugin_details);
}
/*------------------------------------------------------------------------------
* Initialize the plugin's class
*----------------------------------------------------------------------------*/
static void
livesupport_partial_play_class_init(LivesupportPartialPlayClass * klass)
{
GObjectClass * gobject_class;
GstElementClass * gstelement_class;
gobject_class = (GObjectClass*) klass;
gstelement_class = (GstElementClass*) klass;
parent_class = g_type_class_ref(GST_TYPE_BIN);
g_object_class_install_property(gobject_class,
ARG_LOCATION,
g_param_spec_string("location",
"Location",
"Location of the file to read",
"",
G_PARAM_READWRITE));
g_object_class_install_property(gobject_class,
ARG_CONFIG,
g_param_spec_string("config",
"Play configuration",
"specify the silence and play details",
"",
G_PARAM_READWRITE));
gobject_class->set_property = livesupport_partial_play_set_property;
gobject_class->get_property = livesupport_partial_play_get_property;
gstelement_class->change_state = livesupport_partial_play_change_state;
}
/*------------------------------------------------------------------------------
* Initialize a new PartialPlay element.
*----------------------------------------------------------------------------*/
static void
livesupport_partial_play_init(LivesupportPartialPlay * pplay)
{
pplay->seekPack = livesupport_seek_pack_new("seekPack");
pplay->seekPackInited = FALSE;
livesupport_seek_pack_add_to_bin(pplay->seekPack, GST_BIN(pplay));
pplay->srcpad = gst_element_add_ghost_pad(GST_ELEMENT(pplay),
gst_element_get_pad(pplay->seekPack->bin, "src"),
"src");
/* TODO: free these strings when disposing of the object */
pplay->location = g_strdup("");
pplay->config = g_strdup("");
pplay->silenceDuration = 0LL;
pplay->playFrom = 0LL;
pplay->playTo = 0LL;
}
/*------------------------------------------------------------------------------
* Update the source config.
*----------------------------------------------------------------------------*/
static void
update_source_config(LivesupportPartialPlay * pplay)
{
gchar ** tokens;
gchar * token;
guint i = 0;
tokens = g_strsplit(pplay->config, ";", 0);
if ((token = tokens[i++])) {
pplay->silenceDuration = smil_clock_value_to_nanosec(token);
}
if ((token = tokens[i++])) {
gint len = strlen(token);
gchar * from = g_malloc(sizeof(gchar) * len + 1);
gchar * to = g_malloc(sizeof(gchar) * len + 1);
if (sscanf(token, "%[^-]-%s", from, to) == 2) {
pplay->playFrom = smil_clock_value_to_nanosec(from);
pplay->playTo = smil_clock_value_to_nanosec(to);
}
g_free(to);
g_free(from);
}
g_strfreev(tokens);
}
/*------------------------------------------------------------------------------
* Set a property.
*----------------------------------------------------------------------------*/
static void
livesupport_partial_play_set_property(GObject * object,
guint prop_id,
const GValue * value,
GParamSpec * pspec)
{
LivesupportPartialPlay * pplay;
g_return_if_fail(LIVESUPPORT_IS_PARTIAL_PLAY(object));
pplay = LIVESUPPORT_PARTIAL_PLAY(object);
switch (prop_id) {
case ARG_LOCATION:
if (pplay->location) {
g_free(pplay->location);
}
pplay->location = g_strdup(g_value_get_string(value));
break;
case ARG_CONFIG:
if (pplay->config) {
g_free(pplay->config);
}
pplay->config = g_strdup(g_value_get_string(value));
update_source_config(pplay);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
/*------------------------------------------------------------------------------
* Get a property.
*----------------------------------------------------------------------------*/
static void
livesupport_partial_play_get_property(GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec)
{
LivesupportPartialPlay * pplay;
g_return_if_fail(LIVESUPPORT_IS_PARTIAL_PLAY(object));
pplay = LIVESUPPORT_PARTIAL_PLAY(object);
switch (prop_id) {
case ARG_LOCATION:
g_value_set_string(value, pplay->location);
break;
case ARG_CONFIG:
g_value_set_string(value, pplay->config);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
/*------------------------------------------------------------------------------
* Initialize the plugin.
*----------------------------------------------------------------------------*/
static gboolean
plugin_init(GstPlugin * plugin)
{
return gst_element_register(plugin,
"partialplay",
GST_RANK_NONE,
LIVESUPPORT_TYPE_PARTIAL_PLAY);
}

View file

@ -0,0 +1,134 @@
/*------------------------------------------------------------------------------
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/partial-play.h,v $
------------------------------------------------------------------------------*/
#ifndef LivesSupport_GstreamerElements_PartialPlay_h
#define LivesSupport_GstreamerElements_PartialPlay_h
/**
* @file
* A gstreamer element that plays its source partially, first by playing
* some specified silence, then playing the source from a specified
* offset until a specified offset.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
/* ============================================================ include files */
#include <gst/gst.h>
#include "seek-pack.h"
/* ================================================================ constants */
/* =================================================================== macros */
G_BEGIN_DECLS
#define LIVESUPPORT_TYPE_PARTIAL_PLAY \
(livesupport_partial_play_get_type())
#define LIVESUPPORT_PARTIAL_PLAY(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
LIVESUPPORT_TYPE_PARTIAL_PLAY, \
LivesupportPartialPlay))
#define LIVESUPPORT_PARTIAL_PLAY_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
LIVESUPPORT_TYPE_PARTIAL_PLAY, \
LivesupportPartialPlay))
#define LIVESUPPORT_IS_PARTIAL_PLAY(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
LIVESUPPORT_TYPE_PARTIAL_PLAY))
#define LIVESUPPORT_IS_PARTIAL_PLAY_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),LIVESUPPORT_TYPE_PARTIAL_PLAY))
/* =============================================================== data types */
typedef struct _LivesupportPartialPlay LivesupportPartialPlay;
typedef struct _LivesupportPartialPlayClass LivesupportPartialPlayClass;
/**
* The PartialPlay structure.
*/
struct _LivesupportPartialPlay
{
GstBin parent;
GstPad * srcpad;
GstElement * source;
LivesupportSeekPack * seekPack;
gboolean seekPackInited;
gchar * location;
gchar * config;
gint64 silenceDuration;
gint64 playFrom;
gint64 playTo;
};
/**
* The PartialPlay class.
*/
struct _LivesupportPartialPlayClass
{
GstBinClass parent_class;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
/**
* Initilize (register, etc.) the plugin.
*
* @param plugin the plugin itself.
* @return TRUE if initialization was successful, FALSE otherwise.
*/
static gboolean
plugin_init(GstPlugin * plugin);
/**
* Return the appropriate type for the element.
*
* @return the type structure of the element.
*/
GType livesupport_partial_play_get_type(void);
G_END_DECLS
#endif /* LivesSupport_GstreamerElements_PartialPlay_h */

View file

@ -0,0 +1,345 @@
/*------------------------------------------------------------------------------
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/seek-pack.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include <gst/gst.h>
#include "seek.h"
#include "seek-pack.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
#define NSEC_PER_SEC 1000000000LL
#define SEC_PER_MIN 60
#define SEC_PER_HOUR 3600
#define NSEC_PER_SEC_FLOAT 1000000000.0
#define SEC_PER_MIN_FLOAT 60.0
#define SEC_PER_HOUR_FLOAT 3600.0
/* =============================================== local function prototypes */
/**
* Perform the seeks on the SeekPack, set by the initialization function.
*
* @param seekPack the SeekPack to perform the seek on.
* @see #livesupport_seek_pack_init
*/
static void
livesupport_seek_pack_seek(LivesupportSeekPack * seekPack);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Create a new SeekPack.
*----------------------------------------------------------------------------*/
LivesupportSeekPack *
livesupport_seek_pack_new(const gchar * uniqueName)
{
unsigned int len = strlen(uniqueName) + 64;
gchar * str = g_malloc(len);
LivesupportSeekPack * seekPack = g_malloc(sizeof(LivesupportSeekPack));
g_snprintf(str, len, "%s_seekPackSilence", uniqueName);
seekPack->silence = gst_element_factory_make("silence", str);
g_snprintf(str, len, "%s_seekPackAudioConvert", uniqueName);
seekPack->audioconvert = gst_element_factory_make("audioconvert", str);
seekPack->source = NULL;
/* TODO: typefind, and create Ogg Vorbis parser/decoder */
seekPack->parser = NULL;
g_snprintf(str, len, "%s_seekPackDecoder", uniqueName);
seekPack->decoder = gst_element_factory_make("mad", str);
g_snprintf(str, len, "%s_seekPackSwitch", uniqueName);
seekPack->switchElement = gst_element_factory_make("switch", str);
g_snprintf(str, len, "%s_seekPackSwitcher", uniqueName);
seekPack->switcher = gst_element_factory_make("switcher", str);
g_snprintf(str, len, "%s_seekPackBin", uniqueName);
seekPack->bin = gst_bin_new(str);
g_free(str);
seekPack->silenceDuration = 0LL;
seekPack->startTime = 0LL;
seekPack->endTime = 0LL;
seekPack->duration = 0LL;
seekPack->positionAfterSeek = 0LL;
seekPack->realEndTime = 0LL;
seekPack->sendingSilence = TRUE;
gst_element_link_many(seekPack->silence,
seekPack->audioconvert,
seekPack->switchElement,
seekPack->switcher,
NULL);
/* put all inside the bin, and link up a ghost pad to switch's src pad */
gst_bin_add_many(GST_BIN(seekPack->bin),
seekPack->silence,
seekPack->audioconvert,
seekPack->switchElement,
seekPack->switcher,
NULL);
gst_element_add_ghost_pad(seekPack->bin,
gst_element_get_pad(seekPack->switcher, "src"),
"src");
return seekPack;
}
/*------------------------------------------------------------------------------
* Initialize a SeekPack.
*----------------------------------------------------------------------------*/
void
livesupport_seek_pack_init(LivesupportSeekPack * seekPack,
GstElement * source,
gint64 silenceDuration,
gint64 startTime,
gint64 endTime)
{
GValue gvalue = { 0 };
gchar str[256];
seekPack->source = source;
seekPack->silenceDuration = silenceDuration;
seekPack->startTime = startTime;
seekPack->endTime = endTime;
seekPack->duration = endTime - startTime;
seekPack->positionAfterSeek = 0LL;
seekPack->realEndTime = 0LL;
g_value_init(&gvalue, G_TYPE_STRING);
g_snprintf(str, 256, "0[%lfs];1[%lfs]",
seekPack->silenceDuration / NSEC_PER_SEC_FLOAT,
seekPack->duration / NSEC_PER_SEC_FLOAT);
g_value_set_string(&gvalue, str);
gst_element_set_property(seekPack->switcher, "source-config", &gvalue);
gst_element_link(seekPack->source, seekPack->decoder);
livesupport_seek_pack_seek(seekPack);
gst_element_link(seekPack->decoder, seekPack->switchElement);
gst_bin_add_many(GST_BIN(seekPack->bin),
seekPack->source,
seekPack->decoder,
NULL);
}
/*------------------------------------------------------------------------------
* Destroy a SeekPack.
*----------------------------------------------------------------------------*/
void
livesupport_seek_pack_destroy(LivesupportSeekPack * seekPack)
{
gst_element_set_state(seekPack->bin, GST_STATE_NULL);
g_object_unref(seekPack->bin);
g_free(seekPack);
}
/*------------------------------------------------------------------------------
* Link a SeekPack to another element.
*----------------------------------------------------------------------------*/
gboolean
livesupport_seek_pack_link(LivesupportSeekPack * seekPack,
GstElement * element)
{
return gst_element_link(seekPack->bin, element);
}
/*------------------------------------------------------------------------------
* Add a SeekPack to a bin.
*----------------------------------------------------------------------------*/
void
livesupport_seek_pack_add_to_bin(LivesupportSeekPack * seekPack,
GstBin * bin)
{
/* put an extra ref on our elements, as the bin will decrease the
* ref when they are removed from there */
g_object_ref(seekPack->bin);
gst_bin_add(bin, seekPack->bin);
}
/*------------------------------------------------------------------------------
* Remove a SeekPack from a bin.
*----------------------------------------------------------------------------*/
void
livesupport_seek_pack_remove_from_bin(LivesupportSeekPack * seekPack,
GstBin * bin)
{
gst_bin_remove(bin, seekPack->bin);
}
/*------------------------------------------------------------------------------
* Set the state of a SeekPack.
*----------------------------------------------------------------------------*/
void
livesupport_seek_pack_set_state(LivesupportSeekPack * seekPack,
GstElementState state)
{
/* FIXME: resetting the source from PLAYING state would make it lose
* it's seek position */
gst_element_set_state(seekPack->audioconvert, state);
gst_element_set_state(seekPack->decoder, state);
gst_element_set_state(seekPack->switchElement, state);
}
/*------------------------------------------------------------------------------
* Do the seeking on a SeekPack.
*----------------------------------------------------------------------------*/
static void
livesupport_seek_pack_seek(LivesupportSeekPack * seekPack)
{
GstElement * pipeline;
GstElement * fakesink;
gboolean ret;
gint64 value;
GstSeekType seekType;
seekType = (GstSeekType) (GST_FORMAT_TIME |
GST_SEEK_METHOD_SET |
GST_SEEK_FLAG_FLUSH);
pipeline = gst_pipeline_new("seek_pipeline");
fakesink = gst_element_factory_make("fakesink", "seek_fakesink");
gst_element_link(seekPack->decoder, fakesink);
/* ref the objects we want to keep after pipeline, as it will unref them */
g_object_ref(seekPack->source);
g_object_ref(seekPack->decoder);
gst_bin_add_many(GST_BIN(pipeline),
seekPack->source,
seekPack->decoder,
fakesink,
NULL);
GST_DEBUG("setting seek pipeline to PLAYING state");
gst_element_set_state(seekPack->decoder, GST_STATE_READY);
gst_element_set_state(fakesink, GST_STATE_READY);
gst_element_set_state(pipeline, GST_STATE_PLAYING);
GST_DEBUG("starting to iterate...");
for (value = 0; value == 0 && gst_bin_iterate(GST_BIN(pipeline)); ) {
GstFormat format = GST_FORMAT_DEFAULT;
gst_element_query(fakesink, GST_QUERY_POSITION, &format, &value);
GST_DEBUG("position value: %" G_GINT64_FORMAT, value);
}
GST_DEBUG("seeking on element");
ret = livesupport_seek(seekPack->decoder, seekType, seekPack->startTime);
GST_DEBUG("seek result: %d", ret);
gst_bin_remove_many(GST_BIN(pipeline),
seekPack->source,
seekPack->decoder,
NULL);
gst_element_unlink(seekPack->decoder, fakesink);
gst_object_unref(GST_OBJECT(pipeline));
}
/*------------------------------------------------------------------------------
* Iterate on a SeekPack.
* This will change from silence to the proper audio if needed.
*----------------------------------------------------------------------------*/
gboolean
livesupport_seek_pack_iterate(LivesupportSeekPack * seekPack)
{
gint64 value;
GstFormat format = GST_FORMAT_TIME;
gst_bin_iterate(GST_BIN(seekPack->bin));
if (seekPack->sendingSilence) {
gst_element_query(seekPack->silence,
GST_QUERY_POSITION,
&format,
&value);
if (value >= seekPack->silenceDuration) {
GValue gvalue = { 0 };
g_value_init(&gvalue, G_TYPE_INT);
g_value_set_int(&gvalue, 1);
gst_element_set_property(seekPack->switchElement,
"active-source",
&gvalue);
seekPack->sendingSilence = FALSE;
}
} else {
gst_element_query(seekPack->decoder,
GST_QUERY_POSITION,
&format,
&value);
/* FIXME: this is a workaround, as the seek actually won't get us
* where we asked it to. */
if (!seekPack->realEndTime) {
seekPack->positionAfterSeek = value;
seekPack->realEndTime = value + seekPack->duration;
}
if (value >= seekPack->realEndTime) {
GST_INFO("reached EOS at %" G_GINT64_FORMAT "\n", value);
gst_element_set_eos(seekPack->source);
gst_element_set_eos(seekPack->decoder);
gst_element_set_eos(seekPack->bin);
return FALSE;
}
}
return TRUE;
}

View file

@ -0,0 +1,176 @@
/*------------------------------------------------------------------------------
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/seek-pack.h,v $
------------------------------------------------------------------------------*/
#ifndef SeekPack_h
#define SeekPack_h
/**
* @file
* A SeekPack - a structure that plays a gstreamer source by playing
* some silence and then some specified part of the source.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
/* ============================================================ include files */
#include <gst/gst.h>
#include "seek.h"
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
typedef struct _LivesupportSeekPack LivesupportSeekPack;
/**
* A SeekPack structure.
*/
struct _LivesupportSeekPack {
GstElement * silence;
GstElement * audioconvert;
GstElement * source;
GstElement * parser;
GstElement * decoder;
GstElement * switchElement;
GstElement * switcher;
GstElement * bin;
gint64 silenceDuration;
gint64 startTime;
gint64 endTime;
gint64 duration;
gint64 positionAfterSeek;
gint64 realEndTime;
gboolean sendingSilence;
};
/* ====================================================== function prototypes */
/**
* Create a new SeekPack.
* Initialize the SeekPack before using it, and destroy after it's not
* needed anymore.
*
* @param uniqueName a name unique in the SeekPack's context.
* @return a new SeekPack.
* @see #livesupport_seek_pack_init
* @see #livesupport_seek_pack_destroy
*/
LivesupportSeekPack *
livesupport_seek_pack_new(const gchar * uniqueName);
/**
* Initialize a SeekPack.
*
* @param seekPack the SeekPack to initialize.
* @param source the source the SeekPack will play.
* @param silenceDuration the number of nanoseconds the SeekPack will
* play only silence in the beginning.
* @param startTime the offset at which source will start to play after
* the silence.
* @param endTime the offset until which source will play.
*/
void
livesupport_seek_pack_init(LivesupportSeekPack * seekPack,
GstElement * source,
gint64 silenceDuration,
gint64 startTime,
gint64 endTime);
/**
* Destory a SeekPack.
*
* @param seekPack the SeekPack to destroy.
*/
void
livesupport_seek_pack_destroy(LivesupportSeekPack * seekPack);
/**
* Link a SeekPack to an element.
*
* @param seekPack the SeekPack to link.
* @param element the element to link to.
* @return TRUE if linking was successful, FALSE otherwise.
*/
gboolean
livesupport_seek_pack_link(LivesupportSeekPack * seekPack,
GstElement * element);
/**
* Add a SeekPack to a bin.
*
* @param seekPack the SeekPack to add.
* @param bin the bin to add to.
*/
void
livesupport_seek_pack_add_to_bin(LivesupportSeekPack * seekPack,
GstBin * bin);
/**
* Remove a SeekPack from a bin.
*
* @param seekPack the SeekPack to remove.
* @param bin the bin to remove from.
*/
void
livesupport_seek_pack_remove_from_bin(LivesupportSeekPack * seekPack,
GstBin * bin);
/**
* Set the state of a SeekPack.
*
* @param seekPack the SeekPack to set the state for.
* @param state the new state of the SeekPack.
*/
void
livesupport_seek_pack_set_state(LivesupportSeekPack * seekPack,
GstElementState state);
/**
* Iterate on the seekpack.
*
* @param seekPack the SeekPack to iterate on.
*/
gboolean
livesupport_seek_pack_iterate(LivesupportSeekPack * seekPack);
#endif /* SeekPack_h */

View file

@ -0,0 +1,200 @@
/*------------------------------------------------------------------------------
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/seek.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#include "seek.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/**
* Define PAD_PUSH if seeking on an src pad should be done with
* pushin a new seek event down the pad.
* Otherwise, the event will be sent normally.
*/
#undef PAD_PUSH
/**
* Define SEEK_ELEMENT if seeking should be done by seeking on an element
* itself. Otherwise, the seek will be done on the first src pad of
* the element.
*/
#undef SEEK_ELEMENT
/* =============================================== local function prototypes */
#ifdef SEEK_ELEMENT
/**
* Seek on an element.
*
* @param element the element to seek on.
* @param seekType the type of seek.
* @param seekTime the seek time in nanoseconds.
* @return TRUE if seeking was successfult, FALSE otherwise.
*/
static gboolean
seek_element(GstElement * element,
GstSeekType seekType,
gint64 seekTime);
#endif
#ifndef SEEK_ELEMENT
/**
* Return the first src pad for an element.
*
* @param element the element to return the pad from.
* @return the first src pad for element, or NULL.
*/
static GstPad *
get_src_pad(GstElement * element);
#endif
#ifndef SEEK_ELEMENT
/**
* Seek on the first src pad of an element.
*
* @param element the element to seek on.
* @param seekType the type of seek.
* @param seekTime the time of seek, in nanoseconds.
* @return TRUE if seeking was successfult, FALSE otherwise.
*/
static gboolean
seek_src_pad(GstElement * element,
GstSeekType seekType,
gint64 seekTime);
#endif
/* ============================================================= module code */
#ifdef SEEK_ELEMENT
/*------------------------------------------------------------------------------
* Seek on an element.
*----------------------------------------------------------------------------*/
static gboolean
seek_element(GstElement * element,
GstSeekType seekType,
gint64 seekTime)
{
return gst_element_seek(element, seekType, seekTime);
}
#endif
#ifndef SEEK_ELEMENT
/*------------------------------------------------------------------------------
* Return the first src pad for an element.
*----------------------------------------------------------------------------*/
static GstPad *
get_src_pad(GstElement * element)
{
const GList * pads;
for (pads = gst_element_get_pad_list(element);
pads;
pads = g_list_next(pads)) {
GstPad * pad = pads->data;
if (GST_PAD_IS_SRC(pad)) {
return pad;
}
}
return 0;
}
#endif
#ifndef SEEK_ELEMENT
/*------------------------------------------------------------------------------
* Seek on the first src pad of an element.
*----------------------------------------------------------------------------*/
static gboolean
seek_src_pad(GstElement * element,
GstSeekType seekType,
gint64 seekTime)
{
GstPad * pad;
GstEvent * seek;
if ((pad = get_src_pad(element))) {
seek = gst_event_new_seek(seekType, seekTime);
#ifdef PAD_PUSH
gst_pad_push(pad, GST_DATA(seek));
return TRUE;
#else
return gst_pad_send_event(pad, seek);
#endif
}
GST_WARNING("element doesn't have a src pad");
return FALSE;
}
#endif
/*------------------------------------------------------------------------------
* Seek on an element.
*----------------------------------------------------------------------------*/
gboolean
livesupport_seek(GstElement * element,
GstSeekType seekType,
gint64 seekTime)
{
#ifdef SEEK_ELEMENT
return seek_element(element, seekType, seekTime);
#else
return seek_src_pad(element, seekType, seekTime);
#endif
}
/*------------------------------------------------------------------------------
* Helper function to make it easy to seek for a number of seconds.
*----------------------------------------------------------------------------*/
gboolean
livesupport_seek_seconds(GstElement * element,
gint64 seconds)
{
GstSeekType seekType;
gint64 seekTime;
seekType = (GstSeekType) (GST_FORMAT_TIME |
GST_SEEK_METHOD_SET |
GST_SEEK_FLAG_FLUSH);
seekTime = seconds * GST_SECOND;
return livesupport_seek(element, seekType, seekTime);
}

View file

@ -0,0 +1,83 @@
/*------------------------------------------------------------------------------
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/seek.h,v $
------------------------------------------------------------------------------*/
#ifndef Seek_h
#define Seek_h
/**
* @file
* Utility functions to help seeking in gstreamer elements.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
/* ============================================================ include files */
#include <gst/gst.h>
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/* ====================================================== function prototypes */
/**
* Seek on an element.
*
* @param element the element to seek on.
* @param seekType the type of seek.
* @param seekTime the time of seek, in nanoseconds.
* @return TRUE if the seek was successful, FALSE otherwise.
*/
gboolean
livesupport_seek(GstElement * element,
GstSeekType seekType,
gint64 seekTime);
/**
* Seek a number of seconds on an element.
*
* @param element the element to seek on.
* @param seconds the number of seconds to seek.
* @return TRUE if the seek was successful, FALSE otherwise.
*/
gboolean
livesupport_seek_seconds(GstElement * element,
gint64 seconds);
#endif /* Seek_h */

View file

@ -0,0 +1,154 @@
/*------------------------------------------------------------------------------
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/smil-util.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "smil-util.h"
/* =================================================== local data structures */
/* ================================================ local constants & macros */
#define NSEC_PER_SEC 1000000000LL
#define SEC_PER_MIN 60
#define SEC_PER_HOUR 3600
#define NSEC_PER_SEC_FLOAT 1000000000.0
#define SEC_PER_MIN_FLOAT 60.0
#define SEC_PER_HOUR_FLOAT 3600.0
/* =============================================== local function prototypes */
/**
* Convert an hour - minute - second triplet into a nanosecond value.
*
* @param hours the number of hours
* @param minutes the number of minutes (may be more than 59)
* @param seconds the number of seconds (may be mora than 59)
* @return the supplied time in nanoseconds
*/
static gint64
hms_to_nanosec(int hours,
int minutes,
double seconds);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Convert a hour-minute-second triplet to nanoseconds
*----------------------------------------------------------------------------*/
static gint64
hms_to_nanosec(int hours,
int minutes,
double seconds)
{
gint64 nanosec;
double nsec;
nsec = seconds * NSEC_PER_SEC_FLOAT;
nanosec = (gint64) nsec;
nanosec += ((gint64) hours) * NSEC_PER_SEC;
nanosec += ((gint64) minutes) * SEC_PER_MIN * NSEC_PER_SEC;
return nanosec;
}
/*------------------------------------------------------------------------------
* Parse the clock value according to the SMIL clock spec
*
* see http://www.w3.org/TR/2005/REC-SMIL2-20050107/smil-timing.html#Timing-ClockValueSyntax
*
* the BNF for the value is:
*
* Clock-value ::= ( Full-clock-value | Partial-clock-value
* | Timecount-value )
* Full-clock-value ::= Hours ":" Minutes ":" Seconds ("." Fraction)?
* Partial-clock-value ::= Minutes ":" Seconds ("." Fraction)?
* Timecount-value ::= Timecount ("." Fraction)? (Metric)?
* Metric ::= "h" | "min" | "s" | "ms"
* Hours ::= DIGIT+; any positive number
* Minutes ::= 2DIGIT; range from 00 to 59
* Seconds ::= 2DIGIT; range from 00 to 59
* Fraction ::= DIGIT+
* Timecount ::= DIGIT+
* 2DIGIT ::= DIGIT DIGIT
* DIGIT ::= [0-9]
*----------------------------------------------------------------------------*/
gint64
smil_clock_value_to_nanosec(const gchar * value)
{
int hours;
int minutes;
double seconds;
/* see if it's a full-clock-value */
if (sscanf(value, "%2d:%2d:%lf", &hours, &minutes, &seconds) == 3) {
return hms_to_nanosec(hours, minutes, seconds);
}
/* see if it's a partial-clock-value */
if (sscanf(value, "%2d:%lf", &minutes, &seconds) == 2) {
return hms_to_nanosec(0, minutes, seconds);
}
/* see if it's a timecount-value, in hours */
if (g_str_has_suffix(value, "h")
&& sscanf(value, "%lfh", &seconds) == 1) {
return hms_to_nanosec(0, 0, seconds * SEC_PER_HOUR_FLOAT);
}
/* see if it's a timecount-value, in minutes */
if (g_str_has_suffix(value, "min")
&& sscanf(value, "%lfmin", &seconds) == 1) {
return hms_to_nanosec(0, 0, seconds * SEC_PER_MIN_FLOAT);
}
/* see if it's a timecount-value, in millisecs */
if (g_str_has_suffix(value, "ms")
&& sscanf(value, "%lfms", &seconds) == 1) {
return hms_to_nanosec(0, 0, seconds / 100.0);
}
/* it's a timecount-value, either with no metric, or explicit seconds */
if (sscanf(value, "%lfs", &seconds) == 1) {
return hms_to_nanosec(0, 0, seconds);
}
return -1LL;
}

View file

@ -0,0 +1,88 @@
/*------------------------------------------------------------------------------
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/smil-util.h,v $
------------------------------------------------------------------------------*/
#ifndef SmilUtil_h
#define SmilUtil_h
/**
* @file
* Utility functions helping to work with SMIL-related data structures.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
/* ============================================================ include files */
#include <gst/gst.h>
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/* ====================================================== function prototypes */
/**
* Parse the clock value according to the SMIL clock spec
*
* see http://www.w3.org/TR/2005/REC-SMIL2-20050107/smil-timing.html#Timing-ClockValueSyntax
*
* the BNF for the value is:
*
* <pre><code>
* Clock-value ::= ( Full-clock-value | Partial-clock-value
* | Timecount-value )
* Full-clock-value ::= Hours ":" Minutes ":" Seconds ("." Fraction)?
* Partial-clock-value ::= Minutes ":" Seconds ("." Fraction)?
* Timecount-value ::= Timecount ("." Fraction)? (Metric)?
* Metric ::= "h" | "min" | "s" | "ms"
* Hours ::= DIGIT+; any positive number
* Minutes ::= 2DIGIT; range from 00 to 59
* Seconds ::= 2DIGIT; range from 00 to 59
* Fraction ::= DIGIT+
* Timecount ::= DIGIT+
* 2DIGIT ::= DIGIT DIGIT
* DIGIT ::= [0-9]
* </code></pre>
*
* @param value the SMIL clock value in string form
* @return the clock value in nanoseconds
*/
gint64
smil_clock_value_to_nanosec(const gchar * value);
#endif /* SmilUtil_h */

View file

@ -0,0 +1,593 @@
/*------------------------------------------------------------------------------
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/switcher.c,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#else
#error need string.h
#endif
#include <gst/gst.h>
#include "switcher.h"
#include "smil-util.h"
/* =================================================== local data structures */
/**
* The properties of the Switcher element.
*/
enum {
ARG_0,
ARG_SOURCE_CONFIG
};
/**
* The plugin registry definition.
*/
GST_PLUGIN_DEFINE (
GST_VERSION_MAJOR,
GST_VERSION_MINOR,
"switcher",
"A filter that connects to a swtich, and changes its source",
plugin_init,
"$Revision: 1.1 $",
"GPL",
"LiveSupport",
"http://livesupport.campware.org/"
)
/* ================================================ local constants & macros */
/**
* The parent class of the Switcher class.
*/
static GstElementClass * parent_class = NULL;
/**
* The sink pad factory.
*/
static GstStaticPadTemplate sink_factory = GST_STATIC_PAD_TEMPLATE(
"sink",
GST_PAD_SINK,
GST_PAD_ALWAYS,
GST_STATIC_CAPS("ANY"));
/**
* The source pad factory.
*/
static GstStaticPadTemplate src_factory = GST_STATIC_PAD_TEMPLATE(
"src",
GST_PAD_SRC,
GST_PAD_ALWAYS,
GST_STATIC_CAPS("ANY"));
/* =============================================== local function prototypes */
/**
* Initialize the Switcher class.
*
* @param klass the class to initialize
*/
static void
livesupport_switcher_class_init(LivesupportSwitcherClass * klass);
/**
* Base initialization for Switcher objects.
*
* @param klass a Switcher class
*/
static void
livesupport_switcher_base_init(LivesupportSwitcherClass * klass);
/**
* Initialize a Switcher object.
*
* @param switcher the Switcher object to initialize.
*/
static void
livesupport_switcher_init(LivesupportSwitcher * switcher);
/**
* Set a property on a Switcher object.
*
* @param object a Switcher object
* @param prop_id the property id
* @param value the value to set
* @param pspec the property specification
*/
static void
livesupport_switcher_set_property(GObject * object,
guint prop_id,
const GValue * value,
GParamSpec * pspec);
/**
* Get a property from a Switcher object.
*
* @param object a Switcher object.
* @param prop_id the property id
* @param value the requested property (an out parameter)
* @param pspec the property specification
*/
static void
livesupport_switcher_get_property(GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec);
/**
* The main chain function of the Switcher element.
*
* @param pad the pad on which data is received.
* @param in the data recieved.
*/
static void
livesupport_switcher_chain(GstPad * pad,
GstData * in);
/**
* This function handles the link with other plug-ins.
*
* @param pad the pad that is about to be linked.
* @param caps the set of possible linking capabilities
* @return GST_PAD_LINK_OK or GST_PAD_LINK_DONE if linking can be or has
* been done, GST_PAD_LINK_DELAYED if linking can not yet be done,
* GST_PAD_LINK_REFUSED in linking can not be done.
*/
static GstPadLinkReturn
livesupport_switcher_link(GstPad * pad,
const GstCaps * caps);
/**
* Switch to the source next in line.
* Call this function if it's time to switch to the next source.
*
* @param switcher a Switcher object to swtich on.
*/
static void
switch_to_next_source(LivesupportSwitcher * switcher);
/**
* Update the source configuration.
* Call this function when the sourceConfigList string has been updated.
*
* @param switcher a Switcher object to perform the update on.
*/
static void
update_source_config(LivesupportSwitcher * switcher);
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* This function handles the link with other plug-ins.
*----------------------------------------------------------------------------*/
static GstPadLinkReturn
livesupport_switcher_link(GstPad * pad,
const GstCaps * caps)
{
LivesupportSwitcher * filter;
GstPad * otherpad;
filter = LIVESUPPORT_SWITCHER(gst_pad_get_parent(pad));
g_return_val_if_fail(filter != NULL, GST_PAD_LINK_REFUSED);
g_return_val_if_fail(LIVESUPPORT_IS_SWITCHER(filter),
GST_PAD_LINK_REFUSED);
otherpad = (pad == filter->srcpad ? filter->sinkpad : filter->srcpad);
/* set caps on next or previous element's pad, and see what they
* think. In real cases, we would (after this step) extract
* properties from the caps such as video size or audio samplerat. */
return gst_pad_try_set_caps (otherpad, caps);
}
/*------------------------------------------------------------------------------
* Return the type structure for the Switcher plugin.
*----------------------------------------------------------------------------*/
GType
livesupport_switcher_get_type(void)
{
static GType plugin_type = 0;
if (!plugin_type) {
static const GTypeInfo plugin_info = {
sizeof (LivesupportSwitcherClass),
(GBaseInitFunc) livesupport_switcher_base_init,
NULL,
(GClassInitFunc) livesupport_switcher_class_init,
NULL,
NULL,
sizeof (LivesupportSwitcher),
0,
(GInstanceInitFunc) livesupport_switcher_init,
};
plugin_type = g_type_register_static(GST_TYPE_ELEMENT,
"LivesupportSwitcher",
&plugin_info, 0);
}
return plugin_type;
}
/*------------------------------------------------------------------------------
* Do base initialization for the Switcher class.
*----------------------------------------------------------------------------*/
static void
livesupport_switcher_base_init(LivesupportSwitcherClass * klass)
{
static GstElementDetails plugin_details = {
"Switcher",
"Generic/Switcher",
"A plugin that is connected to a switch element, and changes its source",
"Akos Maroy <maroy@campware.org>"
};
GstElementClass * element_class = GST_ELEMENT_CLASS (klass);
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&src_factory));
gst_element_class_add_pad_template(element_class,
gst_static_pad_template_get(&sink_factory));
gst_element_class_set_details(element_class, &plugin_details);
}
/*------------------------------------------------------------------------------
* Initialize the plugin's class.
*----------------------------------------------------------------------------*/
static void
livesupport_switcher_class_init(LivesupportSwitcherClass * klass)
{
GObjectClass * gobject_class;
GstElementClass * gstelement_class;
gobject_class = (GObjectClass*) klass;
gstelement_class = (GstElementClass*) klass;
parent_class = g_type_class_ref(GST_TYPE_ELEMENT);
g_object_class_install_property(gobject_class,
ARG_SOURCE_CONFIG,
g_param_spec_string("source_config",
"source config",
"source config",
"",
G_PARAM_READWRITE));
gobject_class->set_property = livesupport_switcher_set_property;
gobject_class->get_property = livesupport_switcher_get_property;
}
/*------------------------------------------------------------------------------
* Initialize a Switcher object.
*----------------------------------------------------------------------------*/
static void
livesupport_switcher_init(LivesupportSwitcher * switcher)
{
GstElementClass * klass = GST_ELEMENT_GET_CLASS(switcher);
switcher->sinkpad = gst_pad_new_from_template(
gst_element_class_get_pad_template(klass, "sink"),
"sink");
gst_pad_set_link_function(switcher->sinkpad, livesupport_switcher_link);
gst_pad_set_getcaps_function(switcher->sinkpad, gst_pad_proxy_getcaps);
switcher->srcpad = gst_pad_new_from_template (
gst_element_class_get_pad_template(klass, "src"),
"src");
gst_pad_set_link_function(switcher->srcpad, livesupport_switcher_link);
gst_pad_set_getcaps_function(switcher->srcpad, gst_pad_proxy_getcaps);
gst_element_add_pad(GST_ELEMENT(switcher), switcher->sinkpad);
gst_element_add_pad(GST_ELEMENT(switcher), switcher->srcpad);
gst_pad_set_chain_function(switcher->sinkpad, livesupport_switcher_chain);
switcher->elapsedTime = 0LL;
switcher->nextOffset = 0LL;
switcher->eos = FALSE;
/* TODO: dispose of the config string and list later */
switcher->sourceConfig = 0;
switcher->sourceConfigList = NULL;
}
/*------------------------------------------------------------------------------
* Switch to the source next in line.
*----------------------------------------------------------------------------*/
static void
switch_to_next_source(LivesupportSwitcher * switcher)
{
LivesupportSwitcherSourceConfig * oldConfig;
LivesupportSwitcherSourceConfig * newConfig;
oldConfig = (LivesupportSwitcherSourceConfig*)
switcher->currentConfig->data;
if ((switcher->currentConfig = g_list_next(switcher->currentConfig))) {
GValue gvalue = { 0 };
GstElement * switchElement;
GST_INFO("switching from source %d, duration: %" G_GINT64_FORMAT,
oldConfig->sourceId, oldConfig->duration);
newConfig = (LivesupportSwitcherSourceConfig*)
switcher->currentConfig->data;
switchElement = GST_PAD_PARENT(GST_PAD_PEER(switcher->sinkpad));
g_value_init(&gvalue, G_TYPE_INT);
g_value_set_int(&gvalue, newConfig->sourceId);
gst_element_set_property(switchElement, "active-source", &gvalue);
switcher->nextOffset = oldConfig->duration >= 0
? switcher->nextOffset + newConfig->duration
: switcher->elapsedTime + newConfig->duration;
} else {
/* mark EOS, as there are no more sources to switch to */
switcher->eos = TRUE;
}
}
/*------------------------------------------------------------------------------
* The main chain function.
*----------------------------------------------------------------------------*/
static void
livesupport_switcher_chain(GstPad * pad,
GstData * in)
{
LivesupportSwitcher * switcher;
GstBuffer * buf;
LivesupportSwitcherSourceConfig * config = NULL;
g_return_if_fail(GST_IS_PAD(pad));
g_return_if_fail(in != NULL);
switcher = LIVESUPPORT_SWITCHER(GST_OBJECT_PARENT(pad));
g_return_if_fail(LIVESUPPORT_IS_SWITCHER(switcher));
if (switcher->eos) {
GstElement * parent;
GstEvent * event;
GST_DEBUG("switcher_chain: eos");
/* push an EOS event down the srcpad, just to make sure */
event = gst_event_new(GST_EVENT_EOS);
gst_pad_send_event(switcher->srcpad, event);
gst_element_set_eos(GST_ELEMENT(switcher));
parent = GST_ELEMENT(gst_element_get_parent(GST_ELEMENT(switcher)));
if (parent) {
gst_element_set_eos(parent);
}
/* TODO: fix this mess here... */
/*
for (parent =
GST_ELEMENT(gst_element_get_parent(GST_ELEMENT(switcher)));
parent;
parent = GST_ELEMENT(gst_element_get_parent(parent))) {
GST_DEBUG("switcher_chain: eos #1.1");
gst_element_set_eos(parent);
}
*/
return;
}
if (switcher->currentConfig == NULL) {
switcher->currentConfig = g_list_first(switcher->sourceConfigList);
config = (LivesupportSwitcherSourceConfig*)
switcher->currentConfig->data;
switcher->nextOffset = config->duration;
} else {
config = (LivesupportSwitcherSourceConfig*)
switcher->currentConfig->data;
}
if (config->duration < 0) {
/* handle config->duration == -1LL (play until EOS) */
if (GST_IS_EVENT(in)) {
GstEvent * event = GST_EVENT(in);
if (GST_EVENT_TYPE(event) == GST_EVENT_EOS) {
switch_to_next_source(switcher);
return;
}
}
}
if (GST_IS_EVENT(in)) {
/* handle events */
GstEvent * event = GST_EVENT(in);
gst_pad_event_default(switcher->srcpad, event);
return;
}
buf = GST_BUFFER(in);
if (GST_BUFFER_DURATION(buf) != GST_CLOCK_TIME_NONE) {
switcher->elapsedTime += GST_BUFFER_DURATION(buf);
}
GST_INFO("elapsed time: %" G_GINT64_FORMAT, switcher->elapsedTime);
if (switcher->elapsedTime >= switcher->nextOffset) {
/* time to switch to the next source */
switch_to_next_source(switcher);
}
/* just push out the incoming buffer without touching it */
gst_pad_push(switcher->srcpad, GST_DATA(buf));
}
/*------------------------------------------------------------------------------
* Update the source config.
*----------------------------------------------------------------------------*/
static void
update_source_config(LivesupportSwitcher * switcher)
{
gchar ** tokens;
gchar * token;
guint i = 0;
GList * listElem;
/* first free the config list */
for (listElem = g_list_first(switcher->sourceConfigList);
listElem;
listElem = g_list_next(listElem)) {
g_free(listElem->data);
}
g_list_free(switcher->sourceConfigList);
switcher->sourceConfigList = NULL;
switcher->currentConfig = NULL;
listElem = NULL;
tokens = g_strsplit(switcher->sourceConfig, ";", 0);
while ((token = tokens[i++])) {
gchar * durationStr;
gint len;
LivesupportSwitcherSourceConfig * config;
gboolean found;
len = strlen(token);
durationStr = g_malloc(sizeof(gchar) * len + 1);
config = g_malloc(sizeof(LivesupportSwitcherSourceConfig));
found = FALSE;
/* token formats can be:
*
* id[] play the whole thing, until EOS
* id[duration] play from begin for duration time
*/
if (g_str_has_suffix(token, "[]")
&& sscanf(token, "%d[]", &config->sourceId) == 1) {
config->duration = -1LL;
found = TRUE;
} else if (sscanf(token, "%d[%[^]]]",
&config->sourceId, durationStr) == 2) {
config->duration = smil_clock_value_to_nanosec(durationStr);
found = config->duration >= 0;
}
g_free(durationStr);
if (!found) {
g_free(config);
continue;
}
switcher->sourceConfigList = g_list_append(switcher->sourceConfigList,
config);
listElem = g_list_last(switcher->sourceConfigList);
}
g_strfreev(tokens);
}
/*------------------------------------------------------------------------------
* Set a property.
*----------------------------------------------------------------------------*/
static void
livesupport_switcher_set_property(GObject * object,
guint prop_id,
const GValue * value,
GParamSpec * pspec)
{
LivesupportSwitcher * switcher;
g_return_if_fail(LIVESUPPORT_IS_SWITCHER(object));
switcher = LIVESUPPORT_SWITCHER(object);
switch (prop_id) {
case ARG_SOURCE_CONFIG:
if (switcher->sourceConfig) {
g_free(switcher->sourceConfig);
}
switcher->sourceConfig = g_value_dup_string(value);
update_source_config(switcher);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
/*------------------------------------------------------------------------------
* Get a property.
*----------------------------------------------------------------------------*/
static void
livesupport_switcher_get_property(GObject * object,
guint prop_id,
GValue * value,
GParamSpec * pspec)
{
LivesupportSwitcher * switcher;
g_return_if_fail(LIVESUPPORT_IS_SWITCHER(object));
switcher = LIVESUPPORT_SWITCHER(object);
switch (prop_id) {
case ARG_SOURCE_CONFIG:
g_value_set_string(value, switcher->sourceConfig);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
break;
}
}
/*------------------------------------------------------------------------------
* Initialize the plugin.
*----------------------------------------------------------------------------*/
static gboolean
plugin_init(GstPlugin * plugin)
{
return gst_element_register(plugin,
"switcher",
GST_RANK_NONE,
LIVESUPPORT_TYPE_SWITCHER);
}

View file

@ -0,0 +1,143 @@
/*------------------------------------------------------------------------------
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/switcher.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_GstreamerElements_Switcher_h
#define LiveSupport_GstreamerElements_Switcher_h
/**
* @file
* A gstreamer element that expects to be linked after a switch
* element. The element will switch the active source on the attached
* switcher according to the time positions it is configured with.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
/* ============================================================ include files */
#include <gst/gst.h>
/* ================================================================ constants */
/* =================================================================== macros */
G_BEGIN_DECLS
#define LIVESUPPORT_TYPE_SWITCHER \
(livesupport_switcher_get_type())
#define LIVESUPPORT_SWITCHER(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), \
LIVESUPPORT_TYPE_SWITCHER, \
LivesupportSwitcher))
#define LIVESUPPORT_SWITCHER_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), \
LIVESUPPORT_TYPE_SWITCHER, \
LivesupportSwitcher))
#define LIVESUPPORT_IS_SWITCHER(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), \
LIVESUPPORT_TYPE_SWITCHER))
#define LIVESUPPORT_IS_SWITCHER_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass), \
LIVESUPPORT_TYPE_SWITCHER))
/* =============================================================== data types */
typedef struct _LivesupportSwitcherSourceConfig LivesupportSwitcherSourceConfig;
typedef struct _LivesupportSwitcher LivesupportSwitcher;
typedef struct _LivesupportSwitcherClass LivesupportSwitcherClass;
/**
* A source configuration, describing how long a source should be played
* before switching to the next.
*/
struct _LivesupportSwitcherSourceConfig {
gint sourceId;
gint64 duration;
};
/**
* The Switcher object.
*/
struct _LivesupportSwitcher
{
GstElement element;
GstPad * sinkpad;
GstPad * srcpad;
gint64 elapsedTime;
gint64 nextOffset;
gboolean eos;
gchar * sourceConfig;
GList * sourceConfigList;
GList * currentConfig;
};
/**
* The Switcher class.
*/
struct _LivesupportSwitcherClass
{
GstElementClass parent_class;
};
/* ====================================================== function prototypes */
/**
* Return the type structure for the Switcher class.
*
* @return the type structure for the Switcher class.
*/
GType
livesupport_switcher_get_type(void);
/**
* Initialize the plugin.
*
* @param plugin the plugin to initialize.
*/
static gboolean
plugin_init(GstPlugin * plugin);
G_END_DECLS
#endif /* LiveSupport_GstreamerElements_Switcher_h */

View file

@ -0,0 +1 @@
keep me

View file

@ -0,0 +1 @@
She sells seashells by the seashore.

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<smil xmlns="http://www.w3.org/2001/SMIL20/Language" >
<body>
<par>
<audio src = "file:var/1minutecounter.mp3"
begin = "3s"
clipBegin = "10s"
clipEnd = "15s" />
</par>
</body>
</smil>