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/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 Loading... |
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::kOk, |
| 598 DecoderBuffer::CreateEOSBuffer()); |
| 599 } |
| 600 } |
| 601 |
595 void FFmpegDemuxerStream::Stop() { | 602 void FFmpegDemuxerStream::Stop() { |
596 DCHECK(task_runner_->BelongsToCurrentThread()); | 603 DCHECK(task_runner_->BelongsToCurrentThread()); |
597 buffer_queue_.Clear(); | 604 buffer_queue_.Clear(); |
598 if (!read_cb_.is_null()) { | 605 if (!read_cb_.is_null()) { |
599 base::ResetAndReturn(&read_cb_).Run( | 606 base::ResetAndReturn(&read_cb_).Run( |
600 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); | 607 DemuxerStream::kOk, DecoderBuffer::CreateEOSBuffer()); |
601 } | 608 } |
602 demuxer_ = NULL; | 609 demuxer_ = NULL; |
603 stream_ = NULL; | 610 stream_ = NULL; |
604 end_of_stream_ = true; | 611 end_of_stream_ = true; |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 | 881 |
875 // Open the AVFormatContext using our glue layer. | 882 // Open the AVFormatContext using our glue layer. |
876 CHECK(blocking_thread_.Start()); | 883 CHECK(blocking_thread_.Start()); |
877 base::PostTaskAndReplyWithResult( | 884 base::PostTaskAndReplyWithResult( |
878 blocking_thread_.task_runner().get(), FROM_HERE, | 885 blocking_thread_.task_runner().get(), FROM_HERE, |
879 base::Bind(&FFmpegGlue::OpenContext, base::Unretained(glue_.get())), | 886 base::Bind(&FFmpegGlue::OpenContext, base::Unretained(glue_.get())), |
880 base::Bind(&FFmpegDemuxer::OnOpenContextDone, weak_factory_.GetWeakPtr(), | 887 base::Bind(&FFmpegDemuxer::OnOpenContextDone, weak_factory_.GetWeakPtr(), |
881 status_cb)); | 888 status_cb)); |
882 } | 889 } |
883 | 890 |
| 891 void FFmpegDemuxer::AbortPendingReads() { |
| 892 DCHECK(task_runner_->BelongsToCurrentThread()); |
| 893 |
| 894 // This should only be called after the demuxer has been initialized. |
| 895 DCHECK(blocking_thread_.IsRunning()); |
| 896 DCHECK_GT(streams_.size(), 0u); |
| 897 |
| 898 // Abort all outstanding reads by returning EOS buffers (to avoid any errors |
| 899 // being triggered in the pipeline). |
| 900 for (auto* stream : streams_) { |
| 901 if (stream) |
| 902 stream->Abort(); |
| 903 } |
| 904 |
| 905 // Ordering is important here, we want to ignore any errors that occur during |
| 906 // the Abort() of the data source. Note: We don't abort the URLProtocol here |
| 907 // since that is a permanent action. |
| 908 weak_factory_.InvalidateWeakPtrs(); |
| 909 data_source_->Abort(); |
| 910 } |
| 911 |
884 void FFmpegDemuxer::Stop() { | 912 void FFmpegDemuxer::Stop() { |
885 DCHECK(task_runner_->BelongsToCurrentThread()); | 913 DCHECK(task_runner_->BelongsToCurrentThread()); |
886 | 914 |
887 // The order of Stop() and Abort() is important here. If Abort() is called | 915 // 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 | 916 // first, control may pass into FFmpeg where it can destruct buffers that are |
889 // in the process of being fulfilled by the DataSource. | 917 // in the process of being fulfilled by the DataSource. |
890 data_source_->Stop(); | 918 data_source_->Stop(); |
891 url_protocol_->Abort(); | 919 url_protocol_->Abort(); |
892 | 920 |
893 // This will block until all tasks complete. Note that after this returns it's | 921 // 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 Loading... |
1697 | 1725 |
1698 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1726 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1699 DCHECK(task_runner_->BelongsToCurrentThread()); | 1727 DCHECK(task_runner_->BelongsToCurrentThread()); |
1700 for (auto* stream : streams_) { | 1728 for (auto* stream : streams_) { |
1701 if (stream) | 1729 if (stream) |
1702 stream->SetLiveness(liveness); | 1730 stream->SetLiveness(liveness); |
1703 } | 1731 } |
1704 } | 1732 } |
1705 | 1733 |
1706 } // namespace media | 1734 } // namespace media |
OLD | NEW |