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

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

Issue 2267963002: Add support for cancellation of demuxer reads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix and add tests. Created 4 years, 3 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
« no previous file with comments | « media/filters/chunk_demuxer.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include <utility> 10 #include <utility>
(...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 TimeDelta ChunkDemuxer::GetStartTime() const { 503 TimeDelta ChunkDemuxer::GetStartTime() const {
504 return TimeDelta(); 504 return TimeDelta();
505 } 505 }
506 506
507 int64_t ChunkDemuxer::GetMemoryUsage() const { 507 int64_t ChunkDemuxer::GetMemoryUsage() const {
508 base::AutoLock auto_lock(lock_); 508 base::AutoLock auto_lock(lock_);
509 return (audio_ ? audio_->GetBufferedSize() : 0) + 509 return (audio_ ? audio_->GetBufferedSize() : 0) +
510 (video_ ? video_->GetBufferedSize() : 0); 510 (video_ ? video_->GetBufferedSize() : 0);
511 } 511 }
512 512
513 void ChunkDemuxer::AbortPendingReads() {
514 base::AutoLock auto_lock(lock_);
515 DCHECK(state_ == INITIALIZED || state_ == ENDED || state_ == SHUTDOWN ||
516 state_ == PARSE_ERROR)
517 << state_;
518
519 if (state_ == SHUTDOWN || state_ == PARSE_ERROR)
520 return;
521
522 AbortPendingReads_Locked();
523 }
524
513 void ChunkDemuxer::StartWaitingForSeek(TimeDelta seek_time) { 525 void ChunkDemuxer::StartWaitingForSeek(TimeDelta seek_time) {
514 DVLOG(1) << "StartWaitingForSeek()"; 526 DVLOG(1) << "StartWaitingForSeek()";
515 base::AutoLock auto_lock(lock_); 527 base::AutoLock auto_lock(lock_);
516 DCHECK(state_ == INITIALIZED || state_ == ENDED || state_ == SHUTDOWN || 528 DCHECK(state_ == INITIALIZED || state_ == ENDED || state_ == SHUTDOWN ||
517 state_ == PARSE_ERROR) << state_; 529 state_ == PARSE_ERROR) << state_;
518 DCHECK(seek_cb_.is_null()); 530 DCHECK(seek_cb_.is_null());
519 531
520 if (state_ == SHUTDOWN || state_ == PARSE_ERROR) 532 if (state_ == SHUTDOWN || state_ == PARSE_ERROR)
521 return; 533 return;
522 534
523 AbortPendingReads(); 535 AbortPendingReads_Locked();
524 SeekAllSources(seek_time); 536 SeekAllSources(seek_time);
525 537
526 // Cancel state set in CancelPendingSeek() since we want to 538 // Cancel state set in CancelPendingSeek() since we want to
527 // accept the next Seek(). 539 // accept the next Seek().
528 cancel_next_seek_ = false; 540 cancel_next_seek_ = false;
529 } 541 }
530 542
531 void ChunkDemuxer::CancelPendingSeek(TimeDelta seek_time) { 543 void ChunkDemuxer::CancelPendingSeek(TimeDelta seek_time) {
532 base::AutoLock auto_lock(lock_); 544 base::AutoLock auto_lock(lock_);
533 DCHECK_NE(state_, INITIALIZING); 545 DCHECK_NE(state_, INITIALIZING);
534 DCHECK(seek_cb_.is_null() || IsSeekWaitingForData_Locked()); 546 DCHECK(seek_cb_.is_null() || IsSeekWaitingForData_Locked());
535 547
536 if (cancel_next_seek_) 548 if (cancel_next_seek_)
537 return; 549 return;
538 550
539 AbortPendingReads(); 551 AbortPendingReads_Locked();
540 SeekAllSources(seek_time); 552 SeekAllSources(seek_time);
541 553
542 if (seek_cb_.is_null()) { 554 if (seek_cb_.is_null()) {
543 cancel_next_seek_ = true; 555 cancel_next_seek_ = true;
544 return; 556 return;
545 } 557 }
546 558
547 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK); 559 base::ResetAndReturn(&seek_cb_).Run(PIPELINE_OK);
548 } 560 }
549 561
(...skipping 681 matching lines...) Expand 10 before | Expand all | Expand 10 after
1231 return MediaSourceState::ComputeRangesIntersection(ranges_list, ended); 1243 return MediaSourceState::ComputeRangesIntersection(ranges_list, ended);
1232 } 1244 }
1233 1245
1234 void ChunkDemuxer::StartReturningData() { 1246 void ChunkDemuxer::StartReturningData() {
1235 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1247 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1236 itr != source_state_map_.end(); ++itr) { 1248 itr != source_state_map_.end(); ++itr) {
1237 itr->second->StartReturningData(); 1249 itr->second->StartReturningData();
1238 } 1250 }
1239 } 1251 }
1240 1252
1241 void ChunkDemuxer::AbortPendingReads() { 1253 void ChunkDemuxer::AbortPendingReads_Locked() {
1242 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1254 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1243 itr != source_state_map_.end(); ++itr) { 1255 itr != source_state_map_.end(); ++itr) {
1244 itr->second->AbortReads(); 1256 itr->second->AbortReads();
1245 } 1257 }
1246 } 1258 }
1247 1259
1248 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) { 1260 void ChunkDemuxer::SeekAllSources(TimeDelta seek_time) {
1249 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1261 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1250 itr != source_state_map_.end(); ++itr) { 1262 itr != source_state_map_.end(); ++itr) {
1251 itr->second->Seek(seek_time); 1263 itr->second->Seek(seek_time);
1252 } 1264 }
1253 } 1265 }
1254 1266
1255 void ChunkDemuxer::CompletePendingReadsIfPossible() { 1267 void ChunkDemuxer::CompletePendingReadsIfPossible() {
1256 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1268 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1257 itr != source_state_map_.end(); ++itr) { 1269 itr != source_state_map_.end(); ++itr) {
1258 itr->second->CompletePendingReadIfPossible(); 1270 itr->second->CompletePendingReadIfPossible();
1259 } 1271 }
1260 } 1272 }
1261 1273
1262 void ChunkDemuxer::ShutdownAllStreams() { 1274 void ChunkDemuxer::ShutdownAllStreams() {
1263 for (MediaSourceStateMap::iterator itr = source_state_map_.begin(); 1275 for (MediaSourceStateMap::iterator itr = source_state_map_.begin();
1264 itr != source_state_map_.end(); ++itr) { 1276 itr != source_state_map_.end(); ++itr) {
1265 itr->second->Shutdown(); 1277 itr->second->Shutdown();
1266 } 1278 }
1267 } 1279 }
1268 1280
1269 } // namespace media 1281 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/chunk_demuxer.h ('k') | media/filters/ffmpeg_demuxer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698