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 #include <sstream> | 9 #include <sstream> |
10 | 10 |
(...skipping 588 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 | 599 |
600 void SourceBufferStream::SetConfigIds(const BufferQueue& buffers) { | 600 void SourceBufferStream::SetConfigIds(const BufferQueue& buffers) { |
601 for (BufferQueue::const_iterator itr = buffers.begin(); | 601 for (BufferQueue::const_iterator itr = buffers.begin(); |
602 itr != buffers.end(); ++itr) { | 602 itr != buffers.end(); ++itr) { |
603 (*itr)->SetConfigId(append_config_index_); | 603 (*itr)->SetConfigId(append_config_index_); |
604 } | 604 } |
605 } | 605 } |
606 | 606 |
607 void SourceBufferStream::GarbageCollectIfNeeded() { | 607 void SourceBufferStream::GarbageCollectIfNeeded() { |
608 // Compute size of |ranges_|. | 608 // Compute size of |ranges_|. |
609 int ranges_size = 0; | 609 size_t ranges_size = 0; |
610 for (RangeList::iterator itr = ranges_.begin(); itr != ranges_.end(); ++itr) | 610 for (RangeList::iterator itr = ranges_.begin(); itr != ranges_.end(); ++itr) |
611 ranges_size += (*itr)->size_in_bytes(); | 611 ranges_size += (*itr)->size_in_bytes(); |
wolenetz
2015/07/17 20:23:53
SourceBufferRange::size_in_bytes() returns int. Co
servolk
2015/07/17 21:34:07
Done.
| |
612 | 612 |
613 // Return if we're under or at the memory limit. | 613 // Return if we're under or at the memory limit. |
614 if (ranges_size <= memory_limit_) | 614 if (ranges_size <= memory_limit_) |
615 return; | 615 return; |
616 | 616 |
617 int bytes_to_free = ranges_size - memory_limit_; | 617 size_t bytes_to_free = ranges_size - memory_limit_; |
618 | 618 |
619 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() << ": Before GC" | 619 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() << ": Before GC" |
620 << " ranges_size=" << ranges_size | 620 << " ranges_size=" << ranges_size |
621 << " ranges_=" << RangesToString(ranges_) | 621 << " ranges_=" << RangesToString(ranges_) |
622 << " memory_limit_=" << memory_limit_; | 622 << " memory_limit_=" << memory_limit_; |
623 | 623 |
624 // Begin deleting after the last appended buffer. | 624 // Begin deleting after the last appended buffer. |
625 int bytes_freed = FreeBuffersAfterLastAppended(bytes_to_free); | 625 size_t bytes_freed = FreeBuffersAfterLastAppended(bytes_to_free); |
626 | 626 |
627 // Begin deleting from the front. | 627 // Begin deleting from the front. |
628 if (bytes_to_free - bytes_freed > 0) | 628 if (bytes_freed < bytes_to_free) |
629 bytes_freed += FreeBuffers(bytes_to_free - bytes_freed, false); | 629 bytes_freed += FreeBuffers(bytes_to_free - bytes_freed, false); |
630 | 630 |
631 // Begin deleting from the back. | 631 // Begin deleting from the back. |
632 if (bytes_to_free - bytes_freed > 0) | 632 if (bytes_freed < bytes_to_free) |
633 bytes_freed += FreeBuffers(bytes_to_free - bytes_freed, true); | 633 bytes_freed += FreeBuffers(bytes_to_free - bytes_freed, true); |
634 | 634 |
635 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() << ": After GC" | 635 DVLOG(2) << __FUNCTION__ << " " << GetStreamTypeName() << ": After GC" |
636 << " bytes_freed=" << bytes_freed | 636 << " bytes_freed=" << bytes_freed |
637 << " ranges_=" << RangesToString(ranges_); | 637 << " ranges_=" << RangesToString(ranges_); |
638 } | 638 } |
639 | 639 |
640 int SourceBufferStream::FreeBuffersAfterLastAppended(int total_bytes_to_free) { | 640 int SourceBufferStream::FreeBuffersAfterLastAppended(int total_bytes_to_free) { |
wolenetz
2015/07/17 20:23:53
ditto: size_t (param, retval, and internals)
servolk
2015/07/17 21:34:06
Done.
| |
641 DecodeTimestamp next_buffer_timestamp = GetNextBufferTimestamp(); | 641 DecodeTimestamp next_buffer_timestamp = GetNextBufferTimestamp(); |
642 if (last_appended_buffer_timestamp_ == kNoDecodeTimestamp() || | 642 if (last_appended_buffer_timestamp_ == kNoDecodeTimestamp() || |
643 next_buffer_timestamp == kNoDecodeTimestamp() || | 643 next_buffer_timestamp == kNoDecodeTimestamp() || |
644 last_appended_buffer_timestamp_ >= next_buffer_timestamp) { | 644 last_appended_buffer_timestamp_ >= next_buffer_timestamp) { |
645 return 0; | 645 return 0; |
646 } | 646 } |
647 | 647 |
648 DecodeTimestamp remove_range_start = last_appended_buffer_timestamp_; | 648 DecodeTimestamp remove_range_start = last_appended_buffer_timestamp_; |
649 if (last_appended_buffer_is_keyframe_) | 649 if (last_appended_buffer_is_keyframe_) |
650 remove_range_start += GetMaxInterbufferDistance(); | 650 remove_range_start += GetMaxInterbufferDistance(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
689 continue; | 689 continue; |
690 | 690 |
691 int bytes_removed = range->GetRemovalGOP( | 691 int bytes_removed = range->GetRemovalGOP( |
692 start_timestamp, end_timestamp, bytes_to_free, removal_end_timestamp); | 692 start_timestamp, end_timestamp, bytes_to_free, removal_end_timestamp); |
693 bytes_to_free -= bytes_removed; | 693 bytes_to_free -= bytes_removed; |
694 bytes_freed += bytes_removed; | 694 bytes_freed += bytes_removed; |
695 } | 695 } |
696 return bytes_freed; | 696 return bytes_freed; |
697 } | 697 } |
698 | 698 |
699 int SourceBufferStream::FreeBuffers(int total_bytes_to_free, | 699 int SourceBufferStream::FreeBuffers(int total_bytes_to_free, |
wolenetz
2015/07/17 20:23:53
ditto
servolk
2015/07/17 21:34:06
Done.
| |
700 bool reverse_direction) { | 700 bool reverse_direction) { |
701 TRACE_EVENT2("media", "SourceBufferStream::FreeBuffers", | 701 TRACE_EVENT2("media", "SourceBufferStream::FreeBuffers", |
702 "total bytes to free", total_bytes_to_free, | 702 "total bytes to free", total_bytes_to_free, |
703 "reverse direction", reverse_direction); | 703 "reverse direction", reverse_direction); |
704 | 704 |
705 DCHECK_GT(total_bytes_to_free, 0); | 705 DCHECK_GT(total_bytes_to_free, 0); |
706 int bytes_to_free = total_bytes_to_free; | 706 int bytes_to_free = total_bytes_to_free; |
707 int bytes_freed = 0; | 707 int bytes_freed = 0; |
708 | 708 |
709 // This range will save the last GOP appended to |range_for_next_append_| | 709 // This range will save the last GOP appended to |range_for_next_append_| |
(...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1253 const TextTrackConfig& SourceBufferStream::GetCurrentTextTrackConfig() { | 1253 const TextTrackConfig& SourceBufferStream::GetCurrentTextTrackConfig() { |
1254 return text_track_config_; | 1254 return text_track_config_; |
1255 } | 1255 } |
1256 | 1256 |
1257 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { | 1257 base::TimeDelta SourceBufferStream::GetMaxInterbufferDistance() const { |
1258 if (max_interbuffer_distance_ == kNoTimestamp()) | 1258 if (max_interbuffer_distance_ == kNoTimestamp()) |
1259 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs); | 1259 return base::TimeDelta::FromMilliseconds(kDefaultBufferDurationInMs); |
1260 return max_interbuffer_distance_; | 1260 return max_interbuffer_distance_; |
1261 } | 1261 } |
1262 | 1262 |
1263 void SourceBufferStream::SetMemoryLimit(size_t memory_limit) { | |
1264 memory_limit_ = memory_limit; | |
1265 } | |
1266 | |
1263 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) { | 1267 bool SourceBufferStream::UpdateAudioConfig(const AudioDecoderConfig& config) { |
1264 DCHECK(!audio_configs_.empty()); | 1268 DCHECK(!audio_configs_.empty()); |
1265 DCHECK(video_configs_.empty()); | 1269 DCHECK(video_configs_.empty()); |
1266 DVLOG(3) << "UpdateAudioConfig."; | 1270 DVLOG(3) << "UpdateAudioConfig."; |
1267 | 1271 |
1268 if (audio_configs_[0].codec() != config.codec()) { | 1272 if (audio_configs_[0].codec() != config.codec()) { |
1269 MEDIA_LOG(ERROR, log_cb_) << "Audio codec changes not allowed."; | 1273 MEDIA_LOG(ERROR, log_cb_) << "Audio codec changes not allowed."; |
1270 return false; | 1274 return false; |
1271 } | 1275 } |
1272 | 1276 |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1600 return false; | 1604 return false; |
1601 | 1605 |
1602 DCHECK_NE(have_splice_buffers, have_preroll_buffer); | 1606 DCHECK_NE(have_splice_buffers, have_preroll_buffer); |
1603 splice_buffers_index_ = 0; | 1607 splice_buffers_index_ = 0; |
1604 pending_buffer_.swap(*out_buffer); | 1608 pending_buffer_.swap(*out_buffer); |
1605 pending_buffers_complete_ = false; | 1609 pending_buffers_complete_ = false; |
1606 return true; | 1610 return true; |
1607 } | 1611 } |
1608 | 1612 |
1609 } // namespace media | 1613 } // namespace media |
OLD | NEW |