| 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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 103 private: | 103 private: |
| 104 ViEEncoder* owner_; | 104 ViEEncoder* owner_; |
| 105 }; | 105 }; |
| 106 | 106 |
| 107 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 107 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| 108 ProcessThread* module_process_thread, | 108 ProcessThread* module_process_thread, |
| 109 SendStatisticsProxy* stats_proxy, | 109 SendStatisticsProxy* stats_proxy, |
| 110 I420FrameCallback* pre_encode_callback, | 110 I420FrameCallback* pre_encode_callback, |
| 111 OveruseFrameDetector* overuse_detector, | 111 OveruseFrameDetector* overuse_detector, |
| 112 PacedSender* pacer, | 112 PacedSender* pacer, |
| 113 PayloadRouter* payload_router, |
| 113 BitrateAllocator* bitrate_allocator) | 114 BitrateAllocator* bitrate_allocator) |
| 114 : number_of_cores_(number_of_cores), | 115 : number_of_cores_(number_of_cores), |
| 115 vp_(VideoProcessing::Create()), | 116 vp_(VideoProcessing::Create()), |
| 116 qm_callback_(new QMVideoSettingsCallback(vp_.get())), | 117 qm_callback_(new QMVideoSettingsCallback(vp_.get())), |
| 117 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), | 118 vcm_(VideoCodingModule::Create(Clock::GetRealTimeClock(), |
| 118 this, | 119 this, |
| 119 qm_callback_.get())), | 120 qm_callback_.get())), |
| 120 send_payload_router_(NULL), | |
| 121 stats_proxy_(stats_proxy), | 121 stats_proxy_(stats_proxy), |
| 122 pre_encode_callback_(pre_encode_callback), | 122 pre_encode_callback_(pre_encode_callback), |
| 123 overuse_detector_(overuse_detector), | 123 overuse_detector_(overuse_detector), |
| 124 pacer_(pacer), | 124 pacer_(pacer), |
| 125 send_payload_router_(payload_router), |
| 125 bitrate_allocator_(bitrate_allocator), | 126 bitrate_allocator_(bitrate_allocator), |
| 126 time_of_last_frame_activity_ms_(0), | 127 time_of_last_frame_activity_ms_(0), |
| 127 encoder_config_(), | 128 encoder_config_(), |
| 128 min_transmit_bitrate_kbps_(0), | 129 min_transmit_bitrate_kbps_(0), |
| 129 last_observed_bitrate_bps_(0), | 130 last_observed_bitrate_bps_(0), |
| 130 target_delay_ms_(0), | 131 target_delay_ms_(0), |
| 131 network_is_transmitting_(true), | 132 network_is_transmitting_(true), |
| 132 encoder_paused_(false), | 133 encoder_paused_(false), |
| 133 encoder_paused_and_dropped_frame_(false), | 134 encoder_paused_and_dropped_frame_(false), |
| 134 module_process_thread_(module_process_thread), | 135 module_process_thread_(module_process_thread), |
| 135 has_received_sli_(false), | 136 has_received_sli_(false), |
| 136 picture_id_sli_(0), | 137 picture_id_sli_(0), |
| 137 has_received_rpsi_(false), | 138 has_received_rpsi_(false), |
| 138 picture_id_rpsi_(0), | 139 picture_id_rpsi_(0), |
| 139 video_suspended_(false) { | 140 video_suspended_(false) { |
| 140 bitrate_observer_.reset(new ViEBitrateObserver(this)); | 141 bitrate_observer_.reset(new ViEBitrateObserver(this)); |
| 142 module_process_thread_->RegisterModule(vcm_.get()); |
| 141 } | 143 } |
| 142 | 144 |
| 143 bool ViEEncoder::Init() { | 145 bool ViEEncoder::Init() { |
| 144 vp_->EnableTemporalDecimation(true); | 146 vp_->EnableTemporalDecimation(true); |
| 145 | 147 |
| 146 // Enable/disable content analysis: off by default for now. | 148 // Enable/disable content analysis: off by default for now. |
| 147 vp_->EnableContentAnalysis(false); | 149 vp_->EnableContentAnalysis(false); |
| 148 | 150 |
| 149 if (vcm_->RegisterTransportCallback(this) != 0) { | 151 if (vcm_->RegisterTransportCallback(this) != 0) { |
| 150 return false; | 152 return false; |
| 151 } | 153 } |
| 152 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { | 154 if (vcm_->RegisterSendStatisticsCallback(this) != 0) { |
| 153 return false; | 155 return false; |
| 154 } | 156 } |
| 155 return true; | 157 return true; |
| 156 } | 158 } |
| 157 | 159 |
| 158 void ViEEncoder::StartThreadsAndSetSharedMembers( | 160 VideoCodingModule* ViEEncoder::vcm() const { |
| 159 rtc::scoped_refptr<PayloadRouter> send_payload_router, | 161 return vcm_.get(); |
| 160 VCMProtectionCallback* vcm_protection_callback) { | |
| 161 RTC_DCHECK(send_payload_router_ == NULL); | |
| 162 | |
| 163 send_payload_router_ = send_payload_router; | |
| 164 vcm_->RegisterProtectionCallback(vcm_protection_callback); | |
| 165 module_process_thread_->RegisterModule(vcm_.get()); | |
| 166 } | |
| 167 | |
| 168 void ViEEncoder::StopThreadsAndRemoveSharedMembers() { | |
| 169 if (bitrate_allocator_) | |
| 170 bitrate_allocator_->RemoveBitrateObserver(bitrate_observer_.get()); | |
| 171 module_process_thread_->DeRegisterModule(vcm_.get()); | |
| 172 } | 162 } |
| 173 | 163 |
| 174 ViEEncoder::~ViEEncoder() { | 164 ViEEncoder::~ViEEncoder() { |
| 165 module_process_thread_->DeRegisterModule(vcm_.get()); |
| 166 if (bitrate_allocator_) |
| 167 bitrate_allocator_->RemoveBitrateObserver(bitrate_observer_.get()); |
| 175 } | 168 } |
| 176 | 169 |
| 177 void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { | 170 void ViEEncoder::SetNetworkTransmissionState(bool is_transmitting) { |
| 178 { | 171 { |
| 179 rtc::CritScope lock(&data_cs_); | 172 rtc::CritScope lock(&data_cs_); |
| 180 network_is_transmitting_ = is_transmitting; | 173 network_is_transmitting_ = is_transmitting; |
| 181 } | 174 } |
| 182 } | 175 } |
| 183 | 176 |
| 184 void ViEEncoder::Pause() { | 177 void ViEEncoder::Pause() { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 | 324 |
| 332 void ViEEncoder::TraceFrameDropEnd() { | 325 void ViEEncoder::TraceFrameDropEnd() { |
| 333 // End trace event on first frame after encoder resumes, if frame was dropped. | 326 // End trace event on first frame after encoder resumes, if frame was dropped. |
| 334 if (encoder_paused_and_dropped_frame_) { | 327 if (encoder_paused_and_dropped_frame_) { |
| 335 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); | 328 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); |
| 336 } | 329 } |
| 337 encoder_paused_and_dropped_frame_ = false; | 330 encoder_paused_and_dropped_frame_ = false; |
| 338 } | 331 } |
| 339 | 332 |
| 340 void ViEEncoder::DeliverFrame(VideoFrame video_frame) { | 333 void ViEEncoder::DeliverFrame(VideoFrame video_frame) { |
| 341 RTC_DCHECK(send_payload_router_ != NULL); | |
| 342 if (!send_payload_router_->active()) { | 334 if (!send_payload_router_->active()) { |
| 343 // We've paused or we have no channels attached, don't waste resources on | 335 // We've paused or we have no channels attached, don't waste resources on |
| 344 // encoding. | 336 // encoding. |
| 345 return; | 337 return; |
| 346 } | 338 } |
| 347 VideoCodecType codec_type; | 339 VideoCodecType codec_type; |
| 348 { | 340 { |
| 349 rtc::CritScope lock(&data_cs_); | 341 rtc::CritScope lock(&data_cs_); |
| 350 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); | 342 time_of_last_frame_activity_ms_ = TickTime::MillisecondTimestamp(); |
| 351 if (EncoderPaused()) { | 343 if (EncoderPaused()) { |
| (...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 625 const uint32_t width, | 617 const uint32_t width, |
| 626 const uint32_t height) { | 618 const uint32_t height) { |
| 627 return vp_->SetTargetResolution(width, height, frame_rate); | 619 return vp_->SetTargetResolution(width, height, frame_rate); |
| 628 } | 620 } |
| 629 | 621 |
| 630 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { | 622 void QMVideoSettingsCallback::SetTargetFramerate(int frame_rate) { |
| 631 vp_->SetTargetFramerate(frame_rate); | 623 vp_->SetTargetFramerate(frame_rate); |
| 632 } | 624 } |
| 633 | 625 |
| 634 } // namespace webrtc | 626 } // namespace webrtc |
| OLD | NEW |