From 2f6ef90968bb64c6df42f2ddef2b99963bc42d5c Mon Sep 17 00:00:00 2001
From: fgerlits <fgerlits@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Sat, 26 Feb 2005 12:33:48 +0000
Subject: [PATCH] added setAudioDevice() method to HelixPlayer and
 (AudioPlayerInterface); added HelixPlayer::openAndStartPlaylist() to
 AudioPlayerInterface.

---
 .../PlaylistExecutor/AudioPlayerInterface.h   | 39 +++++++++++++++++--
 .../src/AudioPlayerFactoryTest.cxx            | 35 ++++++++++++++++-
 .../src/AudioPlayerFactoryTest.h              | 17 ++++++--
 .../playlistExecutor/src/HelixPlayer.cxx      | 14 ++++++-
 .../playlistExecutor/src/HelixPlayer.h        | 23 +++++++++--
 .../playlistExecutor/var/simpleSmil.smil      |  2 +-
 6 files changed, 115 insertions(+), 15 deletions(-)

diff --git a/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h b/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h
index ca30e27cd..26aa470c4 100644
--- a/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h
+++ b/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h
@@ -21,8 +21,8 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
  
-    Author   : $Author: maroy $
-    Version  : $Revision: 1.4 $
+    Author   : $Author: fgerlits $
+    Version  : $Revision: 1.5 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/include/LiveSupport/PlaylistExecutor/AudioPlayerInterface.h,v $
 
 ------------------------------------------------------------------------------*/
@@ -46,6 +46,7 @@
 #include <boost/date_time/posix_time/posix_time.hpp>
 
 #include "LiveSupport/Core/Ptr.h"
+#include "LiveSupport/Core/Playlist.h"
 
 
 namespace LiveSupport {
@@ -66,8 +67,8 @@ using namespace LiveSupport::Core;
 /**
  *  A generic interface for playing audio files.
  *
- *  @author  $Author: maroy $
- *  @version $Revision: 1.4 $
+ *  @author  $Author: fgerlits $
+ *  @version $Revision: 1.5 $
  */
 class AudioPlayerInterface
 {
@@ -164,6 +165,36 @@ class AudioPlayerInterface
         virtual void
         stop(void)                              throw (std::logic_error)
                                                                       = 0;
+        /**
+         *  Play a playlist, with simulated fading.
+         *
+         *  This is a stopgap method, and should be replaced as soon as
+         *  the SMIL animation issues are fixed in the Helix client.
+         *
+         *  @param playlist the Playlist object to be played.
+         *  @exception std::invalid_argument playlist is invalid (e.g.,
+         *              does not have a URI field, or there is no valid
+         *              SMIL file at the given URI).
+         *  @exception std::logic_error thrown by start() if open() was
+         *              unsuccessful, but returned normally (never happens)
+         *  @exception std::runtime_error on errors thrown by the helix player
+         */
+        virtual void
+        openAndStartPlaylist(Ptr<Playlist>::Ref  playlist)       
+                                                throw (std::invalid_argument,
+                                                       std::logic_error,
+                                                       std::runtime_error)
+                                                                      = 0;
+
+        /**
+         *  Set the audio device used for playback.
+         *
+         *  @param deviceName the new device name, e.g., /dev/dsp
+         *  @return true if successful, false if not
+         */
+        virtual bool
+        setAudioDevice(const std::string &deviceName)       
+                                                throw ()              = 0;
 };
 
 
diff --git a/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx
index a3a38b68a..fe2696d87 100644
--- a/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx
+++ b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.cxx
@@ -21,8 +21,8 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
  
-    Author   : $Author: maroy $
-    Version  : $Revision: 1.5 $
+    Author   : $Author: fgerlits $
+    Version  : $Revision: 1.6 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/AudioPlayerFactoryTest.cxx,v $
 
 ------------------------------------------------------------------------------*/
@@ -167,3 +167,34 @@ AudioPlayerFactoryTest :: simplePlayTest(void)
     audioPlayer->close();
 }
 
+
+/*------------------------------------------------------------------------------
+ *  Send stuff to /dev/null
+ *----------------------------------------------------------------------------*/
+void
+AudioPlayerFactoryTest :: nullDeviceTest(void)
+                                                throw (CPPUNIT_NS::Exception)
+{
+    Ptr<AudioPlayerFactory>::Ref        audioPlayerFactory;
+    Ptr<AudioPlayerInterface>::Ref      audioPlayer;
+    Ptr<time_duration>::Ref     sleepT(new time_duration(microseconds(10)));
+
+    audioPlayerFactory = AudioPlayerFactory::getInstance();
+    audioPlayer        = audioPlayerFactory->getAudioPlayer();
+
+    CPPUNIT_ASSERT_NO_THROW(audioPlayer->open("file:var/simpleSmil.smil"));
+    CPPUNIT_ASSERT(!audioPlayer->isPlaying());
+
+    CPPUNIT_ASSERT(audioPlayer->setAudioDevice("/dev/null"));
+    CPPUNIT_ASSERT_NO_THROW(audioPlayer->start());
+    CPPUNIT_ASSERT(audioPlayer->isPlaying());
+
+    while (audioPlayer->isPlaying()) {
+        TimeConversion::sleep(sleepT);
+    }
+    CPPUNIT_ASSERT(!audioPlayer->isPlaying());
+
+    CPPUNIT_ASSERT(audioPlayer->setAudioDevice(""));
+    audioPlayer->close();
+}
+
diff --git a/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h
index 434342767..49ef8038c 100644
--- a/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h
+++ b/livesupport/modules/playlistExecutor/src/AudioPlayerFactoryTest.h
@@ -21,8 +21,8 @@
     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  
  
