mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [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 | |
pbos@webrtc.org | 16e03b7 | 2013-10-28 16:32:01 +0000 | [diff] [blame] | 11 | // TODO(pbos): Move Config from common.h to here. |
| 12 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 13 | #ifndef WEBRTC_CONFIG_H_ |
| 14 | #define WEBRTC_CONFIG_H_ |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 15 | |
| 16 | #include <string> |
pbos@webrtc.org | 5860de0 | 2013-09-16 13:01:47 +0000 | [diff] [blame] | 17 | #include <vector> |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 18 | |
brandtr | 76648da | 2016-10-20 04:54:48 -0700 | [diff] [blame] | 19 | #include "webrtc/base/basictypes.h" |
johan | 3859c89 | 2016-08-05 09:19:25 -0700 | [diff] [blame] | 20 | #include "webrtc/base/optional.h" |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 21 | #include "webrtc/base/refcount.h" |
| 22 | #include "webrtc/base/scoped_ref_ptr.h" |
sprang@webrtc.org | ccd4284 | 2014-01-07 09:54:34 +0000 | [diff] [blame] | 23 | #include "webrtc/common_types.h" |
pbos@webrtc.org | ce90eff | 2013-11-20 11:48:56 +0000 | [diff] [blame] | 24 | #include "webrtc/typedefs.h" |
| 25 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 26 | namespace webrtc { |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 27 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 28 | // Settings for NACK, see RFC 4585 for details. |
| 29 | struct NackConfig { |
pbos@webrtc.org | eceb532 | 2013-05-28 08:04:45 +0000 | [diff] [blame] | 30 | NackConfig() : rtp_history_ms(0) {} |
solenberg | 971cab0 | 2016-06-14 10:02:41 -0700 | [diff] [blame] | 31 | std::string ToString() const; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 32 | // Send side: the time RTP packets are stored for retransmissions. |
| 33 | // Receive side: the time the receiver is prepared to wait for |
| 34 | // retransmissions. |
pbos@webrtc.org | eceb532 | 2013-05-28 08:04:45 +0000 | [diff] [blame] | 35 | // Set to '0' to disable. |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 36 | int rtp_history_ms; |
| 37 | }; |
| 38 | |
brandtr | b5f2c3f | 2016-10-04 23:28:39 -0700 | [diff] [blame] | 39 | // Settings for ULPFEC forward error correction. |
| 40 | // Set the payload types to '-1' to disable. |
| 41 | struct UlpfecConfig { |
| 42 | UlpfecConfig() |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 43 | : ulpfec_payload_type(-1), |
| 44 | red_payload_type(-1), |
| 45 | red_rtx_payload_type(-1) {} |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 46 | std::string ToString() const; |
brandtr | 468da7c | 2016-11-22 02:16:47 -0800 | [diff] [blame] | 47 | bool operator==(const UlpfecConfig& other) const; |
| 48 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 49 | // Payload type used for ULPFEC packets. |
| 50 | int ulpfec_payload_type; |
| 51 | |
| 52 | // Payload type used for RED packets. |
| 53 | int red_payload_type; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 54 | |
| 55 | // RTX payload type for RED payload. |
| 56 | int red_rtx_payload_type; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 57 | }; |
| 58 | |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 59 | // RTP header extension, see RFC 5285. |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 60 | struct RtpExtension { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 61 | RtpExtension() : id(0) {} |
| 62 | RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {} |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 63 | std::string ToString() const; |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 64 | bool operator==(const RtpExtension& rhs) const { |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 65 | return uri == rhs.uri && id == rhs.id; |
solenberg | 3a94154 | 2015-11-16 07:34:50 -0800 | [diff] [blame] | 66 | } |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 67 | static bool IsSupportedForAudio(const std::string& uri); |
| 68 | static bool IsSupportedForVideo(const std::string& uri); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 69 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 70 | // Header extension for audio levels, as defined in: |
| 71 | // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03 |
| 72 | static const char* kAudioLevelUri; |
| 73 | static const int kAudioLevelDefaultId; |
| 74 | |
| 75 | // Header extension for RTP timestamp offset, see RFC 5450 for details: |
| 76 | // http://tools.ietf.org/html/rfc5450 |
| 77 | static const char* kTimestampOffsetUri; |
| 78 | static const int kTimestampOffsetDefaultId; |
| 79 | |
| 80 | // Header extension for absolute send time, see url for details: |
| 81 | // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time |
| 82 | static const char* kAbsSendTimeUri; |
| 83 | static const int kAbsSendTimeDefaultId; |
| 84 | |
| 85 | // Header extension for coordination of video orientation, see url for |
| 86 | // details: |
| 87 | // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf |
| 88 | static const char* kVideoRotationUri; |
| 89 | static const int kVideoRotationDefaultId; |
| 90 | |
ilnik | 00d802b | 2017-04-11 10:34:31 -0700 | [diff] [blame] | 91 | // Header extension for video content type. E.g. default or screenshare. |
| 92 | static const char* kVideoContentTypeUri; |
| 93 | static const int kVideoContentTypeDefaultId; |
| 94 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 95 | // Header extension for transport sequence number, see url for details: |
| 96 | // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions |
| 97 | static const char* kTransportSequenceNumberUri; |
| 98 | static const int kTransportSequenceNumberDefaultId; |
| 99 | |
isheriff | 6b4b5f3 | 2016-06-08 00:24:21 -0700 | [diff] [blame] | 100 | static const char* kPlayoutDelayUri; |
| 101 | static const int kPlayoutDelayDefaultId; |
| 102 | |
deadbeef | e814a0d | 2017-02-25 18:15:09 -0800 | [diff] [blame] | 103 | // Inclusive min and max IDs for one-byte header extensions, per RFC5285. |
| 104 | static const int kMinId; |
| 105 | static const int kMaxId; |
| 106 | |
isheriff | 6f8d686 | 2016-05-26 11:24:55 -0700 | [diff] [blame] | 107 | std::string uri; |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 108 | int id; |
| 109 | }; |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 110 | |
| 111 | struct VideoStream { |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 112 | VideoStream(); |
| 113 | ~VideoStream(); |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 114 | std::string ToString() const; |
| 115 | |
| 116 | size_t width; |
| 117 | size_t height; |
| 118 | int max_framerate; |
| 119 | |
| 120 | int min_bitrate_bps; |
| 121 | int target_bitrate_bps; |
| 122 | int max_bitrate_bps; |
| 123 | |
| 124 | int max_qp; |
| 125 | |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 126 | // Bitrate thresholds for enabling additional temporal layers. Since these are |
| 127 | // thresholds in between layers, we have one additional layer. One threshold |
| 128 | // gives two temporal layers, one below the threshold and one above, two give |
| 129 | // three, and so on. |
| 130 | // The VideoEncoder may redistribute bitrates over the temporal layers so a |
| 131 | // bitrate threshold of 100k and an estimate of 105k does not imply that we |
| 132 | // get 100k in one temporal layer and 5k in the other, just that the bitrate |
| 133 | // in the first temporal layer should not exceed 100k. |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 134 | // TODO(kthelgason): Apart from a special case for two-layer screencast these |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 135 | // thresholds are not propagated to the VideoEncoder. To be implemented. |
| 136 | std::vector<int> temporal_layer_thresholds_bps; |
pbos@webrtc.org | 1e92b0a | 2014-05-15 09:35:06 +0000 | [diff] [blame] | 137 | }; |
| 138 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 139 | class VideoEncoderConfig { |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 140 | public: |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 141 | // These are reference counted to permit copying VideoEncoderConfig and be |
| 142 | // kept alive until all encoder_specific_settings go out of scope. |
| 143 | // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig |
| 144 | // and use rtc::Optional for encoder_specific_settings instead. |
| 145 | class EncoderSpecificSettings : public rtc::RefCountInterface { |
| 146 | public: |
| 147 | // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is |
| 148 | // not in use and encoder implementations ask for codec-specific structs |
| 149 | // directly. |
| 150 | void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; |
| 151 | |
| 152 | virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; |
| 153 | virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; |
| 154 | virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; |
| 155 | private: |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 156 | ~EncoderSpecificSettings() override {} |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 157 | friend class VideoEncoderConfig; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 158 | }; |
| 159 | |
| 160 | class H264EncoderSpecificSettings : public EncoderSpecificSettings { |
| 161 | public: |
| 162 | explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 163 | void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 164 | |
| 165 | private: |
| 166 | VideoCodecH264 specifics_; |
| 167 | }; |
| 168 | |
| 169 | class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { |
| 170 | public: |
| 171 | explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 172 | void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 173 | |
| 174 | private: |
| 175 | VideoCodecVP8 specifics_; |
| 176 | }; |
| 177 | |
| 178 | class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { |
| 179 | public: |
| 180 | explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 181 | void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 182 | |
| 183 | private: |
| 184 | VideoCodecVP9 specifics_; |
| 185 | }; |
| 186 | |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 187 | enum class ContentType { |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 188 | kRealtimeVideo, |
Erik Språng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 189 | kScreen, |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 190 | }; |
| 191 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 192 | class VideoStreamFactoryInterface : public rtc::RefCountInterface { |
| 193 | public: |
| 194 | // An implementation should return a std::vector<VideoStream> with the |
| 195 | // wanted VideoStream settings for the given video resolution. |
| 196 | // The size of the vector may not be larger than |
| 197 | // |encoder_config.number_of_streams|. |
| 198 | virtual std::vector<VideoStream> CreateEncoderStreams( |
| 199 | int width, |
| 200 | int height, |
| 201 | const VideoEncoderConfig& encoder_config) = 0; |
| 202 | |
| 203 | protected: |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 204 | ~VideoStreamFactoryInterface() override {} |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 205 | }; |
| 206 | |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 207 | VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; |
| 208 | VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; |
| 209 | |
| 210 | // Mostly used by tests. Avoid creating copies if you can. |
| 211 | VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } |
| 212 | |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 213 | VideoEncoderConfig(); |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 214 | VideoEncoderConfig(VideoEncoderConfig&&); |
kwiberg@webrtc.org | ac2d27d | 2015-02-26 13:59:22 +0000 | [diff] [blame] | 215 | ~VideoEncoderConfig(); |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 216 | std::string ToString() const; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 217 | |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 218 | rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory; |
sprang | ce4aef1 | 2015-11-02 07:23:20 -0800 | [diff] [blame] | 219 | std::vector<SpatialLayer> spatial_layers; |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 220 | ContentType content_type; |
kthelgason | 29a44e3 | 2016-09-27 03:52:02 -0700 | [diff] [blame] | 221 | rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings; |
pbos@webrtc.org | ad3b5a5 | 2014-10-24 09:23:21 +0000 | [diff] [blame] | 222 | |
| 223 | // Padding will be used up to this bitrate regardless of the bitrate produced |
| 224 | // by the encoder. Padding above what's actually produced by the encoder helps |
| 225 | // maintaining a higher bitrate estimate. Padding will however not be sent |
| 226 | // unless the estimated bandwidth indicates that the link can handle it. |
| 227 | int min_transmit_bitrate_bps; |
perkj | fa10b55 | 2016-10-02 23:45:26 -0700 | [diff] [blame] | 228 | int max_bitrate_bps; |
| 229 | |
| 230 | // Max number of encoded VideoStreams to produce. |
| 231 | size_t number_of_streams; |
perkj | 26091b1 | 2016-09-01 01:17:40 -0700 | [diff] [blame] | 232 | |
| 233 | private: |
| 234 | // Access to the copy constructor is private to force use of the Copy() |
| 235 | // method for those exceptional cases where we do use it. |
solenberg | 940b6d6 | 2016-10-25 11:19:07 -0700 | [diff] [blame] | 236 | VideoEncoderConfig(const VideoEncoderConfig&); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 237 | }; |
| 238 | |
mflodman@webrtc.org | 65f995a | 2013-04-18 12:02:52 +0000 | [diff] [blame] | 239 | } // namespace webrtc |
| 240 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 241 | #endif // WEBRTC_CONFIG_H_ |