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/chunk_demuxer.h" | 5 #include "media/filters/chunk_demuxer.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <list> | 9 #include <list> |
10 | 10 |
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 // Helper methods that call methods with similar names on all the | 149 // Helper methods that call methods with similar names on all the |
150 // ChunkDemuxerStreams managed by this object. | 150 // ChunkDemuxerStreams managed by this object. |
151 void StartReturningData(); | 151 void StartReturningData(); |
152 void AbortReads(); | 152 void AbortReads(); |
153 void Seek(TimeDelta seek_time); | 153 void Seek(TimeDelta seek_time); |
154 void CompletePendingReadIfPossible(); | 154 void CompletePendingReadIfPossible(); |
155 void OnSetDuration(TimeDelta duration); | 155 void OnSetDuration(TimeDelta duration); |
156 void MarkEndOfStream(); | 156 void MarkEndOfStream(); |
157 void UnmarkEndOfStream(); | 157 void UnmarkEndOfStream(); |
158 void Shutdown(); | 158 void Shutdown(); |
159 // Sets the memory limit on each stream. |memory_limit| is the | 159 // Sets the memory limit on each stream of a specific type. |
160 // maximum number of bytes each stream is allowed to hold in its buffer. | 160 // |memory_limit| is the maximum number of bytes each stream of type |type| |
161 void SetMemoryLimitsForTesting(int memory_limit); | 161 // is allowed to hold in its buffer. |
| 162 void SetMemoryLimits(DemuxerStream::Type type, int memory_limit); |
162 bool IsSeekWaitingForData() const; | 163 bool IsSeekWaitingForData() const; |
163 | 164 |
164 private: | 165 private: |
165 // Called by the |stream_parser_| when a new initialization segment is | 166 // Called by the |stream_parser_| when a new initialization segment is |
166 // encountered. | 167 // encountered. |
167 // Returns true on a successful call. Returns false if an error occurred while | 168 // Returns true on a successful call. Returns false if an error occurred while |
168 // processing decoder configurations. | 169 // processing decoder configurations. |
169 bool OnNewConfigs(bool allow_audio, bool allow_video, | 170 bool OnNewConfigs(bool allow_audio, bool allow_video, |
170 const AudioDecoderConfig& audio_config, | 171 const AudioDecoderConfig& audio_config, |
171 const VideoDecoderConfig& video_config, | 172 const VideoDecoderConfig& video_config, |
(...skipping 306 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 479 |
479 if (video_) | 480 if (video_) |
480 video_->Shutdown(); | 481 video_->Shutdown(); |
481 | 482 |
482 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | 483 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
483 itr != text_stream_map_.end(); ++itr) { | 484 itr != text_stream_map_.end(); ++itr) { |
484 itr->second->Shutdown(); | 485 itr->second->Shutdown(); |
485 } | 486 } |
486 } | 487 } |
487 | 488 |
488 void SourceState::SetMemoryLimitsForTesting(int memory_limit) { | 489 void SourceState::SetMemoryLimits(DemuxerStream::Type type, int memory_limit) { |
489 if (audio_) | 490 switch (type) { |
490 audio_->set_memory_limit_for_testing(memory_limit); | 491 case DemuxerStream::AUDIO: |
491 | 492 if (audio_) |
492 if (video_) | 493 audio_->set_memory_limit(memory_limit); |
493 video_->set_memory_limit_for_testing(memory_limit); | 494 break; |
494 | 495 case DemuxerStream::VIDEO: |
495 for (TextStreamMap::iterator itr = text_stream_map_.begin(); | 496 if (video_) |
496 itr != text_stream_map_.end(); ++itr) { | 497 video_->set_memory_limit(memory_limit); |
497 itr->second->set_memory_limit_for_testing(memory_limit); | 498 break; |
| 499 case DemuxerStream::TEXT: |
| 500 for (TextStreamMap::iterator itr = text_stream_map_.begin(); |
| 501 itr != text_stream_map_.end(); ++itr) { |
| 502 itr->second->set_memory_limit(memory_limit); |
| 503 } |
| 504 break; |
| 505 case DemuxerStream::UNKNOWN: |
| 506 case DemuxerStream::NUM_TYPES: |
| 507 NOTREACHED(); |
| 508 break; |
498 } | 509 } |
499 } | 510 } |
500 | 511 |
501 bool SourceState::IsSeekWaitingForData() const { | 512 bool SourceState::IsSeekWaitingForData() const { |
502 if (audio_ && audio_->IsSeekWaitingForData()) | 513 if (audio_ && audio_->IsSeekWaitingForData()) |
503 return true; | 514 return true; |
504 | 515 |
505 if (video_ && video_->IsSeekWaitingForData()) | 516 if (video_ && video_->IsSeekWaitingForData()) |
506 return true; | 517 return true; |
507 | 518 |
(...skipping 985 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1493 return; | 1504 return; |
1494 | 1505 |
1495 ShutdownAllStreams(); | 1506 ShutdownAllStreams(); |
1496 | 1507 |
1497 ChangeState_Locked(SHUTDOWN); | 1508 ChangeState_Locked(SHUTDOWN); |
1498 | 1509 |
1499 if(!seek_cb_.is_null()) | 1510 if(!seek_cb_.is_null()) |
1500 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_ERROR_ABORT); | 1511 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_ERROR_ABORT); |
1501 } | 1512 } |
1502 | 1513 |
1503 void ChunkDemuxer::SetMemoryLimitsForTesting(int memory_limit) { | 1514 void ChunkDemuxer::SetMemoryLimits(DemuxerStream::Type type, int memory_limit) { |
1504 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1515 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
1505 itr != source_state_map_.end(); ++itr) { | 1516 itr != source_state_map_.end(); ++itr) { |
1506 itr->second->SetMemoryLimitsForTesting(memory_limit); | 1517 itr->second->SetMemoryLimits(type, memory_limit); |
1507 } | 1518 } |
1508 } | 1519 } |
1509 | 1520 |
1510 void ChunkDemuxer::ChangeState_Locked(State new_state) { | 1521 void ChunkDemuxer::ChangeState_Locked(State new_state) { |
1511 lock_.AssertAcquired(); | 1522 lock_.AssertAcquired(); |
1512 DVLOG(1) << "ChunkDemuxer::ChangeState_Locked() : " | 1523 DVLOG(1) << "ChunkDemuxer::ChangeState_Locked() : " |
1513 << state_ << " -> " << new_state; | 1524 << state_ << " -> " << new_state; |
1514 state_ = new_state; | 1525 state_ = new_state; |
1515 } | 1526 } |
1516 | 1527 |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1750 } | 1761 } |
1751 | 1762 |
1752 void ChunkDemuxer::ShutdownAllStreams() { | 1763 void ChunkDemuxer::ShutdownAllStreams() { |
1753 for (SourceStateMap::iterator itr = source_state_map_.begin(); | 1764 for (SourceStateMap::iterator itr = source_state_map_.begin(); |
1754 itr != source_state_map_.end(); ++itr) { | 1765 itr != source_state_map_.end(); ++itr) { |
1755 itr->second->Shutdown(); | 1766 itr->second->Shutdown(); |
1756 } | 1767 } |
1757 } | 1768 } |
1758 | 1769 |
1759 } // namespace media | 1770 } // namespace media |
OLD | NEW |