pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 1 | /* |
| 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 | |
kthelgason | 4cc4a8d | 2016-09-27 10:52:02 | [diff] [blame] | 15 | #include "webrtc/base/checks.h" |
| 16 | |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 17 | namespace webrtc { |
solenberg | 5a37e3e | 2016-06-14 17:02:41 | [diff] [blame] | 18 | std::string NackConfig::ToString() const { |
| 19 | std::stringstream ss; |
| 20 | ss << "{rtp_history_ms: " << rtp_history_ms; |
| 21 | ss << '}'; |
| 22 | return ss.str(); |
| 23 | } |
| 24 | |
brandtr | d984c57 | 2016-10-05 06:28:39 | [diff] [blame] | 25 | std::string UlpfecConfig::ToString() const { |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 26 | std::stringstream ss; |
| 27 | ss << "{ulpfec_payload_type: " << ulpfec_payload_type; |
| 28 | ss << ", red_payload_type: " << red_payload_type; |
Stefan Holmer | 75851e0 | 2016-02-03 12:29:59 | [diff] [blame] | 29 | ss << ", red_rtx_payload_type: " << red_rtx_payload_type; |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 30 | ss << '}'; |
| 31 | return ss.str(); |
| 32 | } |
| 33 | |
brandtr | 056bdda | 2016-11-22 10:16:47 | [diff] [blame] | 34 | bool 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 | |
solenberg | 91c6f34 | 2016-10-25 18:19:07 | [diff] [blame] | 40 | FlexfecConfig::FlexfecConfig() |
| 41 | : flexfec_payload_type(-1), flexfec_ssrc(0), protected_media_ssrcs() {} |
| 42 | |
| 43 | FlexfecConfig::~FlexfecConfig() = default; |
| 44 | |
brandtr | 4e97439 | 2016-10-20 11:54:48 | [diff] [blame] | 45 | std::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 | |
brandtr | 056bdda | 2016-11-22 10:16:47 | [diff] [blame] | 59 | bool 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 | |
| 72 | bool 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.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 78 | std::string RtpExtension::ToString() const { |
| 79 | std::stringstream ss; |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 80 | ss << "{uri: " << uri; |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 81 | ss << ", id: " << id; |
| 82 | ss << '}'; |
| 83 | return ss.str(); |
| 84 | } |
| 85 | |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 86 | const char* RtpExtension::kAudioLevelUri = |
Fredrik Solenberg | ad86786 | 2015-04-29 13:24:01 | [diff] [blame] | 87 | "urn:ietf:params:rtp-hdrext:ssrc-audio-level"; |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 88 | const int RtpExtension::kAudioLevelDefaultId = 1; |
Fredrik Solenberg | ad86786 | 2015-04-29 13:24:01 | [diff] [blame] | 89 | |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 90 | const char* RtpExtension::kTimestampOffsetUri = |
| 91 | "urn:ietf:params:rtp-hdrext:toffset"; |
| 92 | const int RtpExtension::kTimestampOffsetDefaultId = 2; |
| 93 | |
| 94 | const char* RtpExtension::kAbsSendTimeUri = |
| 95 | "http://www.webrtc.org/experiments/rtp-hdrext/abs-send-time"; |
| 96 | const int RtpExtension::kAbsSendTimeDefaultId = 3; |
| 97 | |
| 98 | const char* RtpExtension::kVideoRotationUri = "urn:3gpp:video-orientation"; |
| 99 | const int RtpExtension::kVideoRotationDefaultId = 4; |
| 100 | |
| 101 | const char* RtpExtension::kTransportSequenceNumberUri = |
| 102 | "http://www.ietf.org/id/draft-holmer-rmcat-transport-wide-cc-extensions-01"; |
| 103 | const int RtpExtension::kTransportSequenceNumberDefaultId = 5; |
| 104 | |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 105 | // 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. |
| 109 | const char* RtpExtension::kPlayoutDelayUri = |
| 110 | "http://www.webrtc.org/experiments/rtp-hdrext/playout-delay"; |
| 111 | const int RtpExtension::kPlayoutDelayDefaultId = 6; |
| 112 | |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 113 | bool RtpExtension::IsSupportedForAudio(const std::string& uri) { |
solenberg | ac14ca2 | 2016-11-17 14:26:52 | [diff] [blame] | 114 | return uri == webrtc::RtpExtension::kAudioLevelUri || |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 115 | uri == webrtc::RtpExtension::kTransportSequenceNumberUri; |
Fredrik Solenberg | ad86786 | 2015-04-29 13:24:01 | [diff] [blame] | 116 | } |
| 117 | |
isheriff | c4921f4 | 2016-05-26 18:24:55 | [diff] [blame] | 118 | bool RtpExtension::IsSupportedForVideo(const std::string& uri) { |
| 119 | return uri == webrtc::RtpExtension::kTimestampOffsetUri || |
| 120 | uri == webrtc::RtpExtension::kAbsSendTimeUri || |
| 121 | uri == webrtc::RtpExtension::kVideoRotationUri || |
isheriff | 00cc045 | 2016-06-08 07:24:21 | [diff] [blame] | 122 | uri == webrtc::RtpExtension::kTransportSequenceNumberUri || |
| 123 | uri == webrtc::RtpExtension::kPlayoutDelayUri; |
Fredrik Solenberg | ad86786 | 2015-04-29 13:24:01 | [diff] [blame] | 124 | } |
| 125 | |
kwiberg@webrtc.org | c4e2cd0 | 2015-02-26 13:59:22 | [diff] [blame] | 126 | VideoStream::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 | |
| 135 | VideoStream::~VideoStream() = default; |
| 136 | |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 137 | std::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.org | 98dd0b8 | 2014-11-06 09:35:08 | [diff] [blame] | 147 | ss << ", temporal_layer_thresholds_bps: ["; |
pbos@webrtc.org | ddb84aa | 2014-10-31 13:08:10 | [diff] [blame] | 148 | 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.org | 98dd0b8 | 2014-11-06 09:35:08 | [diff] [blame] | 151 | ss << ", "; |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 152 | } |
pbos@webrtc.org | 98dd0b8 | 2014-11-06 09:35:08 | [diff] [blame] | 153 | ss << ']'; |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 154 | |
| 155 | ss << '}'; |
| 156 | return ss.str(); |
| 157 | } |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 158 | |
kwiberg@webrtc.org | c4e2cd0 | 2015-02-26 13:59:22 | [diff] [blame] | 159 | VideoEncoderConfig::VideoEncoderConfig() |
Erik Språng | fc398fe | 2015-04-28 08:01:41 | [diff] [blame] | 160 | : content_type(ContentType::kRealtimeVideo), |
kthelgason | 4cc4a8d | 2016-09-27 10:52:02 | [diff] [blame] | 161 | encoder_specific_settings(nullptr), |
skvlad | 48be054 | 2016-06-16 19:08:03 | [diff] [blame] | 162 | min_transmit_bitrate_bps(0), |
perkj | 730a9e7 | 2016-10-03 06:45:26 | [diff] [blame] | 163 | max_bitrate_bps(0), |
| 164 | number_of_streams(0) {} |
kwiberg@webrtc.org | c4e2cd0 | 2015-02-26 13:59:22 | [diff] [blame] | 165 | |
solenberg | 91c6f34 | 2016-10-25 18:19:07 | [diff] [blame] | 166 | VideoEncoderConfig::VideoEncoderConfig(VideoEncoderConfig&&) = default; |
| 167 | |
kwiberg@webrtc.org | c4e2cd0 | 2015-02-26 13:59:22 | [diff] [blame] | 168 | VideoEncoderConfig::~VideoEncoderConfig() = default; |
| 169 | |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 170 | std::string VideoEncoderConfig::ToString() const { |
| 171 | std::stringstream ss; |
perkj | 730a9e7 | 2016-10-03 06:45:26 | [diff] [blame] | 172 | ss << "{content_type: "; |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 173 | switch (content_type) { |
Erik Språng | fc398fe | 2015-04-28 08:01:41 | [diff] [blame] | 174 | case ContentType::kRealtimeVideo: |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 175 | ss << "kRealtimeVideo"; |
| 176 | break; |
Erik Språng | fc398fe | 2015-04-28 08:01:41 | [diff] [blame] | 177 | case ContentType::kScreen: |
pbos@webrtc.org | 2366875 | 2014-10-24 09:23:21 | [diff] [blame] | 178 | 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 | |
solenberg | 91c6f34 | 2016-10-25 18:19:07 | [diff] [blame] | 189 | VideoEncoderConfig::VideoEncoderConfig(const VideoEncoderConfig&) = default; |
| 190 | |
kthelgason | 4cc4a8d | 2016-09-27 10:52:02 | [diff] [blame] | 191 | void VideoEncoderConfig::EncoderSpecificSettings::FillEncoderSpecificSettings( |
| 192 | VideoCodec* codec) const { |
| 193 | if (codec->codecType == kVideoCodecH264) { |
hta | 8ee7814 | 2016-11-17 07:23:04 | [diff] [blame] | 194 | FillVideoCodecH264(codec->H264()); |
kthelgason | 4cc4a8d | 2016-09-27 10:52:02 | [diff] [blame] | 195 | } else if (codec->codecType == kVideoCodecVP8) { |
hta | 8ee7814 | 2016-11-17 07:23:04 | [diff] [blame] | 196 | FillVideoCodecVp8(codec->VP8()); |
kthelgason | 4cc4a8d | 2016-09-27 10:52:02 | [diff] [blame] | 197 | } else if (codec->codecType == kVideoCodecVP9) { |
hta | 8ee7814 | 2016-11-17 07:23:04 | [diff] [blame] | 198 | FillVideoCodecVp9(codec->VP9()); |
kthelgason | 4cc4a8d | 2016-09-27 10:52:02 | [diff] [blame] | 199 | } else { |
| 200 | RTC_NOTREACHED() << "Encoder specifics set/used for unknown codec type."; |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecH264( |
| 205 | VideoCodecH264* h264_settings) const { |
| 206 | RTC_NOTREACHED(); |
| 207 | } |
| 208 | |
| 209 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp8( |
| 210 | VideoCodecVP8* vp8_settings) const { |
| 211 | RTC_NOTREACHED(); |
| 212 | } |
| 213 | |
| 214 | void VideoEncoderConfig::EncoderSpecificSettings::FillVideoCodecVp9( |
| 215 | VideoCodecVP9* vp9_settings) const { |
| 216 | RTC_NOTREACHED(); |
| 217 | } |
| 218 | |
| 219 | VideoEncoderConfig::H264EncoderSpecificSettings::H264EncoderSpecificSettings( |
| 220 | const VideoCodecH264& specifics) |
| 221 | : specifics_(specifics) {} |
| 222 | |
| 223 | void VideoEncoderConfig::H264EncoderSpecificSettings::FillVideoCodecH264( |
| 224 | VideoCodecH264* h264_settings) const { |
| 225 | *h264_settings = specifics_; |
| 226 | } |
| 227 | |
| 228 | VideoEncoderConfig::Vp8EncoderSpecificSettings::Vp8EncoderSpecificSettings( |
| 229 | const VideoCodecVP8& specifics) |
| 230 | : specifics_(specifics) {} |
| 231 | |
| 232 | void VideoEncoderConfig::Vp8EncoderSpecificSettings::FillVideoCodecVp8( |
| 233 | VideoCodecVP8* vp8_settings) const { |
| 234 | *vp8_settings = specifics_; |
| 235 | } |
| 236 | |
| 237 | VideoEncoderConfig::Vp9EncoderSpecificSettings::Vp9EncoderSpecificSettings( |
| 238 | const VideoCodecVP9& specifics) |
| 239 | : specifics_(specifics) {} |
| 240 | |
| 241 | void VideoEncoderConfig::Vp9EncoderSpecificSettings::FillVideoCodecVp9( |
| 242 | VideoCodecVP9* vp9_settings) const { |
| 243 | *vp9_settings = specifics_; |
| 244 | } |
| 245 | |
pbos@webrtc.org | 7e68693 | 2014-05-15 09:35:06 | [diff] [blame] | 246 | } // namespace webrtc |