philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
| 11 | #include "webrtc/modules/video_coding/frame_buffer2.h" |
| 12 | |
| 13 | #include <algorithm> |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 14 | #include <cstring> |
| 15 | #include <queue> |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 16 | |
| 17 | #include "webrtc/base/checks.h" |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 18 | #include "webrtc/base/logging.h" |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 19 | #include "webrtc/modules/video_coding/jitter_estimator.h" |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 20 | #include "webrtc/modules/video_coding/timing.h" |
| 21 | #include "webrtc/system_wrappers/include/clock.h" |
philipel | 266f0a4 | 2016-11-28 08:49:07 -0800 | [diff] [blame] | 22 | #include "webrtc/system_wrappers/include/metrics.h" |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 23 | |
| 24 | namespace webrtc { |
| 25 | namespace video_coding { |
| 26 | |
| 27 | namespace { |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 28 | // Max number of frames the buffer will hold. |
| 29 | constexpr int kMaxFramesBuffered = 600; |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 30 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 31 | // Max number of decoded frame info that will be saved. |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 32 | constexpr int kMaxFramesHistory = 50; |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 33 | } // namespace |
| 34 | |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 35 | FrameBuffer::FrameBuffer(Clock* clock, |
| 36 | VCMJitterEstimator* jitter_estimator, |
philipel | 4f6cd6a | 2016-08-03 10:59:32 +0200 | [diff] [blame] | 37 | VCMTiming* timing) |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 38 | : clock_(clock), |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 39 | new_countinuous_frame_event_(false, false), |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 40 | jitter_estimator_(jitter_estimator), |
| 41 | timing_(timing), |
philipel | 4f6cd6a | 2016-08-03 10:59:32 +0200 | [diff] [blame] | 42 | inter_frame_delay_(clock_->TimeInMilliseconds()), |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 43 | last_decoded_frame_it_(frames_.end()), |
| 44 | last_continuous_frame_it_(frames_.end()), |
| 45 | num_frames_history_(0), |
| 46 | num_frames_buffered_(0), |
philipel | 4f6cd6a | 2016-08-03 10:59:32 +0200 | [diff] [blame] | 47 | stopped_(false), |
philipel | be74270 | 2016-11-30 01:31:40 -0800 | [diff] [blame] | 48 | protection_mode_(kProtectionNack) {} |
philipel | 266f0a4 | 2016-11-28 08:49:07 -0800 | [diff] [blame] | 49 | |
| 50 | FrameBuffer::~FrameBuffer() { |
| 51 | UpdateHistograms(); |
| 52 | } |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 53 | |
philipel | 7556282 | 2016-09-05 10:57:41 +0200 | [diff] [blame] | 54 | FrameBuffer::ReturnReason FrameBuffer::NextFrame( |
| 55 | int64_t max_wait_time_ms, |
| 56 | std::unique_ptr<FrameObject>* frame_out) { |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 57 | int64_t latest_return_time = clock_->TimeInMilliseconds() + max_wait_time_ms; |
philipel | 504c47d | 2016-06-30 17:33:02 +0200 | [diff] [blame] | 58 | int64_t wait_ms = max_wait_time_ms; |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 59 | FrameMap::iterator next_frame_it; |
| 60 | |
| 61 | do { |
| 62 | int64_t now_ms = clock_->TimeInMilliseconds(); |
philipel | 504c47d | 2016-06-30 17:33:02 +0200 | [diff] [blame] | 63 | { |
| 64 | rtc::CritScope lock(&crit_); |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 65 | new_countinuous_frame_event_.Reset(); |
philipel | 504c47d | 2016-06-30 17:33:02 +0200 | [diff] [blame] | 66 | if (stopped_) |
philipel | 7556282 | 2016-09-05 10:57:41 +0200 | [diff] [blame] | 67 | return kStopped; |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 68 | |
philipel | 504c47d | 2016-06-30 17:33:02 +0200 | [diff] [blame] | 69 | wait_ms = max_wait_time_ms; |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 70 | |
| 71 | // Need to hold |crit_| in order to use |frames_|, therefore we |
| 72 | // set it here in the loop instead of outside the loop in order to not |
| 73 | // acquire the lock unnecesserily. |
philipel | 4f6cd6a | 2016-08-03 10:59:32 +0200 | [diff] [blame] | 74 | next_frame_it = frames_.end(); |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 75 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 76 | // |frame_it| points to the first frame after the |
| 77 | // |last_decoded_frame_it_|. |
| 78 | auto frame_it = frames_.end(); |
| 79 | if (last_decoded_frame_it_ == frames_.end()) { |
| 80 | frame_it = frames_.begin(); |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 81 | } else { |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 82 | frame_it = last_decoded_frame_it_; |
| 83 | ++frame_it; |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 84 | } |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 85 | |
| 86 | // |continuous_end_it| points to the first frame after the |
| 87 | // |last_continuous_frame_it_|. |
| 88 | auto continuous_end_it = last_continuous_frame_it_; |
| 89 | if (continuous_end_it != frames_.end()) |
| 90 | ++continuous_end_it; |
| 91 | |
| 92 | for (; frame_it != continuous_end_it; ++frame_it) { |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 93 | if (!frame_it->second.continuous || |
| 94 | frame_it->second.num_missing_decodable > 0) { |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 95 | continue; |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 96 | } |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 97 | |
| 98 | FrameObject* frame = frame_it->second.frame.get(); |
| 99 | next_frame_it = frame_it; |
| 100 | if (frame->RenderTime() == -1) |
| 101 | frame->SetRenderTime(timing_->RenderTimeMs(frame->timestamp, now_ms)); |
| 102 | wait_ms = timing_->MaxWaitingTime(frame->RenderTime(), now_ms); |
| 103 | |
| 104 | // This will cause the frame buffer to prefer high framerate rather |
| 105 | // than high resolution in the case of the decoder not decoding fast |
| 106 | // enough and the stream has multiple spatial and temporal layers. |
| 107 | if (wait_ms == 0) |
| 108 | continue; |
| 109 | |
| 110 | break; |
| 111 | } |
| 112 | } // rtc::Critscope lock(&crit_); |
| 113 | |
| 114 | wait_ms = std::min<int64_t>(wait_ms, latest_return_time - now_ms); |
| 115 | wait_ms = std::max<int64_t>(wait_ms, 0); |
| 116 | } while (new_countinuous_frame_event_.Wait(wait_ms)); |
| 117 | |
| 118 | rtc::CritScope lock(&crit_); |
| 119 | if (next_frame_it != frames_.end()) { |
| 120 | std::unique_ptr<FrameObject> frame = std::move(next_frame_it->second.frame); |
| 121 | int64_t received_time = frame->ReceivedTime(); |
philipel | fd5a20f | 2016-11-15 00:57:57 -0800 | [diff] [blame] | 122 | uint32_t timestamp = frame->timestamp; |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 123 | |
| 124 | int64_t frame_delay; |
| 125 | if (inter_frame_delay_.CalculateDelay(timestamp, &frame_delay, |
| 126 | received_time)) { |
nisse | 37abf53 | 2016-10-28 00:37:29 -0700 | [diff] [blame] | 127 | jitter_estimator_->UpdateEstimate(frame_delay, frame->size()); |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 128 | } |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 129 | float rtt_mult = protection_mode_ == kProtectionNackFEC ? 0.0 : 1.0; |
| 130 | timing_->SetJitterDelay(jitter_estimator_->GetJitterEstimate(rtt_mult)); |
| 131 | timing_->UpdateCurrentDelay(frame->RenderTime(), |
| 132 | clock_->TimeInMilliseconds()); |
| 133 | |
philipel | be74270 | 2016-11-30 01:31:40 -0800 | [diff] [blame] | 134 | UpdateJitterDelay(); |
| 135 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 136 | PropagateDecodability(next_frame_it->second); |
| 137 | AdvanceLastDecodedFrame(next_frame_it); |
| 138 | *frame_out = std::move(frame); |
| 139 | return kFrameFound; |
| 140 | } else { |
| 141 | return kTimeout; |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |
philipel | 4f6cd6a | 2016-08-03 10:59:32 +0200 | [diff] [blame] | 145 | void FrameBuffer::SetProtectionMode(VCMVideoProtection mode) { |
| 146 | rtc::CritScope lock(&crit_); |
| 147 | protection_mode_ = mode; |
| 148 | } |
| 149 | |
philipel | 504c47d | 2016-06-30 17:33:02 +0200 | [diff] [blame] | 150 | void FrameBuffer::Start() { |
| 151 | rtc::CritScope lock(&crit_); |
| 152 | stopped_ = false; |
| 153 | } |
| 154 | |
| 155 | void FrameBuffer::Stop() { |
| 156 | rtc::CritScope lock(&crit_); |
| 157 | stopped_ = true; |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 158 | new_countinuous_frame_event_.Set(); |
philipel | 504c47d | 2016-06-30 17:33:02 +0200 | [diff] [blame] | 159 | } |
| 160 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 161 | int FrameBuffer::InsertFrame(std::unique_ptr<FrameObject> frame) { |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 162 | rtc::CritScope lock(&crit_); |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 163 | RTC_DCHECK(frame); |
| 164 | |
philipel | 266f0a4 | 2016-11-28 08:49:07 -0800 | [diff] [blame] | 165 | ++num_total_frames_; |
| 166 | if (frame->num_references == 0) |
| 167 | ++num_key_frames_; |
| 168 | |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 169 | FrameKey key(frame->picture_id, frame->spatial_layer); |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 170 | int last_continuous_picture_id = |
| 171 | last_continuous_frame_it_ == frames_.end() |
| 172 | ? -1 |
| 173 | : last_continuous_frame_it_->first.picture_id; |
| 174 | |
| 175 | if (num_frames_buffered_ >= kMaxFramesBuffered) { |
| 176 | LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
| 177 | << ":" << static_cast<int>(key.spatial_layer) |
| 178 | << ") could not be inserted due to the frame " |
| 179 | << "buffer being full, dropping frame."; |
| 180 | return last_continuous_picture_id; |
| 181 | } |
| 182 | |
| 183 | if (frame->inter_layer_predicted && frame->spatial_layer == 0) { |
| 184 | LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
| 185 | << ":" << static_cast<int>(key.spatial_layer) |
| 186 | << ") is marked as inter layer predicted, dropping frame."; |
| 187 | return last_continuous_picture_id; |
| 188 | } |
| 189 | |
| 190 | if (last_decoded_frame_it_ != frames_.end() && |
| 191 | key < last_decoded_frame_it_->first) { |
| 192 | LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
| 193 | << ":" << static_cast<int>(key.spatial_layer) |
| 194 | << ") inserted after frame (" |
| 195 | << last_decoded_frame_it_->first.picture_id << ":" |
| 196 | << static_cast<int>( |
| 197 | last_decoded_frame_it_->first.spatial_layer) |
| 198 | << ") was handed off for decoding, dropping frame."; |
| 199 | return last_continuous_picture_id; |
| 200 | } |
| 201 | |
| 202 | auto info = frames_.insert(std::make_pair(key, FrameInfo())).first; |
| 203 | |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 204 | if (info->second.frame) { |
| 205 | LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
| 206 | << ":" << static_cast<int>(key.spatial_layer) |
| 207 | << ") already inserted, dropping frame."; |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 208 | return last_continuous_picture_id; |
| 209 | } |
| 210 | |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 211 | if (!UpdateFrameInfoWithIncomingFrame(*frame, info)) |
| 212 | return last_continuous_picture_id; |
| 213 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 214 | info->second.frame = std::move(frame); |
| 215 | ++num_frames_buffered_; |
| 216 | |
| 217 | if (info->second.num_missing_continuous == 0) { |
| 218 | info->second.continuous = true; |
| 219 | PropagateContinuity(info); |
| 220 | last_continuous_picture_id = last_continuous_frame_it_->first.picture_id; |
| 221 | |
| 222 | // Since we now have new continuous frames there might be a better frame |
| 223 | // to return from NextFrame. Signal that thread so that it again can choose |
| 224 | // which frame to return. |
| 225 | new_countinuous_frame_event_.Set(); |
| 226 | } |
| 227 | |
| 228 | return last_continuous_picture_id; |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 229 | } |
| 230 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 231 | void FrameBuffer::PropagateContinuity(FrameMap::iterator start) { |
| 232 | RTC_DCHECK(start->second.continuous); |
| 233 | if (last_continuous_frame_it_ == frames_.end()) |
| 234 | last_continuous_frame_it_ = start; |
| 235 | |
| 236 | std::queue<FrameMap::iterator> continuous_frames; |
| 237 | continuous_frames.push(start); |
| 238 | |
| 239 | // A simple BFS to traverse continuous frames. |
| 240 | while (!continuous_frames.empty()) { |
| 241 | auto frame = continuous_frames.front(); |
| 242 | continuous_frames.pop(); |
| 243 | |
| 244 | if (last_continuous_frame_it_->first < frame->first) |
| 245 | last_continuous_frame_it_ = frame; |
| 246 | |
| 247 | // Loop through all dependent frames, and if that frame no longer has |
| 248 | // any unfulfilled dependencies then that frame is continuous as well. |
| 249 | for (size_t d = 0; d < frame->second.num_dependent_frames; ++d) { |
| 250 | auto frame_ref = frames_.find(frame->second.dependent_frames[d]); |
| 251 | --frame_ref->second.num_missing_continuous; |
| 252 | |
| 253 | if (frame_ref->second.num_missing_continuous == 0) { |
| 254 | frame_ref->second.continuous = true; |
| 255 | continuous_frames.push(frame_ref); |
| 256 | } |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | void FrameBuffer::PropagateDecodability(const FrameInfo& info) { |
| 262 | for (size_t d = 0; d < info.num_dependent_frames; ++d) { |
| 263 | auto ref_info = frames_.find(info.dependent_frames[d]); |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 264 | RTC_DCHECK(ref_info != frames_.end()); |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 265 | RTC_DCHECK_GT(ref_info->second.num_missing_decodable, 0U); |
| 266 | --ref_info->second.num_missing_decodable; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | void FrameBuffer::AdvanceLastDecodedFrame(FrameMap::iterator decoded) { |
| 271 | if (last_decoded_frame_it_ == frames_.end()) { |
| 272 | last_decoded_frame_it_ = frames_.begin(); |
| 273 | } else { |
| 274 | RTC_DCHECK(last_decoded_frame_it_->first < decoded->first); |
| 275 | ++last_decoded_frame_it_; |
| 276 | } |
| 277 | --num_frames_buffered_; |
| 278 | ++num_frames_history_; |
| 279 | |
| 280 | // First, delete non-decoded frames from the history. |
| 281 | while (last_decoded_frame_it_ != decoded) { |
| 282 | if (last_decoded_frame_it_->second.frame) |
| 283 | --num_frames_buffered_; |
| 284 | last_decoded_frame_it_ = frames_.erase(last_decoded_frame_it_); |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 285 | } |
| 286 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 287 | // Then remove old history if we have too much history saved. |
| 288 | if (num_frames_history_ > kMaxFramesHistory) { |
| 289 | frames_.erase(frames_.begin()); |
| 290 | --num_frames_history_; |
| 291 | } |
| 292 | } |
| 293 | |
| 294 | bool FrameBuffer::UpdateFrameInfoWithIncomingFrame(const FrameObject& frame, |
| 295 | FrameMap::iterator info) { |
| 296 | FrameKey key(frame.picture_id, frame.spatial_layer); |
| 297 | info->second.num_missing_continuous = frame.num_references; |
| 298 | info->second.num_missing_decodable = frame.num_references; |
| 299 | |
| 300 | RTC_DCHECK(last_decoded_frame_it_ == frames_.end() || |
| 301 | last_decoded_frame_it_->first < info->first); |
| 302 | |
| 303 | // Check how many dependencies that have already been fulfilled. |
| 304 | for (size_t i = 0; i < frame.num_references; ++i) { |
| 305 | FrameKey ref_key(frame.references[i], frame.spatial_layer); |
| 306 | auto ref_info = frames_.find(ref_key); |
| 307 | |
| 308 | // Does |frame| depend on a frame earlier than the last decoded frame? |
| 309 | if (last_decoded_frame_it_ != frames_.end() && |
| 310 | ref_key <= last_decoded_frame_it_->first) { |
| 311 | if (ref_info == frames_.end()) { |
| 312 | LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" |
| 313 | << key.picture_id << ":" |
| 314 | << static_cast<int>(key.spatial_layer) |
| 315 | << " depends on a non-decoded frame more previous than " |
| 316 | << "the last decoded frame, dropping frame."; |
| 317 | return false; |
| 318 | } |
| 319 | |
| 320 | --info->second.num_missing_continuous; |
| 321 | --info->second.num_missing_decodable; |
| 322 | } else { |
| 323 | if (ref_info == frames_.end()) |
| 324 | ref_info = frames_.insert(std::make_pair(ref_key, FrameInfo())).first; |
| 325 | |
| 326 | if (ref_info->second.continuous) |
| 327 | --info->second.num_missing_continuous; |
| 328 | |
| 329 | // Add backwards reference so |frame| can be updated when new |
| 330 | // frames are inserted or decoded. |
| 331 | ref_info->second.dependent_frames[ref_info->second.num_dependent_frames] = |
| 332 | key; |
| 333 | ++ref_info->second.num_dependent_frames; |
| 334 | } |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 335 | RTC_DCHECK_LE(ref_info->second.num_missing_continuous, |
| 336 | ref_info->second.num_missing_decodable); |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 337 | } |
| 338 | |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 339 | // Check if we have the lower spatial layer frame. |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 340 | if (frame.inter_layer_predicted) { |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 341 | ++info->second.num_missing_continuous; |
| 342 | ++info->second.num_missing_decodable; |
| 343 | |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 344 | FrameKey ref_key(frame.picture_id, frame.spatial_layer - 1); |
philipel | e0b2f15 | 2016-09-28 10:23:49 +0200 | [diff] [blame] | 345 | // Gets or create the FrameInfo for the referenced frame. |
| 346 | auto ref_info = frames_.insert(std::make_pair(ref_key, FrameInfo())).first; |
| 347 | if (ref_info->second.continuous) |
| 348 | --info->second.num_missing_continuous; |
| 349 | |
| 350 | if (ref_info == last_decoded_frame_it_) { |
| 351 | --info->second.num_missing_decodable; |
| 352 | } else { |
| 353 | ref_info->second.dependent_frames[ref_info->second.num_dependent_frames] = |
| 354 | key; |
| 355 | ++ref_info->second.num_dependent_frames; |
| 356 | } |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 357 | RTC_DCHECK_LE(ref_info->second.num_missing_continuous, |
| 358 | ref_info->second.num_missing_decodable); |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 359 | } |
| 360 | |
philipel | 93e451b | 2016-10-06 12:25:13 +0200 | [diff] [blame] | 361 | RTC_DCHECK_LE(info->second.num_missing_continuous, |
| 362 | info->second.num_missing_decodable); |
| 363 | |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 364 | return true; |
| 365 | } |
| 366 | |
philipel | be74270 | 2016-11-30 01:31:40 -0800 | [diff] [blame] | 367 | void FrameBuffer::UpdateJitterDelay() { |
| 368 | int unused; |
| 369 | int delay; |
| 370 | timing_->GetTimings(&unused, &unused, &unused, &unused, &delay, &unused, |
| 371 | &unused); |
| 372 | |
| 373 | accumulated_delay_ += delay; |
| 374 | ++accumulated_delay_samples_; |
| 375 | } |
| 376 | |
philipel | 266f0a4 | 2016-11-28 08:49:07 -0800 | [diff] [blame] | 377 | void FrameBuffer::UpdateHistograms() const { |
| 378 | rtc::CritScope lock(&crit_); |
| 379 | if (num_total_frames_ > 0) { |
| 380 | int key_frames_permille = (static_cast<float>(num_key_frames_) * 1000.0f / |
| 381 | static_cast<float>(num_total_frames_) + |
| 382 | 0.5f); |
| 383 | RTC_HISTOGRAM_COUNTS_1000("WebRTC.Video.KeyFramesReceivedInPermille", |
| 384 | key_frames_permille); |
| 385 | } |
philipel | be74270 | 2016-11-30 01:31:40 -0800 | [diff] [blame] | 386 | |
| 387 | if (accumulated_delay_samples_ > 0) { |
| 388 | RTC_HISTOGRAM_COUNTS_10000("WebRTC.Video.JitterBufferDelayInMs", |
| 389 | accumulated_delay_ / accumulated_delay_samples_); |
| 390 | } |
philipel | 266f0a4 | 2016-11-28 08:49:07 -0800 | [diff] [blame] | 391 | } |
| 392 | |
philipel | be7a9e5 | 2016-05-19 12:19:35 +0200 | [diff] [blame] | 393 | } // namespace video_coding |
| 394 | } // namespace webrtc |