| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // TODO(pbos): Move Config from common.h to here. | |
| 12 | |
| 13 #ifndef WEBRTC_CONFIG_H_ | 11 #ifndef WEBRTC_CONFIG_H_ |
| 14 #define WEBRTC_CONFIG_H_ | 12 #define WEBRTC_CONFIG_H_ |
| 15 | 13 |
| 16 #include <string> | 14 // TODO(holmer): Delete this file once downstream projects have been updated. |
| 17 #include <vector> | |
| 18 | 15 |
| 19 #include "webrtc/common_types.h" | 16 #include "webrtc/api/rtpparameters.h" |
| 20 #include "webrtc/rtc_base/basictypes.h" | 17 #include "webrtc/call/rtp_config.h" |
| 21 #include "webrtc/rtc_base/optional.h" | |
| 22 #include "webrtc/rtc_base/refcount.h" | |
| 23 #include "webrtc/rtc_base/scoped_ref_ptr.h" | |
| 24 #include "webrtc/typedefs.h" | |
| 25 | |
| 26 namespace webrtc { | |
| 27 | |
| 28 // Settings for NACK, see RFC 4585 for details. | |
| 29 struct NackConfig { | |
| 30 NackConfig() : rtp_history_ms(0) {} | |
| 31 std::string ToString() const; | |
| 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. | |
| 35 // Set to '0' to disable. | |
| 36 int rtp_history_ms; | |
| 37 }; | |
| 38 | |
| 39 // Settings for ULPFEC forward error correction. | |
| 40 // Set the payload types to '-1' to disable. | |
| 41 struct UlpfecConfig { | |
| 42 UlpfecConfig() | |
| 43 : ulpfec_payload_type(-1), | |
| 44 red_payload_type(-1), | |
| 45 red_rtx_payload_type(-1) {} | |
| 46 std::string ToString() const; | |
| 47 bool operator==(const UlpfecConfig& other) const; | |
| 48 | |
| 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; | |
| 54 | |
| 55 // RTX payload type for RED payload. | |
| 56 int red_rtx_payload_type; | |
| 57 }; | |
| 58 | |
| 59 // RTP header extension, see RFC 5285. | |
| 60 struct RtpExtension { | |
| 61 RtpExtension() {} | |
| 62 RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {} | |
| 63 RtpExtension(const std::string& uri, int id, bool encrypt) : uri(uri), | |
| 64 id(id), encrypt(encrypt) {} | |
| 65 std::string ToString() const; | |
| 66 bool operator==(const RtpExtension& rhs) const { | |
| 67 return uri == rhs.uri && id == rhs.id && encrypt == rhs.encrypt; | |
| 68 } | |
| 69 static bool IsSupportedForAudio(const std::string& uri); | |
| 70 static bool IsSupportedForVideo(const std::string& uri); | |
| 71 // Return "true" if the given RTP header extension URI may be encrypted. | |
| 72 static bool IsEncryptionSupported(const std::string& uri); | |
| 73 | |
| 74 // Returns the named header extension if found among all extensions, | |
| 75 // nullptr otherwise. | |
| 76 static const RtpExtension* FindHeaderExtensionByUri( | |
| 77 const std::vector<RtpExtension>& extensions, | |
| 78 const std::string& uri); | |
| 79 | |
| 80 // Return a list of RTP header extensions with the non-encrypted extensions | |
| 81 // removed if both the encrypted and non-encrypted extension is present for | |
| 82 // the same URI. | |
| 83 static std::vector<RtpExtension> FilterDuplicateNonEncrypted( | |
| 84 const std::vector<RtpExtension>& extensions); | |
| 85 | |
| 86 // Header extension for audio levels, as defined in: | |
| 87 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03 | |
| 88 static const char kAudioLevelUri[]; | |
| 89 static const int kAudioLevelDefaultId; | |
| 90 | |
| 91 // Header extension for RTP timestamp offset, see RFC 5450 for details: | |
| 92 // http://tools.ietf.org/html/rfc5450 | |
| 93 static const char kTimestampOffsetUri[]; | |
| 94 static const int kTimestampOffsetDefaultId; | |
| 95 | |
| 96 // Header extension for absolute send time, see url for details: | |
| 97 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time | |
| 98 static const char kAbsSendTimeUri[]; | |
| 99 static const int kAbsSendTimeDefaultId; | |
| 100 | |
| 101 // Header extension for coordination of video orientation, see url for | |
| 102 // details: | |
| 103 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126
114v120700p.pdf | |
| 104 static const char kVideoRotationUri[]; | |
| 105 static const int kVideoRotationDefaultId; | |
| 106 | |
| 107 // Header extension for video content type. E.g. default or screenshare. | |
| 108 static const char kVideoContentTypeUri[]; | |
| 109 static const int kVideoContentTypeDefaultId; | |
| 110 | |
| 111 // Header extension for video timing. | |
| 112 static const char kVideoTimingUri[]; | |
| 113 static const int kVideoTimingDefaultId; | |
| 114 | |
| 115 // Header extension for transport sequence number, see url for details: | |
| 116 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions | |
| 117 static const char kTransportSequenceNumberUri[]; | |
| 118 static const int kTransportSequenceNumberDefaultId; | |
| 119 | |
| 120 static const char kPlayoutDelayUri[]; | |
| 121 static const int kPlayoutDelayDefaultId; | |
| 122 | |
| 123 // Encryption of Header Extensions, see RFC 6904 for details: | |
| 124 // https://tools.ietf.org/html/rfc6904 | |
| 125 static const char kEncryptHeaderExtensionsUri[]; | |
| 126 | |
| 127 // Inclusive min and max IDs for one-byte header extensions, per RFC5285. | |
| 128 static const int kMinId; | |
| 129 static const int kMaxId; | |
| 130 | |
| 131 std::string uri; | |
| 132 int id = 0; | |
| 133 bool encrypt = false; | |
| 134 }; | |
| 135 | |
| 136 struct VideoStream { | |
| 137 VideoStream(); | |
| 138 ~VideoStream(); | |
| 139 std::string ToString() const; | |
| 140 | |
| 141 size_t width; | |
| 142 size_t height; | |
| 143 int max_framerate; | |
| 144 | |
| 145 int min_bitrate_bps; | |
| 146 int target_bitrate_bps; | |
| 147 int max_bitrate_bps; | |
| 148 | |
| 149 int max_qp; | |
| 150 | |
| 151 // Bitrate thresholds for enabling additional temporal layers. Since these are | |
| 152 // thresholds in between layers, we have one additional layer. One threshold | |
| 153 // gives two temporal layers, one below the threshold and one above, two give | |
| 154 // three, and so on. | |
| 155 // The VideoEncoder may redistribute bitrates over the temporal layers so a | |
| 156 // bitrate threshold of 100k and an estimate of 105k does not imply that we | |
| 157 // get 100k in one temporal layer and 5k in the other, just that the bitrate | |
| 158 // in the first temporal layer should not exceed 100k. | |
| 159 // TODO(kthelgason): Apart from a special case for two-layer screencast these | |
| 160 // thresholds are not propagated to the VideoEncoder. To be implemented. | |
| 161 std::vector<int> temporal_layer_thresholds_bps; | |
| 162 }; | |
| 163 | |
| 164 class VideoEncoderConfig { | |
| 165 public: | |
| 166 // These are reference counted to permit copying VideoEncoderConfig and be | |
| 167 // kept alive until all encoder_specific_settings go out of scope. | |
| 168 // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig | |
| 169 // and use rtc::Optional for encoder_specific_settings instead. | |
| 170 class EncoderSpecificSettings : public rtc::RefCountInterface { | |
| 171 public: | |
| 172 // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is | |
| 173 // not in use and encoder implementations ask for codec-specific structs | |
| 174 // directly. | |
| 175 void FillEncoderSpecificSettings(VideoCodec* codec_struct) const; | |
| 176 | |
| 177 virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const; | |
| 178 virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const; | |
| 179 virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const; | |
| 180 private: | |
| 181 ~EncoderSpecificSettings() override {} | |
| 182 friend class VideoEncoderConfig; | |
| 183 }; | |
| 184 | |
| 185 class H264EncoderSpecificSettings : public EncoderSpecificSettings { | |
| 186 public: | |
| 187 explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics); | |
| 188 void FillVideoCodecH264(VideoCodecH264* h264_settings) const override; | |
| 189 | |
| 190 private: | |
| 191 VideoCodecH264 specifics_; | |
| 192 }; | |
| 193 | |
| 194 class Vp8EncoderSpecificSettings : public EncoderSpecificSettings { | |
| 195 public: | |
| 196 explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics); | |
| 197 void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override; | |
| 198 | |
| 199 private: | |
| 200 VideoCodecVP8 specifics_; | |
| 201 }; | |
| 202 | |
| 203 class Vp9EncoderSpecificSettings : public EncoderSpecificSettings { | |
| 204 public: | |
| 205 explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics); | |
| 206 void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override; | |
| 207 | |
| 208 private: | |
| 209 VideoCodecVP9 specifics_; | |
| 210 }; | |
| 211 | |
| 212 enum class ContentType { | |
| 213 kRealtimeVideo, | |
| 214 kScreen, | |
| 215 }; | |
| 216 | |
| 217 class VideoStreamFactoryInterface : public rtc::RefCountInterface { | |
| 218 public: | |
| 219 // An implementation should return a std::vector<VideoStream> with the | |
| 220 // wanted VideoStream settings for the given video resolution. | |
| 221 // The size of the vector may not be larger than | |
| 222 // |encoder_config.number_of_streams|. | |
| 223 virtual std::vector<VideoStream> CreateEncoderStreams( | |
| 224 int width, | |
| 225 int height, | |
| 226 const VideoEncoderConfig& encoder_config) = 0; | |
| 227 | |
| 228 protected: | |
| 229 ~VideoStreamFactoryInterface() override {} | |
| 230 }; | |
| 231 | |
| 232 VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default; | |
| 233 VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete; | |
| 234 | |
| 235 // Mostly used by tests. Avoid creating copies if you can. | |
| 236 VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); } | |
| 237 | |
| 238 VideoEncoderConfig(); | |
| 239 VideoEncoderConfig(VideoEncoderConfig&&); | |
| 240 ~VideoEncoderConfig(); | |
| 241 std::string ToString() const; | |
| 242 | |
| 243 rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory; | |
| 244 std::vector<SpatialLayer> spatial_layers; | |
| 245 ContentType content_type; | |
| 246 rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings; | |
| 247 | |
| 248 // Padding will be used up to this bitrate regardless of the bitrate produced | |
| 249 // by the encoder. Padding above what's actually produced by the encoder helps | |
| 250 // maintaining a higher bitrate estimate. Padding will however not be sent | |
| 251 // unless the estimated bandwidth indicates that the link can handle it. | |
| 252 int min_transmit_bitrate_bps; | |
| 253 int max_bitrate_bps; | |
| 254 | |
| 255 // Max number of encoded VideoStreams to produce. | |
| 256 size_t number_of_streams; | |
| 257 | |
| 258 private: | |
| 259 // Access to the copy constructor is private to force use of the Copy() | |
| 260 // method for those exceptional cases where we do use it. | |
| 261 VideoEncoderConfig(const VideoEncoderConfig&); | |
| 262 }; | |
| 263 | |
| 264 } // namespace webrtc | |
| 265 | 18 |
| 266 #endif // WEBRTC_CONFIG_H_ | 19 #endif // WEBRTC_CONFIG_H_ |
| OLD | NEW |