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