PlatformDecoderModule.cpp (2120B)
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "PlatformDecoderModule.h" 8 9 #include "ImageContainer.h" 10 #include "nsPrintfCString.h" 11 12 namespace mozilla { 13 14 CreateDecoderParamsForAsync::CreateDecoderParamsForAsync( 15 const CreateDecoderParams& aParams) 16 : mConfig(aParams.mConfig.Clone()), 17 mImageContainer(aParams.mImageContainer), 18 mKnowsCompositor(aParams.mKnowsCompositor), 19 mCrashHelper(aParams.mCrashHelper), 20 mCDM(aParams.mCDM), 21 mUseNullDecoder(aParams.mUseNullDecoder), 22 mWrappers(aParams.mWrappers), 23 mType(aParams.mType), 24 mOnWaitingForKeyEvent(aParams.mOnWaitingForKeyEvent), 25 mOptions(aParams.mOptions), 26 mRate(aParams.mRate), 27 mMediaEngineId(aParams.mMediaEngineId), 28 mTrackingId(aParams.mTrackingId) {} 29 30 CreateDecoderParamsForAsync::CreateDecoderParamsForAsync( 31 CreateDecoderParamsForAsync&& aParams) = default; 32 33 RefPtr<PlatformDecoderModule::CreateDecoderPromise> 34 PlatformDecoderModule::AsyncCreateDecoder(const CreateDecoderParams& aParams) { 35 RefPtr<MediaDataDecoder> decoder; 36 MediaResult result = NS_OK; 37 if (aParams.mConfig.IsAudio()) { 38 decoder = CreateAudioDecoder(CreateDecoderParams{aParams, &result}); 39 } else if (aParams.mConfig.IsVideo()) { 40 decoder = CreateVideoDecoder(CreateDecoderParams{aParams, &result}); 41 } 42 if (!decoder) { 43 if (NS_FAILED(result)) { 44 return CreateDecoderPromise::CreateAndReject(result, __func__); 45 } 46 return CreateDecoderPromise::CreateAndReject( 47 MediaResult(NS_ERROR_DOM_MEDIA_FATAL_ERR, 48 nsPrintfCString("Error creating decoder for %s", 49 aParams.mConfig.mMimeType.get()) 50 .get()), 51 __func__); 52 } 53 return CreateDecoderPromise::CreateAndResolve(decoder, __func__); 54 } 55 56 } // namespace mozilla