Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 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/modules/video_coding/frame_buffer2.h" | 11 #include "webrtc/modules/video_coding/frame_buffer2.h" |
| 12 | 12 |
| 13 #include <algorithm> | 13 #include <algorithm> |
| 14 #include <cstring> | 14 #include <cstring> |
| 15 #include <queue> | 15 #include <queue> |
| 16 | 16 |
| 17 #include "webrtc/base/checks.h" | 17 #include "webrtc/base/checks.h" |
| 18 #include "webrtc/base/logging.h" | 18 #include "webrtc/base/logging.h" |
| 19 #include "webrtc/modules/video_coding/jitter_estimator.h" | 19 #include "webrtc/modules/video_coding/jitter_estimator.h" |
| 20 #include "webrtc/modules/video_coding/timing.h" | 20 #include "webrtc/modules/video_coding/timing.h" |
| 21 #include "webrtc/system_wrappers/include/clock.h" | 21 #include "webrtc/system_wrappers/include/clock.h" |
| 22 #include "webrtc/system_wrappers/include/metrics.h" | |
| 22 | 23 |
| 23 namespace webrtc { | 24 namespace webrtc { |
| 24 namespace video_coding { | 25 namespace video_coding { |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| 27 // Max number of frames the buffer will hold. | 28 // Max number of frames the buffer will hold. |
| 28 constexpr int kMaxFramesBuffered = 600; | 29 constexpr int kMaxFramesBuffered = 600; |
| 29 | 30 |
| 30 // Max number of decoded frame info that will be saved. | 31 // Max number of decoded frame info that will be saved. |
| 31 constexpr int kMaxFramesHistory = 50; | 32 constexpr int kMaxFramesHistory = 50; |
| 32 } // namespace | 33 } // namespace |
| 33 | 34 |
| 34 FrameBuffer::FrameBuffer(Clock* clock, | 35 FrameBuffer::FrameBuffer(Clock* clock, |
| 35 VCMJitterEstimator* jitter_estimator, | 36 VCMJitterEstimator* jitter_estimator, |
| 36 VCMTiming* timing) | 37 VCMTiming* timing) |
| 37 : clock_(clock), | 38 : clock_(clock), |
| 38 new_countinuous_frame_event_(false, false), | 39 new_countinuous_frame_event_(false, false), |
| 39 jitter_estimator_(jitter_estimator), | 40 jitter_estimator_(jitter_estimator), |
| 40 timing_(timing), | 41 timing_(timing), |
| 41 inter_frame_delay_(clock_->TimeInMilliseconds()), | 42 inter_frame_delay_(clock_->TimeInMilliseconds()), |
| 42 last_decoded_frame_it_(frames_.end()), | 43 last_decoded_frame_it_(frames_.end()), |
| 43 last_continuous_frame_it_(frames_.end()), | 44 last_continuous_frame_it_(frames_.end()), |
| 44 num_frames_history_(0), | 45 num_frames_history_(0), |
| 45 num_frames_buffered_(0), | 46 num_frames_buffered_(0), |
| 46 stopped_(false), | 47 stopped_(false), |
| 47 protection_mode_(kProtectionNack) {} | 48 protection_mode_(kProtectionNack), |
| 49 num_total_frames_(0), | |
| 50 num_key_frames_(0) {} | |
| 51 | |
| 52 FrameBuffer::~FrameBuffer() { | |
| 53 UpdateHistograms(); | |
| 54 } | |
| 48 | 55 |
| 49 FrameBuffer::ReturnReason FrameBuffer::NextFrame( | 56 FrameBuffer::ReturnReason FrameBuffer::NextFrame( |
| 50 int64_t max_wait_time_ms, | 57 int64_t max_wait_time_ms, |
| 51 std::unique_ptr<FrameObject>* frame_out) { | 58 std::unique_ptr<FrameObject>* frame_out) { |
| 52 int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; | 59 int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; |
| 53 int64_t wait_ms = max_wait_time_ms; | 60 int64_t wait_ms = max_wait_time_ms; |
| 54 FrameMap::iterator next_frame_it; | 61 FrameMap::iterator next_frame_it; |
| 55 | 62 |
| 56 do { | 63 do { |
| 57 int64_t now_ms = clock_->TimeInMilliseconds(); | 64 int64_t now_ms = clock_->TimeInMilliseconds(); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 148 void FrameBuffer::Stop() { | 155 void FrameBuffer::Stop() { |
| 149 rtc::CritScope lock(&crit_); | 156 rtc::CritScope lock(&crit_); |
| 150 stopped_ = true; | 157 stopped_ = true; |
| 151 new_countinuous_frame_event_.Set(); | 158 new_countinuous_frame_event_.Set(); |
| 152 } | 159 } |
| 153 | 160 |
| 154 int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { | 161 int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { |
| 155 rtc::CritScope lock(&crit_); | 162 rtc::CritScope lock(&crit_); |
| 156 RTC_DCHECK(frame); | 163 RTC_DCHECK(frame); |
| 157 | 164 |
| 165 ++num_total_frames_; | |
| 166 if (frame->num_references == 0) | |
| 167 ++num_key_frames_; | |
| 168 | |
| 158 FrameKey key(frame->picture_id, frame->spatial_layer); | 169 FrameKey key(frame->picture_id, frame->spatial_layer); |
| 159 int last_continuous_picture_id = | 170 int last_continuous_picture_id = |
| 160 last_continuous_frame_it_ == frames_.end() | 171 last_continuous_frame_it_ == frames_.end() |
| 161 ? -1 | 172 ? -1 |
| 162 : last_continuous_frame_it_->first.picture_id; | 173 : last_continuous_frame_it_->first.picture_id; |
| 163 | 174 |
| 164 if (num_frames_buffered_ >= kMaxFramesBuffered) { | 175 if (num_frames_buffered_ >= kMaxFramesBuffered) { |
| 165 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id | 176 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
| 166 << ":" << static_cast<int>(key.spatial_layer) | 177 << ":" << static_cast<int>(key.spatial_layer) |
| 167 << ") could not be inserted due to the frame " | 178 << ") could not be inserted due to the frame " |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 346 RTC_DCHECK_LE(ref_info->second.num_missing_continuous, | 357 RTC_DCHECK_LE(ref_info->second.num_missing_continuous, |
| 347 ref_info->second.num_missing_decodable); | 358 ref_info->second.num_missing_decodable); |
| 348 } | 359 } |
| 349 | 360 |
| 350 RTC_DCHECK_LE(info->second.num_missing_continuous, | 361 RTC_DCHECK_LE(info->second.num_missing_continuous, |
| 351 info->second.num_missing_decodable); | 362 info->second.num_missing_decodable); |
| 352 | 363 |
| 353 return true; | 364 return true; |
| 354 } | 365 } |
| 355 | 366 |
| 367 void FrameBuffer::UpdateHistograms() const { | |
| 368 rtc::CritScope lock(&crit_); | |
| 369 if (num_total_frames_ > 0) { | |
| 370 int key_frames_permille = (static_cast<float>(num_key_frames_) / | |
|
brandtr
2016/11/21 16:46:45
Are you missing a factor 1000 here?
philipel
2016/11/22 14:56:23
Done.
| |
| 371 static_cast<float>(num_total_frames_) + | |
| 372 0.5f); | |
| 373 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille", | |
| 374 key_frames_permille); | |
| 375 } | |
| 376 } | |
| 377 | |
| 356 } // namespace video_coding | 378 } // namespace video_coding |
| 357 } // namespace webrtc | 379 } // namespace webrtc |
| OLD | NEW |