added AudioPlayerInterface and AudioPlayerFactory

This commit is contained in:
maroy 2004-11-01 08:37:57 +00:00
parent 45edb6399e
commit 81972cffe6
9 changed files with 807 additions and 21 deletions

View File

@ -21,7 +21,7 @@
#
#
# Author : $Author: maroy $
# Version : $Revision: 1.1 $
# Version : $Revision: 1.2 $
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/etc/Makefile.in,v $
#
# @configure_input@
@ -111,8 +111,10 @@ PLAYLIST_EXECUTOR_LIB_OBJS = ${TMP_DIR}/HelixPlayer.o \
${TMP_DIR}/AuthenticationManager.o \
${TMP_DIR}/ClientContext.o \
${TMP_DIR}/ErrorSink.o \
${TMP_DIR}/HelixIIDs.o
${TMP_DIR}/HelixIIDs.o \
${TMP_DIR}/AudioPlayerFactory.o
TEST_RUNNER_OBJS = ${TMP_DIR}/HelixPlayerTest.o \
${TMP_DIR}/AudioPlayerFactoryTest.o \
${TMP_DIR}/TestRunner.o
TEST_RUNNER_LIBS = -l${PLAYLIST_EXECUTOR_LIB} -l${CORE_LIB} \
${HELIX_LIBS} \

View File

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE audioPlayer [
<!ELEMENT audioPlayer (helixPlayer) >
<!ELEMENT helixPlayer EMPTY >
<!ATTLIST helixPlayer dllPath CDATA #REQUIRED >
]>
<audioPlayer>
<helixPlayer dllPath = "../../usr/lib/helix"
/>
</audioPlayer>

View File

