diff --git a/dom/media/platforms/PDMFactory.cpp b/dom/media/platforms/PDMFactory.cpp index f14b8a0bd5d..54006762716 100644 --- a/dom/media/platforms/PDMFactory.cpp +++ b/dom/media/platforms/PDMFactory.cpp @@ -32,9 +32,7 @@ #include "FuzzingWrapper.h" #include "H264Converter.h" -#include "OpusDecoder.h" -#include "VorbisDecoder.h" -#include "VPXDecoder.h" +#include "AgnosticDecoderModule.h" namespace mozilla { @@ -112,22 +110,15 @@ PDMFactory::CreateDecoder(const TrackInfo& aConfig, layers::ImageContainer* aImageContainer) { nsRefPtr current = GetDecoder(aConfig.mMimeType); + if (!current) { + return nullptr; + } nsRefPtr m; if (aConfig.GetAsAudioInfo()) { - if (!current && VorbisDataDecoder::IsVorbis(aConfig.mMimeType)) { - m = new VorbisDataDecoder(*aConfig.GetAsAudioInfo(), - aTaskQueue, - aCallback); - } else if (!current && OpusDataDecoder::IsOpus(aConfig.mMimeType)) { - m = new OpusDataDecoder(*aConfig.GetAsAudioInfo(), - aTaskQueue, - aCallback); - } else if (current) { - m = current->CreateAudioDecoder(*aConfig.GetAsAudioInfo(), + m = current->CreateAudioDecoder(*aConfig.GetAsAudioInfo(), aTaskQueue, aCallback); - } return m.forget(); } @@ -145,34 +136,27 @@ PDMFactory::CreateDecoder(const TrackInfo& aConfig, callback = callbackWrapper.get(); } - if (!current && VPXDecoder::IsVPX(aConfig.mMimeType)) { - m = new VPXDecoder(*aConfig.GetAsVideoInfo(), - aImageContainer, - aTaskQueue, - callback); - } else if (current) { - if (H264Converter::IsH264(aConfig)) { - nsRefPtr h - = new H264Converter(current, - *aConfig.GetAsVideoInfo(), - aLayersBackend, - aImageContainer, - aTaskQueue, - callback); - const nsresult rv = h->GetLastError(); - if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) { - // The H264Converter either successfully created the wrapped decoder, - // or there wasn't enough AVCC data to do so. Otherwise, there was some - // problem, for example WMF DLLs were missing. - m = h.forget(); - } - } else { - m = current->CreateVideoDecoder(*aConfig.GetAsVideoInfo(), - aLayersBackend, - aImageContainer, - aTaskQueue, - callback); + if (H264Converter::IsH264(aConfig)) { + nsRefPtr h + = new H264Converter(current, + *aConfig.GetAsVideoInfo(), + aLayersBackend, + aImageContainer, + aTaskQueue, + callback); + const nsresult rv = h->GetLastError(); + if (NS_SUCCEEDED(rv) || rv == NS_ERROR_NOT_INITIALIZED) { + // The H264Converter either successfully created the wrapped decoder, + // or there wasn't enough AVCC data to do so. Otherwise, there was some + // problem, for example WMF DLLs were missing. + m = h.forget(); } + } else { + m = current->CreateVideoDecoder(*aConfig.GetAsVideoInfo(), + aLayersBackend, + aImageContainer, + aTaskQueue, + callback); } if (callbackWrapper && m) { @@ -186,10 +170,7 @@ bool PDMFactory::SupportsMimeType(const nsACString& aMimeType) { nsRefPtr current = GetDecoder(aMimeType); - return current || - VPXDecoder::IsVPX(aMimeType) || - OpusDataDecoder::IsOpus(aMimeType) || - VorbisDataDecoder::IsVorbis(aMimeType); + return !!current; } void @@ -231,6 +212,10 @@ PDMFactory::CreatePDMs() StartupPDM(m); } #endif + + m = new AgnosticDecoderModule(); + StartupPDM(m); + if (sUseBlankDecoder) { m = CreateBlankDecoderModule(); StartupPDM(m); diff --git a/dom/media/platforms/agnostic/AgnosticDecoderModule.cpp b/dom/media/platforms/agnostic/AgnosticDecoderModule.cpp new file mode 100644 index 00000000000..c877e80f392 --- /dev/null +++ b/dom/media/platforms/agnostic/AgnosticDecoderModule.cpp @@ -0,0 +1,61 @@ +/* -*- 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 "AgnosticDecoderModule.h" +#include "OpusDecoder.h" +#include "VorbisDecoder.h" +#include "VPXDecoder.h" + +namespace mozilla { + +bool +AgnosticDecoderModule::SupportsMimeType(const nsACString& aMimeType) +{ + return VPXDecoder::IsVPX(aMimeType) || + OpusDataDecoder::IsOpus(aMimeType) || + VorbisDataDecoder::IsVorbis(aMimeType); +} + +already_AddRefed +AgnosticDecoderModule::CreateVideoDecoder(const VideoInfo& aConfig, + layers::LayersBackend aLayersBackend, + layers::ImageContainer* aImageContainer, + FlushableTaskQueue* aVideoTaskQueue, + MediaDataDecoderCallback* aCallback) +{ + nsRefPtr m; + + if (VPXDecoder::IsVPX(aConfig.mMimeType)) { + m = new VPXDecoder(*aConfig.GetAsVideoInfo(), + aImageContainer, + aVideoTaskQueue, + aCallback); + } + + return m.forget(); +} + +already_AddRefed +AgnosticDecoderModule::CreateAudioDecoder(const AudioInfo& aConfig, + FlushableTaskQueue* aAudioTaskQueue, + MediaDataDecoderCallback* aCallback) +{ + nsRefPtr m; + + if (VorbisDataDecoder::IsVorbis(aConfig.mMimeType)) { + m = new VorbisDataDecoder(*aConfig.GetAsAudioInfo(), + aAudioTaskQueue, + aCallback); + } else if (OpusDataDecoder::IsOpus(aConfig.mMimeType)) { + m = new OpusDataDecoder(*aConfig.GetAsAudioInfo(), + aAudioTaskQueue, + aCallback); + } + + return m.forget(); +} + +} // namespace mozilla diff --git a/dom/media/platforms/agnostic/AgnosticDecoderModule.h b/dom/media/platforms/agnostic/AgnosticDecoderModule.h new file mode 100644 index 00000000000..97cc23e799b --- /dev/null +++ b/dom/media/platforms/agnostic/AgnosticDecoderModule.h @@ -0,0 +1,39 @@ +#if !defined(AgnosticDecoderModule_h_) +#define AgnosticDecoderModule_h_ + +#include "PlatformDecoderModule.h" + +namespace mozilla { + +class AgnosticDecoderModule : public PlatformDecoderModule { +public: + AgnosticDecoderModule() = default; + virtual ~AgnosticDecoderModule() = default; + + bool SupportsMimeType(const nsACString& aMimeType) override; + + ConversionRequired + DecoderNeedsConversion(const TrackInfo& aConfig) const override + { + return ConversionRequired::kNeedNone; + } + +protected: + // Decode thread. + already_AddRefed + CreateVideoDecoder(const VideoInfo& aConfig, + layers::LayersBackend aLayersBackend, + layers::ImageContainer* aImageContainer, + FlushableTaskQueue* aVideoTaskQueue, + MediaDataDecoderCallback* aCallback) override; + + // Decode thread. + already_AddRefed + CreateAudioDecoder(const AudioInfo& aConfig, + FlushableTaskQueue* aAudioTaskQueue, + MediaDataDecoderCallback* aCallback) override; +}; + +} // namespace mozilla + +#endif /* AgnosticDecoderModule_h_ */ diff --git a/dom/media/platforms/agnostic/BlankDecoderModule.cpp b/dom/media/platforms/agnostic/BlankDecoderModule.cpp index f176055f59d..5b6e788f296 100644 --- a/dom/media/platforms/agnostic/BlankDecoderModule.cpp +++ b/dom/media/platforms/agnostic/BlankDecoderModule.cpp @@ -259,27 +259,10 @@ public: }; -class AgnosticDecoderModule : public BlankDecoderModule { -public: - - bool SupportsMimeType(const nsACString& aMimeType) override - { - // This module does not support any decoders itself, - // agnostic decoders are created in PlatformDecoderModule::CreateDecoder - return false; - } -}; - already_AddRefed CreateBlankDecoderModule() { nsRefPtr pdm = new BlankDecoderModule(); return pdm.forget(); } -already_AddRefed CreateAgnosticDecoderModule() -{ - nsRefPtr adm = new AgnosticDecoderModule(); - return adm.forget(); -} - } // namespace mozilla diff --git a/dom/media/platforms/moz.build b/dom/media/platforms/moz.build index ae84d1f0144..8a217ce267c 100644 --- a/dom/media/platforms/moz.build +++ b/dom/media/platforms/moz.build @@ -5,6 +5,7 @@ # file, You can obtain one at http://mozilla.org/MPL/2.0/. EXPORTS += [ + 'agnostic/AgnosticDecoderModule.h', 'agnostic/OpusDecoder.h', 'agnostic/VorbisDecoder.h', 'agnostic/VPXDecoder.h', @@ -14,6 +15,7 @@ EXPORTS += [ ] UNIFIED_SOURCES += [ + 'agnostic/AgnosticDecoderModule.cpp', 'agnostic/BlankDecoderModule.cpp', 'agnostic/OpusDecoder.cpp', 'agnostic/VorbisDecoder.cpp',