Bug 1127171 - Put mozCaptureStream operations in the same lock. r=roc

This commit is contained in:
JW Wang 2015-01-28 18:57:00 -05:00
Родитель 2b1c3cb2e2
Коммит 99e95e2eff
5 изменённых файлов: 29 добавлений и 37 удалений

Просмотреть файл

@ -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);

Просмотреть файл

@ -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) {

Просмотреть файл

@ -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;

Просмотреть файл

@ -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<double>(mCurrentFrameTime) / static_cast<double>(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();
}

Просмотреть файл

@ -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