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 485 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
496 } else { | 496 } else { |
497 base::TimeDelta new_range_start_time = std::min( | 497 base::TimeDelta new_range_start_time = std::min( |
498 media_segment_start_time_, buffers.front()->GetDecodeTimestamp()); | 498 media_segment_start_time_, buffers.front()->GetDecodeTimestamp()); |
499 const BufferQueue* buffers_for_new_range = &buffers; | 499 const BufferQueue* buffers_for_new_range = &buffers; |
500 BufferQueue trimmed_buffers; | 500 BufferQueue trimmed_buffers; |
501 | 501 |
502 // If the new range is not being created because of a new media | 502 // If the new range is not being created because of a new media |
503 // segment, then we must make sure that we start with a keyframe. | 503 // segment, then we must make sure that we start with a keyframe. |
504 // This can happen if the GOP in the previous append gets destroyed | 504 // This can happen if the GOP in the previous append gets destroyed |
505 // by a Remove() call. | 505 // by a Remove() call. |
506 if (!new_media_segment_ && !buffers.front()->IsKeyframe()) { | 506 if (!new_media_segment_) { |
507 BufferQueue::const_iterator itr = buffers.begin(); | 507 BufferQueue::const_iterator itr = buffers.begin(); |
508 | 508 |
509 // Scan past all the non-keyframes. | 509 // Scan past all the non-keyframes. |
510 while (itr != buffers.end() && !(*itr)->IsKeyframe()) { | 510 while (itr != buffers.end() && !(*itr)->IsKeyframe()) { |
511 ++itr; | 511 ++itr; |
512 } | 512 } |
513 | 513 |
514 // If we didn't find a keyframe, then update the last appended | 514 // If we didn't find a keyframe, then update the last appended |
515 // buffer state and return. | 515 // buffer state and return. |
516 if (itr == buffers.end()) { | 516 if (itr == buffers.end()) { |
517 last_appended_buffer_timestamp_ = buffers.back()->GetDecodeTimestamp(); | 517 last_appended_buffer_timestamp_ = buffers.back()->GetDecodeTimestamp(); |
518 last_appended_buffer_is_keyframe_ = buffers.back()->IsKeyframe(); | 518 last_appended_buffer_is_keyframe_ = buffers.back()->IsKeyframe(); |
519 return true; | 519 return true; |
520 } else if (itr != buffers.begin()) { | |
521 // Copy the first keyframe and everything after it into | |
522 // |trimmed_buffers|. | |
523 trimmed_buffers.assign(itr, buffers.end()); | |
524 buffers_for_new_range = &trimmed_buffers; | |
520 } | 525 } |
521 | 526 |
522 // Copy the first keyframe and everything after it into |trimmed_buffers|. | 527 new_range_start_time = |
523 trimmed_buffers.assign(itr, buffers.end()); | 528 buffers_for_new_range->front()->GetDecodeTimestamp(); |
524 | |
525 new_range_start_time = trimmed_buffers.front()->GetDecodeTimestamp(); | |
526 buffers_for_new_range = &trimmed_buffers; | |
527 } | 529 } |
528 | 530 |
529 range_for_next_append_ = | 531 range_for_next_append_ = |
530 AddToRanges(new SourceBufferRange( | 532 AddToRanges(new SourceBufferRange( |
531 GetType(), *buffers_for_new_range, new_range_start_time, | 533 GetType(), *buffers_for_new_range, new_range_start_time, |
532 base::Bind(&SourceBufferStream::GetMaxInterbufferDistance, | 534 base::Bind(&SourceBufferStream::GetMaxInterbufferDistance, |
533 base::Unretained(this)))); | 535 base::Unretained(this)))); |
534 last_appended_buffer_timestamp_ = | 536 last_appended_buffer_timestamp_ = |
535 buffers_for_new_range->back()->GetDecodeTimestamp(); | 537 buffers_for_new_range->back()->GetDecodeTimestamp(); |
536 last_appended_buffer_is_keyframe_ = | 538 last_appended_buffer_is_keyframe_ = |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
663 // Clear |range_for_next_append_| if we determine that the removal | 665 // Clear |range_for_next_append_| if we determine that the removal |
664 // operation makes it impossible for the next append to be added | 666 // operation makes it impossible for the next append to be added |
665 // to the current range. | 667 // to the current range. |
666 if (range_for_next_append_ != ranges_.end() && | 668 if (range_for_next_append_ != ranges_.end() && |
667 *range_for_next_append_ == range && | 669 *range_for_next_append_ == range && |
668 last_appended_buffer_timestamp_ != kNoTimestamp()) { | 670 last_appended_buffer_timestamp_ != kNoTimestamp()) { |
669 base::TimeDelta potential_next_append_timestamp = | 671 base::TimeDelta potential_next_append_timestamp = |
670 last_appended_buffer_timestamp_ + | 672 last_appended_buffer_timestamp_ + |
671 base::TimeDelta::FromInternalValue(1); | 673 base::TimeDelta::FromInternalValue(1); |
672 | 674 |
673 if (!range->BelongsToRange(potential_next_append_timestamp)) { | 675 if (!range->BelongsToRange(potential_next_append_timestamp)) { |
wolenetz
2014/06/11 01:53:54
I'm unclear how this path could be reached if rang
acolwell GONE FROM CHROMIUM
2014/06/11 16:47:51
Yes. TruncateAt() should return true. I'm still in
| |
674 DVLOG(1) << "Resetting range_for_next_append_ since the next append" | 676 DVLOG(1) << "Resetting range_for_next_append_ since the next append" |
675 << " can't add to the current range."; | 677 << " can't add to the current range."; |
676 range_for_next_append_ = | 678 range_for_next_append_ = |
677 FindExistingRangeFor(potential_next_append_timestamp); | 679 FindExistingRangeFor(potential_next_append_timestamp); |
678 } | 680 } |
679 } | 681 } |
680 | 682 |
681 // Move on to the next range. | 683 // Move on to the next range. |
682 ++itr; | 684 ++itr; |
683 } | 685 } |
(...skipping 928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1612 | 1614 |
1613 DCHECK(*itr != ranges_.end()); | 1615 DCHECK(*itr != ranges_.end()); |
1614 if (**itr == selected_range_) { | 1616 if (**itr == selected_range_) { |
1615 DVLOG(1) << __FUNCTION__ << " deleting selected range."; | 1617 DVLOG(1) << __FUNCTION__ << " deleting selected range."; |
1616 SetSelectedRange(NULL); | 1618 SetSelectedRange(NULL); |
1617 } | 1619 } |
1618 | 1620 |
1619 if (*itr == range_for_next_append_) { | 1621 if (*itr == range_for_next_append_) { |
1620 DVLOG(1) << __FUNCTION__ << " deleting range_for_next_append_."; | 1622 DVLOG(1) << __FUNCTION__ << " deleting range_for_next_append_."; |
1621 range_for_next_append_ = ranges_.end(); | 1623 range_for_next_append_ = ranges_.end(); |
1624 last_appended_buffer_timestamp_ = kNoTimestamp(); | |
acolwell GONE FROM CHROMIUM
2014/06/10 23:11:13
This prevents the interbuffer distance calculation
| |
1625 last_appended_buffer_is_keyframe_ = false; | |
1622 } | 1626 } |
1623 | 1627 |
1624 delete **itr; | 1628 delete **itr; |
1625 *itr = ranges_.erase(*itr); | 1629 *itr = ranges_.erase(*itr); |
1626 } | 1630 } |
1627 | 1631 |
1628 void SourceBufferStream::GenerateSpliceFrame(const BufferQueue& new_buffers) { | 1632 void SourceBufferStream::GenerateSpliceFrame(const BufferQueue& new_buffers) { |
1629 DCHECK(!new_buffers.empty()); | 1633 DCHECK(!new_buffers.empty()); |
1630 | 1634 |
1631 // Splice frames are only supported for audio. | 1635 // Splice frames are only supported for audio. |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2004 } | 2008 } |
2005 buffers_.erase(starting_point, ending_point); | 2009 buffers_.erase(starting_point, ending_point); |
2006 } | 2010 } |
2007 | 2011 |
2008 bool SourceBufferRange::TruncateAt( | 2012 bool SourceBufferRange::TruncateAt( |
2009 const BufferQueue::iterator& starting_point, BufferQueue* removed_buffers) { | 2013 const BufferQueue::iterator& starting_point, BufferQueue* removed_buffers) { |
2010 DCHECK(!removed_buffers || removed_buffers->empty()); | 2014 DCHECK(!removed_buffers || removed_buffers->empty()); |
2011 | 2015 |
2012 // Return if we're not deleting anything. | 2016 // Return if we're not deleting anything. |
2013 if (starting_point == buffers_.end()) | 2017 if (starting_point == buffers_.end()) |
2014 return false; | 2018 return false; |
wolenetz
2014/06/11 01:53:54
Should this return true? (see my other comment)
acolwell GONE FROM CHROMIUM
2014/06/11 16:47:51
I believe this should return buffers_.empty(). I w
| |
2015 | 2019 |
2016 // Reset the next buffer index if we will be deleting the buffer that's next | 2020 // Reset the next buffer index if we will be deleting the buffer that's next |
2017 // in sequence. | 2021 // in sequence. |
2018 if (HasNextBufferPosition()) { | 2022 if (HasNextBufferPosition()) { |
2019 base::TimeDelta next_buffer_timestamp = GetNextTimestamp(); | 2023 base::TimeDelta next_buffer_timestamp = GetNextTimestamp(); |
2020 if (next_buffer_timestamp == kNoTimestamp() || | 2024 if (next_buffer_timestamp == kNoTimestamp() || |
2021 next_buffer_timestamp >= (*starting_point)->GetDecodeTimestamp()) { | 2025 next_buffer_timestamp >= (*starting_point)->GetDecodeTimestamp()) { |
2022 if (HasNextBuffer() && removed_buffers) { | 2026 if (HasNextBuffer() && removed_buffers) { |
2023 int starting_offset = starting_point - buffers_.begin(); | 2027 int starting_offset = starting_point - buffers_.begin(); |
2024 int next_buffer_offset = next_buffer_index_ - starting_offset; | 2028 int next_buffer_offset = next_buffer_index_ - starting_offset; |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2236 return false; | 2240 return false; |
2237 | 2241 |
2238 DCHECK_NE(have_splice_buffers, have_preroll_buffer); | 2242 DCHECK_NE(have_splice_buffers, have_preroll_buffer); |
2239 splice_buffers_index_ = 0; | 2243 splice_buffers_index_ = 0; |
2240 pending_buffer_.swap(*out_buffer); | 2244 pending_buffer_.swap(*out_buffer); |
2241 pending_buffers_complete_ = false; | 2245 pending_buffers_complete_ = false; |
2242 return true; | 2246 return true; |
2243 } | 2247 } |
2244 | 2248 |
2245 } // namespace media | 2249 } // namespace media |
OLD | NEW |