Bug 820596 - Defend against nullptr calls to mDecoderStateMachine and mReentrantMonitor r=cpearce

This commit is contained in:
Steve Workman 2012-12-13 11:42:45 -08:00
parent d35442c8ee
commit a9d69b1969
2 changed files with 17 additions and 1 deletions

View File

@ -283,6 +283,7 @@ double MediaDecoder::GetDuration()
int64_t MediaDecoder::GetMediaDuration()
{
NS_ENSURE_TRUE(GetStateMachine(), -1);
return GetStateMachine()->GetDuration();
}
@ -429,6 +430,7 @@ nsresult MediaDecoder::Load(MediaResource* aResource,
nsresult MediaDecoder::InitializeStateMachine(MediaDecoder* aCloneDonor)
{
MOZ_ASSERT(NS_IsMainThread());
NS_ASSERTION(mDecoderStateMachine, "Cannot initialize null state machine!");
MediaDecoder* cloneDonor = static_cast<MediaDecoder*>(aCloneDonor);
if (NS_FAILED(mDecoderStateMachine->Init(cloneDonor ?
@ -968,6 +970,7 @@ void MediaDecoder::NotifyPrincipalChanged()
void MediaDecoder::NotifyBytesConsumed(int64_t aBytes)
{
NS_ENSURE_TRUE(mDecoderStateMachine, );
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
MOZ_ASSERT(OnStateMachineThread() || mDecoderStateMachine->OnDecodeThread());
if (!mIgnoreProgressData) {
@ -1199,6 +1202,7 @@ void MediaDecoder::SetDuration(double aDuration)
void MediaDecoder::SetMediaDuration(int64_t aDuration)
{
NS_ENSURE_TRUE(GetStateMachine(), );
GetStateMachine()->SetDuration(aDuration);
}
@ -1229,6 +1233,7 @@ bool MediaDecoder::IsTransportSeekable()
bool MediaDecoder::IsMediaSeekable()
{
NS_ENSURE_TRUE(GetStateMachine(), false);
ReentrantMonitorAutoEnter mon(GetReentrantMonitor());
MOZ_ASSERT(OnDecodeThread() || NS_IsMainThread());
return mMediaSeekable;
@ -1265,6 +1270,7 @@ void MediaDecoder::SetFragmentEndTime(double aTime)
void MediaDecoder::SetMediaEndTime(int64_t aTime)
{
NS_ENSURE_TRUE(GetStateMachine(), );
GetStateMachine()->SetMediaEndTime(aTime);
}
@ -1367,6 +1373,7 @@ void MediaDecoder::SetPreservesPitch(bool aPreservesPitch)
}
bool MediaDecoder::OnDecodeThread() const {
NS_ENSURE_TRUE(mDecoderStateMachine, false);
return mDecoderStateMachine->OnDecodeThread();
}
@ -1426,10 +1433,12 @@ MediaDecoderStateMachine* MediaDecoder::GetStateMachine() const {
}
bool MediaDecoder::IsShutdown() const {
NS_ENSURE_TRUE(GetStateMachine(), true);
return GetStateMachine()->IsShutdown();
}
int64_t MediaDecoder::GetEndMediaTime() const {
NS_ENSURE_TRUE(GetStateMachine(), -1);
return GetStateMachine()->GetEndMediaTime();
}

View File

@ -473,7 +473,14 @@ ReentrantMonitor&
DASHRepDecoder::GetReentrantMonitor()
{
NS_ASSERTION(mMainDecoder, "Can't get monitor if main decoder is null!");
return mMainDecoder->GetReentrantMonitor();
if (mMainDecoder) {
return mMainDecoder->GetReentrantMonitor();
} else {
// XXX If mMainDecoder is gone, most likely we're past shutdown and
// a waiting function has been wakened. Just return this decoder's own
// monitor and let the function complete.
return MediaDecoder::GetReentrantMonitor();
}
}
mozilla::layers::ImageContainer*