Bug 586535 - Reduce delay in volume changes on OS X by using sydneyaudio volume control. r=doublec a=blocking2.0
authorMatthew Gregan <kinetik@flim.org>
Thu, 12 Aug 2010 13:52:36 +1200
changeset 50362 61004a07b318e3f1cb7dc070629b5e65dc82c66c
parent 50361 5eb8034048992b884b75ec6f84cf7170867684d7
child 50363 2ce3d3fdd6806e29c5b39b13d4e088bdbacdf5a7
push idunknown
push userunknown
push dateunknown
reviewersdoublec, blocking2
bugs586535
milestone2.0b4pre
Bug 586535 - Reduce delay in volume changes on OS X by using sydneyaudio volume control. r=doublec a=blocking2.0
content/media/nsAudioStream.cpp
--- a/content/media/nsAudioStream.cpp
+++ b/content/media/nsAudioStream.cpp
@@ -42,16 +42,20 @@
 #include "nsAutoPtr.h"
 #include "nsAudioStream.h"
 #include "nsAlgorithm.h"
 extern "C" {
 #include "sydneyaudio/sydney_audio.h"
 }
 #include "mozilla/TimeStamp.h"
 
+#if defined(XP_MACOSX)
+#define SA_PER_STREAM_VOLUME 1
+#endif
+
 using mozilla::TimeStamp;
 
 #ifdef PR_LOGGING
 PRLogModuleInfo* gAudioStreamLog = nsnull;
 #endif
 
 #define FAKE_BUFFER_SIZE 176400
 
@@ -206,17 +210,24 @@ PRUint32 nsAudioStream::Available()
     return 0;
 
   return s / sizeof(short);
 }
 
 void nsAudioStream::SetVolume(float aVolume)
 {
   NS_ASSERTION(aVolume >= 0.0 && aVolume <= 1.0, "Invalid volume");
+#if defined(SA_PER_STREAM_VOLUME)
+  if (sa_stream_set_volume_abs(static_cast<sa_stream_t*>(mAudioHandle), aVolume) != SA_SUCCESS) {
+    PR_LOG(gAudioStreamLog, PR_LOG_ERROR, ("nsAudioStream: sa_stream_set_volume_abs error"));
+    Shutdown();
+  }
+#else
   mVolume = aVolume;
+#endif
 }
 
 void nsAudioStream::Drain()
 {
   if (!mAudioHandle)
     return;
 
   // Write any remaining unwritten sound data in the overflow buffer