-    Author   : $Author: maroy $
-    Version  : $Revision: 1.1 $
+    Author   : $Author: fgerlits $
+    Version  : $Revision: 1.2 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/AudioPlayerFactoryTest.h,v $
 
 ------------------------------------------------------------------------------*/
@@ -59,14 +59,15 @@ namespace PlaylistExecutor {
 /**
  *  Unit test for the AudioPlayerFactory class.
  *
- *  @author  $Author: maroy $
- *  @version $Revision: 1.1 $
+ *  @author  $Author: fgerlits $
+ *  @version $Revision: 1.2 $
  *  @see AudioPlayerFactory
  */
 class AudioPlayerFactoryTest : public CPPUNIT_NS::TestFixture
 {
     CPPUNIT_TEST_SUITE(AudioPlayerFactoryTest);
     CPPUNIT_TEST(firstTest);
+    CPPUNIT_TEST(nullDeviceTest);
     CPPUNIT_TEST(simplePlayTest);
     CPPUNIT_TEST_SUITE_END();
 
@@ -88,6 +89,14 @@ class AudioPlayerFactoryTest : public CPPUNIT_NS::TestFixture
         void
         simplePlayTest(void)                    throw (CPPUNIT_NS::Exception);
 
+        /**
+         *  Check the setAudioDevice() method.
+         *
+         *  @exception CPPUNIT_NS::Exception on test failures.
+         */
+        void
+        nullDeviceTest(void)                    throw (CPPUNIT_NS::Exception);
+
     public:
         
         /**
diff --git a/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx b/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx
index bf721bdb6..2e4088704 100644
--- a/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx
+++ b/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx
@@ -22,7 +22,7 @@
  
  
     Author   : $Author: fgerlits $
-    Version  : $Revision: 1.12 $
+    Version  : $Revision: 1.13 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.cxx,v $
 
 ------------------------------------------------------------------------------*/
@@ -492,3 +492,15 @@ HelixPlayer :: openAndStartPlaylist(Ptr<Playlist>::Ref  playlist)
     HX_RELEASE(audioPlayer);
 }
 
+
+/*------------------------------------------------------------------------------
+ *  Set the audio device.
+ *----------------------------------------------------------------------------*/
+bool
+HelixPlayer :: setAudioDevice(const std::string &deviceName)       
+                                                throw ()
+{
+    return (setenv("AUDIO", deviceName.c_str(), 1) == 0);
+                                             // 1 = overwrite if exists
+}
+
diff --git a/livesupport/modules/playlistExecutor/src/HelixPlayer.h b/livesupport/modules/playlistExecutor/src/HelixPlayer.h
index a51edaac9..f0ae9dd04 100644
--- a/livesupport/modules/playlistExecutor/src/HelixPlayer.h
+++ b/livesupport/modules/playlistExecutor/src/HelixPlayer.h
@@ -22,7 +22,7 @@
  
  
     Author   : $Author: fgerlits $
-    Version  : $Revision: 1.10 $
+    Version  : $Revision: 1.11 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.h,v $
 
 ------------------------------------------------------------------------------*/
@@ -91,7 +91,7 @@ using namespace LiveSupport::Core;
  *  </pre></code>
  *
  *  @author  $Author: fgerlits $
- *  @version $Revision: 1.10 $
+ *  @version $Revision: 1.11 $
  */
 class HelixPlayer : virtual public Configurable,
                     virtual public AudioPlayerInterface,
@@ -349,11 +349,28 @@ class HelixPlayer : virtual public Configurable,
          *              unsuccessful, but returned normally (never happens)
          *  @exception std::runtime_error on errors thrown by the helix player
          */
-        void
+        virtual void
         openAndStartPlaylist(Ptr<Playlist>::Ref  playlist)       
                                                 throw (std::invalid_argument,
                                                        std::logic_error,
                                                        std::runtime_error);
+
+        /**
+         *  Set the audio device used for playback.
+         *
+         *  Sets the environment variable AUDIO.  This should be replaced with
+         *  a Helix function call as soon as this functionality is provided.
+         *
+         *  There are some strange issues with this: e.g., if you set the
+         *  device to "/dev/null", this works fine for SMIL files, but gives
+         *  Helix error 80040100 (HXR_AUDIO_DRIVER) when an mp3 file is played.
+         *
+         *  @param deviceName the new device name, e.g., /dev/dsp
+         *  @return true if successful, false if not
+         */
+        virtual bool
+        setAudioDevice(const std::string &deviceName)       
+                                                throw ();
 };
 
 
diff --git a/livesupport/modules/playlistExecutor/var/simpleSmil.smil b/livesupport/modules/playlistExecutor/var/simpleSmil.smil
index bb652ca79..070d739fb 100644
--- a/livesupport/modules/playlistExecutor/var/simpleSmil.smil
+++ b/livesupport/modules/playlistExecutor/var/simpleSmil.smil
@@ -1,6 +1,6 @@
 <smil xmlns    = "http://www.w3.org/2001/SMIL20/Language"
       xmlns:rn = "http://features.real.com/2001/SMIL20/Extensions">
     <body>
-        <audio src="file:var/test.mp3"/> 
+        <audio src="file:var/test-short.mp3"/> 
     </body>
 </smil>