Chromium Code Reviews| 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 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 219 time_when_posted_ms_(time_when_posted_in_ms), | 219 time_when_posted_ms_(time_when_posted_in_ms), |
| 220 log_stats_(log_stats) { | 220 log_stats_(log_stats) { |
| 221 frame_.ShallowCopy(frame); | 221 frame_.ShallowCopy(frame); |
| 222 ++vie_encoder_->posted_frames_waiting_for_encode_; | 222 ++vie_encoder_->posted_frames_waiting_for_encode_; |
| 223 } | 223 } |
| 224 | 224 |
| 225 private: | 225 private: |
| 226 bool Run() override { | 226 bool Run() override { |
| 227 RTC_DCHECK_RUN_ON(&vie_encoder_->encoder_queue_); | 227 RTC_DCHECK_RUN_ON(&vie_encoder_->encoder_queue_); |
| 228 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); | 228 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); |
| 229 vie_encoder_->stats_proxy_->OnIncomingFrame( | |
| 230 frame_.width(), frame_.height(), | |
| 231 vie_encoder_->cpu_restricted_counter_ != 0); | |
| 229 ++vie_encoder_->captured_frame_count_; | 232 ++vie_encoder_->captured_frame_count_; |
| 230 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { | 233 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { |
| 231 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); | 234 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); |
| 232 } else { | 235 } else { |
| 233 // There is a newer frame in flight. Do not encode this frame. | 236 // There is a newer frame in flight. Do not encode this frame. |
| 234 LOG(LS_VERBOSE) | 237 LOG(LS_VERBOSE) |
| 235 << "Incoming frame dropped due to that the encoder is blocked."; | 238 << "Incoming frame dropped due to that the encoder is blocked."; |
| 236 ++vie_encoder_->dropped_frame_count_; | 239 ++vie_encoder_->dropped_frame_count_; |
| 237 } | 240 } |
| 238 if (log_stats_) { | 241 if (log_stats_) { |
| 239 LOG(LS_INFO) << "Number of frames: captured " | 242 LOG(LS_INFO) << "Number of frames: captured " |
| 240 << vie_encoder_->captured_frame_count_ | 243 << vie_encoder_->captured_frame_count_ |
| 241 << ", dropped (due to encoder blocked) " | 244 << ", dropped (due to encoder blocked) " |
| 242 << vie_encoder_->dropped_frame_count_ << ", interval_ms " | 245 << vie_encoder_->dropped_frame_count_ << ", interval_ms " |
| 243 << kFrameLogIntervalMs; | 246 << kFrameLogIntervalMs; |
| 244 vie_encoder_->captured_frame_count_ = 0; | 247 vie_encoder_->captured_frame_count_ = 0; |
| 245 vie_encoder_->dropped_frame_count_ = 0; | 248 vie_encoder_->dropped_frame_count_ = 0; |
| 246 } | 249 } |
| 247 return true; | 250 return true; |
| 248 } | 251 } |
| 249 VideoFrame frame_; | 252 VideoFrame frame_; |
| 250 ViEEncoder* const vie_encoder_; | 253 ViEEncoder* const vie_encoder_; |
| 251 const int64_t time_when_posted_ms_; | 254 const int64_t time_when_posted_ms_; |
| 252 const bool log_stats_; | 255 const bool log_stats_; |
| 253 }; | 256 }; |
| 254 | 257 |
| 255 // VideoSourceProxy is responsible ensuring thread safety between calls to | 258 // VideoSourceProxy is responsible ensuring thread safety between calls to |
| 256 // ViEEncoder::SetSource that will happen on libjingles worker thread when a | 259 // ViEEncoder::SetSource that will happen on libjingle's worker thread when a |
| 257 // video capturer is connected to the encoder and the encoder task queue | 260 // video capturer is connected to the encoder and the encoder task queue |
| 258 // (encoder_queue_) where the encoder reports its VideoSinkWants. | 261 // (encoder_queue_) where the encoder reports its VideoSinkWants. |
| 259 class ViEEncoder::VideoSourceProxy { | 262 class ViEEncoder::VideoSourceProxy { |
| 260 public: | 263 public: |
| 261 explicit VideoSourceProxy(ViEEncoder* vie_encoder) | 264 explicit VideoSourceProxy(ViEEncoder* vie_encoder) |
| 262 : vie_encoder_(vie_encoder), source_(nullptr) {} | 265 : vie_encoder_(vie_encoder), |
| 266 resolution_scaling_disabled_(false), | |
| 267 source_(nullptr) {} | |
| 263 | 268 |
| 264 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source) { | 269 void SetSource(rtc::VideoSourceInterface<VideoFrame>* source, |
| 270 bool disable_resolution_scaling) { | |
| 271 // Called on libjingle's worker thread. | |
| 265 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_); | 272 RTC_DCHECK_CALLED_SEQUENTIALLY(&main_checker_); |
| 266 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr; | 273 rtc::VideoSourceInterface<VideoFrame>* old_source = nullptr; |
| 274 rtc::VideoSinkWants wants; | |
| 267 { | 275 { |
| 268 rtc::CritScope lock(&crit_); | 276 rtc::CritScope lock(&crit_); |
| 269 old_source = source_; | 277 old_source = source_; |
| 270 source_ = source; | 278 source_ = source; |
| 279 resolution_scaling_disabled_ = disable_resolution_scaling; | |
| 280 wants = disable_resolution_scaling ? disabled_scaling_sink_wants_ | |
| 281 : sink_wants_; | |
| 271 } | 282 } |
| 272 | 283 |
| 273 if (old_source != source && old_source != nullptr) { | 284 if (old_source != source && old_source != nullptr) { |
| 274 old_source->RemoveSink(vie_encoder_); | 285 old_source->RemoveSink(vie_encoder_); |
| 275 } | 286 } |
| 276 | 287 |
| 277 if (!source) { | 288 if (!source) { |
| 278 return; | 289 return; |
| 279 } | 290 } |
| 280 | 291 |
| 281 // TODO(perkj): Let VideoSourceProxy implement LoadObserver and truly send | |
| 282 // CPU load as sink wants. | |
| 283 rtc::VideoSinkWants wants; | |
| 284 source->AddOrUpdateSink(vie_encoder_, wants); | 292 source->AddOrUpdateSink(vie_encoder_, wants); |
| 285 } | 293 } |
| 286 | 294 |
| 295 void SetWantsRotationApplied(bool rotation_applied) { | |
| 296 rtc::CritScope lock(&crit_); | |
| 297 sink_wants_.rotation_applied = rotation_applied; | |
| 298 disabled_scaling_sink_wants_.rotation_applied = rotation_applied; | |
| 299 if (source_) { | |
| 300 source_->AddOrUpdateSink(vie_encoder_, resolution_scaling_disabled_ | |
| 301 ? disabled_scaling_sink_wants_ | |
| 302 : sink_wants_); | |
| 303 } | |
| 304 } | |
| 305 | |
| 306 void RequestResolutionLowerThan(int pixel_count) { | |
| 307 // Called on the encoder task queue. | |
| 308 rtc::CritScope lock(&crit_); | |
| 309 if (resolution_scaling_disabled_) { | |
| 310 // This can happen since |resolution_scaling_disabled_| is set on | |
| 311 // libjingle's worker thread but the adaptation is done on the encoder | |
| 312 // task | |
| 313 // queue. | |
| 314 return; | |
| 315 } | |
| 316 // The input video frame size will have a resolution with less than or | |
| 317 // equal to |max_pixel_count| depending on how the source can scale the | |
| 318 // input frame size. | |
| 319 sink_wants_.max_pixel_count = rtc::Optional<int>((pixel_count * 3) / 5); | |
| 320 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(); | |
| 321 if (source_) | |
| 322 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | |
| 323 } | |
| 324 | |
| 325 void RequestHigherResolutionThan(int pixel_count) { | |
| 326 rtc::CritScope lock(&crit_); | |
| 327 if (resolution_scaling_disabled_) { | |
| 328 // This can happen since |resolution_scaling_disabled_| is set on | |
| 329 // libjingles worker thread but the adaptation is done on the encoder task | |
| 330 // queue. | |
| 331 return; | |
| 332 } | |
| 333 // The input video frame size will have a resolution with "one step up" | |
| 334 // pixels than |max_pixel_count_step_up| where "one step up" depends on | |
| 335 // how the source can scale the input frame size. | |
| 336 sink_wants_.max_pixel_count = rtc::Optional<int>(); | |
| 337 sink_wants_.max_pixel_count_step_up = rtc::Optional<int>(pixel_count); | |
| 338 if (source_) | |
| 339 source_->AddOrUpdateSink(vie_encoder_, sink_wants_); | |
| 340 } | |
| 341 | |
| 287 private: | 342 private: |
| 288 rtc::CriticalSection crit_; | 343 rtc::CriticalSection crit_; |
| 289 rtc::SequencedTaskChecker main_checker_; | 344 rtc::SequencedTaskChecker main_checker_; |
| 290 ViEEncoder* vie_encoder_; | 345 ViEEncoder* const vie_encoder_; |
| 346 rtc::VideoSinkWants sink_wants_ GUARDED_BY(&crit_); | |
| 347 rtc::VideoSinkWants disabled_scaling_sink_wants_ GUARDED_BY(&crit_); | |
| 348 bool resolution_scaling_disabled_ GUARDED_BY(&crit_); | |
| 291 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); | 349 rtc::VideoSourceInterface<VideoFrame>* source_ GUARDED_BY(&crit_); |
| 292 | 350 |
| 293 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); | 351 RTC_DISALLOW_COPY_AND_ASSIGN(VideoSourceProxy); |
| 294 }; | 352 }; |
| 295 | 353 |
| 296 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 354 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| 297 SendStatisticsProxy* stats_proxy, | 355 SendStatisticsProxy* stats_proxy, |
| 298 const VideoSendStream::Config::EncoderSettings& settings, | 356 const VideoSendStream::Config::EncoderSettings& settings, |
| 299 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 357 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
| 300 LoadObserver* overuse_callback, | |
| 301 EncodedFrameObserver* encoder_timing) | 358 EncodedFrameObserver* encoder_timing) |
| 302 : shutdown_event_(true /* manual_reset */, false), | 359 : shutdown_event_(true /* manual_reset */, false), |
| 303 number_of_cores_(number_of_cores), | 360 number_of_cores_(number_of_cores), |
| 304 source_proxy_(new VideoSourceProxy(this)), | 361 source_proxy_(new VideoSourceProxy(this)), |
| 305 sink_(nullptr), | 362 sink_(nullptr), |
| 306 settings_(settings), | 363 settings_(settings), |
| 307 codec_type_(PayloadNameToCodecType(settings.payload_name)), | 364 codec_type_(PayloadNameToCodecType(settings.payload_name)), |
| 308 video_sender_(Clock::GetRealTimeClock(), this, this), | 365 video_sender_(Clock::GetRealTimeClock(), this, this), |
| 366 disable_resolution_scaling_(false), | |
| 309 overuse_detector_(Clock::GetRealTimeClock(), | 367 overuse_detector_(Clock::GetRealTimeClock(), |
| 310 GetCpuOveruseOptions(settings.full_overuse_time), | 368 GetCpuOveruseOptions(settings.full_overuse_time), |
| 311 this, | 369 this, |
| 312 encoder_timing, | 370 encoder_timing, |
| 313 stats_proxy), | 371 stats_proxy), |
| 314 load_observer_(overuse_callback), | |
| 315 stats_proxy_(stats_proxy), | 372 stats_proxy_(stats_proxy), |
| 316 pre_encode_callback_(pre_encode_callback), | 373 pre_encode_callback_(pre_encode_callback), |
| 317 module_process_thread_(nullptr), | 374 module_process_thread_(nullptr), |
| 318 pending_encoder_reconfiguration_(false), | 375 pending_encoder_reconfiguration_(false), |
| 319 encoder_start_bitrate_bps_(0), | 376 encoder_start_bitrate_bps_(0), |
| 320 max_data_payload_length_(0), | 377 max_data_payload_length_(0), |
| 321 last_observed_bitrate_bps_(0), | 378 last_observed_bitrate_bps_(0), |
| 322 encoder_paused_and_dropped_frame_(false), | 379 encoder_paused_and_dropped_frame_(false), |
| 323 has_received_sli_(false), | 380 has_received_sli_(false), |
| 324 picture_id_sli_(0), | 381 picture_id_sli_(0), |
| 325 has_received_rpsi_(false), | 382 has_received_rpsi_(false), |
| 326 picture_id_rpsi_(0), | 383 picture_id_rpsi_(0), |
| 327 clock_(Clock::GetRealTimeClock()), | 384 clock_(Clock::GetRealTimeClock()), |
| 385 cpu_restricted_counter_(0), | |
| 386 last_frame_width_(0), | |
| 387 last_frame_height_(0), | |
| 328 last_captured_timestamp_(0), | 388 last_captured_timestamp_(0), |
| 329 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 389 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
| 330 clock_->TimeInMilliseconds()), | 390 clock_->TimeInMilliseconds()), |
| 331 last_frame_log_ms_(clock_->TimeInMilliseconds()), | 391 last_frame_log_ms_(clock_->TimeInMilliseconds()), |
| 332 captured_frame_count_(0), | 392 captured_frame_count_(0), |
| 333 dropped_frame_count_(0), | 393 dropped_frame_count_(0), |
| 334 encoder_queue_("EncoderQueue") { | 394 encoder_queue_("EncoderQueue") { |
| 335 encoder_queue_.PostTask([this, encoder_timing] { | 395 encoder_queue_.PostTask([this, encoder_timing] { |
| 336 RTC_DCHECK_RUN_ON(&encoder_queue_); | 396 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 337 video_sender_.RegisterExternalEncoder( | 397 video_sender_.RegisterExternalEncoder( |
| 338 settings_.encoder, settings_.payload_type, settings_.internal_source); | 398 settings_.encoder, settings_.payload_type, settings_.internal_source); |
| 339 overuse_detector_.StartCheckForOveruse(); | 399 overuse_detector_.StartCheckForOveruse(); |
| 340 }); | 400 }); |
| 341 } | 401 } |
| 342 | 402 |
| 343 ViEEncoder::~ViEEncoder() { | 403 ViEEncoder::~ViEEncoder() { |
| 344 RTC_DCHECK_RUN_ON(&thread_checker_); | 404 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 345 RTC_DCHECK(shutdown_event_.Wait(0)) | 405 RTC_DCHECK(shutdown_event_.Wait(0)) |
| 346 << "Must call ::Stop() before destruction."; | 406 << "Must call ::Stop() before destruction."; |
| 347 } | 407 } |
| 348 | 408 |
| 349 void ViEEncoder::Stop() { | 409 void ViEEncoder::Stop() { |
| 350 RTC_DCHECK_RUN_ON(&thread_checker_); | 410 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 351 source_proxy_->SetSource(nullptr); | 411 source_proxy_->SetSource(nullptr, false); |
|
kthelgason
2016/10/05 12:42:20
Why hardcode false here?
perkj_webrtc
2016/10/18 07:48:21
true to disable overuse detection maybe make more
| |
| 352 encoder_queue_.PostTask([this] { | 412 encoder_queue_.PostTask([this] { |
| 353 RTC_DCHECK_RUN_ON(&encoder_queue_); | 413 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 354 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, | 414 video_sender_.RegisterExternalEncoder(nullptr, settings_.payload_type, |
| 355 false); | 415 false); |
| 356 overuse_detector_.StopCheckForOveruse(); | 416 overuse_detector_.StopCheckForOveruse(); |
| 357 shutdown_event_.Set(); | 417 shutdown_event_.Set(); |
| 358 }); | 418 }); |
| 359 | 419 |
| 360 shutdown_event_.Wait(rtc::Event::kForever); | 420 shutdown_event_.Wait(rtc::Event::kForever); |
| 361 } | 421 } |
| 362 | 422 |
| 363 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { | 423 void ViEEncoder::RegisterProcessThread(ProcessThread* module_process_thread) { |
| 364 RTC_DCHECK_RUN_ON(&thread_checker_); | 424 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 365 RTC_DCHECK(!module_process_thread_); | 425 RTC_DCHECK(!module_process_thread_); |
| 366 module_process_thread_ = module_process_thread; | 426 module_process_thread_ = module_process_thread; |
| 367 module_process_thread_->RegisterModule(&video_sender_); | 427 module_process_thread_->RegisterModule(&video_sender_); |
| 368 module_process_thread_checker_.DetachFromThread(); | 428 module_process_thread_checker_.DetachFromThread(); |
| 369 } | 429 } |
| 370 | 430 |
| 371 void ViEEncoder::DeRegisterProcessThread() { | 431 void ViEEncoder::DeRegisterProcessThread() { |
| 372 RTC_DCHECK_RUN_ON(&thread_checker_); | 432 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 373 module_process_thread_->DeRegisterModule(&video_sender_); | 433 module_process_thread_->DeRegisterModule(&video_sender_); |
| 374 } | 434 } |
| 375 | 435 |
| 376 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source) { | 436 void ViEEncoder::SetSource(rtc::VideoSourceInterface<VideoFrame>* source, |
| 437 bool disable_resolution_scaling) { | |
| 377 RTC_DCHECK_RUN_ON(&thread_checker_); | 438 RTC_DCHECK_RUN_ON(&thread_checker_); |
| 378 source_proxy_->SetSource(source); | 439 source_proxy_->SetSource(source, disable_resolution_scaling); |
| 440 encoder_queue_.PostTask([this, disable_resolution_scaling] { | |
| 441 RTC_DCHECK_RUN_ON(&encoder_queue_); | |
| 442 if (disable_resolution_scaling_ != disable_resolution_scaling) { | |
| 443 stats_proxy_->SetCpuRestrictedResolution(!disable_resolution_scaling && | |
| 444 cpu_restricted_counter_ != 0); | |
| 445 } | |
| 446 disable_resolution_scaling_ = disable_resolution_scaling; | |
| 447 }); | |
| 379 } | 448 } |
| 380 | 449 |
| 381 void ViEEncoder::SetSink(EncoderSink* sink) { | 450 void ViEEncoder::SetSink(EncoderSink* sink, bool rotation_applied) { |
| 382 encoder_queue_.PostTask([this, sink] { | 451 source_proxy_->SetWantsRotationApplied(rotation_applied); |
| 452 encoder_queue_.PostTask([this, sink, rotation_applied] { | |
|
kthelgason
2016/10/06 16:46:12
captured variable unused in lambda
perkj_webrtc
2016/10/18 07:48:21
Done.
| |
| 383 RTC_DCHECK_RUN_ON(&encoder_queue_); | 453 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 384 sink_ = sink; | 454 sink_ = sink; |
| 385 }); | 455 }); |
| 386 } | 456 } |
| 387 | 457 |
| 388 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { | 458 void ViEEncoder::SetStartBitrate(int start_bitrate_bps) { |
| 389 encoder_queue_.PostTask([this, start_bitrate_bps] { | 459 encoder_queue_.PostTask([this, start_bitrate_bps] { |
| 390 RTC_DCHECK_RUN_ON(&encoder_queue_); | 460 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 391 encoder_start_bitrate_bps_ = start_bitrate_bps; | 461 encoder_start_bitrate_bps_ = start_bitrate_bps; |
| 392 }); | 462 }); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 456 if (stats_proxy_) { | 526 if (stats_proxy_) { |
| 457 stats_proxy_->OnEncoderReconfigured(encoder_config_, | 527 stats_proxy_->OnEncoderReconfigured(encoder_config_, |
| 458 rate_allocator_->GetPreferedBitrate()); | 528 rate_allocator_->GetPreferedBitrate()); |
| 459 } | 529 } |
| 460 sink_->OnEncoderConfigurationChanged( | 530 sink_->OnEncoderConfigurationChanged( |
| 461 std::move(streams), encoder_config_.min_transmit_bitrate_bps); | 531 std::move(streams), encoder_config_.min_transmit_bitrate_bps); |
| 462 } | 532 } |
| 463 | 533 |
| 464 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { | 534 void ViEEncoder::OnFrame(const VideoFrame& video_frame) { |
| 465 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); | 535 RTC_DCHECK_RUNS_SERIALIZED(&incoming_frame_race_checker_); |
| 466 stats_proxy_->OnIncomingFrame(video_frame.width(), video_frame.height()); | |
| 467 | |
| 468 VideoFrame incoming_frame = video_frame; | 536 VideoFrame incoming_frame = video_frame; |
| 469 | 537 |
| 470 // Local time in webrtc time base. | 538 // Local time in webrtc time base. |
| 471 int64_t current_time = clock_->TimeInMilliseconds(); | 539 int64_t current_time = clock_->TimeInMilliseconds(); |
| 472 incoming_frame.set_render_time_ms(current_time); | 540 incoming_frame.set_render_time_ms(current_time); |
| 473 | 541 |
| 474 // Capture time may come from clock with an offset and drift from clock_. | 542 // Capture time may come from clock with an offset and drift from clock_. |
| 475 int64_t capture_ntp_time_ms; | 543 int64_t capture_ntp_time_ms; |
| 476 if (video_frame.ntp_time_ms() != 0) { | 544 if (video_frame.ntp_time_ms() != 0) { |
| 477 capture_ntp_time_ms = video_frame.ntp_time_ms(); | 545 capture_ntp_time_ms = video_frame.ntp_time_ms(); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 531 // End trace event on first frame after encoder resumes, if frame was dropped. | 599 // End trace event on first frame after encoder resumes, if frame was dropped. |
| 532 if (encoder_paused_and_dropped_frame_) { | 600 if (encoder_paused_and_dropped_frame_) { |
| 533 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); | 601 TRACE_EVENT_ASYNC_END0("webrtc", "EncoderPaused", this); |
| 534 } | 602 } |
| 535 encoder_paused_and_dropped_frame_ = false; | 603 encoder_paused_and_dropped_frame_ = false; |
| 536 } | 604 } |
| 537 | 605 |
| 538 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, | 606 void ViEEncoder::EncodeVideoFrame(const VideoFrame& video_frame, |
| 539 int64_t time_when_posted_in_ms) { | 607 int64_t time_when_posted_in_ms) { |
| 540 RTC_DCHECK_RUN_ON(&encoder_queue_); | 608 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 609 | |
| 541 if (pre_encode_callback_) | 610 if (pre_encode_callback_) |
| 542 pre_encode_callback_->OnFrame(video_frame); | 611 pre_encode_callback_->OnFrame(video_frame); |
| 543 | 612 |
| 544 if (video_frame.width() != last_frame_info_->width || | 613 if (video_frame.width() != last_frame_info_->width || |
| 545 video_frame.height() != last_frame_info_->height || | 614 video_frame.height() != last_frame_info_->height || |
| 546 video_frame.rotation() != last_frame_info_->rotation || | 615 video_frame.rotation() != last_frame_info_->rotation || |
| 547 video_frame.is_texture() != last_frame_info_->is_texture) { | 616 video_frame.is_texture() != last_frame_info_->is_texture) { |
| 548 pending_encoder_reconfiguration_ = true; | 617 pending_encoder_reconfiguration_ = true; |
| 549 last_frame_info_ = rtc::Optional<VideoFrameInfo>( | 618 last_frame_info_ = rtc::Optional<VideoFrameInfo>( |
| 550 VideoFrameInfo(video_frame.width(), video_frame.height(), | 619 VideoFrameInfo(video_frame.width(), video_frame.height(), |
| 551 video_frame.rotation(), video_frame.is_texture())); | 620 video_frame.rotation(), video_frame.is_texture())); |
| 552 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" | 621 LOG(LS_INFO) << "Video frame parameters changed: dimensions=" |
| 553 << last_frame_info_->width << "x" << last_frame_info_->height | 622 << last_frame_info_->width << "x" << last_frame_info_->height |
| 554 << ", rotation=" << last_frame_info_->rotation | 623 << ", rotation=" << last_frame_info_->rotation |
| 555 << ", texture=" << last_frame_info_->is_texture; | 624 << ", texture=" << last_frame_info_->is_texture; |
| 556 } | 625 } |
| 557 | 626 |
| 558 if (pending_encoder_reconfiguration_) { | 627 if (pending_encoder_reconfiguration_) { |
| 559 ReconfigureEncoder(); | 628 ReconfigureEncoder(); |
| 560 } | 629 } |
| 561 | 630 |
| 562 if (EncoderPaused()) { | 631 if (EncoderPaused()) { |
| 563 TraceFrameDropStart(); | 632 TraceFrameDropStart(); |
| 564 return; | 633 return; |
| 565 } | 634 } |
| 566 TraceFrameDropEnd(); | 635 TraceFrameDropEnd(); |
| 567 | 636 |
| 637 last_frame_height_ = video_frame.height(); | |
| 638 last_frame_width_ = video_frame.width(); | |
| 639 | |
| 568 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), | 640 TRACE_EVENT_ASYNC_STEP0("webrtc", "Video", video_frame.render_time_ms(), |
| 569 "Encode"); | 641 "Encode"); |
| 570 | 642 |
| 571 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); | 643 overuse_detector_.FrameCaptured(video_frame, time_when_posted_in_ms); |
| 572 | 644 |
| 573 if (codec_type_ == webrtc::kVideoCodecVP8) { | 645 if (codec_type_ == webrtc::kVideoCodecVP8) { |
| 574 webrtc::CodecSpecificInfo codec_specific_info; | 646 webrtc::CodecSpecificInfo codec_specific_info; |
| 575 codec_specific_info.codecType = webrtc::kVideoCodecVP8; | 647 codec_specific_info.codecType = webrtc::kVideoCodecVP8; |
| 576 | 648 |
| 577 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = | 649 codec_specific_info.codecSpecific.VP8.hasReceivedRPSI = |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 | 762 |
| 691 if (stats_proxy_ && video_suspension_changed) { | 763 if (stats_proxy_ && video_suspension_changed) { |
| 692 LOG(LS_INFO) << "Video suspend state changed to: " | 764 LOG(LS_INFO) << "Video suspend state changed to: " |
| 693 << (video_is_suspended ? "suspended" : "not suspended"); | 765 << (video_is_suspended ? "suspended" : "not suspended"); |
| 694 stats_proxy_->OnSuspendChange(video_is_suspended); | 766 stats_proxy_->OnSuspendChange(video_is_suspended); |
| 695 } | 767 } |
| 696 } | 768 } |
| 697 | 769 |
| 698 void ViEEncoder::OveruseDetected() { | 770 void ViEEncoder::OveruseDetected() { |
| 699 RTC_DCHECK_RUN_ON(&encoder_queue_); | 771 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 700 // TODO(perkj): When ViEEncoder inherit rtc::VideoSink instead of | 772 |
| 701 // VideoCaptureInput |load_observer_| should be removed and overuse be | 773 if (disable_resolution_scaling_) |
|
kthelgason
2016/10/05 12:42:20
Rather than checking this here, I feel it would ma
| |
| 702 // expressed as rtc::VideoSinkWants instead. | 774 return; |
| 703 if (load_observer_) | 775 |
| 704 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); | 776 if (cpu_restricted_counter_ >= kMaxCpuDowngrades) { |
| 777 return; | |
| 778 } | |
| 779 // Request lower resolution if the current resolution is lower than last time | |
| 780 // we asked for the resolution to be lowered. | |
| 781 // Update stats accordingly. | |
| 782 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
| 783 if (current_pixel_count < | |
| 784 max_pixel_count_.value_or(current_pixel_count + 1)) { | |
| 785 max_pixel_count_ = rtc::Optional<int>(current_pixel_count); | |
| 786 max_pixel_count_step_up_ = rtc::Optional<int>(); | |
| 787 stats_proxy_->OnCpuRestrictedResolutionChanged(true); | |
| 788 ++cpu_restricted_counter_; | |
| 789 source_proxy_->RequestResolutionLowerThan(current_pixel_count); | |
| 790 } | |
| 705 } | 791 } |
| 706 | 792 |
| 707 void ViEEncoder::NormalUsage() { | 793 void ViEEncoder::NormalUsage() { |
| 708 RTC_DCHECK_RUN_ON(&encoder_queue_); | 794 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 709 if (load_observer_) | 795 if (disable_resolution_scaling_) |
|
kthelgason
2016/10/05 12:42:20
Ditto
| |
| 710 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); | 796 return; |
| 797 | |
| 798 int current_pixel_count = last_frame_height_ * last_frame_width_; | |
| 799 // Request higher resolution if we are cpu restricted and the the current | |
| 800 // resolution is higher than last time we requested higher resolution. | |
| 801 // Update stats accordingly. | |
| 802 if (cpu_restricted_counter_ > 0 && | |
| 803 current_pixel_count > max_pixel_count_step_up_.value_or(0)) { | |
| 804 max_pixel_count_ = rtc::Optional<int>(); | |
| 805 max_pixel_count_step_up_ = rtc::Optional<int>(current_pixel_count); | |
| 806 --cpu_restricted_counter_; | |
| 807 stats_proxy_->OnCpuRestrictedResolutionChanged(cpu_restricted_counter_ > 0); | |
| 808 source_proxy_->RequestHigherResolutionThan(current_pixel_count); | |
| 809 } | |
| 711 } | 810 } |
| 712 | 811 |
| 713 } // namespace webrtc | 812 } // namespace webrtc |
| OLD | NEW |