Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(32)

Side by Side Diff: webrtc/video/video_send_stream.cc

Issue 1674663002: Initialize VideoSendStream members in constructor. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: rebase Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video/vie_channel.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source 5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/video/video_send_stream.h" 11 #include "webrtc/video/video_send_stream.h"
12 12
13 #include <algorithm> 13 #include <algorithm>
14 #include <sstream> 14 #include <sstream>
15 #include <string> 15 #include <string>
16 #include <vector> 16 #include <vector>
17 17
18 #include "webrtc/base/checks.h" 18 #include "webrtc/base/checks.h"
19 #include "webrtc/base/logging.h" 19 #include "webrtc/base/logging.h"
20 #include "webrtc/base/trace_event.h" 20 #include "webrtc/base/trace_event.h"
21 #include "webrtc/call/congestion_controller.h" 21 #include "webrtc/call/congestion_controller.h"
22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h"
23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" 23 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h"
24 #include "webrtc/modules/pacing/packet_router.h" 24 #include "webrtc/modules/pacing/packet_router.h"
25 #include "webrtc/modules/utility/include/process_thread.h" 25 #include "webrtc/modules/utility/include/process_thread.h"
26 #include "webrtc/video/call_stats.h" 26 #include "webrtc/video/call_stats.h"
27 #include "webrtc/video/encoder_state_feedback.h"
28 #include "webrtc/video/video_capture_input.h" 27 #include "webrtc/video/video_capture_input.h"
29 #include "webrtc/video/vie_channel.h"
30 #include "webrtc/video/vie_encoder.h"
31 #include "webrtc/video_send_stream.h" 28 #include "webrtc/video_send_stream.h"
32 29
33 namespace webrtc { 30 namespace webrtc {
34 31
35 class PacedSender; 32 class PacedSender;
36 class RtcpIntraFrameObserver; 33 class RtcpIntraFrameObserver;
37 class TransportFeedbackObserver; 34 class TransportFeedbackObserver;
38 35
39 std::string 36 std::string
40 VideoSendStream::Config::EncoderSettings::ToString() const { 37 VideoSendStream::Config::EncoderSettings::ToString() const {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
138 suspended_ssrcs_(suspended_ssrcs), 135 suspended_ssrcs_(suspended_ssrcs),
139 module_process_thread_(module_process_thread), 136 module_process_thread_(module_process_thread),
140 call_stats_(call_stats), 137 call_stats_(call_stats),
141 congestion_controller_(congestion_controller), 138 congestion_controller_(congestion_controller),
142 overuse_detector_( 139 overuse_detector_(
143 Clock::GetRealTimeClock(), 140 Clock::GetRealTimeClock(),
144 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), 141 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time),
145 this, 142 this,
146 config.post_encode_callback, 143 config.post_encode_callback,
147 &stats_proxy_), 144 &stats_proxy_),
148 encoder_feedback_(new EncoderStateFeedback()), 145 vie_encoder_(num_cpu_cores,
149 use_config_bitrate_(true) { 146 module_process_thread_,
147 &stats_proxy_,
148 config.pre_encode_callback,
149 &overuse_detector_,
150 congestion_controller_->pacer(),
151 &payload_router_,
152 bitrate_allocator),
153 vcm_(vie_encoder_.vcm()),
154 vie_channel_(config.send_transport,
155 module_process_thread_,
156 &payload_router_,
157 nullptr,
158 encoder_feedback_.GetRtcpIntraFrameObserver(),
159 congestion_controller_->GetBitrateController()
160 ->CreateRtcpBandwidthObserver(),
161 GetTransportFeedbackObserver(),
stefan-webrtc 2016/02/11 10:15:40 I'd prefer if this is done as in audio_send_stream
pbos-webrtc 2016/02/11 11:23:33 Done.
162 congestion_controller_->GetRemoteBitrateEstimator(false),
stefan-webrtc 2016/02/11 10:15:40 I think we should be able to pass in nullptr here.
pbos-webrtc 2016/02/11 11:23:34 Done.
163 call_stats_->rtcp_rtt_stats(),
164 congestion_controller_->pacer(),
165 congestion_controller_->packet_router(),
166 config_.rtp.ssrcs.size(),
167 true),
168 input_(&vie_encoder_,
169 config_.local_renderer,
170 &stats_proxy_,
171 &overuse_detector_) {
150 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); 172 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString();
151 RTC_DCHECK(!config_.rtp.ssrcs.empty()); 173 RTC_DCHECK(!config_.rtp.ssrcs.empty());
152 174
153 // Set up Call-wide sequence numbers, if configured for this send stream. 175 RTC_CHECK(vie_encoder_.Init());
154 TransportFeedbackObserver* transport_feedback_observer = nullptr; 176 RTC_CHECK(vie_channel_.Init() == 0);
155 for (const RtpExtension& extension : config.rtp.extensions) {
156 if (extension.name == RtpExtension::kTransportSequenceNumber) {
157 transport_feedback_observer =
158 congestion_controller_->GetTransportFeedbackObserver();
159 break;
160 }
161 }
162 177
163 const std::vector<uint32_t>& ssrcs = config.rtp.ssrcs; 178 vcm_->RegisterProtectionCallback(vie_channel_.vcm_protection_callback());
164 179
165 vie_encoder_.reset(new ViEEncoder( 180 call_stats_->RegisterStatsObserver(vie_channel_.GetStatsObserver());
166 num_cpu_cores, module_process_thread_, &stats_proxy_,
167 config.pre_encode_callback, &overuse_detector_,
168 congestion_controller_->pacer(), &payload_router_, bitrate_allocator));
169 vcm_ = vie_encoder_->vcm();
170 RTC_CHECK(vie_encoder_->Init());
171 181
172 vie_channel_.reset(new ViEChannel( 182 vie_encoder_.SetSsrcs(std::vector<uint32_t>(1, config_.rtp.ssrcs[0]));
173 config.send_transport, module_process_thread_, &payload_router_, nullptr,
174 encoder_feedback_->GetRtcpIntraFrameObserver(),
175 congestion_controller_->GetBitrateController()
176 ->CreateRtcpBandwidthObserver(),
177 transport_feedback_observer,
178 congestion_controller_->GetRemoteBitrateEstimator(false),
179 call_stats_->rtcp_rtt_stats(), congestion_controller_->pacer(),
180 congestion_controller_->packet_router(), ssrcs.size(), true));
181 RTC_CHECK(vie_channel_->Init() == 0);
182
183 vcm_->RegisterProtectionCallback(vie_channel_->vcm_protection_callback());
184
185 call_stats_->RegisterStatsObserver(vie_channel_->GetStatsObserver());
186
187 std::vector<uint32_t> first_ssrc(1, ssrcs[0]);
188 vie_encoder_->SetSsrcs(first_ssrc);
189 183
190 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) { 184 for (size_t i = 0; i < config_.rtp.extensions.size(); ++i) {
191 const std::string& extension = config_.rtp.extensions[i].name; 185 const std::string& extension = config_.rtp.extensions[i].name;
192 int id = config_.rtp.extensions[i].id; 186 int id = config_.rtp.extensions[i].id;
193 // One-byte-extension local identifiers are in the range 1-14 inclusive. 187 // One-byte-extension local identifiers are in the range 1-14 inclusive.
194 RTC_DCHECK_GE(id, 1); 188 RTC_DCHECK_GE(id, 1);
195 RTC_DCHECK_LE(id, 14); 189 RTC_DCHECK_LE(id, 14);
196 if (extension == RtpExtension::kTOffset) { 190 if (extension == RtpExtension::kTOffset) {
197 RTC_CHECK_EQ(0, vie_channel_->SetSendTimestampOffsetStatus(true, id)); 191 RTC_CHECK_EQ(0, vie_channel_.SetSendTimestampOffsetStatus(true, id));
198 } else if (extension == RtpExtension::kAbsSendTime) { 192 } else if (extension == RtpExtension::kAbsSendTime) {
199 RTC_CHECK_EQ(0, vie_channel_->SetSendAbsoluteSendTimeStatus(true, id)); 193 RTC_CHECK_EQ(0, vie_channel_.SetSendAbsoluteSendTimeStatus(true, id));
200 } else if (extension == RtpExtension::kVideoRotation) { 194 } else if (extension == RtpExtension::kVideoRotation) {
201 RTC_CHECK_EQ(0, vie_channel_->SetSendVideoRotationStatus(true, id)); 195 RTC_CHECK_EQ(0, vie_channel_.SetSendVideoRotationStatus(true, id));
202 } else if (extension == RtpExtension::kTransportSequenceNumber) { 196 } else if (extension == RtpExtension::kTransportSequenceNumber) {
203 RTC_CHECK_EQ(0, vie_channel_->SetSendTransportSequenceNumber(true, id)); 197 RTC_CHECK_EQ(0, vie_channel_.SetSendTransportSequenceNumber(true, id));
204 } else { 198 } else {
205 RTC_NOTREACHED() << "Registering unsupported RTP extension."; 199 RTC_NOTREACHED() << "Registering unsupported RTP extension.";
206 } 200 }
207 } 201 }
208 202
209 congestion_controller_->SetChannelRembStatus(true, false, 203 congestion_controller_->SetChannelRembStatus(true, false,
210 vie_channel_->rtp_rtcp()); 204 vie_channel_.rtp_rtcp());
211 205
212 // Enable NACK, FEC or both. 206 // Enable NACK, FEC or both.
213 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0; 207 const bool enable_protection_nack = config_.rtp.nack.rtp_history_ms > 0;
214 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1; 208 const bool enable_protection_fec = config_.rtp.fec.red_payload_type != -1;
215 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future. 209 // TODO(changbin): Should set RTX for RED mapping in RTP sender in future.
216 vie_channel_->SetProtectionMode(enable_protection_nack, enable_protection_fec, 210 vie_channel_.SetProtectionMode(enable_protection_nack, enable_protection_fec,
217 config_.rtp.fec.red_payload_type, 211 config_.rtp.fec.red_payload_type,
218 config_.rtp.fec.ulpfec_payload_type); 212 config_.rtp.fec.ulpfec_payload_type);
219 vie_encoder_->SetProtectionMethod(enable_protection_nack, 213 vie_encoder_.SetProtectionMethod(enable_protection_nack,
220 enable_protection_fec); 214 enable_protection_fec);
221 215
222 ConfigureSsrcs(); 216 ConfigureSsrcs();
223 217
224 vie_channel_->SetRTCPCName(config_.rtp.c_name.c_str()); 218 vie_channel_.SetRTCPCName(config_.rtp.c_name.c_str());
225
226 input_.reset(new internal::VideoCaptureInput(
227 vie_encoder_.get(), config_.local_renderer, &stats_proxy_,
228 &overuse_detector_));
229 219
230 // 28 to match packet overhead in ModuleRtpRtcpImpl. 220 // 28 to match packet overhead in ModuleRtpRtcpImpl.
231 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28)); 221 RTC_DCHECK_LE(config_.rtp.max_packet_size, static_cast<size_t>(0xFFFF - 28));
232 vie_channel_->SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28)); 222 vie_channel_.SetMTU(static_cast<uint16_t>(config_.rtp.max_packet_size + 28));
233 223
234 RTC_DCHECK(config.encoder_settings.encoder != nullptr); 224 RTC_DCHECK(config.encoder_settings.encoder != nullptr);
235 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0); 225 RTC_DCHECK_GE(config.encoder_settings.payload_type, 0);
236 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127); 226 RTC_DCHECK_LE(config.encoder_settings.payload_type, 127);
237 RTC_CHECK_EQ(0, vie_encoder_->RegisterExternalEncoder( 227 RTC_CHECK_EQ(0, vie_encoder_.RegisterExternalEncoder(
238 config.encoder_settings.encoder, 228 config.encoder_settings.encoder,
239 config.encoder_settings.payload_type, 229 config.encoder_settings.payload_type,
240 config.encoder_settings.internal_source)); 230 config.encoder_settings.internal_source));
241 231
242 RTC_CHECK(ReconfigureVideoEncoder(encoder_config)); 232 RTC_CHECK(ReconfigureVideoEncoder(encoder_config));
243 233
244 vie_channel_->RegisterSendSideDelayObserver(&stats_proxy_); 234 vie_channel_.RegisterSendSideDelayObserver(&stats_proxy_);
245 235
246 if (config_.post_encode_callback) 236 if (config_.post_encode_callback)
247 vie_encoder_->RegisterPostEncodeImageCallback(&encoded_frame_proxy_); 237 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_);
248 238
249 if (config_.suspend_below_min_bitrate) 239 if (config_.suspend_below_min_bitrate)
250 vie_encoder_->SuspendBelowMinBitrate(); 240 vie_encoder_.SuspendBelowMinBitrate();
251 241
252 congestion_controller_->AddEncoder(vie_encoder_.get()); 242 congestion_controller_->AddEncoder(&vie_encoder_);
253 encoder_feedback_->AddEncoder(ssrcs, vie_encoder_.get()); 243 encoder_feedback_.AddEncoder(config_.rtp.ssrcs, &vie_encoder_);
254 244
255 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_); 245 vie_channel_.RegisterSendChannelRtcpStatisticsCallback(&stats_proxy_);
256 vie_channel_->RegisterSendChannelRtpStatisticsCallback(&stats_proxy_); 246 vie_channel_.RegisterSendChannelRtpStatisticsCallback(&stats_proxy_);
257 vie_channel_->RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); 247 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_);
258 vie_channel_->RegisterSendBitrateObserver(&stats_proxy_); 248 vie_channel_.RegisterSendBitrateObserver(&stats_proxy_);
259 vie_channel_->RegisterSendFrameCountObserver(&stats_proxy_); 249 vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_);
260 250
261 module_process_thread_->RegisterModule(&overuse_detector_); 251 module_process_thread_->RegisterModule(&overuse_detector_);
262 } 252 }
263 253
264 VideoSendStream::~VideoSendStream() { 254 VideoSendStream::~VideoSendStream() {
265 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); 255 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString();
266 module_process_thread_->DeRegisterModule(&overuse_detector_); 256 module_process_thread_->DeRegisterModule(&overuse_detector_);
267 // Remove vcm_protection_callback (part of vie_channel_) before destroying 257 // Remove vcm_protection_callback (part of vie_channel_) before destroying
268 // ViEChannel. vcm_ is owned by ViEEncoder and the registered callback does 258 // ViEChannel. vcm_ is owned by ViEEncoder and the registered callback does
269 // not outlive it. 259 // not outlive it.
270 vcm_->RegisterProtectionCallback(nullptr); 260 vcm_->RegisterProtectionCallback(nullptr);
271 vie_channel_->RegisterSendFrameCountObserver(nullptr); 261 vie_channel_.RegisterSendFrameCountObserver(nullptr);
272 vie_channel_->RegisterSendBitrateObserver(nullptr); 262 vie_channel_.RegisterSendBitrateObserver(nullptr);
273 vie_channel_->RegisterRtcpPacketTypeCounterObserver(nullptr); 263 vie_channel_.RegisterRtcpPacketTypeCounterObserver(nullptr);
274 vie_channel_->RegisterSendChannelRtpStatisticsCallback(nullptr); 264 vie_channel_.RegisterSendChannelRtpStatisticsCallback(nullptr);
275 vie_channel_->RegisterSendChannelRtcpStatisticsCallback(nullptr); 265 vie_channel_.RegisterSendChannelRtcpStatisticsCallback(nullptr);
276 266
277 // Remove capture input (thread) so that it's not running after the current 267 vie_encoder_.DeRegisterExternalEncoder(
278 // channel is deleted.
279 input_.reset();
280
281 vie_encoder_->DeRegisterExternalEncoder(
282 config_.encoder_settings.payload_type); 268 config_.encoder_settings.payload_type);
283 269
284 call_stats_->DeregisterStatsObserver(vie_channel_->GetStatsObserver()); 270 call_stats_->DeregisterStatsObserver(vie_channel_.GetStatsObserver());
285 congestion_controller_->SetChannelRembStatus(false, false, 271 congestion_controller_->SetChannelRembStatus(false, false,
286 vie_channel_->rtp_rtcp()); 272 vie_channel_.rtp_rtcp());
287 273
288 // Remove the feedback, stop all encoding threads and processing. This must be 274 // Remove the feedback, stop all encoding threads and processing. This must be
289 // done before deleting the channel. 275 // done before deleting the channel.
290 congestion_controller_->RemoveEncoder(vie_encoder_.get()); 276 congestion_controller_->RemoveEncoder(&vie_encoder_);
291 encoder_feedback_->RemoveEncoder(vie_encoder_.get()); 277 encoder_feedback_.RemoveEncoder(&vie_encoder_);
292 278
293 uint32_t remote_ssrc = vie_channel_->GetRemoteSSRC(); 279 uint32_t remote_ssrc = vie_channel_.GetRemoteSSRC();
294 congestion_controller_->GetRemoteBitrateEstimator(false)->RemoveStream( 280 congestion_controller_->GetRemoteBitrateEstimator(false)->RemoveStream(
295 remote_ssrc); 281 remote_ssrc);
296 } 282 }
297 283
298 VideoCaptureInput* VideoSendStream::Input() { 284 VideoCaptureInput* VideoSendStream::Input() {
299 return input_.get(); 285 return &input_;
300 } 286 }
301 287
302 void VideoSendStream::Start() { 288 void VideoSendStream::Start() {
303 transport_adapter_.Enable(); 289 transport_adapter_.Enable();
304 vie_encoder_->Pause(); 290 vie_encoder_.Pause();
305 if (vie_channel_->StartSend() == 0) { 291 if (vie_channel_.StartSend() == 0) {
306 // Was not already started, trigger a keyframe. 292 // Was not already started, trigger a keyframe.
307 vie_encoder_->SendKeyFrame(); 293 vie_encoder_.SendKeyFrame();
308 } 294 }
309 vie_encoder_->Restart(); 295 vie_encoder_.Restart();
310 vie_channel_->StartReceive(); 296 vie_channel_.StartReceive();
311 } 297 }
312 298
313 void VideoSendStream::Stop() { 299 void VideoSendStream::Stop() {
314 // TODO(pbos): Make sure the encoder stops here. 300 // TODO(pbos): Make sure the encoder stops here.
315 vie_channel_->StopSend(); 301 vie_channel_.StopSend();
316 vie_channel_->StopReceive(); 302 vie_channel_.StopReceive();
317 transport_adapter_.Disable(); 303 transport_adapter_.Disable();
318 } 304 }
319 305
320 bool VideoSendStream::ReconfigureVideoEncoder( 306 bool VideoSendStream::ReconfigureVideoEncoder(
321 const VideoEncoderConfig& config) { 307 const VideoEncoderConfig& config) {
322 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder"); 308 TRACE_EVENT0("webrtc", "VideoSendStream::(Re)configureVideoEncoder");
323 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString(); 309 LOG(LS_INFO) << "(Re)configureVideoEncoder: " << config.ToString();
324 const std::vector<VideoStream>& streams = config.streams; 310 const std::vector<VideoStream>& streams = config.streams;
325 RTC_DCHECK(!streams.empty()); 311 RTC_DCHECK(!streams.empty());
326 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size()); 312 RTC_DCHECK_GE(config_.rtp.ssrcs.size(), streams.size());
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 442
457 // Clear stats for disabled layers. 443 // Clear stats for disabled layers.
458 for (size_t i = video_codec.numberOfSimulcastStreams; 444 for (size_t i = video_codec.numberOfSimulcastStreams;
459 i < config_.rtp.ssrcs.size(); ++i) { 445 i < config_.rtp.ssrcs.size(); ++i) {
460 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]); 446 stats_proxy_.OnInactiveSsrc(config_.rtp.ssrcs[i]);
461 } 447 }
462 448
463 stats_proxy_.SetContentType(config.content_type); 449 stats_proxy_.SetContentType(config.content_type);
464 450
465 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0); 451 RTC_DCHECK_GE(config.min_transmit_bitrate_bps, 0);
466 vie_encoder_->SetMinTransmitBitrate(config.min_transmit_bitrate_bps / 1000); 452 vie_encoder_.SetMinTransmitBitrate(config.min_transmit_bitrate_bps / 1000);
467 453
468 encoder_config_ = config; 454 encoder_config_ = config;
469 use_config_bitrate_ = false;
470 return true; 455 return true;
471 } 456 }
472 457
473 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { 458 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) {
474 return vie_channel_->ReceivedRTCPPacket(packet, length) == 0; 459 return vie_channel_.ReceivedRTCPPacket(packet, length) == 0;
475 } 460 }
476 461
477 VideoSendStream::Stats VideoSendStream::GetStats() { 462 VideoSendStream::Stats VideoSendStream::GetStats() {
478 return stats_proxy_.GetStats(); 463 return stats_proxy_.GetStats();
479 } 464 }
480 465
481 void VideoSendStream::OveruseDetected() { 466 void VideoSendStream::OveruseDetected() {
482 if (config_.overuse_callback) 467 if (config_.overuse_callback)
483 config_.overuse_callback->OnLoadUpdate(LoadObserver::kOveruse); 468 config_.overuse_callback->OnLoadUpdate(LoadObserver::kOveruse);
484 } 469 }
485 470
486 void VideoSendStream::NormalUsage() { 471 void VideoSendStream::NormalUsage() {
487 if (config_.overuse_callback) 472 if (config_.overuse_callback)
488 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse); 473 config_.overuse_callback->OnLoadUpdate(LoadObserver::kUnderuse);
489 } 474 }
490 475
491 void VideoSendStream::ConfigureSsrcs() { 476 void VideoSendStream::ConfigureSsrcs() {
492 vie_channel_->SetSSRC(config_.rtp.ssrcs.front(), kViEStreamTypeNormal, 0); 477 vie_channel_.SetSSRC(config_.rtp.ssrcs.front(), kViEStreamTypeNormal, 0);
493 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { 478 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) {
494 uint32_t ssrc = config_.rtp.ssrcs[i]; 479 uint32_t ssrc = config_.rtp.ssrcs[i];
495 vie_channel_->SetSSRC(ssrc, kViEStreamTypeNormal, 480 vie_channel_.SetSSRC(ssrc, kViEStreamTypeNormal,
496 static_cast<unsigned char>(i)); 481 static_cast<unsigned char>(i));
497 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc); 482 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc);
498 if (it != suspended_ssrcs_.end()) 483 if (it != suspended_ssrcs_.end())
499 vie_channel_->SetRtpStateForSsrc(ssrc, it->second); 484 vie_channel_.SetRtpStateForSsrc(ssrc, it->second);
500 } 485 }
501 486
502 if (config_.rtp.rtx.ssrcs.empty()) { 487 if (config_.rtp.rtx.ssrcs.empty()) {
503 return; 488 return;
504 } 489 }
505 490
506 // Set up RTX. 491 // Set up RTX.
507 RTC_DCHECK_EQ(config_.rtp.rtx.ssrcs.size(), config_.rtp.ssrcs.size()); 492 RTC_DCHECK_EQ(config_.rtp.rtx.ssrcs.size(), config_.rtp.ssrcs.size());
508 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) { 493 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) {
509 uint32_t ssrc = config_.rtp.rtx.ssrcs[i]; 494 uint32_t ssrc = config_.rtp.rtx.ssrcs[i];
510 vie_channel_->SetSSRC(config_.rtp.rtx.ssrcs[i], kViEStreamTypeRtx, 495 vie_channel_.SetSSRC(config_.rtp.rtx.ssrcs[i], kViEStreamTypeRtx,
511 static_cast<unsigned char>(i)); 496 static_cast<unsigned char>(i));
512 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc); 497 RtpStateMap::iterator it = suspended_ssrcs_.find(ssrc);
513 if (it != suspended_ssrcs_.end()) 498 if (it != suspended_ssrcs_.end())
514 vie_channel_->SetRtpStateForSsrc(ssrc, it->second); 499 vie_channel_.SetRtpStateForSsrc(ssrc, it->second);
515 } 500 }
516 501
517 RTC_DCHECK_GE(config_.rtp.rtx.payload_type, 0); 502 RTC_DCHECK_GE(config_.rtp.rtx.payload_type, 0);
518 vie_channel_->SetRtxSendPayloadType(config_.rtp.rtx.payload_type, 503 vie_channel_.SetRtxSendPayloadType(config_.rtp.rtx.payload_type,
519 config_.encoder_settings.payload_type); 504 config_.encoder_settings.payload_type);
520 if (config_.rtp.fec.red_payload_type != -1 && 505 if (config_.rtp.fec.red_payload_type != -1 &&
521 config_.rtp.fec.red_rtx_payload_type != -1) { 506 config_.rtp.fec.red_rtx_payload_type != -1) {
522 vie_channel_->SetRtxSendPayloadType(config_.rtp.fec.red_rtx_payload_type, 507 vie_channel_.SetRtxSendPayloadType(config_.rtp.fec.red_rtx_payload_type,
523 config_.rtp.fec.red_payload_type); 508 config_.rtp.fec.red_payload_type);
524 } 509 }
525 } 510 }
526 511
527 std::map<uint32_t, RtpState> VideoSendStream::GetRtpStates() const { 512 std::map<uint32_t, RtpState> VideoSendStream::GetRtpStates() const {
528 std::map<uint32_t, RtpState> rtp_states; 513 std::map<uint32_t, RtpState> rtp_states;
529 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) { 514 for (size_t i = 0; i < config_.rtp.ssrcs.size(); ++i) {
530 uint32_t ssrc = config_.rtp.ssrcs[i]; 515 uint32_t ssrc = config_.rtp.ssrcs[i];
531 rtp_states[ssrc] = vie_channel_->GetRtpStateForSsrc(ssrc); 516 rtp_states[ssrc] = vie_channel_.GetRtpStateForSsrc(ssrc);
532 } 517 }
533 518
534 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) { 519 for (size_t i = 0; i < config_.rtp.rtx.ssrcs.size(); ++i) {
535 uint32_t ssrc = config_.rtp.rtx.ssrcs[i]; 520 uint32_t ssrc = config_.rtp.rtx.ssrcs[i];
536 rtp_states[ssrc] = vie_channel_->GetRtpStateForSsrc(ssrc); 521 rtp_states[ssrc] = vie_channel_.GetRtpStateForSsrc(ssrc);
537 } 522 }
538 523
539 return rtp_states; 524 return rtp_states;
540 } 525 }
541 526
542 void VideoSendStream::SignalNetworkState(NetworkState state) { 527 void VideoSendStream::SignalNetworkState(NetworkState state) {
543 // When network goes up, enable RTCP status before setting transmission state. 528 // When network goes up, enable RTCP status before setting transmission state.
544 // When it goes down, disable RTCP afterwards. This ensures that any packets 529 // When it goes down, disable RTCP afterwards. This ensures that any packets
545 // sent due to the network state changed will not be dropped. 530 // sent due to the network state changed will not be dropped.
546 if (state == kNetworkUp) 531 if (state == kNetworkUp)
547 vie_channel_->SetRTCPMode(config_.rtp.rtcp_mode); 532 vie_channel_.SetRTCPMode(config_.rtp.rtcp_mode);
548 vie_encoder_->SetNetworkTransmissionState(state == kNetworkUp); 533 vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp);
549 if (state == kNetworkDown) 534 if (state == kNetworkDown)
550 vie_channel_->SetRTCPMode(RtcpMode::kOff); 535 vie_channel_.SetRTCPMode(RtcpMode::kOff);
551 } 536 }
552 537
553 int64_t VideoSendStream::GetRtt() const { 538 int64_t VideoSendStream::GetRtt() const {
554 webrtc::RtcpStatistics rtcp_stats; 539 webrtc::RtcpStatistics rtcp_stats;
555 uint16_t frac_lost; 540 uint16_t frac_lost;
556 uint32_t cumulative_lost; 541 uint32_t cumulative_lost;
557 uint32_t extended_max_sequence_number; 542 uint32_t extended_max_sequence_number;
558 uint32_t jitter; 543 uint32_t jitter;
559 int64_t rtt_ms; 544 int64_t rtt_ms;
560 if (vie_channel_->GetSendRtcpStatistics(&frac_lost, &cumulative_lost, 545 if (vie_channel_.GetSendRtcpStatistics(&frac_lost, &cumulative_lost,
561 &extended_max_sequence_number, 546 &extended_max_sequence_number,
562 &jitter, &rtt_ms) == 0) { 547 &jitter, &rtt_ms) == 0) {
563 return rtt_ms; 548 return rtt_ms;
564 } 549 }
565 return -1; 550 return -1;
566 } 551 }
567 552
568 int VideoSendStream::GetPaddingNeededBps() const { 553 int VideoSendStream::GetPaddingNeededBps() const {
569 return vie_encoder_->GetPaddingNeededBps(); 554 return vie_encoder_.GetPaddingNeededBps();
570 } 555 }
571 556
572 bool VideoSendStream::SetSendCodec(VideoCodec video_codec) { 557 bool VideoSendStream::SetSendCodec(VideoCodec video_codec) {
573 static const int kEncoderMinBitrate = 30; 558 static const int kEncoderMinBitrate = 30;
574 if (video_codec.maxBitrate == 0) { 559 if (video_codec.maxBitrate == 0) {
575 // Unset max bitrate -> cap to one bit per pixel. 560 // Unset max bitrate -> cap to one bit per pixel.
576 video_codec.maxBitrate = 561 video_codec.maxBitrate =
577 (video_codec.width * video_codec.height * video_codec.maxFramerate) / 562 (video_codec.width * video_codec.height * video_codec.maxFramerate) /
578 1000; 563 1000;
579 } 564 }
580 565
581 if (video_codec.minBitrate < kEncoderMinBitrate) 566 if (video_codec.minBitrate < kEncoderMinBitrate)
582 video_codec.minBitrate = kEncoderMinBitrate; 567 video_codec.minBitrate = kEncoderMinBitrate;
583 if (video_codec.maxBitrate < kEncoderMinBitrate) 568 if (video_codec.maxBitrate < kEncoderMinBitrate)
584 video_codec.maxBitrate = kEncoderMinBitrate; 569 video_codec.maxBitrate = kEncoderMinBitrate;
585 570
586 // Stop the media flow while reconfiguring. 571 // Stop the media flow while reconfiguring.
587 vie_encoder_->Pause(); 572 vie_encoder_.Pause();
588 573
589 if (vie_encoder_->SetEncoder(video_codec) != 0) { 574 if (vie_encoder_.SetEncoder(video_codec) != 0) {
590 LOG(LS_ERROR) << "Failed to set encoder."; 575 LOG(LS_ERROR) << "Failed to set encoder.";
591 return false; 576 return false;
592 } 577 }
593 578
594 if (vie_channel_->SetSendCodec(video_codec, false) != 0) { 579 if (vie_channel_.SetSendCodec(video_codec, false) != 0) {
595 LOG(LS_ERROR) << "Failed to set send codec."; 580 LOG(LS_ERROR) << "Failed to set send codec.";
596 return false; 581 return false;
597 } 582 }
598 583
599 // Not all configured SSRCs have to be utilized (simulcast senders don't have 584 // Not all configured SSRCs have to be utilized (simulcast senders don't have
600 // to send on all SSRCs at once etc.) 585 // to send on all SSRCs at once etc.)
601 std::vector<uint32_t> used_ssrcs = config_.rtp.ssrcs; 586 std::vector<uint32_t> used_ssrcs = config_.rtp.ssrcs;
602 used_ssrcs.resize(static_cast<size_t>(video_codec.numberOfSimulcastStreams)); 587 used_ssrcs.resize(static_cast<size_t>(video_codec.numberOfSimulcastStreams));
603 vie_encoder_->SetSsrcs(used_ssrcs); 588 vie_encoder_.SetSsrcs(used_ssrcs);
604 589
605 // Restart the media flow 590 // Restart the media flow
606 vie_encoder_->Restart(); 591 vie_encoder_.Restart();
607 592
608 return true; 593 return true;
609 } 594 }
610 595
596 TransportFeedbackObserver* VideoSendStream::GetTransportFeedbackObserver()
597 const {
598 // Set up Call-wide sequence numbers, if configured for this send stream.
599 for (const RtpExtension& extension : config_.rtp.extensions) {
600 if (extension.name == RtpExtension::kTransportSequenceNumber) {
601 return congestion_controller_->GetTransportFeedbackObserver();
602 }
603 }
604 return nullptr;
605 }
606
611 } // namespace internal 607 } // namespace internal
612 } // namespace webrtc 608 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/video_send_stream.h ('k') | webrtc/video/vie_channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698