Line data Source code
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 : // TODO(pbos): Move Config from common.h to here.
12 :
13 : #ifndef WEBRTC_CONFIG_H_
14 : #define WEBRTC_CONFIG_H_
15 :
16 : #include <string>
17 : #include <vector>
18 : #include <string.h>
19 : #include <algorithm>
20 :
21 : #include "webrtc/base/basictypes.h"
22 : #include "webrtc/base/optional.h"
23 : #include "webrtc/base/refcount.h"
24 : #include "webrtc/base/scoped_ref_ptr.h"
25 : #include "webrtc/common_types.h"
26 : #include "webrtc/typedefs.h"
27 :
28 : namespace webrtc {
29 :
30 : // Settings for NACK, see RFC 4585 for details.
31 : struct NackConfig {
32 0 : NackConfig() : rtp_history_ms(0) {}
33 : std::string ToString() const;
34 : // Send side: the time RTP packets are stored for retransmissions.
35 : // Receive side: the time the receiver is prepared to wait for
36 : // retransmissions.
37 : // Set to '0' to disable.
38 : int rtp_history_ms;
39 : };
40 :
41 : // Settings for ULPFEC forward error correction.
42 : // Set the payload types to '-1' to disable.
43 : struct UlpfecConfig {
44 0 : UlpfecConfig()
45 0 : : ulpfec_payload_type(-1),
46 : red_payload_type(-1),
47 0 : red_rtx_payload_type(-1) {}
48 : std::string ToString() const;
49 : bool operator==(const UlpfecConfig& other) const;
50 :
51 : // Payload type used for ULPFEC packets.
52 : int ulpfec_payload_type;
53 :
54 : // Payload type used for RED packets.
55 : int red_payload_type;
56 :
57 : // RTX payload type for RED payload.
58 : int red_rtx_payload_type;
59 : };
60 :
61 : // RTP header extension, see RFC 5285.
62 0 : struct RtpExtension {
63 : RtpExtension() : id(0) {}
64 0 : RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {}
65 : std::string ToString() const;
66 : bool operator==(const RtpExtension& rhs) const {
67 : return uri == rhs.uri && id == rhs.id;
68 : }
69 : static bool IsSupportedForAudio(const std::string& uri);
70 : static bool IsSupportedForVideo(const std::string& uri);
71 :
72 : // Header extension for audio levels, as defined in:
73 : // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
74 : static const char* kAudioLevelUri;
75 : static const int kAudioLevelDefaultId;
76 :
77 : // Header extension for RTP timestamp offset, see RFC 5450 for details:
78 : // http://tools.ietf.org/html/rfc5450
79 : static const char* kTimestampOffsetUri;
80 : static const int kTimestampOffsetDefaultId;
81 :
82 : // Header extension for absolute send time, see url for details:
83 : // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
84 : static const char* kAbsSendTimeUri;
85 : static const int kAbsSendTimeDefaultId;
86 :
87 : // Header extension for coordination of video orientation, see url for
88 : // details:
89 : // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
90 : static const char* kVideoRotationUri;
91 : static const int kVideoRotationDefaultId;
92 :
93 : // Header extension for transport sequence number, see url for details:
94 : // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
95 : static const char* kTransportSequenceNumberUri;
96 : static const int kTransportSequenceNumberDefaultId;
97 :
98 : static const char* kPlayoutDelayUri;
99 : static const int kPlayoutDelayDefaultId;
100 :
101 : static const char* kRtpStreamIdUri;
102 : static const int kRtpStreamIdDefaultId;
103 :
104 : std::string uri;
105 : int id;
106 : };
107 :
108 0 : struct VideoStream {
109 : VideoStream();
110 : ~VideoStream();
111 : std::string ToString() const;
112 :
113 : size_t width;
114 : size_t height;
115 : int max_framerate;
116 :
117 : int min_bitrate_bps;
118 : int target_bitrate_bps;
119 : int max_bitrate_bps;
120 :
121 : int max_qp;
122 :
123 : char rid[kRIDSize+1];
124 :
125 : const std::string Rid() const {
126 : return std::string(rid);
127 : }
128 :
129 0 : void SetRid(const std::string & aRid) {
130 : static_assert(sizeof(rid) > kRIDSize,
131 : "mRid must be large enought to hold a RID + null termination");
132 0 : auto len = std::min((size_t)kRIDSize-1, aRid.length());
133 0 : strncpy(&rid[0], aRid.c_str(), len);
134 0 : rid[len] = 0;
135 0 : }
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.
144 : // TODO(kthelgason): Apart from a special case for two-layer screencast these
145 : // thresholds are not propagated to the VideoEncoder. To be implemented.
146 : std::vector<int> temporal_layer_thresholds_bps;
147 : };
148 :
149 0 : class VideoEncoderConfig {
150 : public:
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 0 : 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:
166 0 : ~EncoderSpecificSettings() override {}
167 : friend class VideoEncoderConfig;
168 : };
169 :
170 0 : class H264EncoderSpecificSettings : public EncoderSpecificSettings {
171 : public:
172 : explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics);
173 : void FillVideoCodecH264(VideoCodecH264* h264_settings) const override;
174 :
175 : private:
176 : VideoCodecH264 specifics_;
177 : };
178 :
179 0 : class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
180 : public:
181 : explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
182 : void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override;
183 :
184 : private:
185 : VideoCodecVP8 specifics_;
186 : };
187 :
188 0 : class Vp9EncoderSpecificSettings : public EncoderSpecificSettings {
189 : public:
190 : explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics);
191 : void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override;
192 :
193 : private:
194 : VideoCodecVP9 specifics_;
195 : };
196 :
197 : enum class ContentType {
198 : kRealtimeVideo,
199 : kScreen,
200 : };
201 :
202 0 : 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:
214 0 : ~VideoStreamFactoryInterface() override {}
215 : };
216 :
217 : VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default;
218 : VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete;
219 :
220 : // Mostly used by tests. Avoid creating copies if you can.
221 0 : VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); }
222 :
223 : VideoEncoderConfig();
224 : VideoEncoderConfig(VideoEncoderConfig&&);
225 : ~VideoEncoderConfig();
226 : std::string ToString() const;
227 :
228 : rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory;
229 : std::vector<SpatialLayer> spatial_layers;
230 : ContentType content_type;
231 : rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings;
232 : unsigned char resolution_divisor;
233 :
234 : // Padding will be used up to this bitrate regardless of the bitrate produced
235 : // by the encoder. Padding above what's actually produced by the encoder helps
236 : // maintaining a higher bitrate estimate. Padding will however not be sent
237 : // unless the estimated bandwidth indicates that the link can handle it.
238 : int min_transmit_bitrate_bps;
239 : int max_bitrate_bps;
240 :
241 : // Max number of encoded VideoStreams to produce.
242 : size_t number_of_streams;
243 :
244 : private:
245 : // Access to the copy constructor is private to force use of the Copy()
246 : // method for those exceptional cases where we do use it.
247 : VideoEncoderConfig(const VideoEncoderConfig&);
248 : };
249 :
250 : } // namespace webrtc
251 :
252 : #endif // WEBRTC_CONFIG_H_
|