bool MP4Reader::EnsureDecodersSetup() { if (CheckIfDecoderSetup()) { return true; } if (mIsEncrypted) { // EME not supported. return false; } else { // mPlatform doesn't need to be recreated when resuming from dormant. if (!mPlatform) { mPlatform = PlatformDecoderModule::Create(); NS_ENSURE_TRUE(mPlatform, false); } } if (HasAudio()) { NS_ENSURE_TRUE(IsSupportedAudioMimeType(mDemuxer->AudioConfig().mMimeType), false); mAudio.mDecoder = mPlatform->CreateDecoder(mDemuxer->AudioConfig(), mAudio.mTaskQueue, mAudio.mCallback); NS_ENSURE_TRUE(mAudio.mDecoder != nullptr, false); nsresult rv = mAudio.mDecoder->Init(); NS_ENSURE_SUCCESS(rv, false); } if (HasVideo()) { NS_ENSURE_TRUE(IsSupportedVideoMimeType(mDemuxer->VideoConfig().mMimeType), false); if (mSharedDecoderManager && mPlatform->SupportsSharedDecoders(mDemuxer->VideoConfig())) { mVideo.mDecoder = mSharedDecoderManager->CreateVideoDecoder(mPlatform, mDemuxer->VideoConfig(), mLayersBackendType, mDecoder->GetImageContainer(), mVideo.mTaskQueue, mVideo.mCallback); } else { mVideo.mDecoder = mPlatform->CreateDecoder(mDemuxer->VideoConfig(), mVideo.mTaskQueue, mVideo.mCallback, mLayersBackendType, mDecoder->GetImageContainer()); } NS_ENSURE_TRUE(mVideo.mDecoder != nullptr, false); nsresult rv = mVideo.mDecoder->Init(); NS_ENSURE_SUCCESS(rv, false); } return true; }
bool MP4Reader::EnsureDecodersSetup() { if (mAreDecodersSetup) { return !!mPlatform; } if (mIsEncrypted) { #ifdef MOZ_EME // We have encrypted audio or video. We'll need a CDM to decrypt and // possibly decode this. Wait until we've received a CDM from the // JavaScript player app. Note: we still go through the motions here // even if EME is disabled, so that if script tries and fails to create // a CDM, we can detect that and notify chrome and show some UI explaining // that we failed due to EME being disabled. nsRefPtr<CDMProxy> proxy; if (IsWaitingMediaResources()) { return true; } MOZ_ASSERT(!IsWaitingMediaResources()); { ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor()); proxy = mDecoder->GetCDMProxy(); } MOZ_ASSERT(proxy); mPlatform = PlatformDecoderModule::CreateCDMWrapper(proxy, HasAudio(), HasVideo()); NS_ENSURE_TRUE(mPlatform, false); #else // EME not supported. return false; #endif } else { mPlatform = PlatformDecoderModule::Create(); NS_ENSURE_TRUE(mPlatform, false); } if (HasAudio()) { NS_ENSURE_TRUE(IsSupportedAudioMimeType(mDemuxer->AudioConfig().mime_type), false); mAudio.mDecoder = mPlatform->CreateAudioDecoder(mDemuxer->AudioConfig(), mAudio.mTaskQueue, mAudio.mCallback); NS_ENSURE_TRUE(mAudio.mDecoder != nullptr, false); nsresult rv = mAudio.mDecoder->Init(); NS_ENSURE_SUCCESS(rv, false); } if (HasVideo()) { NS_ENSURE_TRUE(IsSupportedVideoMimeType(mDemuxer->VideoConfig().mime_type), false); if (mSharedDecoderManager && mPlatform->SupportsSharedDecoders(mDemuxer->VideoConfig())) { mVideo.mDecoder = mSharedDecoderManager->CreateVideoDecoder(mPlatform, mDemuxer->VideoConfig(), mLayersBackendType, mDecoder->GetImageContainer(), mVideo.mTaskQueue, mVideo.mCallback); } else { mVideo.mDecoder = mPlatform->CreateVideoDecoder(mDemuxer->VideoConfig(), mLayersBackendType, mDecoder->GetImageContainer(), mVideo.mTaskQueue, mVideo.mCallback); } NS_ENSURE_TRUE(mVideo.mDecoder != nullptr, false); nsresult rv = mVideo.mDecoder->Init(); NS_ENSURE_SUCCESS(rv, false); } mAreDecodersSetup = true; return true; }