Bug 1277188. Part 4 - remove AudioClock::mAudioStream. r=kinetik.
authorJW Wang <jwwang@mozilla.com>
Wed, 01 Jun 2016 16:36:10 +0800
changeset 339310 6f33d9a58e7216799c5f98238b7a56620083a5fe
parent 339309 76384d9681f05f0ecbf441da86f488263b76523f
child 339311 a340f7b143e30ee0f8449855070b7232275ba1fd
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik
bugs1277188
milestone49.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 1277188. Part 4 - remove AudioClock::mAudioStream. r=kinetik. MozReview-Commit-ID: KjrfgHIg8z4
dom/media/AudioStream.cpp
dom/media/AudioStream.h
--- a/dom/media/AudioStream.cpp
+++ b/dom/media/AudioStream.cpp
@@ -120,17 +120,16 @@ private:
 };
 
 AudioStream::AudioStream(DataSource& aSource)
   : mMonitor("AudioStream")
   , mInRate(0)
   , mOutRate(0)
   , mChannels(0)
   , mOutChannels(0)
-  , mAudioClock(this)
   , mTimeStretcher(nullptr)
   , mDumpFile(nullptr)
   , mState(INITIALIZED)
   , mDataSource(aSource)
 {
 }
 
 AudioStream::~AudioStream()
@@ -347,17 +346,17 @@ AudioStream::Init(uint32_t aNumChannels,
 #endif
 
   if (params.stream_type == CUBEB_STREAM_TYPE_MAX) {
     return NS_ERROR_INVALID_ARG;
   }
 #endif
 
   params.format = ToCubebFormat<AUDIO_OUTPUT_FORMAT>::value;
-  mAudioClock.Init();
+  mAudioClock.Init(aRate);
 
   return OpenCubeb(params, startTime, isFirst);
 }
 
 nsresult
 AudioStream::OpenCubeb(cubeb_stream_params& aParams,
                        TimeStamp aStartTime, bool aIsFirst)
 {
@@ -641,28 +640,27 @@ AudioStream::StateCallback(cubeb_state a
     mState = DRAINED;
     mDataSource.Drained();
   } else if (aState == CUBEB_STATE_ERROR) {
     LOG("StateCallback() state %d cubeb error", mState);
     mState = ERRORED;
   }
 }
 
-AudioClock::AudioClock(AudioStream* aStream)
- :mAudioStream(aStream),
-  mOutRate(0),
+AudioClock::AudioClock()
+: mOutRate(0),
   mInRate(0),
   mPreservesPitch(true),
   mFrameHistory(new FrameHistory())
 {}
 
-void AudioClock::Init()
+void AudioClock::Init(uint32_t aRate)
 {
-  mOutRate = mAudioStream->GetRate();
-  mInRate = mAudioStream->GetRate();
+  mOutRate = aRate;
+  mInRate = aRate;
 }
 
 void AudioClock::UpdateFrameHistory(uint32_t aServiced, uint32_t aUnderrun)
 {
   mFrameHistory->Append(aServiced, aUnderrun, mOutRate);
 }
 
 int64_t AudioClock::GetPositionInFrames(int64_t frames) const
--- a/dom/media/AudioStream.h
+++ b/dom/media/AudioStream.h
@@ -30,20 +30,22 @@ struct CubebDestroyPolicy
 class AudioStream;
 class FrameHistory;
 class AudioConfig;
 class AudioConverter;
 
 class AudioClock
 {
 public:
-  explicit AudioClock(AudioStream* aStream);
-  // Initialize the clock with the current AudioStream. Need to be called
-  // before querying the clock. Called on the audio thread.
-  void Init();
+  AudioClock();
+
+  // Initialize the clock with the current sampling rate.
+  // Need to be called before querying the clock.
+  void Init(uint32_t aRate);
+
   // Update the number of samples that has been written in the audio backend.
   // Called on the state machine thread.
   void UpdateFrameHistory(uint32_t aServiced, uint32_t aUnderrun);
 
   /**
    * @param frames The playback position in frames of the audio engine.
    * @return The playback position in frames of the stream,
    *         adjusted by playback rate changes and underrun frames.
@@ -66,20 +68,18 @@ public:
   // Called on the audio thread.
   double GetPlaybackRate() const;
   // Set if we are preserving the pitch.
   // Called on the audio thread.
   void SetPreservesPitch(bool aPreservesPitch);
   // Get the current pitch preservation state.
   // Called on the audio thread.
   bool GetPreservesPitch() const;
+
 private:
-  // This AudioStream holds a strong reference to this AudioClock. This
-  // pointer is garanteed to always be valid.
-  AudioStream* const mAudioStream;
   // Output rate in Hz (characteristic of the playback rate)
   uint32_t mOutRate;
   // Input rate in Hz (characteristic of the media being played)
   uint32_t mInRate;
   // True if the we are timestretching, false if we are resampling.
   bool mPreservesPitch;
   // The history of frames sent to the audio engine in each DataCallback.
   const nsAutoPtr<FrameHistory> mFrameHistory;