| 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 472 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 483 | 483 |
| 484 PrepareRangesForNextAppend(buffers, &deleted_buffers); | 484 PrepareRangesForNextAppend(buffers, &deleted_buffers); |
| 485 | 485 |
| 486 // If there's a range for |buffers|, insert |buffers| accordingly. Otherwise, | 486 // If there's a range for |buffers|, insert |buffers| accordingly. Otherwise, |
| 487 // create a new range with |buffers|. | 487 // create a new range with |buffers|. |
| 488 if (range_for_next_append_ != ranges_.end()) { | 488 if (range_for_next_append_ != ranges_.end()) { |
| 489 (*range_for_next_append_)->AppendBuffersToEnd(buffers); | 489 (*range_for_next_append_)->AppendBuffersToEnd(buffers); |
| 490 last_appended_buffer_timestamp_ = buffers.back()->GetDecodeTimestamp(); | 490 last_appended_buffer_timestamp_ = buffers.back()->GetDecodeTimestamp(); |
| 491 last_appended_buffer_is_keyframe_ = buffers.back()->IsKeyframe(); | 491 last_appended_buffer_is_keyframe_ = buffers.back()->IsKeyframe(); |
| 492 } else { | 492 } else { |
| 493 base::TimeDelta new_range_start_time = media_segment_start_time_; | 493 base::TimeDelta new_range_start_time = std::min( |
| 494 media_segment_start_time_, buffers.front()->GetDecodeTimestamp()); |
| 494 const BufferQueue* buffers_for_new_range = &buffers; | 495 const BufferQueue* buffers_for_new_range = &buffers; |
| 495 BufferQueue trimmed_buffers; | 496 BufferQueue trimmed_buffers; |
| 496 | 497 |
| 497 // If the new range is not being created because of a new media | 498 // If the new range is not being created because of a new media |
| 498 // segment, then we must make sure that we start with a keyframe. | 499 // segment, then we must make sure that we start with a keyframe. |
| 499 // This can happen if the GOP in the previous append gets destroyed | 500 // This can happen if the GOP in the previous append gets destroyed |
| 500 // by a Remove() call. | 501 // by a Remove() call. |
| 501 if (!new_media_segment_ && !buffers.front()->IsKeyframe()) { | 502 if (!new_media_segment_ && !buffers.front()->IsKeyframe()) { |
| 502 BufferQueue::const_iterator itr = buffers.begin(); | 503 BufferQueue::const_iterator itr = buffers.begin(); |
| 503 | 504 |
| (...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 981 if (prev_timestamp != kNoTimestamp() && prev_timestamp != next_timestamp) { | 982 if (prev_timestamp != kNoTimestamp() && prev_timestamp != next_timestamp) { |
| 982 // Clean up the old buffers between the last appended buffer and the | 983 // Clean up the old buffers between the last appended buffer and the |
| 983 // beginning of |new_buffers|. | 984 // beginning of |new_buffers|. |
| 984 RemoveInternal(prev_timestamp, next_timestamp, true, deleted_buffers); | 985 RemoveInternal(prev_timestamp, next_timestamp, true, deleted_buffers); |
| 985 } | 986 } |
| 986 | 987 |
| 987 // Make the delete range exclusive if we are dealing with an allowed same | 988 // Make the delete range exclusive if we are dealing with an allowed same |
| 988 // timestamp situation. This prevents the first buffer in the current append | 989 // timestamp situation. This prevents the first buffer in the current append |
| 989 // from deleting the last buffer in the previous append if both buffers | 990 // from deleting the last buffer in the previous append if both buffers |
| 990 // have the same timestamp. | 991 // have the same timestamp. |
| 991 bool is_exclusive = (prev_timestamp == next_timestamp) && | 992 // |
| 993 // The delete range should never be exclusive if a splice frame was generated |
| 994 // because we don't generate splice frames for same timestamp situations. |
| 995 DCHECK(new_buffers.front()->splice_timestamp() != |
| 996 new_buffers.front()->timestamp()); |
| 997 const bool is_exclusive = |
| 998 new_buffers.front()->get_splice_buffers().empty() && |
| 999 prev_timestamp == next_timestamp && |
| 992 AllowSameTimestamp(prev_is_keyframe, next_is_keyframe, GetType()); | 1000 AllowSameTimestamp(prev_is_keyframe, next_is_keyframe, GetType()); |
| 993 | 1001 |
| 994 // Delete the buffers that |new_buffers| overlaps. | 1002 // Delete the buffers that |new_buffers| overlaps. |
| 995 base::TimeDelta start = new_buffers.front()->GetDecodeTimestamp(); | 1003 base::TimeDelta start = new_buffers.front()->GetDecodeTimestamp(); |
| 996 base::TimeDelta end = new_buffers.back()->GetDecodeTimestamp(); | 1004 base::TimeDelta end = new_buffers.back()->GetDecodeTimestamp(); |
| 997 base::TimeDelta duration = new_buffers.back()->duration(); | 1005 base::TimeDelta duration = new_buffers.back()->duration(); |
| 998 | 1006 |
| 999 if (duration != kNoTimestamp() && duration > base::TimeDelta()) { | 1007 if (duration != kNoTimestamp() && duration > base::TimeDelta()) { |
| 1000 end += duration; | 1008 end += duration; |
| 1001 } else { | 1009 } else { |
| (...skipping 668 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1670 interbuffer_distance_cb_(interbuffer_distance_cb), | 1678 interbuffer_distance_cb_(interbuffer_distance_cb), |
| 1671 size_in_bytes_(0) { | 1679 size_in_bytes_(0) { |
| 1672 DCHECK(!new_buffers.empty()); | 1680 DCHECK(!new_buffers.empty()); |
| 1673 DCHECK(new_buffers.front()->IsKeyframe()); | 1681 DCHECK(new_buffers.front()->IsKeyframe()); |
| 1674 DCHECK(!interbuffer_distance_cb.is_null()); | 1682 DCHECK(!interbuffer_distance_cb.is_null()); |
| 1675 AppendBuffersToEnd(new_buffers); | 1683 AppendBuffersToEnd(new_buffers); |
| 1676 } | 1684 } |
| 1677 | 1685 |
| 1678 void SourceBufferRange::AppendBuffersToEnd(const BufferQueue& new_buffers) { | 1686 void SourceBufferRange::AppendBuffersToEnd(const BufferQueue& new_buffers) { |
| 1679 DCHECK(buffers_.empty() || CanAppendBuffersToEnd(new_buffers)); | 1687 DCHECK(buffers_.empty() || CanAppendBuffersToEnd(new_buffers)); |
| 1688 DCHECK(media_segment_start_time_ == kNoTimestamp() || |
| 1689 media_segment_start_time_ <= |
| 1690 new_buffers.front()->GetDecodeTimestamp()); |
| 1680 for (BufferQueue::const_iterator itr = new_buffers.begin(); | 1691 for (BufferQueue::const_iterator itr = new_buffers.begin(); |
| 1681 itr != new_buffers.end(); ++itr) { | 1692 itr != new_buffers.end(); |
| 1693 ++itr) { |
| 1682 DCHECK((*itr)->GetDecodeTimestamp() != kNoTimestamp()); | 1694 DCHECK((*itr)->GetDecodeTimestamp() != kNoTimestamp()); |
| 1683 buffers_.push_back(*itr); | 1695 buffers_.push_back(*itr); |
| 1684 size_in_bytes_ += (*itr)->data_size(); | 1696 size_in_bytes_ += (*itr)->data_size(); |
| 1685 | 1697 |
| 1686 if ((*itr)->IsKeyframe()) { | 1698 if ((*itr)->IsKeyframe()) { |
| 1687 keyframe_map_.insert( | 1699 keyframe_map_.insert( |
| 1688 std::make_pair((*itr)->GetDecodeTimestamp(), | 1700 std::make_pair((*itr)->GetDecodeTimestamp(), |
| 1689 buffers_.size() - 1 + keyframe_map_index_base_)); | 1701 buffers_.size() - 1 + keyframe_map_index_base_)); |
| 1690 } | 1702 } |
| 1691 } | 1703 } |
| (...skipping 488 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2180 if (buffer->end_of_stream() || buffer->timestamp() >= end) | 2192 if (buffer->end_of_stream() || buffer->timestamp() >= end) |
| 2181 break; | 2193 break; |
| 2182 if (buffer->timestamp() + buffer->duration() <= start) | 2194 if (buffer->timestamp() + buffer->duration() <= start) |
| 2183 continue; | 2195 continue; |
| 2184 buffers->push_back(buffer); | 2196 buffers->push_back(buffer); |
| 2185 } | 2197 } |
| 2186 return previous_size < buffers->size(); | 2198 return previous_size < buffers->size(); |
| 2187 } | 2199 } |
| 2188 | 2200 |
| 2189 } // namespace media | 2201 } // namespace media |
| OLD | NEW |