| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/filters/source_buffer_range.h" | 5 #include "media/filters/source_buffer_range.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "media/base/timestamp_constants.h" | 9 #include "media/base/timestamp_constants.h" |
| 10 | 10 |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 } | 96 } |
| 97 } | 97 } |
| 98 | 98 |
| 99 void SourceBufferRange::Seek(DecodeTimestamp timestamp) { | 99 void SourceBufferRange::Seek(DecodeTimestamp timestamp) { |
| 100 DCHECK(CanSeekTo(timestamp)); | 100 DCHECK(CanSeekTo(timestamp)); |
| 101 DCHECK(!keyframe_map_.empty()); | 101 DCHECK(!keyframe_map_.empty()); |
| 102 | 102 |
| 103 KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp); | 103 KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp); |
| 104 next_buffer_index_ = result->second - keyframe_map_index_base_; | 104 next_buffer_index_ = result->second - keyframe_map_index_base_; |
| 105 CHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size())) | 105 CHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size())); |
| 106 << next_buffer_index_ << ", size = " << buffers_.size(); | |
| 107 } | 106 } |
| 108 | 107 |
| 109 int SourceBufferRange::GetConfigIdAtTime(DecodeTimestamp timestamp) { | 108 int SourceBufferRange::GetConfigIdAtTime(DecodeTimestamp timestamp) { |
| 110 DCHECK(CanSeekTo(timestamp)); | 109 DCHECK(CanSeekTo(timestamp)); |
| 111 DCHECK(!keyframe_map_.empty()); | 110 DCHECK(!keyframe_map_.empty()); |
| 112 | 111 |
| 113 KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp); | 112 KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp); |
| 114 CHECK(result != keyframe_map_.end()); | 113 CHECK(result != keyframe_map_.end()); |
| 115 size_t buffer_index = result->second - keyframe_map_index_base_; | 114 size_t buffer_index = result->second - keyframe_map_index_base_; |
| 116 CHECK_LT(buffer_index, buffers_.size()) << buffer_index | 115 CHECK_LT(buffer_index, buffers_.size()) << buffer_index |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 deleted_buffers->push_back(buffers_.front()); | 309 deleted_buffers->push_back(buffers_.front()); |
| 311 buffers_.pop_front(); | 310 buffers_.pop_front(); |
| 312 ++buffers_deleted; | 311 ++buffers_deleted; |
| 313 } | 312 } |
| 314 | 313 |
| 315 // Update |keyframe_map_index_base_| to account for the deleted buffers. | 314 // Update |keyframe_map_index_base_| to account for the deleted buffers. |
| 316 keyframe_map_index_base_ += buffers_deleted; | 315 keyframe_map_index_base_ += buffers_deleted; |
| 317 | 316 |
| 318 if (next_buffer_index_ > -1) { | 317 if (next_buffer_index_ > -1) { |
| 319 next_buffer_index_ -= buffers_deleted; | 318 next_buffer_index_ -= buffers_deleted; |
| 320 CHECK_GE(next_buffer_index_, 0) << next_buffer_index_ << ", deleted " | 319 CHECK_GE(next_buffer_index_, 0); |
| 321 << buffers_deleted; | |
| 322 } | 320 } |
| 323 | 321 |
| 324 // Invalidate range start time if we've deleted the first buffer of the range. | 322 // Invalidate range start time if we've deleted the first buffer of the range. |
| 325 if (buffers_deleted > 0) | 323 if (buffers_deleted > 0) |
| 326 range_start_time_ = kNoDecodeTimestamp(); | 324 range_start_time_ = kNoDecodeTimestamp(); |
| 327 | 325 |
| 328 return total_bytes_deleted; | 326 return total_bytes_deleted; |
| 329 } | 327 } |
| 330 | 328 |
| 331 size_t SourceBufferRange::DeleteGOPFromBack(BufferQueue* deleted_buffers) { | 329 size_t SourceBufferRange::DeleteGOPFromBack(BufferQueue* deleted_buffers) { |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 next_buffer_index_++; | 489 next_buffer_index_++; |
| 492 return true; | 490 return true; |
| 493 } | 491 } |
| 494 | 492 |
| 495 bool SourceBufferRange::HasNextBuffer() const { | 493 bool SourceBufferRange::HasNextBuffer() const { |
| 496 return next_buffer_index_ >= 0 && | 494 return next_buffer_index_ >= 0 && |
| 497 next_buffer_index_ < static_cast<int>(buffers_.size()); | 495 next_buffer_index_ < static_cast<int>(buffers_.size()); |
| 498 } | 496 } |
| 499 | 497 |
| 500 int SourceBufferRange::GetNextConfigId() const { | 498 int SourceBufferRange::GetNextConfigId() const { |
| 501 CHECK(HasNextBuffer()) << next_buffer_index_; | 499 CHECK(HasNextBuffer()); |
| 502 // If the next buffer is an audio splice frame, the next effective config id | 500 // If the next buffer is an audio splice frame, the next effective config id |
| 503 // comes from the first fade out preroll buffer. | 501 // comes from the first fade out preroll buffer. |
| 504 return buffers_[next_buffer_index_]->GetConfigId(); | 502 return buffers_[next_buffer_index_]->GetConfigId(); |
| 505 } | 503 } |
| 506 | 504 |
| 507 DecodeTimestamp SourceBufferRange::GetNextTimestamp() const { | 505 DecodeTimestamp SourceBufferRange::GetNextTimestamp() const { |
| 508 CHECK(!buffers_.empty()) << next_buffer_index_; | 506 CHECK(!buffers_.empty()); |
| 509 CHECK(HasNextBufferPosition()) << next_buffer_index_ | 507 CHECK(HasNextBufferPosition()); |
| 510 << ", size=" << buffers_.size(); | |
| 511 | 508 |
| 512 if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { | 509 if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { |
| 513 return kNoDecodeTimestamp(); | 510 return kNoDecodeTimestamp(); |
| 514 } | 511 } |
| 515 | 512 |
| 516 return buffers_[next_buffer_index_]->GetDecodeTimestamp(); | 513 return buffers_[next_buffer_index_]->GetDecodeTimestamp(); |
| 517 } | 514 } |
| 518 | 515 |
| 519 bool SourceBufferRange::HasNextBufferPosition() const { | 516 bool SourceBufferRange::HasNextBufferPosition() const { |
| 520 return next_buffer_index_ >= 0; | 517 return next_buffer_index_ >= 0; |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 } | 673 } |
| 677 | 674 |
| 678 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) | 675 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) |
| 679 continue; | 676 continue; |
| 680 buffers->push_back(buffer); | 677 buffers->push_back(buffer); |
| 681 } | 678 } |
| 682 return previous_size < buffers->size(); | 679 return previous_size < buffers->size(); |
| 683 } | 680 } |
| 684 | 681 |
| 685 } // namespace media | 682 } // namespace media |
| OLD | NEW |