tor-browser

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

AndroidEncoderModule.cpp (2240B)


      1 /* This Source Code Form is subject to the terms of the Mozilla Public
      2 * License, v. 2.0. If a copy of the MPL was not distributed with this
      3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      4 
      5 #include "AndroidEncoderModule.h"
      6 
      7 #include "AndroidDataEncoder.h"
      8 #include "mozilla/Logging.h"
      9 #include "mozilla/java/HardwareCodecCapabilityUtilsWrappers.h"
     10 
     11 using mozilla::media::EncodeSupport;
     12 using mozilla::media::EncodeSupportSet;
     13 
     14 namespace mozilla {
     15 extern LazyLogModule sPEMLog;
     16 #define AND_PEM_LOG(arg, ...)            \
     17  MOZ_LOG(                               \
     18      sPEMLog, mozilla::LogLevel::Debug, \
     19      ("AndroidEncoderModule(%p)::%s: " arg, this, __func__, ##__VA_ARGS__))
     20 
     21 EncodeSupportSet AndroidEncoderModule::SupportsCodec(CodecType aCodec) const {
     22  EncodeSupportSet supports{};
     23  switch (aCodec) {
     24    case CodecType::H264:
     25      supports += EncodeSupport::SoftwareEncode;
     26      if (java::HardwareCodecCapabilityUtils::HasHWH264(true /* encoder */)) {
     27        supports += EncodeSupport::HardwareEncode;
     28      }
     29      break;
     30    case CodecType::VP8:
     31      if (java::HardwareCodecCapabilityUtils::HasHWVP8(true /* encoder */)) {
     32        supports += EncodeSupport::HardwareEncode;
     33      }
     34      break;
     35    case CodecType::VP9:
     36      if (java::HardwareCodecCapabilityUtils::HasHWVP9(true /* encoder */)) {
     37        supports += EncodeSupport::HardwareEncode;
     38      }
     39      break;
     40    default:
     41      break;
     42  }
     43  return supports;
     44 }
     45 
     46 EncodeSupportSet AndroidEncoderModule::Supports(
     47    const EncoderConfig& aConfig) const {
     48  if (!CanLikelyEncode(aConfig)) {
     49    return EncodeSupportSet{};
     50  }
     51  if (aConfig.mScalabilityMode != ScalabilityMode::None) {
     52    return EncodeSupportSet{};
     53  }
     54  // Only hardware encoder are supported for now.
     55  return SupportsCodec(aConfig.mCodec);
     56 }
     57 
     58 already_AddRefed<MediaDataEncoder> AndroidEncoderModule::CreateVideoEncoder(
     59    const EncoderConfig& aConfig, const RefPtr<TaskQueue>& aTaskQueue) const {
     60  if (Supports(aConfig).isEmpty()) {
     61    AND_PEM_LOG("Unsupported codec type: %s",
     62                EnumValueToString(aConfig.mCodec));
     63    return nullptr;
     64  }
     65  return MakeRefPtr<AndroidDataEncoder>(aConfig, aTaskQueue).forget();
     66 }
     67 
     68 }  // namespace mozilla
     69 
     70 #undef AND_PEM_LOG