| 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 } | 91 } |
| 92 } | 92 } |
| 93 } | 93 } |
| 94 | 94 |
| 95 void SourceBufferRange::Seek(DecodeTimestamp timestamp) { | 95 void SourceBufferRange::Seek(DecodeTimestamp timestamp) { |
| 96 DCHECK(CanSeekTo(timestamp)); | 96 DCHECK(CanSeekTo(timestamp)); |
| 97 DCHECK(!keyframe_map_.empty()); | 97 DCHECK(!keyframe_map_.empty()); |
| 98 | 98 |
| 99 KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp); | 99 KeyframeMap::iterator result = GetFirstKeyframeAtOrBefore(timestamp); |
| 100 next_buffer_index_ = result->second - keyframe_map_index_base_; | 100 next_buffer_index_ = result->second - keyframe_map_index_base_; |
| 101 DCHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size())); | 101 CHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size())) |
| 102 << next_buffer_index_ << ", size = " << buffers_.size(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 void SourceBufferRange::SeekAheadTo(DecodeTimestamp timestamp) { | 105 void SourceBufferRange::SeekAheadTo(DecodeTimestamp timestamp) { |
| 105 SeekAhead(timestamp, false); | 106 SeekAhead(timestamp, false); |
| 106 } | 107 } |
| 107 | 108 |
| 108 void SourceBufferRange::SeekAheadPast(DecodeTimestamp timestamp) { | 109 void SourceBufferRange::SeekAheadPast(DecodeTimestamp timestamp) { |
| 109 SeekAhead(timestamp, true); | 110 SeekAhead(timestamp, true); |
| 110 } | 111 } |
| 111 | 112 |
| 112 void SourceBufferRange::SeekAhead(DecodeTimestamp timestamp, | 113 void SourceBufferRange::SeekAhead(DecodeTimestamp timestamp, |
| 113 bool skip_given_timestamp) { | 114 bool skip_given_timestamp) { |
| 114 DCHECK(!keyframe_map_.empty()); | 115 DCHECK(!keyframe_map_.empty()); |
| 115 | 116 |
| 116 KeyframeMap::iterator result = | 117 KeyframeMap::iterator result = |
| 117 GetFirstKeyframeAt(timestamp, skip_given_timestamp); | 118 GetFirstKeyframeAt(timestamp, skip_given_timestamp); |
| 118 | 119 |
| 119 // If there isn't a keyframe after |timestamp|, then seek to end and return | 120 // If there isn't a keyframe after |timestamp|, then seek to end and return |
| 120 // kNoTimestamp to signal such. | 121 // kNoTimestamp to signal such. |
| 121 if (result == keyframe_map_.end()) { | 122 if (result == keyframe_map_.end()) { |
| 122 next_buffer_index_ = -1; | 123 next_buffer_index_ = -1; |
| 123 return; | 124 return; |
| 124 } | 125 } |
| 125 next_buffer_index_ = result->second - keyframe_map_index_base_; | 126 next_buffer_index_ = result->second - keyframe_map_index_base_; |
| 126 DCHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size())); | 127 DCHECK_LT(next_buffer_index_, static_cast<int>(buffers_.size())); |
| 127 } | 128 } |
| 128 | 129 |
| 129 void SourceBufferRange::SeekToStart() { | 130 void SourceBufferRange::SeekToStart() { |
| 130 DCHECK(!buffers_.empty()); | 131 CHECK(!buffers_.empty()); |
| 131 next_buffer_index_ = 0; | 132 next_buffer_index_ = 0; |
| 132 } | 133 } |
| 133 | 134 |
| 134 SourceBufferRange* SourceBufferRange::SplitRange(DecodeTimestamp timestamp) { | 135 SourceBufferRange* SourceBufferRange::SplitRange(DecodeTimestamp timestamp) { |
| 135 CHECK(!buffers_.empty()); | 136 CHECK(!buffers_.empty()); |
| 136 | 137 |
| 137 // Find the first keyframe at or after |timestamp|. | 138 // Find the first keyframe at or after |timestamp|. |
| 138 KeyframeMap::iterator new_beginning_keyframe = | 139 KeyframeMap::iterator new_beginning_keyframe = |
| 139 GetFirstKeyframeAt(timestamp, false); | 140 GetFirstKeyframeAt(timestamp, false); |
| 140 | 141 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 166 // Create a new range with |removed_buffers|. | 167 // Create a new range with |removed_buffers|. |
| 167 SourceBufferRange* split_range = | 168 SourceBufferRange* split_range = |
| 168 new SourceBufferRange( | 169 new SourceBufferRange( |
| 169 gap_policy_, removed_buffers, new_range_start_timestamp, | 170 gap_policy_, removed_buffers, new_range_start_timestamp, |
| 170 interbuffer_distance_cb_); | 171 interbuffer_distance_cb_); |
| 171 | 172 |
| 172 // If the next buffer position is now in |split_range|, update the state of | 173 // If the next buffer position is now in |split_range|, update the state of |
| 173 // this range and |split_range| accordingly. | 174 // this range and |split_range| accordingly. |
| 174 if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { | 175 if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { |
| 175 split_range->next_buffer_index_ = next_buffer_index_ - keyframe_index; | 176 split_range->next_buffer_index_ = next_buffer_index_ - keyframe_index; |
| 177 CHECK_GE(split_range->next_buffer_index_, 0) |
| 178 << split_range->next_buffer_index_; |
| 176 ResetNextBufferPosition(); | 179 ResetNextBufferPosition(); |
| 177 } | 180 } |
| 178 | 181 |
| 179 return split_range; | 182 return split_range; |
| 180 } | 183 } |
| 181 | 184 |
| 182 SourceBufferRange::BufferQueue::iterator SourceBufferRange::GetBufferItrAt( | 185 SourceBufferRange::BufferQueue::iterator SourceBufferRange::GetBufferItrAt( |
| 183 DecodeTimestamp timestamp, | 186 DecodeTimestamp timestamp, |
| 184 bool skip_given_timestamp) { | 187 bool skip_given_timestamp) { |
| 185 return skip_given_timestamp | 188 return skip_given_timestamp |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 deleted_buffers->push_back(buffers_.front()); | 259 deleted_buffers->push_back(buffers_.front()); |
| 257 buffers_.pop_front(); | 260 buffers_.pop_front(); |
| 258 ++buffers_deleted; | 261 ++buffers_deleted; |
| 259 } | 262 } |
| 260 | 263 |
| 261 // Update |keyframe_map_index_base_| to account for the deleted buffers. | 264 // Update |keyframe_map_index_base_| to account for the deleted buffers. |
| 262 keyframe_map_index_base_ += buffers_deleted; | 265 keyframe_map_index_base_ += buffers_deleted; |
| 263 | 266 |
| 264 if (next_buffer_index_ > -1) { | 267 if (next_buffer_index_ > -1) { |
| 265 next_buffer_index_ -= buffers_deleted; | 268 next_buffer_index_ -= buffers_deleted; |
| 266 DCHECK_GE(next_buffer_index_, 0); | 269 CHECK_GE(next_buffer_index_, 0) << next_buffer_index_ << ", deleted " |
| 270 << buffers_deleted; |
| 267 } | 271 } |
| 268 | 272 |
| 269 // Invalidate media segment start time if we've deleted the first buffer of | 273 // Invalidate media segment start time if we've deleted the first buffer of |
| 270 // the range. | 274 // the range. |
| 271 if (buffers_deleted > 0) | 275 if (buffers_deleted > 0) |
| 272 media_segment_start_time_ = kNoDecodeTimestamp(); | 276 media_segment_start_time_ = kNoDecodeTimestamp(); |
| 273 | 277 |
| 274 return total_bytes_deleted; | 278 return total_bytes_deleted; |
| 275 } | 279 } |
| 276 | 280 |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 436 next_buffer_index_++; | 440 next_buffer_index_++; |
| 437 return true; | 441 return true; |
| 438 } | 442 } |
| 439 | 443 |
| 440 bool SourceBufferRange::HasNextBuffer() const { | 444 bool SourceBufferRange::HasNextBuffer() const { |
| 441 return next_buffer_index_ >= 0 && | 445 return next_buffer_index_ >= 0 && |
| 442 next_buffer_index_ < static_cast<int>(buffers_.size()); | 446 next_buffer_index_ < static_cast<int>(buffers_.size()); |
| 443 } | 447 } |
| 444 | 448 |
| 445 int SourceBufferRange::GetNextConfigId() const { | 449 int SourceBufferRange::GetNextConfigId() const { |
| 446 DCHECK(HasNextBuffer()); | 450 CHECK(HasNextBuffer()) << next_buffer_index_; |
| 447 // If the next buffer is an audio splice frame, the next effective config id | 451 // If the next buffer is an audio splice frame, the next effective config id |
| 448 // comes from the first fade out preroll buffer. | 452 // comes from the first fade out preroll buffer. |
| 449 return buffers_[next_buffer_index_]->GetSpliceBufferConfigId(0); | 453 return buffers_[next_buffer_index_]->GetSpliceBufferConfigId(0); |
| 450 } | 454 } |
| 451 | 455 |
| 452 DecodeTimestamp SourceBufferRange::GetNextTimestamp() const { | 456 DecodeTimestamp SourceBufferRange::GetNextTimestamp() const { |
| 453 DCHECK(!buffers_.empty()); | 457 CHECK(!buffers_.empty()) << next_buffer_index_; |
| 454 DCHECK(HasNextBufferPosition()); | 458 CHECK(HasNextBufferPosition()) << next_buffer_index_ |
| 459 << ", size=" << buffers_.size(); |
| 455 | 460 |
| 456 if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { | 461 if (next_buffer_index_ >= static_cast<int>(buffers_.size())) { |
| 457 return kNoDecodeTimestamp(); | 462 return kNoDecodeTimestamp(); |
| 458 } | 463 } |
| 459 | 464 |
| 460 return buffers_[next_buffer_index_]->GetDecodeTimestamp(); | 465 return buffers_[next_buffer_index_]->GetDecodeTimestamp(); |
| 461 } | 466 } |
| 462 | 467 |
| 463 bool SourceBufferRange::HasNextBufferPosition() const { | 468 bool SourceBufferRange::HasNextBufferPosition() const { |
| 464 return next_buffer_index_ >= 0; | 469 return next_buffer_index_ >= 0; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 } | 626 } |
| 622 | 627 |
| 623 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) | 628 if (buffer->timestamp() + buffer->duration() <= start.ToPresentationTime()) |
| 624 continue; | 629 continue; |
| 625 buffers->push_back(buffer); | 630 buffers->push_back(buffer); |
| 626 } | 631 } |
| 627 return previous_size < buffers->size(); | 632 return previous_size < buffers->size(); |
| 628 } | 633 } |
| 629 | 634 |
| 630 } // namespace media | 635 } // namespace media |
| OLD | NEW |