| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/audio/cast_audio_output_stream.h" | 5 #include "chromecast/media/audio/cast_audio_output_stream.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/threading/thread_checker.h" | 9 #include "base/threading/thread_checker.h" |
| 10 #include "chromecast/base/metrics/cast_metrics_helper.h" | 10 #include "chromecast/base/metrics/cast_metrics_helper.h" |
| 11 #include "chromecast/base/task_runner_impl.h" |
| 11 #include "chromecast/media/audio/cast_audio_manager.h" | 12 #include "chromecast/media/audio/cast_audio_manager.h" |
| 12 #include "chromecast/media/base/media_message_loop.h" | 13 #include "chromecast/media/base/media_message_loop.h" |
| 13 #include "chromecast/media/cma/base/cast_decoder_buffer_impl.h" | 14 #include "chromecast/media/cma/base/cast_decoder_buffer_impl.h" |
| 14 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" | 15 #include "chromecast/media/cma/base/decoder_buffer_adapter.h" |
| 15 #include "chromecast/media/cma/pipeline/frame_status_cb_impl.h" | 16 #include "chromecast/media/cma/pipeline/frame_status_cb_impl.h" |
| 16 #include "chromecast/public/media/audio_pipeline_device.h" | 17 #include "chromecast/public/media/audio_pipeline_device.h" |
| 17 #include "chromecast/public/media/decoder_config.h" | 18 #include "chromecast/public/media/decoder_config.h" |
| 18 #include "chromecast/public/media/decrypt_context.h" | 19 #include "chromecast/public/media/decrypt_context.h" |
| 19 #include "chromecast/public/media/media_clock_device.h" | 20 #include "chromecast/public/media/media_clock_device.h" |
| 20 #include "chromecast/public/media/media_pipeline_backend.h" | 21 #include "chromecast/public/media/media_pipeline_backend.h" |
| 22 #include "chromecast/public/media/media_pipeline_device_params.h" |
| 21 #include "media/base/bind_to_current_loop.h" | 23 #include "media/base/bind_to_current_loop.h" |
| 22 #include "media/base/decoder_buffer.h" | 24 #include "media/base/decoder_buffer.h" |
| 23 | 25 |
| 24 namespace chromecast { | 26 namespace chromecast { |
| 25 namespace media { | 27 namespace media { |
| 26 | 28 |
| 27 namespace { | 29 namespace { |
| 28 bool InitClockDevice(MediaClockDevice* clock_device) { | 30 bool InitClockDevice(MediaClockDevice* clock_device) { |
| 29 DCHECK(clock_device); | 31 DCHECK(clock_device); |
| 30 DCHECK_EQ(clock_device->GetState(), MediaClockDevice::kStateUninitialized); | 32 DCHECK_EQ(clock_device->GetState(), MediaClockDevice::kStateUninitialized); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 thread_checker_.DetachFromThread(); | 80 thread_checker_.DetachFromThread(); |
| 79 } | 81 } |
| 80 ~Backend() {} | 82 ~Backend() {} |
| 81 | 83 |
| 82 void Open(CastAudioManager* audio_manager, | 84 void Open(CastAudioManager* audio_manager, |
| 83 bool* success, | 85 bool* success, |
| 84 base::WaitableEvent* completion_event) { | 86 base::WaitableEvent* completion_event) { |
| 85 DCHECK(thread_checker_.CalledOnValidThread()); | 87 DCHECK(thread_checker_.CalledOnValidThread()); |
| 86 DCHECK(backend_ == nullptr); | 88 DCHECK(backend_ == nullptr); |
| 87 | 89 |
| 90 backend_task_runner_.reset(new TaskRunnerImpl()); |
| 91 MediaPipelineDeviceParams device_params( |
| 92 MediaPipelineDeviceParams::kModeIgnorePts, backend_task_runner_.get()); |
| 93 |
| 88 scoped_ptr<MediaPipelineBackend> pipeline_backend = | 94 scoped_ptr<MediaPipelineBackend> pipeline_backend = |
| 89 audio_manager->CreateMediaPipelineBackend(); | 95 audio_manager->CreateMediaPipelineBackend(device_params); |
| 90 if (pipeline_backend && InitClockDevice(pipeline_backend->GetClock()) && | 96 if (pipeline_backend && InitClockDevice(pipeline_backend->GetClock()) && |
| 91 InitAudioDevice(audio_params_, pipeline_backend->GetAudio())) { | 97 InitAudioDevice(audio_params_, pipeline_backend->GetAudio())) { |
| 92 backend_ = pipeline_backend.Pass(); | 98 backend_ = pipeline_backend.Pass(); |
| 93 } | 99 } |
| 94 *success = backend_ != nullptr; | 100 *success = backend_ != nullptr; |
| 95 completion_event->Signal(); | 101 completion_event->Signal(); |
| 96 } | 102 } |
| 97 | 103 |
| 98 void Close() { | 104 void Close() { |
| 99 DCHECK(thread_checker_.CalledOnValidThread()); | 105 DCHECK(thread_checker_.CalledOnValidThread()); |
| 100 | 106 |
| 101 if (backend_) { | 107 if (backend_) { |
| 102 backend_->GetClock()->SetState(MediaClockDevice::kStateIdle); | 108 backend_->GetClock()->SetState(MediaClockDevice::kStateIdle); |
| 103 backend_->GetAudio()->SetState(AudioPipelineDevice::kStateIdle); | 109 backend_->GetAudio()->SetState(AudioPipelineDevice::kStateIdle); |
| 104 } | 110 } |
| 105 backend_.reset(); | 111 backend_.reset(); |
| 112 backend_task_runner_.reset(); |
| 106 } | 113 } |
| 107 | 114 |
| 108 void Start() { | 115 void Start() { |
| 109 DCHECK(thread_checker_.CalledOnValidThread()); | 116 DCHECK(thread_checker_.CalledOnValidThread()); |
| 110 | 117 |
| 111 MediaClockDevice* clock_device = backend_->GetClock(); | 118 MediaClockDevice* clock_device = backend_->GetClock(); |
| 112 clock_device->SetState(MediaClockDevice::kStateRunning); | 119 clock_device->SetState(MediaClockDevice::kStateRunning); |
| 113 clock_device->SetRate(1.0f); | 120 clock_device->SetRate(1.0f); |
| 114 | 121 |
| 115 AudioPipelineDevice* audio_device = backend_->GetAudio(); | 122 AudioPipelineDevice* audio_device = backend_->GetAudio(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 void OnPushFrameStatus(const PushFrameCompletionCallback& completion_cb, | 157 void OnPushFrameStatus(const PushFrameCompletionCallback& completion_cb, |
| 151 MediaComponentDevice::FrameStatus status) { | 158 MediaComponentDevice::FrameStatus status) { |
| 152 DCHECK(thread_checker_.CalledOnValidThread()); | 159 DCHECK(thread_checker_.CalledOnValidThread()); |
| 153 DCHECK_NE(status, MediaComponentDevice::kFramePending); | 160 DCHECK_NE(status, MediaComponentDevice::kFramePending); |
| 154 | 161 |
| 155 completion_cb.Run(status == MediaComponentDevice::kFrameSuccess); | 162 completion_cb.Run(status == MediaComponentDevice::kFrameSuccess); |
| 156 } | 163 } |
| 157 | 164 |
| 158 const ::media::AudioParameters audio_params_; | 165 const ::media::AudioParameters audio_params_; |
| 159 scoped_ptr<MediaPipelineBackend> backend_; | 166 scoped_ptr<MediaPipelineBackend> backend_; |
| 167 scoped_ptr<TaskRunnerImpl> backend_task_runner_; |
| 160 base::ThreadChecker thread_checker_; | 168 base::ThreadChecker thread_checker_; |
| 161 DISALLOW_COPY_AND_ASSIGN(Backend); | 169 DISALLOW_COPY_AND_ASSIGN(Backend); |
| 162 }; | 170 }; |
| 163 | 171 |
| 164 // CastAudioOutputStream runs on audio thread (AudioManager::GetTaskRunner). | 172 // CastAudioOutputStream runs on audio thread (AudioManager::GetTaskRunner). |
| 165 CastAudioOutputStream::CastAudioOutputStream( | 173 CastAudioOutputStream::CastAudioOutputStream( |
| 166 const ::media::AudioParameters& audio_params, | 174 const ::media::AudioParameters& audio_params, |
| 167 CastAudioManager* audio_manager) | 175 CastAudioManager* audio_manager) |
| 168 : audio_params_(audio_params), | 176 : audio_params_(audio_params), |
| 169 audio_manager_(audio_manager), | 177 audio_manager_(audio_manager), |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 next_push_time_ = now + delay; | 334 next_push_time_ = now + delay; |
| 327 | 335 |
| 328 audio_task_runner_->PostDelayedTask( | 336 audio_task_runner_->PostDelayedTask( |
| 329 FROM_HERE, | 337 FROM_HERE, |
| 330 base::Bind(&CastAudioOutputStream::PushFrame, weak_factory_.GetWeakPtr()), | 338 base::Bind(&CastAudioOutputStream::PushFrame, weak_factory_.GetWeakPtr()), |
| 331 delay); | 339 delay); |
| 332 } | 340 } |
| 333 | 341 |
| 334 } // namespace media | 342 } // namespace media |
| 335 } // namespace chromecast | 343 } // namespace chromecast |
| OLD | NEW |