tor-browser

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

video_encoder_interface.h (2468B)


      1 /*
      2 *  Copyright (c) 2023 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_ENCODER_INTERFACE_H_
     12 #define API_VIDEO_CODECS_VIDEO_ENCODER_INTERFACE_H_
     13 
     14 #include <cstdint>
     15 #include <memory>
     16 #include <optional>
     17 #include <variant>
     18 #include <vector>
     19 
     20 #include "api/array_view.h"
     21 #include "api/scoped_refptr.h"
     22 #include "api/units/data_rate.h"
     23 #include "api/units/data_size.h"
     24 #include "api/units/time_delta.h"
     25 #include "api/units/timestamp.h"
     26 #include "api/video/resolution.h"
     27 #include "api/video/video_frame_buffer.h"
     28 #include "api/video_codecs/video_codec.h"
     29 
     30 namespace webrtc {
     31 // NOTE: This class is still under development and may change without notice.
     32 class VideoEncoderInterface {
     33 public:
     34  virtual ~VideoEncoderInterface() = default;
     35  enum class FrameType { kKeyframe, kStartFrame, kDeltaFrame };
     36 
     37  struct EncodingError {};
     38  struct EncodedData {
     39    FrameType frame_type;
     40    int encoded_qp;
     41  };
     42  using EncodeResult = std::variant<EncodingError, EncodedData>;
     43 
     44  struct FrameOutput {
     45    virtual ~FrameOutput() = default;
     46    virtual ArrayView<uint8_t> GetBitstreamOutputBuffer(DataSize size) = 0;
     47    virtual void EncodeComplete(const EncodeResult& encode_result) = 0;
     48  };
     49 
     50  struct TemporalUnitSettings {
     51    VideoCodecMode content_hint = VideoCodecMode::kRealtimeVideo;
     52    Timestamp presentation_timestamp;
     53  };
     54 
     55  struct FrameEncodeSettings {
     56    struct Cbr {
     57      TimeDelta duration;
     58      DataRate target_bitrate;
     59    };
     60 
     61    struct Cqp {
     62      int target_qp;
     63    };
     64 
     65    std::variant<Cqp, Cbr> rate_options;
     66 
     67    FrameType frame_type = FrameType::kDeltaFrame;
     68    int temporal_id = 0;
     69    int spatial_id = 0;
     70    Resolution resolution;
     71    std::vector<int> reference_buffers;
     72    std::optional<int> update_buffer;
     73    int effort_level = 0;
     74 
     75    std::unique_ptr<FrameOutput> frame_output;
     76  };
     77 
     78  virtual void Encode(scoped_refptr<VideoFrameBuffer> frame_buffer,
     79                      const TemporalUnitSettings& settings,
     80                      std::vector<FrameEncodeSettings> frame_settings) = 0;
     81 };
     82 
     83 }  // namespace webrtc
     84 #endif  // API_VIDEO_CODECS_VIDEO_ENCODER_INTERFACE_H_