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/include/video_coding_defines.h" |
19 #include "webrtc/modules/video_coding/jitter_estimator.h" | 20 #include "webrtc/modules/video_coding/jitter_estimator.h" |
20 #include "webrtc/modules/video_coding/timing.h" | 21 #include "webrtc/modules/video_coding/timing.h" |
21 #include "webrtc/system_wrappers/include/clock.h" | 22 #include "webrtc/system_wrappers/include/clock.h" |
22 #include "webrtc/system_wrappers/include/metrics.h" | 23 #include "webrtc/system_wrappers/include/metrics.h" |
23 | 24 |
24 namespace webrtc { | 25 namespace webrtc { |
25 namespace video_coding { | 26 namespace video_coding { |
26 | 27 |
27 namespace { | 28 namespace { |
28 // Max number of frames the buffer will hold. | 29 // Max number of frames the buffer will hold. |
29 constexpr int kMaxFramesBuffered = 600; | 30 constexpr int kMaxFramesBuffered = 600; |
30 | 31 |
31 // Max number of decoded frame info that will be saved. | 32 // Max number of decoded frame info that will be saved. |
32 constexpr int kMaxFramesHistory = 50; | 33 constexpr int kMaxFramesHistory = 50; |
33 } // namespace | 34 } // namespace |
34 | 35 |
35 FrameBuffer::FrameBuffer(Clock* clock, | 36 FrameBuffer::FrameBuffer(Clock* clock, |
36 VCMJitterEstimator* jitter_estimator, | 37 VCMJitterEstimator* jitter_estimator, |
37 VCMTiming* timing) | 38 VCMTiming* timing, |
| 39 VCMReceiveStatisticsCallback* stats_callback) |
38 : clock_(clock), | 40 : clock_(clock), |
39 new_countinuous_frame_event_(false, false), | 41 new_countinuous_frame_event_(false, false), |
40 jitter_estimator_(jitter_estimator), | 42 jitter_estimator_(jitter_estimator), |
41 timing_(timing), | 43 timing_(timing), |
42 inter_frame_delay_(clock_->TimeInMilliseconds()), | 44 inter_frame_delay_(clock_->TimeInMilliseconds()), |
43 last_decoded_frame_it_(frames_.end()), | 45 last_decoded_frame_it_(frames_.end()), |
44 last_continuous_frame_it_(frames_.end()), | 46 last_continuous_frame_it_(frames_.end()), |
45 num_frames_history_(0), | 47 num_frames_history_(0), |
46 num_frames_buffered_(0), | 48 num_frames_buffered_(0), |
47 stopped_(false), | 49 stopped_(false), |
48 protection_mode_(kProtectionNack) {} | 50 protection_mode_(kProtectionNack), |
| 51 stats_callback_(stats_callback) {} |
49 | 52 |
50 FrameBuffer::~FrameBuffer() { | 53 FrameBuffer::~FrameBuffer() {} |
51 UpdateHistograms(); | |
52 } | |
53 | 54 |
54 FrameBuffer::ReturnReason FrameBuffer::NextFrame( | 55 FrameBuffer::ReturnReason FrameBuffer::NextFrame( |
55 int64_t max_wait_time_ms, | 56 int64_t max_wait_time_ms, |
56 std::unique_ptr<FrameObject>* frame_out) { | 57 std::unique_ptr<FrameObject>* frame_out) { |
57 int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; | 58 int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; |
58 int64_t wait_ms = max_wait_time_ms; | 59 int64_t wait_ms = max_wait_time_ms; |
59 FrameMap::iterator next_frame_it; | 60 FrameMap::iterator next_frame_it; |
60 | 61 |
61 do { | 62 do { |
62 int64_t now_ms = clock_->TimeInMilliseconds(); | 63 int64_t now_ms = clock_->TimeInMilliseconds(); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 void FrameBuffer::Stop() { | 157 void FrameBuffer::Stop() { |
157 rtc::CritScope lock(&crit_); | 158 rtc::CritScope lock(&crit_); |
158 stopped_ = true; | 159 stopped_ = true; |
159 new_countinuous_frame_event_.Set(); | 160 new_countinuous_frame_event_.Set(); |
160 } | 161 } |
161 | 162 |
162 int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { | 163 int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { |
163 rtc::CritScope lock(&crit_); | 164 rtc::CritScope lock(&crit_); |
164 RTC_DCHECK(frame); | 165 RTC_DCHECK(frame); |
165 | 166 |
166 ++num_total_frames_; | 167 if (stats_callback_) |
167 if (frame->num_references == 0) | 168 stats_callback_->OnCompleteFrame(frame->num_references == 0, frame->size()); |
168 ++num_key_frames_; | |
169 | 169 |
170 FrameKey key(frame->picture_id, frame->spatial_layer); | 170 FrameKey key(frame->picture_id, frame->spatial_layer); |
171 int last_continuous_picture_id = | 171 int last_continuous_picture_id = |
172 last_continuous_frame_it_ == frames_.end() | 172 last_continuous_frame_it_ == frames_.end() |
173 ? -1 | 173 ? -1 |
174 : last_continuous_frame_it_->first.picture_id; | 174 : last_continuous_frame_it_->first.picture_id; |
175 | 175 |
176 if (num_frames_buffered_ >= kMaxFramesBuffered) { | 176 if (num_frames_buffered_ >= kMaxFramesBuffered) { |
177 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id | 177 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
178 << ":" << static_cast<int>(key.spatial_layer) | 178 << ":" << static_cast<int>(key.spatial_layer) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 ref_info->second.num_missing_decodable); | 372 ref_info->second.num_missing_decodable); |
373 } | 373 } |
374 | 374 |
375 RTC_DCHECK_LE(info->second.num_missing_continuous, | 375 RTC_DCHECK_LE(info->second.num_missing_continuous, |
376 info->second.num_missing_decodable); | 376 info->second.num_missing_decodable); |
377 | 377 |
378 return true; | 378 return true; |
379 } | 379 } |
380 | 380 |
381 void FrameBuffer::UpdateJitterDelay() { | 381 void FrameBuffer::UpdateJitterDelay() { |
382 int unused; | 382 if (!stats_callback_) |
383 int delay; | 383 return; |
384 timing_->GetTimings(&unused, &unused, &unused, &unused, &delay, &unused, | |
385 &unused); | |
386 | 384 |
387 accumulated_delay_ += delay; | 385 int decode_ms; |
388 ++accumulated_delay_samples_; | 386 int max_decode_ms; |
389 } | 387 int current_delay_ms; |
390 | 388 int target_delay_ms; |
391 void FrameBuffer::UpdateHistograms() const { | 389 int jitter_buffer_ms; |
392 rtc::CritScope lock(&crit_); | 390 int min_playout_delay_ms; |
393 if (num_total_frames_ > 0) { | 391 int render_delay_ms; |
394 int key_frames_permille = (static_cast<float>(num_key_frames_) * 1000.0f / | 392 if (timing_->GetTimings(&decode_ms, &max_decode_ms, ¤t_delay_ms, |
395 static_cast<float>(num_total_frames_) + | 393 &target_delay_ms, &jitter_buffer_ms, |
396 0.5f); | 394 &min_playout_delay_ms, &render_delay_ms)) { |
397 RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille", | 395 stats_callback_->OnFrameBufferTimingsUpdated( |
398 key_frames_permille); | 396 decode_ms, max_decode_ms, current_delay_ms, target_delay_ms, |
399 } | 397 jitter_buffer_ms, min_playout_delay_ms, render_delay_ms); |
400 | |
401 if (accumulated_delay_samples_ > 0) { | |
402 RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", | |
403 accumulated_delay_ / accumulated_delay_samples_); | |
404 } | 398 } |
405 } | 399 } |
406 | 400 |
407 void FrameBuffer::ClearFramesAndHistory() { | 401 void FrameBuffer::ClearFramesAndHistory() { |
408 frames_.clear(); | 402 frames_.clear(); |
409 last_decoded_frame_it_ = frames_.end(); | 403 last_decoded_frame_it_ = frames_.end(); |
410 last_continuous_frame_it_ = frames_.end(); | 404 last_continuous_frame_it_ = frames_.end(); |
411 num_frames_history_ = 0; | 405 num_frames_history_ = 0; |
412 num_frames_buffered_ = 0; | 406 num_frames_buffered_ = 0; |
413 } | 407 } |
414 | 408 |
415 } // namespace video_coding | 409 } // namespace video_coding |
416 } // namespace webrtc | 410 } // namespace webrtc |
OLD | NEW |