| 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 11 matching lines...) Expand all Loading... |
| 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" | 22 #include "webrtc/common_video/libyuv/include/webrtc_libyuv.h" |
| 23 #include "webrtc/frame_callback.h" | 23 #include "webrtc/frame_callback.h" |
| 24 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" | 24 #include "webrtc/modules/bitrate_controller/include/bitrate_controller.h" |
| 25 #include "webrtc/modules/pacing/paced_sender.h" | 25 #include "webrtc/modules/pacing/paced_sender.h" |
| 26 #include "webrtc/modules/utility/include/process_thread.h" | 26 #include "webrtc/modules/utility/include/process_thread.h" |
| 27 #include "webrtc/modules/video_coding/include/video_codec_interface.h" | 27 #include "webrtc/modules/video_coding/include/video_codec_interface.h" |
| 28 #include "webrtc/modules/video_coding/include/video_coding.h" | 28 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 29 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 29 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 30 #include "webrtc/modules/video_coding/encoded_frame.h" | 30 #include "webrtc/modules/video_coding/encoded_frame.h" |
| 31 #include "webrtc/system_wrappers/include/clock.h" | 31 #include "webrtc/system_wrappers/include/clock.h" |
| 32 #include "webrtc/system_wrappers/include/critical_section_wrapper.h" | |
| 33 #include "webrtc/system_wrappers/include/metrics.h" | 32 #include "webrtc/system_wrappers/include/metrics.h" |
| 34 #include "webrtc/system_wrappers/include/tick_util.h" | 33 #include "webrtc/system_wrappers/include/tick_util.h" |
| 35 #include "webrtc/video/payload_router.h" | 34 #include "webrtc/video/payload_router.h" |
| 36 #include "webrtc/video/send_statistics_proxy.h" | 35 #include "webrtc/video/send_statistics_proxy.h" |
| 37 | 36 |
| 38 namespace webrtc { | 37 namespace webrtc { |
| 39 | 38 |
| 40 // Margin on when we pause the encoder when the pacing buffer overflows relative | 39 // Margin on when we pause the encoder when the pacing buffer overflows relative |
| 41 // to the configured buffer delay. | 40 // to the configured buffer delay. |
| 42 static const float kEncoderPausePacerMargin = 2.0f; | 41 static const float kEncoderPausePacerMargin = 2.0f; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 I420FrameCallback* pre_encode_callback, | 109 I420FrameCallback* pre_encode_callback, |
| 111 PacedSender* pacer, | 110 PacedSender* pacer, |
| 112 BitrateAllocator* bitrate_allocator) | 111 BitrateAllocator* bitrate_allocator) |
| 113 : number_of_cores_(number_of_cores), | 112 : number_of_cores_(number_of_cores), |
| 114 vp_(VideoProcessing::Create()), | 113 vp_(VideoProcessing::Create()), |
| 115 qm_callback_(new QMVideoSettingsCallback(vp_.get())), | 114 qm_callback_(new QMVideoSettingsCallback(vp_.get())), |
| 116 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 115 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
| 117 this, | 116 this, |
| 118 qm_callback_.get())), | 117 qm_callback_.get())), |
| 119 send_payload_router_(NULL), | 118 send_payload_router_(NULL), |
| 120 data_cs_(CriticalSectionWrapper::CreateCriticalSection()), | |
| 121 stats_proxy_(stats_proxy), | 119 stats_proxy_(stats_proxy), |
| 122 pre_encode_callback_(pre_encode_callback), | 120 pre_encode_callback_(pre_encode_callback), |
| 123 pacer_(pacer), | 121 pacer_(pacer), |
| 124 bitrate_allocator_(bitrate_allocator), | 122 bitrate_allocator_(bitrate_allocator), |
| 125 time_of_last_frame_activity_ms_(0), | 123 time_of_last_frame_activity_ms_(0), |
| 126 encoder_config_(), | 124 encoder_config_(), |
| 127 min_transmit_bitrate_kbps_(0), | 125 min_transmit_bitrate_kbps_(0), |
| 128 last_observed_bitrate_bps_(0), | 126 last_observed_bitrate_bps_(0), |
| 129 target_delay_ms_(0), | 127 target_delay_ms_(0), |
| 130 network_is_transmitting_(true), | 128 network_is_transmitting_(true), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 if (bitrate_allocator_) | 166 if (bitrate_allocator_) |
| 169 bitrate_allocator_->RemoveBitrateObserver(bitrate_observer_.get()); | 167 bitrate_allocator_->RemoveBitrateObserver(bitrate_observer_.get()); |
| 170 module_process_thread_->DeRegisterModule(vcm_.get()); | 168 module_process_thread_->DeRegisterModule(vcm_.get()); |
| 171 } | 169 } |
| 172 | 170 |
| 173 ViEEncoder::~ViEEncoder() { | 171 ViEEncoder::~ViEEncoder() { |
| 174 } | 172 } |
| 175 | 173 |
| 176 void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { | 174 void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { |
| 177 { | 175 { |
| 178 CriticalSectionScoped cs(data_cs_.get()); | 176 rtc::CritScope lock(&data_cs_); |
| 179 network_is_transmitting_ = is_transmitting; | 177 network_is_transmitting_ = is_transmitting; |
| 180 } | 178 } |
| 181 } | 179 } |
| 182 | 180 |
| 183 void ViEEncoder::Pause() { | 181 void ViEEncoder::Pause() { |
| 184 CriticalSectionScoped cs(data_cs_.get()); | 182 rtc::CritScope lock(&data_cs_); |
| 185 encoder_paused_ = true; | 183 encoder_paused_ = true; |
| 186 } | 184 } |
| 187 | 185 |
| 188 void ViEEncoder::Restart() { | 186 void ViEEncoder::Restart() { |
| 189 CriticalSectionScoped cs(data_cs_.get()); | 187 rtc::CritScope lock(&data_cs_); |
| 190 encoder_paused_ = false; | 188 encoder_paused_ = false; |
| 191 } | 189 } |
| 192 | 190 |
| 193 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, | 191 int32_t ViEEncoder::RegisterExternalEncoder(webrtc::VideoEncoder* encoder, |
| 194 uint8_t pl_type, | 192 uint8_t pl_type, |
| 195 bool internal_source) { | 193 bool internal_source) { |
| 196 if (vcm_->RegisterExternalEncoder(encoder, pl_type, internal_source) != | 194 if (vcm_->RegisterExternalEncoder(encoder, pl_type, internal_source) != |
| 197 VCM_OK) { | 195 VCM_OK) { |
| 198 return -1; | 196 return -1; |
| 199 } | 197 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 211 RTC_DCHECK(send_payload_router_ != NULL); | 209 RTC_DCHECK(send_payload_router_ != NULL); |
| 212 // Setting target width and height for VPM. | 210 // Setting target width and height for VPM. |
| 213 if (vp_->SetTargetResolution(video_codec.width, video_codec.height, | 211 if (vp_->SetTargetResolution(video_codec.width, video_codec.height, |
| 214 video_codec.maxFramerate) != VPM_OK) { | 212 video_codec.maxFramerate) != VPM_OK) { |
| 215 return -1; | 213 return -1; |
| 216 } | 214 } |
| 217 | 215 |
| 218 // Cache codec before calling AddBitrateObserver (which calls OnNetworkChanged | 216 // Cache codec before calling AddBitrateObserver (which calls OnNetworkChanged |
| 219 // that makes use of the number of simulcast streams configured). | 217 // that makes use of the number of simulcast streams configured). |
| 220 { | 218 { |
| 221 CriticalSectionScoped cs(data_cs_.get()); | 219 rtc::CritScope lock(&data_cs_); |
| 222 encoder_config_ = video_codec; | 220 encoder_config_ = video_codec; |
| 223 } | 221 } |
| 224 | 222 |
| 225 // Add a bitrate observer to the allocator and update the start, max and | 223 // Add a bitrate observer to the allocator and update the start, max and |
| 226 // min bitrates of the bitrate controller as needed. | 224 // min bitrates of the bitrate controller as needed. |
| 227 int allocated_bitrate_bps = bitrate_allocator_->AddBitrateObserver( | 225 int allocated_bitrate_bps = bitrate_allocator_->AddBitrateObserver( |
| 228 bitrate_observer_.get(), video_codec.minBitrate * 1000, | 226 bitrate_observer_.get(), video_codec.minBitrate * 1000, |
| 229 video_codec.maxBitrate * 1000); | 227 video_codec.maxBitrate * 1000); |
| 230 | 228 |
| 231 webrtc::VideoCodec modified_video_codec = video_codec; | 229 webrtc::VideoCodec modified_video_codec = video_codec; |
| 232 modified_video_codec.startBitrate = allocated_bitrate_bps / 1000; | 230 modified_video_codec.startBitrate = allocated_bitrate_bps / 1000; |
| 233 | 231 |
| 234 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); | 232 size_t max_data_payload_length = send_payload_router_->MaxPayloadLength(); |
| 235 if (vcm_->RegisterSendCodec(&modified_video_codec, number_of_cores_, | 233 if (vcm_->RegisterSendCodec(&modified_video_codec, number_of_cores_, |
| 236 static_cast<uint32_t>(max_data_payload_length)) != | 234 static_cast<uint32_t>(max_data_payload_length)) != |
| 237 VCM_OK) { | 235 VCM_OK) { |
| 238 return -1; | 236 return -1; |
| 239 } | 237 } |
| 240 return 0; | 238 return 0; |
| 241 } | 239 } |
| 242 | 240 |
| 243 int ViEEncoder::GetPaddingNeededBps() const { | 241 int ViEEncoder::GetPaddingNeededBps() const { |
| 244 int64_t time_of_last_frame_activity_ms; | 242 int64_t time_of_last_frame_activity_ms; |
| 245 int min_transmit_bitrate_bps; | 243 int min_transmit_bitrate_bps; |
| 246 int bitrate_bps; | 244 int bitrate_bps; |
| 247 VideoCodec send_codec; | 245 VideoCodec send_codec; |
| 248 { | 246 { |
| 249 CriticalSectionScoped cs(data_cs_.get()); | 247 rtc::CritScope lock(&data_cs_); |
| 250 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || | 248 bool send_padding = encoder_config_.numberOfSimulcastStreams > 1 || |
| 251 video_suspended_ || min_transmit_bitrate_kbps_ > 0; | 249 video_suspended_ || min_transmit_bitrate_kbps_ > 0; |
| 252 if (!send_padding) | 250 if (!send_padding) |
| 253 return 0; | 251 return 0; |
| 254 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; | 252 time_of_last_frame_activity_ms = time_of_last_frame_activity_ms_; |
| 255 min_transmit_bitrate_bps = 1000 * min_transmit_bitrate_kbps_; | 253 min_transmit_bitrate_bps = 1000 * min_transmit_bitrate_kbps_; |
| 256 bitrate_bps = last_observed_bitrate_bps_; | 254 bitrate_bps = last_observed_bitrate_bps_; |
| 257 send_codec = encoder_config_; | 255 send_codec = encoder_config_; |
| 258 } | 256 } |
| 259 | 257 |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 | 336 |
| 339 void ViEEncoder::DeliverFrame(VideoFrame video_frame) { | 337 void ViEEncoder::DeliverFrame(VideoFrame video_frame) { |
| 340 RTC_DCHECK(send_payload_router_ != NULL); | 338 RTC_DCHECK(send_payload_router_ != NULL); |
| 341 if (!send_payload_router_->active()) { | 339 if (!send_payload_router_->active()) { |
| 342 // We've paused or we have no channels attached, don't waste resources on | 340 // We've paused or we have no channels attached, don't waste resources on |
| 343 // encoding. | 341 // encoding. |
| 344 return; | 342 return; |
| 345 } | 343 } |
| 346 VideoCodecType codec_type; | 344 VideoCodecType codec_type; |
| 347 { | 345 { |
| 348 CriticalSectionScoped cs(data_cs_.get()); | 346 rtc::CritScope lock(&data_cs_); |
| 349 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 347 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); |
| 350 if (EncoderPaused()) { | 348 if (EncoderPaused()) { |
| 351 TraceFrameDropStart(); | 349 TraceFrameDropStart(); |
| 352 return; | 350 return; |
| 353 } | 351 } |
| 354 TraceFrameDropEnd(); | 352 TraceFrameDropEnd(); |
| 355 codec_type = encoder_config_.codecType; | 353 codec_type = encoder_config_.codecType; |
| 356 } | 354 } |
| 357 | 355 |
| 358 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 356 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| (...skipping 15 matching lines...) Expand all Loading... |
| 374 if (pre_encode_callback_) { | 372 if (pre_encode_callback_) { |
| 375 copied_frame.CopyFrame(*frame_to_send); | 373 copied_frame.CopyFrame(*frame_to_send); |
| 376 pre_encode_callback_->FrameCallback(&copied_frame); | 374 pre_encode_callback_->FrameCallback(&copied_frame); |
| 377 frame_to_send = &copied_frame; | 375 frame_to_send = &copied_frame; |
| 378 } | 376 } |
| 379 | 377 |
| 380 if (codec_type == webrtc::kVideoCodecVP8) { | 378 if (codec_type == webrtc::kVideoCodecVP8) { |
| 381 webrtc::CodecSpecificInfo codec_specific_info; | 379 webrtc::CodecSpecificInfo codec_specific_info; |
| 382 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 380 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 383 { | 381 { |
| 384 CriticalSectionScoped cs(data_cs_.get()); | 382 rtc::CritScope lock(&data_cs_); |
| 385 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = | 383 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = |
| 386 has_received_rpsi_; | 384 has_received_rpsi_; |
| 387 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = | 385 codec_specific_info.codecSpecific.VP8.hasReceivedSLI = |
| 388 has_received_sli_; | 386 has_received_sli_; |
| 389 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = | 387 codec_specific_info.codecSpecific.VP8.pictureIdRPSI = |
| 390 picture_id_rpsi_; | 388 picture_id_rpsi_; |
| 391 codec_specific_info.codecSpecific.VP8.pictureIdSLI = | 389 codec_specific_info.codecSpecific.VP8.pictureIdSLI = |
| 392 picture_id_sli_; | 390 picture_id_sli_; |
| 393 has_received_sli_ = false; | 391 has_received_sli_ = false; |
| 394 has_received_rpsi_ = false; | 392 has_received_rpsi_ = false; |
| 395 } | 393 } |
| 396 | 394 |
| 397 vcm_->AddVideoFrame(*frame_to_send, vp_->GetContentMetrics(), | 395 vcm_->AddVideoFrame(*frame_to_send, vp_->GetContentMetrics(), |
| 398 &codec_specific_info); | 396 &codec_specific_info); |
| 399 return; | 397 return; |
| 400 } | 398 } |
| 401 vcm_->AddVideoFrame(*frame_to_send); | 399 vcm_->AddVideoFrame(*frame_to_send); |
| 402 } | 400 } |
| 403 | 401 |
| 404 void ViEEncoder::SendKeyFrame() { | 402 void ViEEncoder::SendKeyFrame() { |
| 405 vcm_->IntraFrameRequest(0); | 403 vcm_->IntraFrameRequest(0); |
| 406 } | 404 } |
| 407 | 405 |
| 408 uint32_t ViEEncoder::LastObservedBitrateBps() const { | 406 uint32_t ViEEncoder::LastObservedBitrateBps() const { |
| 409 CriticalSectionScoped cs(data_cs_.get()); | 407 rtc::CritScope lock(&data_cs_); |
| 410 return last_observed_bitrate_bps_; | 408 return last_observed_bitrate_bps_; |
| 411 } | 409 } |
| 412 | 410 |
| 413 int ViEEncoder::CodecTargetBitrate(uint32_t* bitrate) const { | 411 int ViEEncoder::CodecTargetBitrate(uint32_t* bitrate) const { |
| 414 if (vcm_->Bitrate(bitrate) != 0) | 412 if (vcm_->Bitrate(bitrate) != 0) |
| 415 return -1; | 413 return -1; |
| 416 return 0; | 414 return 0; |
| 417 } | 415 } |
| 418 | 416 |
| 419 void ViEEncoder::SetProtectionMethod(bool nack, bool fec) { | 417 void ViEEncoder::SetProtectionMethod(bool nack, bool fec) { |
| 420 // Set Video Protection for VCM. | 418 // Set Video Protection for VCM. |
| 421 VCMVideoProtection protection_mode; | 419 VCMVideoProtection protection_mode; |
| 422 if (fec) { | 420 if (fec) { |
| 423 protection_mode = | 421 protection_mode = |
| 424 nack ? webrtc::kProtectionNackFEC : kProtectionFEC; | 422 nack ? webrtc::kProtectionNackFEC : kProtectionFEC; |
| 425 } else { | 423 } else { |
| 426 protection_mode = nack ? kProtectionNack : kProtectionNone; | 424 protection_mode = nack ? kProtectionNack : kProtectionNone; |
| 427 } | 425 } |
| 428 vcm_->SetVideoProtection(protection_mode, true); | 426 vcm_->SetVideoProtection(protection_mode, true); |
| 429 } | 427 } |
| 430 | 428 |
| 431 void ViEEncoder::SetSenderBufferingMode(int target_delay_ms) { | 429 void ViEEncoder::SetSenderBufferingMode(int target_delay_ms) { |
| 432 { | 430 { |
| 433 CriticalSectionScoped cs(data_cs_.get()); | 431 rtc::CritScope lock(&data_cs_); |
| 434 target_delay_ms_ = target_delay_ms; | 432 target_delay_ms_ = target_delay_ms; |
| 435 } | 433 } |
| 436 if (target_delay_ms > 0) { | 434 if (target_delay_ms > 0) { |
| 437 // Disable external frame-droppers. | 435 // Disable external frame-droppers. |
| 438 vcm_->EnableFrameDropper(false); | 436 vcm_->EnableFrameDropper(false); |
| 439 vp_->EnableTemporalDecimation(false); | 437 vp_->EnableTemporalDecimation(false); |
| 440 } else { | 438 } else { |
| 441 // Real-time mode - enable frame droppers. | 439 // Real-time mode - enable frame droppers. |
| 442 vp_->EnableTemporalDecimation(true); | 440 vp_->EnableTemporalDecimation(true); |
| 443 vcm_->EnableFrameDropper(true); | 441 vcm_->EnableFrameDropper(true); |
| 444 } | 442 } |
| 445 } | 443 } |
| 446 | 444 |
| 447 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { | 445 void ViEEncoder::OnSetRates(uint32_t bitrate_bps, int framerate) { |
| 448 if (stats_proxy_) | 446 if (stats_proxy_) |
| 449 stats_proxy_->OnSetRates(bitrate_bps, framerate); | 447 stats_proxy_->OnSetRates(bitrate_bps, framerate); |
| 450 } | 448 } |
| 451 | 449 |
| 452 int32_t ViEEncoder::SendData( | 450 int32_t ViEEncoder::SendData( |
| 453 const uint8_t payload_type, | 451 const uint8_t payload_type, |
| 454 const EncodedImage& encoded_image, | 452 const EncodedImage& encoded_image, |
| 455 const webrtc::RTPFragmentationHeader& fragmentation_header, | 453 const webrtc::RTPFragmentationHeader& fragmentation_header, |
| 456 const RTPVideoHeader* rtp_video_hdr) { | 454 const RTPVideoHeader* rtp_video_hdr) { |
| 457 RTC_DCHECK(send_payload_router_ != NULL); | 455 RTC_DCHECK(send_payload_router_ != NULL); |
| 458 | 456 |
| 459 { | 457 { |
| 460 CriticalSectionScoped cs(data_cs_.get()); | 458 rtc::CritScope lock(&data_cs_); |
| 461 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 459 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); |
| 462 } | 460 } |
| 463 | 461 |
| 464 if (stats_proxy_ != NULL) | 462 if (stats_proxy_ != NULL) |
| 465 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); | 463 stats_proxy_->OnSendEncodedImage(encoded_image, rtp_video_hdr); |
| 466 | 464 |
| 467 return send_payload_router_->RoutePayload( | 465 return send_payload_router_->RoutePayload( |
| 468 encoded_image._frameType, payload_type, encoded_image._timeStamp, | 466 encoded_image._frameType, payload_type, encoded_image._timeStamp, |
| 469 encoded_image.capture_time_ms_, encoded_image._buffer, | 467 encoded_image.capture_time_ms_, encoded_image._buffer, |
| 470 encoded_image._length, &fragmentation_header, rtp_video_hdr) | 468 encoded_image._length, &fragmentation_header, rtp_video_hdr) |
| 471 ? 0 | 469 ? 0 |
| 472 : -1; | 470 : -1; |
| 473 } | 471 } |
| 474 | 472 |
| 475 void ViEEncoder::OnEncoderImplementationName( | 473 void ViEEncoder::OnEncoderImplementationName( |
| 476 const char* implementation_name) { | 474 const char* implementation_name) { |
| 477 if (stats_proxy_) | 475 if (stats_proxy_) |
| 478 stats_proxy_->OnEncoderImplementationName(implementation_name); | 476 stats_proxy_->OnEncoderImplementationName(implementation_name); |
| 479 } | 477 } |
| 480 | 478 |
| 481 int32_t ViEEncoder::SendStatistics(const uint32_t bit_rate, | 479 int32_t ViEEncoder::SendStatistics(const uint32_t bit_rate, |
| 482 const uint32_t frame_rate) { | 480 const uint32_t frame_rate) { |
| 483 if (stats_proxy_) | 481 if (stats_proxy_) |
| 484 stats_proxy_->OnOutgoingRate(frame_rate, bit_rate); | 482 stats_proxy_->OnOutgoingRate(frame_rate, bit_rate); |
| 485 return 0; | 483 return 0; |
| 486 } | 484 } |
| 487 | 485 |
| 488 void ViEEncoder::OnReceivedSLI(uint32_t /*ssrc*/, | 486 void ViEEncoder::OnReceivedSLI(uint32_t /*ssrc*/, |
| 489 uint8_t picture_id) { | 487 uint8_t picture_id) { |
| 490 CriticalSectionScoped cs(data_cs_.get()); | 488 rtc::CritScope lock(&data_cs_); |
| 491 picture_id_sli_ = picture_id; | 489 picture_id_sli_ = picture_id; |
| 492 has_received_sli_ = true; | 490 has_received_sli_ = true; |
| 493 } | 491 } |
| 494 | 492 |
| 495 void ViEEncoder::OnReceivedRPSI(uint32_t /*ssrc*/, | 493 void ViEEncoder::OnReceivedRPSI(uint32_t /*ssrc*/, |
| 496 uint64_t picture_id) { | 494 uint64_t picture_id) { |
| 497 CriticalSectionScoped cs(data_cs_.get()); | 495 rtc::CritScope lock(&data_cs_); |
| 498 picture_id_rpsi_ = picture_id; | 496 picture_id_rpsi_ = picture_id; |
| 499 has_received_rpsi_ = true; | 497 has_received_rpsi_ = true; |
| 500 } | 498 } |
| 501 | 499 |
| 502 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { | 500 void ViEEncoder::OnReceivedIntraFrameRequest(uint32_t ssrc) { |
| 503 // Key frame request from remote side, signal to VCM. | 501 // Key frame request from remote side, signal to VCM. |
| 504 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); | 502 TRACE_EVENT0("webrtc", "OnKeyFrameRequest"); |
| 505 | 503 |
| 506 int idx = 0; | 504 int idx = 0; |
| 507 { | 505 { |
| 508 CriticalSectionScoped cs(data_cs_.get()); | 506 rtc::CritScope lock(&data_cs_); |
| 509 auto stream_it = ssrc_streams_.find(ssrc); | 507 auto stream_it = ssrc_streams_.find(ssrc); |
| 510 if (stream_it == ssrc_streams_.end()) { | 508 if (stream_it == ssrc_streams_.end()) { |
| 511 LOG_F(LS_WARNING) << "ssrc not found: " << ssrc << ", map size " | 509 LOG_F(LS_WARNING) << "ssrc not found: " << ssrc << ", map size " |
| 512 << ssrc_streams_.size(); | 510 << ssrc_streams_.size(); |
| 513 return; | 511 return; |
| 514 } | 512 } |
| 515 std::map<unsigned int, int64_t>::iterator time_it = | 513 std::map<unsigned int, int64_t>::iterator time_it = |
| 516 time_last_intra_request_ms_.find(ssrc); | 514 time_last_intra_request_ms_.find(ssrc); |
| 517 if (time_it == time_last_intra_request_ms_.end()) { | 515 if (time_it == time_last_intra_request_ms_.end()) { |
| 518 time_last_intra_request_ms_[ssrc] = 0; | 516 time_last_intra_request_ms_[ssrc] = 0; |
| 519 } | 517 } |
| 520 | 518 |
| 521 int64_t now = TickTime::MillisecondTimestamp(); | 519 int64_t now = TickTime::MillisecondTimestamp(); |
| 522 if (time_last_intra_request_ms_[ssrc] + kMinKeyFrameRequestIntervalMs | 520 if (time_last_intra_request_ms_[ssrc] + kMinKeyFrameRequestIntervalMs |
| 523 > now) { | 521 > now) { |
| 524 return; | 522 return; |
| 525 } | 523 } |
| 526 time_last_intra_request_ms_[ssrc] = now; | 524 time_last_intra_request_ms_[ssrc] = now; |
| 527 idx = stream_it->second; | 525 idx = stream_it->second; |
| 528 } | 526 } |
| 529 // Release the critsect before triggering key frame. | 527 // Release the critsect before triggering key frame. |
| 530 vcm_->IntraFrameRequest(idx); | 528 vcm_->IntraFrameRequest(idx); |
| 531 } | 529 } |
| 532 | 530 |
| 533 void ViEEncoder::OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { | 531 void ViEEncoder::OnLocalSsrcChanged(uint32_t old_ssrc, uint32_t new_ssrc) { |
| 534 CriticalSectionScoped cs(data_cs_.get()); | 532 rtc::CritScope lock(&data_cs_); |
| 535 std::map<unsigned int, int>::iterator it = ssrc_streams_.find(old_ssrc); | 533 std::map<unsigned int, int>::iterator it = ssrc_streams_.find(old_ssrc); |
| 536 if (it == ssrc_streams_.end()) { | 534 if (it == ssrc_streams_.end()) { |
| 537 return; | 535 return; |
| 538 } | 536 } |
| 539 | 537 |
| 540 ssrc_streams_[new_ssrc] = it->second; | 538 ssrc_streams_[new_ssrc] = it->second; |
| 541 ssrc_streams_.erase(it); | 539 ssrc_streams_.erase(it); |
| 542 | 540 |
| 543 std::map<unsigned int, int64_t>::iterator time_it = | 541 std::map<unsigned int, int64_t>::iterator time_it = |
| 544 time_last_intra_request_ms_.find(old_ssrc); | 542 time_last_intra_request_ms_.find(old_ssrc); |
| 545 int64_t last_intra_request_ms = 0; | 543 int64_t last_intra_request_ms = 0; |
| 546 if (time_it != time_last_intra_request_ms_.end()) { | 544 if (time_it != time_last_intra_request_ms_.end()) { |
| 547 last_intra_request_ms = time_it->second; | 545 last_intra_request_ms = time_it->second; |
| 548 time_last_intra_request_ms_.erase(time_it); | 546 time_last_intra_request_ms_.erase(time_it); |
| 549 } | 547 } |
| 550 time_last_intra_request_ms_[new_ssrc] = last_intra_request_ms; | 548 time_last_intra_request_ms_[new_ssrc] = last_intra_request_ms; |
| 551 } | 549 } |
| 552 | 550 |
| 553 void ViEEncoder::SetSsrcs(const std::vector<uint32_t>& ssrcs) { | 551 void ViEEncoder::SetSsrcs(const std::vector<uint32_t>& ssrcs) { |
| 554 CriticalSectionScoped cs(data_cs_.get()); | 552 rtc::CritScope lock(&data_cs_); |
| 555 ssrc_streams_.clear(); | 553 ssrc_streams_.clear(); |
| 556 time_last_intra_request_ms_.clear(); | 554 time_last_intra_request_ms_.clear(); |
| 557 int idx = 0; | 555 int idx = 0; |
| 558 for (uint32_t ssrc : ssrcs) { | 556 for (uint32_t ssrc : ssrcs) { |
| 559 ssrc_streams_[ssrc] = idx++; | 557 ssrc_streams_[ssrc] = idx++; |
| 560 } | 558 } |
| 561 } | 559 } |
| 562 | 560 |
| 563 void ViEEncoder::SetMinTransmitBitrate(int min_transmit_bitrate_kbps) { | 561 void ViEEncoder::SetMinTransmitBitrate(int min_transmit_bitrate_kbps) { |
| 564 assert(min_transmit_bitrate_kbps >= 0); | 562 assert(min_transmit_bitrate_kbps >= 0); |
| 565 CriticalSectionScoped crit(data_cs_.get()); | 563 rtc::CritScope lock(&data_cs_); |
| 566 min_transmit_bitrate_kbps_ = min_transmit_bitrate_kbps; | 564 min_transmit_bitrate_kbps_ = min_transmit_bitrate_kbps; |
| 567 } | 565 } |
| 568 | 566 |
| 569 // Called from ViEBitrateObserver. | 567 // Called from ViEBitrateObserver. |
| 570 void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps, | 568 void ViEEncoder::OnNetworkChanged(uint32_t bitrate_bps, |
| 571 uint8_t fraction_lost, | 569 uint8_t fraction_lost, |
| 572 int64_t round_trip_time_ms) { | 570 int64_t round_trip_time_ms) { |
| 573 LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps | 571 LOG(LS_VERBOSE) << "OnNetworkChanged, bitrate" << bitrate_bps |
| 574 << " packet loss " << static_cast<int>(fraction_lost) | 572 << " packet loss " << static_cast<int>(fraction_lost) |
| 575 << " rtt " << round_trip_time_ms; | 573 << " rtt " << round_trip_time_ms; |
| 576 RTC_DCHECK(send_payload_router_ != NULL); | 574 RTC_DCHECK(send_payload_router_ != NULL); |
| 577 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); | 575 vcm_->SetChannelParameters(bitrate_bps, fraction_lost, round_trip_time_ms); |
| 578 bool video_is_suspended = vcm_->VideoSuspended(); | 576 bool video_is_suspended = vcm_->VideoSuspended(); |
| 579 bool video_suspension_changed; | 577 bool video_suspension_changed; |
| 580 VideoCodec send_codec; | 578 VideoCodec send_codec; |
| 581 uint32_t first_ssrc; | 579 uint32_t first_ssrc; |
| 582 { | 580 { |
| 583 CriticalSectionScoped cs(data_cs_.get()); | 581 rtc::CritScope lock(&data_cs_); |
| 584 last_observed_bitrate_bps_ = bitrate_bps; | 582 last_observed_bitrate_bps_ = bitrate_bps; |
| 585 video_suspension_changed = video_suspended_ != video_is_suspended; | 583 video_suspension_changed = video_suspended_ != video_is_suspended; |
| 586 video_suspended_ = video_is_suspended; | 584 video_suspended_ = video_is_suspended; |
| 587 send_codec = encoder_config_; | 585 send_codec = encoder_config_; |
| 588 first_ssrc = ssrc_streams_.begin()->first; | 586 first_ssrc = ssrc_streams_.begin()->first; |
| 589 } | 587 } |
| 590 | 588 |
| 591 SimulcastStream* stream_configs = send_codec.simulcastStream; | 589 SimulcastStream* stream_configs = send_codec.simulcastStream; |
| 592 // Allocate the bandwidth between the streams. | 590 // Allocate the bandwidth between the streams. |
| 593 std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( | 591 std::vector<uint32_t> stream_bitrates = AllocateStreamBitrates( |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 const uint32_t width, | 623 const uint32_t width, |
| 626 const uint32_t height) { | 624 const uint32_t height) { |
| 627 return vp_->SetTargetResolution(width, height, frame_rate); | 625 return vp_->SetTargetResolution(width, height, frame_rate); |
| 628 } | 626 } |
| 629 | 627 |
| 630 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 628 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
| 631 vp_->SetTargetFramerate(frame_rate); | 629 vp_->SetTargetFramerate(frame_rate); |
| 632 } | 630 } |
| 633 | 631 |
| 634 } // namespace webrtc | 632 } // namespace webrtc |
| OLD | NEW |