tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

GMPDecoderModule.cpp (3151B)


      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 "GMPDecoderModule.h"
      8 
      9 #ifdef MOZ_AV1
     10 #  include "AOMDecoder.h"
     11 #endif
     12 #include "DecoderDoctorDiagnostics.h"
     13 #include "GMPService.h"
     14 #include "GMPUtils.h"
     15 #include "GMPVideoDecoder.h"
     16 #include "MP4Decoder.h"
     17 #include "MediaDataDecoderProxy.h"
     18 #include "VPXDecoder.h"
     19 #include "VideoUtils.h"
     20 #include "gmp-video-decode.h"
     21 #include "mozilla/StaticMutex.h"
     22 #include "nsServiceManagerUtils.h"
     23 #ifdef XP_WIN
     24 #  include "WMFDecoderModule.h"
     25 #endif
     26 
     27 namespace mozilla {
     28 
     29 static already_AddRefed<MediaDataDecoderProxy> CreateDecoderWrapper(
     30    GMPVideoDecoderParams&& aParams) {
     31  RefPtr<gmp::GeckoMediaPluginService> s(
     32      gmp::GeckoMediaPluginService::GetGeckoMediaPluginService());
     33  if (!s) {
     34    return nullptr;
     35  }
     36  nsCOMPtr<nsISerialEventTarget> thread(s->GetGMPThread());
     37  if (!thread) {
     38    return nullptr;
     39  }
     40 
     41  RefPtr<MediaDataDecoderProxy> decoder(new MediaDataDecoderProxy(
     42      do_AddRef(new GMPVideoDecoder(std::move(aParams))), thread.forget()));
     43  return decoder.forget();
     44 }
     45 
     46 already_AddRefed<MediaDataDecoder> GMPDecoderModule::CreateVideoDecoder(
     47    const CreateDecoderParams& aParams) {
     48  if (!MP4Decoder::IsH264(aParams.mConfig.mMimeType) &&
     49 #ifdef MOZ_AV1
     50      !AOMDecoder::IsAV1(aParams.mConfig.mMimeType) &&
     51 #endif
     52      !VPXDecoder::IsVP8(aParams.mConfig.mMimeType) &&
     53      !VPXDecoder::IsVP9(aParams.mConfig.mMimeType)) {
     54    return nullptr;
     55  }
     56 
     57  return CreateDecoderWrapper(GMPVideoDecoderParams(aParams));
     58 }
     59 
     60 already_AddRefed<MediaDataDecoder> GMPDecoderModule::CreateAudioDecoder(
     61    const CreateDecoderParams& aParams) {
     62  return nullptr;
     63 }
     64 
     65 /* static */
     66 media::DecodeSupportSet GMPDecoderModule::SupportsMimeType(
     67    const nsACString& aMimeType, const nsACString& aApi,
     68    const Maybe<nsCString>& aKeySystem) {
     69  AutoTArray<nsCString, 2> tags;
     70  if (MP4Decoder::IsH264(aMimeType)) {
     71    tags.AppendElement("h264"_ns);
     72 #ifdef MOZ_AV1
     73  } else if (AOMDecoder::IsAV1(aMimeType)) {
     74    tags.AppendElement("av1"_ns);
     75 #endif
     76  } else if (VPXDecoder::IsVP9(aMimeType)) {
     77    tags.AppendElement("vp9"_ns);
     78  } else if (VPXDecoder::IsVP8(aMimeType)) {
     79    tags.AppendElement("vp8"_ns);
     80  } else {
     81    return media::DecodeSupportSet{};
     82  }
     83 
     84  // Optional tag for EME GMP plugins.
     85  if (aKeySystem) {
     86    tags.AppendElement(*aKeySystem);
     87  }
     88 
     89  // GMP plugins are always software based.
     90  return HaveGMPFor(aApi, tags) ? media::DecodeSupport::SoftwareDecode
     91                                : media::DecodeSupportSet{};
     92 }
     93 
     94 media::DecodeSupportSet GMPDecoderModule::SupportsMimeType(
     95    const nsACString& aMimeType, DecoderDoctorDiagnostics* aDiagnostics) const {
     96  return SupportsMimeType(aMimeType, "decode-video"_ns, Nothing());
     97 }
     98 
     99 /* static */
    100 already_AddRefed<PlatformDecoderModule> GMPDecoderModule::Create() {
    101  return MakeAndAddRef<GMPDecoderModule>();
    102 }
    103 
    104 }  // namespace mozilla