blob: cb6dcb24a162c1c78025a4174673e99a8a04ec1a [file] [log] [blame]
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +00001/*
2 * Copyright (c) 2014 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#include "webrtc/config.h"
11
12#include <sstream>
13#include <string>
14
kthelgason29a44e32016-09-27 03:52:02 -070015#include "webrtc/base/checks.h"
16
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000017namespace webrtc {
solenberg971cab02016-06-14 10:02:41 -070018std::string NackConfig::ToString() const {
19 std::stringstream ss;
20 ss << "{rtp_history_ms: " << rtp_history_ms;
21 ss << '}';
22 return ss.str();
23}
24
brandtrb5f2c3f2016-10-04 23:28:39 -070025std::string UlpfecConfig::ToString() const {
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000026 std::stringstream ss;
27 ss << "{ulpfec_payload_type: " << ulpfec_payload_type;
28 ss << ", red_payload_type: " << red_payload_type;
Stefan Holmer10880012016-02-03 13:29:59 +010029 ss << ", red_rtx_payload_type: " << red_rtx_payload_type;
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000030 ss << '}';
31 return ss.str();
32}
33
brandtr468da7c2016-11-22 02:16:47 -080034bool UlpfecConfig::operator==(const UlpfecConfig& other) const {
35 return ulpfec_payload_type == other.ulpfec_payload_type &&
36 red_payload_type == other.red_payload_type &&
37 red_rtx_payload_type == other.red_rtx_payload_type;
38}
39
solenberg940b6d62016-10-25 11:19:07 -070040FlexfecConfig::FlexfecConfig()
41 : flexfec_payload_type(-1), flexfec_ssrc(0), protected_media_ssrcs() {}
42
43FlexfecConfig::~FlexfecConfig() = default;
44
brandtr76648da2016-10-20 04:54:48 -070045std::string FlexfecConfig::ToString() const {
46 std::stringstream ss;
47 ss << "{flexfec_payload_type: " << flexfec_payload_type;
48 ss << ", flexfec_ssrc: " << flexfec_ssrc;
49 ss << ", protected_media_ssrcs: [";
50 size_t i = 0;
51 for (; i + 1 < protected_media_ssrcs.size(); ++i)
52 ss << protected_media_ssrcs[i] << ", ";
53 if (!protected_media_ssrcs.empty())
54 ss << protected_media_ssrcs[i];
55 ss << "]}";
56 return ss.str();
57}
58
brandtr468da7c2016-11-22 02:16:47 -080059bool FlexfecConfig::IsCompleteAndEnabled() const {
60 // Check if FlexFEC is enabled.
61 if (flexfec_payload_type < 0)
62 return false;
63 // Do we have the necessary SSRC information?
64 if (flexfec_ssrc == 0)
65 return false;
66 // TODO(brandtr): Update this check when we support multistream protection.
67 if (protected_media_ssrcs.size() != 1u)
68 return false;
69 return true;
70}
71
72bool FlexfecConfig::operator==(const FlexfecConfig& other) const {
73 return flexfec_payload_type == other.flexfec_payload_type &&
74 flexfec_ssrc == other.flexfec_ssrc &&
75 protected_media_ssrcs == other.protected_media_ssrcs;
76}
77
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000078std::string RtpExtension::ToString() const {
79 std::stringstream ss;
isheriff6f8d6862016-05-26 11:24:55 -070080 ss << "{uri: " << uri;
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +000081 ss << ", id: " << id;
82 ss << '}';
83 return ss.str();
84}
85
isheriff6f8d6862016-05-26 11:24:55 -070086const char* RtpExtension::kAudioLevelUri =
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020087 "urn:ietf:params:rtp-hdrext:ssrc-audio-level";
isheriff6f8d6862016-05-26 11:24:55 -070088const int RtpExtension::kAudioLevelDefaultId = 1;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +020089
isheriff6f8d6862016-05-26 11:24:55 -070090const char* RtpExtension::kTimestampOffsetUri =
91 "urn:ietf:params:rtp-hdrext:toffset";
92const int RtpExtension::kTimestampOffsetDefaultId = 2;
93
94const char* RtpExtension::kAbsSendTimeUri =
95 "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time";
96const int RtpExtension::kAbsSendTimeDefaultId = 3;
97
98const char* RtpExtension::kVideoRotationUri = "urn:3gpp:video-orientation";
99const int RtpExtension::kVideoRotationDefaultId = 4;
100
101const char* RtpExtension::kTransportSequenceNumberUri =
102 "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01";
103const int RtpExtension::kTransportSequenceNumberDefaultId = 5;
104
isheriff6b4b5f32016-06-08 00:24:21 -0700105// This extension allows applications to adaptively limit the playout delay
106// on frames as per the current needs. For example, a gaming application
107// has very different needs on end-to-end delay compared to a video-conference
108// application.
109const char* RtpExtension::kPlayoutDelayUri =
110 "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay";
111const int RtpExtension::kPlayoutDelayDefaultId = 6;
112
isheriff6f8d6862016-05-26 11:24:55 -0700113bool RtpExtension::IsSupportedForAudio(const std::string& uri) {
solenbergd4adce42016-11-17 06:26:52 -0800114 return uri == webrtc::RtpExtension::kAudioLevelUri ||
isheriff6f8d6862016-05-26 11:24:55 -0700115 uri == webrtc::RtpExtension::kTransportSequenceNumberUri;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200116}
117
isheriff6f8d6862016-05-26 11:24:55 -0700118bool RtpExtension::IsSupportedForVideo(const std::string& uri) {
119 return uri == webrtc::RtpExtension::kTimestampOffsetUri ||
120 uri == webrtc::RtpExtension::kAbsSendTimeUri ||
121 uri == webrtc::RtpExtension::kVideoRotationUri ||
isheriff6b4b5f32016-06-08 00:24:21 -0700122 uri == webrtc::RtpExtension::kTransportSequenceNumberUri ||
123 uri == webrtc::RtpExtension::kPlayoutDelayUri;
Fredrik Solenberg23fba1f2015-04-29 15:24:01 +0200124}
125
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000126VideoStream::VideoStream()
127 : width(0),
128 height(0),
129 max_framerate(-1),
130 min_bitrate_bps(-1),
131 target_bitrate_bps(-1),
132 max_bitrate_bps(-1),
133 max_qp(-1) {}
134
135VideoStream::~VideoStream() = default;
136
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000137std::string VideoStream::ToString() const {
138 std::stringstream ss;
139 ss << "{width: " << width;
140 ss << ", height: " << height;
141 ss << ", max_framerate: " << max_framerate;
142 ss << ", min_bitrate_bps:" << min_bitrate_bps;
143 ss << ", target_bitrate_bps:" << target_bitrate_bps;
144 ss << ", max_bitrate_bps:" << max_bitrate_bps;
145 ss << ", max_qp: " << max_qp;
146
pbos@webrtc.org931e3da2014-11-06 09:35:08 +0000147 ss << ", temporal_layer_thresholds_bps: [";
pbos@webrtc.orgb7ed7792014-10-31 13:08:10 +0000148 for (size_t i = 0; i < temporal_layer_thresholds_bps.size(); ++i) {
149 ss << temporal_layer_thresholds_bps[i];
150 if (i != temporal_layer_thresholds_bps.size() - 1)
pbos@webrtc.org931e3da2014-11-06 09:35:08 +0000151 ss << ", ";
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000152 }
pbos@webrtc.org931e3da2014-11-06 09:35:08 +0000153 ss << ']';
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000154
155 ss << '}';
156 return ss.str();
157}
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000158
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000159VideoEncoderConfig::VideoEncoderConfig()
Erik Språng143cec12015-04-28 10:01:41 +0200160 : content_type(ContentType::kRealtimeVideo),
kthelgason29a44e32016-09-27 03:52:02 -0700161 encoder_specific_settings(nullptr),
skvlad3abb7642016-06-16 12:08:03 -0700162 min_transmit_bitrate_bps(0),
perkjfa10b552016-10-02 23:45:26 -0700163 max_bitrate_bps(0),
164 number_of_streams(0) {}
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000165
solenberg940b6d62016-10-25 11:19:07 -0700166VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default;
167
kwiberg@webrtc.orgac2d27d2015-02-26 13:59:22 +0000168VideoEncoderConfig::~VideoEncoderConfig() = default;
169
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000170std::string VideoEncoderConfig::ToString() const {
171 std::stringstream ss;
perkjfa10b552016-10-02 23:45:26 -0700172 ss << "{content_type: ";
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000173 switch (content_type) {
Erik Språng143cec12015-04-28 10:01:41 +0200174 case ContentType::kRealtimeVideo:
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000175 ss << "kRealtimeVideo";
176 break;
Erik Språng143cec12015-04-28 10:01:41 +0200177 case ContentType::kScreen:
pbos@webrtc.orgad3b5a52014-10-24 09:23:21 +0000178 ss << "kScreenshare";
179 break;
180 }
181 ss << ", encoder_specific_settings: ";
182 ss << (encoder_specific_settings != NULL ? "(ptr)" : "NULL");
183
184 ss << ", min_transmit_bitrate_bps: " << min_transmit_bitrate_bps;
185 ss << '}';
186 return ss.str();
187}
188
solenberg940b6d62016-10-25 11:19:07 -0700189VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default;
190
kthelgason29a44e32016-09-27 03:52:02 -0700191void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings(
192 VideoCodec* codec) const {
193 if (codec->codecType == kVideoCodecH264) {
hta527d3472016-11-16 23:23:04 -0800194 FillVideoCodecH264(codec->H264());
kthelgason29a44e32016-09-27 03:52:02 -0700195 } else if (codec->codecType == kVideoCodecVP8) {
hta527d3472016-11-16 23:23:04 -0800196 FillVideoCodecVp8(codec->VP8());
kthelgason29a44e32016-09-27 03:52:02 -0700197 } else if (codec->codecType == kVideoCodecVP9) {
hta527d3472016-11-16 23:23:04 -0800198 FillVideoCodecVp9(codec->VP9());
kthelgason29a44e32016-09-27 03:52:02 -0700199 } else {
200 RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type.";
201 }
202}
203
204void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264(
205 VideoCodecH264* h264_settings) const {
206 RTC_NOTREACHED();
207}
208
209void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8(
210 VideoCodecVP8* vp8_settings) const {
211 RTC_NOTREACHED();
212}
213
214void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9(
215 VideoCodecVP9* vp9_settings) const {
216 RTC_NOTREACHED();
217}
218
219VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings(
220 const VideoCodecH264& specifics)
221 : specifics_(specifics) {}
222
223void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264(
224 VideoCodecH264* h264_settings) const {
225 *h264_settings = specifics_;
226}
227
228VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings(
229 const VideoCodecVP8& specifics)
230 : specifics_(specifics) {}
231
232void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8(
233 VideoCodecVP8* vp8_settings) const {
234 *vp8_settings = specifics_;
235}
236
237VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings(
238 const VideoCodecVP9& specifics)
239 : specifics_(specifics) {}
240
241void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9(
242 VideoCodecVP9* vp9_settings) const {
243 *vp9_settings = specifics_;
244}
245
pbos@webrtc.org1e92b0a2014-05-15 09:35:06 +0000246} // namespace webrtc