Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2013 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_CONFIG_H_ |
| 12 | #define API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ |
| 13 | |
Yves Gerey | 988cc08 | 2018-10-23 12:03:01 +0200 | [diff] [blame] | 14 | #include <stddef.h> |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 15 | #include <string> |
| 16 | #include <vector> |
| 17 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 18 | #include "absl/types/optional.h" |
Mirko Bonadei | d970807 | 2019-01-25 20:26:48 +0100 | [diff] [blame] | 19 | #include "api/scoped_refptr.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 20 | #include "api/video_codecs/sdp_video_format.h" |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 21 | #include "api/video_codecs/video_codec.h" |
Steve Anton | 10542f2 | 2019-01-11 09:11:00 -0800 | [diff] [blame] | 22 | #include "rtc_base/ref_count.h" |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | |
| 26 | struct VideoStream { |
| 27 | VideoStream(); |
| 28 | ~VideoStream(); |
| 29 | VideoStream(const VideoStream& other); |
| 30 | std::string ToString() const; |
| 31 | |
Danil Chapovalov | 350531e | 2018-06-08 11:04:04 +0000 | [diff] [blame] | 32 | size_t width; |
| 33 | size_t height; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 34 | int max_framerate; |
| 35 | |
| 36 | int min_bitrate_bps; |
| 37 | int target_bitrate_bps; |
| 38 | int max_bitrate_bps; |
Florent Castelli | c1a0bcb | 2019-01-29 14:26:48 +0100 | [diff] [blame] | 39 | // Scaling factor applied to the stream size. |
| 40 | // |width| and |height| values are already scaled down. |
| 41 | double scale_resolution_down_by; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 42 | int max_qp; |
| 43 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 44 | absl::optional<size_t> num_temporal_layers; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 45 | |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 46 | absl::optional<double> bitrate_priority; |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 47 | |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 48 | bool active; |
| 49 | }; |
| 50 | |
| 51 | class VideoEncoderConfig { |
| 52 | public: |
| 53 | // These are reference counted to permit copying VideoEncoderConfig and be |
| 54 | // kept alive until all encoder_specific_settings go out of scope. |
| 55 | // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig |
Danil Chapovalov | 0bc58cf | 2018-06-21 13:32:56 +0200 | [diff] [blame] | 56 | // and use absl::optional for encoder_specific_settings instead. |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 57 | class EncoderSpecificSettings : public rtc::RefCountInterface { |
| 58 | public: |
| 59 | // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is |
| 60 | // not in use and encoder implementations ask for codec-specific structs |
| 61 | // directly. |
| 62 | void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; |
| 63 | |
| 64 | virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; |
| 65 | virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; |
| 66 | virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; |
| 67 | |
| 68 | private: |
| 69 | ~EncoderSpecificSettings() override {} |
| 70 | friend class VideoEncoderConfig; |
| 71 | }; |
| 72 | |
| 73 | class H264EncoderSpecificSettings : public EncoderSpecificSettings { |
| 74 | public: |
| 75 | explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); |
| 76 | void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; |
| 77 | |
| 78 | private: |
| 79 | VideoCodecH264 specifics_; |
| 80 | }; |
| 81 | |
| 82 | class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { |
| 83 | public: |
| 84 | explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); |
| 85 | void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; |
| 86 | |
| 87 | private: |
| 88 | VideoCodecVP8 specifics_; |
| 89 | }; |
| 90 | |
| 91 | class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { |
| 92 | public: |
| 93 | explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); |
| 94 | void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; |
| 95 | |
| 96 | private: |
| 97 | VideoCodecVP9 specifics_; |
| 98 | }; |
| 99 | |
| 100 | enum class ContentType { |
| 101 | kRealtimeVideo, |
| 102 | kScreen, |
| 103 | }; |
| 104 | |
| 105 | class VideoStreamFactoryInterface : public rtc::RefCountInterface { |
| 106 | public: |
| 107 | // An implementation should return a std::vector<VideoStream> with the |
| 108 | // wanted VideoStream settings for the given video resolution. |
| 109 | // The size of the vector may not be larger than |
| 110 | // |encoder_config.number_of_streams|. |
| 111 | virtual std::vector<VideoStream> CreateEncoderStreams( |
| 112 | int width, |
| 113 | int height, |
| 114 | const VideoEncoderConfig& encoder_config) = 0; |
| 115 | |
| 116 | protected: |
| 117 | ~VideoStreamFactoryInterface() override {} |
| 118 | }; |
| 119 | |
| 120 | VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; |
| 121 | VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; |
| 122 | |
| 123 | // Mostly used by tests. Avoid creating copies if you can. |
| 124 | VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } |
| 125 | |
| 126 | VideoEncoderConfig(); |
| 127 | VideoEncoderConfig(VideoEncoderConfig&&); |
| 128 | ~VideoEncoderConfig(); |
| 129 | std::string ToString() const; |
| 130 | |
| 131 | // TODO(nisse): Consolidate on one of these. |
| 132 | VideoCodecType codec_type; |
| 133 | SdpVideoFormat video_format; |
| 134 | |
| 135 | rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory; |
| 136 | std::vector<SpatialLayer> spatial_layers; |
| 137 | ContentType content_type; |
| 138 | rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings; |
| 139 | |
| 140 | // Padding will be used up to this bitrate regardless of the bitrate produced |
| 141 | // by the encoder. Padding above what's actually produced by the encoder helps |
| 142 | // maintaining a higher bitrate estimate. Padding will however not be sent |
| 143 | // unless the estimated bandwidth indicates that the link can handle it. |
| 144 | int min_transmit_bitrate_bps; |
| 145 | int max_bitrate_bps; |
| 146 | // The bitrate priority used for all VideoStreams. |
| 147 | double bitrate_priority; |
| 148 | |
| 149 | // The simulcast layer's configurations set by the application for this video |
| 150 | // sender. These are modified by the video_stream_factory before being passed |
| 151 | // down to lower layers for the video encoding. |
Åsa Persson | bdee46d | 2018-06-25 11:28:06 +0200 | [diff] [blame] | 152 | // |simulcast_layers| is also used for configuring non-simulcast (when there |
| 153 | // is a single VideoStream). |
Niels Möller | 0a8f435 | 2018-05-18 11:37:23 +0200 | [diff] [blame] | 154 | std::vector<VideoStream> simulcast_layers; |
| 155 | |
| 156 | // Max number of encoded VideoStreams to produce. |
| 157 | size_t number_of_streams; |
| 158 | |
| 159 | private: |
| 160 | // Access to the copy constructor is private to force use of the Copy() |
| 161 | // method for those exceptional cases where we do use it. |
| 162 | VideoEncoderConfig(const VideoEncoderConfig&); |
| 163 | }; |
| 164 | |
| 165 | } // namespace webrtc |
| 166 | |
| 167 | #endif // API_VIDEO_CODECS_VIDEO_ENCODER_CONFIG_H_ |