Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1624)

Side by Side Diff: webrtc/video/vie_encoder.cc

Issue 2298213002: Add periodic logging of number of captured and dropped frames in VideoCaptureInput. (Closed)
Patch Set: rebase Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Time interval for logging frame counts.
31 const int64_t kFrameLogIntervalMs = 60000;
31 32
32 VideoCodecType PayloadNameToCodecType(const std::string& payload_name) { 33 VideoCodecType PayloadNameToCodecType(const std::string& payload_name) {
33 if (payload_name == "VP8") 34 if (payload_name == "VP8")
34 return kVideoCodecVP8; 35 return kVideoCodecVP8;
35 if (payload_name == "VP9") 36 if (payload_name == "VP9")
36 return kVideoCodecVP9; 37 return kVideoCodecVP9;
37 if (payload_name == "H264") 38 if (payload_name == "H264")
38 return kVideoCodecH264; 39 return kVideoCodecH264;
39 return kVideoCodecGeneric; 40 return kVideoCodecGeneric;
40 } 41 }
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 } 195 }
195 return options; 196 return options;
196 } 197 }
197 198
198 } // namespace 199 } // namespace
199 200
200 class ViEEncoder::EncodeTask : public rtc::QueuedTask { 201 class ViEEncoder::EncodeTask : public rtc::QueuedTask {
201 public: 202 public:
202 EncodeTask(const VideoFrame& frame, 203 EncodeTask(const VideoFrame& frame,
203 ViEEncoder* vie_encoder, 204 ViEEncoder* vie_encoder,
204 int64_t time_when_posted_in_ms) 205 int64_t time_when_posted_in_ms,
206 bool log_stats)
205 : vie_encoder_(vie_encoder), 207 : vie_encoder_(vie_encoder),
206 time_when_posted_ms_(time_when_posted_in_ms) { 208 time_when_posted_ms_(time_when_posted_in_ms),
209 log_stats_(log_stats) {
207 frame_.ShallowCopy(frame); 210 frame_.ShallowCopy(frame);
208 ++vie_encoder_->posted_frames_waiting_for_encode_; 211 ++vie_encoder_->posted_frames_waiting_for_encode_;
209 } 212 }
210 213
211 private: 214 private:
212 bool Run() override { 215 bool Run() override {
216 RTC_DCHECK_RUN_ON(&vie_encoder_->encoder_queue_);
213 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0); 217 RTC_DCHECK_GT(vie_encoder_->posted_frames_waiting_for_encode_.Value(), 0);
218 ++vie_encoder_->captured_frame_count_;
214 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) { 219 if (--vie_encoder_->posted_frames_waiting_for_encode_ == 0) {
215 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_); 220 vie_encoder_->EncodeVideoFrame(frame_, time_when_posted_ms_);
216 } else { 221 } else {
217 // There is a newer frame in flight. Do not encode this frame. 222 // There is a newer frame in flight. Do not encode this frame.
218 LOG(LS_VERBOSE) 223 LOG(LS_VERBOSE)
219 << "Incoming frame dropped due to that the encoder is blocked."; 224 << "Incoming frame dropped due to that the encoder is blocked.";
225 ++vie_encoder_->dropped_frame_count_;
226 }
227 if (log_stats_) {
228 LOG(LS_INFO) << "Number of frames: captured "
229 << vie_encoder_->captured_frame_count_
230 << ", dropped (due to encoder blocked) "
231 << vie_encoder_->dropped_frame_count_ << ", interval_ms "
232 << kFrameLogIntervalMs;
233 vie_encoder_->captured_frame_count_ = 0;
234 vie_encoder_->dropped_frame_count_ = 0;
220 } 235 }
221 return true; 236 return true;
222 } 237 }
223 VideoFrame frame_; 238 VideoFrame frame_;
224 ViEEncoder* const vie_encoder_; 239 ViEEncoder* const vie_encoder_;
225 const int64_t time_when_posted_ms_; 240 const int64_t time_when_posted_ms_;
241 const bool log_stats_;
226 }; 242 };
227 243
228 ViEEncoder::ViEEncoder(uint32_t number_of_cores, 244 ViEEncoder::ViEEncoder(uint32_t number_of_cores,
229 SendStatisticsProxy* stats_proxy, 245 SendStatisticsProxy* stats_proxy,
230 const VideoSendStream::Config::EncoderSettings& settings, 246 const VideoSendStream::Config::EncoderSettings& settings,
231 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback, 247 rtc::VideoSinkInterface<VideoFrame>* pre_encode_callback,
232 LoadObserver* overuse_callback, 248 LoadObserver* overuse_callback,
233 EncodedFrameObserver* encoder_timing) 249 EncodedFrameObserver* encoder_timing)
234 : shutdown_event_(true /* manual_reset */, false), 250 : shutdown_event_(true /* manual_reset */, false),
235 number_of_cores_(number_of_cores), 251 number_of_cores_(number_of_cores),
(...skipping 14 matching lines...) Expand all
250 last_observed_bitrate_bps_(0), 266 last_observed_bitrate_bps_(0),
251 encoder_paused_and_dropped_frame_(false), 267 encoder_paused_and_dropped_frame_(false),
252 has_received_sli_(false), 268 has_received_sli_(false),
253 picture_id_sli_(0), 269 picture_id_sli_(0),
254 has_received_rpsi_(false), 270 has_received_rpsi_(false),
255 picture_id_rpsi_(0), 271 picture_id_rpsi_(0),
256 clock_(Clock::GetRealTimeClock()), 272 clock_(Clock::GetRealTimeClock()),
257 last_captured_timestamp_(0), 273 last_captured_timestamp_(0),
258 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() - 274 delta_ntp_internal_ms_(clock_->CurrentNtpInMilliseconds() -
259 clock_->TimeInMilliseconds()), 275 clock_->TimeInMilliseconds()),
276 last_frame_log_ms_(clock_->TimeInMilliseconds()),
277 captured_frame_count_(0),
278 dropped_frame_count_(0),
260 encoder_queue_("EncoderQueue") { 279 encoder_queue_("EncoderQueue") {
261 vp_->EnableTemporalDecimation(false); 280 vp_->EnableTemporalDecimation(false);
262 281
263 encoder_queue_.PostTask([this, encoder_timing] { 282 encoder_queue_.PostTask([this, encoder_timing] {
264 RTC_DCHECK_RUN_ON(&encoder_queue_); 283 RTC_DCHECK_RUN_ON(&encoder_queue_);
265 video_sender_.RegisterExternalEncoder( 284 video_sender_.RegisterExternalEncoder(
266 settings_.encoder, settings_.payload_type, settings_.internal_source); 285 settings_.encoder, settings_.payload_type, settings_.internal_source);
267 overuse_detector_.StartCheckForOveruse(); 286 overuse_detector_.StartCheckForOveruse();
268 }); 287 });
269 } 288 }
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 412
394 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) { 413 if (incoming_frame.ntp_time_ms() <= last_captured_timestamp_) {
395 // We don't allow the same capture time for two frames, drop this one. 414 // We don't allow the same capture time for two frames, drop this one.
396 LOG(LS_WARNING) << "Same/old NTP timestamp (" 415 LOG(LS_WARNING) << "Same/old NTP timestamp ("
397 << incoming_frame.ntp_time_ms() 416 << incoming_frame.ntp_time_ms()
398 << " <= " << last_captured_timestamp_ 417 << " <= " << last_captured_timestamp_
399 << ") for incoming frame. Dropping."; 418 << ") for incoming frame. Dropping.";
400 return; 419 return;
401 } 420 }
402 421
422 bool log_stats = false;
423 if (current_time - last_frame_log_ms_ > kFrameLogIntervalMs) {
424 last_frame_log_ms_ = current_time;
425 log_stats = true;
426 }
427
403 last_captured_timestamp_ = incoming_frame.ntp_time_ms(); 428 last_captured_timestamp_ = incoming_frame.ntp_time_ms();
404 encoder_queue_.PostTask(std::unique_ptr<rtc::QueuedTask>( 429 encoder_queue_.PostTask(std::unique_ptr<rtc::QueuedTask>(new EncodeTask(
405 new EncodeTask(incoming_frame, this, clock_->TimeInMilliseconds()))); 430 incoming_frame, this, clock_->TimeInMilliseconds(), log_stats)));
406 } 431 }
407 432
408 bool ViEEncoder::EncoderPaused() const { 433 bool ViEEncoder::EncoderPaused() const {
409 RTC_DCHECK_RUN_ON(&encoder_queue_); 434 RTC_DCHECK_RUN_ON(&encoder_queue_);
410 // Pause video if paused by caller or as long as the network is down or the 435 // Pause video if paused by caller or as long as the network is down or the
411 // pacer queue has grown too large in buffered mode. 436 // pacer queue has grown too large in buffered mode.
412 // If the pacer queue has grown too large or the network is down, 437 // If the pacer queue has grown too large or the network is down,
413 // last_observed_bitrate_bps_ will be 0. 438 // last_observed_bitrate_bps_ will be 0.
414 return last_observed_bitrate_bps_ == 0; 439 return last_observed_bitrate_bps_ == 0;
415 } 440 }
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 load_observer_->OnLoadUpdate(LoadObserver::kOveruse); 619 load_observer_->OnLoadUpdate(LoadObserver::kOveruse);
595 } 620 }
596 621
597 void ViEEncoder::NormalUsage() { 622 void ViEEncoder::NormalUsage() {
598 RTC_DCHECK_RUN_ON(&encoder_queue_); 623 RTC_DCHECK_RUN_ON(&encoder_queue_);
599 if (load_observer_) 624 if (load_observer_)
600 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse); 625 load_observer_->OnLoadUpdate(LoadObserver::kUnderuse);
601 } 626 }
602 627
603 } // namespace webrtc 628 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/video/vie_encoder.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698