diff --git a/dom/html/HTMLMediaElement.cpp b/dom/html/HTMLMediaElement.cpp
index 81e86992d819..e0cb3441f61a 100644
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -1889,7 +1889,6 @@ HTMLMediaElement::CaptureStreamInternal(bool aFinishWhenEnded)
// back into the output stream.
out->mStream->GetStream()->ChangeExplicitBlockerCount(1);
if (mDecoder) {
- mDecoder->SetAudioCaptured(true);
mDecoder->AddOutputStream(
out->mStream->GetStream()->AsProcessedStream(), aFinishWhenEnded);
}
@@ -2705,7 +2704,6 @@ nsresult HTMLMediaElement::FinishDecoderSetup(MediaDecoder* aDecoder,
// available immediately.
mDecoder->SetResource(aStream);
mDecoder->SetAudioChannel(mAudioChannel);
- mDecoder->SetAudioCaptured(mAudioCaptured);
mDecoder->SetVolume(mMuted ? 0.0 : mVolume);
mDecoder->SetPreservesPitch(mPreservesPitch);
mDecoder->SetPlaybackRate(mPlaybackRate);
diff --git a/dom/media/MediaDecoder.cpp b/dom/media/MediaDecoder.cpp
index 9e6b7eea649f..96597e405681 100644
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -263,15 +263,6 @@ void MediaDecoder::SetVolume(double aVolume)
}
}
-void MediaDecoder::SetAudioCaptured(bool aCaptured)
-{
- MOZ_ASSERT(NS_IsMainThread());
- mInitialAudioCaptured = aCaptured;
- if (mDecoderStateMachine) {
- mDecoderStateMachine->SetAudioCaptured(aCaptured);
- }
-}
-
void MediaDecoder::ConnectDecodedStreamToOutputStream(OutputStreamData* aStream)
{
NS_ASSERTION(!aStream->mPort, "Already connected?");
@@ -360,13 +351,6 @@ MediaDecoder::DecodedStreamGraphListener::NotifyEvent(MediaStreamGraph* aGraph,
}
}
-void MediaDecoder::RecreateDecodedStreamIfNecessary(int64_t aStartTimeUSecs)
-{
- if (mInitialAudioCaptured) {
- RecreateDecodedStream(aStartTimeUSecs);
- }
-}
-
void MediaDecoder::DestroyDecodedStream()
{
MOZ_ASSERT(NS_IsMainThread());
@@ -470,9 +454,13 @@ void MediaDecoder::AddOutputStream(ProcessedMediaStream* aStream,
{
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
- if (!mDecodedStream) {
- RecreateDecodedStream(mDecoderStateMachine ?
- int64_t(mDecoderStateMachine->GetCurrentTime()*USECS_PER_S) : 0);
+ if (mDecoderStateMachine) {
+ mDecoderStateMachine->SetAudioCaptured();
+ }
+ if (!GetDecodedStream()) {
+ int64_t t = mDecoderStateMachine ?
+ mDecoderStateMachine->GetCurrentTimeUs() : 0;
+ RecreateDecodedStream(t);
}
OutputStreamData* os = mOutputStreams.AppendElement();
os->Init(aStream, aFinishWhenEnded);
@@ -672,7 +660,9 @@ void MediaDecoder::SetStateMachineParameters()
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
mDecoderStateMachine->SetDuration(mDuration);
mDecoderStateMachine->SetVolume(mInitialVolume);
- mDecoderStateMachine->SetAudioCaptured(mInitialAudioCaptured);
+ if (GetDecodedStream()) {
+ mDecoderStateMachine->SetAudioCaptured();
+ }
SetPlaybackRate(mInitialPlaybackRate);
mDecoderStateMachine->SetPreservesPitch(mInitialPreservesPitch);
if (mMinimizePreroll) {
diff --git a/dom/media/MediaDecoder.h b/dom/media/MediaDecoder.h
index eae936b49f73..1895826ac772 100644
--- a/dom/media/MediaDecoder.h
+++ b/dom/media/MediaDecoder.h
@@ -374,9 +374,6 @@ public:
virtual void Pause();
// Adjust the speed of the playback, optionally with pitch correction,
virtual void SetVolume(double aVolume);
- // Sets whether audio is being captured. If it is, we won't play any
- // of our audio.
- virtual void SetAudioCaptured(bool aCaptured);
virtual void NotifyWaitingForResourcesStatusChanged() MOZ_OVERRIDE;
@@ -857,9 +854,6 @@ public:
// The decoder monitor must be held.
bool IsLogicallyPlaying();
- // Re-create a decoded stream if audio being captured
- void RecreateDecodedStreamIfNecessary(int64_t aStartTimeUSecs);
-
#ifdef MOZ_EME
// This takes the decoder monitor.
virtual nsresult SetCDMProxy(CDMProxy* aProxy) MOZ_OVERRIDE;
@@ -1068,9 +1062,6 @@ protected:
// only.
int64_t mDuration;
- // True when playback should start with audio captured (not playing).
- bool mInitialAudioCaptured;
-
// True if the media is seekable (i.e. supports random access).
bool mMediaSeekable;
diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp
index db2fea73b0cf..98d2a557540e 100644
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -1387,11 +1387,11 @@ void MediaDecoderStateMachine::SetVolume(double volume)
}
}
-void MediaDecoderStateMachine::SetAudioCaptured(bool aCaptured)
+void MediaDecoderStateMachine::SetAudioCaptured()
{
NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
- ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
- if (!mAudioCaptured && aCaptured && !mStopAudioThread) {
+ AssertCurrentThreadInMonitor();
+ if (!mAudioCaptured && !mStopAudioThread) {
// Make sure the state machine runs as soon as possible. That will
// stop the audio sink.
// If mStopAudioThread is true then we're already stopping the audio sink
@@ -1405,7 +1405,7 @@ void MediaDecoderStateMachine::SetAudioCaptured(bool aCaptured)
ResyncAudioClock();
}
}
- mAudioCaptured = aCaptured;
+ mAudioCaptured = true;
}
double MediaDecoderStateMachine::GetCurrentTime() const
@@ -1418,6 +1418,16 @@ double MediaDecoderStateMachine::GetCurrentTime() const
return static_cast(mCurrentFrameTime) / static_cast(USECS_PER_S);
}
+int64_t MediaDecoderStateMachine::GetCurrentTimeUs() const
+{
+ NS_ASSERTION(NS_IsMainThread() ||
+ OnStateMachineThread() ||
+ OnDecodeThread(),
+ "Should be on main, decode, or state machine thread.");
+
+ return mCurrentFrameTime;
+}
+
bool MediaDecoderStateMachine::IsRealTime() const {
return mScheduler->IsRealTime();
}
@@ -1782,7 +1792,9 @@ MediaDecoderStateMachine::StartSeek(const SeekTarget& aTarget)
DECODER_LOG("Changed state to SEEKING (to %lld)", mSeekTarget.mTime);
SetState(DECODER_STATE_SEEKING);
- mDecoder->RecreateDecodedStreamIfNecessary(seekTime - mStartTime);
+ if (mAudioCaptured) {
+ mDecoder->RecreateDecodedStream(seekTime - mStartTime);
+ }
ScheduleStateMachine();
}
diff --git a/dom/media/MediaDecoderStateMachine.h b/dom/media/MediaDecoderStateMachine.h
index 002cae067290..0ad8144a5dec 100644
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -155,7 +155,7 @@ public:
// Set the audio volume. The decoder monitor must be obtained before
// calling this.
void SetVolume(double aVolume);
- void SetAudioCaptured(bool aCapture);
+ void SetAudioCaptured();
// Check if the decoder needs to become dormant state.
bool IsDormantNeeded();
@@ -241,6 +241,7 @@ public:
// Called from the main thread to get the current frame time. The decoder
// monitor must be obtained before calling this.
double GetCurrentTime() const;
+ int64_t GetCurrentTimeUs() const;
// Clear the flag indicating that a playback position change event
// is currently queued. This is called from the main thread and must