OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_stream.h" | 5 #include "media/filters/source_buffer_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
224 static bool BufferComparator( | 224 static bool BufferComparator( |
225 const scoped_refptr<media::StreamParserBuffer>& first, | 225 const scoped_refptr<media::StreamParserBuffer>& first, |
226 const scoped_refptr<media::StreamParserBuffer>& second) { | 226 const scoped_refptr<media::StreamParserBuffer>& second) { |
227 return first->GetDecodeTimestamp() < second->GetDecodeTimestamp(); | 227 return first->GetDecodeTimestamp() < second->GetDecodeTimestamp(); |
228 } | 228 } |
229 | 229 |
230 // An arbitrarily-chosen number to estimate the duration of a buffer if none | 230 // An arbitrarily-chosen number to estimate the duration of a buffer if none |
231 // is set and there's not enough information to get a better estimate. | 231 // is set and there's not enough information to get a better estimate. |
232 static int kDefaultBufferDurationInMs = 125; | 232 static int kDefaultBufferDurationInMs = 125; |
233 | 233 |
| 234 // The amount of time the beginning of the buffered data can differ from the |
| 235 // start time in order to still be considered the start of stream. |
| 236 static base::TimeDelta kSeekToStartFudgeRoom() { |
| 237 return base::TimeDelta::FromMilliseconds(1000); |
| 238 } |
| 239 |
234 namespace media { | 240 namespace media { |
235 | 241 |
236 SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config) | 242 SourceBufferStream::SourceBufferStream(const AudioDecoderConfig& audio_config) |
237 : current_config_index_(0), | 243 : current_config_index_(0), |
238 append_config_index_(0), | 244 append_config_index_(0), |
239 audio_configs_(1), | 245 audio_configs_(1), |
240 video_configs_(0), | 246 video_configs_(0), |
241 stream_start_time_(kNoTimestamp()), | 247 stream_start_time_(kNoTimestamp()), |
242 seek_pending_(false), | 248 seek_pending_(false), |
243 seek_buffer_timestamp_(kNoTimestamp()), | 249 seek_buffer_timestamp_(kNoTimestamp()), |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 // than |end_buffer_timestamp|). | 387 // than |end_buffer_timestamp|). |
382 selected_range_->SeekAheadPast(end_buffer_timestamp); | 388 selected_range_->SeekAheadPast(end_buffer_timestamp); |
383 } | 389 } |
384 } | 390 } |
385 | 391 |
386 DCHECK(IsRangeListSorted(ranges_)); | 392 DCHECK(IsRangeListSorted(ranges_)); |
387 DCHECK(OnlySelectedRangeIsSeeked()); | 393 DCHECK(OnlySelectedRangeIsSeeked()); |
388 return true; | 394 return true; |
389 } | 395 } |
390 | 396 |
391 bool SourceBufferStream::IsBeforeFirstRange(base::TimeDelta timestamp) const { | 397 bool SourceBufferStream::ShouldSeekToStartOfBuffered( |
| 398 base::TimeDelta seek_timestamp) const { |
392 if (ranges_.empty()) | 399 if (ranges_.empty()) |
393 return false; | 400 return false; |
394 return timestamp < ranges_.front()->GetStartTimestamp(); | 401 base::TimeDelta beginning_of_buffered = |
| 402 ranges_.front()->GetStartTimestamp(); |
| 403 base::TimeDelta start_time_delta = beginning_of_buffered - stream_start_time_; |
| 404 return seek_timestamp <= beginning_of_buffered && |
| 405 start_time_delta < kSeekToStartFudgeRoom(); |
395 } | 406 } |
396 | 407 |
397 bool SourceBufferStream::IsMonotonicallyIncreasing( | 408 bool SourceBufferStream::IsMonotonicallyIncreasing( |
398 const BufferQueue& buffers) const { | 409 const BufferQueue& buffers) const { |
399 DCHECK(!buffers.empty()); | 410 DCHECK(!buffers.empty()); |
400 base::TimeDelta prev_timestamp = last_buffer_timestamp_; | 411 base::TimeDelta prev_timestamp = last_buffer_timestamp_; |
401 for (BufferQueue::const_iterator itr = buffers.begin(); | 412 for (BufferQueue::const_iterator itr = buffers.begin(); |
402 itr != buffers.end(); ++itr) { | 413 itr != buffers.end(); ++itr) { |
403 base::TimeDelta current_timestamp = (*itr)->GetDecodeTimestamp(); | 414 base::TimeDelta current_timestamp = (*itr)->GetDecodeTimestamp(); |
404 DCHECK(current_timestamp != kNoTimestamp()); | 415 DCHECK(current_timestamp != kNoTimestamp()); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
644 ranges_.erase(next_range_itr); | 655 ranges_.erase(next_range_itr); |
645 } | 656 } |
646 } | 657 } |
647 | 658 |
648 void SourceBufferStream::Seek(base::TimeDelta timestamp) { | 659 void SourceBufferStream::Seek(base::TimeDelta timestamp) { |
649 DCHECK(stream_start_time_ != kNoTimestamp()); | 660 DCHECK(stream_start_time_ != kNoTimestamp()); |
650 DCHECK(timestamp >= stream_start_time_); | 661 DCHECK(timestamp >= stream_start_time_); |
651 SetSelectedRange(NULL); | 662 SetSelectedRange(NULL); |
652 track_buffer_.clear(); | 663 track_buffer_.clear(); |
653 | 664 |
654 if (IsBeforeFirstRange(timestamp)) { | 665 if (ShouldSeekToStartOfBuffered(timestamp)) { |
655 SetSelectedRange(ranges_.front()); | 666 SetSelectedRange(ranges_.front()); |
656 ranges_.front()->SeekToStart(); | 667 ranges_.front()->SeekToStart(); |
657 seek_pending_ = false; | 668 seek_pending_ = false; |
658 return; | 669 return; |
659 } | 670 } |
660 | 671 |
661 seek_buffer_timestamp_ = timestamp; | 672 seek_buffer_timestamp_ = timestamp; |
662 seek_pending_ = true; | 673 seek_pending_ = true; |
663 | 674 |
664 RangeList::iterator itr = ranges_.end(); | 675 RangeList::iterator itr = ranges_.end(); |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1174 return 2 * GetApproximateDuration(); | 1185 return 2 * GetApproximateDuration(); |
1175 } | 1186 } |
1176 | 1187 |
1177 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { | 1188 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { |
1178 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); | 1189 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); |
1179 DCHECK(max_interbuffer_distance != kNoTimestamp()); | 1190 DCHECK(max_interbuffer_distance != kNoTimestamp()); |
1180 return max_interbuffer_distance; | 1191 return max_interbuffer_distance; |
1181 } | 1192 } |
1182 | 1193 |
1183 } // namespace media | 1194 } // namespace media |
OLD | NEW |