Bug 1277188. Part 4 - remove AudioClock::mAudioStream. r=kinetik.
MozReview-Commit-ID: KjrfgHIg8z4
--- 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;