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 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
214 // There is a newer frame in flight. Do not encode this frame. | 214 // There is a newer frame in flight. Do not encode this frame. |
215 LOG(LS_VERBOSE) | 215 LOG(LS_VERBOSE) |
216 << "Incoming frame dropped due to that the encoder is blocked."; | 216 << "Incoming frame dropped due to that the encoder is blocked."; |
217 } | 217 } |
218 return true; | 218 return true; |
219 } | 219 } |
220 VideoFrame frame_; | 220 VideoFrame frame_; |
221 ViEEncoder* vie_encoder_; | 221 ViEEncoder* vie_encoder_; |
222 }; | 222 }; |
223 | 223 |
224 class ViEEncoder::VideoSourceProxy { | |
nisse-webrtc
2016/08/22 07:20:30
I'd like to see a comment briefly explaining the p
perkj_webrtc
2016/09/01 11:46:16
Done.
| |
225 public: | |
226 explicit VideoSourceProxy(ViEEncoder* vie_encoder) | |
227 : vie_encoder_(vie_encoder), source_(nullptr) {} | |
228 | |
229 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source) { | |
230 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_); | |
231 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr; | |
232 { | |
233 rtc::CritScope lock(&crit_); | |
234 old_source = source_; | |
235 source_ = source; | |
236 } | |
237 | |
238 if (old_source != source && old_source != nullptr) { | |
239 old_source->RemoveSink(vie_encoder_); | |
240 } | |
241 | |
242 if (!source) | |
243 return; | |
244 | |
245 // TODO(perkj): Let VideoSourceProxy implement LoadObserver and truly send | |
246 // CPU load as sink wants. | |
247 rtc::VideoSinkWants wants; | |
248 source->AddOrUpdateSink(vie_encoder_, wants); | |
249 } | |
250 | |
251 private: | |
252 rtc::CriticalSection crit_; | |
253 rtc::SequencedTaskChecker main_checker_; | |
254 ViEEncoder* vie_encoder_; | |
255 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); | |
256 | |
257 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | |
258 }; | |
259 | |
224 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 260 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
225 SendStatisticsProxy* stats_proxy, | 261 SendStatisticsProxy* stats_proxy, |
226 const VideoSendStream::Config::EncoderSettings& settings, | 262 const VideoSendStream::Config::EncoderSettings& settings, |
227 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 263 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
228 LoadObserver* overuse_callback, | 264 LoadObserver* overuse_callback, |
229 EncodedFrameObserver* encoder_timing) | 265 EncodedFrameObserver* encoder_timing) |
230 : shutdown_event_(true /* manual_reset */, false), | 266 : shutdown_event_(true /* manual_reset */, false), |
231 number_of_cores_(number_of_cores), | 267 number_of_cores_(number_of_cores), |
268 source_proxy_(new VideoSourceProxy(this)), | |
232 settings_(settings), | 269 settings_(settings), |
233 vp_(VideoProcessing::Create()), | 270 vp_(VideoProcessing::Create()), |
234 video_sender_(Clock::GetRealTimeClock(), this, this), | 271 video_sender_(Clock::GetRealTimeClock(), this, this), |
235 overuse_detector_(Clock::GetRealTimeClock(), | 272 overuse_detector_(Clock::GetRealTimeClock(), |
236 GetCpuOveruseOptions(settings.full_overuse_time), | 273 GetCpuOveruseOptions(settings.full_overuse_time), |
237 this, | 274 this, |
238 encoder_timing, | 275 encoder_timing, |
239 stats_proxy), | 276 stats_proxy), |
240 load_observer_(overuse_callback), | 277 load_observer_(overuse_callback), |
241 stats_proxy_(stats_proxy), | 278 stats_proxy_(stats_proxy), |
(...skipping 15 matching lines...) Expand all Loading... | |
257 vp_->EnableTemporalDecimation(false); | 294 vp_->EnableTemporalDecimation(false); |
258 | 295 |
259 encoder_queue_.PostTask([this] { | 296 encoder_queue_.PostTask([this] { |
260 RTC_DCHECK_RUN_ON(&encoder_queue_); | 297 RTC_DCHECK_RUN_ON(&encoder_queue_); |
261 video_sender_.RegisterExternalEncoder( | 298 video_sender_.RegisterExternalEncoder( |
262 settings_.encoder, settings_.payload_type, settings_.internal_source); | 299 settings_.encoder, settings_.payload_type, settings_.internal_source); |
263 }); | 300 }); |
264 } | 301 } |
265 | 302 |
266 ViEEncoder::~ViEEncoder() { | 303 ViEEncoder::~ViEEncoder() { |
304 RTC_DCHECK_RUN_ON(&main_thread_checker_); | |
267 RTC_DCHECK(shutdown_event_.Wait(0)) | 305 RTC_DCHECK(shutdown_event_.Wait(0)) |
268 << "Must call ::Stop() before destruction."; | 306 << "Must call ::Stop() before destruction."; |
269 } | 307 } |
270 | 308 |
271 void ViEEncoder::Stop() { | 309 void ViEEncoder::Stop() { |
272 if (!encoder_queue_.IsCurrent()) { | 310 RTC_DCHECK_RUN_ON(&main_thread_checker_); |
273 encoder_queue_.PostTask([this] { Stop(); }); | 311 source_proxy_->SetSource(nullptr); |
274 shutdown_event_.Wait(rtc::Event::kForever); | 312 encoder_queue_.PostTask([this] { |
275 return; | 313 RTC_DCHECK_RUN_ON(&encoder_queue_); |
276 } | 314 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
277 RTC_DCHECK_RUN_ON(&encoder_queue_); | 315 false); |
278 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, false); | 316 shutdown_event_.Set(); |
279 shutdown_event_.Set(); | 317 }); |
318 | |
319 shutdown_event_.Wait(rtc::Event::kForever); | |
280 } | 320 } |
281 | 321 |
282 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 322 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
323 RTC_DCHECK_RUN_ON(&main_thread_checker_); | |
283 RTC_DCHECK(!module_process_thread_); | 324 RTC_DCHECK(!module_process_thread_); |
284 module_process_thread_ = module_process_thread; | 325 module_process_thread_ = module_process_thread; |
285 module_process_thread_->RegisterModule(&overuse_detector_); | 326 module_process_thread_->RegisterModule(&overuse_detector_); |
286 module_process_thread_->RegisterModule(&video_sender_); | 327 module_process_thread_->RegisterModule(&video_sender_); |
287 module_process_thread_checker_.DetachFromThread(); | 328 module_process_thread_checker_.DetachFromThread(); |
288 } | 329 } |
289 | 330 |
290 void ViEEncoder::DeRegisterProcessThread() { | 331 void ViEEncoder::DeRegisterProcessThread() { |
332 RTC_DCHECK_RUN_ON(&main_thread_checker_); | |
291 module_process_thread_->DeRegisterModule(&overuse_detector_); | 333 module_process_thread_->DeRegisterModule(&overuse_detector_); |
292 module_process_thread_->DeRegisterModule(&video_sender_); | 334 module_process_thread_->DeRegisterModule(&video_sender_); |
293 } | 335 } |
294 | 336 |
337 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source) { | |
338 RTC_DCHECK_RUN_ON(&main_thread_checker_); | |
339 source_proxy_->SetSource(source); | |
340 } | |
341 | |
295 void ViEEncoder::SetSink(EncodedImageCallback* sink) { | 342 void ViEEncoder::SetSink(EncodedImageCallback* sink) { |
296 encoder_queue_.PostTask([this, sink] { | 343 encoder_queue_.PostTask([this, sink] { |
297 RTC_DCHECK_RUN_ON(&encoder_queue_); | 344 RTC_DCHECK_RUN_ON(&encoder_queue_); |
298 sink_ = sink; | 345 sink_ = sink; |
299 }); | 346 }); |
300 } | 347 } |
301 | 348 |
302 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { | 349 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { |
303 encoder_queue_.PostTask([this, start_bitrate_bps] { | 350 encoder_queue_.PostTask([this, start_bitrate_bps] { |
304 RTC_DCHECK_RUN_ON(&encoder_queue_); | 351 RTC_DCHECK_RUN_ON(&encoder_queue_); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 content_type = VideoEncoderConfig::ContentType::kScreen; | 401 content_type = VideoEncoderConfig::ContentType::kScreen; |
355 break; | 402 break; |
356 default: | 403 default: |
357 RTC_NOTREACHED(); | 404 RTC_NOTREACHED(); |
358 break; | 405 break; |
359 } | 406 } |
360 stats_proxy_->SetContentType(content_type); | 407 stats_proxy_->SetContentType(content_type); |
361 } | 408 } |
362 } | 409 } |
363 | 410 |
364 void ViEEncoder::IncomingCapturedFrame(const VideoFrame& video_frame) { | 411 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
365 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 412 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
366 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | 413 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); |
367 | 414 |
368 VideoFrame incoming_frame = video_frame; | 415 VideoFrame incoming_frame = video_frame; |
369 | 416 |
370 // Local time in webrtc time base. | 417 // Local time in webrtc time base. |
371 int64_t current_time = clock_->TimeInMilliseconds(); | 418 int64_t current_time = clock_->TimeInMilliseconds(); |
372 incoming_frame.set_render_time_ms(current_time); | 419 incoming_frame.set_render_time_ms(current_time); |
373 | 420 |
374 // Capture time may come from clock with an offset and drift from clock_. | 421 // Capture time may come from clock with an offset and drift from clock_. |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
585 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); | 632 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); |
586 } | 633 } |
587 | 634 |
588 void ViEEncoder::NormalUsage() { | 635 void ViEEncoder::NormalUsage() { |
589 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); | 636 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
590 if (load_observer_) | 637 if (load_observer_) |
591 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); | 638 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); |
592 } | 639 } |
593 | 640 |
594 } // namespace webrtc | 641 } // namespace webrtc |
OLD | NEW |