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