tor-browser

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

internal_decoder_factory.cc (3568B)


      1 /*
      2 *  Copyright (c) 2016 The WebRTC project authors. All Rights Reserved.
      3 *
      4 *  Use of this source code is governed by a BSD-style license
      5 *  that can be found in the LICENSE file in the root of the source
      6 *  tree. An additional intellectual property rights grant can be found
      7 *  in the file PATENTS.  All contributing project authors may
      8 *  be found in the AUTHORS file in the root of the source tree.
      9 */
     10 
     11 #include "media/engine/internal_decoder_factory.h"
     12 
     13 #include <memory>
     14 #include <vector>
     15 
     16 #include "absl/strings/match.h"
     17 #include "api/environment/environment.h"
     18 #include "api/video/video_codec_type.h"
     19 #include "api/video_codecs/sdp_video_format.h"
     20 #include "api/video_codecs/video_codec.h"
     21 #include "api/video_codecs/video_decoder.h"
     22 #include "api/video_codecs/video_decoder_factory.h"
     23 #include "media/base/media_constants.h"
     24 #include "modules/video_coding/codecs/h264/include/h264.h"
     25 #include "modules/video_coding/codecs/vp8/include/vp8.h"
     26 #include "modules/video_coding/codecs/vp9/include/vp9.h"
     27 #include "rtc_base/checks.h"
     28 #include "rtc_base/logging.h"
     29 
     30 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
     31 #include "modules/video_coding/codecs/av1/dav1d_decoder.h"  // nogncheck
     32 #endif
     33 
     34 namespace webrtc {
     35 namespace {
     36 #if defined(RTC_DAV1D_IN_INTERNAL_DECODER_FACTORY)
     37 constexpr bool kDav1dIsIncluded = true;
     38 #else
     39 constexpr bool kDav1dIsIncluded = false;
     40 std::unique_ptr<VideoDecoder> CreateDav1dDecoder(const Environment& env) {
     41  return nullptr;
     42 }
     43 #endif
     44 
     45 }  // namespace
     46 
     47 std::vector<SdpVideoFormat> InternalDecoderFactory::GetSupportedFormats()
     48    const {
     49  std::vector<SdpVideoFormat> formats;
     50  formats.push_back(SdpVideoFormat::VP8());
     51  for (const SdpVideoFormat& format : SupportedVP9DecoderCodecs())
     52    formats.push_back(format);
     53  for (const SdpVideoFormat& h264_format : SupportedH264DecoderCodecs())
     54    formats.push_back(h264_format);
     55 
     56 #if !defined(WEBRTC_MOZILLA_BUILD)
     57  if (kDav1dIsIncluded) {
     58    formats.push_back(SdpVideoFormat::AV1Profile0());
     59    formats.push_back(SdpVideoFormat::AV1Profile1());
     60  }
     61 #endif
     62 
     63  return formats;
     64 }
     65 
     66 VideoDecoderFactory::CodecSupport InternalDecoderFactory::QueryCodecSupport(
     67    const SdpVideoFormat& format,
     68    bool reference_scaling) const {
     69  // Query for supported formats and check if the specified format is supported.
     70  // Return unsupported if an invalid combination of format and
     71  // reference_scaling is specified.
     72  if (reference_scaling) {
     73    VideoCodecType codec = PayloadStringToCodecType(format.name);
     74    if (codec != kVideoCodecVP9 && codec != kVideoCodecAV1) {
     75      return {.is_supported = false, .is_power_efficient = false};
     76    }
     77  }
     78 
     79  CodecSupport codec_support;
     80  codec_support.is_supported = format.IsCodecInList(GetSupportedFormats());
     81  return codec_support;
     82 }
     83 
     84 std::unique_ptr<VideoDecoder> InternalDecoderFactory::Create(
     85    const Environment& env,
     86    const SdpVideoFormat& format) {
     87  if (!format.IsCodecInList(GetSupportedFormats())) {
     88    RTC_LOG(LS_WARNING) << "Trying to create decoder for unsupported format. "
     89                        << format.ToString();
     90    return nullptr;
     91  }
     92 
     93  if (absl::EqualsIgnoreCase(format.name, kVp8CodecName))
     94    return CreateVp8Decoder(env);
     95  if (absl::EqualsIgnoreCase(format.name, kVp9CodecName))
     96    return VP9Decoder::Create();
     97  if (absl::EqualsIgnoreCase(format.name, kH264CodecName))
     98    return H264Decoder::Create();
     99 
    100  if (absl::EqualsIgnoreCase(format.name, kAv1CodecName) && kDav1dIsIncluded) {
    101    return CreateDav1dDecoder(env);
    102  }
    103 
    104  RTC_DCHECK_NOTREACHED();
    105  return nullptr;
    106 }
    107 
    108 }  // namespace webrtc