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

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

Issue 2267963002: Add support for cancellation of demuxer reads. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Switch to using aborted status. Created 4 years, 4 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/ffmpeg_demuxer.h" 5 #include "media/filters/ffmpeg_demuxer.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
585 // Reset bitstream for converter to do so. 585 // Reset bitstream for converter to do so.
586 // This is related to chromium issue 140371 (http://crbug.com/140371). 586 // This is related to chromium issue 140371 (http://crbug.com/140371).
587 ResetBitstreamConverter(); 587 ResetBitstreamConverter();
588 588
589 buffer_queue_.Clear(); 589 buffer_queue_.Clear();
590 end_of_stream_ = false; 590 end_of_stream_ = false;
591 last_packet_timestamp_ = kNoTimestamp; 591 last_packet_timestamp_ = kNoTimestamp;
592 last_packet_duration_ = kNoTimestamp; 592 last_packet_duration_ = kNoTimestamp;
593 } 593 }
594 594
595 void FFmpegDemuxerStream::Abort() {
596 if (!read_cb_.is_null())
597 base::ResetAndReturn(&read_cb_).Run(DemuxerStream::kAborted, nullptr);
598 }
599
595 void FFmpegDemuxerStream::Stop() { 600 void FFmpegDemuxerStream::Stop() {
596 DCHECK(task_runner_->BelongsToCurrentThread()); 601 DCHECK(task_runner_->BelongsToCurrentThread());
597 buffer_queue_.Clear(); 602 buffer_queue_.Clear();
598 if (!read_cb_.is_null()) { 603 if (!read_cb_.is_null()) {
599 base::ResetAndReturn(&read_cb_).Run( 604 base::ResetAndReturn(&read_cb_).Run(
600 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); 605 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer());
601 } 606 }
602 demuxer_ = NULL; 607 demuxer_ = NULL;
603 stream_ = NULL; 608 stream_ = NULL;
604 end_of_stream_ = true; 609 end_of_stream_ = true;
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 879
875 // Open the AVFormatContext using our glue layer. 880 // Open the AVFormatContext using our glue layer.
876 CHECK(blocking_thread_.Start()); 881 CHECK(blocking_thread_.Start());
877 base::PostTaskAndReplyWithResult( 882 base::PostTaskAndReplyWithResult(
878 blocking_thread_.task_runner().get(), FROM_HERE, 883 blocking_thread_.task_runner().get(), FROM_HERE,
879 base::Bind(&FFmpegGlue::OpenContext, base::Unretained(glue_.get())), 884 base::Bind(&FFmpegGlue::OpenContext, base::Unretained(glue_.get())),
880 base::Bind(&FFmpegDemuxer::OnOpenContextDone, weak_factory_.GetWeakPtr(), 885 base::Bind(&FFmpegDemuxer::OnOpenContextDone, weak_factory_.GetWeakPtr(),
881 status_cb)); 886 status_cb));
882 } 887 }
883 888
889 void FFmpegDemuxer::AbortPendingReads() {
890 DCHECK(task_runner_->BelongsToCurrentThread());
891
892 // This should only be called after the demuxer has been initialized.
893 DCHECK(blocking_thread_.IsRunning());
894 DCHECK_GT(streams_.size(), 0u);
895
896 // Abort all outstanding reads by returning EOS buffers (to avoid any errors
897 // being triggered in the pipeline).
898 for (auto* stream : streams_) {
899 if (stream)
900 stream->Abort();
901 }
902
903 data_source_->Abort();
904 }
905
884 void FFmpegDemuxer::Stop() { 906 void FFmpegDemuxer::Stop() {
885 DCHECK(task_runner_->BelongsToCurrentThread()); 907 DCHECK(task_runner_->BelongsToCurrentThread());
886 908
887 // The order of Stop() and Abort() is important here. If Abort() is called 909 // The order of Stop() and Abort() is important here. If Abort() is called
888 // first, control may pass into FFmpeg where it can destruct buffers that are 910 // first, control may pass into FFmpeg where it can destruct buffers that are
889 // in the process of being fulfilled by the DataSource. 911 // in the process of being fulfilled by the DataSource.
890 data_source_->Stop(); 912 data_source_->Stop();
891 url_protocol_->Abort(); 913 url_protocol_->Abort();
892 914
893 // This will block until all tasks complete. Note that after this returns it's 915 // This will block until all tasks complete. Note that after this returns it's
(...skipping 803 matching lines...) Expand 10 before | Expand all | Expand 10 after
1697 1719
1698 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { 1720 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) {
1699 DCHECK(task_runner_->BelongsToCurrentThread()); 1721 DCHECK(task_runner_->BelongsToCurrentThread());
1700 for (auto* stream : streams_) { 1722 for (auto* stream : streams_) {
1701 if (stream) 1723 if (stream)
1702 stream->SetLiveness(liveness); 1724 stream->SetLiveness(liveness);
1703 } 1725 }
1704 } 1726 }
1705 1727
1706 } // namespace media 1728 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698