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/pipeline/av_pipeline_impl.h" | 5 #include "chromecast/media/cma/pipeline/av_pipeline_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/location.h" | 8 #include "base/location.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/single_thread_task_runner.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| 11 #include "base/thread_task_runner_handle.h" |
11 #include "chromecast/media/base/decrypt_context.h" | 12 #include "chromecast/media/base/decrypt_context.h" |
12 #include "chromecast/media/cdm/browser_cdm_cast.h" | 13 #include "chromecast/media/cdm/browser_cdm_cast.h" |
13 #include "chromecast/media/cma/backend/media_clock_device.h" | 14 #include "chromecast/media/cma/backend/media_clock_device.h" |
14 #include "chromecast/media/cma/backend/media_component_device.h" | 15 #include "chromecast/media/cma/backend/media_component_device.h" |
15 #include "chromecast/media/cma/base/buffering_frame_provider.h" | 16 #include "chromecast/media/cma/base/buffering_frame_provider.h" |
16 #include "chromecast/media/cma/base/buffering_state.h" | 17 #include "chromecast/media/cma/base/buffering_state.h" |
17 #include "chromecast/media/cma/base/cma_logging.h" | 18 #include "chromecast/media/cma/base/cma_logging.h" |
18 #include "chromecast/media/cma/base/coded_frame_provider.h" | 19 #include "chromecast/media/cma/base/coded_frame_provider.h" |
19 #include "chromecast/media/cma/base/decoder_buffer_base.h" | 20 #include "chromecast/media/cma/base/decoder_buffer_base.h" |
20 #include "chromecast/media/cma/pipeline/decrypt_util.h" | 21 #include "chromecast/media/cma/pipeline/decrypt_util.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 DCHECK(frame_provider_); | 118 DCHECK(frame_provider_); |
118 buffering_state_ = buffering_state; | 119 buffering_state_ = buffering_state; |
119 if (buffering_state_.get()) | 120 if (buffering_state_.get()) |
120 buffering_state_->SetMediaTime(time); | 121 buffering_state_->SetMediaTime(time); |
121 | 122 |
122 if (!media_component_device_->SetState(MediaComponentDevice::kStateRunning)) | 123 if (!media_component_device_->SetState(MediaComponentDevice::kStateRunning)) |
123 return false; | 124 return false; |
124 | 125 |
125 // Start feeding the pipeline. | 126 // Start feeding the pipeline. |
126 enable_feeding_ = true; | 127 enable_feeding_ = true; |
127 base::MessageLoopProxy::current()->PostTask( | 128 base::ThreadTaskRunnerHandle::Get()->PostTask( |
128 FROM_HERE, | 129 FROM_HERE, base::Bind(&AvPipelineImpl::FetchBufferIfNeeded, weak_this_)); |
129 base::Bind(&AvPipelineImpl::FetchBufferIfNeeded, weak_this_)); | |
130 | 130 |
131 return true; | 131 return true; |
132 } | 132 } |
133 | 133 |
134 void AvPipelineImpl::Flush(const base::Closure& done_cb) { | 134 void AvPipelineImpl::Flush(const base::Closure& done_cb) { |
135 DCHECK(thread_checker_.CalledOnValidThread()); | 135 DCHECK(thread_checker_.CalledOnValidThread()); |
136 DCHECK_EQ(state_, kFlushing); | 136 DCHECK_EQ(state_, kFlushing); |
137 DCHECK_EQ( | 137 DCHECK_EQ( |
138 media_component_device_->GetState(), MediaComponentDevice::kStateRunning); | 138 media_component_device_->GetState(), MediaComponentDevice::kStateRunning); |
139 // Note: returning to idle state aborts any pending frame push. | 139 // Note: returning to idle state aborts any pending frame push. |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 const ::media::VideoDecoderConfig& video_config) { | 219 const ::media::VideoDecoderConfig& video_config) { |
220 DCHECK(thread_checker_.CalledOnValidThread()); | 220 DCHECK(thread_checker_.CalledOnValidThread()); |
221 pending_read_ = false; | 221 pending_read_ = false; |
222 | 222 |
223 if (audio_config.IsValidConfig() || video_config.IsValidConfig()) | 223 if (audio_config.IsValidConfig() || video_config.IsValidConfig()) |
224 update_config_cb_.Run(audio_config, video_config); | 224 update_config_cb_.Run(audio_config, video_config); |
225 | 225 |
226 pending_buffer_ = buffer; | 226 pending_buffer_ = buffer; |
227 ProcessPendingBuffer(); | 227 ProcessPendingBuffer(); |
228 | 228 |
229 base::MessageLoopProxy::current()->PostTask( | 229 base::ThreadTaskRunnerHandle::Get()->PostTask( |
230 FROM_HERE, | 230 FROM_HERE, base::Bind(&AvPipelineImpl::FetchBufferIfNeeded, weak_this_)); |
231 base::Bind(&AvPipelineImpl::FetchBufferIfNeeded, weak_this_)); | |
232 } | 231 } |
233 | 232 |
234 void AvPipelineImpl::ProcessPendingBuffer() { | 233 void AvPipelineImpl::ProcessPendingBuffer() { |
235 if (!enable_feeding_) | 234 if (!enable_feeding_) |
236 return; | 235 return; |
237 | 236 |
238 // Initiate a read if there isn't already one. | 237 // Initiate a read if there isn't already one. |
239 if (!pending_buffer_.get() && !pending_read_) { | 238 if (!pending_buffer_.get() && !pending_read_) { |
240 base::MessageLoopProxy::current()->PostTask( | 239 base::ThreadTaskRunnerHandle::Get()->PostTask( |
241 FROM_HERE, | 240 FROM_HERE, |
242 base::Bind(&AvPipelineImpl::FetchBufferIfNeeded, weak_this_)); | 241 base::Bind(&AvPipelineImpl::FetchBufferIfNeeded, weak_this_)); |
243 return; | 242 return; |
244 } | 243 } |
245 | 244 |
246 if (!pending_buffer_.get() || pending_push_) | 245 if (!pending_buffer_.get() || pending_push_) |
247 return; | 246 return; |
248 | 247 |
249 // Break the feeding loop when the end of stream is reached. | 248 // Break the feeding loop when the end of stream is reached. |
250 if (pending_buffer_->end_of_stream()) { | 249 if (pending_buffer_->end_of_stream()) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
300 | 299 |
301 void AvPipelineImpl::OnFramePushed(MediaComponentDevice::FrameStatus status) { | 300 void AvPipelineImpl::OnFramePushed(MediaComponentDevice::FrameStatus status) { |
302 DCHECK(thread_checker_.CalledOnValidThread()); | 301 DCHECK(thread_checker_.CalledOnValidThread()); |
303 pending_push_ = false; | 302 pending_push_ = false; |
304 if (status == MediaComponentDevice::kFrameFailed) { | 303 if (status == MediaComponentDevice::kFrameFailed) { |
305 LOG(WARNING) << "AvPipelineImpl: PushFrame failed"; | 304 LOG(WARNING) << "AvPipelineImpl: PushFrame failed"; |
306 enable_feeding_ = false; | 305 enable_feeding_ = false; |
307 state_ = kError; | 306 state_ = kError; |
308 return; | 307 return; |
309 } | 308 } |
310 base::MessageLoopProxy::current()->PostTask( | 309 base::ThreadTaskRunnerHandle::Get()->PostTask( |
311 FROM_HERE, | 310 FROM_HERE, base::Bind(&AvPipelineImpl::ProcessPendingBuffer, weak_this_)); |
312 base::Bind(&AvPipelineImpl::ProcessPendingBuffer, weak_this_)); | |
313 } | 311 } |
314 | 312 |
315 void AvPipelineImpl::OnCdmStateChanged() { | 313 void AvPipelineImpl::OnCdmStateChanged() { |
316 DCHECK(thread_checker_.CalledOnValidThread()); | 314 DCHECK(thread_checker_.CalledOnValidThread()); |
317 | 315 |
318 // Update the buffering state if needed. | 316 // Update the buffering state if needed. |
319 if (buffering_state_.get()) | 317 if (buffering_state_.get()) |
320 UpdatePlayableFrames(); | 318 UpdatePlayableFrames(); |
321 | 319 |
322 // Process the pending buffer in case the CDM now has the frame key id. | 320 // Process the pending buffer in case the CDM now has the frame key id. |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 } | 376 } |
379 } | 377 } |
380 | 378 |
381 // The frame is playable: remove it from the list of non playable frames. | 379 // The frame is playable: remove it from the list of non playable frames. |
382 non_playable_frames_.pop_front(); | 380 non_playable_frames_.pop_front(); |
383 } | 381 } |
384 } | 382 } |
385 | 383 |
386 } // namespace media | 384 } // namespace media |
387 } // namespace chromecast | 385 } // namespace chromecast |
OLD | NEW |