blob: a6778715d87f634692a63b59aac64d3010ec73c6 [file] [log] [blame]
mflodman@webrtc.org06e80262013-04-18 12:02:521/*
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.org24e20892013-10-28 16:32:0111// TODO(pbos): Move Config from common.h to here.
12
pbos@webrtc.orgf0a119f2014-07-20 15:27:3513#ifndef WEBRTC_CONFIG_H_
14#define WEBRTC_CONFIG_H_
mflodman@webrtc.org06e80262013-04-18 12:02:5215
16#include <string>
pbos@webrtc.org041d54b2013-09-16 13:01:4717#include <vector>
mflodman@webrtc.org06e80262013-04-18 12:02:5218
johan246856b2016-08-05 16:19:2519#include "webrtc/base/optional.h"
kthelgason4cc4a8d2016-09-27 10:52:0220#include "webrtc/base/refcount.h"
21#include "webrtc/base/scoped_ref_ptr.h"
sprang@webrtc.org49812e62014-01-07 09:54:3422#include "webrtc/common_types.h"
pbos@webrtc.org346dbe72013-11-20 11:48:5623#include "webrtc/typedefs.h"
24
mflodman@webrtc.org06e80262013-04-18 12:02:5225namespace webrtc {
mflodman@webrtc.org06e80262013-04-18 12:02:5226
mflodman@webrtc.org06e80262013-04-18 12:02:5227// Settings for NACK, see RFC 4585 for details.
28struct NackConfig {
pbos@webrtc.orgb2d1a402013-05-28 08:04:4529 NackConfig() : rtp_history_ms(0) {}
solenberg5a37e3e2016-06-14 17:02:4130 std::string ToString() const;
mflodman@webrtc.org06e80262013-04-18 12:02:5231 // Send side: the time RTP packets are stored for retransmissions.
32 // Receive side: the time the receiver is prepared to wait for
33 // retransmissions.
pbos@webrtc.orgb2d1a402013-05-28 08:04:4534 // Set to '0' to disable.
mflodman@webrtc.org06e80262013-04-18 12:02:5235 int rtp_history_ms;
36};
37
brandtrd984c572016-10-05 06:28:3938// Settings for ULPFEC forward error correction.
39// Set the payload types to '-1' to disable.
40struct UlpfecConfig {
41 UlpfecConfig()
Shao Changbin0f071712015-04-21 12:24:5042 : ulpfec_payload_type(-1),
43 red_payload_type(-1),
44 red_rtx_payload_type(-1) {}
pbos@webrtc.org7e686932014-05-15 09:35:0645 std::string ToString() const;
mflodman@webrtc.org06e80262013-04-18 12:02:5246 // Payload type used for ULPFEC packets.
47 int ulpfec_payload_type;
48
49 // Payload type used for RED packets.
50 int red_payload_type;
Shao Changbin0f071712015-04-21 12:24:5051
52 // RTX payload type for RED payload.
53 int red_rtx_payload_type;
mflodman@webrtc.org06e80262013-04-18 12:02:5254};
55
solenbergffe1ce02015-11-16 15:34:5056// RTP header extension, see RFC 5285.
mflodman@webrtc.org06e80262013-04-18 12:02:5257struct RtpExtension {
isheriffc4921f42016-05-26 18:24:5558 RtpExtension() : id(0) {}
59 RtpExtension(const std::string& uri, int id) : uri(uri), id(id) {}
pbos@webrtc.org7e686932014-05-15 09:35:0660 std::string ToString() const;
solenbergffe1ce02015-11-16 15:34:5061 bool operator==(const RtpExtension& rhs) const {
isheriffc4921f42016-05-26 18:24:5562 return uri == rhs.uri && id == rhs.id;
solenbergffe1ce02015-11-16 15:34:5063 }
isheriffc4921f42016-05-26 18:24:5564 static bool IsSupportedForAudio(const std::string& uri);
65 static bool IsSupportedForVideo(const std::string& uri);
pbos@webrtc.orgf0a119f2014-07-20 15:27:3566
isheriffc4921f42016-05-26 18:24:5567 // Header extension for audio levels, as defined in:
68 // http://tools.ietf.org/html/draft-ietf-avtext-client-to-mixer-audio-level-03
69 static const char* kAudioLevelUri;
70 static const int kAudioLevelDefaultId;
71
72 // Header extension for RTP timestamp offset, see RFC 5450 for details:
73 // http://tools.ietf.org/html/rfc5450
74 static const char* kTimestampOffsetUri;
75 static const int kTimestampOffsetDefaultId;
76
77 // Header extension for absolute send time, see url for details:
78 // http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time
79 static const char* kAbsSendTimeUri;
80 static const int kAbsSendTimeDefaultId;
81
82 // Header extension for coordination of video orientation, see url for
83 // details:
84 // http://www.etsi.org/deliver/etsi_ts/126100_126199/126114/12.07.00_60/ts_126114v120700p.pdf
85 static const char* kVideoRotationUri;
86 static const int kVideoRotationDefaultId;
87
88 // Header extension for transport sequence number, see url for details:
89 // http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions
90 static const char* kTransportSequenceNumberUri;
91 static const int kTransportSequenceNumberDefaultId;
92
isheriff00cc0452016-06-08 07:24:2193 static const char* kPlayoutDelayUri;
94 static const int kPlayoutDelayDefaultId;
95
isheriffc4921f42016-05-26 18:24:5596 std::string uri;
mflodman@webrtc.org06e80262013-04-18 12:02:5297 int id;
98};
pbos@webrtc.org7e686932014-05-15 09:35:0699
100struct VideoStream {
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22101 VideoStream();
102 ~VideoStream();
pbos@webrtc.org7e686932014-05-15 09:35:06103 std::string ToString() const;
104
105 size_t width;
106 size_t height;
107 int max_framerate;
108
109 int min_bitrate_bps;
110 int target_bitrate_bps;
111 int max_bitrate_bps;
112
113 int max_qp;
114
pbos@webrtc.orgddb84aa2014-10-31 13:08:10115 // Bitrate thresholds for enabling additional temporal layers. Since these are
116 // thresholds in between layers, we have one additional layer. One threshold
117 // gives two temporal layers, one below the threshold and one above, two give
118 // three, and so on.
119 // The VideoEncoder may redistribute bitrates over the temporal layers so a
120 // bitrate threshold of 100k and an estimate of 105k does not imply that we
121 // get 100k in one temporal layer and 5k in the other, just that the bitrate
122 // in the first temporal layer should not exceed 100k.
kthelgason4cc4a8d2016-09-27 10:52:02123 // TODO(kthelgason): Apart from a special case for two-layer screencast these
pbos@webrtc.orgddb84aa2014-10-31 13:08:10124 // thresholds are not propagated to the VideoEncoder. To be implemented.
125 std::vector<int> temporal_layer_thresholds_bps;
pbos@webrtc.org7e686932014-05-15 09:35:06126};
127
perkj730a9e72016-10-03 06:45:26128class VideoEncoderConfig {
perkj3f65eaf2016-09-01 08:17:40129 public:
kthelgason4cc4a8d2016-09-27 10:52:02130 // These are reference counted to permit copying VideoEncoderConfig and be
131 // kept alive until all encoder_specific_settings go out of scope.
132 // TODO(kthelgason): Consider removing the need for copying VideoEncoderConfig
133 // and use rtc::Optional for encoder_specific_settings instead.
134 class EncoderSpecificSettings : public rtc::RefCountInterface {
135 public:
136 // TODO(pbos): Remove FillEncoderSpecificSettings as soon as VideoCodec is
137 // not in use and encoder implementations ask for codec-specific structs
138 // directly.
139 void FillEncoderSpecificSettings(VideoCodec* codec_struct) const;
140
141 virtual void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const;
142 virtual void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const;
143 virtual void FillVideoCodecH264(VideoCodecH264* h264_settings) const;
144 private:
145 virtual ~EncoderSpecificSettings() {}
perkj730a9e72016-10-03 06:45:26146 friend class VideoEncoderConfig;
kthelgason4cc4a8d2016-09-27 10:52:02147 };
148
149 class H264EncoderSpecificSettings : public EncoderSpecificSettings {
150 public:
151 explicit H264EncoderSpecificSettings(const VideoCodecH264& specifics);
perkj730a9e72016-10-03 06:45:26152 void FillVideoCodecH264(VideoCodecH264* h264_settings) const override;
kthelgason4cc4a8d2016-09-27 10:52:02153
154 private:
155 VideoCodecH264 specifics_;
156 };
157
158 class Vp8EncoderSpecificSettings : public EncoderSpecificSettings {
159 public:
160 explicit Vp8EncoderSpecificSettings(const VideoCodecVP8& specifics);
perkj730a9e72016-10-03 06:45:26161 void FillVideoCodecVp8(VideoCodecVP8* vp8_settings) const override;
kthelgason4cc4a8d2016-09-27 10:52:02162
163 private:
164 VideoCodecVP8 specifics_;
165 };
166
167 class Vp9EncoderSpecificSettings : public EncoderSpecificSettings {
168 public:
169 explicit Vp9EncoderSpecificSettings(const VideoCodecVP9& specifics);
perkj730a9e72016-10-03 06:45:26170 void FillVideoCodecVp9(VideoCodecVP9* vp9_settings) const override;
kthelgason4cc4a8d2016-09-27 10:52:02171
172 private:
173 VideoCodecVP9 specifics_;
174 };
175
Erik Språngfc398fe2015-04-28 08:01:41176 enum class ContentType {
pbos@webrtc.org58b51402014-09-19 12:30:25177 kRealtimeVideo,
Erik Språngfc398fe2015-04-28 08:01:41178 kScreen,
pbos@webrtc.org58b51402014-09-19 12:30:25179 };
180
perkj730a9e72016-10-03 06:45:26181 class VideoStreamFactoryInterface : public rtc::RefCountInterface {
182 public:
183 // An implementation should return a std::vector<VideoStream> with the
184 // wanted VideoStream settings for the given video resolution.
185 // The size of the vector may not be larger than
186 // |encoder_config.number_of_streams|.
187 virtual std::vector<VideoStream> CreateEncoderStreams(
188 int width,
189 int height,
190 const VideoEncoderConfig& encoder_config) = 0;
191
192 protected:
193 virtual ~VideoStreamFactoryInterface() {}
194 };
195
perkj3f65eaf2016-09-01 08:17:40196 VideoEncoderConfig& operator=(VideoEncoderConfig&&) = default;
197 VideoEncoderConfig& operator=(const VideoEncoderConfig&) = delete;
198
199 // Mostly used by tests. Avoid creating copies if you can.
200 VideoEncoderConfig Copy() const { return VideoEncoderConfig(*this); }
201
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22202 VideoEncoderConfig();
perkj3f65eaf2016-09-01 08:17:40203 VideoEncoderConfig(VideoEncoderConfig&&) = default;
kwiberg@webrtc.orgc4e2cd02015-02-26 13:59:22204 ~VideoEncoderConfig();
pbos@webrtc.org23668752014-10-24 09:23:21205 std::string ToString() const;
pbos@webrtc.org58b51402014-09-19 12:30:25206
perkj730a9e72016-10-03 06:45:26207 rtc::scoped_refptr<VideoStreamFactoryInterface> video_stream_factory;
sprang0ba16d12015-11-02 15:23:20208 std::vector<SpatialLayer> spatial_layers;
pbos@webrtc.org58b51402014-09-19 12:30:25209 ContentType content_type;
kthelgason4cc4a8d2016-09-27 10:52:02210 rtc::scoped_refptr<const EncoderSpecificSettings> encoder_specific_settings;
pbos@webrtc.org23668752014-10-24 09:23:21211
212 // Padding will be used up to this bitrate regardless of the bitrate produced
213 // by the encoder. Padding above what's actually produced by the encoder helps
214 // maintaining a higher bitrate estimate. Padding will however not be sent
215 // unless the estimated bandwidth indicates that the link can handle it.
216 int min_transmit_bitrate_bps;
perkj730a9e72016-10-03 06:45:26217 int max_bitrate_bps;
218
219 // Max number of encoded VideoStreams to produce.
220 size_t number_of_streams;
perkj3f65eaf2016-09-01 08:17:40221
222 private:
223 // Access to the copy constructor is private to force use of the Copy()
224 // method for those exceptional cases where we do use it.
225 VideoEncoderConfig(const VideoEncoderConfig&) = default;
pbos@webrtc.org58b51402014-09-19 12:30:25226};
227
johan246856b2016-08-05 16:19:25228struct VideoDecoderH264Settings {
229 std::string sprop_parameter_sets;
230};
231
232class DecoderSpecificSettings {
233 public:
234 virtual ~DecoderSpecificSettings() {}
235 rtc::Optional<VideoDecoderH264Settings> h264_extra_settings;
236};
237
mflodman@webrtc.org06e80262013-04-18 12:02:52238} // namespace webrtc
239
pbos@webrtc.orgf0a119f2014-07-20 15:27:35240#endif // WEBRTC_CONFIG_H_