Bug 1144481 - Force state machine setting to go through a setter. r=jww

We need this so that we can hook up the state mirroring in the subsequent patch.
This commit is contained in:
Bobby Holley 2015-04-02 10:49:01 -07:00
parent 0f474e5cf5
commit 3849ab2cb8
4 changed files with 32 additions and 20 deletions

View File

@ -712,8 +712,8 @@ nsresult MediaDecoder::Load(nsIStreamListener** aStreamListener,
nsresult rv = OpenResource(aStreamListener);
NS_ENSURE_SUCCESS(rv, rv);
mDecoderStateMachine = CreateStateMachine();
NS_ENSURE_TRUE(mDecoderStateMachine, NS_ERROR_FAILURE);
SetStateMachine(CreateStateMachine());
NS_ENSURE_TRUE(GetStateMachine(), NS_ERROR_FAILURE);
return InitializeStateMachine(aCloneDonor);
}
@ -1596,6 +1596,13 @@ bool MediaDecoder::OnDecodeTaskQueue() const {
return mDecoderStateMachine ? mDecoderStateMachine->OnDecodeTaskQueue() : false;
}
void
MediaDecoder::SetStateMachine(MediaDecoderStateMachine* aStateMachine)
{
MOZ_ASSERT_IF(aStateMachine, !mDecoderStateMachine);
mDecoderStateMachine = aStateMachine;
}
ReentrantMonitor& MediaDecoder::GetReentrantMonitor() {
return mReentrantMonitor;
}
@ -1670,7 +1677,7 @@ bool MediaDecoder::IsShutdown() const {
// Drop reference to state machine. Only called during shutdown dance.
void MediaDecoder::BreakCycles() {
mDecoderStateMachine = nullptr;
SetStateMachine(nullptr);
}
MediaDecoderOwner* MediaDecoder::GetMediaOwner() const

View File

@ -680,6 +680,9 @@ public:
bool OnDecodeTaskQueue() const override;
MediaDecoderStateMachine* GetStateMachine() { return mDecoderStateMachine; }
void SetStateMachine(MediaDecoderStateMachine* aStateMachine);
// Returns the monitor for other threads to synchronise access to
// state.
ReentrantMonitor& GetReentrantMonitor() override;
@ -1109,17 +1112,19 @@ protected:
* The following member variables can be accessed from any thread.
******/
// Media data resource.
nsRefPtr<MediaResource> mResource;
private:
// The state machine object for handling the decoding. It is safe to
// call methods of this object from other threads. Its internal data
// is synchronised on a monitor. The lifetime of this object is
// after mPlayState is LOADING and before mPlayState is SHUTDOWN. It
// is safe to access it during this period.
//
// Explicitly prievate to force access via accessors.
nsRefPtr<MediaDecoderStateMachine> mDecoderStateMachine;
// Media data resource.
nsRefPtr<MediaResource> mResource;
private:
// |ReentrantMonitor| for detecting when the video play state changes. A call
// to |Wait| on this monitor will block the thread until the next state
// change. Explicitly private for force access via GetReentrantMonitor.

View File

@ -54,14 +54,14 @@ MediaSourceDecoder::CreateStateMachine()
nsresult
MediaSourceDecoder::Load(nsIStreamListener**, MediaDecoder*)
{
MOZ_ASSERT(!mDecoderStateMachine);
mDecoderStateMachine = CreateStateMachine();
if (!mDecoderStateMachine) {
MOZ_ASSERT(!GetStateMachine());
SetStateMachine(CreateStateMachine());
if (!GetStateMachine()) {
NS_WARNING("Failed to create state machine!");
return NS_ERROR_FAILURE;
}
nsresult rv = mDecoderStateMachine->Init(nullptr);
nsresult rv = GetStateMachine()->Init(nullptr);
NS_ENSURE_SUCCESS(rv, rv);
SetStateMachineParameters();
@ -116,7 +116,7 @@ MediaSourceDecoder::CreateResource(nsIPrincipal* aPrincipal)
void
MediaSourceDecoder::AttachMediaSource(dom::MediaSource* aMediaSource)
{
MOZ_ASSERT(!mMediaSource && !mDecoderStateMachine && NS_IsMainThread());
MOZ_ASSERT(!mMediaSource && !GetStateMachine() && NS_IsMainThread());
mMediaSource = aMediaSource;
}
@ -233,10 +233,10 @@ MediaSourceDecoder::SetMediaSourceDuration(double aDuration, MSRangeRemovalActio
// We want a very bigger number, but not infinity.
checkedDuration = INT64_MAX - 1;
}
mDecoderStateMachine->SetDuration(checkedDuration);
GetStateMachine()->SetDuration(checkedDuration);
mMediaSourceDuration = aDuration;
} else {
mDecoderStateMachine->SetDuration(INT64_MAX);
GetStateMachine()->SetDuration(INT64_MAX);
mMediaSourceDuration = PositiveInfinity<double>();
}
if (mReader) {

View File

@ -98,16 +98,16 @@ MediaOmxCommonDecoder::PauseStateMachine()
MOZ_ASSERT(NS_IsMainThread());
GetReentrantMonitor().AssertCurrentThreadIn();
DECODER_LOG(PR_LOG_DEBUG, ("%s", __PRETTY_FUNCTION__));
if (!mDecoderStateMachine) {
if (!GetStateMachine()) {
return;
}
// enter dormant state
RefPtr<nsRunnable> event =
NS_NewRunnableMethodWithArg<bool>(
mDecoderStateMachine,
GetStateMachine(),
&MediaDecoderStateMachine::SetDormant,
true);
mDecoderStateMachine->TaskQueue()->Dispatch(event);
GetStateMachine()->TaskQueue()->Dispatch(event);
}
void
@ -118,7 +118,7 @@ MediaOmxCommonDecoder::ResumeStateMachine()
DECODER_LOG(PR_LOG_DEBUG, ("%s current time %f", __PRETTY_FUNCTION__,
mCurrentTime));
if (!mDecoderStateMachine) {
if (!GetStateMachine()) {
return;
}
@ -134,10 +134,10 @@ MediaOmxCommonDecoder::ResumeStateMachine()
// exit dormant state
RefPtr<nsRunnable> event =
NS_NewRunnableMethodWithArg<bool>(
mDecoderStateMachine,
GetStateMachine(),
&MediaDecoderStateMachine::SetDormant,
false);
mDecoderStateMachine->TaskQueue()->Dispatch(event);
GetStateMachine()->TaskQueue()->Dispatch(event);
}
void