OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2012 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 |
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
139 num_active_rtp_rtcp_modules_(1) { | 139 num_active_rtp_rtcp_modules_(1) { |
140 vie_receiver_.SetRtpRtcpModule(rtp_rtcp_modules_[0]); | 140 vie_receiver_.SetRtpRtcpModule(rtp_rtcp_modules_[0]); |
141 vcm_->SetNackSettings(kMaxNackListSize, max_nack_reordering_threshold_, 0); | 141 vcm_->SetNackSettings(kMaxNackListSize, max_nack_reordering_threshold_, 0); |
142 } | 142 } |
143 | 143 |
144 int32_t ViEChannel::Init() { | 144 int32_t ViEChannel::Init() { |
145 static const int kDefaultRenderDelayMs = 10; | 145 static const int kDefaultRenderDelayMs = 10; |
146 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); | 146 module_process_thread_->RegisterModule(vie_receiver_.GetReceiveStatistics()); |
147 | 147 |
148 // RTP/RTCP initialization. | 148 // RTP/RTCP initialization. |
149 module_process_thread_->RegisterModule(rtp_rtcp_modules_[0]); | |
150 | |
151 rtp_rtcp_modules_[0]->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); | 149 rtp_rtcp_modules_[0]->SetKeyFrameRequestMethod(kKeyFrameReqPliRtcp); |
152 if (paced_sender_) { | 150 if (paced_sender_) { |
153 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 151 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
154 rtp_rtcp->SetStorePacketsStatus(true, nack_history_size_sender_); | 152 rtp_rtcp->SetStorePacketsStatus(true, nack_history_size_sender_); |
155 } | 153 } |
156 packet_router_->AddRtpModule(rtp_rtcp_modules_[0]); | 154 packet_router_->AddRtpModule(rtp_rtcp_modules_[0]); |
157 if (sender_) { | 155 if (sender_) { |
158 std::list<RtpRtcp*> send_rtp_modules(1, rtp_rtcp_modules_[0]); | 156 send_payload_router_->SetSendingRtpModules( |
159 send_payload_router_->SetSendingRtpModules(send_rtp_modules); | 157 std::vector<RtpRtcp*>(1, rtp_rtcp_modules_[0])); |
160 RTC_DCHECK(!send_payload_router_->active()); | 158 RTC_DCHECK(!send_payload_router_->active()); |
161 } | 159 } |
162 if (vcm_->RegisterReceiveCallback(this) != 0) { | 160 if (vcm_->RegisterReceiveCallback(this) != 0) { |
163 return -1; | 161 return -1; |
164 } | 162 } |
165 vcm_->RegisterFrameTypeCallback(this); | 163 vcm_->RegisterFrameTypeCallback(this); |
166 vcm_->RegisterReceiveStatisticsCallback(this); | 164 vcm_->RegisterReceiveStatisticsCallback(this); |
167 vcm_->RegisterDecoderTimingCallback(this); | 165 vcm_->RegisterDecoderTimingCallback(this); |
168 vcm_->SetRenderDelay(kDefaultRenderDelayMs); | 166 vcm_->SetRenderDelay(kDefaultRenderDelayMs); |
169 | 167 |
170 module_process_thread_->RegisterModule(vcm_); | 168 module_process_thread_->RegisterModule(vcm_); |
171 module_process_thread_->RegisterModule(&vie_sync_); | 169 module_process_thread_->RegisterModule(&vie_sync_); |
170 module_process_thread_->RegisterModule(this); | |
172 | 171 |
173 return 0; | 172 return 0; |
174 } | 173 } |
175 | 174 |
175 // TODO(pbos): Consider atomics, this might block. | |
176 int64_t ViEChannel::TimeUntilNextProcess() { | |
177 size_t active_modules; | |
178 { | |
179 CriticalSectionScoped cs(crit_.get()); | |
180 active_modules = num_active_rtp_rtcp_modules_; | |
181 } | |
182 | |
183 int64_t min_time = rtp_rtcp_modules_[0]->TimeUntilNextProcess(); | |
184 for (size_t i = 1; i < active_modules; ++i) { | |
185 int64_t time = rtp_rtcp_modules_[i]->TimeUntilNextProcess(); | |
186 if (time < min_time) | |
187 min_time = time; | |
188 } | |
189 return min_time; | |
190 } | |
191 | |
192 // TODO(pbos): Consider atomics, this might block. | |
193 int32_t ViEChannel::Process() { | |
194 size_t active_modules; | |
195 { | |
196 CriticalSectionScoped cs(crit_.get()); | |
197 active_modules = num_active_rtp_rtcp_modules_; | |
198 } | |
199 | |
200 for (size_t i = 0; i < active_modules; ++i) { | |
201 rtp_rtcp_modules_[i]->Process(); | |
202 } | |
203 return 0; | |
204 } | |
stefan-webrtc
2016/01/19 12:02:10
Could you enlighten why this was necessary to chan
pbos-webrtc
2016/01/19 15:27:58
I can only add/remove modules from the constructio
stefan-webrtc
2016/01/20 12:22:48
I don't think I fully understand. How is the proce
stefan-webrtc
2016/01/27 09:06:43
Ping
| |
205 | |
176 ViEChannel::~ViEChannel() { | 206 ViEChannel::~ViEChannel() { |
177 UpdateHistograms(); | 207 UpdateHistograms(); |
178 // Make sure we don't get more callbacks from the RTP module. | 208 // Make sure we don't get more callbacks from the RTP module. |
209 module_process_thread_->DeRegisterModule(this); | |
179 module_process_thread_->DeRegisterModule( | 210 module_process_thread_->DeRegisterModule( |
180 vie_receiver_.GetReceiveStatistics()); | 211 vie_receiver_.GetReceiveStatistics()); |
181 module_process_thread_->DeRegisterModule(vcm_); | 212 module_process_thread_->DeRegisterModule(vcm_); |
182 module_process_thread_->DeRegisterModule(&vie_sync_); | 213 module_process_thread_->DeRegisterModule(&vie_sync_); |
183 send_payload_router_->SetSendingRtpModules(std::list<RtpRtcp*>()); | 214 send_payload_router_->SetSendingRtpModules(std::vector<RtpRtcp*>()); |
184 for (size_t i = 0; i < num_active_rtp_rtcp_modules_; ++i) | 215 for (size_t i = 0; i < num_active_rtp_rtcp_modules_; ++i) |
185 packet_router_->RemoveRtpModule(rtp_rtcp_modules_[i]); | 216 packet_router_->RemoveRtpModule(rtp_rtcp_modules_[i]); |
186 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 217 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
187 module_process_thread_->DeRegisterModule(rtp_rtcp); | 218 module_process_thread_->DeRegisterModule(rtp_rtcp); |
188 delete rtp_rtcp; | 219 delete rtp_rtcp; |
189 } | 220 } |
190 if (!sender_) | 221 if (!sender_) |
191 StopDecodeThread(); | 222 StopDecodeThread(); |
192 // Release modules. | 223 // Release modules. |
193 VideoCodingModule::Destroy(vcm_); | 224 VideoCodingModule::Destroy(vcm_); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
330 if (vie_receiver_.IsFecEnabled()) { | 361 if (vie_receiver_.IsFecEnabled()) { |
331 RTC_HISTOGRAM_COUNTS_SPARSE_10000( | 362 RTC_HISTOGRAM_COUNTS_SPARSE_10000( |
332 "WebRTC.Video.FecBitrateReceivedInKbps", | 363 "WebRTC.Video.FecBitrateReceivedInKbps", |
333 static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / | 364 static_cast<int>(rtp_rtx.fec.TotalBytes() * 8 / elapsed_sec / |
334 1000)); | 365 1000)); |
335 } | 366 } |
336 } | 367 } |
337 } | 368 } |
338 } | 369 } |
339 | 370 |
340 int32_t ViEChannel::SetSendCodec(const VideoCodec& video_codec, | 371 void ViEChannel::SetSendCodec(const VideoCodec& video_codec) { |
stefan-webrtc
2016/01/19 12:02:10
Should we check what thread this is being called o
pbos-webrtc
2016/01/19 15:27:58
It'd be interesting to inject thread checkers from
stefan-webrtc
2016/01/20 12:22:48
Can't you have a separate thread checker?
| |
341 bool new_stream) { | 372 // Here crit_ is used to synchronize between this method, StartSend and |
373 // StopSend and not end up in an inconsistent sending state. | |
374 CriticalSectionScoped cs(crit_.get()); | |
342 RTC_DCHECK(sender_); | 375 RTC_DCHECK(sender_); |
343 if (video_codec.codecType == kVideoCodecRED || | 376 RTC_DCHECK(video_codec.codecType != kVideoCodecRED); |
344 video_codec.codecType == kVideoCodecULPFEC) { | 377 RTC_DCHECK(video_codec.codecType != kVideoCodecULPFEC); |
345 LOG_F(LS_ERROR) << "Not a valid send codec " << video_codec.codecType; | 378 RTC_DCHECK_LE(video_codec.numberOfSimulcastStreams, kMaxSimulcastStreams); |
346 return -1; | |
347 } | |
348 if (kMaxSimulcastStreams < video_codec.numberOfSimulcastStreams) { | |
349 LOG_F(LS_ERROR) << "Incorrect config " | |
350 << video_codec.numberOfSimulcastStreams; | |
351 return -1; | |
352 } | |
353 // Update the RTP module with the settings. | 379 // Update the RTP module with the settings. |
354 // Stop and Start the RTP module -> trigger new SSRC, if an SSRC hasn't been | 380 // Stop and Start the RTP module -> trigger new SSRC, if an SSRC hasn't been |
355 // set explicitly. | 381 // set explicitly. |
356 // The first layer is always active, so the first module can be checked for | 382 // The first layer is always active, so the first module can be checked for |
357 // sending status. | 383 // sending status. |
358 bool is_sending = rtp_rtcp_modules_[0]->Sending(); | |
359 bool router_was_active = send_payload_router_->active(); | 384 bool router_was_active = send_payload_router_->active(); |
360 send_payload_router_->set_active(false); | 385 send_payload_router_->set_active(false); |
361 send_payload_router_->SetSendingRtpModules(std::list<RtpRtcp*>()); | 386 send_payload_router_->SetSendingRtpModules(std::vector<RtpRtcp*>()); |
362 | 387 |
388 size_t num_prev_active_modules = num_active_rtp_rtcp_modules_; | |
389 num_active_rtp_rtcp_modules_ = video_codec.numberOfSimulcastStreams > 0 | |
390 ? video_codec.numberOfSimulcastStreams | |
391 : 1; | |
363 std::vector<RtpRtcp*> registered_modules; | 392 std::vector<RtpRtcp*> registered_modules; |
364 std::vector<RtpRtcp*> deregistered_modules; | 393 for (size_t i = 0; i < num_active_rtp_rtcp_modules_; ++i) |
365 size_t num_active_modules = video_codec.numberOfSimulcastStreams > 0 | |
366 ? video_codec.numberOfSimulcastStreams | |
367 : 1; | |
368 size_t num_prev_active_modules; | |
369 { | |
370 // Cache which modules are active so StartSend can know which ones to start. | |
371 CriticalSectionScoped cs(crit_.get()); | |
372 num_prev_active_modules = num_active_rtp_rtcp_modules_; | |
373 num_active_rtp_rtcp_modules_ = num_active_modules; | |
374 } | |
375 for (size_t i = 0; i < num_active_modules; ++i) | |
376 registered_modules.push_back(rtp_rtcp_modules_[i]); | 394 registered_modules.push_back(rtp_rtcp_modules_[i]); |
377 | 395 |
378 for (size_t i = num_active_modules; i < rtp_rtcp_modules_.size(); ++i) | |
379 deregistered_modules.push_back(rtp_rtcp_modules_[i]); | |
380 | |
381 // Disable inactive modules. | 396 // Disable inactive modules. |
382 for (RtpRtcp* rtp_rtcp : deregistered_modules) { | 397 for (size_t i = num_active_rtp_rtcp_modules_; i < rtp_rtcp_modules_.size(); |
398 ++i) { | |
399 RtpRtcp* const rtp_rtcp = rtp_rtcp_modules_[i]; | |
383 rtp_rtcp->SetSendingStatus(false); | 400 rtp_rtcp->SetSendingStatus(false); |
384 rtp_rtcp->SetSendingMediaStatus(false); | 401 rtp_rtcp->SetSendingMediaStatus(false); |
385 } | 402 } |
386 | 403 |
387 // Configure active modules. | 404 // Configure active modules. |
405 bool is_sending = rtp_rtcp_modules_[0]->Sending(); | |
388 for (RtpRtcp* rtp_rtcp : registered_modules) { | 406 for (RtpRtcp* rtp_rtcp : registered_modules) { |
389 rtp_rtcp->DeRegisterSendPayload(video_codec.plType); | 407 rtp_rtcp->DeRegisterSendPayload(video_codec.plType); |
390 if (rtp_rtcp->RegisterSendPayload(video_codec) != 0) { | 408 RTC_CHECK_EQ(0, rtp_rtcp->RegisterSendPayload(video_codec)); |
391 return -1; | |
392 } | |
393 rtp_rtcp->SetSendingStatus(is_sending); | 409 rtp_rtcp->SetSendingStatus(is_sending); |
394 rtp_rtcp->SetSendingMediaStatus(is_sending); | 410 rtp_rtcp->SetSendingMediaStatus(is_sending); |
395 } | 411 } |
396 | 412 |
397 // |RegisterSimulcastRtpRtcpModules| resets all old weak pointers and old | |
398 // modules can be deleted after this step. | |
399 vie_receiver_.RegisterRtpRtcpModules(registered_modules); | 413 vie_receiver_.RegisterRtpRtcpModules(registered_modules); |
400 | 414 |
401 // Update the packet and payload routers with the sending RtpRtcp modules. | |
402 if (sender_) { | |
403 std::list<RtpRtcp*> active_send_modules; | |
404 for (RtpRtcp* rtp_rtcp : registered_modules) | |
405 active_send_modules.push_back(rtp_rtcp); | |
406 send_payload_router_->SetSendingRtpModules(active_send_modules); | |
407 } | |
408 | |
409 if (router_was_active) | |
410 send_payload_router_->set_active(true); | |
411 | 415 |
412 // Deregister previously registered modules. | 416 // Deregister previously registered modules. |
413 for (size_t i = num_active_modules; i < num_prev_active_modules; ++i) { | 417 for (size_t i = num_active_rtp_rtcp_modules_; i < num_prev_active_modules; |
414 module_process_thread_->DeRegisterModule(rtp_rtcp_modules_[i]); | 418 ++i) { |
415 packet_router_->RemoveRtpModule(rtp_rtcp_modules_[i]); | 419 packet_router_->RemoveRtpModule(rtp_rtcp_modules_[i]); |
416 } | 420 } |
417 // Register new active modules. | 421 // Register new active modules. |
418 for (size_t i = num_prev_active_modules; i < num_active_modules; ++i) { | 422 for (size_t i = num_prev_active_modules; i < num_active_rtp_rtcp_modules_; |
419 module_process_thread_->RegisterModule(rtp_rtcp_modules_[i]); | 423 ++i) { |
420 packet_router_->AddRtpModule(rtp_rtcp_modules_[i]); | 424 packet_router_->AddRtpModule(rtp_rtcp_modules_[i]); |
421 } | 425 } |
422 return 0; | 426 |
427 // Update the packet and payload routers with the sending RtpRtcp modules. | |
428 send_payload_router_->SetSendingRtpModules(registered_modules); | |
429 if (router_was_active) | |
430 send_payload_router_->set_active(true); | |
423 } | 431 } |
stefan-webrtc
2016/01/19 12:02:10
When reading the changes for this method I can't s
pbos-webrtc
2016/01/19 15:27:58
Yes, and move crit_ to cover the entire function (
stefan-webrtc
2016/01/20 12:22:48
Ok!
| |
424 | 432 |
425 int32_t ViEChannel::SetReceiveCodec(const VideoCodec& video_codec) { | 433 int32_t ViEChannel::SetReceiveCodec(const VideoCodec& video_codec) { |
426 RTC_DCHECK(!sender_); | 434 RTC_DCHECK(!sender_); |
427 if (!vie_receiver_.SetReceiveCodec(video_codec)) { | 435 if (!vie_receiver_.SetReceiveCodec(video_codec)) { |
428 return -1; | 436 return -1; |
429 } | 437 } |
430 | 438 |
431 if (video_codec.codecType != kVideoCodecRED && | 439 if (video_codec.codecType != kVideoCodecRED && |
432 video_codec.codecType != kVideoCodecULPFEC) { | 440 video_codec.codecType != kVideoCodecULPFEC) { |
433 // Register codec type with VCM, but do not register RED or ULPFEC. | 441 // Register codec type with VCM, but do not register RED or ULPFEC. |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
893 for (size_t i = 0; i < num_active_rtp_rtcp_modules_; ++i) { | 901 for (size_t i = 0; i < num_active_rtp_rtcp_modules_; ++i) { |
894 RtpRtcp* rtp_rtcp = rtp_rtcp_modules_[i]; | 902 RtpRtcp* rtp_rtcp = rtp_rtcp_modules_[i]; |
895 rtp_rtcp->SetSendingMediaStatus(true); | 903 rtp_rtcp->SetSendingMediaStatus(true); |
896 rtp_rtcp->SetSendingStatus(true); | 904 rtp_rtcp->SetSendingStatus(true); |
897 } | 905 } |
898 send_payload_router_->set_active(true); | 906 send_payload_router_->set_active(true); |
899 return 0; | 907 return 0; |
900 } | 908 } |
901 | 909 |
902 int32_t ViEChannel::StopSend() { | 910 int32_t ViEChannel::StopSend() { |
911 // Acquire crit_ to synchronize sending status with StartSend and | |
912 // SetSendCodec. | |
913 CriticalSectionScoped cs(crit_.get()); | |
903 send_payload_router_->set_active(false); | 914 send_payload_router_->set_active(false); |
904 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 915 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
905 rtp_rtcp->SetSendingMediaStatus(false); | 916 rtp_rtcp->SetSendingMediaStatus(false); |
906 | 917 |
907 if (!rtp_rtcp_modules_[0]->Sending()) { | 918 if (!rtp_rtcp_modules_[0]->Sending()) { |
908 return -1; | 919 return -1; |
909 } | 920 } |
910 | 921 |
911 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { | 922 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) { |
912 rtp_rtcp->SetSendingStatus(false); | 923 rtp_rtcp->SetSendingStatus(false); |
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1209 CriticalSectionScoped cs(crit_.get()); | 1220 CriticalSectionScoped cs(crit_.get()); |
1210 receive_stats_callback_ = receive_statistics_proxy; | 1221 receive_stats_callback_ = receive_statistics_proxy; |
1211 } | 1222 } |
1212 | 1223 |
1213 void ViEChannel::SetIncomingVideoStream( | 1224 void ViEChannel::SetIncomingVideoStream( |
1214 IncomingVideoStream* incoming_video_stream) { | 1225 IncomingVideoStream* incoming_video_stream) { |
1215 CriticalSectionScoped cs(crit_.get()); | 1226 CriticalSectionScoped cs(crit_.get()); |
1216 incoming_video_stream_ = incoming_video_stream; | 1227 incoming_video_stream_ = incoming_video_stream; |
1217 } | 1228 } |
1218 } // namespace webrtc | 1229 } // namespace webrtc |
OLD | NEW |