Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: media/filters/chunk_demuxer.cc

Issue 1171263004: Allow setting memory limits on media::DemuxerStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Include logging.h for NOTIMPLEMENTED definition Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 // Helper methods that call methods with similar names on all the 156 // Helper methods that call methods with similar names on all the
157 // ChunkDemuxerStreams managed by this object. 157 // ChunkDemuxerStreams managed by this object.
158 void StartReturningData(); 158 void StartReturningData();
159 void AbortReads(); 159 void AbortReads();
160 void Seek(TimeDelta seek_time); 160 void Seek(TimeDelta seek_time);
161 void CompletePendingReadIfPossible(); 161 void CompletePendingReadIfPossible();
162 void OnSetDuration(TimeDelta duration); 162 void OnSetDuration(TimeDelta duration);
163 void MarkEndOfStream(); 163 void MarkEndOfStream();
164 void UnmarkEndOfStream(); 164 void UnmarkEndOfStream();
165 void Shutdown(); 165 void Shutdown();
166 // Sets the memory limit on each stream of a specific type.
167 // |memory_limit| is the maximum number of bytes each stream of type |type|
168 // is allowed to hold in its buffer.
169 void SetMemoryLimits(DemuxerStream::Type type, int memory_limit);
170 bool IsSeekWaitingForData() const; 166 bool IsSeekWaitingForData() const;
171 167
172 private: 168 private:
173 // Called by the |stream_parser_| when a new initialization segment is 169 // Called by the |stream_parser_| when a new initialization segment is
174 // encountered. 170 // encountered.
175 // Returns true on a successful call. Returns false if an error occurred while 171 // Returns true on a successful call. Returns false if an error occurred while
176 // processing decoder configurations. 172 // processing decoder configurations.
177 bool OnNewConfigs(bool allow_audio, bool allow_video, 173 bool OnNewConfigs(bool allow_audio, bool allow_video,
178 const AudioDecoderConfig& audio_config, 174 const AudioDecoderConfig& audio_config,
179 const VideoDecoderConfig& video_config, 175 const VideoDecoderConfig& video_config,
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 503
508 if (video_) 504 if (video_)
509 video_->Shutdown(); 505 video_->Shutdown();
510 506
511 for (TextStreamMap::iterator itr = text_stream_map_.begin(); 507 for (TextStreamMap::iterator itr = text_stream_map_.begin();
512 itr != text_stream_map_.end(); ++itr) { 508 itr != text_stream_map_.end(); ++itr) {
513 itr->second->Shutdown(); 509 itr->second->Shutdown();
514 } 510 }
515 } 511 }
516 512
517 void SourceState::SetMemoryLimits(DemuxerStream::Type type, int memory_limit) {
518 switch (type) {
519 case DemuxerStream::AUDIO:
520 if (audio_)
521 audio_->set_memory_limit(memory_limit);
522 break;
523 case DemuxerStream::VIDEO:
524 if (video_)
525 video_->set_memory_limit(memory_limit);
526 break;
527 case DemuxerStream::TEXT:
528 for (TextStreamMap::iterator itr = text_stream_map_.begin();
529 itr != text_stream_map_.end(); ++itr) {
530 itr->second->set_memory_limit(memory_limit);
531 }
532 break;
533 case DemuxerStream::UNKNOWN:
534 case DemuxerStream::NUM_TYPES:
535 NOTREACHED();
536 break;
537 }
538 }
539
540 bool SourceState::IsSeekWaitingForData() const { 513 bool SourceState::IsSeekWaitingForData() const {
541 if (audio_ && audio_->IsSeekWaitingForData()) 514 if (audio_ && audio_->IsSeekWaitingForData())
542 return true; 515 return true;
543 516
544 if (video_ && video_->IsSeekWaitingForData()) 517 if (video_ && video_->IsSeekWaitingForData())
545 return true; 518 return true;
546 519
547 // NOTE: We are intentionally not checking the text tracks 520 // NOTE: We are intentionally not checking the text tracks
548 // because text tracks are discontinuous and may not have data 521 // because text tracks are discontinuous and may not have data
549 // for the seek position. This is ok and playback should not be 522 // for the seek position. This is ok and playback should not be
(...skipping 463 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 base::AutoLock auto_lock(lock_); 986 base::AutoLock auto_lock(lock_);
1014 return stream_->GetCurrentVideoDecoderConfig(); 987 return stream_->GetCurrentVideoDecoderConfig();
1015 } 988 }
1016 989
1017 bool ChunkDemuxerStream::SupportsConfigChanges() { return true; } 990 bool ChunkDemuxerStream::SupportsConfigChanges() { return true; }
1018 991
1019 VideoRotation ChunkDemuxerStream::video_rotation() { 992 VideoRotation ChunkDemuxerStream::video_rotation() {
1020 return VIDEO_ROTATION_0; 993 return VIDEO_ROTATION_0;
1021 } 994 }
1022 995
996 int ChunkDemuxerStream::GetMemoryLimit() const {
997 return stream_->GetMemoryLimit();
998 }
999
1000 void ChunkDemuxerStream::SetMemoryLimit(int memory_limit) {
1001 stream_->SetMemoryLimit(memory_limit);
1002 }
1003
1023 TextTrackConfig ChunkDemuxerStream::text_track_config() { 1004 TextTrackConfig ChunkDemuxerStream::text_track_config() {
1024 CHECK_EQ(type_, TEXT); 1005 CHECK_EQ(type_, TEXT);
1025 base::AutoLock auto_lock(lock_); 1006 base::AutoLock auto_lock(lock_);
1026 return stream_->GetCurrentTextTrackConfig(); 1007 return stream_->GetCurrentTextTrackConfig();
1027 } 1008 }
1028 1009
1029 void ChunkDemuxerStream::SetLiveness(Liveness liveness) { 1010 void ChunkDemuxerStream::SetLiveness(Liveness liveness) {
1030 base::AutoLock auto_lock(lock_); 1011 base::AutoLock auto_lock(lock_);
1031 liveness_ = liveness; 1012 liveness_ = liveness;
1032 } 1013 }
(...skipping 544 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 return; 1558 return;
1578 1559
1579 ShutdownAllStreams(); 1560 ShutdownAllStreams();
1580 1561
1581 ChangeState_Locked(SHUTDOWN); 1562 ChangeState_Locked(SHUTDOWN);
1582 1563
1583 if(!seek_cb_.is_null()) 1564 if(!seek_cb_.is_null())
1584 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_ERROR_ABORT); 1565 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_ERROR_ABORT);
1585 } 1566 }
1586 1567
1587 void ChunkDemuxer::SetMemoryLimits(DemuxerStream::Type type, int memory_limit) {
1588 for (SourceStateMap::iterator itr = source_state_map_.begin();
1589 itr != source_state_map_.end(); ++itr) {
1590 itr->second->SetMemoryLimits(type, memory_limit);
1591 }
1592 }
1593
1594 void ChunkDemuxer::ChangeState_Locked(State new_state) { 1568 void ChunkDemuxer::ChangeState_Locked(State new_state) {
1595 lock_.AssertAcquired(); 1569 lock_.AssertAcquired();
1596 DVLOG(1) << "ChunkDemuxer::ChangeState_Locked() : " 1570 DVLOG(1) << "ChunkDemuxer::ChangeState_Locked() : "
1597 << state_ << " -> " << new_state; 1571 << state_ << " -> " << new_state;
1598 state_ = new_state; 1572 state_ = new_state;
1599 } 1573 }
1600 1574
1601 ChunkDemuxer::~ChunkDemuxer() { 1575 ChunkDemuxer::~ChunkDemuxer() {
1602 DCHECK_NE(state_, INITIALIZED); 1576 DCHECK_NE(state_, INITIALIZED);
1603 1577
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 } 1802 }
1829 1803
1830 void ChunkDemuxer::ShutdownAllStreams() { 1804 void ChunkDemuxer::ShutdownAllStreams() {
1831 for (SourceStateMap::iterator itr = source_state_map_.begin(); 1805 for (SourceStateMap::iterator itr = source_state_map_.begin();
1832 itr != source_state_map_.end(); ++itr) { 1806 itr != source_state_map_.end(); ++itr) {
1833 itr->second->Shutdown(); 1807 itr->second->Shutdown();
1834 } 1808 }
1835 } 1809 }
1836 1810
1837 } // namespace media 1811 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698