tor-browser

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

GMPEncoderModule.cpp (2591B)


      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 "GMPEncoderModule.h"
      8 
      9 #include "GMPService.h"
     10 #include "GMPUtils.h"
     11 #include "GMPVideoEncoder.h"
     12 #include "MP4Decoder.h"
     13 #include "MediaDataEncoderProxy.h"
     14 
     15 using mozilla::media::EncodeSupport;
     16 using mozilla::media::EncodeSupportSet;
     17 
     18 namespace mozilla {
     19 
     20 already_AddRefed<MediaDataEncoder> GMPEncoderModule::CreateVideoEncoder(
     21    const EncoderConfig& aConfig, const RefPtr<TaskQueue>& aTaskQueue) const {
     22  if (Supports(aConfig).isEmpty()) {
     23    return nullptr;
     24  }
     25 
     26  RefPtr<gmp::GeckoMediaPluginService> s(
     27      gmp::GeckoMediaPluginService::GetGeckoMediaPluginService());
     28  if (NS_WARN_IF(!s)) {
     29    return nullptr;
     30  }
     31 
     32  nsCOMPtr<nsISerialEventTarget> thread(s->GetGMPThread());
     33  if (NS_WARN_IF(!thread)) {
     34    return nullptr;
     35  }
     36 
     37  RefPtr<MediaDataEncoder> encoder(new GMPVideoEncoder(aConfig));
     38  return do_AddRef(
     39      new MediaDataEncoderProxy(encoder.forget(), thread.forget()));
     40 }
     41 
     42 media::EncodeSupportSet GMPEncoderModule::Supports(
     43    const EncoderConfig& aConfig) const {
     44  if (!CanLikelyEncode(aConfig)) {
     45    return EncodeSupportSet{};
     46  }
     47  if (aConfig.mCodec != CodecType::H264) {
     48    return EncodeSupportSet{};
     49  }
     50  if (aConfig.mHardwarePreference == HardwarePreference::RequireHardware) {
     51    return EncodeSupportSet{};
     52  }
     53  if (aConfig.mCodecSpecific.is<H264Specific>()) {
     54    const auto& codecSpecific = aConfig.mCodecSpecific.as<H264Specific>();
     55    if (codecSpecific.mProfile != H264_PROFILE_UNKNOWN &&
     56        codecSpecific.mProfile != H264_PROFILE_BASE &&
     57        !HaveGMPFor("encode-video"_ns, {"moz-h264-advanced"_ns})) {
     58      return EncodeSupportSet{};
     59    }
     60  }
     61  if (aConfig.mScalabilityMode != ScalabilityMode::None &&
     62      !HaveGMPFor("encode-video"_ns, {"moz-h264-temporal-svc"_ns})) {
     63    return EncodeSupportSet{};
     64  }
     65  if (!HaveGMPFor("encode-video"_ns, {"h264"_ns})) {
     66    return EncodeSupportSet{};
     67  }
     68  return EncodeSupportSet{EncodeSupport::SoftwareEncode};
     69 }
     70 
     71 media::EncodeSupportSet GMPEncoderModule::SupportsCodec(
     72    CodecType aCodecType) const {
     73  if (aCodecType != CodecType::H264) {
     74    return EncodeSupportSet{};
     75  }
     76  if (!HaveGMPFor("encode-video"_ns, {"h264"_ns})) {
     77    return EncodeSupportSet{};
     78  }
     79  return EncodeSupportSet{EncodeSupport::SoftwareEncode};
     80 }
     81 
     82 }  // namespace mozilla