@ -0,0 +1,189 @@
/*------------------------------------------------------------------------------
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/include/LiveSupport/PlaylistExecutor/AudioPlayerFactory.h,v $
------------------------------------------------------------------------------*/
#ifndef LiveSupport_PlaylistExecutor_AudioPlayerFactory_h
#define LiveSupport_PlaylistExecutor_AudioPlayerFactory_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
namespace LiveSupport {
namespace PlaylistExecutor {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* The factory to create appropriate AudioPlayer objects.
* This singleton class has to be configured with an XML element,
* describing the AudioPlayerInterface that it should build
* and maintain. This is done by including the configuration element
* for the desired type of connection manager inside the configuration
* element for the factory.
*
* Currently only the HelixAudioPlayer is supported, thus a
* configuration file may look like this:
*
* <pre><code>
* &lt;audioPlayer&gt;
* <helixPlayer dllPath = "../../usr/lib/helix"
* />
* &lt;/audioPlayer&gt;
* </code></pre>
*
* The DTD for the above XML structure is:
*
* <pre><code>
* <!ELEMENT audioPlayer (helixPlayer) >
* </code></pre>
*
* For the DTD and details of the helixPlayer configuration
* element, see the HelixPlayer documentation.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @see HelixPlayer
*/
class AudioPlayerFactory :
virtual public Configurable
{
private:
/**
* The name of the configuration XML elmenent used by this object.
*/
static const std::string configElementNameStr;
/**
* The singleton instance of this object.
*/
static Ptr<AudioPlayerFactory>::Ref singleton;
/**
* The audio player created by this factory.
*/
Ptr<AudioPlayerInterface>::Ref audioPlayer;
/**
* The default constructor.
*/
AudioPlayerFactory(void) throw ()
{
}
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~AudioPlayerFactory(void) throw ()
{
}
/**
* Return the name of the XML element this object expects
* to be sent to a call to configure().
*
* @return the name of the expected XML configuration element.
*/
static const std::string
getConfigElementName(void) throw ()
{
return configElementNameStr;
}
/**
* Returns the singleton instance of this object.
*
* @return the singleton instance of this object.
*/
static Ptr<AudioPlayerFactory>::Ref
getInstance() throw ();
/**
* Configure the object based on the XML element supplied.
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the object has already
* been configured, and can not be reconfigured.
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error);
/**
* Return an audio player.
* The returned player will already have been initialized.
*
* @return the appropriate audio player, according to the
* configuration of this factory.
*/
Ptr<AudioPlayerInterface>::Ref
getAudioPlayer(void) throw ()
{
return audioPlayer;
}
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace PlaylistExecutor
} // namespace LiveSupport
#endif // LiveSupport_PlaylistExecutor_AudioPlayerFactory_h

View File

@ -0,0 +1,170 @@
/*------------------------------------------------------------------------------
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/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h,v $
------------------------------------------------------------------------------*/
#ifndef AudioPlayerInterface_h
#define AudioPlayerInterface_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/Core/Configurable.h"
namespace LiveSupport {
namespace PlaylistExecutor {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* A generic interface for playing audio files.
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
*/
class AudioPlayerInterface : virtual public Configurable
{
public:
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~AudioPlayerInterface(void) throw ()
{
}
/**
* Configure the object based on the XML element supplied.
*
* @param element the XML element to configure the object from.
* @exception std::invalid_argument if the supplied XML element
* contains bad configuraiton information
* @exception std::logic_error if the scheduler daemon has already
* been configured, and can not be reconfigured.
*/
virtual void
configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error) = 0;
/**
* Initialize the Player object, so that it is ready to
* play audio files.
*
* @exception std::exception on initialization problems.
*/
virtual void
initialize(void) throw (std::exception) = 0;
/**
* De-initialize the Player object.
*/
virtual void
deInitialize(void) throw () = 0;
/**
* Specify which audio resource to play.
* The file may be a playlist, referencing other files, which
* will be accessed automatically.
* Note: this call will <b>not</b> start playing! You will
* have to call the start() function to begin playing.
*
* @param fileUrl a URL to a file
* @exception std::invalid_argument if the supplied fileUrl
* seems to be invalid.
* @see #start
*/
virtual void
playThis(const std::string fileUrl) throw (std::invalid_argument)
= 0;
/**
* Start playing.
* This call will start playing the active playlist, which was
* set by a previous call to playThis().
* Playing can be stopped by calling stop().
*
* @exception std::logic_error if there was no previous call to
* playThis().
* @see #playThis
* @see #stop
*/
virtual void
start(void) throw (std::logic_error)
= 0;
/**
* Tell if we're currently playing.
*
* @return true of the player is currently playing, false
* otherwise.
*/
virtual bool
isPlaying(void) throw () = 0;
/**
* Stop playing.
*
* @exception std::logic_error if there was no previous call to
* start()
*/
virtual void
stop(void) throw (std::logic_error)
= 0;
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace PlaylistExecutor
} // namespace LiveSupport
#endif // AudioPlayerInterface_h

View File

@ -0,0 +1,112 @@
/*------------------------------------------------------------------------------
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/AudioPlayerFactory.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include "LiveSupport/PlaylistExecutor/AudioPlayerFactory.h"
#include "HelixPlayer.h"
using namespace LiveSupport::Core;
using namespace LiveSupport::PlaylistExecutor;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of the config element for this class
*----------------------------------------------------------------------------*/
const std::string AudioPlayerFactory::configElementNameStr =
"audioPlayer";
/*------------------------------------------------------------------------------
* The singleton instance of AudioPlayerFactory
*----------------------------------------------------------------------------*/
Ptr<AudioPlayerFactory>::Ref AudioPlayerFactory::singleton;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Return the singleton instance to AudioPlayerFactory
*----------------------------------------------------------------------------*/
Ptr<AudioPlayerFactory>::Ref
AudioPlayerFactory :: getInstance(void) throw ()
{
if (!singleton.get()) {
singleton.reset(new AudioPlayerFactory());
}
return singleton;
}
/*------------------------------------------------------------------------------
* Configure the connection manager factory.
*----------------------------------------------------------------------------*/
void
AudioPlayerFactory :: configure(const xmlpp::Element & element)
throw (std::invalid_argument,
std::logic_error)
{
if (element.get_name() != configElementNameStr) {
std::string eMsg = "Bad configuration element ";
eMsg += element.get_name();
throw std::invalid_argument(eMsg);
}
audioPlayer.reset();
// try to look for a SimpleConnectionManager configuration element
xmlpp::Node::NodeList 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);
hp->initialize();
audioPlayer = hp;
}
if (!audioPlayer) {
throw std::invalid_argument("no audio player factories to configure");
}
}

View File

@ -0,0 +1,145 @@
/*------------------------------------------------------------------------------
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/Attic/AudioPlayerFactoryTest.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 "AudioPlayerFactoryTest.h"
using namespace LiveSupport::PlaylistExecutor;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(AudioPlayerFactoryTest);
/**
* The name of the configuration file for the Helix player.
*/
static const std::string configFileName = "etc/audioPlayer.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Set up the test environment
*----------------------------------------------------------------------------*/
void
AudioPlayerFactoryTest :: 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);
} 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
AudioPlayerFactoryTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Test to see if the HelixPlayer engine can be started and stopped
*----------------------------------------------------------------------------*/
void
AudioPlayerFactoryTest :: 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
AudioPlayerFactoryTest :: simplePlayTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<AudioPlayerFactory>::Ref audioPlayerFactory;
Ptr<AudioPlayerInterface>::Ref audioPlayer;
audioPlayerFactory = AudioPlayerFactory::getInstance();
audioPlayer = audioPlayerFactory->getAudioPlayer();
audioPlayer->playThis("file:var/test.mp3");
CPPUNIT_ASSERT(!audioPlayer->isPlaying());
audioPlayer->start();
CPPUNIT_ASSERT(audioPlayer->isPlaying());
while (audioPlayer->isPlaying()) {
usleep(10000);
}
CPPUNIT_ASSERT(!audioPlayer->isPlaying());
}

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/Attic/AudioPlayerFactoryTest.h,v $
------------------------------------------------------------------------------*/
#ifndef AudioPlayerFactoryTest_h
#define AudioPlayerFactoryTest_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 AudioPlayerFactoryTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(AudioPlayerFactoryTest);
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 // AudioPlayerFactoryTest_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/Attic/HelixPlayer.cxx,v $
------------------------------------------------------------------------------*/
@ -128,6 +128,10 @@ HelixPlayer :: configure(const xmlpp::Element & element)
void
HelixPlayer :: initialize(void) throw (std::exception)
{
if (initialized) {
return;
}
// open the Helix Client Core shared object
std::string staticLibPath(dllPath);
staticLibPath += clntcoreName;
@ -207,7 +211,8 @@ HelixPlayer :: initialize(void) throw (std::exception)
}
// set up other variables
playing = false;
playing = false;
initialized = true;
}
@ -215,21 +220,25 @@ HelixPlayer :: initialize(void) throw (std::exception)
* De-initialize the Helix Player
*----------------------------------------------------------------------------*/
void
HelixPlayer :: deInitialize(void)
HelixPlayer :: deInitialize(void) throw ()
{
// signal stop to and wait for the event handling thread to stop
handleEvents = false;
pthread_join(eventHandlingThread, 0);
if (initialized) {
// signal stop to and wait for the event handling thread to stop
handleEvents = false;
pthread_join(eventHandlingThread, 0);
// release Helix resources
clientContext->Release();
// release Helix resources
clientContext->Release();
clientEngine->ClosePlayer(player);
player->Release();
clientEngine->ClosePlayer(player);
player->Release();
closeEngine(clientEngine);
closeEngine(clientEngine);
dllAccess.close();
dllAccess.close();
initialized = false;
}
}

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/Attic/HelixPlayer.h,v $
------------------------------------------------------------------------------*/
@ -46,7 +46,7 @@
#include <dllacces.h>
#include <dllpath.h>
#include "LiveSupport/Core/Configurable.h"
#include "LiveSupport/PlaylistExecutor/AudioPlayerInterface.h"
#include "AdviseSink.h"
#include "ErrorSink.h"
@ -71,12 +71,27 @@ using namespace LiveSupport::Core;
/**
* A class to play audio files and SMIL files through the Helix
* Community Library.
* This class can be configured with the following XML element.
*
* <pre><code>
* <helixPlayer dllPath = "../../usr/lib/helix"
* />
* <pre><code>
*
* where the dllPath is the path to the directory containing the Helix
* library shared objects.
*
* The DTD for the above configuration is the following:
*
* <pre><code>
* <!ELEMENT helixPlayer EMPTY >
* <!ATTLIST helixPlayer dllPath CDATA #REQUIRED >
* </pre></code>
*
* @author $Author: maroy $
* @version $Revision: 1.1 $
* @version $Revision: 1.2 $
*/
class HelixPlayer :
virtual public Configurable
class HelixPlayer : virtual public AudioPlayerInterface
{
friend void * eventHandlerThread(void *) throw();
@ -131,6 +146,11 @@ class HelixPlayer :
*/
pthread_t eventHandlingThread;
/**
* Flag to indicate if this object has been initialized.
*/
bool initialized;
/**
* Flag to mark if the event handling thread should be running
* and handling events.
@ -149,12 +169,22 @@ class HelixPlayer :
public:
/**
* Constructor.
*/
HelixPlayer(void) throw ()
{
playing = false;
initialized = false;
}
/**
* A virtual destructor, as this class has virtual functions.
*/
virtual
~HelixPlayer(void) throw ()
~HelixPlayer(void) throw ()
{
deInitialize();
}
/**
@ -196,7 +226,7 @@ class HelixPlayer :
* De-initialize the Helix Player object.
*/
virtual void
deInitialize(void);
deInitialize(void) throw ();
/**
* Specify which audio resource to play.