pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * libjingle |
| 3 | * Copyright 2014 Google Inc. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions are met: |
| 7 | * |
| 8 | * 1. Redistributions of source code must retain the above copyright notice, |
| 9 | * this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO |
| 19 | * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 20 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 21 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; |
| 22 | * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 23 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR |
| 24 | * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF |
| 25 | * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
| 28 | #ifdef HAVE_WEBRTC_VIDEO |
| 29 | #include "talk/media/webrtc/webrtcvideoengine2.h" |
| 30 | |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 31 | #include <algorithm> |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 32 | #include <set> |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 33 | #include <string> |
| 34 | |
| 35 | #include "libyuv/convert_from.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 36 | #include "talk/media/base/videocapturer.h" |
| 37 | #include "talk/media/base/videorenderer.h" |
buildbot@webrtc.org | df9bbbe | 2014-06-19 19:54:33 +0000 | [diff] [blame] | 38 | #include "talk/media/webrtc/constants.h" |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 39 | #include "talk/media/webrtc/simulcast.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 40 | #include "talk/media/webrtc/webrtcvideocapturer.h" |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 41 | #include "talk/media/webrtc/webrtcvideoengine.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 42 | #include "talk/media/webrtc/webrtcvideoframe.h" |
| 43 | #include "talk/media/webrtc/webrtcvoiceengine.h" |
buildbot@webrtc.org | a09a999 | 2014-08-13 17:26:08 +0000 | [diff] [blame] | 44 | #include "webrtc/base/buffer.h" |
| 45 | #include "webrtc/base/logging.h" |
| 46 | #include "webrtc/base/stringutils.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 47 | #include "webrtc/call.h" |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 48 | #include "webrtc/system_wrappers/interface/trace_event.h" |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 49 | #include "webrtc/video_decoder.h" |
pbos@webrtc.org | ab990ae | 2014-09-17 09:02:25 +0000 | [diff] [blame] | 50 | #include "webrtc/video_encoder.h" |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 51 | |
| 52 | #define UNIMPLEMENTED \ |
| 53 | LOG(LS_ERROR) << "Call to unimplemented function " << __FUNCTION__; \ |
| 54 | ASSERT(false) |
| 55 | |
| 56 | namespace cricket { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 57 | namespace { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 58 | static std::string CodecVectorToString(const std::vector<VideoCodec>& codecs) { |
| 59 | std::stringstream out; |
| 60 | out << '{'; |
| 61 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 62 | out << codecs[i].ToString(); |
| 63 | if (i != codecs.size() - 1) { |
| 64 | out << ", "; |
| 65 | } |
| 66 | } |
| 67 | out << '}'; |
| 68 | return out.str(); |
| 69 | } |
| 70 | |
| 71 | static bool ValidateCodecFormats(const std::vector<VideoCodec>& codecs) { |
| 72 | bool has_video = false; |
| 73 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 74 | if (!codecs[i].ValidateCodecFormat()) { |
| 75 | return false; |
| 76 | } |
| 77 | if (codecs[i].GetCodecType() == VideoCodec::CODEC_VIDEO) { |
| 78 | has_video = true; |
| 79 | } |
| 80 | } |
| 81 | if (!has_video) { |
| 82 | LOG(LS_ERROR) << "Setting codecs without a video codec is invalid: " |
| 83 | << CodecVectorToString(codecs); |
| 84 | return false; |
| 85 | } |
| 86 | return true; |
| 87 | } |
| 88 | |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 89 | static bool ValidateStreamParams(const StreamParams& sp) { |
| 90 | if (sp.ssrcs.empty()) { |
| 91 | LOG(LS_ERROR) << "No SSRCs in stream parameters: " << sp.ToString(); |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | std::vector<uint32> primary_ssrcs; |
| 96 | sp.GetPrimarySsrcs(&primary_ssrcs); |
| 97 | std::vector<uint32> rtx_ssrcs; |
| 98 | sp.GetFidSsrcs(primary_ssrcs, &rtx_ssrcs); |
| 99 | for (uint32_t rtx_ssrc : rtx_ssrcs) { |
| 100 | bool rtx_ssrc_present = false; |
| 101 | for (uint32_t sp_ssrc : sp.ssrcs) { |
| 102 | if (sp_ssrc == rtx_ssrc) { |
| 103 | rtx_ssrc_present = true; |
| 104 | break; |
| 105 | } |
| 106 | } |
| 107 | if (!rtx_ssrc_present) { |
| 108 | LOG(LS_ERROR) << "RTX SSRC '" << rtx_ssrc |
| 109 | << "' missing from StreamParams ssrcs: " << sp.ToString(); |
| 110 | return false; |
| 111 | } |
| 112 | } |
| 113 | if (!rtx_ssrcs.empty() && primary_ssrcs.size() != rtx_ssrcs.size()) { |
| 114 | LOG(LS_ERROR) |
| 115 | << "RTX SSRCs exist, but don't cover all SSRCs (unsupported): " |
| 116 | << sp.ToString(); |
| 117 | return false; |
| 118 | } |
| 119 | |
| 120 | return true; |
| 121 | } |
| 122 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 123 | static std::string RtpExtensionsToString( |
| 124 | const std::vector<RtpHeaderExtension>& extensions) { |
| 125 | std::stringstream out; |
| 126 | out << '{'; |
| 127 | for (size_t i = 0; i < extensions.size(); ++i) { |
| 128 | out << "{" << extensions[i].uri << ": " << extensions[i].id << "}"; |
| 129 | if (i != extensions.size() - 1) { |
| 130 | out << ", "; |
| 131 | } |
| 132 | } |
| 133 | out << '}'; |
| 134 | return out.str(); |
| 135 | } |
| 136 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 137 | inline const webrtc::RtpExtension* FindHeaderExtension( |
| 138 | const std::vector<webrtc::RtpExtension>& extensions, |
| 139 | const std::string& name) { |
| 140 | for (const auto& kv : extensions) { |
| 141 | if (kv.name == name) { |
| 142 | return &kv; |
| 143 | } |
| 144 | } |
| 145 | return NULL; |
| 146 | } |
| 147 | |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 148 | // Merges two fec configs and logs an error if a conflict arises |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 149 | // such that merging in different order would trigger a different output. |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 150 | static void MergeFecConfig(const webrtc::FecConfig& other, |
| 151 | webrtc::FecConfig* output) { |
| 152 | if (other.ulpfec_payload_type != -1) { |
| 153 | if (output->ulpfec_payload_type != -1 && |
| 154 | output->ulpfec_payload_type != other.ulpfec_payload_type) { |
| 155 | LOG(LS_WARNING) << "Conflict merging ulpfec_payload_type configs: " |
| 156 | << output->ulpfec_payload_type << " and " |
| 157 | << other.ulpfec_payload_type; |
| 158 | } |
| 159 | output->ulpfec_payload_type = other.ulpfec_payload_type; |
| 160 | } |
| 161 | if (other.red_payload_type != -1) { |
| 162 | if (output->red_payload_type != -1 && |
| 163 | output->red_payload_type != other.red_payload_type) { |
| 164 | LOG(LS_WARNING) << "Conflict merging red_payload_type configs: " |
| 165 | << output->red_payload_type << " and " |
| 166 | << other.red_payload_type; |
| 167 | } |
| 168 | output->red_payload_type = other.red_payload_type; |
| 169 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 170 | if (other.red_rtx_payload_type != -1) { |
| 171 | if (output->red_rtx_payload_type != -1 && |
| 172 | output->red_rtx_payload_type != other.red_rtx_payload_type) { |
| 173 | LOG(LS_WARNING) << "Conflict merging red_rtx_payload_type configs: " |
| 174 | << output->red_rtx_payload_type << " and " |
| 175 | << other.red_rtx_payload_type; |
| 176 | } |
| 177 | output->red_rtx_payload_type = other.red_rtx_payload_type; |
| 178 | } |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 179 | } |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 180 | } // namespace |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 181 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 182 | // This constant is really an on/off, lower-level configurable NACK history |
| 183 | // duration hasn't been implemented. |
| 184 | static const int kNackHistoryMs = 1000; |
| 185 | |
buildbot@webrtc.org | 933d88a | 2014-09-18 20:23:05 +0000 | [diff] [blame] | 186 | static const int kDefaultQpMax = 56; |
| 187 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 188 | static const int kDefaultRtcpReceiverReportSsrc = 1; |
| 189 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 190 | const char kH264CodecName[] = "H264"; |
| 191 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 192 | const int kMinBandwidthBps = 30000; |
| 193 | const int kStartBandwidthBps = 300000; |
| 194 | const int kMaxBandwidthBps = 2000000; |
| 195 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 196 | static bool FindFirstMatchingCodec(const std::vector<VideoCodec>& codecs, |
| 197 | const VideoCodec& requested_codec, |
| 198 | VideoCodec* matching_codec) { |
| 199 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 200 | if (requested_codec.Matches(codecs[i])) { |
| 201 | *matching_codec = codecs[i]; |
| 202 | return true; |
| 203 | } |
| 204 | } |
| 205 | return false; |
| 206 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 207 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 208 | static bool ValidateRtpHeaderExtensionIds( |
| 209 | const std::vector<RtpHeaderExtension>& extensions) { |
| 210 | std::set<int> extensions_used; |
| 211 | for (size_t i = 0; i < extensions.size(); ++i) { |
Peter Boström | 23914fe | 2015-03-31 15:08:04 +0200 | [diff] [blame] | 212 | if (extensions[i].id <= 0 || extensions[i].id >= 15 || |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 213 | !extensions_used.insert(extensions[i].id).second) { |
| 214 | LOG(LS_ERROR) << "RTP extensions are with incorrect or duplicate ids."; |
| 215 | return false; |
| 216 | } |
| 217 | } |
| 218 | return true; |
| 219 | } |
| 220 | |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 221 | static bool CompareRtpHeaderExtensionIds( |
| 222 | const webrtc::RtpExtension& extension1, |
| 223 | const webrtc::RtpExtension& extension2) { |
| 224 | // Sorting on ID is sufficient, more than one extension per ID is unsupported. |
| 225 | return extension1.id > extension2.id; |
| 226 | } |
| 227 | |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 228 | static std::vector<webrtc::RtpExtension> FilterRtpExtensions( |
| 229 | const std::vector<RtpHeaderExtension>& extensions) { |
| 230 | std::vector<webrtc::RtpExtension> webrtc_extensions; |
| 231 | for (size_t i = 0; i < extensions.size(); ++i) { |
| 232 | // Unsupported extensions will be ignored. |
| 233 | if (webrtc::RtpExtension::IsSupported(extensions[i].uri)) { |
| 234 | webrtc_extensions.push_back(webrtc::RtpExtension( |
| 235 | extensions[i].uri, extensions[i].id)); |
| 236 | } else { |
| 237 | LOG(LS_WARNING) << "Unsupported RTP extension: " << extensions[i].uri; |
| 238 | } |
| 239 | } |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 240 | |
| 241 | // Sort filtered headers to make sure that they can later be compared |
| 242 | // regardless of in which order they were entered. |
| 243 | std::sort(webrtc_extensions.begin(), webrtc_extensions.end(), |
| 244 | CompareRtpHeaderExtensionIds); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 245 | return webrtc_extensions; |
| 246 | } |
| 247 | |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 248 | static bool RtpExtensionsHaveChanged( |
| 249 | const std::vector<webrtc::RtpExtension>& before, |
| 250 | const std::vector<webrtc::RtpExtension>& after) { |
| 251 | if (before.size() != after.size()) |
| 252 | return true; |
| 253 | for (size_t i = 0; i < before.size(); ++i) { |
| 254 | if (before[i].id != after[i].id) |
| 255 | return true; |
| 256 | if (before[i].name != after[i].name) |
| 257 | return true; |
| 258 | } |
| 259 | return false; |
| 260 | } |
| 261 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 262 | std::vector<webrtc::VideoStream> |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 263 | WebRtcVideoChannel2::WebRtcVideoSendStream::CreateSimulcastVideoStreams( |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 264 | const VideoCodec& codec, |
| 265 | const VideoOptions& options, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 266 | int max_bitrate_bps, |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 267 | size_t num_streams) { |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 268 | int max_qp = kDefaultQpMax; |
| 269 | codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
| 270 | |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 271 | return GetSimulcastConfig( |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 272 | num_streams, GetSimulcastBitrateMode(options), codec.width, codec.height, |
| 273 | max_bitrate_bps, max_qp, |
buildbot@webrtc.org | a853077 | 2014-12-10 09:01:18 +0000 | [diff] [blame] | 274 | codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate); |
| 275 | } |
| 276 | |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 277 | std::vector<webrtc::VideoStream> |
| 278 | WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoStreams( |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 279 | const VideoCodec& codec, |
| 280 | const VideoOptions& options, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 281 | int max_bitrate_bps, |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 282 | size_t num_streams) { |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 283 | int codec_max_bitrate_kbps; |
| 284 | if (codec.GetParam(kCodecParamMaxBitrate, &codec_max_bitrate_kbps)) { |
| 285 | max_bitrate_bps = codec_max_bitrate_kbps * 1000; |
| 286 | } |
| 287 | if (num_streams != 1) { |
| 288 | return CreateSimulcastVideoStreams(codec, options, max_bitrate_bps, |
| 289 | num_streams); |
| 290 | } |
| 291 | |
| 292 | // For unset max bitrates set default bitrate for non-simulcast. |
| 293 | if (max_bitrate_bps <= 0) |
| 294 | max_bitrate_bps = kMaxVideoBitrate * 1000; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 295 | |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 296 | webrtc::VideoStream stream; |
| 297 | stream.width = codec.width; |
| 298 | stream.height = codec.height; |
| 299 | stream.max_framerate = |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 300 | codec.framerate != 0 ? codec.framerate : kDefaultVideoMaxFramerate; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 301 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 302 | stream.min_bitrate_bps = kMinVideoBitrate * 1000; |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 303 | stream.target_bitrate_bps = stream.max_bitrate_bps = max_bitrate_bps; |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 304 | |
buildbot@webrtc.org | 933d88a | 2014-09-18 20:23:05 +0000 | [diff] [blame] | 305 | int max_qp = kDefaultQpMax; |
buildbot@webrtc.org | d41eaeb | 2014-06-12 07:13:26 +0000 | [diff] [blame] | 306 | codec.GetParam(kCodecParamMaxQuantization, &max_qp); |
| 307 | stream.max_qp = max_qp; |
| 308 | std::vector<webrtc::VideoStream> streams; |
| 309 | streams.push_back(stream); |
| 310 | return streams; |
| 311 | } |
| 312 | |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 313 | void* WebRtcVideoChannel2::WebRtcVideoSendStream::ConfigureVideoEncoderSettings( |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 314 | const VideoCodec& codec, |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 315 | const VideoOptions& options, |
| 316 | bool is_screencast) { |
| 317 | // No automatic resizing when using simulcast. |
| 318 | bool automatic_resize = !is_screencast && ssrcs_.size() == 1; |
| 319 | bool frame_dropping = !is_screencast; |
| 320 | bool denoising; |
| 321 | if (is_screencast) { |
| 322 | denoising = false; |
| 323 | } else { |
| 324 | options.video_noise_reduction.Get(&denoising); |
| 325 | } |
| 326 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 327 | if (CodecNamesEq(codec.name, kVp8CodecName)) { |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 328 | encoder_settings_.vp8 = webrtc::VideoEncoder::GetDefaultVp8Settings(); |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 329 | encoder_settings_.vp8.automaticResizeOn = automatic_resize; |
| 330 | encoder_settings_.vp8.denoisingOn = denoising; |
| 331 | encoder_settings_.vp8.frameDroppingOn = frame_dropping; |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 332 | return &encoder_settings_.vp8; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 333 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 334 | if (CodecNamesEq(codec.name, kVp9CodecName)) { |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 335 | encoder_settings_.vp9 = webrtc::VideoEncoder::GetDefaultVp9Settings(); |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 336 | encoder_settings_.vp9.denoisingOn = denoising; |
| 337 | encoder_settings_.vp9.frameDroppingOn = frame_dropping; |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 338 | return &encoder_settings_.vp9; |
andresp@webrtc.org | 188d3b2 | 2014-11-07 13:21:04 +0000 | [diff] [blame] | 339 | } |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 340 | return NULL; |
| 341 | } |
| 342 | |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 343 | DefaultUnsignalledSsrcHandler::DefaultUnsignalledSsrcHandler() |
| 344 | : default_recv_ssrc_(0), default_renderer_(NULL) {} |
| 345 | |
| 346 | UnsignalledSsrcHandler::Action DefaultUnsignalledSsrcHandler::OnUnsignalledSsrc( |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 347 | WebRtcVideoChannel2* channel, |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 348 | uint32_t ssrc) { |
| 349 | if (default_recv_ssrc_ != 0) { // Already one default stream. |
| 350 | LOG(LS_WARNING) << "Unknown SSRC, but default receive stream already set."; |
| 351 | return kDropPacket; |
| 352 | } |
| 353 | |
| 354 | StreamParams sp; |
| 355 | sp.ssrcs.push_back(ssrc); |
| 356 | LOG(LS_INFO) << "Creating default receive stream for SSRC=" << ssrc << "."; |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 357 | if (!channel->AddRecvStream(sp, true)) { |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 358 | LOG(LS_WARNING) << "Could not create default receive stream."; |
| 359 | } |
| 360 | |
| 361 | channel->SetRenderer(ssrc, default_renderer_); |
| 362 | default_recv_ssrc_ = ssrc; |
| 363 | return kDeliverPacket; |
| 364 | } |
| 365 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 366 | WebRtcCallFactory::~WebRtcCallFactory() { |
| 367 | } |
| 368 | webrtc::Call* WebRtcCallFactory::CreateCall( |
| 369 | const webrtc::Call::Config& config) { |
| 370 | return webrtc::Call::Create(config); |
| 371 | } |
| 372 | |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 373 | VideoRenderer* DefaultUnsignalledSsrcHandler::GetDefaultRenderer() const { |
| 374 | return default_renderer_; |
| 375 | } |
| 376 | |
| 377 | void DefaultUnsignalledSsrcHandler::SetDefaultRenderer( |
| 378 | VideoMediaChannel* channel, |
| 379 | VideoRenderer* renderer) { |
| 380 | default_renderer_ = renderer; |
| 381 | if (default_recv_ssrc_ != 0) { |
| 382 | channel->SetRenderer(default_recv_ssrc_, default_renderer_); |
| 383 | } |
| 384 | } |
| 385 | |
pbos@webrtc.org | f1f0d9a | 2015-03-02 13:30:15 +0000 | [diff] [blame] | 386 | WebRtcVideoEngine2::WebRtcVideoEngine2(WebRtcVoiceEngine* voice_engine) |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 387 | : worker_thread_(NULL), |
pbos@webrtc.org | f1f0d9a | 2015-03-02 13:30:15 +0000 | [diff] [blame] | 388 | voice_engine_(voice_engine), |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 389 | initialized_(false), |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 390 | call_factory_(&default_call_factory_), |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 391 | external_decoder_factory_(NULL), |
| 392 | external_encoder_factory_(NULL) { |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 393 | LOG(LS_INFO) << "WebRtcVideoEngine2::WebRtcVideoEngine2()"; |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 394 | video_codecs_ = GetSupportedCodecs(); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 395 | rtp_header_extensions_.push_back( |
| 396 | RtpHeaderExtension(kRtpTimestampOffsetHeaderExtension, |
| 397 | kRtpTimestampOffsetHeaderExtensionDefaultId)); |
| 398 | rtp_header_extensions_.push_back( |
| 399 | RtpHeaderExtension(kRtpAbsoluteSenderTimeHeaderExtension, |
| 400 | kRtpAbsoluteSenderTimeHeaderExtensionDefaultId)); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 401 | rtp_header_extensions_.push_back( |
| 402 | RtpHeaderExtension(kRtpVideoRotationHeaderExtension, |
| 403 | kRtpVideoRotationHeaderExtensionDefaultId)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | WebRtcVideoEngine2::~WebRtcVideoEngine2() { |
| 407 | LOG(LS_INFO) << "WebRtcVideoEngine2::~WebRtcVideoEngine2"; |
| 408 | |
| 409 | if (initialized_) { |
| 410 | Terminate(); |
| 411 | } |
| 412 | } |
| 413 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 414 | void WebRtcVideoEngine2::SetCallFactory(WebRtcCallFactory* call_factory) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 415 | assert(!initialized_); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 416 | call_factory_ = call_factory; |
| 417 | } |
| 418 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 419 | bool WebRtcVideoEngine2::Init(rtc::Thread* worker_thread) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 420 | LOG(LS_INFO) << "WebRtcVideoEngine2::Init"; |
| 421 | worker_thread_ = worker_thread; |
| 422 | ASSERT(worker_thread_ != NULL); |
| 423 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 424 | initialized_ = true; |
| 425 | return true; |
| 426 | } |
| 427 | |
| 428 | void WebRtcVideoEngine2::Terminate() { |
| 429 | LOG(LS_INFO) << "WebRtcVideoEngine2::Terminate"; |
| 430 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 431 | initialized_ = false; |
| 432 | } |
| 433 | |
| 434 | int WebRtcVideoEngine2::GetCapabilities() { return VIDEO_RECV | VIDEO_SEND; } |
| 435 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 436 | bool WebRtcVideoEngine2::SetDefaultEncoderConfig( |
| 437 | const VideoEncoderConfig& config) { |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 438 | const VideoCodec& codec = config.max_codec; |
pbos@webrtc.org | 957e802 | 2014-11-10 12:36:11 +0000 | [diff] [blame] | 439 | bool supports_codec = false; |
| 440 | for (size_t i = 0; i < video_codecs_.size(); ++i) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 441 | if (CodecNamesEq(video_codecs_[i].name, codec.name)) { |
pbos@webrtc.org | 2a72c65 | 2015-02-26 16:01:24 +0000 | [diff] [blame] | 442 | video_codecs_[i].width = codec.width; |
| 443 | video_codecs_[i].height = codec.height; |
| 444 | video_codecs_[i].framerate = codec.framerate; |
pbos@webrtc.org | 957e802 | 2014-11-10 12:36:11 +0000 | [diff] [blame] | 445 | supports_codec = true; |
| 446 | break; |
| 447 | } |
| 448 | } |
| 449 | |
| 450 | if (!supports_codec) { |
| 451 | LOG(LS_ERROR) << "SetDefaultEncoderConfig, codec not supported: " |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 452 | << codec.ToString(); |
| 453 | return false; |
| 454 | } |
| 455 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 456 | return true; |
| 457 | } |
| 458 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 459 | WebRtcVideoChannel2* WebRtcVideoEngine2::CreateChannel( |
buildbot@webrtc.org | 1ecbe45 | 2014-10-14 20:29:28 +0000 | [diff] [blame] | 460 | const VideoOptions& options, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 461 | VoiceMediaChannel* voice_channel) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 462 | assert(initialized_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 463 | LOG(LS_INFO) << "CreateChannel: " |
| 464 | << (voice_channel != NULL ? "With" : "Without") |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 465 | << " voice channel. Options: " << options.ToString(); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 466 | WebRtcVideoChannel2* channel = |
| 467 | new WebRtcVideoChannel2(call_factory_, |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 468 | voice_engine_, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 469 | voice_channel, |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 470 | options, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 471 | external_encoder_factory_, |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 472 | external_decoder_factory_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 473 | if (!channel->Init()) { |
| 474 | delete channel; |
| 475 | return NULL; |
| 476 | } |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 477 | channel->SetRecvCodecs(video_codecs_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 478 | return channel; |
| 479 | } |
| 480 | |
| 481 | const std::vector<VideoCodec>& WebRtcVideoEngine2::codecs() const { |
| 482 | return video_codecs_; |
| 483 | } |
| 484 | |
| 485 | const std::vector<RtpHeaderExtension>& |
| 486 | WebRtcVideoEngine2::rtp_header_extensions() const { |
| 487 | return rtp_header_extensions_; |
| 488 | } |
| 489 | |
| 490 | void WebRtcVideoEngine2::SetLogging(int min_sev, const char* filter) { |
| 491 | // TODO(pbos): Set up logging. |
| 492 | LOG(LS_VERBOSE) << "SetLogging: " << min_sev << '"' << filter << '"'; |
| 493 | // if min_sev == -1, we keep the current log level. |
| 494 | if (min_sev < 0) { |
| 495 | assert(min_sev == -1); |
| 496 | return; |
| 497 | } |
| 498 | } |
| 499 | |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 500 | void WebRtcVideoEngine2::SetExternalDecoderFactory( |
| 501 | WebRtcVideoDecoderFactory* decoder_factory) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 502 | assert(!initialized_); |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 503 | external_decoder_factory_ = decoder_factory; |
| 504 | } |
| 505 | |
| 506 | void WebRtcVideoEngine2::SetExternalEncoderFactory( |
| 507 | WebRtcVideoEncoderFactory* encoder_factory) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 508 | assert(!initialized_); |
pbos@webrtc.org | f18fba2 | 2015-01-14 16:26:23 +0000 | [diff] [blame] | 509 | if (external_encoder_factory_ == encoder_factory) |
| 510 | return; |
| 511 | |
| 512 | // No matter what happens we shouldn't hold on to a stale |
| 513 | // WebRtcSimulcastEncoderFactory. |
| 514 | simulcast_encoder_factory_.reset(); |
| 515 | |
| 516 | if (encoder_factory && |
| 517 | WebRtcSimulcastEncoderFactory::UseSimulcastEncoderFactory( |
| 518 | encoder_factory->codecs())) { |
| 519 | simulcast_encoder_factory_.reset( |
| 520 | new WebRtcSimulcastEncoderFactory(encoder_factory)); |
| 521 | encoder_factory = simulcast_encoder_factory_.get(); |
| 522 | } |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 523 | external_encoder_factory_ = encoder_factory; |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 524 | |
| 525 | video_codecs_ = GetSupportedCodecs(); |
pbos@webrtc.org | 0a2087a | 2014-09-23 09:40:22 +0000 | [diff] [blame] | 526 | } |
| 527 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 528 | bool WebRtcVideoEngine2::EnableTimedRender() { |
| 529 | // TODO(pbos): Figure out whether this can be removed. |
| 530 | return true; |
| 531 | } |
| 532 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 533 | // Checks to see whether we comprehend and could receive a particular codec |
| 534 | bool WebRtcVideoEngine2::FindCodec(const VideoCodec& in) { |
| 535 | // TODO(pbos): Probe encoder factory to figure out that the codec is supported |
| 536 | // if supported by the encoder factory. Add a corresponding test that fails |
| 537 | // with this code (that doesn't ask the factory). |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 538 | for (size_t j = 0; j < video_codecs_.size(); ++j) { |
| 539 | VideoCodec codec(video_codecs_[j].id, video_codecs_[j].name, 0, 0, 0, 0); |
| 540 | if (codec.Matches(in)) { |
| 541 | return true; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 542 | } |
| 543 | } |
| 544 | return false; |
| 545 | } |
| 546 | |
| 547 | // Tells whether the |requested| codec can be transmitted or not. If it can be |
| 548 | // transmitted |out| is set with the best settings supported. Aspect ratio will |
| 549 | // be set as close to |current|'s as possible. If not set |requested|'s |
| 550 | // dimensions will be used for aspect ratio matching. |
| 551 | bool WebRtcVideoEngine2::CanSendCodec(const VideoCodec& requested, |
| 552 | const VideoCodec& current, |
| 553 | VideoCodec* out) { |
| 554 | assert(out != NULL); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 555 | |
| 556 | if (requested.width != requested.height && |
| 557 | (requested.height == 0 || requested.width == 0)) { |
| 558 | // 0xn and nx0 are invalid resolutions. |
| 559 | return false; |
| 560 | } |
| 561 | |
| 562 | VideoCodec matching_codec; |
| 563 | if (!FindFirstMatchingCodec(video_codecs_, requested, &matching_codec)) { |
| 564 | // Codec not supported. |
| 565 | return false; |
| 566 | } |
| 567 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 568 | out->id = requested.id; |
| 569 | out->name = requested.name; |
| 570 | out->preference = requested.preference; |
| 571 | out->params = requested.params; |
andresp@webrtc.org | ff689be | 2015-02-12 11:54:26 +0000 | [diff] [blame] | 572 | out->framerate = std::min(requested.framerate, matching_codec.framerate); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 573 | out->params = requested.params; |
| 574 | out->feedback_params = requested.feedback_params; |
pbos@webrtc.org | 8fdeee6 | 2014-07-20 14:40:23 +0000 | [diff] [blame] | 575 | out->width = requested.width; |
| 576 | out->height = requested.height; |
| 577 | if (requested.width == 0 && requested.height == 0) { |
| 578 | return true; |
| 579 | } |
| 580 | |
| 581 | while (out->width > matching_codec.width) { |
| 582 | out->width /= 2; |
| 583 | out->height /= 2; |
| 584 | } |
| 585 | |
| 586 | return out->width > 0 && out->height > 0; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 587 | } |
| 588 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 589 | // Ignore spammy trace messages, mostly from the stats API when we haven't |
| 590 | // gotten RTCP info yet from the remote side. |
| 591 | bool WebRtcVideoEngine2::ShouldIgnoreTrace(const std::string& trace) { |
| 592 | static const char* const kTracesToIgnore[] = {NULL}; |
| 593 | for (const char* const* p = kTracesToIgnore; *p; ++p) { |
| 594 | if (trace.find(*p) == 0) { |
| 595 | return true; |
| 596 | } |
| 597 | } |
| 598 | return false; |
| 599 | } |
| 600 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 601 | std::vector<VideoCodec> WebRtcVideoEngine2::GetSupportedCodecs() const { |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 602 | std::vector<VideoCodec> supported_codecs = DefaultVideoCodecList(); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 603 | |
| 604 | if (external_encoder_factory_ == NULL) { |
| 605 | return supported_codecs; |
| 606 | } |
| 607 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 608 | const std::vector<WebRtcVideoEncoderFactory::VideoCodec>& codecs = |
| 609 | external_encoder_factory_->codecs(); |
| 610 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 611 | // Don't add internally-supported codecs twice. |
| 612 | if (CodecIsInternallySupported(codecs[i].name)) { |
| 613 | continue; |
| 614 | } |
| 615 | |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 616 | // External video encoders are given payloads 120-127. This also means that |
| 617 | // we only support up to 8 external payload types. |
| 618 | const int kExternalVideoPayloadTypeBase = 120; |
| 619 | size_t payload_type = kExternalVideoPayloadTypeBase + i; |
| 620 | assert(payload_type < 128); |
| 621 | VideoCodec codec(static_cast<int>(payload_type), |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 622 | codecs[i].name, |
| 623 | codecs[i].max_width, |
| 624 | codecs[i].max_height, |
| 625 | codecs[i].max_fps, |
| 626 | 0); |
| 627 | |
| 628 | AddDefaultFeedbackParams(&codec); |
| 629 | supported_codecs.push_back(codec); |
| 630 | } |
| 631 | return supported_codecs; |
| 632 | } |
| 633 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 634 | WebRtcVideoChannel2::WebRtcVideoChannel2( |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 635 | WebRtcCallFactory* call_factory, |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 636 | WebRtcVoiceEngine* voice_engine, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 637 | VoiceMediaChannel* voice_channel, |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 638 | const VideoOptions& options, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 639 | WebRtcVideoEncoderFactory* external_encoder_factory, |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 640 | WebRtcVideoDecoderFactory* external_decoder_factory) |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 641 | : unsignalled_ssrc_handler_(&default_unsignalled_ssrc_handler_), |
pbos@webrtc.org | 8296ec5 | 2015-03-20 14:27:49 +0000 | [diff] [blame] | 642 | voice_channel_id_(voice_channel != nullptr |
| 643 | ? static_cast<WebRtcVoiceMediaChannel*>( |
| 644 | voice_channel)->voe_channel() |
| 645 | : -1), |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 646 | external_encoder_factory_(external_encoder_factory), |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 647 | external_decoder_factory_(external_decoder_factory) { |
pbos@webrtc.org | fa553ef | 2014-10-20 11:07:07 +0000 | [diff] [blame] | 648 | SetDefaultOptions(); |
| 649 | options_.SetAll(options); |
Peter Boström | e7b221f | 2015-04-13 15:34:32 +0200 | [diff] [blame] | 650 | options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 651 | webrtc::Call::Config config(this); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 652 | config.overuse_callback = this; |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 653 | if (voice_engine != NULL) { |
| 654 | config.voice_engine = voice_engine->voe()->engine(); |
| 655 | } |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 656 | config.bitrate_config.min_bitrate_bps = kMinBandwidthBps; |
| 657 | config.bitrate_config.start_bitrate_bps = kStartBandwidthBps; |
| 658 | config.bitrate_config.max_bitrate_bps = kMaxBandwidthBps; |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 659 | call_.reset(call_factory->CreateCall(config)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 660 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 661 | rtcp_receiver_report_ssrc_ = kDefaultRtcpReceiverReportSsrc; |
| 662 | sending_ = false; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 663 | default_send_ssrc_ = 0; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 664 | } |
| 665 | |
| 666 | void WebRtcVideoChannel2::SetDefaultOptions() { |
Peter Boström | e432800 | 2015-04-14 22:45:29 +0200 | [diff] [blame] | 667 | options_.cpu_overuse_detection.Set(true); |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 668 | options_.dscp.Set(false); |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 669 | options_.suspend_below_min_bitrate.Set(false); |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 670 | options_.video_noise_reduction.Set(true); |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 671 | options_.screencast_min_bitrate.Set(0); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 672 | } |
| 673 | |
| 674 | WebRtcVideoChannel2::~WebRtcVideoChannel2() { |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 675 | for (auto& kv : send_streams_) |
| 676 | delete kv.second; |
| 677 | for (auto& kv : receive_streams_) |
| 678 | delete kv.second; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | bool WebRtcVideoChannel2::Init() { return true; } |
| 682 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 683 | bool WebRtcVideoChannel2::CodecIsExternallySupported( |
| 684 | const std::string& name) const { |
| 685 | if (external_encoder_factory_ == NULL) { |
| 686 | return false; |
| 687 | } |
| 688 | |
| 689 | const std::vector<WebRtcVideoEncoderFactory::VideoCodec> external_codecs = |
| 690 | external_encoder_factory_->codecs(); |
| 691 | for (size_t c = 0; c < external_codecs.size(); ++c) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 692 | if (CodecNamesEq(name, external_codecs[c].name)) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 693 | return true; |
| 694 | } |
| 695 | } |
| 696 | return false; |
| 697 | } |
| 698 | |
| 699 | std::vector<WebRtcVideoChannel2::VideoCodecSettings> |
| 700 | WebRtcVideoChannel2::FilterSupportedCodecs( |
| 701 | const std::vector<WebRtcVideoChannel2::VideoCodecSettings>& mapped_codecs) |
| 702 | const { |
| 703 | std::vector<VideoCodecSettings> supported_codecs; |
| 704 | for (size_t i = 0; i < mapped_codecs.size(); ++i) { |
| 705 | const VideoCodecSettings& codec = mapped_codecs[i]; |
| 706 | if (CodecIsInternallySupported(codec.codec.name) || |
| 707 | CodecIsExternallySupported(codec.codec.name)) { |
| 708 | supported_codecs.push_back(codec); |
| 709 | } |
| 710 | } |
| 711 | return supported_codecs; |
| 712 | } |
| 713 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 714 | bool WebRtcVideoChannel2::SetRecvCodecs(const std::vector<VideoCodec>& codecs) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 715 | TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvCodecs"); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 716 | LOG(LS_INFO) << "SetRecvCodecs: " << CodecVectorToString(codecs); |
| 717 | if (!ValidateCodecFormats(codecs)) { |
| 718 | return false; |
| 719 | } |
| 720 | |
| 721 | const std::vector<VideoCodecSettings> mapped_codecs = MapCodecs(codecs); |
| 722 | if (mapped_codecs.empty()) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 723 | LOG(LS_ERROR) << "SetRecvCodecs called without any video codecs."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 724 | return false; |
| 725 | } |
| 726 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 727 | const std::vector<VideoCodecSettings> supported_codecs = |
| 728 | FilterSupportedCodecs(mapped_codecs); |
| 729 | |
| 730 | if (mapped_codecs.size() != supported_codecs.size()) { |
| 731 | LOG(LS_ERROR) << "SetRecvCodecs called with unsupported video codecs."; |
| 732 | return false; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Peter Boström | ee0b00e | 2015-04-22 18:41:14 +0200 | [diff] [blame] | 735 | // Prevent reconfiguration when setting identical receive codecs. |
| 736 | if (recv_codecs_.size() == supported_codecs.size()) { |
| 737 | bool reconfigured = false; |
| 738 | for (size_t i = 0; i < supported_codecs.size(); ++i) { |
| 739 | if (recv_codecs_[i] != supported_codecs[i]) { |
| 740 | reconfigured = true; |
| 741 | break; |
| 742 | } |
| 743 | } |
| 744 | if (!reconfigured) |
| 745 | return true; |
| 746 | } |
| 747 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 748 | recv_codecs_ = supported_codecs; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 749 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 750 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 751 | for (std::map<uint32, WebRtcVideoReceiveStream*>::iterator it = |
| 752 | receive_streams_.begin(); |
| 753 | it != receive_streams_.end(); |
| 754 | ++it) { |
| 755 | it->second->SetRecvCodecs(recv_codecs_); |
| 756 | } |
| 757 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 758 | return true; |
| 759 | } |
| 760 | |
| 761 | bool WebRtcVideoChannel2::SetSendCodecs(const std::vector<VideoCodec>& codecs) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 762 | TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendCodecs"); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 763 | LOG(LS_INFO) << "SetSendCodecs: " << CodecVectorToString(codecs); |
| 764 | if (!ValidateCodecFormats(codecs)) { |
| 765 | return false; |
| 766 | } |
| 767 | |
| 768 | const std::vector<VideoCodecSettings> supported_codecs = |
| 769 | FilterSupportedCodecs(MapCodecs(codecs)); |
| 770 | |
| 771 | if (supported_codecs.empty()) { |
Peter Boström | 3c3f646 | 2015-04-15 16:27:49 +0200 | [diff] [blame] | 772 | LOG(LS_ERROR) << "No video codecs supported."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 773 | return false; |
| 774 | } |
| 775 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 776 | LOG(LS_INFO) << "Using codec: " << supported_codecs.front().codec.ToString(); |
| 777 | |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 778 | VideoCodecSettings old_codec; |
| 779 | if (send_codec_.Get(&old_codec) && supported_codecs.front() == old_codec) { |
| 780 | // Using same codec, avoid reconfiguring. |
| 781 | return true; |
| 782 | } |
| 783 | |
| 784 | send_codec_.Set(supported_codecs.front()); |
| 785 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 786 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 787 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 788 | send_streams_.begin(); |
| 789 | it != send_streams_.end(); |
| 790 | ++it) { |
| 791 | assert(it->second != NULL); |
| 792 | it->second->SetCodec(supported_codecs.front()); |
| 793 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 794 | |
Stefan Holmer | e590416 | 2015-03-26 11:11:06 +0100 | [diff] [blame] | 795 | // TODO(holmer): Changing the codec parameters shouldn't necessarily mean that |
| 796 | // we change the min/max of bandwidth estimation. Reevaluate this. |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 797 | VideoCodec codec = supported_codecs.front().codec; |
| 798 | int bitrate_kbps; |
| 799 | if (codec.GetParam(kCodecParamMinBitrate, &bitrate_kbps) && |
| 800 | bitrate_kbps > 0) { |
| 801 | bitrate_config_.min_bitrate_bps = bitrate_kbps * 1000; |
| 802 | } else { |
| 803 | bitrate_config_.min_bitrate_bps = 0; |
| 804 | } |
| 805 | if (codec.GetParam(kCodecParamStartBitrate, &bitrate_kbps) && |
| 806 | bitrate_kbps > 0) { |
| 807 | bitrate_config_.start_bitrate_bps = bitrate_kbps * 1000; |
| 808 | } else { |
| 809 | // Do not reconfigure start bitrate unless it's specified and positive. |
| 810 | bitrate_config_.start_bitrate_bps = -1; |
| 811 | } |
| 812 | if (codec.GetParam(kCodecParamMaxBitrate, &bitrate_kbps) && |
| 813 | bitrate_kbps > 0) { |
| 814 | bitrate_config_.max_bitrate_bps = bitrate_kbps * 1000; |
| 815 | } else { |
| 816 | bitrate_config_.max_bitrate_bps = -1; |
| 817 | } |
| 818 | call_->SetBitrateConfig(bitrate_config_); |
| 819 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 820 | return true; |
| 821 | } |
| 822 | |
| 823 | bool WebRtcVideoChannel2::GetSendCodec(VideoCodec* codec) { |
| 824 | VideoCodecSettings codec_settings; |
| 825 | if (!send_codec_.Get(&codec_settings)) { |
| 826 | LOG(LS_VERBOSE) << "GetSendCodec: No send codec set."; |
| 827 | return false; |
| 828 | } |
| 829 | *codec = codec_settings.codec; |
| 830 | return true; |
| 831 | } |
| 832 | |
| 833 | bool WebRtcVideoChannel2::SetSendStreamFormat(uint32 ssrc, |
| 834 | const VideoFormat& format) { |
| 835 | LOG(LS_VERBOSE) << "SetSendStreamFormat:" << ssrc << " -> " |
| 836 | << format.ToString(); |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 837 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 838 | if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 839 | return false; |
| 840 | } |
| 841 | return send_streams_[ssrc]->SetVideoFormat(format); |
| 842 | } |
| 843 | |
| 844 | bool WebRtcVideoChannel2::SetRender(bool render) { |
| 845 | // TODO(pbos): Implement. Or refactor away as it shouldn't be needed. |
| 846 | LOG(LS_VERBOSE) << "SetRender: " << (render ? "true" : "false"); |
| 847 | return true; |
| 848 | } |
| 849 | |
| 850 | bool WebRtcVideoChannel2::SetSend(bool send) { |
| 851 | LOG(LS_VERBOSE) << "SetSend: " << (send ? "true" : "false"); |
| 852 | if (send && !send_codec_.IsSet()) { |
| 853 | LOG(LS_ERROR) << "SetSend(true) called before setting codec."; |
| 854 | return false; |
| 855 | } |
| 856 | if (send) { |
| 857 | StartAllSendStreams(); |
| 858 | } else { |
| 859 | StopAllSendStreams(); |
| 860 | } |
| 861 | sending_ = send; |
| 862 | return true; |
| 863 | } |
| 864 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 865 | bool WebRtcVideoChannel2::ValidateSendSsrcAvailability( |
| 866 | const StreamParams& sp) const { |
| 867 | for (uint32_t ssrc: sp.ssrcs) { |
| 868 | if (send_ssrcs_.find(ssrc) != send_ssrcs_.end()) { |
| 869 | LOG(LS_ERROR) << "Send stream with SSRC '" << ssrc << "' already exists."; |
| 870 | return false; |
| 871 | } |
| 872 | } |
| 873 | return true; |
| 874 | } |
| 875 | |
| 876 | bool WebRtcVideoChannel2::ValidateReceiveSsrcAvailability( |
| 877 | const StreamParams& sp) const { |
| 878 | for (uint32_t ssrc: sp.ssrcs) { |
| 879 | if (receive_ssrcs_.find(ssrc) != receive_ssrcs_.end()) { |
| 880 | LOG(LS_ERROR) << "Receive stream with SSRC '" << ssrc |
| 881 | << "' already exists."; |
| 882 | return false; |
| 883 | } |
| 884 | } |
| 885 | return true; |
| 886 | } |
| 887 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 888 | bool WebRtcVideoChannel2::AddSendStream(const StreamParams& sp) { |
| 889 | LOG(LS_INFO) << "AddSendStream: " << sp.ToString(); |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 890 | if (!ValidateStreamParams(sp)) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 891 | return false; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 892 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 893 | rtc::CritScope stream_lock(&stream_crit_); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 894 | |
| 895 | if (!ValidateSendSsrcAvailability(sp)) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 896 | return false; |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 897 | |
| 898 | for (uint32 used_ssrc : sp.ssrcs) |
| 899 | send_ssrcs_.insert(used_ssrc); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 900 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 901 | WebRtcVideoSendStream* stream = |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 902 | new WebRtcVideoSendStream(call_.get(), |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 903 | external_encoder_factory_, |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 904 | options_, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 905 | bitrate_config_.max_bitrate_bps, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 906 | send_codec_, |
| 907 | sp, |
| 908 | send_rtp_extensions_); |
| 909 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 910 | uint32 ssrc = sp.first_ssrc(); |
| 911 | assert(ssrc != 0); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 912 | send_streams_[ssrc] = stream; |
| 913 | |
| 914 | if (rtcp_receiver_report_ssrc_ == kDefaultRtcpReceiverReportSsrc) { |
| 915 | rtcp_receiver_report_ssrc_ = ssrc; |
| 916 | } |
| 917 | if (default_send_ssrc_ == 0) { |
| 918 | default_send_ssrc_ = ssrc; |
| 919 | } |
| 920 | if (sending_) { |
| 921 | stream->Start(); |
| 922 | } |
| 923 | |
| 924 | return true; |
| 925 | } |
| 926 | |
| 927 | bool WebRtcVideoChannel2::RemoveSendStream(uint32 ssrc) { |
| 928 | LOG(LS_INFO) << "RemoveSendStream: " << ssrc; |
| 929 | |
| 930 | if (ssrc == 0) { |
| 931 | if (default_send_ssrc_ == 0) { |
| 932 | LOG(LS_ERROR) << "No default send stream active."; |
| 933 | return false; |
| 934 | } |
| 935 | |
| 936 | LOG(LS_VERBOSE) << "Removing default stream: " << default_send_ssrc_; |
| 937 | ssrc = default_send_ssrc_; |
| 938 | } |
| 939 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 940 | WebRtcVideoSendStream* removed_stream; |
| 941 | { |
| 942 | rtc::CritScope stream_lock(&stream_crit_); |
| 943 | std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 944 | send_streams_.find(ssrc); |
| 945 | if (it == send_streams_.end()) { |
| 946 | return false; |
| 947 | } |
| 948 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 949 | for (uint32 old_ssrc : it->second->GetSsrcs()) |
| 950 | send_ssrcs_.erase(old_ssrc); |
| 951 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 952 | removed_stream = it->second; |
| 953 | send_streams_.erase(it); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 954 | } |
| 955 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 956 | delete removed_stream; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 957 | |
| 958 | if (ssrc == default_send_ssrc_) { |
| 959 | default_send_ssrc_ = 0; |
| 960 | } |
| 961 | |
| 962 | return true; |
| 963 | } |
| 964 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 965 | void WebRtcVideoChannel2::DeleteReceiveStream( |
| 966 | WebRtcVideoChannel2::WebRtcVideoReceiveStream* stream) { |
| 967 | for (uint32 old_ssrc : stream->GetSsrcs()) |
| 968 | receive_ssrcs_.erase(old_ssrc); |
| 969 | delete stream; |
| 970 | } |
| 971 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 972 | bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp) { |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 973 | return AddRecvStream(sp, false); |
| 974 | } |
| 975 | |
| 976 | bool WebRtcVideoChannel2::AddRecvStream(const StreamParams& sp, |
| 977 | bool default_stream) { |
Peter Boström | d4362cd | 2015-03-25 14:17:23 +0100 | [diff] [blame] | 978 | LOG(LS_INFO) << "AddRecvStream" << (default_stream ? " (default stream)" : "") |
| 979 | << ": " << sp.ToString(); |
| 980 | if (!ValidateStreamParams(sp)) |
| 981 | return false; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 982 | |
| 983 | uint32 ssrc = sp.first_ssrc(); |
| 984 | assert(ssrc != 0); // TODO(pbos): Is this ever valid? |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 985 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 986 | rtc::CritScope stream_lock(&stream_crit_); |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 987 | // Remove running stream if this was a default stream. |
| 988 | auto prev_stream = receive_streams_.find(ssrc); |
| 989 | if (prev_stream != receive_streams_.end()) { |
| 990 | if (default_stream || !prev_stream->second->IsDefaultStream()) { |
| 991 | LOG(LS_ERROR) << "Receive stream for SSRC '" << ssrc |
| 992 | << "' already exists."; |
| 993 | return false; |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 994 | } |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 995 | DeleteReceiveStream(prev_stream->second); |
| 996 | receive_streams_.erase(prev_stream); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 997 | } |
| 998 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 999 | if (!ValidateReceiveSsrcAvailability(sp)) |
| 1000 | return false; |
| 1001 | |
| 1002 | for (uint32 used_ssrc : sp.ssrcs) |
| 1003 | receive_ssrcs_.insert(used_ssrc); |
| 1004 | |
pbos@webrtc.org | bd249bc | 2014-07-07 04:45:15 +0000 | [diff] [blame] | 1005 | webrtc::VideoReceiveStream::Config config; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1006 | ConfigureReceiverRtp(&config, sp); |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 1007 | |
| 1008 | // Set up A/V sync if there is a VoiceChannel. |
| 1009 | // TODO(pbos): The A/V is synched by the receiving channel. So we need to know |
| 1010 | // the SSRC of the remote audio channel in order to sync the correct webrtc |
| 1011 | // VoiceEngine channel. For now sync the first channel in non-conference to |
| 1012 | // match existing behavior in WebRtcVideoEngine. |
pbos@webrtc.org | 8296ec5 | 2015-03-20 14:27:49 +0000 | [diff] [blame] | 1013 | if (voice_channel_id_ != -1 && receive_streams_.empty() && |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 1014 | !options_.conference_mode.GetWithDefaultIfUnset(false)) { |
pbos@webrtc.org | 8296ec5 | 2015-03-20 14:27:49 +0000 | [diff] [blame] | 1015 | config.audio_channel_id = voice_channel_id_; |
pbos@webrtc.org | 3bf3d23 | 2014-10-31 12:59:34 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 1018 | receive_streams_[ssrc] = new WebRtcVideoReceiveStream( |
| 1019 | call_.get(), sp.ssrcs, external_decoder_factory_, default_stream, config, |
| 1020 | recv_codecs_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1021 | |
| 1022 | return true; |
| 1023 | } |
| 1024 | |
| 1025 | void WebRtcVideoChannel2::ConfigureReceiverRtp( |
| 1026 | webrtc::VideoReceiveStream::Config* config, |
| 1027 | const StreamParams& sp) const { |
| 1028 | uint32 ssrc = sp.first_ssrc(); |
| 1029 | |
| 1030 | config->rtp.remote_ssrc = ssrc; |
| 1031 | config->rtp.local_ssrc = rtcp_receiver_report_ssrc_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1032 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1033 | config->rtp.extensions = recv_rtp_extensions_; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 1034 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1035 | // TODO(pbos): This protection is against setting the same local ssrc as |
| 1036 | // remote which is not permitted by the lower-level API. RTCP requires a |
| 1037 | // corresponding sender SSRC. Figure out what to do when we don't have |
| 1038 | // (receive-only) or know a good local SSRC. |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1039 | if (config->rtp.remote_ssrc == config->rtp.local_ssrc) { |
| 1040 | if (config->rtp.local_ssrc != kDefaultRtcpReceiverReportSsrc) { |
| 1041 | config->rtp.local_ssrc = kDefaultRtcpReceiverReportSsrc; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1042 | } else { |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1043 | config->rtp.local_ssrc = kDefaultRtcpReceiverReportSsrc + 1; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1044 | } |
| 1045 | } |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1046 | |
| 1047 | for (size_t i = 0; i < recv_codecs_.size(); ++i) { |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 1048 | MergeFecConfig(recv_codecs_[i].fec, &config->rtp.fec); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1049 | } |
| 1050 | |
andresp@webrtc.org | 82775b1 | 2014-11-07 09:37:54 +0000 | [diff] [blame] | 1051 | for (size_t i = 0; i < recv_codecs_.size(); ++i) { |
| 1052 | uint32 rtx_ssrc; |
| 1053 | if (recv_codecs_[i].rtx_payload_type != -1 && |
| 1054 | sp.GetFidSsrc(ssrc, &rtx_ssrc)) { |
| 1055 | webrtc::VideoReceiveStream::Config::Rtp::Rtx& rtx = |
| 1056 | config->rtp.rtx[recv_codecs_[i].codec.id]; |
| 1057 | rtx.ssrc = rtx_ssrc; |
| 1058 | rtx.payload_type = recv_codecs_[i].rtx_payload_type; |
| 1059 | } |
| 1060 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
| 1063 | bool WebRtcVideoChannel2::RemoveRecvStream(uint32 ssrc) { |
| 1064 | LOG(LS_INFO) << "RemoveRecvStream: " << ssrc; |
| 1065 | if (ssrc == 0) { |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 1066 | LOG(LS_ERROR) << "RemoveRecvStream with 0 ssrc is not supported."; |
| 1067 | return false; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1070 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1071 | std::map<uint32, WebRtcVideoReceiveStream*>::iterator stream = |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1072 | receive_streams_.find(ssrc); |
| 1073 | if (stream == receive_streams_.end()) { |
| 1074 | LOG(LS_ERROR) << "Stream not found for ssrc: " << ssrc; |
| 1075 | return false; |
| 1076 | } |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 1077 | DeleteReceiveStream(stream->second); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1078 | receive_streams_.erase(stream); |
| 1079 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1080 | return true; |
| 1081 | } |
| 1082 | |
| 1083 | bool WebRtcVideoChannel2::SetRenderer(uint32 ssrc, VideoRenderer* renderer) { |
| 1084 | LOG(LS_INFO) << "SetRenderer: ssrc:" << ssrc << " " |
| 1085 | << (renderer ? "(ptr)" : "NULL"); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1086 | if (ssrc == 0) { |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 1087 | default_unsignalled_ssrc_handler_.SetDefaultRenderer(this, renderer); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1088 | return true; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1089 | } |
| 1090 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1091 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1092 | std::map<uint32, WebRtcVideoReceiveStream*>::iterator it = |
| 1093 | receive_streams_.find(ssrc); |
| 1094 | if (it == receive_streams_.end()) { |
| 1095 | return false; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | it->second->SetRenderer(renderer); |
| 1099 | return true; |
| 1100 | } |
| 1101 | |
| 1102 | bool WebRtcVideoChannel2::GetRenderer(uint32 ssrc, VideoRenderer** renderer) { |
| 1103 | if (ssrc == 0) { |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 1104 | *renderer = default_unsignalled_ssrc_handler_.GetDefaultRenderer(); |
| 1105 | return *renderer != NULL; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1106 | } |
| 1107 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1108 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1109 | std::map<uint32, WebRtcVideoReceiveStream*>::iterator it = |
| 1110 | receive_streams_.find(ssrc); |
| 1111 | if (it == receive_streams_.end()) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1112 | return false; |
| 1113 | } |
| 1114 | *renderer = it->second->GetRenderer(); |
| 1115 | return true; |
| 1116 | } |
| 1117 | |
pbos@webrtc.org | 058b1f1 | 2015-03-04 08:54:32 +0000 | [diff] [blame] | 1118 | bool WebRtcVideoChannel2::GetStats(VideoMediaInfo* info) { |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1119 | info->Clear(); |
| 1120 | FillSenderStats(info); |
| 1121 | FillReceiverStats(info); |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 1122 | webrtc::Call::Stats stats = call_->GetStats(); |
| 1123 | FillBandwidthEstimationStats(stats, info); |
| 1124 | if (stats.rtt_ms != -1) { |
| 1125 | for (size_t i = 0; i < info->senders.size(); ++i) { |
| 1126 | info->senders[i].rtt_ms = stats.rtt_ms; |
| 1127 | } |
| 1128 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1129 | return true; |
| 1130 | } |
| 1131 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1132 | void WebRtcVideoChannel2::FillSenderStats(VideoMediaInfo* video_media_info) { |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1133 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1134 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 1135 | send_streams_.begin(); |
| 1136 | it != send_streams_.end(); |
| 1137 | ++it) { |
| 1138 | video_media_info->senders.push_back(it->second->GetVideoSenderInfo()); |
| 1139 | } |
| 1140 | } |
| 1141 | |
| 1142 | void WebRtcVideoChannel2::FillReceiverStats(VideoMediaInfo* video_media_info) { |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1143 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1144 | for (std::map<uint32, WebRtcVideoReceiveStream*>::iterator it = |
| 1145 | receive_streams_.begin(); |
| 1146 | it != receive_streams_.end(); |
| 1147 | ++it) { |
| 1148 | video_media_info->receivers.push_back(it->second->GetVideoReceiverInfo()); |
| 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | void WebRtcVideoChannel2::FillBandwidthEstimationStats( |
pbos@webrtc.org | 2b19f06 | 2014-12-11 13:26:09 +0000 | [diff] [blame] | 1153 | const webrtc::Call::Stats& stats, |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1154 | VideoMediaInfo* video_media_info) { |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1155 | BandwidthEstimationInfo bwe_info; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1156 | bwe_info.available_send_bandwidth = stats.send_bandwidth_bps; |
| 1157 | bwe_info.available_recv_bandwidth = stats.recv_bandwidth_bps; |
| 1158 | bwe_info.bucket_delay = stats.pacer_delay_ms; |
| 1159 | |
| 1160 | // Get send stream bitrate stats. |
| 1161 | rtc::CritScope stream_lock(&stream_crit_); |
| 1162 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator stream = |
| 1163 | send_streams_.begin(); |
| 1164 | stream != send_streams_.end(); |
| 1165 | ++stream) { |
| 1166 | stream->second->FillBandwidthEstimationInfo(&bwe_info); |
| 1167 | } |
| 1168 | video_media_info->bw_estimations.push_back(bwe_info); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1169 | } |
| 1170 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1171 | bool WebRtcVideoChannel2::SetCapturer(uint32 ssrc, VideoCapturer* capturer) { |
| 1172 | LOG(LS_INFO) << "SetCapturer: " << ssrc << " -> " |
| 1173 | << (capturer != NULL ? "(capturer)" : "NULL"); |
| 1174 | assert(ssrc != 0); |
Peter Boström | e7b221f | 2015-04-13 15:34:32 +0200 | [diff] [blame] | 1175 | { |
| 1176 | rtc::CritScope stream_lock(&stream_crit_); |
| 1177 | if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 1178 | LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
| 1179 | return false; |
| 1180 | } |
| 1181 | if (!send_streams_[ssrc]->SetCapturer(capturer)) { |
| 1182 | return false; |
| 1183 | } |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | if (capturer) { |
| 1187 | capturer->SetApplyRotation( |
| 1188 | !FindHeaderExtension(send_rtp_extensions_, |
| 1189 | kRtpVideoRotationHeaderExtension)); |
| 1190 | } |
Peter Boström | e7b221f | 2015-04-13 15:34:32 +0200 | [diff] [blame] | 1191 | { |
| 1192 | rtc::CritScope lock(&capturer_crit_); |
| 1193 | capturers_[ssrc] = capturer; |
| 1194 | } |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 1195 | return true; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | bool WebRtcVideoChannel2::SendIntraFrame() { |
| 1199 | // TODO(pbos): Implement. |
| 1200 | LOG(LS_VERBOSE) << "SendIntraFrame()."; |
| 1201 | return true; |
| 1202 | } |
| 1203 | |
| 1204 | bool WebRtcVideoChannel2::RequestIntraFrame() { |
| 1205 | // TODO(pbos): Implement. |
| 1206 | LOG(LS_VERBOSE) << "SendIntraFrame()."; |
| 1207 | return true; |
| 1208 | } |
| 1209 | |
| 1210 | void WebRtcVideoChannel2::OnPacketReceived( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1211 | rtc::Buffer* packet, |
| 1212 | const rtc::PacketTime& packet_time) { |
pbos@webrtc.org | 4e545cc | 2014-05-14 13:58:13 +0000 | [diff] [blame] | 1213 | const webrtc::PacketReceiver::DeliveryStatus delivery_result = |
| 1214 | call_->Receiver()->DeliverPacket( |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 1215 | reinterpret_cast<const uint8_t*>(packet->data()), packet->size()); |
pbos@webrtc.org | 4e545cc | 2014-05-14 13:58:13 +0000 | [diff] [blame] | 1216 | switch (delivery_result) { |
| 1217 | case webrtc::PacketReceiver::DELIVERY_OK: |
| 1218 | return; |
| 1219 | case webrtc::PacketReceiver::DELIVERY_PACKET_ERROR: |
| 1220 | return; |
| 1221 | case webrtc::PacketReceiver::DELIVERY_UNKNOWN_SSRC: |
| 1222 | break; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1223 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1224 | |
| 1225 | uint32 ssrc = 0; |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 1226 | if (!GetRtpSsrc(packet->data(), packet->size(), &ssrc)) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1227 | return; |
| 1228 | } |
| 1229 | |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 1230 | // TODO(pbos): Ignore unsignalled packets that don't use the video payload |
| 1231 | // (prevent creating default receivers for RTX configured as if it would |
| 1232 | // receive media payloads on those SSRCs). |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 1233 | switch (unsignalled_ssrc_handler_->OnUnsignalledSsrc(this, ssrc)) { |
| 1234 | case UnsignalledSsrcHandler::kDropPacket: |
| 1235 | return; |
| 1236 | case UnsignalledSsrcHandler::kDeliverPacket: |
| 1237 | break; |
| 1238 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1239 | |
pbos@webrtc.org | 1e019d1 | 2014-05-16 11:38:45 +0000 | [diff] [blame] | 1240 | if (call_->Receiver()->DeliverPacket( |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 1241 | reinterpret_cast<const uint8_t*>(packet->data()), packet->size()) != |
pbos@webrtc.org | 1e019d1 | 2014-05-16 11:38:45 +0000 | [diff] [blame] | 1242 | webrtc::PacketReceiver::DELIVERY_OK) { |
pbos@webrtc.org | afb554f4 | 2014-08-12 23:17:13 +0000 | [diff] [blame] | 1243 | LOG(LS_WARNING) << "Failed to deliver RTP packet on re-delivery."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1244 | return; |
| 1245 | } |
| 1246 | } |
| 1247 | |
| 1248 | void WebRtcVideoChannel2::OnRtcpReceived( |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1249 | rtc::Buffer* packet, |
| 1250 | const rtc::PacketTime& packet_time) { |
pbos@webrtc.org | 1e019d1 | 2014-05-16 11:38:45 +0000 | [diff] [blame] | 1251 | if (call_->Receiver()->DeliverPacket( |
kwiberg@webrtc.org | eebcab5 | 2015-03-24 09:19:06 +0000 | [diff] [blame] | 1252 | reinterpret_cast<const uint8_t*>(packet->data()), packet->size()) != |
pbos@webrtc.org | 1e019d1 | 2014-05-16 11:38:45 +0000 | [diff] [blame] | 1253 | webrtc::PacketReceiver::DELIVERY_OK) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1254 | LOG(LS_WARNING) << "Failed to deliver RTCP packet."; |
| 1255 | } |
| 1256 | } |
| 1257 | |
| 1258 | void WebRtcVideoChannel2::OnReadyToSend(bool ready) { |
pbos@webrtc.org | 26c0c41 | 2014-09-03 16:17:12 +0000 | [diff] [blame] | 1259 | LOG(LS_VERBOSE) << "OnReadyToSend: " << (ready ? "Ready." : "Not ready."); |
| 1260 | call_->SignalNetworkState(ready ? webrtc::Call::kNetworkUp |
| 1261 | : webrtc::Call::kNetworkDown); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | bool WebRtcVideoChannel2::MuteStream(uint32 ssrc, bool mute) { |
| 1265 | LOG(LS_VERBOSE) << "MuteStream: " << ssrc << " -> " |
| 1266 | << (mute ? "mute" : "unmute"); |
| 1267 | assert(ssrc != 0); |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1268 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1269 | if (send_streams_.find(ssrc) == send_streams_.end()) { |
| 1270 | LOG(LS_ERROR) << "No sending stream on ssrc " << ssrc; |
| 1271 | return false; |
| 1272 | } |
pbos@webrtc.org | ef8bb8d | 2014-08-13 21:36:18 +0000 | [diff] [blame] | 1273 | |
| 1274 | send_streams_[ssrc]->MuteStream(mute); |
| 1275 | return true; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | bool WebRtcVideoChannel2::SetRecvRtpHeaderExtensions( |
| 1279 | const std::vector<RtpHeaderExtension>& extensions) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 1280 | TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetRecvRtpHeaderExtensions"); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 1281 | LOG(LS_INFO) << "SetRecvRtpHeaderExtensions: " |
| 1282 | << RtpExtensionsToString(extensions); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1283 | if (!ValidateRtpHeaderExtensionIds(extensions)) |
| 1284 | return false; |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1285 | |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 1286 | std::vector<webrtc::RtpExtension> filtered_extensions = |
| 1287 | FilterRtpExtensions(extensions); |
| 1288 | if (!RtpExtensionsHaveChanged(recv_rtp_extensions_, filtered_extensions)) |
| 1289 | return true; |
| 1290 | |
| 1291 | recv_rtp_extensions_ = filtered_extensions; |
| 1292 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1293 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1294 | for (std::map<uint32, WebRtcVideoReceiveStream*>::iterator it = |
| 1295 | receive_streams_.begin(); |
| 1296 | it != receive_streams_.end(); |
| 1297 | ++it) { |
| 1298 | it->second->SetRtpExtensions(recv_rtp_extensions_); |
| 1299 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1300 | return true; |
| 1301 | } |
| 1302 | |
| 1303 | bool WebRtcVideoChannel2::SetSendRtpHeaderExtensions( |
| 1304 | const std::vector<RtpHeaderExtension>& extensions) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 1305 | TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetSendRtpHeaderExtensions"); |
pbos@webrtc.org | 587ef60 | 2014-06-16 17:32:02 +0000 | [diff] [blame] | 1306 | LOG(LS_INFO) << "SetSendRtpHeaderExtensions: " |
| 1307 | << RtpExtensionsToString(extensions); |
pbos@webrtc.org | 3c10758 | 2014-07-20 15:27:35 +0000 | [diff] [blame] | 1308 | if (!ValidateRtpHeaderExtensionIds(extensions)) |
| 1309 | return false; |
| 1310 | |
pbos@webrtc.org | c37e72e | 2015-01-05 18:51:13 +0000 | [diff] [blame] | 1311 | std::vector<webrtc::RtpExtension> filtered_extensions = |
| 1312 | FilterRtpExtensions(extensions); |
| 1313 | if (!RtpExtensionsHaveChanged(send_rtp_extensions_, filtered_extensions)) |
| 1314 | return true; |
| 1315 | |
| 1316 | send_rtp_extensions_ = filtered_extensions; |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1317 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 1318 | const webrtc::RtpExtension* cvo_extension = FindHeaderExtension( |
| 1319 | send_rtp_extensions_, kRtpVideoRotationHeaderExtension); |
| 1320 | |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1321 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1322 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 1323 | send_streams_.begin(); |
| 1324 | it != send_streams_.end(); |
| 1325 | ++it) { |
| 1326 | it->second->SetRtpExtensions(send_rtp_extensions_); |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 1327 | it->second->SetApplyRotation(!cvo_extension); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1328 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1329 | return true; |
| 1330 | } |
| 1331 | |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1332 | // Counter-intuitively this method doesn't only set global bitrate caps but also |
| 1333 | // per-stream codec max bitrates. This is to permit SetMaxSendBitrate (b=AS) to |
| 1334 | // raise bitrates above the 2000k default bitrate cap. |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 1335 | bool WebRtcVideoChannel2::SetMaxSendBandwidth(int max_bitrate_bps) { |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1336 | // TODO(pbos): Figure out whether b=AS means max bitrate for this |
| 1337 | // WebRtcVideoChannel2 (in which case we're good), or per sender (SSRC), in |
| 1338 | // which case this should not set a Call::BitrateConfig but rather reconfigure |
| 1339 | // all senders. |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 1340 | LOG(LS_INFO) << "SetMaxSendBandwidth: " << max_bitrate_bps << "bps."; |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1341 | if (max_bitrate_bps == bitrate_config_.max_bitrate_bps) |
| 1342 | return true; |
| 1343 | |
pbos@webrtc.org | 0087318 | 2014-11-25 14:03:34 +0000 | [diff] [blame] | 1344 | if (max_bitrate_bps <= 0) { |
| 1345 | // Unsetting max bitrate. |
| 1346 | max_bitrate_bps = -1; |
| 1347 | } |
| 1348 | bitrate_config_.start_bitrate_bps = -1; |
| 1349 | bitrate_config_.max_bitrate_bps = max_bitrate_bps; |
| 1350 | if (max_bitrate_bps > 0 && |
| 1351 | bitrate_config_.min_bitrate_bps > max_bitrate_bps) { |
| 1352 | bitrate_config_.min_bitrate_bps = max_bitrate_bps; |
| 1353 | } |
| 1354 | call_->SetBitrateConfig(bitrate_config_); |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1355 | rtc::CritScope stream_lock(&stream_crit_); |
| 1356 | for (auto& kv : send_streams_) |
| 1357 | kv.second->SetMaxBitrateBps(max_bitrate_bps); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1358 | return true; |
| 1359 | } |
| 1360 | |
| 1361 | bool WebRtcVideoChannel2::SetOptions(const VideoOptions& options) { |
pbos@webrtc.org | 50fe359 | 2015-01-29 12:33:07 +0000 | [diff] [blame] | 1362 | TRACE_EVENT0("webrtc", "WebRtcVideoChannel2::SetOptions"); |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1363 | LOG(LS_INFO) << "SetOptions: " << options.ToString(); |
| 1364 | VideoOptions old_options = options_; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1365 | options_.SetAll(options); |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1366 | if (options_ == old_options) { |
| 1367 | // No new options to set. |
| 1368 | return true; |
| 1369 | } |
Peter Boström | e7b221f | 2015-04-13 15:34:32 +0200 | [diff] [blame] | 1370 | { |
| 1371 | rtc::CritScope lock(&capturer_crit_); |
| 1372 | options_.cpu_overuse_detection.Get(&signal_cpu_adaptation_); |
| 1373 | } |
pbos@webrtc.org | d819803 | 2014-11-10 14:41:43 +0000 | [diff] [blame] | 1374 | rtc::DiffServCodePoint dscp = options_.dscp.GetWithDefaultIfUnset(false) |
| 1375 | ? rtc::DSCP_AF41 |
| 1376 | : rtc::DSCP_DEFAULT; |
| 1377 | MediaChannel::SetDscp(dscp); |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1378 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1379 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 1380 | send_streams_.begin(); |
| 1381 | it != send_streams_.end(); |
| 1382 | ++it) { |
| 1383 | it->second->SetOptions(options_); |
| 1384 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1385 | return true; |
| 1386 | } |
| 1387 | |
| 1388 | void WebRtcVideoChannel2::SetInterface(NetworkInterface* iface) { |
| 1389 | MediaChannel::SetInterface(iface); |
| 1390 | // Set the RTP recv/send buffer to a bigger size |
| 1391 | MediaChannel::SetOption(NetworkInterface::ST_RTP, |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1392 | rtc::Socket::OPT_RCVBUF, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1393 | kVideoRtpBufferSize); |
| 1394 | |
buildbot@webrtc.org | ae694ef | 2014-10-28 17:37:17 +0000 | [diff] [blame] | 1395 | // Speculative change to increase the outbound socket buffer size. |
| 1396 | // In b/15152257, we are seeing a significant number of packets discarded |
| 1397 | // due to lack of socket buffer space, although it's not yet clear what the |
| 1398 | // ideal value should be. |
| 1399 | MediaChannel::SetOption(NetworkInterface::ST_RTP, |
| 1400 | rtc::Socket::OPT_SNDBUF, |
| 1401 | kVideoRtpBufferSize); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1402 | } |
| 1403 | |
| 1404 | void WebRtcVideoChannel2::UpdateAspectRatio(int ratio_w, int ratio_h) { |
| 1405 | // TODO(pbos): Implement. |
| 1406 | } |
| 1407 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1408 | void WebRtcVideoChannel2::OnMessage(rtc::Message* msg) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1409 | // Ignored. |
| 1410 | } |
| 1411 | |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1412 | void WebRtcVideoChannel2::OnLoadUpdate(Load load) { |
Peter Boström | e7b221f | 2015-04-13 15:34:32 +0200 | [diff] [blame] | 1413 | // OnLoadUpdate can not take any locks that are held while creating streams |
| 1414 | // etc. Doing so establishes lock-order inversions between the webrtc process |
| 1415 | // thread on stream creation and locks such as stream_crit_ while calling out. |
| 1416 | rtc::CritScope stream_lock(&capturer_crit_); |
| 1417 | if (!signal_cpu_adaptation_) |
| 1418 | return; |
| 1419 | for (auto& kv : capturers_) { |
| 1420 | if (kv.second != nullptr && kv.second->video_adapter() != nullptr) { |
| 1421 | kv.second->video_adapter()->OnCpuResolutionRequest( |
| 1422 | load == kOveruse ? CoordinatedVideoAdapter::DOWNGRADE |
| 1423 | : CoordinatedVideoAdapter::UPGRADE); |
| 1424 | } |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 1425 | } |
| 1426 | } |
| 1427 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1428 | bool WebRtcVideoChannel2::SendRtp(const uint8_t* data, size_t len) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1429 | rtc::Buffer packet(data, len, kMaxRtpPacketLen); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1430 | return MediaChannel::SendPacket(&packet); |
| 1431 | } |
| 1432 | |
| 1433 | bool WebRtcVideoChannel2::SendRtcp(const uint8_t* data, size_t len) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1434 | rtc::Buffer packet(data, len, kMaxRtpPacketLen); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1435 | return MediaChannel::SendRtcp(&packet); |
| 1436 | } |
| 1437 | |
| 1438 | void WebRtcVideoChannel2::StartAllSendStreams() { |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1439 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1440 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 1441 | send_streams_.begin(); |
| 1442 | it != send_streams_.end(); |
| 1443 | ++it) { |
| 1444 | it->second->Start(); |
| 1445 | } |
| 1446 | } |
| 1447 | |
| 1448 | void WebRtcVideoChannel2::StopAllSendStreams() { |
pbos@webrtc.org | 575d126 | 2014-10-08 14:48:08 +0000 | [diff] [blame] | 1449 | rtc::CritScope stream_lock(&stream_crit_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1450 | for (std::map<uint32, WebRtcVideoSendStream*>::iterator it = |
| 1451 | send_streams_.begin(); |
| 1452 | it != send_streams_.end(); |
| 1453 | ++it) { |
| 1454 | it->second->Stop(); |
| 1455 | } |
| 1456 | } |
| 1457 | |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1458 | WebRtcVideoChannel2::WebRtcVideoSendStream::VideoSendStreamParameters:: |
| 1459 | VideoSendStreamParameters( |
| 1460 | const webrtc::VideoSendStream::Config& config, |
| 1461 | const VideoOptions& options, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1462 | int max_bitrate_bps, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1463 | const Settable<VideoCodecSettings>& codec_settings) |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1464 | : config(config), |
| 1465 | options(options), |
| 1466 | max_bitrate_bps(max_bitrate_bps), |
| 1467 | codec_settings(codec_settings) { |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1468 | } |
| 1469 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1470 | WebRtcVideoChannel2::WebRtcVideoSendStream::WebRtcVideoSendStream( |
| 1471 | webrtc::Call* call, |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1472 | WebRtcVideoEncoderFactory* external_encoder_factory, |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1473 | const VideoOptions& options, |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1474 | int max_bitrate_bps, |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1475 | const Settable<VideoCodecSettings>& codec_settings, |
| 1476 | const StreamParams& sp, |
| 1477 | const std::vector<webrtc::RtpExtension>& rtp_extensions) |
Henrik Kjellander | 7c027b6 | 2015-04-22 13:21:30 +0200 | [diff] [blame] | 1478 | : ssrcs_(sp.ssrcs), |
| 1479 | call_(call), |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1480 | external_encoder_factory_(external_encoder_factory), |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1481 | stream_(NULL), |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1482 | parameters_(webrtc::VideoSendStream::Config(), |
| 1483 | options, |
| 1484 | max_bitrate_bps, |
| 1485 | codec_settings), |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1486 | allocated_encoder_(NULL, webrtc::kVideoCodecUnknown, false), |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 1487 | capturer_(NULL), |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1488 | sending_(false), |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 1489 | muted_(false), |
| 1490 | old_adapt_changes_(0) { |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1491 | parameters_.config.rtp.max_packet_size = kVideoMtu; |
| 1492 | |
| 1493 | sp.GetPrimarySsrcs(¶meters_.config.rtp.ssrcs); |
| 1494 | sp.GetFidSsrcs(parameters_.config.rtp.ssrcs, |
| 1495 | ¶meters_.config.rtp.rtx.ssrcs); |
| 1496 | parameters_.config.rtp.c_name = sp.cname; |
| 1497 | parameters_.config.rtp.extensions = rtp_extensions; |
| 1498 | |
| 1499 | VideoCodecSettings params; |
| 1500 | if (codec_settings.Get(¶ms)) { |
| 1501 | SetCodec(params); |
| 1502 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1503 | } |
| 1504 | |
| 1505 | WebRtcVideoChannel2::WebRtcVideoSendStream::~WebRtcVideoSendStream() { |
| 1506 | DisconnectCapturer(); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1507 | if (stream_ != NULL) { |
| 1508 | call_->DestroyVideoSendStream(stream_); |
| 1509 | } |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1510 | DestroyVideoEncoder(&allocated_encoder_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1513 | static void CreateBlackFrame(webrtc::I420VideoFrame* video_frame, |
| 1514 | int width, |
| 1515 | int height) { |
pbos@webrtc.org | b4987bf | 2015-02-18 10:13:09 +0000 | [diff] [blame] | 1516 | video_frame->CreateEmptyFrame(width, height, width, (width + 1) / 2, |
| 1517 | (width + 1) / 2); |
| 1518 | memset(video_frame->buffer(webrtc::kYPlane), 16, |
| 1519 | video_frame->allocated_size(webrtc::kYPlane)); |
| 1520 | memset(video_frame->buffer(webrtc::kUPlane), 128, |
| 1521 | video_frame->allocated_size(webrtc::kUPlane)); |
| 1522 | memset(video_frame->buffer(webrtc::kVPlane), 128, |
| 1523 | video_frame->allocated_size(webrtc::kVPlane)); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1524 | } |
| 1525 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1526 | void WebRtcVideoChannel2::WebRtcVideoSendStream::InputFrame( |
| 1527 | VideoCapturer* capturer, |
| 1528 | const VideoFrame* frame) { |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 1529 | TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::InputFrame"); |
magjed@webrtc.org | afdd5dd | 2015-03-12 13:11:25 +0000 | [diff] [blame] | 1530 | webrtc::I420VideoFrame video_frame(frame->GetVideoFrameBuffer(), 0, 0, |
| 1531 | frame->GetVideoRotation()); |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1532 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1533 | if (stream_ == NULL) { |
Peter Boström | ad1f9b6 | 2015-04-08 14:04:01 +0200 | [diff] [blame] | 1534 | // Frame input before send codecs are configured, dropping frame. |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1535 | return; |
| 1536 | } |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 1537 | |
| 1538 | // Not sending, abort early to prevent expensive reconfigurations while |
| 1539 | // setting up codecs etc. |
| 1540 | if (!sending_) |
| 1541 | return; |
| 1542 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1543 | if (format_.width == 0) { // Dropping frames. |
| 1544 | assert(format_.height == 0); |
| 1545 | LOG(LS_VERBOSE) << "VideoFormat 0x0 set, Dropping frame."; |
| 1546 | return; |
| 1547 | } |
pbos@webrtc.org | d60d79a | 2014-09-24 07:10:57 +0000 | [diff] [blame] | 1548 | if (muted_) { |
| 1549 | // Create a black frame to transmit instead. |
magjed@webrtc.org | afdd5dd | 2015-03-12 13:11:25 +0000 | [diff] [blame] | 1550 | CreateBlackFrame(&video_frame, |
pbos@webrtc.org | d60d79a | 2014-09-24 07:10:57 +0000 | [diff] [blame] | 1551 | static_cast<int>(frame->GetWidth()), |
| 1552 | static_cast<int>(frame->GetHeight())); |
| 1553 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1554 | // Reconfigure codec if necessary. |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame] | 1555 | SetDimensions( |
magjed@webrtc.org | afdd5dd | 2015-03-12 13:11:25 +0000 | [diff] [blame] | 1556 | video_frame.width(), video_frame.height(), capturer->IsScreencast()); |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame] | 1557 | |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 1558 | stream_->Input()->IncomingCapturedFrame(video_frame); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1559 | } |
| 1560 | |
| 1561 | bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetCapturer( |
| 1562 | VideoCapturer* capturer) { |
pbos@webrtc.org | b4987bf | 2015-02-18 10:13:09 +0000 | [diff] [blame] | 1563 | TRACE_EVENT0("webrtc", "WebRtcVideoSendStream::SetCapturer"); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1564 | if (!DisconnectCapturer() && capturer == NULL) { |
| 1565 | return false; |
| 1566 | } |
| 1567 | |
| 1568 | { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1569 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1570 | |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 1571 | if (capturer == NULL) { |
| 1572 | if (stream_ != NULL) { |
| 1573 | LOG(LS_VERBOSE) << "Disabling capturer, sending black frame."; |
| 1574 | webrtc::I420VideoFrame black_frame; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1575 | |
pbos@webrtc.org | b4987bf | 2015-02-18 10:13:09 +0000 | [diff] [blame] | 1576 | CreateBlackFrame(&black_frame, last_dimensions_.width, |
| 1577 | last_dimensions_.height); |
perkj@webrtc.org | af612d5 | 2015-03-18 09:51:05 +0000 | [diff] [blame] | 1578 | stream_->Input()->IncomingCapturedFrame(black_frame); |
pbos@webrtc.org | 9359cb3 | 2014-07-23 15:44:48 +0000 | [diff] [blame] | 1579 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1580 | |
| 1581 | capturer_ = NULL; |
| 1582 | return true; |
| 1583 | } |
| 1584 | |
| 1585 | capturer_ = capturer; |
| 1586 | } |
| 1587 | // Lock cannot be held while connecting the capturer to prevent lock-order |
| 1588 | // violations. |
| 1589 | capturer->SignalVideoFrame.connect(this, &WebRtcVideoSendStream::InputFrame); |
| 1590 | return true; |
| 1591 | } |
| 1592 | |
| 1593 | bool WebRtcVideoChannel2::WebRtcVideoSendStream::SetVideoFormat( |
| 1594 | const VideoFormat& format) { |
| 1595 | if ((format.width == 0 || format.height == 0) && |
| 1596 | format.width != format.height) { |
| 1597 | LOG(LS_ERROR) << "Can't set VideoFormat, width or height is zero (but not " |
| 1598 | "both, 0x0 drops frames)."; |
| 1599 | return false; |
| 1600 | } |
| 1601 | |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1602 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1603 | if (format.width == 0 && format.height == 0) { |
| 1604 | LOG(LS_INFO) |
| 1605 | << "0x0 resolution selected. Captured frames will be dropped for ssrc: " |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1606 | << parameters_.config.rtp.ssrcs[0] << "."; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1607 | } else { |
| 1608 | // TODO(pbos): Fix me, this only affects the last stream! |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 1609 | parameters_.encoder_config.streams.back().max_framerate = |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1610 | VideoFormat::IntervalToFps(format.interval); |
pbos@webrtc.org | c4175b9 | 2014-09-03 15:25:49 +0000 | [diff] [blame] | 1611 | SetDimensions(format.width, format.height, false); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1612 | } |
| 1613 | |
| 1614 | format_ = format; |
| 1615 | return true; |
| 1616 | } |
| 1617 | |
pbos@webrtc.org | ef8bb8d | 2014-08-13 21:36:18 +0000 | [diff] [blame] | 1618 | void WebRtcVideoChannel2::WebRtcVideoSendStream::MuteStream(bool mute) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1619 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1620 | muted_ = mute; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | bool WebRtcVideoChannel2::WebRtcVideoSendStream::DisconnectCapturer() { |
pbos@webrtc.org | 963b979 | 2014-10-07 14:27:27 +0000 | [diff] [blame] | 1624 | cricket::VideoCapturer* capturer; |
| 1625 | { |
| 1626 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 1627 | if (capturer_ == NULL) |
pbos@webrtc.org | 963b979 | 2014-10-07 14:27:27 +0000 | [diff] [blame] | 1628 | return false; |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 1629 | |
| 1630 | if (capturer_->video_adapter() != nullptr) |
| 1631 | old_adapt_changes_ += capturer_->video_adapter()->adaptation_changes(); |
| 1632 | |
pbos@webrtc.org | 963b979 | 2014-10-07 14:27:27 +0000 | [diff] [blame] | 1633 | capturer = capturer_; |
| 1634 | capturer_ = NULL; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1635 | } |
pbos@webrtc.org | 963b979 | 2014-10-07 14:27:27 +0000 | [diff] [blame] | 1636 | capturer->SignalVideoFrame.disconnect(this); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1637 | return true; |
| 1638 | } |
| 1639 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 1640 | const std::vector<uint32>& |
| 1641 | WebRtcVideoChannel2::WebRtcVideoSendStream::GetSsrcs() const { |
| 1642 | return ssrcs_; |
| 1643 | } |
| 1644 | |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 1645 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetApplyRotation( |
| 1646 | bool apply_rotation) { |
| 1647 | rtc::CritScope cs(&lock_); |
| 1648 | if (capturer_ == NULL) |
| 1649 | return; |
| 1650 | |
| 1651 | capturer_->SetApplyRotation(apply_rotation); |
| 1652 | } |
| 1653 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1654 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetOptions( |
| 1655 | const VideoOptions& options) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1656 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1657 | VideoCodecSettings codec_settings; |
| 1658 | if (parameters_.codec_settings.Get(&codec_settings)) { |
| 1659 | SetCodecAndOptions(codec_settings, options); |
| 1660 | } else { |
| 1661 | parameters_.options = options; |
| 1662 | } |
| 1663 | } |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1664 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1665 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodec( |
| 1666 | const VideoCodecSettings& codec_settings) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1667 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1668 | SetCodecAndOptions(codec_settings, parameters_.options); |
| 1669 | } |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1670 | |
| 1671 | webrtc::VideoCodecType CodecTypeFromName(const std::string& name) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 1672 | if (CodecNamesEq(name, kVp8CodecName)) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1673 | return webrtc::kVideoCodecVP8; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 1674 | } else if (CodecNamesEq(name, kVp9CodecName)) { |
andresp@webrtc.org | 188d3b2 | 2014-11-07 13:21:04 +0000 | [diff] [blame] | 1675 | return webrtc::kVideoCodecVP9; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 1676 | } else if (CodecNamesEq(name, kH264CodecName)) { |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1677 | return webrtc::kVideoCodecH264; |
| 1678 | } |
| 1679 | return webrtc::kVideoCodecUnknown; |
| 1680 | } |
| 1681 | |
| 1682 | WebRtcVideoChannel2::WebRtcVideoSendStream::AllocatedEncoder |
| 1683 | WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoder( |
| 1684 | const VideoCodec& codec) { |
| 1685 | webrtc::VideoCodecType type = CodecTypeFromName(codec.name); |
| 1686 | |
| 1687 | // Do not re-create encoders of the same type. |
| 1688 | if (type == allocated_encoder_.type && allocated_encoder_.encoder != NULL) { |
| 1689 | return allocated_encoder_; |
| 1690 | } |
| 1691 | |
| 1692 | if (external_encoder_factory_ != NULL) { |
| 1693 | webrtc::VideoEncoder* encoder = |
| 1694 | external_encoder_factory_->CreateVideoEncoder(type); |
| 1695 | if (encoder != NULL) { |
| 1696 | return AllocatedEncoder(encoder, type, true); |
| 1697 | } |
| 1698 | } |
| 1699 | |
| 1700 | if (type == webrtc::kVideoCodecVP8) { |
| 1701 | return AllocatedEncoder( |
| 1702 | webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kVp8), type, false); |
andresp@webrtc.org | 188d3b2 | 2014-11-07 13:21:04 +0000 | [diff] [blame] | 1703 | } else if (type == webrtc::kVideoCodecVP9) { |
| 1704 | return AllocatedEncoder( |
| 1705 | webrtc::VideoEncoder::Create(webrtc::VideoEncoder::kVp9), type, false); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | // This shouldn't happen, we should not be trying to create something we don't |
| 1709 | // support. |
| 1710 | assert(false); |
| 1711 | return AllocatedEncoder(NULL, webrtc::kVideoCodecUnknown, false); |
| 1712 | } |
| 1713 | |
| 1714 | void WebRtcVideoChannel2::WebRtcVideoSendStream::DestroyVideoEncoder( |
| 1715 | AllocatedEncoder* encoder) { |
| 1716 | if (encoder->external) { |
| 1717 | external_encoder_factory_->DestroyVideoEncoder(encoder->encoder); |
| 1718 | } else { |
| 1719 | delete encoder->encoder; |
| 1720 | } |
| 1721 | } |
| 1722 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1723 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetCodecAndOptions( |
| 1724 | const VideoCodecSettings& codec_settings, |
| 1725 | const VideoOptions& options) { |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1726 | parameters_.encoder_config = |
| 1727 | CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
pbos@webrtc.org | 86196c4 | 2015-02-16 21:02:00 +0000 | [diff] [blame] | 1728 | if (parameters_.encoder_config.streams.empty()) |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1729 | return; |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1730 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1731 | format_ = VideoFormat(codec_settings.codec.width, |
| 1732 | codec_settings.codec.height, |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1733 | VideoFormat::FpsToInterval(30), |
| 1734 | FOURCC_I420); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1735 | |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1736 | AllocatedEncoder new_encoder = CreateVideoEncoder(codec_settings.codec); |
| 1737 | parameters_.config.encoder_settings.encoder = new_encoder.encoder; |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1738 | parameters_.config.encoder_settings.payload_name = codec_settings.codec.name; |
| 1739 | parameters_.config.encoder_settings.payload_type = codec_settings.codec.id; |
| 1740 | parameters_.config.rtp.fec = codec_settings.fec; |
| 1741 | |
| 1742 | // Set RTX payload type if RTX is enabled. |
| 1743 | if (!parameters_.config.rtp.rtx.ssrcs.empty()) { |
pbos@webrtc.org | b9557a9 | 2015-03-20 19:52:56 +0000 | [diff] [blame] | 1744 | if (codec_settings.rtx_payload_type == -1) { |
| 1745 | LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " |
| 1746 | "payload type. Ignoring."; |
| 1747 | parameters_.config.rtp.rtx.ssrcs.clear(); |
| 1748 | } else { |
| 1749 | parameters_.config.rtp.rtx.payload_type = codec_settings.rtx_payload_type; |
| 1750 | } |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1751 | } |
| 1752 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 1753 | if (HasNack(codec_settings.codec)) { |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1754 | parameters_.config.rtp.nack.rtp_history_ms = kNackHistoryMs; |
| 1755 | } |
| 1756 | |
pbos@webrtc.org | 5ff71ab | 2014-07-23 07:28:56 +0000 | [diff] [blame] | 1757 | options.suspend_below_min_bitrate.Get( |
| 1758 | ¶meters_.config.suspend_below_min_bitrate); |
| 1759 | |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1760 | parameters_.codec_settings.Set(codec_settings); |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 1761 | parameters_.options = options; |
pbos@webrtc.org | 543e589 | 2014-07-23 07:01:31 +0000 | [diff] [blame] | 1762 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1763 | RecreateWebRtcStream(); |
pbos@webrtc.org | 7fe1e03 | 2014-10-14 04:25:33 +0000 | [diff] [blame] | 1764 | if (allocated_encoder_.encoder != new_encoder.encoder) { |
| 1765 | DestroyVideoEncoder(&allocated_encoder_); |
| 1766 | allocated_encoder_ = new_encoder; |
| 1767 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1768 | } |
| 1769 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1770 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetRtpExtensions( |
| 1771 | const std::vector<webrtc::RtpExtension>& rtp_extensions) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1772 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1773 | parameters_.config.rtp.extensions = rtp_extensions; |
Peter Boström | 3c3f646 | 2015-04-15 16:27:49 +0200 | [diff] [blame] | 1774 | if (stream_ != nullptr) |
| 1775 | RecreateWebRtcStream(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 1776 | } |
| 1777 | |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1778 | webrtc::VideoEncoderConfig |
| 1779 | WebRtcVideoChannel2::WebRtcVideoSendStream::CreateVideoEncoderConfig( |
| 1780 | const Dimensions& dimensions, |
| 1781 | const VideoCodec& codec) const { |
| 1782 | webrtc::VideoEncoderConfig encoder_config; |
| 1783 | if (dimensions.is_screencast) { |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 1784 | int screencast_min_bitrate_kbps; |
| 1785 | parameters_.options.screencast_min_bitrate.Get( |
| 1786 | &screencast_min_bitrate_kbps); |
| 1787 | encoder_config.min_transmit_bitrate_bps = |
| 1788 | screencast_min_bitrate_kbps * 1000; |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 1789 | encoder_config.content_type = |
| 1790 | webrtc::VideoEncoderConfig::ContentType::kScreen; |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 1791 | } else { |
| 1792 | encoder_config.min_transmit_bitrate_bps = 0; |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 1793 | encoder_config.content_type = |
| 1794 | webrtc::VideoEncoderConfig::ContentType::kRealtimeVideo; |
pbos@webrtc.org | efc82c2 | 2014-10-27 13:58:00 +0000 | [diff] [blame] | 1795 | } |
| 1796 | |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1797 | // Restrict dimensions according to codec max. |
| 1798 | int width = dimensions.width; |
| 1799 | int height = dimensions.height; |
| 1800 | if (!dimensions.is_screencast) { |
| 1801 | if (codec.width < width) |
| 1802 | width = codec.width; |
| 1803 | if (codec.height < height) |
| 1804 | height = codec.height; |
| 1805 | } |
| 1806 | |
| 1807 | VideoCodec clamped_codec = codec; |
| 1808 | clamped_codec.width = width; |
| 1809 | clamped_codec.height = height; |
pbos@webrtc.org | cddd17c | 2014-09-16 16:33:13 +0000 | [diff] [blame] | 1810 | |
pbos@webrtc.org | f1c8b90 | 2015-01-14 17:29:27 +0000 | [diff] [blame] | 1811 | encoder_config.streams = CreateVideoStreams( |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1812 | clamped_codec, parameters_.options, parameters_.max_bitrate_bps, |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 1813 | dimensions.is_screencast ? 1 : parameters_.config.rtp.ssrcs.size()); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 1814 | |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 1815 | // Conference mode screencast uses 2 temporal layers split at 100kbit. |
| 1816 | if (parameters_.options.conference_mode.GetWithDefaultIfUnset(false) && |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1817 | dimensions.is_screencast && encoder_config.streams.size() == 1) { |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 1818 | ScreenshareLayerConfig config = ScreenshareLayerConfig::GetDefault(); |
| 1819 | |
| 1820 | // For screenshare in conference mode, tl0 and tl1 bitrates are piggybacked |
| 1821 | // on the VideoCodec struct as target and max bitrates, respectively. |
| 1822 | // See eg. webrtc::VP8EncoderImpl::SetRates(). |
| 1823 | encoder_config.streams[0].target_bitrate_bps = |
| 1824 | config.tl0_bitrate_kbps * 1000; |
| 1825 | encoder_config.streams[0].max_bitrate_bps = config.tl1_bitrate_kbps * 1000; |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 1826 | encoder_config.streams[0].temporal_layer_thresholds_bps.clear(); |
| 1827 | encoder_config.streams[0].temporal_layer_thresholds_bps.push_back( |
sprang@webrtc.org | 46d4d29 | 2014-12-23 15:19:35 +0000 | [diff] [blame] | 1828 | config.tl0_bitrate_kbps * 1000); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 1829 | } |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 1830 | return encoder_config; |
| 1831 | } |
| 1832 | |
| 1833 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetDimensions( |
| 1834 | int width, |
| 1835 | int height, |
| 1836 | bool is_screencast) { |
| 1837 | if (last_dimensions_.width == width && last_dimensions_.height == height && |
| 1838 | last_dimensions_.is_screencast == is_screencast) { |
| 1839 | // Configured using the same parameters, do not reconfigure. |
| 1840 | return; |
| 1841 | } |
| 1842 | LOG(LS_INFO) << "SetDimensions: " << width << "x" << height |
| 1843 | << (is_screencast ? " (screencast)" : " (not screencast)"); |
| 1844 | |
| 1845 | last_dimensions_.width = width; |
| 1846 | last_dimensions_.height = height; |
| 1847 | last_dimensions_.is_screencast = is_screencast; |
| 1848 | |
| 1849 | assert(!parameters_.encoder_config.streams.empty()); |
| 1850 | |
| 1851 | VideoCodecSettings codec_settings; |
| 1852 | parameters_.codec_settings.Get(&codec_settings); |
| 1853 | |
| 1854 | webrtc::VideoEncoderConfig encoder_config = |
| 1855 | CreateVideoEncoderConfig(last_dimensions_, codec_settings.codec); |
| 1856 | |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 1857 | encoder_config.encoder_specific_settings = ConfigureVideoEncoderSettings( |
| 1858 | codec_settings.codec, parameters_.options, is_screencast); |
pbos@webrtc.org | b7ed779 | 2014-10-31 13:08:10 +0000 | [diff] [blame] | 1859 | |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 1860 | bool stream_reconfigured = stream_->ReconfigureVideoEncoder(encoder_config); |
| 1861 | |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 1862 | encoder_config.encoder_specific_settings = NULL; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 1863 | |
| 1864 | if (!stream_reconfigured) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1865 | LOG(LS_WARNING) << "Failed to reconfigure video encoder for dimensions: " |
| 1866 | << width << "x" << height; |
| 1867 | return; |
| 1868 | } |
pbos@webrtc.org | cddd17c | 2014-09-16 16:33:13 +0000 | [diff] [blame] | 1869 | |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 1870 | parameters_.encoder_config = encoder_config; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1871 | } |
| 1872 | |
| 1873 | void WebRtcVideoChannel2::WebRtcVideoSendStream::Start() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1874 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1875 | assert(stream_ != NULL); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1876 | stream_->Start(); |
| 1877 | sending_ = true; |
| 1878 | } |
| 1879 | |
| 1880 | void WebRtcVideoChannel2::WebRtcVideoSendStream::Stop() { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 1881 | rtc::CritScope cs(&lock_); |
pbos@webrtc.org | 5301b0f | 2014-07-17 08:51:46 +0000 | [diff] [blame] | 1882 | if (stream_ != NULL) { |
| 1883 | stream_->Stop(); |
| 1884 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 1885 | sending_ = false; |
| 1886 | } |
| 1887 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1888 | VideoSenderInfo |
| 1889 | WebRtcVideoChannel2::WebRtcVideoSendStream::GetVideoSenderInfo() { |
| 1890 | VideoSenderInfo info; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 1891 | webrtc::VideoSendStream::Stats stats; |
| 1892 | { |
| 1893 | rtc::CritScope cs(&lock_); |
| 1894 | for (uint32_t ssrc : parameters_.config.rtp.ssrcs) |
| 1895 | info.add_ssrc(ssrc); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1896 | |
Peter Boström | 74d9ed7 | 2015-03-26 16:28:31 +0100 | [diff] [blame] | 1897 | VideoCodecSettings codec_settings; |
| 1898 | if (parameters_.codec_settings.Get(&codec_settings)) |
| 1899 | info.codec_name = codec_settings.codec.name; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 1900 | for (size_t i = 0; i < parameters_.encoder_config.streams.size(); ++i) { |
| 1901 | if (i == parameters_.encoder_config.streams.size() - 1) { |
| 1902 | info.preferred_bitrate += |
| 1903 | parameters_.encoder_config.streams[i].max_bitrate_bps; |
| 1904 | } else { |
| 1905 | info.preferred_bitrate += |
| 1906 | parameters_.encoder_config.streams[i].target_bitrate_bps; |
| 1907 | } |
| 1908 | } |
pbos@webrtc.org | c3d2bd2 | 2014-08-12 20:55:10 +0000 | [diff] [blame] | 1909 | |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 1910 | if (stream_ == NULL) |
| 1911 | return info; |
| 1912 | |
| 1913 | stats = stream_->GetStats(); |
| 1914 | |
pbos@webrtc.org | 9a4410e | 2015-02-26 10:03:39 +0000 | [diff] [blame] | 1915 | info.adapt_changes = old_adapt_changes_; |
| 1916 | info.adapt_reason = CoordinatedVideoAdapter::ADAPTREASON_NONE; |
| 1917 | |
| 1918 | if (capturer_ != NULL) { |
| 1919 | if (!capturer_->IsMuted()) { |
| 1920 | VideoFormat last_captured_frame_format; |
| 1921 | capturer_->GetStats(&info.adapt_frame_drops, &info.effects_frame_drops, |
| 1922 | &info.capturer_frame_time, |
| 1923 | &last_captured_frame_format); |
| 1924 | info.input_frame_width = last_captured_frame_format.width; |
| 1925 | info.input_frame_height = last_captured_frame_format.height; |
| 1926 | } |
| 1927 | if (capturer_->video_adapter() != nullptr) { |
| 1928 | info.adapt_changes += capturer_->video_adapter()->adaptation_changes(); |
| 1929 | info.adapt_reason = capturer_->video_adapter()->adapt_reason(); |
| 1930 | } |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 1931 | } |
| 1932 | } |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1933 | info.framerate_input = stats.input_frame_rate; |
| 1934 | info.framerate_sent = stats.encode_frame_rate; |
pbos@webrtc.org | 3e6e271 | 2015-02-26 12:19:31 +0000 | [diff] [blame] | 1935 | info.avg_encode_ms = stats.avg_encode_time_ms; |
| 1936 | info.encode_usage_percent = stats.encode_usage_percent; |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1937 | |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 1938 | info.nominal_bitrate = stats.media_bitrate_bps; |
| 1939 | |
pbos@webrtc.org | 273a414 | 2014-12-01 15:23:21 +0000 | [diff] [blame] | 1940 | info.send_frame_width = 0; |
| 1941 | info.send_frame_height = 0; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1942 | for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it = |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1943 | stats.substreams.begin(); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1944 | it != stats.substreams.end(); ++it) { |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1945 | // TODO(pbos): Wire up additional stats, such as padding bytes. |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1946 | webrtc::VideoSendStream::StreamStats stream_stats = it->second; |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 1947 | info.bytes_sent += stream_stats.rtp_stats.transmitted.payload_bytes + |
| 1948 | stream_stats.rtp_stats.transmitted.header_bytes + |
| 1949 | stream_stats.rtp_stats.transmitted.padding_bytes; |
| 1950 | info.packets_sent += stream_stats.rtp_stats.transmitted.packets; |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1951 | info.packets_lost += stream_stats.rtcp_stats.cumulative_lost; |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1952 | if (stream_stats.width > info.send_frame_width) |
| 1953 | info.send_frame_width = stream_stats.width; |
| 1954 | if (stream_stats.height > info.send_frame_height) |
| 1955 | info.send_frame_height = stream_stats.height; |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 1956 | info.firs_rcvd += stream_stats.rtcp_packet_type_counts.fir_packets; |
| 1957 | info.nacks_rcvd += stream_stats.rtcp_packet_type_counts.nack_packets; |
| 1958 | info.plis_rcvd += stream_stats.rtcp_packet_type_counts.pli_packets; |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1959 | } |
| 1960 | |
| 1961 | if (!stats.substreams.empty()) { |
| 1962 | // TODO(pbos): Report fraction lost per SSRC. |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1963 | webrtc::VideoSendStream::StreamStats first_stream_stats = |
| 1964 | stats.substreams.begin()->second; |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1965 | info.fraction_lost = |
| 1966 | static_cast<float>(first_stream_stats.rtcp_stats.fraction_lost) / |
| 1967 | (1 << 8); |
| 1968 | } |
| 1969 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 1970 | return info; |
| 1971 | } |
| 1972 | |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1973 | void WebRtcVideoChannel2::WebRtcVideoSendStream::FillBandwidthEstimationInfo( |
| 1974 | BandwidthEstimationInfo* bwe_info) { |
| 1975 | rtc::CritScope cs(&lock_); |
| 1976 | if (stream_ == NULL) { |
| 1977 | return; |
| 1978 | } |
| 1979 | webrtc::VideoSendStream::Stats stats = stream_->GetStats(); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1980 | for (std::map<uint32_t, webrtc::VideoSendStream::StreamStats>::iterator it = |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1981 | stats.substreams.begin(); |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 1982 | it != stats.substreams.end(); ++it) { |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1983 | bwe_info->transmit_bitrate += it->second.total_bitrate_bps; |
| 1984 | bwe_info->retransmit_bitrate += it->second.retransmit_bitrate_bps; |
| 1985 | } |
pbos@webrtc.org | 891d483 | 2015-02-26 13:15:22 +0000 | [diff] [blame] | 1986 | bwe_info->target_enc_bitrate += stats.target_media_bitrate_bps; |
pbos@webrtc.org | 77e11bb | 2015-02-23 16:39:07 +0000 | [diff] [blame] | 1987 | bwe_info->actual_enc_bitrate += stats.media_bitrate_bps; |
stefan@webrtc.org | 0bae1fa | 2014-11-05 14:05:29 +0000 | [diff] [blame] | 1988 | } |
| 1989 | |
Peter Boström | dfd53fe | 2015-03-27 15:58:11 +0100 | [diff] [blame] | 1990 | void WebRtcVideoChannel2::WebRtcVideoSendStream::SetMaxBitrateBps( |
| 1991 | int max_bitrate_bps) { |
| 1992 | rtc::CritScope cs(&lock_); |
| 1993 | parameters_.max_bitrate_bps = max_bitrate_bps; |
| 1994 | |
| 1995 | // No need to reconfigure if the stream hasn't been configured yet. |
| 1996 | if (parameters_.encoder_config.streams.empty()) |
| 1997 | return; |
| 1998 | |
| 1999 | // Force a stream reconfigure to set the new max bitrate. |
| 2000 | int width = last_dimensions_.width; |
| 2001 | last_dimensions_.width = 0; |
| 2002 | SetDimensions(width, last_dimensions_.height, last_dimensions_.is_screencast); |
| 2003 | } |
pbos@webrtc.org | 42684be | 2014-10-03 11:25:45 +0000 | [diff] [blame] | 2004 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2005 | void WebRtcVideoChannel2::WebRtcVideoSendStream::RecreateWebRtcStream() { |
| 2006 | if (stream_ != NULL) { |
| 2007 | call_->DestroyVideoSendStream(stream_); |
| 2008 | } |
pbos@webrtc.org | 6ae48c6 | 2014-06-06 10:49:19 +0000 | [diff] [blame] | 2009 | |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2010 | VideoCodecSettings codec_settings; |
| 2011 | parameters_.codec_settings.Get(&codec_settings); |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2012 | parameters_.encoder_config.encoder_specific_settings = |
Erik SprĂ¥ng | 143cec1 | 2015-04-28 10:01:41 +0200 | [diff] [blame] | 2013 | ConfigureVideoEncoderSettings( |
| 2014 | codec_settings.codec, parameters_.options, |
| 2015 | parameters_.encoder_config.content_type == |
| 2016 | webrtc::VideoEncoderConfig::ContentType::kScreen); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2017 | |
pbos@webrtc.org | b9557a9 | 2015-03-20 19:52:56 +0000 | [diff] [blame] | 2018 | webrtc::VideoSendStream::Config config = parameters_.config; |
| 2019 | if (!config.rtp.rtx.ssrcs.empty() && config.rtp.rtx.payload_type == -1) { |
| 2020 | LOG(LS_WARNING) << "RTX SSRCs configured but there's no configured RTX " |
| 2021 | "payload type the set codec. Ignoring RTX."; |
| 2022 | config.rtp.rtx.ssrcs.clear(); |
| 2023 | } |
| 2024 | stream_ = call_->CreateVideoSendStream(config, parameters_.encoder_config); |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2025 | |
pbos@webrtc.org | bbe0a85 | 2014-09-19 12:30:25 +0000 | [diff] [blame] | 2026 | parameters_.encoder_config.encoder_specific_settings = NULL; |
pbos@webrtc.org | 6f48f1b | 2014-07-22 16:29:54 +0000 | [diff] [blame] | 2027 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2028 | if (sending_) { |
| 2029 | stream_->Start(); |
| 2030 | } |
| 2031 | } |
| 2032 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2033 | WebRtcVideoChannel2::WebRtcVideoReceiveStream::WebRtcVideoReceiveStream( |
| 2034 | webrtc::Call* call, |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 2035 | const std::vector<uint32>& ssrcs, |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 2036 | WebRtcVideoDecoderFactory* external_decoder_factory, |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 2037 | bool default_stream, |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2038 | const webrtc::VideoReceiveStream::Config& config, |
| 2039 | const std::vector<VideoCodecSettings>& recv_codecs) |
| 2040 | : call_(call), |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 2041 | ssrcs_(ssrcs), |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2042 | stream_(NULL), |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 2043 | default_stream_(default_stream), |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 2044 | config_(config), |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 2045 | external_decoder_factory_(external_decoder_factory), |
pbos@webrtc.org | b648b9d | 2014-08-26 11:08:06 +0000 | [diff] [blame] | 2046 | renderer_(NULL), |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2047 | last_width_(-1), |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 2048 | last_height_(-1), |
| 2049 | first_frame_timestamp_(-1), |
| 2050 | estimated_remote_start_ntp_time_ms_(0) { |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2051 | config_.renderer = this; |
| 2052 | // SetRecvCodecs will also reset (start) the VideoReceiveStream. |
| 2053 | SetRecvCodecs(recv_codecs); |
| 2054 | } |
| 2055 | |
| 2056 | WebRtcVideoChannel2::WebRtcVideoReceiveStream::~WebRtcVideoReceiveStream() { |
| 2057 | call_->DestroyVideoReceiveStream(stream_); |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2058 | ClearDecoders(&allocated_decoders_); |
| 2059 | } |
| 2060 | |
Peter Boström | d6f4c25 | 2015-03-26 16:23:04 +0100 | [diff] [blame] | 2061 | const std::vector<uint32>& |
| 2062 | WebRtcVideoChannel2::WebRtcVideoReceiveStream::GetSsrcs() const { |
| 2063 | return ssrcs_; |
| 2064 | } |
| 2065 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2066 | WebRtcVideoChannel2::WebRtcVideoReceiveStream::AllocatedDecoder |
| 2067 | WebRtcVideoChannel2::WebRtcVideoReceiveStream::CreateOrReuseVideoDecoder( |
| 2068 | std::vector<AllocatedDecoder>* old_decoders, |
| 2069 | const VideoCodec& codec) { |
| 2070 | webrtc::VideoCodecType type = CodecTypeFromName(codec.name); |
| 2071 | |
| 2072 | for (size_t i = 0; i < old_decoders->size(); ++i) { |
| 2073 | if ((*old_decoders)[i].type == type) { |
| 2074 | AllocatedDecoder decoder = (*old_decoders)[i]; |
| 2075 | (*old_decoders)[i] = old_decoders->back(); |
| 2076 | old_decoders->pop_back(); |
| 2077 | return decoder; |
| 2078 | } |
| 2079 | } |
| 2080 | |
| 2081 | if (external_decoder_factory_ != NULL) { |
| 2082 | webrtc::VideoDecoder* decoder = |
| 2083 | external_decoder_factory_->CreateVideoDecoder(type); |
| 2084 | if (decoder != NULL) { |
| 2085 | return AllocatedDecoder(decoder, type, true); |
| 2086 | } |
| 2087 | } |
| 2088 | |
| 2089 | if (type == webrtc::kVideoCodecVP8) { |
| 2090 | return AllocatedDecoder( |
| 2091 | webrtc::VideoDecoder::Create(webrtc::VideoDecoder::kVp8), type, false); |
| 2092 | } |
| 2093 | |
pbos@webrtc.org | b9557a9 | 2015-03-20 19:52:56 +0000 | [diff] [blame] | 2094 | if (type == webrtc::kVideoCodecVP9) { |
| 2095 | return AllocatedDecoder( |
| 2096 | webrtc::VideoDecoder::Create(webrtc::VideoDecoder::kVp9), type, false); |
| 2097 | } |
| 2098 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2099 | // This shouldn't happen, we should not be trying to create something we don't |
| 2100 | // support. |
| 2101 | assert(false); |
| 2102 | return AllocatedDecoder(NULL, webrtc::kVideoCodecUnknown, false); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2103 | } |
| 2104 | |
| 2105 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRecvCodecs( |
| 2106 | const std::vector<VideoCodecSettings>& recv_codecs) { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2107 | std::vector<AllocatedDecoder> old_decoders = allocated_decoders_; |
| 2108 | allocated_decoders_.clear(); |
| 2109 | config_.decoders.clear(); |
| 2110 | for (size_t i = 0; i < recv_codecs.size(); ++i) { |
| 2111 | AllocatedDecoder allocated_decoder = |
| 2112 | CreateOrReuseVideoDecoder(&old_decoders, recv_codecs[i].codec); |
| 2113 | allocated_decoders_.push_back(allocated_decoder); |
| 2114 | |
| 2115 | webrtc::VideoReceiveStream::Decoder decoder; |
| 2116 | decoder.decoder = allocated_decoder.decoder; |
| 2117 | decoder.payload_type = recv_codecs[i].codec.id; |
| 2118 | decoder.payload_name = recv_codecs[i].codec.name; |
| 2119 | config_.decoders.push_back(decoder); |
| 2120 | } |
| 2121 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2122 | // TODO(pbos): Reconfigure RTX based on incoming recv_codecs. |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2123 | config_.rtp.fec = recv_codecs.front().fec; |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2124 | config_.rtp.nack.rtp_history_ms = |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 2125 | HasNack(recv_codecs.begin()->codec) ? kNackHistoryMs : 0; |
| 2126 | config_.rtp.remb = HasRemb(recv_codecs.begin()->codec); |
pbos@webrtc.org | 257e130 | 2014-07-25 19:01:32 +0000 | [diff] [blame] | 2127 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2128 | ClearDecoders(&old_decoders); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2129 | RecreateWebRtcStream(); |
| 2130 | } |
| 2131 | |
| 2132 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRtpExtensions( |
| 2133 | const std::vector<webrtc::RtpExtension>& extensions) { |
| 2134 | config_.rtp.extensions = extensions; |
Peter Boström | 3c3f646 | 2015-04-15 16:27:49 +0200 | [diff] [blame] | 2135 | if (stream_ != nullptr) |
| 2136 | RecreateWebRtcStream(); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::RecreateWebRtcStream() { |
| 2140 | if (stream_ != NULL) { |
| 2141 | call_->DestroyVideoReceiveStream(stream_); |
| 2142 | } |
| 2143 | stream_ = call_->CreateVideoReceiveStream(config_); |
| 2144 | stream_->Start(); |
| 2145 | } |
| 2146 | |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2147 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::ClearDecoders( |
| 2148 | std::vector<AllocatedDecoder>* allocated_decoders) { |
| 2149 | for (size_t i = 0; i < allocated_decoders->size(); ++i) { |
| 2150 | if ((*allocated_decoders)[i].external) { |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 2151 | external_decoder_factory_->DestroyVideoDecoder( |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2152 | (*allocated_decoders)[i].decoder); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 2153 | } else { |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2154 | delete (*allocated_decoders)[i].decoder; |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 2155 | } |
| 2156 | } |
pbos@webrtc.org | 96a9325 | 2014-11-03 14:46:44 +0000 | [diff] [blame] | 2157 | allocated_decoders->clear(); |
pbos@webrtc.org | 776e6f2 | 2014-10-29 15:28:39 +0000 | [diff] [blame] | 2158 | } |
| 2159 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2160 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::RenderFrame( |
| 2161 | const webrtc::I420VideoFrame& frame, |
| 2162 | int time_to_render_ms) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2163 | rtc::CritScope crit(&renderer_lock_); |
magjed@webrtc.org | fc5ad95 | 2015-01-27 09:57:01 +0000 | [diff] [blame] | 2164 | |
| 2165 | if (first_frame_timestamp_ < 0) |
| 2166 | first_frame_timestamp_ = frame.timestamp(); |
| 2167 | int64_t rtp_time_elapsed_since_first_frame = |
| 2168 | (timestamp_wraparound_handler_.Unwrap(frame.timestamp()) - |
| 2169 | first_frame_timestamp_); |
| 2170 | int64_t elapsed_time_ms = rtp_time_elapsed_since_first_frame / |
| 2171 | (cricket::kVideoCodecClockrate / 1000); |
| 2172 | if (frame.ntp_time_ms() > 0) |
| 2173 | estimated_remote_start_ntp_time_ms_ = frame.ntp_time_ms() - elapsed_time_ms; |
| 2174 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2175 | if (renderer_ == NULL) { |
| 2176 | LOG(LS_WARNING) << "VideoReceiveStream not connected to a VideoRenderer."; |
| 2177 | return; |
| 2178 | } |
| 2179 | |
| 2180 | if (frame.width() != last_width_ || frame.height() != last_height_) { |
| 2181 | SetSize(frame.width(), frame.height()); |
| 2182 | } |
| 2183 | |
magjed@webrtc.org | 2386d6d | 2015-03-05 14:03:08 +0000 | [diff] [blame] | 2184 | const WebRtcVideoFrame render_frame( |
| 2185 | frame.video_frame_buffer(), |
| 2186 | elapsed_time_ms * rtc::kNumNanosecsPerMillisec, |
Guo-wei Shieh | 64c1e8c | 2015-04-01 15:33:06 -0700 | [diff] [blame] | 2187 | frame.render_time_ms() * rtc::kNumNanosecsPerMillisec, frame.rotation()); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2188 | renderer_->RenderFrame(&render_frame); |
| 2189 | } |
| 2190 | |
pbos@webrtc.org | 0d852d5 | 2015-02-09 15:14:36 +0000 | [diff] [blame] | 2191 | bool WebRtcVideoChannel2::WebRtcVideoReceiveStream::IsTextureSupported() const { |
| 2192 | return true; |
| 2193 | } |
| 2194 | |
pbos@webrtc.org | a2a6fe6 | 2015-03-06 15:35:19 +0000 | [diff] [blame] | 2195 | bool WebRtcVideoChannel2::WebRtcVideoReceiveStream::IsDefaultStream() const { |
| 2196 | return default_stream_; |
| 2197 | } |
| 2198 | |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2199 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetRenderer( |
| 2200 | cricket::VideoRenderer* renderer) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2201 | rtc::CritScope crit(&renderer_lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2202 | renderer_ = renderer; |
| 2203 | if (renderer_ != NULL && last_width_ != -1) { |
| 2204 | SetSize(last_width_, last_height_); |
| 2205 | } |
| 2206 | } |
| 2207 | |
| 2208 | VideoRenderer* WebRtcVideoChannel2::WebRtcVideoReceiveStream::GetRenderer() { |
| 2209 | // TODO(pbos): Remove GetRenderer and all uses of it, it's thread-unsafe by |
| 2210 | // design. |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2211 | rtc::CritScope crit(&renderer_lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2212 | return renderer_; |
| 2213 | } |
| 2214 | |
| 2215 | void WebRtcVideoChannel2::WebRtcVideoReceiveStream::SetSize(int width, |
| 2216 | int height) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 2217 | rtc::CritScope crit(&renderer_lock_); |
pbos@webrtc.org | d1ea06b | 2014-07-18 09:35:58 +0000 | [diff] [blame] | 2218 | if (!renderer_->SetSize(width, height, 0)) { |
| 2219 | LOG(LS_ERROR) << "Could not set renderer size."; |
| 2220 | } |
| 2221 | last_width_ = width; |
| 2222 | last_height_ = height; |
| 2223 | } |
| 2224 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 2225 | VideoReceiverInfo |
| 2226 | WebRtcVideoChannel2::WebRtcVideoReceiveStream::GetVideoReceiverInfo() { |
| 2227 | VideoReceiverInfo info; |
| 2228 | info.add_ssrc(config_.rtp.remote_ssrc); |
| 2229 | webrtc::VideoReceiveStream::Stats stats = stream_->GetStats(); |
asapersson@webrtc.org | cfd82df | 2015-01-22 09:39:59 +0000 | [diff] [blame] | 2230 | info.bytes_rcvd = stats.rtp_stats.transmitted.payload_bytes + |
| 2231 | stats.rtp_stats.transmitted.header_bytes + |
| 2232 | stats.rtp_stats.transmitted.padding_bytes; |
| 2233 | info.packets_rcvd = stats.rtp_stats.transmitted.packets; |
Peter Boström | 393347f | 2015-04-22 14:52:45 +0200 | [diff] [blame] | 2234 | info.packets_lost = stats.rtcp_stats.cumulative_lost; |
| 2235 | info.fraction_lost = |
| 2236 | static_cast<float>(stats.rtcp_stats.fraction_lost) / (1 << 8); |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 2237 | |
| 2238 | info.framerate_rcvd = stats.network_frame_rate; |
| 2239 | info.framerate_decoded = stats.decode_frame_rate; |
| 2240 | info.framerate_output = stats.render_frame_rate; |
| 2241 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 2242 | { |
| 2243 | rtc::CritScope frame_cs(&renderer_lock_); |
| 2244 | info.frame_width = last_width_; |
| 2245 | info.frame_height = last_height_; |
| 2246 | info.capture_start_ntp_time_ms = estimated_remote_start_ntp_time_ms_; |
| 2247 | } |
| 2248 | |
pbos@webrtc.org | 09c77b9 | 2015-02-25 10:42:16 +0000 | [diff] [blame] | 2249 | info.decode_ms = stats.decode_ms; |
| 2250 | info.max_decode_ms = stats.max_decode_ms; |
| 2251 | info.current_delay_ms = stats.current_delay_ms; |
| 2252 | info.target_delay_ms = stats.target_delay_ms; |
| 2253 | info.jitter_buffer_ms = stats.jitter_buffer_ms; |
| 2254 | info.min_playout_delay_ms = stats.min_playout_delay_ms; |
| 2255 | info.render_delay_ms = stats.render_delay_ms; |
| 2256 | |
pbos@webrtc.org | 1d0fa5d | 2015-02-19 12:47:00 +0000 | [diff] [blame] | 2257 | info.firs_sent = stats.rtcp_packet_type_counts.fir_packets; |
| 2258 | info.plis_sent = stats.rtcp_packet_type_counts.pli_packets; |
| 2259 | info.nacks_sent = stats.rtcp_packet_type_counts.nack_packets; |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 2260 | |
pbos@webrtc.org | e6f84ae | 2014-07-18 11:11:55 +0000 | [diff] [blame] | 2261 | return info; |
| 2262 | } |
| 2263 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2264 | WebRtcVideoChannel2::VideoCodecSettings::VideoCodecSettings() |
| 2265 | : rtx_payload_type(-1) {} |
| 2266 | |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 2267 | bool WebRtcVideoChannel2::VideoCodecSettings::operator==( |
| 2268 | const WebRtcVideoChannel2::VideoCodecSettings& other) const { |
| 2269 | return codec == other.codec && |
| 2270 | fec.ulpfec_payload_type == other.fec.ulpfec_payload_type && |
| 2271 | fec.red_payload_type == other.fec.red_payload_type && |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 2272 | fec.red_rtx_payload_type == other.fec.red_rtx_payload_type && |
pbos@webrtc.org | a2ef4fe | 2014-11-07 10:54:43 +0000 | [diff] [blame] | 2273 | rtx_payload_type == other.rtx_payload_type; |
| 2274 | } |
| 2275 | |
Peter Boström | ee0b00e | 2015-04-22 18:41:14 +0200 | [diff] [blame] | 2276 | bool WebRtcVideoChannel2::VideoCodecSettings::operator!=( |
| 2277 | const WebRtcVideoChannel2::VideoCodecSettings& other) const { |
| 2278 | return !(*this == other); |
| 2279 | } |
| 2280 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2281 | std::vector<WebRtcVideoChannel2::VideoCodecSettings> |
| 2282 | WebRtcVideoChannel2::MapCodecs(const std::vector<VideoCodec>& codecs) { |
| 2283 | assert(!codecs.empty()); |
| 2284 | |
| 2285 | std::vector<VideoCodecSettings> video_codecs; |
| 2286 | std::map<int, bool> payload_used; |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2287 | std::map<int, VideoCodec::CodecType> payload_codec_type; |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 2288 | // |rtx_mapping| maps video payload type to rtx payload type. |
| 2289 | std::map<int, int> rtx_mapping; |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2290 | |
| 2291 | webrtc::FecConfig fec_settings; |
| 2292 | |
| 2293 | for (size_t i = 0; i < codecs.size(); ++i) { |
| 2294 | const VideoCodec& in_codec = codecs[i]; |
| 2295 | int payload_type = in_codec.id; |
| 2296 | |
| 2297 | if (payload_used[payload_type]) { |
| 2298 | LOG(LS_ERROR) << "Payload type already registered: " |
| 2299 | << in_codec.ToString(); |
| 2300 | return std::vector<VideoCodecSettings>(); |
| 2301 | } |
| 2302 | payload_used[payload_type] = true; |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2303 | payload_codec_type[payload_type] = in_codec.GetCodecType(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2304 | |
| 2305 | switch (in_codec.GetCodecType()) { |
| 2306 | case VideoCodec::CODEC_RED: { |
| 2307 | // RED payload type, should not have duplicates. |
| 2308 | assert(fec_settings.red_payload_type == -1); |
| 2309 | fec_settings.red_payload_type = in_codec.id; |
| 2310 | continue; |
| 2311 | } |
| 2312 | |
| 2313 | case VideoCodec::CODEC_ULPFEC: { |
| 2314 | // ULPFEC payload type, should not have duplicates. |
| 2315 | assert(fec_settings.ulpfec_payload_type == -1); |
| 2316 | fec_settings.ulpfec_payload_type = in_codec.id; |
| 2317 | continue; |
| 2318 | } |
| 2319 | |
| 2320 | case VideoCodec::CODEC_RTX: { |
| 2321 | int associated_payload_type; |
| 2322 | if (!in_codec.GetParam(kCodecParamAssociatedPayloadType, |
pkasting@chromium.org | e9facf8 | 2015-02-17 20:36:28 +0000 | [diff] [blame] | 2323 | &associated_payload_type) || |
| 2324 | !IsValidRtpPayloadType(associated_payload_type)) { |
| 2325 | LOG(LS_ERROR) |
| 2326 | << "RTX codec with invalid or no associated payload type: " |
| 2327 | << in_codec.ToString(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2328 | return std::vector<VideoCodecSettings>(); |
| 2329 | } |
| 2330 | rtx_mapping[associated_payload_type] = in_codec.id; |
| 2331 | continue; |
| 2332 | } |
| 2333 | |
| 2334 | case VideoCodec::CODEC_VIDEO: |
| 2335 | break; |
| 2336 | } |
| 2337 | |
| 2338 | video_codecs.push_back(VideoCodecSettings()); |
| 2339 | video_codecs.back().codec = in_codec; |
| 2340 | } |
| 2341 | |
| 2342 | // One of these codecs should have been a video codec. Only having FEC |
| 2343 | // parameters into this code is a logic error. |
| 2344 | assert(!video_codecs.empty()); |
| 2345 | |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2346 | for (std::map<int, int>::const_iterator it = rtx_mapping.begin(); |
| 2347 | it != rtx_mapping.end(); |
| 2348 | ++it) { |
| 2349 | if (!payload_used[it->first]) { |
| 2350 | LOG(LS_ERROR) << "RTX mapped to payload not in codec list."; |
| 2351 | return std::vector<VideoCodecSettings>(); |
| 2352 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 2353 | if (payload_codec_type[it->first] != VideoCodec::CODEC_VIDEO && |
| 2354 | payload_codec_type[it->first] != VideoCodec::CODEC_RED) { |
| 2355 | LOG(LS_ERROR) << "RTX not mapped to regular video codec or RED codec."; |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2356 | return std::vector<VideoCodecSettings>(); |
| 2357 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 2358 | |
| 2359 | if (it->first == fec_settings.red_payload_type) { |
| 2360 | fec_settings.red_rtx_payload_type = it->second; |
| 2361 | } |
pbos@webrtc.org | e322a17 | 2014-06-13 11:47:28 +0000 | [diff] [blame] | 2362 | } |
| 2363 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2364 | for (size_t i = 0; i < video_codecs.size(); ++i) { |
| 2365 | video_codecs[i].fec = fec_settings; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 2366 | if (rtx_mapping[video_codecs[i].codec.id] != 0 && |
| 2367 | rtx_mapping[video_codecs[i].codec.id] != |
| 2368 | fec_settings.red_payload_type) { |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2369 | video_codecs[i].rtx_payload_type = rtx_mapping[video_codecs[i].codec.id]; |
| 2370 | } |
| 2371 | } |
| 2372 | |
| 2373 | return video_codecs; |
| 2374 | } |
| 2375 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 2376 | } // namespace cricket |
| 2377 | |
| 2378 | #endif // HAVE_WEBRTC_VIDEO |