Bug 805254. Part 2: Rename nsAudioStream::GetFormat() to Format(), make it static, and use it instead of the MOZ_AUDIO_DATA_FORMAT macro. r=kinetik
authorRobert O'Callahan <robert@ocallahan.org>
Thu, 25 Oct 2012 23:09:38 +1300
changeset 111486 c30be4a4cd06a4ac8e608270c26554f4f347d693
parent 111485 b9102f7a79c0dc6038954876ce59f5967d662779
child 111487 afb0fa607ef2f12dc8f7d238535b4e91768af412
push id23748
push userryanvm@gmail.com
push dateFri, 26 Oct 2012 11:29:12 +0000
treeherdermozilla-central@8586bd350875 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs805254
milestone19.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 805254. Part 2: Rename nsAudioStream::GetFormat() to Format(), make it static, and use it instead of the MOZ_AUDIO_DATA_FORMAT macro. r=kinetik Part 8 mostly replaces this patch, but it's quite difficult to reorder the patches to avoid this one.
content/media/AudioSegment.cpp
content/media/nsAudioStream.cpp
content/media/nsAudioStream.h
content/media/nsBuiltinDecoderStateMachine.cpp
--- a/content/media/AudioSegment.cpp
+++ b/content/media/AudioSegment.cpp
@@ -153,30 +153,30 @@ AudioSegment::ApplyVolume(float aVolume)
 
 static const int STATIC_AUDIO_BUFFER_BYTES = 50000;
 
 void
 AudioSegment::WriteTo(nsAudioStream* aOutput)
 {
   NS_ASSERTION(mChannels == aOutput->GetChannels(), "Wrong number of channels");
   nsAutoTArray<uint8_t,STATIC_AUDIO_BUFFER_BYTES> buf;
-  uint32_t frameSize = GetSampleSize(aOutput->GetFormat())*mChannels;
+  uint32_t frameSize = GetSampleSize(nsAudioStream::Format())*mChannels;
   for (ChunkIterator ci(*this); !ci.IsEnded(); ci.Next()) {
     AudioChunk& c = *ci;
     if (frameSize*c.mDuration > UINT32_MAX) {
       NS_ERROR("Buffer overflow");
       return;
     }
     buf.SetLength(int32_t(frameSize*c.mDuration));
     if (c.mBuffer) {
       InterleaveAndConvertBuffer(c.mBuffer->Data(), c.mBufferFormat, c.mBufferLength,
                                  c.mOffset, int32_t(c.mDuration),
                                  c.mVolume,
                                  aOutput->GetChannels(),
-                                 buf.Elements(), aOutput->GetFormat());
+                                 buf.Elements(), nsAudioStream::Format());
     } else {
       // Assumes that a bit pattern of zeroes == 0.0f
       memset(buf.Elements(), 0, buf.Length());
     }
     aOutput->Write(buf.Elements(), int32_t(c.mDuration));
   }
 }
 
--- a/content/media/nsAudioStream.cpp
+++ b/content/media/nsAudioStream.cpp
@@ -128,17 +128,17 @@ class AudioInitEvent : public nsRunnable
   }
 
   NS_IMETHOD Run()
   {
     ContentChild * cpc = ContentChild::GetSingleton();
     NS_ASSERTION(cpc, "Content Protocol is NULL!");
     mOwner->mAudioChild =  static_cast<AudioChild*>(cpc->SendPAudioConstructor(mOwner->mChannels,
                                                                                mOwner->mRate,
-                                                                               MOZ_AUDIO_DATA_FORMAT));
+                                                                               Format()));
     return NS_OK;
   }
 
   nsRefPtr<nsRemotedAudioStream> mOwner;
 };
 
 class AudioWriteEvent : public nsRunnable
 {
--- a/content/media/nsAudioStream.h
+++ b/content/media/nsAudioStream.h
@@ -7,20 +7,18 @@
 #define nsAudioStream_h_
 
 #include "nscore.h"
 #include "nsISupportsImpl.h"
 #include "nsIThread.h"
 #include "nsAutoPtr.h"
 
 #ifdef MOZ_SAMPLE_TYPE_S16
-#define MOZ_AUDIO_DATA_FORMAT (nsAudioStream::FORMAT_S16)
 typedef short SampleType;
 #else
-#define MOZ_AUDIO_DATA_FORMAT (nsAudioStream::FORMAT_FLOAT32)
 typedef float SampleType;
 #endif
 
 // Access to a single instance of this class must be synchronized by
 // callers, or made from a single thread.  One exception is that access to
 // GetPosition, GetPositionInFrames, SetVolume, and Get{Rate,Channels,Format}
 // is thread-safe without external synchronization.
 class nsAudioStream : public nsISupports
@@ -108,17 +106,24 @@ public:
   // Returns the minimum number of audio frames which must be written before
   // you can be sure that something will be played.
   // Unsafe to call with a monitor held due to synchronous event execution
   // on the main thread, which may attempt to acquire any held monitor.
   virtual int32_t GetMinWriteSize() = 0;
 
   int GetRate() { return mRate; }
   int GetChannels() { return mChannels; }
-  SampleFormat GetFormat() { return MOZ_AUDIO_DATA_FORMAT; }
+
+  static SampleFormat Format() {
+#ifdef MOZ_SAMPLE_TYPE_S16
+    return nsAudioStream::FORMAT_S16;
+#else
+    return nsAudioStream::FORMAT_FLOAT32;
+#endif
+  }
 
 protected:
   nsCOMPtr<nsIThread> mAudioPlaybackThread;
   int mRate;
   int mChannels;
 };
 
 #endif
--- a/content/media/nsBuiltinDecoderStateMachine.cpp
+++ b/content/media/nsBuiltinDecoderStateMachine.cpp
@@ -556,17 +556,17 @@ void nsBuiltinDecoderStateMachine::SendS
   }
 
   if (offset >= aAudio->mFrames)
     return;
 
   aAudio->EnsureAudioBuffer();
   nsRefPtr<SharedBuffer> buffer = aAudio->mAudioBuffer;
   aOutput->AppendFrames(buffer.forget(), aAudio->mFrames, int32_t(offset), aAudio->mFrames,
-                        MOZ_AUDIO_DATA_FORMAT);
+                        nsAudioStream::Format());
   LOG(PR_LOG_DEBUG, ("%p Decoder writing %d frames of data to MediaStream for AudioData at %lld",
                      mDecoder.get(), aAudio->mFrames - int32_t(offset), aAudio->mTime));
   aStream->mAudioFramesWritten += aAudio->mFrames - int32_t(offset);
 }
 
 static void WriteVideoToMediaStream(mozilla::layers::Image* aImage,
                                     int64_t aDuration, const gfxIntSize& aIntrinsicSize,
                                     VideoSegment* aOutput)