added support for the gstreamer playlist executor through the

AudioPlayerFactory
This commit is contained in:
maroy 2005-05-31 10:10:33 +00:00
parent 80dfc3eb4b
commit 2d4e093c3b
9 changed files with 363 additions and 44 deletions

View file

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.11 $
# Version : $Revision: 1.12 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/etc/Makefile.in,v $
#
# @configure_input@
@ -135,7 +135,8 @@ PLAYLIST_EXECUTOR_LIB_OBJS = ${TMP_DIR}/HelixPlayer.o \
TEST_RUNNER_OBJS = ${TMP_DIR}/TestRunner.o \
${TMP_DIR}/GstreamerPlayerTest.o \
${TMP_DIR}/HelixPlayerTest.o \
${TMP_DIR}/AudioPlayerFactoryTest.o
${TMP_DIR}/AudioPlayerFactoryTest.o \
${TMP_DIR}/AudioPlayerFactoryGstreamerTest.o
TEST_RUNNER_LIBS = -l${PLAYLIST_EXECUTOR_LIB} -l${CORE_LIB} \
${HELIX_LIBS} ${TAGLIB_LIBS} \
-lcppunit -ldl -lm -lxmlrpc++

View file

@ -1,13 +1,16 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE audioPlayer [
<!ELEMENT audioPlayer (helixPlayer) >
<!ELEMENT audioPlayer (helixPlayer|gstreamerPlayer) >
<!ELEMENT helixPlayer EMPTY >
<!ATTLIST helixPlayer dllPath CDATA #REQUIRED >
<!ATTLIST helixPlayer audioDevice CDATA #IMPLIED >
<!ATTLIST helixPlayer audioStreamTimeout NMTOKEN #IMPLIED >
<!ATTLIST helixPlayer fadeLookAheatTime NMTOKEN #IMPLIED >
<!ELEMENT gstreamerPlayer EMPTY >
<!ATTLIST gstreamerPlayer audioDevice CDATA #IMPLIED >
]>
<audioPlayer>
<helixPlayer dllPath = "../../usr/lib/helix"

View file

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE audioPlayer [
<!ELEMENT audioPlayer (helixPlayer|gstreamerPlayer) >
<!ELEMENT helixPlayer EMPTY >
<!ATTLIST helixPlayer dllPath CDATA #REQUIRED >
<!ATTLIST helixPlayer audioDevice CDATA #IMPLIED >
<!ATTLIST helixPlayer audioStreamTimeout NMTOKEN #IMPLIED >
<!ATTLIST helixPlayer fadeLookAheatTime NMTOKEN #IMPLIED >
<!ELEMENT gstreamerPlayer EMPTY >
<!ATTLIST gstreamerPlayer audioDevice CDATA #IMPLIED >
]>
<audioPlayer>
<gstreamerPlayer audioDevice = "plughw:0,0" />
</audioPlayer>

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerFactory.h,v $
------------------------------------------------------------------------------*/
@ -81,15 +81,17 @@ using namespace LiveSupport::Core;
* The DTD for the above XML structure is:
*
* <pre><code>
* <!ELEMENT audioPlayer (helixPlayer) >
* <!ELEMENT audioPlayer (helixPlayer|gstreamerPlayer) >
* </code></pre>
*
* For the DTD and details of the helixPlayer configuration
* element, see the HelixPlayer documentation.
* For the DTD and details of the helixPlayer or gstreamerPlayer configuration
* element, see the HelixPlayer or the GstreamerPlayer documentation,
* respectively.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
* @see HelixPlayer
* @see GstreamerPlayer
*/
class AudioPlayerFactory :
virtual public Configurable

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.3 $
Version : $Revision: 1.4 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/AudioPlayerFactory.cxx,v $
------------------------------------------------------------------------------*/
@ -35,6 +35,7 @@
#include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h"
#include "HelixPlayer.h"
#include "GstreamerPlayer.h"
using namespace LiveSupport::Core;
@ -92,20 +93,32 @@ AudioPlayerFactory :: configure(const xmlpp::Element & element)
audioPlayer.reset();
xmlpp::Node::NodeList nodes;
// try to look for a HelixPlayer configuration element
xmlpp::Node::NodeList nodes = element.get_children(
HelixPlayer::getConfigElementName());
nodes = element.get_children(HelixPlayer::getConfigElementName());
if (nodes.size() >= 1) {
const xmlpp::Element * configElement =
dynamic_cast<const xmlpp::Element*> (*(nodes.begin()));
Ptr<HelixPlayer>::Ref hp(new HelixPlayer());
hp->configure(*configElement);
audioPlayer = hp;
return;
}
if (!audioPlayer) {
throw std::invalid_argument("no audio player factories to configure");
nodes = element.get_children(GstreamerPlayer::getConfigElementName());
if (nodes.size() >= 1) {
const xmlpp::Element * configElement =
dynamic_cast<const xmlpp::Element*> (*(nodes.begin()));
Ptr<GstreamerPlayer>::Ref gp(new GstreamerPlayer());
gp->configure(*configElement);
audioPlayer = gp;
return;
}
throw std::invalid_argument("no audio player factories to configure");
}

