blob: d5ed266c89c5eee2a4fe40601b9113221f5e46a8 [file] [log] [blame]
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +00001/*
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.org16e03b72013-10-28 16:32:01 +000011// TODO(pbos): Move Config from common.h to here.
12
pbos@webrtc.org3c107582014-07-20 15:27:35 +000013#ifndef WEBRTC_CONFIG_H_
14#define WEBRTC_CONFIG_H_
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000015
16#include <string>
pbos@webrtc.org5860de02013-09-16 13:01:47 +000017#include <vector>
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000018
brandtr76648da2016-10-20 04:54:48 -070019#include "webrtc/base/basictypes.h"
johan3859c892016-08-05 09:19:25 -070020#include "webrtc/base/optional.h"
kthelgason29a44e32016-09-27 03:52:02 -070021#include "webrtc/base/refcount.h"
22#include "webrtc/base/scoped_ref_ptr.h"
sprang@webrtc.orgccd42842014-01-07 09:54:34 +000023#include "webrtc/common_types.h"
pbos@webrtc.orgce90eff2013-11-20 11:48:56 +000024#include "webrtc/typedefs.h"
25
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000026namespace webrtc {
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000027
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000028// Settings for NACK, see RFC 4585 for details.
29struct NackConfig {
pbos@webrtc.orgeceb5322013-05-28 08:04:45 +000030 NackConfig() : rtp_history_ms(0) {}
solenberg971cab02016-06-14 10:02:41 -070031 std::string ToString() const;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000032 // 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.orgeceb5322013-05-28 08:04:45 +000035 // Set to '0' to disable.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000036 int rtp_history_ms;
37};
38
brandtrb5f2c3f2016-10-04 23:28:39 -070039// Settings for ULPFEC forward error correction.
40// Set the payload types to '-1' to disable.
41struct UlpfecConfig {
42 UlpfecConfig()
Shao Changbine62202f2015-04-21 20:24:50 +080043 : ulpfec_payload_type(-1),
44 red_payload_type(-1),
45 red_rtx_payload_type(-1) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000046 std::string ToString() const;
brandtr468da7c2016-11-22 02:16:47 -080047 bool operator==(const UlpfecConfig& other) const;
48
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000049 // 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 Changbine62202f2015-04-21 20:24:50 +080054
55 // RTX payload type for RED payload.
56 int red_rtx_payload_type;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000057};
58
solenberg3a941542015-11-16 07:34:50 -080059// RTP header extension, see RFC 5285.
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +000060struct RtpExtension {
isheriff6f8d6862016-05-26 11:24:55 -070061 RtpExtension() : id(0) {}
62 RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {}
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000063 std::string ToString() const;
solenberg3a941542015-11-16 07:34:50 -080064 bool operator==(const RtpExtension& rhs) const {
isheriff6f8d6862016-05-26 11:24:55 -070065 return uri == rhs.uri && id == rhs.id;
solenberg3a941542015-11-16 07:34:50 -080066 }
isheriff6f8d6862016-05-26 11:24:55 -070067 static bool IsSupportedForAudio(const std::string& uri);
68 static bool IsSupportedForVideo(const std::string& uri);
pbos@webrtc.org3c107582014-07-20 15:27:35 +000069
isheriff6f8d6862016-05-26 11:24:55 -070070 // 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
ilnik00d802b2017-04-11 10:34:31 -070091 // Header extension for video content type. E.g. default or screenshare.
92 static const char* kVideoContentTypeUri;
93 static const int kVideoContentTypeDefaultId;
94
ilnik04f4d122017-06-19 07:18:55 -070095 // Header extension for video timing.
96 static const char* kVideoTimingUri;
97 static const int kVideoTimingDefaultId;
98
isheriff6f8d6862016-05-26 11:24:55 -070099 // Header extension for transport sequence number, see url for details:
100 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
101 static const char* kTransportSequenceNumberUri;
102 static const int kTransportSequenceNumberDefaultId;
103
isheriff6b4b5f32016-06-08 00:24:21 -0700104 static const char* kPlayoutDelayUri;
105 static const int kPlayoutDelayDefaultId;
106
deadbeefe814a0d2017-02-25 18:15:09 -0800107 // Inclusive min and max IDs for one-byte header extensions, per RFC5285.
108 static const int kMinId;
109 static const int kMaxId;
110
isheriff6f8d6862016-05-26 11:24:55 -0700111 std::string uri;
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000112 int id;
113};
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000114
115struct VideoStream {
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000116 VideoStream();
117 ~VideoStream();
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000118 std::string ToString() const;
119
120 size_t width;
121 size_t height;
122 int max_framerate;
123
124 int min_bitrate_bps;
125 int target_bitrate_bps;
126 int max_bitrate_bps;
127
128 int max_qp;
129
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +0000130 // Bitrate thresholds for enabling additional temporal layers. Since these are
131 // thresholds in between layers, we have one additional layer. One threshold
132 // gives two temporal layers, one below the threshold and one above, two give
133 // three, and so on.
134 // The VideoEncoder may redistribute bitrates over the temporal layers so a
135 // bitrate threshold of 100k and an estimate of 105k does not imply that we
136 // get 100k in one temporal layer and 5k in the other, just that the bitrate
137 // in the first temporal layer should not exceed 100k.
kthelgason29a44e32016-09-27 03:52:02 -0700138 // TODO(kthelgason): Apart from a special case for two-layer screencast these
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +0000139 // thresholds are not propagated to the VideoEncoder. To be implemented.
140 std::vector<int> temporal_layer_thresholds_bps;
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000141};
142
perkjfa10b552016-10-02 23:45:26 -0700143class VideoEncoderConfig {
perkj26091b12016-09-01 01:17:40 -0700144 public:
kthelgason29a44e32016-09-27 03:52:02 -0700145 // These are reference counted to permit copying VideoEncoderConfig and be
146 // kept alive until all encoder_specific_settings go out of scope.
147 // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig
148 // and use rtc::Optional for encoder_specific_settings instead.
149 class EncoderSpecificSettings : public rtc::RefCountInterface {
150 public:
151 // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is
152 // not in use and encoder implementations ask for codec-specific structs
153 // directly.
154 void FillEncoderSpecificSettings(VideoCodec* codec_struct) const;
155
156 virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const;
157 virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const;
158 virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const;
159 private:
solenberg940b6d62016-10-25 11:19:07 -0700160 ~EncoderSpecificSettings() override {}
perkjfa10b552016-10-02 23:45:26 -0700161 friend class VideoEncoderConfig;
kthelgason29a44e32016-09-27 03:52:02 -0700162 };
163
164 class H264EncoderSpecificSettings : public EncoderSpecificSettings {
165 public:
166 explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics);
perkjfa10b552016-10-02 23:45:26 -0700167 void FillVideoCodecH264(VideoCodecH264* h264_settings) const override;
kthelgason29a44e32016-09-27 03:52:02 -0700168
169 private:
170 VideoCodecH264 specifics_;
171 };
172
173 class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
174 public:
175 explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
perkjfa10b552016-10-02 23:45:26 -0700176 void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override;
kthelgason29a44e32016-09-27 03:52:02 -0700177
178 private:
179 VideoCodecVP8 specifics_;
180 };
181
182 class Vp9EncoderSpecificSettings : public EncoderSpecificSettings {
183 public:
184 explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics);
perkjfa10b552016-10-02 23:45:26 -0700185 void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override;
kthelgason29a44e32016-09-27 03:52:02 -0700186
187 private:
188 VideoCodecVP9 specifics_;
189 };
190
Erik Språng143cec12015-04-28 10:01:41 +0200191 enum class ContentType {
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000192 kRealtimeVideo,
Erik Språng143cec12015-04-28 10:01:41 +0200193 kScreen,
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000194 };
195
perkjfa10b552016-10-02 23:45:26 -0700196 class VideoStreamFactoryInterface : public rtc::RefCountInterface {
197 public:
198 // An implementation should return a std::vector<VideoStream> with the
199 // wanted VideoStream settings for the given video resolution.
200 // The size of the vector may not be larger than
201 // |encoder_config.number_of_streams|.
202 virtual std::vector<VideoStream> CreateEncoderStreams(
203 int width,
204 int height,
205 const VideoEncoderConfig& encoder_config) = 0;
206
207 protected:
solenberg940b6d62016-10-25 11:19:07 -0700208 ~VideoStreamFactoryInterface() override {}
perkjfa10b552016-10-02 23:45:26 -0700209 };
210
perkj26091b12016-09-01 01:17:40 -0700211 VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default;
212 VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete;
213
214 // Mostly used by tests. Avoid creating copies if you can.
215 VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); }
216
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000217 VideoEncoderConfig();
solenberg940b6d62016-10-25 11:19:07 -0700218 VideoEncoderConfig(VideoEncoderConfig&&);
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000219 ~VideoEncoderConfig();
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000220 std::string ToString() const;
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000221
perkjfa10b552016-10-02 23:45:26 -0700222 rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory;
sprangce4aef12015-11-02 07:23:20 -0800223 std::vector<SpatialLayer> spatial_layers;
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000224 ContentType content_type;
kthelgason29a44e32016-09-27 03:52:02 -0700225 rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings;
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000226
227 // Padding will be used up to this bitrate regardless of the bitrate produced
228 // by the encoder. Padding above what's actually produced by the encoder helps
229 // maintaining a higher bitrate estimate. Padding will however not be sent
230 // unless the estimated bandwidth indicates that the link can handle it.
231 int min_transmit_bitrate_bps;
perkjfa10b552016-10-02 23:45:26 -0700232 int max_bitrate_bps;
233
234 // Max number of encoded VideoStreams to produce.
235 size_t number_of_streams;
perkj26091b12016-09-01 01:17:40 -0700236
237 private:
238 // Access to the copy constructor is private to force use of the Copy()
239 // method for those exceptional cases where we do use it.
solenberg940b6d62016-10-25 11:19:07 -0700240 VideoEncoderConfig(const VideoEncoderConfig&);
pbos@webrtc.orgbbe0a852014-09-19 12:30:25 +0000241};
242
mflodman@webrtc.org65f995a2013-04-18 12:02:52 +0000243} // namespace webrtc
244
pbos@webrtc.org3c107582014-07-20 15:27:35 +0000245#endif // WEBRTC_CONFIG_H_