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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
831 blocking_thread_("FFmpegDemuxer"), | 831 blocking_thread_("FFmpegDemuxer"), |
832 pending_read_(false), | 832 pending_read_(false), |
833 data_source_(data_source), | 833 data_source_(data_source), |
834 media_log_(media_log), | 834 media_log_(media_log), |
835 bitrate_(0), | 835 bitrate_(0), |
836 start_time_(kNoTimestamp), | 836 start_time_(kNoTimestamp), |
837 text_enabled_(false), | 837 text_enabled_(false), |
838 duration_known_(false), | 838 duration_known_(false), |
839 encrypted_media_init_data_cb_(encrypted_media_init_data_cb), | 839 encrypted_media_init_data_cb_(encrypted_media_init_data_cb), |
840 media_tracks_updated_cb_(media_tracks_updated_cb), | 840 media_tracks_updated_cb_(media_tracks_updated_cb), |
| 841 cancel_pending_seek_factory_(this), |
841 weak_factory_(this) { | 842 weak_factory_(this) { |
842 DCHECK(task_runner_.get()); | 843 DCHECK(task_runner_.get()); |
843 DCHECK(data_source_); | 844 DCHECK(data_source_); |
844 DCHECK(!media_tracks_updated_cb_.is_null()); | 845 DCHECK(!media_tracks_updated_cb_.is_null()); |
845 } | 846 } |
846 | 847 |
847 FFmpegDemuxer::~FFmpegDemuxer() { | 848 FFmpegDemuxer::~FFmpegDemuxer() { |
848 // NOTE: This class is not destroyed on |task_runner|, so we must ensure that | 849 // NOTE: This class is not destroyed on |task_runner|, so we must ensure that |
849 // there are no outstanding WeakPtrs by the time we reach here. | 850 // there are no outstanding WeakPtrs by the time we reach here. |
850 DCHECK(!weak_factory_.HasWeakPtrs()); | 851 DCHECK(!weak_factory_.HasWeakPtrs()); |
851 } | 852 } |
852 | 853 |
853 std::string FFmpegDemuxer::GetDisplayName() const { | 854 std::string FFmpegDemuxer::GetDisplayName() const { |
854 return "FFmpegDemuxer"; | 855 return "FFmpegDemuxer"; |
855 } | 856 } |
856 | 857 |
857 void FFmpegDemuxer::Initialize(DemuxerHost* host, | 858 void FFmpegDemuxer::Initialize(DemuxerHost* host, |
858 const PipelineStatusCB& status_cb, | 859 const PipelineStatusCB& status_cb, |
859 bool enable_text_tracks) { | 860 bool enable_text_tracks) { |
860 DCHECK(task_runner_->BelongsToCurrentThread()); | 861 DCHECK(task_runner_->BelongsToCurrentThread()); |
861 host_ = host; | 862 host_ = host; |
862 text_enabled_ = enable_text_tracks; | 863 text_enabled_ = enable_text_tracks; |
| 864 weak_this_ = cancel_pending_seek_factory_.GetWeakPtr(); |
863 | 865 |
864 url_protocol_.reset(new BlockingUrlProtocol( | 866 url_protocol_.reset(new BlockingUrlProtocol( |
865 data_source_, | 867 data_source_, |
866 BindToCurrentLoop(base::Bind(&FFmpegDemuxer::OnDataSourceError, | 868 BindToCurrentLoop(base::Bind(&FFmpegDemuxer::OnDataSourceError, |
867 base::Unretained(this))))); | 869 base::Unretained(this))))); |
868 glue_.reset(new FFmpegGlue(url_protocol_.get())); | 870 glue_.reset(new FFmpegGlue(url_protocol_.get())); |
869 AVFormatContext* format_context = glue_->format_context(); | 871 AVFormatContext* format_context = glue_->format_context(); |
870 | 872 |
871 // Disable ID3v1 tag reading to avoid costly seeks to end of file for data we | 873 // Disable ID3v1 tag reading to avoid costly seeks to end of file for data we |
872 // don't use. FFmpeg will only read ID3v1 tags if no other metadata is | 874 // don't use. FFmpeg will only read ID3v1 tags if no other metadata is |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
940 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { | 942 for (iter = streams_.begin(); iter != streams_.end(); ++iter) { |
941 if (*iter) | 943 if (*iter) |
942 (*iter)->Stop(); | 944 (*iter)->Stop(); |
943 } | 945 } |
944 | 946 |
945 data_source_ = NULL; | 947 data_source_ = NULL; |
946 | 948 |
947 // Invalidate WeakPtrs on |task_runner_|, destruction may happen on another | 949 // Invalidate WeakPtrs on |task_runner_|, destruction may happen on another |
948 // thread. | 950 // thread. |
949 weak_factory_.InvalidateWeakPtrs(); | 951 weak_factory_.InvalidateWeakPtrs(); |
| 952 cancel_pending_seek_factory_.InvalidateWeakPtrs(); |
950 } | 953 } |
951 | 954 |
952 void FFmpegDemuxer::StartWaitingForSeek(base::TimeDelta seek_time) {} | 955 void FFmpegDemuxer::StartWaitingForSeek(base::TimeDelta seek_time) {} |
953 | 956 |
954 void FFmpegDemuxer::CancelPendingSeek(base::TimeDelta seek_time) { | 957 void FFmpegDemuxer::CancelPendingSeek(base::TimeDelta seek_time) { |
955 if (task_runner_->BelongsToCurrentThread()) { | 958 if (task_runner_->BelongsToCurrentThread()) { |
956 AbortPendingReads(); | 959 AbortPendingReads(); |
957 } else { | 960 } else { |
958 task_runner_->PostTask(FROM_HERE, | 961 // Don't use GetWeakPtr() here since we are on the wrong thread. |
959 base::Bind(&FFmpegDemuxer::AbortPendingReads, | 962 task_runner_->PostTask( |
960 weak_factory_.GetWeakPtr())); | 963 FROM_HERE, base::Bind(&FFmpegDemuxer::AbortPendingReads, weak_this_)); |
961 } | 964 } |
962 } | 965 } |
963 | 966 |
964 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { | 967 void FFmpegDemuxer::Seek(base::TimeDelta time, const PipelineStatusCB& cb) { |
965 DCHECK(task_runner_->BelongsToCurrentThread()); | 968 DCHECK(task_runner_->BelongsToCurrentThread()); |
966 CHECK(pending_seek_cb_.is_null()); | 969 CHECK(pending_seek_cb_.is_null()); |
967 | 970 |
968 // FFmpeg requires seeks to be adjusted according to the lowest starting time. | 971 // FFmpeg requires seeks to be adjusted according to the lowest starting time. |
969 // Since EnqueuePacket() rebased negative timestamps by the start time, we | 972 // Since EnqueuePacket() rebased negative timestamps by the start time, we |
970 // must correct the shift here. | 973 // must correct the shift here. |
(...skipping 781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1752 | 1755 |
1753 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { | 1756 void FFmpegDemuxer::SetLiveness(DemuxerStream::Liveness liveness) { |
1754 DCHECK(task_runner_->BelongsToCurrentThread()); | 1757 DCHECK(task_runner_->BelongsToCurrentThread()); |
1755 for (auto* stream : streams_) { | 1758 for (auto* stream : streams_) { |
1756 if (stream) | 1759 if (stream) |
1757 stream->SetLiveness(liveness); | 1760 stream->SetLiveness(liveness); |
1758 } | 1761 } |
1759 } | 1762 } |
1760 | 1763 |
1761 } // namespace media | 1764 } // namespace media |
OLD | NEW |