From df99ff2cb54d508b060b9621237b8c36d6ebaa33 Mon Sep 17 00:00:00 2001
From: fgerlits <fgerlits@cfc7b370-4200-0410-a6e3-cb6bdb053afe>
Date: Mon, 7 Mar 2005 14:58:24 +0000
Subject: [PATCH] added audioStreamTimeout and fadeLookAheadTime parameters to
 the HelixPlayer config file (for fine-tuning the fade-in/fade-out hack)

---
 .../playlistExecutor/etc/audioPlayer.xml      |  5 +-
 .../playlistExecutor/etc/helixPlayer.xml      |  4 ++
 .../playlistExecutor/src/HelixPlayer.cxx      | 51 ++++++++++++++-----
 .../playlistExecutor/src/HelixPlayer.h        | 28 +++++++++-
 4 files changed, 72 insertions(+), 16 deletions(-)

diff --git a/livesupport/modules/playlistExecutor/etc/audioPlayer.xml b/livesupport/modules/playlistExecutor/etc/audioPlayer.xml
index 0d7c6505b..7bc5b74aa 100644
--- a/livesupport/modules/playlistExecutor/etc/audioPlayer.xml
+++ b/livesupport/modules/playlistExecutor/etc/audioPlayer.xml
@@ -4,7 +4,10 @@
 <!ELEMENT audioPlayer   (helixPlayer) >
 
 <!ELEMENT helixPlayer   EMPTY >
-<!ATTLIST helixPlayer   dllPath     CDATA   #REQUIRED >
+<!ATTLIST helixPlayer   dllPath      CDATA   #REQUIRED >
+<!ATTLIST helixPlayer   audioDevice  CDATA   #IMPLIED  >
+<!ATTLIST helixPlayer   audioStreamTimeout   NMTOKEN   #IMPLIED >
+<!ATTLIST helixPlayer   fadeLookAheatTime    NMTOKEN   #IMPLIED >
 ]>
 <audioPlayer>
     <helixPlayer dllPath = "../../usr/lib/helix"
diff --git a/livesupport/modules/playlistExecutor/etc/helixPlayer.xml b/livesupport/modules/playlistExecutor/etc/helixPlayer.xml
index b9d1c4072..ed5960ac5 100644
--- a/livesupport/modules/playlistExecutor/etc/helixPlayer.xml
+++ b/livesupport/modules/playlistExecutor/etc/helixPlayer.xml
@@ -4,7 +4,11 @@
 <!ELEMENT helixPlayer   EMPTY >
 <!ATTLIST helixPlayer   dllPath      CDATA   #REQUIRED >
 <!ATTLIST helixPlayer   audioDevice  CDATA   #IMPLIED  >
+<!ATTLIST helixPlayer   audioStreamTimeout   NMTOKEN   #IMPLIED >
+<!ATTLIST helixPlayer   fadeLookAheadTime    NMTOKEN   #IMPLIED >
 ]>
 <helixPlayer dllPath = "../../usr/lib/helix"
              audioDevice = "/dev/sound/dsp"
+             audioStreamTimeout="6"
+             fadeLookAheadTime="2510"
 />
diff --git a/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx b/livesupport/modules/playlistExecutor/src/HelixPlayer.cxx
index 31bfab832..50abe2263 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.15 $
+    Version  : $Revision: 1.16 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.cxx,v $
 
 ------------------------------------------------------------------------------*/
@@ -33,6 +33,8 @@
 #include "configure.h"
 #endif
 
+#include <sstream>
+
 #include "HelixDefs.h"
 
 #include "LiveSupport/Core/TimeConversion.h"
@@ -76,22 +78,31 @@ static const std::string    dllPathName = "dllPath";
  */
 static const std::string    audioDeviceName = "audioDevice";
 
