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 |
| 11 #include "webrtc/video/vie_encoder.h" | 11 #include "webrtc/video/vie_encoder.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <limits> | 14 #include <limits> |
| 15 | 15 |
| 16 #include "webrtc/base/checks.h" | 16 #include "webrtc/base/checks.h" |
| 17 #include "webrtc/base/logging.h" | 17 #include "webrtc/base/logging.h" |
| 18 #include "webrtc/base/trace_event.h" | 18 #include "webrtc/base/trace_event.h" |
| 19 #include "webrtc/base/timeutils.h" | 19 #include "webrtc/base/timeutils.h" |
| 20 #include "webrtc/modules/pacing/paced_sender.h" | 20 #include "webrtc/modules/pacing/paced_sender.h" |
| 21 #include "webrtc/modules/video_coding/include/video_coding.h" | 21 #include "webrtc/modules/video_coding/include/video_coding.h" |
| 22 #include "webrtc/modules/video_coding/include/video_coding_defines.h" | 22 #include "webrtc/modules/video_coding/include/video_coding_defines.h" |
| 23 #include "webrtc/system_wrappers/include/metrics.h" | |
| 24 #include "webrtc/video/overuse_frame_detector.h" | 23 #include "webrtc/video/overuse_frame_detector.h" |
| 25 #include "webrtc/video/send_statistics_proxy.h" | 24 #include "webrtc/video/send_statistics_proxy.h" |
| 26 #include "webrtc/video_frame.h" | 25 #include "webrtc/video_frame.h" |
| 27 | 26 |
| 28 namespace webrtc { | 27 namespace webrtc { |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 30 const int64_t kFrameLogIntervalMs = 60000; | |
|
perkj_webrtc
2016/09/08 07:34:40
Can you please add a comment about what this does?
åsapersson
2016/09/08 08:17:53
Done.
| |
| 31 | 31 |
| 32 VideoCodecType PayloadNameToCodecType(const std::string& payload_name) { | 32 VideoCodecType PayloadNameToCodecType(const std::string& payload_name) { |
| 33 if (payload_name == "VP8") | 33 if (payload_name == "VP8") |
| 34 return kVideoCodecVP8; | 34 return kVideoCodecVP8; |
| 35 if (payload_name == "VP9") | 35 if (payload_name == "VP9") |
| 36 return kVideoCodecVP9; | 36 return kVideoCodecVP9; |
| 37 if (payload_name == "H264") | 37 if (payload_name == "H264") |
| 38 return kVideoCodecH264; | 38 return kVideoCodecH264; |
| 39 return kVideoCodecGeneric; | 39 return kVideoCodecGeneric; |
| 40 } | 40 } |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 192 options.low_encode_usage_threshold_percent = 150; | 192 options.low_encode_usage_threshold_percent = 150; |
| 193 options.high_encode_usage_threshold_percent = 200; | 193 options.high_encode_usage_threshold_percent = 200; |
| 194 } | 194 } |
| 195 return options; | 195 return options; |
| 196 } | 196 } |
| 197 | 197 |
| 198 } // namespace | 198 } // namespace |
| 199 | 199 |
| 200 class ViEEncoder::EncodeTask : public rtc::QueuedTask { | 200 class ViEEncoder::EncodeTask : public rtc::QueuedTask { |
| 201 public: | 201 public: |
| 202 EncodeTask(const VideoFrame& frame, ViEEncoder* vie_encoder) | 202 EncodeTask(const VideoFrame& frame, ViEEncoder* vie_encoder, bool log_stats) |
| 203 : vie_encoder_(vie_encoder) { | 203 : vie_encoder_(vie_encoder), log_stats_(log_stats) { |
| 204 frame_.ShallowCopy(frame); | 204 frame_.ShallowCopy(frame); |
| 205 ++vie_encoder_->posted_frames_waiting_for_encode_; | 205 ++vie_encoder_->posted_frames_waiting_for_encode_; |
| 206 } | 206 } |
| 207 | 207 |
| 208 private: | 208 private: |
| 209 bool Run() override { | 209 bool Run() override { |
| 210 RTC_DCHECK_RUN_ON(&vie_encoder_->encoder_queue_); | |
| 210 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); | 211 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); |
| 212 ++vie_encoder_->captured_frame_count_; | |
| 211 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { | 213 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { |
| 212 vie_encoder_->EncodeVideoFrame(frame_); | 214 vie_encoder_->EncodeVideoFrame(frame_); |
| 213 } else { | 215 } else { |
| 214 // There is a newer frame in flight. Do not encode this frame. | 216 // There is a newer frame in flight. Do not encode this frame. |
| 215 LOG(LS_VERBOSE) | 217 LOG(LS_VERBOSE) |
| 216 << "Incoming frame dropped due to that the encoder is blocked."; | 218 << "Incoming frame dropped due to that the encoder is blocked."; |
| 219 ++vie_encoder_->dropped_frame_count_; | |
| 220 } | |
| 221 if (log_stats_) { | |
| 222 LOG(LS_INFO) << "Number of frames: captured " | |
| 223 << vie_encoder_->captured_frame_count_ << ", dropped " | |
|
perkj_webrtc
2016/09/08 07:34:40
add the reason why the frames are dropped? A frame
åsapersson
2016/09/08 08:17:53
Done.
| |
| 224 << vie_encoder_->dropped_frame_count_ << ", interval_ms " | |
| 225 << kFrameLogIntervalMs; | |
| 226 vie_encoder_->captured_frame_count_ = 0; | |
| 227 vie_encoder_->dropped_frame_count_ = 0; | |
| 217 } | 228 } |
| 218 return true; | 229 return true; |
| 219 } | 230 } |
| 220 VideoFrame frame_; | 231 VideoFrame frame_; |
| 221 ViEEncoder* vie_encoder_; | 232 ViEEncoder* vie_encoder_; |
| 233 const bool log_stats_; | |
| 222 }; | 234 }; |
| 223 | 235 |
| 224 ViEEncoder::ViEEncoder(uint32_t number_of_cores, | 236 ViEEncoder::ViEEncoder(uint32_t number_of_cores, |
| 225 SendStatisticsProxy* stats_proxy, | 237 SendStatisticsProxy* stats_proxy, |
| 226 const VideoSendStream::Config::EncoderSettings& settings, | 238 const VideoSendStream::Config::EncoderSettings& settings, |
| 227 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, | 239 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, |
| 228 LoadObserver* overuse_callback, | 240 LoadObserver* overuse_callback, |
| 229 EncodedFrameObserver* encoder_timing) | 241 EncodedFrameObserver* encoder_timing) |
| 230 : shutdown_event_(true /* manual_reset */, false), | 242 : shutdown_event_(true /* manual_reset */, false), |
| 231 number_of_cores_(number_of_cores), | 243 number_of_cores_(number_of_cores), |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 246 last_observed_bitrate_bps_(0), | 258 last_observed_bitrate_bps_(0), |
| 247 encoder_paused_and_dropped_frame_(false), | 259 encoder_paused_and_dropped_frame_(false), |
| 248 has_received_sli_(false), | 260 has_received_sli_(false), |
| 249 picture_id_sli_(0), | 261 picture_id_sli_(0), |
| 250 has_received_rpsi_(false), | 262 has_received_rpsi_(false), |
| 251 picture_id_rpsi_(0), | 263 picture_id_rpsi_(0), |
| 252 clock_(Clock::GetRealTimeClock()), | 264 clock_(Clock::GetRealTimeClock()), |
| 253 last_captured_timestamp_(0), | 265 last_captured_timestamp_(0), |
| 254 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - | 266 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - |
| 255 clock_->TimeInMilliseconds()), | 267 clock_->TimeInMilliseconds()), |
| 268 last_frame_log_ms_(clock_->TimeInMilliseconds()), | |
| 269 captured_frame_count_(0), | |
| 270 dropped_frame_count_(0), | |
| 256 encoder_queue_("EncoderQueue") { | 271 encoder_queue_("EncoderQueue") { |
| 257 vp_->EnableTemporalDecimation(false); | 272 vp_->EnableTemporalDecimation(false); |
| 258 | 273 |
| 259 encoder_queue_.PostTask([this] { | 274 encoder_queue_.PostTask([this] { |
| 260 RTC_DCHECK_RUN_ON(&encoder_queue_); | 275 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 261 video_sender_.RegisterExternalEncoder( | 276 video_sender_.RegisterExternalEncoder( |
| 262 settings_.encoder, settings_.payload_type, settings_.internal_source); | 277 settings_.encoder, settings_.payload_type, settings_.internal_source); |
| 263 }); | 278 }); |
| 264 } | 279 } |
| 265 | 280 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 | 404 |
| 390 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { | 405 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { |
| 391 // We don't allow the same capture time for two frames, drop this one. | 406 // We don't allow the same capture time for two frames, drop this one. |
| 392 LOG(LS_WARNING) << "Same/old NTP timestamp (" | 407 LOG(LS_WARNING) << "Same/old NTP timestamp (" |
| 393 << incoming_frame.ntp_time_ms() | 408 << incoming_frame.ntp_time_ms() |
| 394 << " <= " << last_captured_timestamp_ | 409 << " <= " << last_captured_timestamp_ |
| 395 << ") for incoming frame. Dropping."; | 410 << ") for incoming frame. Dropping."; |
| 396 return; | 411 return; |
| 397 } | 412 } |
| 398 | 413 |
| 414 bool log_stats = false; | |
| 415 if (current_time - last_frame_log_ms_ > kFrameLogIntervalMs) { | |
| 416 last_frame_log_ms_ = current_time; | |
| 417 log_stats = true; | |
| 418 } | |
| 419 | |
| 399 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); | 420 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); |
| 400 overuse_detector_.FrameCaptured(incoming_frame); | 421 overuse_detector_.FrameCaptured(incoming_frame); |
| 401 encoder_queue_.PostTask( | 422 encoder_queue_.PostTask(std::unique_ptr<rtc::QueuedTask>( |
| 402 std::unique_ptr<rtc::QueuedTask>(new EncodeTask(incoming_frame, this))); | 423 new EncodeTask(incoming_frame, this, log_stats))); |
| 403 } | 424 } |
| 404 | 425 |
| 405 bool ViEEncoder::EncoderPaused() const { | 426 bool ViEEncoder::EncoderPaused() const { |
| 406 RTC_DCHECK_RUN_ON(&encoder_queue_); | 427 RTC_DCHECK_RUN_ON(&encoder_queue_); |
| 407 // Pause video if paused by caller or as long as the network is down or the | 428 // Pause video if paused by caller or as long as the network is down or the |
| 408 // pacer queue has grown too large in buffered mode. | 429 // pacer queue has grown too large in buffered mode. |
| 409 // If the pacer queue has grown too large or the network is down, | 430 // If the pacer queue has grown too large or the network is down, |
| 410 // last_observed_bitrate_bps_ will be 0. | 431 // last_observed_bitrate_bps_ will be 0. |
| 411 return last_observed_bitrate_bps_ == 0; | 432 return last_observed_bitrate_bps_ == 0; |
| 412 } | 433 } |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 583 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); | 604 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); |
| 584 } | 605 } |
| 585 | 606 |
| 586 void ViEEncoder::NormalUsage() { | 607 void ViEEncoder::NormalUsage() { |
| 587 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); | 608 RTC_DCHECK_RUN_ON(&module_process_thread_checker_); |
| 588 if (load_observer_) | 609 if (load_observer_) |
| 589 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); | 610 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); |
| 590 } | 611 } |
| 591 | 612 |
| 592 } // namespace webrtc | 613 } // namespace webrtc |
| OLD | NEW |