зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1672072 - P1. Add async wrapper. r=mattwoodrow,bryce,mjf,padenot
This method will become the main entry point of a PDM and allow to create a decoder asynchronously for PDM not supporting that interface. Differential Revision: https://phabricator.services.mozilla.com/D96357
This commit is contained in:
Родитель
6ab48a8579
Коммит
4b07d3400c
|
@ -0,0 +1,53 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "PlatformDecoderModule.h"
|
||||
|
||||
#include "nsPrintfCString.h"
|
||||
|
||||
namespace mozilla {
|
||||
|
||||
RefPtr<PlatformDecoderModule::CreateDecoderPromise>
|
||||
PlatformDecoderModule::AsyncCreateDecoder(const CreateDecoderParams& aParams) {
|
||||
RefPtr<MediaDataDecoder> decoder;
|
||||
if (aParams.mError) {
|
||||
*aParams.mError = NS_OK;
|
||||
}
|
||||
if (aParams.mConfig.IsAudio()) {
|
||||
decoder = CreateAudioDecoder(aParams);
|
||||
} else if (aParams.mConfig.IsVideo()) {
|
||||
decoder = CreateAudioDecoder(aParams);
|
||||
}
|
||||
if (!decoder) {
|
||||
if (aParams.mError && NS_FAILED(*aParams.mError)) {
|
||||
return CreateDecoderPromise::CreateAndReject(*aParams.mError, __func__);
|
||||
}
|
||||
return CreateDecoderPromise::CreateAndReject(
|
||||
MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR,
|
||||
nsPrintfCString("Error creating decoder for %s",
|
||||
aParams.mConfig.mMimeType.get())
|
||||
.get()),
|
||||
__func__);
|
||||
}
|
||||
RefPtr<CreateDecoderPromise> p = decoder->Init()->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
[decoder](MediaDataDecoder::InitPromise::ResolveOrRejectValue&& aValue) {
|
||||
RefPtr<CreateDecoderPromise> p;
|
||||
if (aValue.IsReject()) {
|
||||
p = decoder->Shutdown()->Then(
|
||||
GetCurrentSerialEventTarget(), __func__,
|
||||
[reject = aValue.RejectValue()]() {
|
||||
return CreateDecoderPromise::CreateAndReject(reject, __func__);
|
||||
});
|
||||
} else {
|
||||
p = CreateDecoderPromise::CreateAndResolve(decoder, __func__);
|
||||
}
|
||||
return p;
|
||||
});
|
||||
return p;
|
||||
}
|
||||
|
||||
} // namespace mozilla
|
|
@ -270,6 +270,10 @@ class PlatformDecoderModule {
|
|||
SupportsColorDepth(videoInfo->mColorDepth, aDiagnostics);
|
||||
}
|
||||
|
||||
typedef MozPromise<RefPtr<MediaDataDecoder>, MediaResult,
|
||||
/* IsExclusive = */ true>
|
||||
CreateDecoderPromise;
|
||||
|
||||
protected:
|
||||
PlatformDecoderModule() = default;
|
||||
virtual ~PlatformDecoderModule() = default;
|
||||
|
@ -318,6 +322,10 @@ class PlatformDecoderModule {
|
|||
// not to allow for fallback PDMs to be tried.
|
||||
virtual already_AddRefed<MediaDataDecoder> CreateAudioDecoder(
|
||||
const CreateDecoderParams& aParams) = 0;
|
||||
|
||||
// Asychronously create a decoder.
|
||||
virtual RefPtr<CreateDecoderPromise> AsyncCreateDecoder(
|
||||
const CreateDecoderParams& aParams);
|
||||
};
|
||||
|
||||
DDLoggedTypeDeclName(MediaDataDecoder);
|
||||
|
|
|
@ -39,6 +39,7 @@ UNIFIED_SOURCES += [
|
|||
"AllocationPolicy.cpp",
|
||||
"PDMFactory.cpp",
|
||||
"PEMFactory.cpp",
|
||||
"PlatformDecoderModule.cpp",
|
||||
"wrappers/AudioTrimmer.cpp",
|
||||
"wrappers/MediaChangeMonitor.cpp",
|
||||
"wrappers/MediaDataDecoderProxy.cpp",
|
||||
|
|
Загрузка…
Ссылка в новой задаче