already_AddRefed<SharedThreadPool> GetMediaThreadPool(MediaThreadType aType) { const char* name; switch (aType) { case MediaThreadType::PLATFORM_DECODER: name = "MediaPDecoder"; break; case MediaThreadType::MSG_CONTROL: name = "MSGControl"; break; case MediaThreadType::WEBRTC_DECODER: name = "WebRTCPD"; break; default: MOZ_FALLTHROUGH_ASSERT("Unexpected MediaThreadType"); case MediaThreadType::PLAYBACK: name = "MediaPlayback"; break; } static const uint32_t kMediaThreadPoolDefaultCount = 4; RefPtr<SharedThreadPool> pool = SharedThreadPool::Get( nsDependentCString(name), kMediaThreadPoolDefaultCount); // Ensure a larger stack for platform decoder threads if (aType == MediaThreadType::PLATFORM_DECODER) { const uint32_t minStackSize = 512 * 1024; uint32_t stackSize; MOZ_ALWAYS_SUCCEEDS(pool->GetThreadStackSize(&stackSize)); if (stackSize < minStackSize) { MOZ_ALWAYS_SUCCEEDS(pool->SetThreadStackSize(minStackSize)); } } return pool.forget(); }
already_AddRefed<SharedThreadPool> GetMediaThreadPool(MediaThreadType aType) { const char *name; switch (aType) { case MediaThreadType::PLATFORM_DECODER: name = "MediaPDecoder"; break; default: MOZ_FALLTHROUGH_ASSERT("Unexpected MediaThreadType"); case MediaThreadType::PLAYBACK: name = "MediaPlayback"; break; } return SharedThreadPool:: Get(nsDependentCString(name), MediaPrefs::MediaThreadPoolDefaultCount()); }
void WebAudioDecodeJob::OnFailure(ErrorCode aErrorCode) { MOZ_ASSERT(NS_IsMainThread()); const char* errorMessage; switch (aErrorCode) { case NoError: MOZ_FALLTHROUGH_ASSERT("Who passed NoError to OnFailure?"); // Fall through to get some sort of a sane error message if this actually // happens at runtime. case UnknownError: errorMessage = "MediaDecodeAudioDataUnknownError"; break; case UnknownContent: errorMessage = "MediaDecodeAudioDataUnknownContentType"; break; case InvalidContent: errorMessage = "MediaDecodeAudioDataInvalidContent"; break; case NoAudio: errorMessage = "MediaDecodeAudioDataNoAudio"; break; } nsIDocument* doc = nullptr; if (nsPIDOMWindowInner* pWindow = mContext->GetParentObject()) { doc = pWindow->GetExtantDoc(); } nsContentUtils::ReportToConsole(nsIScriptError::errorFlag, NS_LITERAL_CSTRING("Media"), doc, nsContentUtils::eDOM_PROPERTIES, errorMessage); // Ignore errors in calling the callback, since there is not much that we can // do about it here. if (mFailureCallback) { mFailureCallback->Call(); } mPromise->MaybeReject(NS_ERROR_DOM_ENCODING_NOT_SUPPORTED_ERR); mContext->RemoveFromDecodeQueue(this); }
// static NativeKeyBindings* NativeKeyBindings::GetInstance(NativeKeyBindingsType aType) { switch (aType) { case nsIWidget::NativeKeyBindingsForSingleLineEditor: if (!sInstanceForSingleLineEditor) { sInstanceForSingleLineEditor = new NativeKeyBindings(); sInstanceForSingleLineEditor->Init(aType); } return sInstanceForSingleLineEditor; default: // fallback to multiline editor case in release build MOZ_FALLTHROUGH_ASSERT("aType is invalid or not yet implemented"); case nsIWidget::NativeKeyBindingsForMultiLineEditor: case nsIWidget::NativeKeyBindingsForRichTextEditor: if (!sInstanceForMultiLineEditor) { sInstanceForMultiLineEditor = new NativeKeyBindings(); sInstanceForMultiLineEditor->Init(aType); } return sInstanceForMultiLineEditor; } }
//****************************************************************************** // DoBlend gets called when the timer for animation get fired and we have to // update the composited frame of the animation. bool FrameAnimator::DoBlend(IntRect* aDirtyRect, uint32_t aPrevFrameIndex, uint32_t aNextFrameIndex) { RawAccessFrameRef prevFrame = GetRawFrame(aPrevFrameIndex); RawAccessFrameRef nextFrame = GetRawFrame(aNextFrameIndex); MOZ_ASSERT(prevFrame && nextFrame, "Should have frames here"); AnimationData prevFrameData = prevFrame->GetAnimationData(); if (prevFrameData.mDisposalMethod == DisposalMethod::RESTORE_PREVIOUS && !mCompositingPrevFrame) { prevFrameData.mDisposalMethod = DisposalMethod::CLEAR; } IntRect prevRect = prevFrameData.mBlendRect ? prevFrameData.mRect.Intersect(*prevFrameData.mBlendRect) : prevFrameData.mRect; bool isFullPrevFrame = prevRect.x == 0 && prevRect.y == 0 && prevRect.width == mSize.width && prevRect.height == mSize.height; // Optimization: DisposeClearAll if the previous frame is the same size as // container and it's clearing itself if (isFullPrevFrame && (prevFrameData.mDisposalMethod == DisposalMethod::CLEAR)) { prevFrameData.mDisposalMethod = DisposalMethod::CLEAR_ALL; } AnimationData nextFrameData = nextFrame->GetAnimationData(); IntRect nextRect = nextFrameData.mBlendRect ? nextFrameData.mRect.Intersect(*nextFrameData.mBlendRect) : nextFrameData.mRect; bool isFullNextFrame = nextRect.x == 0 && nextRect.y == 0 && nextRect.width == mSize.width && nextRect.height == mSize.height; if (!nextFrame->GetIsPaletted()) { // Optimization: Skip compositing if the previous frame wants to clear the // whole image if (prevFrameData.mDisposalMethod == DisposalMethod::CLEAR_ALL) { aDirtyRect->SetRect(0, 0, mSize.width, mSize.height); return true; } // Optimization: Skip compositing if this frame is the same size as the // container and it's fully drawing over prev frame (no alpha) if (isFullNextFrame && (nextFrameData.mDisposalMethod != DisposalMethod::RESTORE_PREVIOUS) && !nextFrameData.mHasAlpha) { aDirtyRect->SetRect(0, 0, mSize.width, mSize.height); return true; } } // Calculate area that needs updating switch (prevFrameData.mDisposalMethod) { default: MOZ_FALLTHROUGH_ASSERT("Unexpected DisposalMethod"); case DisposalMethod::NOT_SPECIFIED: case DisposalMethod::KEEP: *aDirtyRect = nextRect; break; case DisposalMethod::CLEAR_ALL: // Whole image container is cleared aDirtyRect->SetRect(0, 0, mSize.width, mSize.height); break; case DisposalMethod::CLEAR: // Calc area that needs to be redrawn (the combination of previous and // this frame) // XXX - This could be done with multiple framechanged calls // Having prevFrame way at the top of the image, and nextFrame // way at the bottom, and both frames being small, we'd be // telling framechanged to refresh the whole image when only two // small areas are needed. aDirtyRect->UnionRect(nextRect, prevRect); break; case DisposalMethod::RESTORE_PREVIOUS: aDirtyRect->SetRect(0, 0, mSize.width, mSize.height); break; } // Optimization: // Skip compositing if the last composited frame is this frame // (Only one composited frame was made for this animation. Example: // Only Frame 3 of a 10 frame image required us to build a composite frame // On the second loop, we do not need to rebuild the frame // since it's still sitting in compositingFrame) if (mLastCompositedFrameIndex == int32_t(aNextFrameIndex)) { return true; } bool needToBlankComposite = false; // Create the Compositing Frame if (!mCompositingFrame) { RefPtr<imgFrame> newFrame = new imgFrame; nsresult rv = newFrame->InitForDecoder(mSize, SurfaceFormat::B8G8R8A8); if (NS_FAILED(rv)) { mCompositingFrame.reset(); return false; } mCompositingFrame = newFrame->RawAccessRef(); needToBlankComposite = true; } else if (int32_t(aNextFrameIndex) != mLastCompositedFrameIndex+1) { // If we are not drawing on top of last composited frame, // then we are building a new composite frame, so let's clear it first. needToBlankComposite = true; } AnimationData compositingFrameData = mCompositingFrame->GetAnimationData(); // More optimizations possible when next frame is not transparent // But if the next frame has DisposalMethod::RESTORE_PREVIOUS, // this "no disposal" optimization is not possible, // because the frame in "after disposal operation" state // needs to be stored in compositingFrame, so it can be // copied into compositingPrevFrame later. bool doDisposal = true; if (!nextFrameData.mHasAlpha && nextFrameData.mDisposalMethod != DisposalMethod::RESTORE_PREVIOUS) { if (isFullNextFrame) { // Optimization: No need to dispose prev.frame when // next frame is full frame and not transparent. doDisposal = false; // No need to blank the composite frame needToBlankComposite = false; } else { if ((prevRect.x >= nextRect.x) && (prevRect.y >= nextRect.y) && (prevRect.x + prevRect.width <= nextRect.x + nextRect.width) && (prevRect.y + prevRect.height <= nextRect.y + nextRect.height)) { // Optimization: No need to dispose prev.frame when // next frame fully overlaps previous frame. doDisposal = false; } } } if (doDisposal) { // Dispose of previous: clear, restore, or keep (copy) switch (prevFrameData.mDisposalMethod) { case DisposalMethod::CLEAR: if (needToBlankComposite) { // If we just created the composite, it could have anything in its // buffer. Clear whole frame ClearFrame(compositingFrameData.mRawData, compositingFrameData.mRect); } else { // Only blank out previous frame area (both color & Mask/Alpha) ClearFrame(compositingFrameData.mRawData, compositingFrameData.mRect, prevRect); } break; case DisposalMethod::CLEAR_ALL: ClearFrame(compositingFrameData.mRawData, compositingFrameData.mRect); break; case DisposalMethod::RESTORE_PREVIOUS: // It would be better to copy only the area changed back to // compositingFrame. if (mCompositingPrevFrame) { AnimationData compositingPrevFrameData = mCompositingPrevFrame->GetAnimationData(); CopyFrameImage(compositingPrevFrameData.mRawData, compositingPrevFrameData.mRect, compositingFrameData.mRawData, compositingFrameData.mRect); // destroy only if we don't need it for this frame's disposal if (nextFrameData.mDisposalMethod != DisposalMethod::RESTORE_PREVIOUS) { mCompositingPrevFrame.reset(); } } else { ClearFrame(compositingFrameData.mRawData, compositingFrameData.mRect); } break; default: MOZ_FALLTHROUGH_ASSERT("Unexpected DisposalMethod"); case DisposalMethod::NOT_SPECIFIED: case DisposalMethod::KEEP: // Copy previous frame into compositingFrame before we put the new // frame on top // Assumes that the previous frame represents a full frame (it could be // smaller in size than the container, as long as the frame before it // erased itself) // Note: Frame 1 never gets into DoBlend(), so (aNextFrameIndex - 1) // will always be a valid frame number. if (mLastCompositedFrameIndex != int32_t(aNextFrameIndex - 1)) { if (isFullPrevFrame && !prevFrame->GetIsPaletted()) { // Just copy the bits CopyFrameImage(prevFrameData.mRawData, prevRect, compositingFrameData.mRawData, compositingFrameData.mRect); } else { if (needToBlankComposite) { // Only blank composite when prev is transparent or not full. if (prevFrameData.mHasAlpha || !isFullPrevFrame) { ClearFrame(compositingFrameData.mRawData, compositingFrameData.mRect); } } DrawFrameTo(prevFrameData.mRawData, prevFrameData.mRect, prevFrameData.mPaletteDataLength, prevFrameData.mHasAlpha, compositingFrameData.mRawData, compositingFrameData.mRect, prevFrameData.mBlendMethod, prevFrameData.mBlendRect); } } } } else if (needToBlankComposite) { // If we just created the composite, it could have anything in its // buffers. Clear them ClearFrame(compositingFrameData.mRawData, compositingFrameData.mRect); } // Check if the frame we are composing wants the previous image restored after // it is done. Don't store it (again) if last frame wanted its image restored // too if ((nextFrameData.mDisposalMethod == DisposalMethod::RESTORE_PREVIOUS) && (prevFrameData.mDisposalMethod != DisposalMethod::RESTORE_PREVIOUS)) { // We are storing the whole image. // It would be better if we just stored the area that nextFrame is going to // overwrite. if (!mCompositingPrevFrame) { RefPtr<imgFrame> newFrame = new imgFrame; nsresult rv = newFrame->InitForDecoder(mSize, SurfaceFormat::B8G8R8A8); if (NS_FAILED(rv)) { mCompositingPrevFrame.reset(); return false; } mCompositingPrevFrame = newFrame->RawAccessRef(); } AnimationData compositingPrevFrameData = mCompositingPrevFrame->GetAnimationData(); CopyFrameImage(compositingFrameData.mRawData, compositingFrameData.mRect, compositingPrevFrameData.mRawData, compositingPrevFrameData.mRect); mCompositingPrevFrame->Finish(); } // blit next frame into it's correct spot DrawFrameTo(nextFrameData.mRawData, nextFrameData.mRect, nextFrameData.mPaletteDataLength, nextFrameData.mHasAlpha, compositingFrameData.mRawData, compositingFrameData.mRect, nextFrameData.mBlendMethod, nextFrameData.mBlendRect); // Tell the image that it is fully 'downloaded'. mCompositingFrame->Finish(); mLastCompositedFrameIndex = int32_t(aNextFrameIndex); return true; }
void DecoderDoctorDocumentWatcher::SynthesizeAnalysis() { MOZ_ASSERT(NS_IsMainThread()); nsAutoString playableFormats; nsAutoString unplayableFormats; // Subsets of unplayableFormats that require a specific platform decoder: #if defined(XP_WIN) nsAutoString formatsRequiringWMF; #endif #if defined(MOZ_FFMPEG) nsAutoString formatsRequiringFFMpeg; #endif nsAutoString supportedKeySystems; nsAutoString unsupportedKeySystems; DecoderDoctorDiagnostics::KeySystemIssue lastKeySystemIssue = DecoderDoctorDiagnostics::eUnset; // Only deal with one decode error per document (the first one found). const MediaResult* firstDecodeError = nullptr; const nsString* firstDecodeErrorMediaSrc = nullptr; // Only deal with one decode warning per document (the first one found). const MediaResult* firstDecodeWarning = nullptr; const nsString* firstDecodeWarningMediaSrc = nullptr; for (const auto& diag : mDiagnosticsSequence) { switch (diag.mDecoderDoctorDiagnostics.Type()) { case DecoderDoctorDiagnostics::eFormatSupportCheck: if (diag.mDecoderDoctorDiagnostics.CanPlay()) { AppendToFormatsList(playableFormats, diag.mDecoderDoctorDiagnostics.Format()); } else { AppendToFormatsList(unplayableFormats, diag.mDecoderDoctorDiagnostics.Format()); #if defined(XP_WIN) if (diag.mDecoderDoctorDiagnostics.DidWMFFailToLoad()) { AppendToFormatsList(formatsRequiringWMF, diag.mDecoderDoctorDiagnostics.Format()); } #endif #if defined(MOZ_FFMPEG) if (diag.mDecoderDoctorDiagnostics.DidFFmpegFailToLoad()) { AppendToFormatsList(formatsRequiringFFMpeg, diag.mDecoderDoctorDiagnostics.Format()); } #endif } break; case DecoderDoctorDiagnostics::eMediaKeySystemAccessRequest: if (diag.mDecoderDoctorDiagnostics.IsKeySystemSupported()) { AppendToFormatsList(supportedKeySystems, diag.mDecoderDoctorDiagnostics.KeySystem()); } else { AppendToFormatsList(unsupportedKeySystems, diag.mDecoderDoctorDiagnostics.KeySystem()); DecoderDoctorDiagnostics::KeySystemIssue issue = diag.mDecoderDoctorDiagnostics.GetKeySystemIssue(); if (issue != DecoderDoctorDiagnostics::eUnset) { lastKeySystemIssue = issue; } } break; case DecoderDoctorDiagnostics::eEvent: MOZ_ASSERT_UNREACHABLE("Events shouldn't be stored for processing."); break; case DecoderDoctorDiagnostics::eDecodeError: if (!firstDecodeError) { firstDecodeError = &diag.mDecoderDoctorDiagnostics.DecodeIssue(); firstDecodeErrorMediaSrc = &diag.mDecoderDoctorDiagnostics.DecodeIssueMediaSrc(); } break; case DecoderDoctorDiagnostics::eDecodeWarning: if (!firstDecodeWarning) { firstDecodeWarning = &diag.mDecoderDoctorDiagnostics.DecodeIssue(); firstDecodeWarningMediaSrc = &diag.mDecoderDoctorDiagnostics.DecodeIssueMediaSrc(); } break; default: MOZ_ASSERT_UNREACHABLE("Unhandled DecoderDoctorDiagnostics type"); break; } } // Check if issues have been solved, by finding if some now-playable // key systems or formats were previously recorded as having issues. if (!supportedKeySystems.IsEmpty() || !playableFormats.IsEmpty()) { DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - supported key systems '%s', playable formats '%s'; See if they show issues have been solved...", this, mDocument, NS_ConvertUTF16toUTF8(supportedKeySystems).Data(), NS_ConvertUTF16toUTF8(playableFormats).get()); const nsAString* workingFormatsArray[] = { &supportedKeySystems, &playableFormats }; // For each type of notification, retrieve the pref that contains formats/ // key systems with issues. for (const NotificationAndReportStringId* id : sAllNotificationsAndReportStringIds) { nsAutoCString formatsPref("media.decoder-doctor."); formatsPref += id->mReportStringId; formatsPref += ".formats"; nsAutoString formatsWithIssues; Preferences::GetString(formatsPref.Data(), formatsWithIssues); if (formatsWithIssues.IsEmpty()) { continue; } // See if that list of formats-with-issues contains any formats that are // now playable/supported. bool solved = false; for (const nsAString* workingFormats : workingFormatsArray) { for (const auto& workingFormat : MakeStringListRange(*workingFormats)) { if (FormatsListContains(formatsWithIssues, workingFormat)) { // This now-working format used not to work -> Report solved issue. DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - %s solved ('%s' now works, it was in pref(%s)='%s')", this, mDocument, id->mReportStringId, NS_ConvertUTF16toUTF8(workingFormat).get(), formatsPref.Data(), NS_ConvertUTF16toUTF8(formatsWithIssues).get()); ReportAnalysis(mDocument, *id, true, workingFormat); // This particular Notification&ReportId has been solved, no need // to keep looking at other keysys/formats that might solve it too. solved = true; break; } } if (solved) { break; } } if (!solved) { DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - %s not solved (pref(%s)='%s')", this, mDocument, id->mReportStringId, formatsPref.Data(), NS_ConvertUTF16toUTF8(formatsWithIssues).get()); } } } // Look at Key System issues first, as they take precedence over format checks. if (!unsupportedKeySystems.IsEmpty() && supportedKeySystems.IsEmpty()) { // No supported key systems! switch (lastKeySystemIssue) { case DecoderDoctorDiagnostics::eWidevineWithNoWMF: DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unsupported key systems: %s, Widevine without WMF", this, mDocument, NS_ConvertUTF16toUTF8(unsupportedKeySystems).get()); ReportAnalysis(mDocument, sMediaWidevineNoWMF, false, unsupportedKeySystems); return; default: break; } } // Next, check playability of requested formats. if (!unplayableFormats.IsEmpty()) { // Some requested formats cannot be played. if (playableFormats.IsEmpty()) { // No requested formats can be played. See if we can help the user, by // going through expected decoders from most to least desirable. #if defined(XP_WIN) if (!formatsRequiringWMF.IsEmpty()) { DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because WMF was not found", this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringWMF).get()); ReportAnalysis(mDocument, sMediaWMFNeeded, false, formatsRequiringWMF); return; } #endif #if defined(MOZ_FFMPEG) if (!formatsRequiringFFMpeg.IsEmpty()) { switch (FFmpegRuntimeLinker::LinkStatusCode()) { case FFmpegRuntimeLinker::LinkStatus_INVALID_FFMPEG_CANDIDATE: case FFmpegRuntimeLinker::LinkStatus_UNUSABLE_LIBAV57: case FFmpegRuntimeLinker::LinkStatus_INVALID_LIBAV_CANDIDATE: case FFmpegRuntimeLinker::LinkStatus_OBSOLETE_FFMPEG: case FFmpegRuntimeLinker::LinkStatus_OBSOLETE_LIBAV: case FFmpegRuntimeLinker::LinkStatus_INVALID_CANDIDATE: DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because of unsupported %s (Reason: %s)", this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringFFMpeg).get(), FFmpegRuntimeLinker::LinkStatusLibraryName(), FFmpegRuntimeLinker::LinkStatusString()); ReportAnalysis(mDocument, sUnsupportedLibavcodec, false, formatsRequiringFFMpeg); return; case FFmpegRuntimeLinker::LinkStatus_INIT: MOZ_FALLTHROUGH_ASSERT("Unexpected LinkStatus_INIT"); case FFmpegRuntimeLinker::LinkStatus_SUCCEEDED: MOZ_FALLTHROUGH_ASSERT("Unexpected LinkStatus_SUCCEEDED"); case FFmpegRuntimeLinker::LinkStatus_NOT_FOUND: DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - unplayable formats: %s -> Cannot play media because platform decoder was not found (Reason: %s)", this, mDocument, NS_ConvertUTF16toUTF8(formatsRequiringFFMpeg).get(), FFmpegRuntimeLinker::LinkStatusString()); ReportAnalysis(mDocument, sMediaPlatformDecoderNotFound, false, formatsRequiringFFMpeg); return; } } #endif DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Cannot play media, unplayable formats: %s", this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get()); ReportAnalysis(mDocument, sMediaCannotPlayNoDecoders, false, unplayableFormats); return; } DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, but no decoders for some requested formats: %s", this, mDocument, NS_ConvertUTF16toUTF8(unplayableFormats).get()); if (Preferences::GetBool("media.decoder-doctor.verbose", false)) { ReportAnalysis(mDocument, sMediaNoDecoders, false, unplayableFormats); } return; } if (firstDecodeError) { DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Decode error: %s", this, mDocument, firstDecodeError->Description().get()); ReportAnalysis(mDocument, sMediaDecodeError, false, NS_LITERAL_STRING(""), *firstDecodeError, true, // aDecodeIssueIsError=true mDocument->GetDocumentURI()->GetSpecOrDefault(), *firstDecodeErrorMediaSrc); return; } if (firstDecodeWarning) { DD_INFO("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Decode warning: %s", this, mDocument, firstDecodeWarning->Description().get()); ReportAnalysis(mDocument, sMediaDecodeWarning, false, NS_LITERAL_STRING(""), *firstDecodeWarning, false, // aDecodeIssueIsError=false mDocument->GetDocumentURI()->GetSpecOrDefault(), *firstDecodeWarningMediaSrc); return; } DD_DEBUG("DecoderDoctorDocumentWatcher[%p, doc=%p]::SynthesizeAnalysis() - Can play media, decoders available for all requested formats", this, mDocument); }