| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 FrameBuffer::~FrameBuffer() {} | 55 FrameBuffer::~FrameBuffer() {} |
| 56 | 56 |
| 57 FrameBuffer::ReturnReason FrameBuffer::NextFrame( | 57 FrameBuffer::ReturnReason FrameBuffer::NextFrame( |
| 58 int64_t max_wait_time_ms, | 58 int64_t max_wait_time_ms, |
| 59 std::unique_ptr<FrameObject>* frame_out) { | 59 std::unique_ptr<FrameObject>* frame_out) { |
| 60 TRACE_EVENT0("webrtc", "FrameBuffer::NextFrame"); | 60 TRACE_EVENT0("webrtc", "FrameBuffer::NextFrame"); |
| 61 int64_t latest_return_time_ms = | 61 int64_t latest_return_time_ms = |
| 62 clock_->TimeInMilliseconds() + max_wait_time_ms; | 62 clock_->TimeInMilliseconds() + max_wait_time_ms; |
| 63 int64_t wait_ms = max_wait_time_ms; | 63 int64_t wait_ms = max_wait_time_ms; |
| 64 int64_t now_ms = 0; | 64 int64_t now_ms = 0; |
| 65 | |
| 66 do { | 65 do { |
| 67 now_ms = clock_->TimeInMilliseconds(); | 66 now_ms = clock_->TimeInMilliseconds(); |
| 68 { | 67 { |
| 69 rtc::CritScope lock(&crit_); | 68 rtc::CritScope lock(&crit_); |
| 70 new_continuous_frame_event_.Reset(); | 69 new_continuous_frame_event_.Reset(); |
| 71 if (stopped_) | 70 if (stopped_) { |
| 72 return kStopped; | 71 return kStopped; |
| 72 } |
| 73 | 73 |
| 74 wait_ms = max_wait_time_ms; | 74 wait_ms = max_wait_time_ms; |
| 75 | 75 |
| 76 // Need to hold |crit_| in order to use |frames_|, therefore we | 76 // Need to hold |crit_| in order to use |frames_|, therefore we |
| 77 // set it here in the loop instead of outside the loop in order to not | 77 // set it here in the loop instead of outside the loop in order to not |
| 78 // acquire the lock unnecesserily. | 78 // acquire the lock unnecesserily. |
| 79 next_frame_it_ = frames_.end(); | 79 next_frame_it_ = frames_.end(); |
| 80 | 80 |
| 81 // |frame_it| points to the first frame after the | 81 // |frame_it| points to the first frame after the |
| 82 // |last_decoded_frame_it_|. | 82 // |last_decoded_frame_it_|. |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 // Sanity check for RTP timestamp monotonicity. | 155 // Sanity check for RTP timestamp monotonicity. |
| 156 if (last_decoded_frame_it_ != frames_.end()) { | 156 if (last_decoded_frame_it_ != frames_.end()) { |
| 157 const FrameKey& last_decoded_frame_key = last_decoded_frame_it_->first; | 157 const FrameKey& last_decoded_frame_key = last_decoded_frame_it_->first; |
| 158 const FrameKey& frame_key = next_frame_it_->first; | 158 const FrameKey& frame_key = next_frame_it_->first; |
| 159 | 159 |
| 160 const bool frame_is_higher_spatial_layer_of_last_decoded_frame = | 160 const bool frame_is_higher_spatial_layer_of_last_decoded_frame = |
| 161 last_decoded_frame_timestamp_ == frame->timestamp && | 161 last_decoded_frame_timestamp_ == frame->timestamp && |
| 162 last_decoded_frame_key.picture_id == frame_key.picture_id && | 162 last_decoded_frame_key.picture_id == frame_key.picture_id && |
| 163 last_decoded_frame_key.spatial_layer < frame_key.spatial_layer; | 163 last_decoded_frame_key.spatial_layer < frame_key.spatial_layer; |
| 164 | 164 |
| 165 if (AheadOrAt(last_decoded_frame_timestamp_, frame->timestamp) && | 165 if (AheadOf(last_decoded_frame_timestamp_, frame->timestamp) && |
| 166 !frame_is_higher_spatial_layer_of_last_decoded_frame) { | 166 !frame_is_higher_spatial_layer_of_last_decoded_frame) { |
| 167 // TODO(brandtr): Consider clearing the entire buffer when we hit | 167 // TODO(brandtr): Consider clearing the entire buffer when we hit |
| 168 // these conditions. | 168 // these conditions. |
| 169 LOG(LS_WARNING) << "Frame with (timestamp:picture_id:spatial_id) (" | 169 LOG(LS_WARNING) << "Frame with (timestamp:picture_id:spatial_id) (" |
| 170 << frame->timestamp << ":" << frame->picture_id << ":" | 170 << frame->timestamp << ":" << frame->picture_id << ":" |
| 171 << static_cast<int>(frame->spatial_layer) << ")" | 171 << static_cast<int>(frame->spatial_layer) << ")" |
| 172 << " sent to decoder after frame with" | 172 << " sent to decoder after frame with" |
| 173 << " (timestamp:picture_id:spatial_id) (" | 173 << " (timestamp:picture_id:spatial_id) (" |
| 174 << last_decoded_frame_timestamp_ << ":" | 174 << last_decoded_frame_timestamp_ << ":" |
| 175 << last_decoded_frame_key.picture_id << ":" | 175 << last_decoded_frame_key.picture_id << ":" |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // Test if inserting this frame would cause the order of the frames to become | 322 // Test if inserting this frame would cause the order of the frames to become |
| 323 // ambiguous (covering more than half the interval of 2^16). This can happen | 323 // ambiguous (covering more than half the interval of 2^16). This can happen |
| 324 // when the picture id make large jumps mid stream. | 324 // when the picture id make large jumps mid stream. |
| 325 if (!frames_.empty() && | 325 if (!frames_.empty() && |
| 326 key < frames_.begin()->first && | 326 key < frames_.begin()->first && |
| 327 frames_.rbegin()->first < key) { | 327 frames_.rbegin()->first < key) { |
| 328 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer."; | 328 LOG(LS_WARNING) << "A jump in picture id was detected, clearing buffer."; |
| 329 ClearFramesAndHistory(); | 329 ClearFramesAndHistory(); |
| 330 last_continuous_picture_id = -1; | 330 last_continuous_picture_id = -1; |
| 331 } | 331 } |
| 332 | |
| 333 auto info = frames_.insert(std::make_pair(key, FrameInfo())).first; | 332 auto info = frames_.insert(std::make_pair(key, FrameInfo())).first; |
| 334 | 333 |
| 335 if (info->second.frame) { | 334 if (info->second.frame) { |
| 336 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id | 335 LOG(LS_WARNING) << "Frame with (picture_id:spatial_id) (" << key.picture_id |
| 337 << ":" << static_cast<int>(key.spatial_layer) | 336 << ":" << static_cast<int>(key.spatial_layer) |
| 338 << ") already inserted, dropping frame."; | 337 << ") already inserted, dropping frame."; |
| 339 return last_continuous_picture_id; | 338 return last_continuous_picture_id; |
| 340 } | 339 } |
| 341 | 340 |
| 342 if (!UpdateFrameInfoWithIncomingFrame(*frame, info)) | 341 if (!UpdateFrameInfoWithIncomingFrame(*frame, info)) |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 395 } | 394 } |
| 396 | 395 |
| 397 void FrameBuffer::PropagateDecodability(const FrameInfo& info) { | 396 void FrameBuffer::PropagateDecodability(const FrameInfo& info) { |
| 398 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability"); | 397 TRACE_EVENT0("webrtc", "FrameBuffer::PropagateDecodability"); |
| 399 RTC_CHECK(info.num_dependent_frames < FrameInfo::kMaxNumDependentFrames); | 398 RTC_CHECK(info.num_dependent_frames < FrameInfo::kMaxNumDependentFrames); |
| 400 for (size_t d = 0; d < info.num_dependent_frames; ++d) { | 399 for (size_t d = 0; d < info.num_dependent_frames; ++d) { |
| 401 auto ref_info = frames_.find(info.dependent_frames[d]); | 400 auto ref_info = frames_.find(info.dependent_frames[d]); |
| 402 RTC_DCHECK(ref_info != frames_.end()); | 401 RTC_DCHECK(ref_info != frames_.end()); |
| 403 // TODO(philipel): Look into why we've seen this happen. | 402 // TODO(philipel): Look into why we've seen this happen. |
| 404 if (ref_info != frames_.end()) { | 403 if (ref_info != frames_.end()) { |
| 405 RTC_DCHECK_GT(ref_info->second.num_missing_decodable, 0U); | 404 // RTC_DCHECK_GT(ref_info->second.num_missing_decodable, 0U); |
| 406 --ref_info->second.num_missing_decodable; | 405 --ref_info->second.num_missing_decodable; |
| 407 } | 406 } |
| 408 } | 407 } |
| 409 } | 408 } |
| 410 | 409 |
| 411 void FrameBuffer::AdvanceLastDecodedFrame(FrameMap::iterator decoded) { | 410 void FrameBuffer::AdvanceLastDecodedFrame(FrameMap::iterator decoded) { |
| 412 TRACE_EVENT0("webrtc", "FrameBuffer::AdvanceLastDecodedFrame"); | 411 TRACE_EVENT0("webrtc", "FrameBuffer::AdvanceLastDecodedFrame"); |
| 413 if (last_decoded_frame_it_ == frames_.end()) { | 412 if (last_decoded_frame_it_ == frames_.end()) { |
| 414 last_decoded_frame_it_ = frames_.begin(); | 413 last_decoded_frame_it_ = frames_.begin(); |
| 415 } else { | 414 } else { |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 frames_.clear(); | 546 frames_.clear(); |
| 548 last_decoded_frame_it_ = frames_.end(); | 547 last_decoded_frame_it_ = frames_.end(); |
| 549 last_continuous_frame_it_ = frames_.end(); | 548 last_continuous_frame_it_ = frames_.end(); |
| 550 next_frame_it_ = frames_.end(); | 549 next_frame_it_ = frames_.end(); |
| 551 num_frames_history_ = 0; | 550 num_frames_history_ = 0; |
| 552 num_frames_buffered_ = 0; | 551 num_frames_buffered_ = 0; |
| 553 } | 552 } |
| 554 | 553 |
| 555 } // namespace video_coding | 554 } // namespace video_coding |
| 556 } // namespace webrtc | 555 } // namespace webrtc |
| OLD | NEW |