From 81972cffe6d22271a767ea3b3f7f2687e2b06db3 Mon Sep 17 00:00:00 2001 From: maroy Date: Mon, 1 Nov 2004 08:37:57 +0000 Subject: [PATCH] added AudioPlayerInterface and AudioPlayerFactory --- .../modules/playlistExecutor/etc/Makefile.in | 6 +- .../playlistExecutor/etc/audioPlayer.xml | 12 ++ .../PlaylistExecutor/AudioPlayerFactory.h | 189 ++++++++++++++++++ .../PlaylistExecutor/AudioPlayerInterface.h | 170 ++++++++++++++++ .../src/AudioPlayerFactory.cxx | 112 +++++++++++ .../src/AudioPlayerFactoryTest.cxx | 145 ++++++++++++++ .../src/AudioPlayerFactoryTest.h | 117 +++++++++++ .../playlistExecutor/src/HelixPlayer.cxx | 33 +-- .../playlistExecutor/src/HelixPlayer.h | 44 +++- 9 files changed, 807 insertions(+), 21 deletions(-) create mode 100644 livesupport/modules/playlistExecutor/etc/audioPlayer.xml create mode 100644 livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerFactory.h create mode 100644 livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h create mode 100644 livesupport/modules/playlistExecutor/src/AudioPlayerFactory.cxx create mode 100644 livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx create mode 100644 livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h diff --git a/livesupport/modules/playlistExecutor/etc/Makefile.in b/livesupport/modules/playlistExecutor/etc/Makefile.in index 5f487ab20..8aacf53a7 100644 --- a/livesupport/modules/playlistExecutor/etc/Makefile.in +++ b/livesupport/modules/playlistExecutor/etc/Makefile.in @@ -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} \ diff --git a/livesupport/modules/playlistExecutor/etc/audioPlayer.xml b/livesupport/modules/playlistExecutor/etc/audioPlayer.xml new file mode 100644 index 000000000..0d7c6505b --- /dev/null +++ b/livesupport/modules/playlistExecutor/etc/audioPlayer.xml @@ -0,0 +1,12 @@ + + + + + +]> + + + diff --git a/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerFactory.h b/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerFactory.h new file mode 100644 index 000000000..f42e4bc28 --- /dev/null +++ b/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerFactory.h @@ -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 + +#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: + * + *

+ *  <audioPlayer>
+ *      
+ *  </audioPlayer>
+ *  
+ * + * The DTD for the above XML structure is: + * + *

+ *  
+ *  
+ * + * 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::Ref singleton; + + /** + * The audio player created by this factory. + */ + Ptr::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::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::Ref + getAudioPlayer(void) throw () + { + return audioPlayer; + } +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace PlaylistExecutor +} // namespace LiveSupport + +#endif // LiveSupport_PlaylistExecutor_AudioPlayerFactory_h + diff --git a/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h b/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h new file mode 100644 index 000000000..f23f8fdf9 --- /dev/null +++ b/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h @@ -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 not 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 + diff --git a/livesupport/modules/playlistExecutor/src/AudioPlayerFactory.cxx b/livesupport/modules/playlistExecutor/src/AudioPlayerFactory.cxx new file mode 100644 index 000000000..286ed294b --- /dev/null +++ b/livesupport/modules/playlistExecutor/src/AudioPlayerFactory.cxx @@ -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::Ref AudioPlayerFactory::singleton; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Return the singleton instance to AudioPlayerFactory + *----------------------------------------------------------------------------*/ +Ptr::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 (*(nodes.begin())); + Ptr::Ref hp(new HelixPlayer()); + hp->configure(*configElement); + hp->initialize(); + audioPlayer = hp; + } + + if (!audioPlayer) { + throw std::invalid_argument("no audio player factories to configure"); + } +} + + diff --git a/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx new file mode 100644 index 000000000..3f342542c --- /dev/null +++ b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx @@ -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 +#else +#error "Need unistd.h" +#endif + + +#include +#include + +#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::Ref parser( + new xmlpp::DomParser(configFileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + Ptr::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::Ref audioPlayerFactory; + + audioPlayerFactory = AudioPlayerFactory::getInstance(); + CPPUNIT_ASSERT(audioPlayerFactory.get()); + + Ptr::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::Ref audioPlayerFactory; + Ptr::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()); +} + diff --git a/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h new file mode 100644 index 000000000..434342767 --- /dev/null +++ b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h @@ -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 + +#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 + diff --git a/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx b/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx index 05c2c3513..b0df58803 100644 --- a/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx +++ b/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx @@ -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; + } } diff --git a/livesupport/modules/playlistExecutor/src/HelixPlayer.h b/livesupport/modules/playlistExecutor/src/HelixPlayer.h index df4330b32..e5e8ef924 100644 --- a/livesupport/modules/playlistExecutor/src/HelixPlayer.h +++ b/livesupport/modules/playlistExecutor/src/HelixPlayer.h @@ -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 #include -#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. + * + *

+ *  
+ *  

+ *
+ *  where the dllPath is the path to the directory containing the Helix
+ *  library shared objects.
+ *
+ *  The DTD for the above configuration is the following:
+ *
+ *  

+ *  
+ *  
+ *  
* * @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.