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 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 | 59 |
60 FrameBuffer::ReturnReason FrameBuffer::NextFrame( | 60 FrameBuffer::ReturnReason FrameBuffer::NextFrame( |
61 int64_t max_wait_time_ms, | 61 int64_t max_wait_time_ms, |
62 std::unique_ptr<FrameObject>* frame_out, | 62 std::unique_ptr<FrameObject>* frame_out, |
63 bool keyframe_required) { | 63 bool keyframe_required) { |
64 TRACE_EVENT0("webrtc", "FrameBuffer::NextFrame"); | 64 TRACE_EVENT0("webrtc", "FrameBuffer::NextFrame"); |
65 int64_t latest_return_time_ms = | 65 int64_t latest_return_time_ms = |
66 clock_->TimeInMilliseconds() + max_wait_time_ms; | 66 clock_->TimeInMilliseconds() + max_wait_time_ms; |
67 int64_t wait_ms = max_wait_time_ms; | 67 int64_t wait_ms = max_wait_time_ms; |
68 int64_t now_ms = 0; | 68 int64_t now_ms = 0; |
69 | |
70 do { | 69 do { |
71 now_ms = clock_->TimeInMilliseconds(); | 70 now_ms = clock_->TimeInMilliseconds(); |
72 { | 71 { |
73 rtc::CritScope lock(&crit_); | 72 rtc::CritScope lock(&crit_); |
74 new_continuous_frame_event_.Reset(); | 73 new_continuous_frame_event_.Reset(); |
75 if (stopped_) | 74 if (stopped_) { |
76 return kStopped; | 75 return kStopped; |
| 76 } |
77 | 77 |
78 wait_ms = max_wait_time_ms; | 78 wait_ms = max_wait_time_ms; |
79 | 79 |
80 // Need to hold |crit_| in order to use |frames_|, therefore we | 80 // Need to hold |crit_| in order to use |frames_|, therefore we |
81 // set it here in the loop instead of outside the loop in order to not | 81 // set it here in the loop instead of outside the loop in order to not |
82 // acquire the lock unnecesserily. | 82 // acquire the lock unnecesserily. |
83 next_frame_it_ = frames_.end(); | 83 next_frame_it_ = frames_.end(); |
84 | 84 |
85 // |frame_it| points to the first frame after the | 85 // |frame_it| points to the first frame after the |
86 // |last_decoded_frame_it_|. | 86 // |last_decoded_frame_it_|. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // Sanity check for RTP timestamp monotonicity. | 163 // Sanity check for RTP timestamp monotonicity. |
164 if (last_decoded_frame_it_ != frames_.end()) { | 164 if (last_decoded_frame_it_ != frames_.end()) { |
165 const FrameKey& last_decoded_frame_key = last_decoded_frame_it_->first; | 165 const FrameKey& last_decoded_frame_key = last_decoded_frame_it_->first; |
166 const FrameKey& frame_key = next_frame_it_->first; | 166 const FrameKey& frame_key = next_frame_it_->first; |
167 | 167 |
168 const bool frame_is_higher_spatial_layer_of_last_decoded_frame = | 168 const bool frame_is_higher_spatial_layer_of_last_decoded_frame = |
169 last_decoded_frame_timestamp_ == frame->timestamp && | 169 last_decoded_frame_timestamp_ == frame->timestamp && |
170 last_decoded_frame_key.picture_id == frame_key.picture_id && | 170 last_decoded_frame_key.picture_id == frame_key.picture_id && |
171 last_decoded_frame_key.spatial_layer < frame_key.spatial_layer; | 171 last_decoded_frame_key.spatial_layer < frame_key.spatial_layer; |
172 | 172 |
173 if (AheadOrAt(last_decoded_frame_timestamp_, frame->timestamp) && | 173 if (AheadOf(last_decoded_frame_timestamp_, frame->timestamp) && |
174 !frame_is_higher_spatial_layer_of_last_decoded_frame) { | 174 !frame_is_higher_spatial_layer_of_last_decoded_frame) { |
175 // TODO(brandtr): Consider clearing the entire buffer when we hit | 175 // TODO(brandtr): Consider clearing the entire buffer when we hit |
176 // these conditions. | 176 // these conditions. |
177 LOG(LS_WARNING) << "Frame with (timestamp:picture_id:spatial_id) (" | 177 LOG(LS_WARNING) << "Frame with (timestamp:picture_id:spatial_id) (" |
178 << frame->timestamp << ":" << frame->picture_id << ":" | 178 << frame->timestamp << ":" << frame->picture_id << ":" |
179 << static_cast<int>(frame->spatial_layer) << ")" | 179 << static_cast<int>(frame->spatial_layer) << ")" |
180 << " sent to decoder after frame with" | 180 << " sent to decoder after frame with" |
181 << " (timestamp:picture_id:spatial_id) (" | 181 << " (timestamp:picture_id:spatial_id) (" |
182 << last_decoded_frame_timestamp_ << ":" | 182 << last_decoded_frame_timestamp_ << ":" |
183 << last_decoded_frame_key.picture_id << ":" | 183 << last_decoded_frame_key.picture_id << ":" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // Test if inserting this frame would cause the order of the frames to become | 335 // Test if inserting this frame would cause the order of the frames to become |
336 // ambiguous (covering more than half the interval of 2^16). This can happen | 336 // ambiguous (covering more than half the interval of 2^16). This can happen |
337 // when the picture id make large jumps mid stream. | 337 // when the picture id make large jumps mid stream. |
338 if (!frames_.empty() && | 338 if (!frames_.empty() && |
339 key < frames_.begin()->first && | 339 key < frames_.begin()->first && |
340 frames_.rbegin()->first < key) { | 340 frames_.rbegin()->first < key) { |
341 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer."; | 341 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer."; |
342 ClearFramesAndHistory(); | 342 ClearFramesAndHistory(); |
343 last_continuous_picture_id = -1; | 343 last_continuous_picture_id = -1; |
344 } | 344 } |
345 | |
346 auto info = frames_.insert(std::make_pair(key, FrameInfo())).first; | 345 auto info = frames_.insert(std::make_pair(key, FrameInfo())).first; |
347 | 346 |
348 if (info->second.frame) { | 347 if (info->second.frame) { |
349 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id | 348 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
350 << ":" << static_cast<int>(key.spatial_layer) | 349 << ":" << static_cast<int>(key.spatial_layer) |
351 << ") already inserted, dropping frame."; | 350 << ") already inserted, dropping frame."; |
352 return last_continuous_picture_id; | 351 return last_continuous_picture_id; |
353 } | 352 } |
354 | 353 |
355 if (!UpdateFrameInfoWithIncomingFrame(*frame, info)) | 354 if (!UpdateFrameInfoWithIncomingFrame(*frame, info)) |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
408 } | 407 } |
409 | 408 |
410 void FrameBuffer::PropagateDecodability(const FrameInfo& info) { | 409 void FrameBuffer::PropagateDecodability(const FrameInfo& info) { |
411 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability"); | 410 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability"); |
412 RTC_CHECK(info.num_dependent_frames < FrameInfo::kMaxNumDependentFrames); | 411 RTC_CHECK(info.num_dependent_frames < FrameInfo::kMaxNumDependentFrames); |
413 for (size_t d = 0; d < info.num_dependent_frames; ++d) { | 412 for (size_t d = 0; d < info.num_dependent_frames; ++d) { |
414 auto ref_info = frames_.find(info.dependent_frames[d]); | 413 auto ref_info = frames_.find(info.dependent_frames[d]); |
415 RTC_DCHECK(ref_info != frames_.end()); | 414 RTC_DCHECK(ref_info != frames_.end()); |
416 // TODO(philipel): Look into why we've seen this happen. | 415 // TODO(philipel): Look into why we've seen this happen. |
417 if (ref_info != frames_.end()) { | 416 if (ref_info != frames_.end()) { |
418 RTC_DCHECK_GT(ref_info->second.num_missing_decodable, 0U); | 417 // RTC_DCHECK_GT(ref_info->second.num_missing_decodable, 0U); |
419 --ref_info->second.num_missing_decodable; | 418 --ref_info->second.num_missing_decodable; |
420 } | 419 } |
421 } | 420 } |
422 } | 421 } |
423 | 422 |
424 void FrameBuffer::AdvanceLastDecodedFrame(FrameMap::iterator decoded) { | 423 void FrameBuffer::AdvanceLastDecodedFrame(FrameMap::iterator decoded) { |
425 TRACE_EVENT0("webrtc", "FrameBuffer::AdvanceLastDecodedFrame"); | 424 TRACE_EVENT0("webrtc", "FrameBuffer::AdvanceLastDecodedFrame"); |
426 if (last_decoded_frame_it_ == frames_.end()) { | 425 if (last_decoded_frame_it_ == frames_.end()) { |
427 last_decoded_frame_it_ = frames_.begin(); | 426 last_decoded_frame_it_ = frames_.begin(); |
428 } else { | 427 } else { |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
564 frames_.clear(); | 563 frames_.clear(); |
565 last_decoded_frame_it_ = frames_.end(); | 564 last_decoded_frame_it_ = frames_.end(); |
566 last_continuous_frame_it_ = frames_.end(); | 565 last_continuous_frame_it_ = frames_.end(); |
567 next_frame_it_ = frames_.end(); | 566 next_frame_it_ = frames_.end(); |
568 num_frames_history_ = 0; | 567 num_frames_history_ = 0; |
569 num_frames_buffered_ = 0; | 568 num_frames_buffered_ = 0; |
570 } | 569 } |
571 | 570 |
572 } // namespace video_coding | 571 } // namespace video_coding |
573 } // namespace webrtc | 572 } // namespace webrtc |
OLD | NEW |