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 453 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 | 464 |
465 GarbageCollectIfNeeded(); | 465 GarbageCollectIfNeeded(); |
466 | 466 |
467 DCHECK(IsRangeListSorted(ranges_)); | 467 DCHECK(IsRangeListSorted(ranges_)); |
468 DCHECK(OnlySelectedRangeIsSeeked()); | 468 DCHECK(OnlySelectedRangeIsSeeked()); |
469 return true; | 469 return true; |
470 } | 470 } |
471 | 471 |
472 void SourceBufferStream::Remove(base::TimeDelta start, base::TimeDelta end, | 472 void SourceBufferStream::Remove(base::TimeDelta start, base::TimeDelta end, |
473 base::TimeDelta duration) { | 473 base::TimeDelta duration) { |
| 474 DVLOG(1) << __FUNCTION__ << "(" << start.InSecondsF() |
| 475 << ", " << end.InSecondsF() |
| 476 << ", " << duration.InSecondsF() << ")"; |
474 DCHECK(start >= base::TimeDelta()) << start.InSecondsF(); | 477 DCHECK(start >= base::TimeDelta()) << start.InSecondsF(); |
475 DCHECK(start < end) << "start " << start.InSecondsF() | 478 DCHECK(start < end) << "start " << start.InSecondsF() |
476 << " end " << end.InSecondsF(); | 479 << " end " << end.InSecondsF(); |
477 DCHECK(duration != kNoTimestamp()); | 480 DCHECK(duration != kNoTimestamp()); |
478 | 481 |
479 base::TimeDelta remove_end_timestamp = duration; | 482 base::TimeDelta remove_end_timestamp = duration; |
480 base::TimeDelta keyframe_timestamp = FindKeyframeAfterTimestamp(end); | 483 base::TimeDelta keyframe_timestamp = FindKeyframeAfterTimestamp(end); |
481 if (keyframe_timestamp != kNoTimestamp()) { | 484 if (keyframe_timestamp != kNoTimestamp()) { |
482 remove_end_timestamp = keyframe_timestamp; | 485 remove_end_timestamp = keyframe_timestamp; |
483 } else if (end < remove_end_timestamp) { | 486 } else if (end < remove_end_timestamp) { |
484 remove_end_timestamp = end; | 487 remove_end_timestamp = end; |
485 } | 488 } |
486 | 489 |
487 RangeList::iterator itr = ranges_.begin(); | 490 RangeList::iterator itr = ranges_.begin(); |
488 | 491 |
489 while (itr != ranges_.end()) { | 492 while (itr != ranges_.end()) { |
490 SourceBufferRange* range = *itr; | 493 SourceBufferRange* range = *itr; |
491 if (range->GetStartTimestamp() >= remove_end_timestamp) | 494 if (range->GetStartTimestamp() >= remove_end_timestamp) |
492 break; | 495 break; |
493 | 496 |
494 // Split off any remaining end piece and add it to |ranges_|. | 497 // Split off any remaining end piece and add it to |ranges_|. |
495 SourceBufferRange* new_range = | 498 SourceBufferRange* new_range = |
496 range->SplitRange(remove_end_timestamp, false); | 499 range->SplitRange(remove_end_timestamp, false); |
497 if (new_range) { | 500 if (new_range) { |
498 itr = ranges_.insert(++itr, new_range); | 501 itr = ranges_.insert(++itr, new_range); |
499 --itr; | 502 --itr; |
| 503 |
| 504 // Update the selected range if the next buffer position was transferred |
| 505 // to |new_range|. |
| 506 if (new_range->HasNextBufferPosition()) |
| 507 SetSelectedRange(new_range); |
500 } | 508 } |
501 | 509 |
502 // If the current range now is completely covered by the removal | 510 // If the current range now is completely covered by the removal |
503 // range then delete it and move on. | 511 // range then delete it and move on. |
504 if (start <= range->GetStartTimestamp()) { | 512 if (start <= range->GetStartTimestamp()) { |
505 if (selected_range_ == range) | 513 if (selected_range_ == range) |
506 SetSelectedRange(NULL); | 514 SetSelectedRange(NULL); |
507 | 515 |
508 delete range; | 516 delete range; |
509 itr = ranges_.erase(itr); | 517 itr = ranges_.erase(itr); |
510 continue; | 518 continue; |
511 } | 519 } |
512 | 520 |
513 // Truncate the current range so that it only contains data before | 521 // Truncate the current range so that it only contains data before |
514 // the removal range. | 522 // the removal range. |
515 BufferQueue saved_buffers; | 523 BufferQueue saved_buffers; |
516 range->TruncateAt(start, &saved_buffers, false); | 524 range->TruncateAt(start, &saved_buffers, false); |
517 | 525 |
518 // Check to see if the current playback position was removed and | 526 // Check to see if the current playback position was removed and |
519 // update the selected range appropriately. | 527 // update the selected range appropriately. |
520 if (!saved_buffers.empty()) { | 528 if (!saved_buffers.empty()) { |
| 529 DCHECK(!range->HasNextBufferPosition()); |
521 SetSelectedRange(NULL); | 530 SetSelectedRange(NULL); |
522 SetSelectedRangeIfNeeded(saved_buffers.front()->GetDecodeTimestamp()); | 531 SetSelectedRangeIfNeeded(saved_buffers.front()->GetDecodeTimestamp()); |
523 } | 532 } |
524 | 533 |
525 // Move on to the next range. | 534 // Move on to the next range. |
526 ++itr; | 535 ++itr; |
527 } | 536 } |
| 537 |
| 538 DCHECK(IsRangeListSorted(ranges_)); |
| 539 DCHECK(OnlySelectedRangeIsSeeked()); |
528 } | 540 } |
529 | 541 |
530 void SourceBufferStream::ResetSeekState() { | 542 void SourceBufferStream::ResetSeekState() { |
531 SetSelectedRange(NULL); | 543 SetSelectedRange(NULL); |
532 track_buffer_.clear(); | 544 track_buffer_.clear(); |
533 config_change_pending_ = false; | 545 config_change_pending_ = false; |
534 last_output_buffer_timestamp_ = kNoTimestamp(); | 546 last_output_buffer_timestamp_ = kNoTimestamp(); |
535 } | 547 } |
536 | 548 |
537 bool SourceBufferStream::ShouldSeekToStartOfBuffered( | 549 bool SourceBufferStream::ShouldSeekToStartOfBuffered( |
(...skipping 708 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1246 current_config_index_ = track_buffer_.front()->GetConfigId(); | 1258 current_config_index_ = track_buffer_.front()->GetConfigId(); |
1247 return; | 1259 return; |
1248 } | 1260 } |
1249 | 1261 |
1250 if (selected_range_ && selected_range_->HasNextBuffer()) | 1262 if (selected_range_ && selected_range_->HasNextBuffer()) |
1251 current_config_index_ = selected_range_->GetNextConfigId(); | 1263 current_config_index_ = selected_range_->GetNextConfigId(); |
1252 } | 1264 } |
1253 | 1265 |
1254 void SourceBufferStream::SetSelectedRangeIfNeeded( | 1266 void SourceBufferStream::SetSelectedRangeIfNeeded( |
1255 const base::TimeDelta timestamp) { | 1267 const base::TimeDelta timestamp) { |
| 1268 DVLOG(1) << __FUNCTION__ << "(" << timestamp.InSecondsF() << ")"; |
| 1269 |
1256 if (selected_range_) { | 1270 if (selected_range_) { |
1257 DCHECK(track_buffer_.empty()); | 1271 DCHECK(track_buffer_.empty()); |
1258 return; | 1272 return; |
1259 } | 1273 } |
1260 | 1274 |
1261 if (!track_buffer_.empty()) { | 1275 if (!track_buffer_.empty()) { |
1262 DCHECK(!selected_range_); | 1276 DCHECK(!selected_range_); |
1263 return; | 1277 return; |
1264 } | 1278 } |
1265 | 1279 |
(...skipping 561 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1827 return ComputeFudgeRoom(GetApproximateDuration()); | 1841 return ComputeFudgeRoom(GetApproximateDuration()); |
1828 } | 1842 } |
1829 | 1843 |
1830 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { | 1844 base::TimeDelta SourceBufferRange::GetApproximateDuration() const { |
1831 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); | 1845 base::TimeDelta max_interbuffer_distance = interbuffer_distance_cb_.Run(); |
1832 DCHECK(max_interbuffer_distance != kNoTimestamp()); | 1846 DCHECK(max_interbuffer_distance != kNoTimestamp()); |
1833 return max_interbuffer_distance; | 1847 return max_interbuffer_distance; |
1834 } | 1848 } |
1835 | 1849 |
1836 } // namespace media | 1850 } // namespace media |
OLD | NEW |