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

Side by Side Diff: media/blink/multibuffer_data_source.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/blink/multibuffer_data_source.h ('k') | media/blink/multibuffer_data_source_unittest.cc » ('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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/blink/multibuffer_data_source.h" 5 #include "media/blink/multibuffer_data_source.h"
6 6
7 #include <utility> 7 #include <utility>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/callback_helpers.h" 10 #include "base/callback_helpers.h"
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 if (cors_mode_ == UrlData::CORS_UNSPECIFIED) 257 if (cors_mode_ == UrlData::CORS_UNSPECIFIED)
258 return false; 258 return false;
259 // If init_cb is set, we initialization is not finished yet. 259 // If init_cb is set, we initialization is not finished yet.
260 if (!init_cb_.is_null()) 260 if (!init_cb_.is_null())
261 return false; 261 return false;
262 if (failed_) 262 if (failed_)
263 return false; 263 return false;
264 return true; 264 return true;
265 } 265 }
266 266
267 void MultibufferDataSource::Abort() {
268 DCHECK(render_task_runner_->BelongsToCurrentThread());
269 {
270 base::AutoLock auto_lock(lock_);
271 StopInternal_Locked();
272 }
273 StopLoader();
274 frame_ = NULL;
275 }
276
277 void MultibufferDataSource::MediaPlaybackRateChanged(double playback_rate) { 267 void MultibufferDataSource::MediaPlaybackRateChanged(double playback_rate) {
278 DCHECK(render_task_runner_->BelongsToCurrentThread()); 268 DCHECK(render_task_runner_->BelongsToCurrentThread());
279 DCHECK(reader_.get()); 269 DCHECK(reader_.get());
280 270
281 if (playback_rate < 0.0) 271 if (playback_rate < 0.0)
282 return; 272 return;
283 273
284 playback_rate_ = playback_rate; 274 playback_rate_ = playback_rate;
285 cancel_on_defer_ = false; 275 cancel_on_defer_ = false;
286 UpdateBufferSizes(); 276 UpdateBufferSizes();
(...skipping 14 matching lines...) Expand all
301 { 291 {
302 base::AutoLock auto_lock(lock_); 292 base::AutoLock auto_lock(lock_);
303 StopInternal_Locked(); 293 StopInternal_Locked();
304 } 294 }
305 295
306 render_task_runner_->PostTask(FROM_HERE, 296 render_task_runner_->PostTask(FROM_HERE,
307 base::Bind(&MultibufferDataSource::StopLoader, 297 base::Bind(&MultibufferDataSource::StopLoader,
308 weak_factory_.GetWeakPtr())); 298 weak_factory_.GetWeakPtr()));
309 } 299 }
310 300
301 void MultibufferDataSource::Abort() {
302 base::AutoLock auto_lock(lock_);
303 DCHECK(init_cb_.is_null());
304 if (read_op_)
305 ReadOperation::Run(std::move(read_op_), kAborted);
306
307 // Abort does not call StopLoader() since it is typically called prior to a
308 // seek or suspend. Let the loader logic make the decision about whether a new
309 // loader is necessary upon the seek or resume.
310 }
311
311 void MultibufferDataSource::SetBitrate(int bitrate) { 312 void MultibufferDataSource::SetBitrate(int bitrate) {
312 render_task_runner_->PostTask( 313 render_task_runner_->PostTask(
313 FROM_HERE, base::Bind(&MultibufferDataSource::SetBitrateTask, 314 FROM_HERE, base::Bind(&MultibufferDataSource::SetBitrateTask,
314 weak_factory_.GetWeakPtr(), bitrate)); 315 weak_factory_.GetWeakPtr(), bitrate));
315 } 316 }
316 317
317 void MultibufferDataSource::OnBufferingHaveEnough(bool always_cancel) { 318 void MultibufferDataSource::OnBufferingHaveEnough(bool always_cancel) {
318 DCHECK(render_task_runner_->BelongsToCurrentThread()); 319 DCHECK(render_task_runner_->BelongsToCurrentThread());
319 if (reader_ && (always_cancel || (preload_ == METADATA && 320 if (reader_ && (always_cancel || (preload_ == METADATA &&
320 !media_has_played_ && !IsStreaming()))) { 321 !media_has_played_ && !IsStreaming()))) {
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 return streaming_; 375 return streaming_;
375 } 376 }
376 377
377 ///////////////////////////////////////////////////////////////////////////// 378 /////////////////////////////////////////////////////////////////////////////
378 // This method is the place where actual read happens, 379 // This method is the place where actual read happens,
379 void MultibufferDataSource::ReadTask() { 380 void MultibufferDataSource::ReadTask() {
380 DCHECK(render_task_runner_->BelongsToCurrentThread()); 381 DCHECK(render_task_runner_->BelongsToCurrentThread());
381 382
382 base::AutoLock auto_lock(lock_); 383 base::AutoLock auto_lock(lock_);
383 int bytes_read = 0; 384 int bytes_read = 0;
384 if (stop_signal_received_) 385 if (stop_signal_received_ || !read_op_)
385 return; 386 return;
386 DCHECK(read_op_);
387 DCHECK(read_op_->size()); 387 DCHECK(read_op_->size());
388 388
389 if (!reader_) { 389 if (!reader_) {
390 CreateResourceLoader(read_op_->position(), kPositionNotSpecified); 390 CreateResourceLoader(read_op_->position(), kPositionNotSpecified);
391 } else { 391 } else {
392 reader_->Seek(read_op_->position()); 392 reader_->Seek(read_op_->position());
393 } 393 }
394 394
395 int64_t available = reader_->Available(); 395 int64_t available = reader_->Available();
396 if (available < 0) { 396 if (available < 0) {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra); 597 reader_->SetPinRange(back_buffer, kMaxBufferPreload + kPreloadHighExtra);
598 598
599 if (preload_ == METADATA) { 599 if (preload_ == METADATA) {
600 reader_->SetPreload(0, 0); 600 reader_->SetPreload(0, 0);
601 } else { 601 } else {
602 reader_->SetPreload(preload_high, preload); 602 reader_->SetPreload(preload_high, preload);
603 } 603 }
604 } 604 }
605 605
606 } // namespace media 606 } // namespace media
OLDNEW
« no previous file with comments | « media/blink/multibuffer_data_source.h ('k') | media/blink/multibuffer_data_source_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698