tor-browser

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

video_decoder.h (5090B)


      1 /*
      2 *  Copyright (c) 2014 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 #ifndef API_VIDEO_CODECS_VIDEO_DECODER_H_
     12 #define API_VIDEO_CODECS_VIDEO_DECODER_H_
     13 
     14 #include <cstdint>
     15 #include <optional>
     16 #include <string>
     17 
     18 #include "api/video/encoded_image.h"
     19 #include "api/video/render_resolution.h"
     20 #include "api/video/video_codec_type.h"
     21 #include "api/video/video_frame.h"
     22 #include "rtc_base/system/rtc_export.h"
     23 
     24 namespace webrtc {
     25 
     26 class RTC_EXPORT DecodedImageCallback {
     27 public:
     28  virtual ~DecodedImageCallback() {}
     29 
     30  virtual int32_t Decoded(VideoFrame& decodedImage) = 0;
     31  // Provides an alternative interface that allows the decoder to specify the
     32  // decode time excluding waiting time for any previous pending frame to
     33  // return. This is necessary for breaking positive feedback in the delay
     34  // estimation when the decoder has a single output buffer.
     35  virtual int32_t Decoded(VideoFrame& decodedImage, int64_t decode_time_ms);
     36 
     37  // TODO(sakal): Remove other implementations when upstream projects have been
     38  // updated.
     39  virtual void Decoded(VideoFrame& decodedImage,
     40                       std::optional<int32_t> decode_time_ms,
     41                       std::optional<uint8_t> qp);
     42 };
     43 
     44 class RTC_EXPORT VideoDecoder {
     45 public:
     46  struct DecoderInfo {
     47    // Descriptive name of the decoder implementation.
     48    std::string implementation_name;
     49 
     50    // True if the decoder is backed by hardware acceleration.
     51    bool is_hardware_accelerated = false;
     52 
     53    std::string ToString() const;
     54    bool operator==(const DecoderInfo& rhs) const;
     55    bool operator!=(const DecoderInfo& rhs) const { return !(*this == rhs); }
     56  };
     57 
     58  class Settings {
     59   public:
     60    Settings() = default;
     61    Settings(const Settings&) = default;
     62    Settings& operator=(const Settings&) = default;
     63    ~Settings() = default;
     64 
     65    // The size of pool which is used to store video frame buffers inside
     66    // decoder. If value isn't present some codec-default value will be used. If
     67    // value is present and decoder doesn't have buffer pool the value will be
     68    // ignored.
     69    std::optional<int> buffer_pool_size() const;
     70    void set_buffer_pool_size(std::optional<int> value);
     71 
     72    // When valid, user of the VideoDecoder interface shouldn't `Decode`
     73    // encoded images with render resolution larger than width and height
     74    // specified here.
     75    RenderResolution max_render_resolution() const;
     76    void set_max_render_resolution(RenderResolution value);
     77 
     78    // Maximum number of cpu cores the decoder is allowed to use in parallel.
     79    // Must be positive.
     80    int number_of_cores() const { return number_of_cores_; }
     81    void set_number_of_cores(int value);
     82 
     83    // Codec of encoded images user of the VideoDecoder interface will `Decode`.
     84    VideoCodecType codec_type() const { return codec_type_; }
     85    void set_codec_type(VideoCodecType value) { codec_type_ = value; }
     86 
     87   private:
     88    std::optional<int> buffer_pool_size_;
     89    RenderResolution max_resolution_;
     90    int number_of_cores_ = 1;
     91    VideoCodecType codec_type_ = kVideoCodecGeneric;
     92  };
     93 
     94  virtual ~VideoDecoder() = default;
     95 
     96  // Prepares decoder to handle incoming encoded frames. Can be called multiple
     97  // times, in such case only latest `settings` are in effect.
     98  virtual bool Configure(const Settings& settings) = 0;
     99 
    100  // TODO(bugs.webrtc.org/15444): Make pure virtual once all subclasses have
    101  // migrated to implementing this class.
    102  virtual int32_t Decode(const EncodedImage& input_image,
    103                         int64_t render_time_ms) {
    104    return Decode(input_image, /*missing_frame=*/false, render_time_ms);
    105  }
    106 
    107  // TODO(bugs.webrtc.org/15444): Migrate all subclasses to Decode() without
    108  // missing_frame and delete this.
    109  virtual int32_t Decode(const EncodedImage& input_image,
    110                         bool /* missing_frames */,
    111                         int64_t render_time_ms) {
    112    return Decode(input_image, render_time_ms);
    113  }
    114 
    115  virtual int32_t RegisterDecodeCompleteCallback(
    116      DecodedImageCallback* callback) = 0;
    117 
    118  virtual int32_t Release() = 0;
    119 
    120  virtual DecoderInfo GetDecoderInfo() const;
    121 
    122  // Deprecated, use GetDecoderInfo().implementation_name instead.
    123  virtual const char* ImplementationName() const;
    124 };
    125 
    126 inline std::optional<int> VideoDecoder::Settings::buffer_pool_size() const {
    127  return buffer_pool_size_;
    128 }
    129 
    130 inline void VideoDecoder::Settings::set_buffer_pool_size(
    131    std::optional<int> value) {
    132  buffer_pool_size_ = value;
    133 }
    134 
    135 inline RenderResolution VideoDecoder::Settings::max_render_resolution() const {
    136  return max_resolution_;
    137 }
    138 
    139 inline void VideoDecoder::Settings::set_max_render_resolution(
    140    RenderResolution value) {
    141  max_resolution_ = value;
    142 }
    143 
    144 }  // namespace webrtc
    145 
    146 #endif  // API_VIDEO_CODECS_VIDEO_DECODER_H_