+/**
+ *  The name of the audio stream timeout attribute.
+ */
+static const std::string    audioStreamTimeoutName = "audioStreamTimeout";
+
+/**
+ *  The default value of the audio stream timeout attribute.
+ */
+static const int            audioStreamTimeoutDefault = 5;
+
+/**
+ *  The name of the fade look ahead time attribute.
+ */
+static const std::string    fadeLookAheadTimeName = "fadeLookAheadTime";
+
+/**
+ *  The default value of the fade look ahead time attribute.
+ */
+static const int            fadeLookAheadTimeDefault = 2500;
 /**
  *  The name of the client core shared object, as found under dllPath
  */
 static const std::string    clntcoreName = "/clntcore.so";
 
 
-/**
- *  Magic number #1: max time to wait for an audio stream, in milliseconds
- */
-static const int            getAudioStreamTimeOut = 5;
-
-/**
- *  Magic number #2: schedule fading this many milliseconds in advance
- */
-static const int            lookAheadTime = 2500;
-
 /* ===============================================  local function prototypes */
 
 
@@ -123,6 +134,20 @@ HelixPlayer :: configure(const xmlpp::Element   &  element)
     if ((attribute = element.get_attribute(audioDeviceName))) {
         setAudioDevice(attribute->get_value());
     }
+
+    if ((attribute = element.get_attribute(audioStreamTimeoutName))) {
+        std::stringstream   timeoutStream(attribute->get_value());
+        timeoutStream >> audioStreamTimeout;
+    } else {
+        audioStreamTimeout = audioStreamTimeoutDefault;
+    }
+
+    if ((attribute = element.get_attribute(fadeLookAheadTimeName))) {
+        std::stringstream   lookAheadStream(attribute->get_value());
+        lookAheadStream >> fadeLookAheadTime;
+    } else {
+        fadeLookAheadTime = fadeLookAheadTimeDefault;
+    }
 }
 
 
@@ -436,7 +461,7 @@ HelixPlayer :: openAndStart(Ptr<Playlist>::Ref  playlist)
         audioStream[i] = audioPlayer->GetAudioStream(i);
         int counter = 0;
         while (!audioStream[i]) {
-            if (counter > getAudioStreamTimeOut * 100) {
+            if (counter > audioStreamTimeout * 100) {
                 std::stringstream   eMsg;
                 eMsg << "can't get audio stream number " << i;
                 throw std::runtime_error(eMsg.str());
@@ -544,7 +569,7 @@ HelixPlayer :: implementFading(unsigned long    position)
             it = fadeDataList->erase(it);
             continue;
 
-        } else if (fadeAt < position + lookAheadTime) {     // we are on time
+        } else if (fadeAt < position + fadeLookAheadTime) { // we are on time
 
             IHXAudioPlayer* audioPlayer = 0;
             if (player->QueryInterface(IID_IHXAudioPlayer, 
diff --git a/livesupport/modules/playlistExecutor/src/HelixPlayer.h b/livesupport/modules/playlistExecutor/src/HelixPlayer.h
index 2ae0b1d0c..776e5c7a2 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.13 $
+    Version  : $Revision: 1.14 $
     Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/playlistExecutor/src/Attic/HelixPlayer.h,v $
 
 ------------------------------------------------------------------------------*/
@@ -89,16 +89,30 @@ using namespace LiveSupport::Core;
  *  library shared objects.  The optional audioDevice argument sets the
  *  AUDIO environment variable which is read by the Helix client.
  *
+ *  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>
  *
  *  @author  $Author: fgerlits $
- *  @version $Revision: 1.13 $
+ *  @version $Revision: 1.14 $
  */
 class HelixPlayer : virtual public Configurable,
                     virtual public AudioPlayerInterface,
@@ -115,6 +129,16 @@ class HelixPlayer : virtual public Configurable,
          */
         std::string             dllPath;
 
+        /**
+         *  Max time to wait for an audio stream, in milliseconds.
+         */
+        int                     audioStreamTimeout;
+
+        /**
+         *  Schedule fading this many milliseconds in advance.
+         */
+        int                     fadeLookAheadTime;
+
         /**
          *  The shared object access point.
          */