OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chromecast/media/cma/base/demuxer_stream_adapter.h" | 5 #include "chromecast/media/cma/base/demuxer_stream_adapter.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/single_thread_task_runner.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" | 10 #include "chromecast/media/cma/base/balanced_media_task_runner_factory.h" |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
90 weak_factory_.InvalidateWeakPtrs(); | 90 weak_factory_.InvalidateWeakPtrs(); |
91 weak_this_ = weak_factory_.GetWeakPtr(); | 91 weak_this_ = weak_factory_.GetWeakPtr(); |
92 | 92 |
93 CMALOG(kLogControl) << "Flush done"; | 93 CMALOG(kLogControl) << "Flush done"; |
94 flush_cb.Run(); | 94 flush_cb.Run(); |
95 } | 95 } |
96 | 96 |
97 void DemuxerStreamAdapter::ResetMediaTaskRunner() { | 97 void DemuxerStreamAdapter::ResetMediaTaskRunner() { |
98 DCHECK(thread_checker_.CalledOnValidThread()); | 98 DCHECK(thread_checker_.CalledOnValidThread()); |
99 | 99 |
100 max_pts_ = ::media::kNoTimestamp(); | 100 max_pts_ = ::media::kNoTimestamp; |
101 if (media_task_runner_factory_.get()) { | 101 if (media_task_runner_factory_.get()) { |
102 media_task_runner_ = | 102 media_task_runner_ = |
103 media_task_runner_factory_->CreateMediaTaskRunner(task_runner_); | 103 media_task_runner_factory_->CreateMediaTaskRunner(task_runner_); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 void DemuxerStreamAdapter::RequestBuffer(const ReadCB& read_cb) { | 107 void DemuxerStreamAdapter::RequestBuffer(const ReadCB& read_cb) { |
108 DCHECK(thread_checker_.CalledOnValidThread()); | 108 DCHECK(thread_checker_.CalledOnValidThread()); |
109 is_pending_demuxer_read_ = true; | 109 is_pending_demuxer_read_ = true; |
110 demuxer_stream_->Read(::media::BindToCurrentLoop( | 110 demuxer_stream_->Read(::media::BindToCurrentLoop( |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 DCHECK_EQ(status, ::media::DemuxerStream::kOk); | 146 DCHECK_EQ(status, ::media::DemuxerStream::kOk); |
147 | 147 |
148 if (input->end_of_stream()) { | 148 if (input->end_of_stream()) { |
149 // This stream has ended, its media time will stop increasing, but there | 149 // This stream has ended, its media time will stop increasing, but there |
150 // might be other streams that are still playing. Remove the task runner of | 150 // might be other streams that are still playing. Remove the task runner of |
151 // this stream to ensure other streams are not blocked waiting for this one. | 151 // this stream to ensure other streams are not blocked waiting for this one. |
152 ResetMediaTaskRunner(); | 152 ResetMediaTaskRunner(); |
153 } | 153 } |
154 | 154 |
155 // Updates the timestamp used for task scheduling. | 155 // Updates the timestamp used for task scheduling. |
156 if (!input->end_of_stream() && | 156 if (!input->end_of_stream() && input->timestamp() != ::media::kNoTimestamp && |
157 input->timestamp() != ::media::kNoTimestamp() && | 157 (max_pts_ == ::media::kNoTimestamp || input->timestamp() > max_pts_)) { |
158 (max_pts_ == ::media::kNoTimestamp() || input->timestamp() > max_pts_)) { | |
159 max_pts_ = input->timestamp(); | 158 max_pts_ = input->timestamp(); |
160 } | 159 } |
161 | 160 |
162 // Provides the buffer as well as possibly valid audio and video configs. | 161 // Provides the buffer as well as possibly valid audio and video configs. |
163 is_pending_read_ = false; | 162 is_pending_read_ = false; |
164 scoped_refptr<DecoderBufferBase> buffer(new DecoderBufferAdapter(input)); | 163 scoped_refptr<DecoderBufferBase> buffer(new DecoderBufferAdapter(input)); |
165 read_cb.Run(buffer, audio_config_, video_config_); | 164 read_cb.Run(buffer, audio_config_, video_config_); |
166 | 165 |
167 // Back to the default audio/video config: | 166 // Back to the default audio/video config: |
168 // an invalid audio/video config means there is no config update. | 167 // an invalid audio/video config means there is no config update. |
169 if (audio_config_.IsValidConfig()) | 168 if (audio_config_.IsValidConfig()) |
170 audio_config_ = ::media::AudioDecoderConfig(); | 169 audio_config_ = ::media::AudioDecoderConfig(); |
171 if (video_config_.IsValidConfig()) | 170 if (video_config_.IsValidConfig()) |
172 video_config_ = ::media::VideoDecoderConfig(); | 171 video_config_ = ::media::VideoDecoderConfig(); |
173 } | 172 } |
174 | 173 |
175 } // namespace media | 174 } // namespace media |
176 } // namespace chromecast | 175 } // namespace chromecast |
OLD | NEW |