View file

@ -0,0 +1,184 @@
/*------------------------------------------------------------------------------
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/playlistExecutor/src/AudioPlayerFactoryGstreamerTest.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
#include <string>
#include <iostream>
#include "LiveSupport/Core/TimeConversion.h"
#include "AudioPlayerFactoryGstreamerTest.h"
using namespace LiveSupport::PlaylistExecutor;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(AudioPlayerFactoryGstreamerTest);
/**
* The name of the configuration file for the Helix player.
*/
static const std::string configFileName = "etc/audioPlayerGstreamer.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
AudioPlayerFactoryGstreamerTest :: setUp(void) throw ()
{
try {
Ptr<xmlpp::DomParser>::Ref parser(
new xmlpp::DomParser(configFileName, true));
const xmlpp::Document * document = parser->get_document();
const xmlpp::Element * root = document->get_root_node();
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
audioPlayerFactory = AudioPlayerFactory::getInstance();
audioPlayerFactory->configure(*root);
// initialize the audio player configured by the factory
Ptr<AudioPlayerInterface>::Ref audioPlayer;
audioPlayer = audioPlayerFactory->getAudioPlayer();
audioPlayer->initialize();
} catch (std::invalid_argument &e) {
std::cerr << "semantic error in configuration file" << std::endl;
} catch (xmlpp::exception &e) {
std::cerr << e.what() << std::endl;
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
AudioPlayerFactoryGstreamerTest :: tearDown(void) throw ()
{
try {
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
audioPlayerFactory = AudioPlayerFactory::getInstance();
// de-initialize the audio player configured by the factory
Ptr<AudioPlayerInterface>::Ref audioPlayer;
audioPlayer = audioPlayerFactory->getAudioPlayer();
audioPlayer->deInitialize();
} catch (xmlpp::exception &e) {
std::cerr << e.what() << std::endl;
}
}
/*------------------------------------------------------------------------------
* Test to see if the HelixPlayer engine can be started and stopped
*----------------------------------------------------------------------------*/
void
AudioPlayerFactoryGstreamerTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
audioPlayerFactory = AudioPlayerFactory::getInstance();
CPPUNIT_ASSERT(audioPlayerFactory.get());
Ptr<AudioPlayerInterface>::Ref audioPlayer;
audioPlayer = audioPlayerFactory->getAudioPlayer();
CPPUNIT_ASSERT(audioPlayer.get());
CPPUNIT_ASSERT(!audioPlayer->isPlaying());
}
/*------------------------------------------------------------------------------
* Play something simple
*----------------------------------------------------------------------------*/
void
AudioPlayerFactoryGstreamerTest :: simplePlayTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
Ptr<AudioPlayerInterface>::Ref audioPlayer;
Ptr<time_duration>::Ref sleepT;
audioPlayerFactory = AudioPlayerFactory::getInstance();
audioPlayer = audioPlayerFactory->getAudioPlayer();
try {
audioPlayer->open("file:var/test.mp3");
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL(e.what());
}
CPPUNIT_ASSERT(!audioPlayer->isPlaying());
audioPlayer->start();
CPPUNIT_ASSERT(audioPlayer->isPlaying());
sleepT.reset(new time_duration(seconds(5)));
TimeConversion::sleep(sleepT);
audioPlayer->pause();
sleepT.reset(new time_duration(seconds(1)));
TimeConversion::sleep(sleepT);
audioPlayer->start();
sleepT.reset(new time_duration(seconds(2)));
TimeConversion::sleep(sleepT);
audioPlayer->pause();
sleepT.reset(new time_duration(seconds(1)));
TimeConversion::sleep(sleepT);
audioPlayer->start();
sleepT.reset(new time_duration(microseconds(10)));
while (audioPlayer->isPlaying()) {
TimeConversion::sleep(sleepT);
}
CPPUNIT_ASSERT(!audioPlayer->isPlaying());
audioPlayer->close();
}

