Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 149 return options; | 149 return options; |
| 150 } | 150 } |
| 151 } // namespace | 151 } // namespace |
| 152 | 152 |
| 153 namespace internal { | 153 namespace internal { |
| 154 VideoSendStream::VideoSendStream( | 154 VideoSendStream::VideoSendStream( |
| 155 int num_cpu_cores, | 155 int num_cpu_cores, |
| 156 ProcessThread* module_process_thread, | 156 ProcessThread* module_process_thread, |
| 157 CallStats* call_stats, | 157 CallStats* call_stats, |
| 158 CongestionController* congestion_controller, | 158 CongestionController* congestion_controller, |
| 159 BitrateAllocator* bitrate_allocator, | |
|
stefan-webrtc
2016/03/11 13:43:53
It would have been nicer if we didn't have to pass
mflodman
2016/03/11 14:26:05
Yes, I did that initially but reverted for the rea
mflodman
2016/03/11 14:28:39
Just to get the discussion on the record.
This do
| |
| 159 VieRemb* remb, | 160 VieRemb* remb, |
| 160 BitrateAllocator* bitrate_allocator, | |
| 161 const VideoSendStream::Config& config, | 161 const VideoSendStream::Config& config, |
| 162 const VideoEncoderConfig& encoder_config, | 162 const VideoEncoderConfig& encoder_config, |
| 163 const std::map<uint32_t, RtpState>& suspended_ssrcs) | 163 const std::map<uint32_t, RtpState>& suspended_ssrcs) |
| 164 : stats_proxy_(Clock::GetRealTimeClock(), | 164 : stats_proxy_(Clock::GetRealTimeClock(), |
| 165 config, | 165 config, |
| 166 encoder_config.content_type), | 166 encoder_config.content_type), |
| 167 encoded_frame_proxy_(config.post_encode_callback), | 167 encoded_frame_proxy_(config.post_encode_callback), |
| 168 config_(config), | 168 config_(config), |
| 169 suspended_ssrcs_(suspended_ssrcs), | 169 suspended_ssrcs_(suspended_ssrcs), |
| 170 module_process_thread_(module_process_thread), | 170 module_process_thread_(module_process_thread), |
| 171 call_stats_(call_stats), | 171 call_stats_(call_stats), |
| 172 congestion_controller_(congestion_controller), | 172 congestion_controller_(congestion_controller), |
| 173 bitrate_allocator_(bitrate_allocator), | |
| 173 remb_(remb), | 174 remb_(remb), |
| 174 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), | 175 encoder_thread_(EncoderThreadFunction, this, "EncoderThread"), |
| 175 encoder_wakeup_event_(false, false), | 176 encoder_wakeup_event_(false, false), |
| 176 stop_encoder_thread_(0), | 177 stop_encoder_thread_(0), |
| 177 overuse_detector_( | 178 overuse_detector_( |
| 178 Clock::GetRealTimeClock(), | 179 Clock::GetRealTimeClock(), |
| 179 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), | 180 GetCpuOveruseOptions(config.encoder_settings.full_overuse_time), |
| 180 this, | 181 this, |
| 181 config.post_encode_callback, | 182 config.post_encode_callback, |
| 182 &stats_proxy_), | 183 &stats_proxy_), |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 195 config_.rtp.ssrcs.size(), | 196 config_.rtp.ssrcs.size(), |
| 196 true), | 197 true), |
| 197 vie_receiver_(vie_channel_.vie_receiver()), | 198 vie_receiver_(vie_channel_.vie_receiver()), |
| 198 vie_encoder_(num_cpu_cores, | 199 vie_encoder_(num_cpu_cores, |
| 199 config_.rtp.ssrcs, | 200 config_.rtp.ssrcs, |
| 200 module_process_thread_, | 201 module_process_thread_, |
| 201 &stats_proxy_, | 202 &stats_proxy_, |
| 202 config.pre_encode_callback, | 203 config.pre_encode_callback, |
| 203 &overuse_detector_, | 204 &overuse_detector_, |
| 204 congestion_controller_->pacer(), | 205 congestion_controller_->pacer(), |
| 205 &payload_router_, | 206 &payload_router_), |
| 206 bitrate_allocator), | |
| 207 vcm_(vie_encoder_.vcm()), | 207 vcm_(vie_encoder_.vcm()), |
| 208 rtp_rtcp_modules_(vie_channel_.rtp_rtcp()), | 208 rtp_rtcp_modules_(vie_channel_.rtp_rtcp()), |
| 209 input_(&encoder_wakeup_event_, | 209 input_(&encoder_wakeup_event_, |
| 210 config_.local_renderer, | 210 config_.local_renderer, |
| 211 &stats_proxy_, | 211 &stats_proxy_, |
| 212 &overuse_detector_) { | 212 &overuse_detector_) { |
| 213 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); | 213 LOG(LS_INFO) << "VideoSendStream: " << config_.ToString(); |
| 214 | 214 |
| 215 RTC_DCHECK(!config_.rtp.ssrcs.empty()); | 215 RTC_DCHECK(!config_.rtp.ssrcs.empty()); |
| 216 RTC_DCHECK(module_process_thread_); | 216 RTC_DCHECK(module_process_thread_); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 291 config.encoder_settings.payload_type, | 291 config.encoder_settings.payload_type, |
| 292 config.encoder_settings.internal_source)); | 292 config.encoder_settings.internal_source)); |
| 293 | 293 |
| 294 ReconfigureVideoEncoder(encoder_config); | 294 ReconfigureVideoEncoder(encoder_config); |
| 295 | 295 |
| 296 vie_channel_.RegisterSendSideDelayObserver(&stats_proxy_); | 296 vie_channel_.RegisterSendSideDelayObserver(&stats_proxy_); |
| 297 | 297 |
| 298 if (config_.post_encode_callback) | 298 if (config_.post_encode_callback) |
| 299 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_); | 299 vie_encoder_.RegisterPostEncodeImageCallback(&encoded_frame_proxy_); |
| 300 | 300 |
| 301 if (config_.suspend_below_min_bitrate) | 301 if (config_.suspend_below_min_bitrate) { |
| 302 vie_encoder_.SuspendBelowMinBitrate(); | 302 vcm_->SuspendBelowMinBitrate(); |
| 303 bitrate_allocator_->EnforceMinBitrate(false); | |
| 304 } | |
| 303 | 305 |
| 304 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); | 306 vie_channel_.RegisterRtcpPacketTypeCounterObserver(&stats_proxy_); |
| 305 vie_channel_.RegisterSendBitrateObserver(&stats_proxy_); | 307 vie_channel_.RegisterSendBitrateObserver(&stats_proxy_); |
| 306 vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_); | 308 vie_channel_.RegisterSendFrameCountObserver(&stats_proxy_); |
| 307 | 309 |
| 308 module_process_thread_->RegisterModule(&overuse_detector_); | 310 module_process_thread_->RegisterModule(&overuse_detector_); |
| 309 | 311 |
| 310 encoder_thread_.Start(); | 312 encoder_thread_.Start(); |
| 311 encoder_thread_.SetPriority(rtc::kHighPriority); | 313 encoder_thread_.SetPriority(rtc::kHighPriority); |
| 312 } | 314 } |
| 313 | 315 |
| 314 VideoSendStream::~VideoSendStream() { | 316 VideoSendStream::~VideoSendStream() { |
| 315 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); | 317 LOG(LS_INFO) << "~VideoSendStream: " << config_.ToString(); |
| 318 | |
| 319 bitrate_allocator_->RemoveObserver(this); | |
| 316 Stop(); | 320 Stop(); |
| 317 | 321 |
| 318 // Stop the encoder thread permanently. | 322 // Stop the encoder thread permanently. |
| 319 rtc::AtomicOps::ReleaseStore(&stop_encoder_thread_, 1); | 323 rtc::AtomicOps::ReleaseStore(&stop_encoder_thread_, 1); |
| 320 encoder_wakeup_event_.Set(); | 324 encoder_wakeup_event_.Set(); |
| 321 encoder_thread_.Stop(); | 325 encoder_thread_.Stop(); |
| 322 | 326 |
| 323 module_process_thread_->DeRegisterModule(&overuse_detector_); | 327 module_process_thread_->DeRegisterModule(&overuse_detector_); |
| 324 vie_channel_.RegisterSendFrameCountObserver(nullptr); | 328 vie_channel_.RegisterSendFrameCountObserver(nullptr); |
| 325 vie_channel_.RegisterSendBitrateObserver(nullptr); | 329 vie_channel_.RegisterSendBitrateObserver(nullptr); |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 509 video_codec.maxBitrate = | 513 video_codec.maxBitrate = |
| 510 (video_codec.width * video_codec.height * video_codec.maxFramerate) / | 514 (video_codec.width * video_codec.height * video_codec.maxFramerate) / |
| 511 1000; | 515 1000; |
| 512 } | 516 } |
| 513 if (video_codec.maxBitrate < kEncoderMinBitrateKbps) | 517 if (video_codec.maxBitrate < kEncoderMinBitrateKbps) |
| 514 video_codec.maxBitrate = kEncoderMinBitrateKbps; | 518 video_codec.maxBitrate = kEncoderMinBitrateKbps; |
| 515 | 519 |
| 516 RTC_DCHECK_GT(streams[0].max_framerate, 0); | 520 RTC_DCHECK_GT(streams[0].max_framerate, 0); |
| 517 video_codec.maxFramerate = streams[0].max_framerate; | 521 video_codec.maxFramerate = streams[0].max_framerate; |
| 518 | 522 |
| 523 video_codec.startBitrate = | |
| 524 bitrate_allocator_->AddObserver(this, | |
| 525 video_codec.minBitrate * 1000, | |
| 526 video_codec.maxBitrate * 1000) / 1000; | |
| 519 vie_encoder_.SetEncoder(video_codec, config.min_transmit_bitrate_bps); | 527 vie_encoder_.SetEncoder(video_codec, config.min_transmit_bitrate_bps); |
| 520 } | 528 } |
| 521 | 529 |
| 522 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { | 530 bool VideoSendStream::DeliverRtcp(const uint8_t* packet, size_t length) { |
| 523 return vie_receiver_->DeliverRtcp(packet, length); | 531 return vie_receiver_->DeliverRtcp(packet, length); |
| 524 } | 532 } |
| 525 | 533 |
| 526 VideoSendStream::Stats VideoSendStream::GetStats() { | 534 VideoSendStream::Stats VideoSendStream::GetStats() { |
| 527 return stats_proxy_.GetStats(); | 535 return stats_proxy_.GetStats(); |
| 528 } | 536 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 607 vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp); | 615 vie_encoder_.SetNetworkTransmissionState(state == kNetworkUp); |
| 608 if (state == kNetworkDown) { | 616 if (state == kNetworkDown) { |
| 609 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) | 617 for (RtpRtcp* rtp_rtcp : rtp_rtcp_modules_) |
| 610 rtp_rtcp->SetRTCPStatus(RtcpMode::kOff); | 618 rtp_rtcp->SetRTCPStatus(RtcpMode::kOff); |
| 611 } | 619 } |
| 612 } | 620 } |
| 613 | 621 |
| 614 int VideoSendStream::GetPaddingNeededBps() const { | 622 int VideoSendStream::GetPaddingNeededBps() const { |
| 615 return vie_encoder_.GetPaddingNeededBps(); | 623 return vie_encoder_.GetPaddingNeededBps(); |
| 616 } | 624 } |
| 625 | |
| 626 void VideoSendStream::OnBitrateUpdated(uint32_t bitrate_bps, | |
| 627 uint8_t fraction_loss, | |
| 628 int64_t rtt) { | |
| 629 vie_encoder_.OnBitrateUpdated(bitrate_bps, fraction_loss, rtt); | |
| 630 } | |
| 631 | |
| 617 } // namespace internal | 632 } // namespace internal |
| 618 } // namespace webrtc | 633 } // namespace webrtc |
| OLD | NEW |