View file

@ -0,0 +1,117 @@
/*------------------------------------------------------------------------------
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/playlistExecutor/src/AudioPlayerFactoryGstreamerTest.h,v $
------------------------------------------------------------------------------*/
#ifndef AudioPlayerFactoryGstreamerTest_h
#define AudioPlayerFactoryGstreamerTest_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>
#include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h"
namespace LiveSupport {
namespace PlaylistExecutor {
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the AudioPlayerFactory class.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see AudioPlayerFactory
*/
class AudioPlayerFactoryGstreamerTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(AudioPlayerFactoryGstreamerTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST(simplePlayTest);
CPPUNIT_TEST_SUITE_END();
protected:
/**
* A simple test.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
firstTest(void) throw (CPPUNIT_NS::Exception);
/**
* Play something simple.
*
* @exception CPPUNIT_NS::Exception on test failures.
*/
void
simplePlayTest(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 PlaylistExecutor
} // namespace LiveSupport
#endif // AudioPlayerFactoryGstreamerTest_h

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.1 $
Version : $Revision: 1.2 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/GstreamerPlayer.h,v $
------------------------------------------------------------------------------*/
@ -72,39 +72,21 @@ using namespace LiveSupport::Core;
* This class can be configured with the following XML element.
*
* <pre><code>
* <helixPlayer dllPath = "../../usr/lib/helix"
* audioDevice = "/dev/sound/dsp"
* />
* <pre><code>
* <gstreamerPlayer audioDevice = "plughw:0,0" />
* </code></pre>
*
* where the dllPath is the path to the directory containing the Helix
* library shared objects. The optional audioDevice argument sets the
* AUDIO environment variable which is read by the Helix client.
* where the optional audioDevice argument specifies the audio device
* (currently ALSA device) to use for playing.
*
* There are two parameters which are only there because the current version
* of the Helix client does not handle animation tags in SMIL files properly.
* They will be removed from later versions.
* <ul>
* <li>audioStreamTimeOut (milliseconds) - the time to wait for each
* GetAudioStream() operation before a timeout occurs;
* the default is 5;</li>
* <li>fadeLookAheadTime (milliseconds) - each fade-in or fade-out is
* scheduled (using IHXAudioCrossFade::CrossFade()) this
* much time before it is to happen; the default is 2500. </li>
* </ul>
*
* The DTD for the above configuration is the following:
*
* <pre><code>
* <!ELEMENT helixPlayer EMPTY >
* <!ATTLIST helixPlayer dllPath CDATA #REQUIRED >
* <!ATTLIST helixPlayer audioDevice CDATA #IMPLIED >
* <!ATTLIST helixPlayer audioStreamTimeout #IMPLIED >
* <!ATTLIST helixPlayer fadeLookAheatTime #IMPLIED >
* </pre></code>
* <!ELEMENT gstreamerPlayer EMPTY >
* <!ATTLIST gstreamerPlayer audioDevice CDATA #IMPLIED >
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class GstreamerPlayer : virtual public Configurable,
virtual public AudioPlayerInterface

View file

@ -22,7 +22,7 @@
Author : $Author: maroy $
Version : $Revision: 1.18 $
Version : $Revision: 1.19 $
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.h,v $
------------------------------------------------------------------------------*/
@ -83,7 +83,7 @@ using namespace LiveSupport::Core;
* <helixPlayer dllPath = "../../usr/lib/helix"
* audioDevice = "/dev/sound/dsp"
* />
* <pre><code>
* </code></pre>
*
* where the dllPath is the path to the directory containing the Helix
* library shared objects. The optional audioDevice argument sets the
@ -109,10 +109,10 @@ using namespace LiveSupport::Core;
* <!ATTLIST helixPlayer audioDevice CDATA #IMPLIED >
* <!ATTLIST helixPlayer audioStreamTimeout #IMPLIED >
* <!ATTLIST helixPlayer fadeLookAheatTime #IMPLIED >
* </pre></code>
* </code></pre>
*
* @author $Author: maroy $
* @version $Revision: 1.18 $
* @version $Revision: 1.19 $
*/
class HelixPlayer : virtual public Configurable,
virtual public AudioPlayerInterface,