| 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/renderer/media/media_pipeline_proxy.h" | 5 #include "chromecast/renderer/media/media_pipeline_proxy.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/location.h" | 9 #include "base/location.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/message_loop/message_loop_proxy.h" | 11 #include "base/single_thread_task_runner.h" |
| 12 #include "chromecast/common/media/cma_messages.h" | 12 #include "chromecast/common/media/cma_messages.h" |
| 13 #include "chromecast/media/cma/base/coded_frame_provider.h" | 13 #include "chromecast/media/cma/base/coded_frame_provider.h" |
| 14 #include "chromecast/renderer/media/audio_pipeline_proxy.h" | 14 #include "chromecast/renderer/media/audio_pipeline_proxy.h" |
| 15 #include "chromecast/renderer/media/media_channel_proxy.h" | 15 #include "chromecast/renderer/media/media_channel_proxy.h" |
| 16 #include "chromecast/renderer/media/video_pipeline_proxy.h" | 16 #include "chromecast/renderer/media/video_pipeline_proxy.h" |
| 17 | 17 |
| 18 namespace chromecast { | 18 namespace chromecast { |
| 19 namespace media { | 19 namespace media { |
| 20 | 20 |
| 21 // MediaPipelineProxyInternal - | 21 // MediaPipelineProxyInternal - |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 media_channel_proxy_->GetId(), playback_rate))); | 142 media_channel_proxy_->GetId(), playback_rate))); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void MediaPipelineProxyInternal::OnStateChanged( | 145 void MediaPipelineProxyInternal::OnStateChanged( |
| 146 ::media::PipelineStatus status) { | 146 ::media::PipelineStatus status) { |
| 147 DCHECK(thread_checker_.CalledOnValidThread()); | 147 DCHECK(thread_checker_.CalledOnValidThread()); |
| 148 DCHECK(!status_cb_.is_null()); | 148 DCHECK(!status_cb_.is_null()); |
| 149 base::ResetAndReturn(&status_cb_).Run(status); | 149 base::ResetAndReturn(&status_cb_).Run(status); |
| 150 } | 150 } |
| 151 | 151 |
| 152 | 152 // A macro runs current member function on |io_task_runner_| thread. |
| 153 // A macro runs current member function on |io_message_loop_proxy_| thread. | 153 #define FORWARD_ON_IO_THREAD(param_fn, ...) \ |
| 154 #define FORWARD_ON_IO_THREAD(param_fn, ...) \ | 154 io_task_runner_->PostTask( \ |
| 155 io_message_loop_proxy_->PostTask( \ | 155 FROM_HERE, base::Bind(&MediaPipelineProxyInternal::param_fn, \ |
| 156 FROM_HERE, \ | 156 base::Unretained(proxy_.get()), ##__VA_ARGS__)) |
| 157 base::Bind(&MediaPipelineProxyInternal::param_fn, \ | |
| 158 base::Unretained(proxy_.get()), ##__VA_ARGS__)) | |
| 159 | 157 |
| 160 MediaPipelineProxy::MediaPipelineProxy( | 158 MediaPipelineProxy::MediaPipelineProxy( |
| 161 int render_frame_id, | 159 int render_frame_id, |
| 162 scoped_refptr<base::MessageLoopProxy> io_message_loop_proxy, | 160 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner, |
| 163 LoadType load_type) | 161 LoadType load_type) |
| 164 : io_message_loop_proxy_(io_message_loop_proxy), | 162 : io_task_runner_(io_task_runner), |
| 165 render_frame_id_(render_frame_id), | 163 render_frame_id_(render_frame_id), |
| 166 media_channel_proxy_(new MediaChannelProxy), | 164 media_channel_proxy_(new MediaChannelProxy), |
| 167 proxy_(new MediaPipelineProxyInternal(media_channel_proxy_)), | 165 proxy_(new MediaPipelineProxyInternal(media_channel_proxy_)), |
| 168 has_audio_(false), | 166 has_audio_(false), |
| 169 has_video_(false), | 167 has_video_(false), |
| 170 audio_pipeline_(new AudioPipelineProxy( | 168 audio_pipeline_( |
| 171 io_message_loop_proxy, media_channel_proxy_)), | 169 new AudioPipelineProxy(io_task_runner, media_channel_proxy_)), |
| 172 video_pipeline_(new VideoPipelineProxy( | 170 video_pipeline_( |
| 173 io_message_loop_proxy, media_channel_proxy_)), | 171 new VideoPipelineProxy(io_task_runner, media_channel_proxy_)), |
| 174 weak_factory_(this) { | 172 weak_factory_(this) { |
| 175 weak_this_ = weak_factory_.GetWeakPtr(); | 173 weak_this_ = weak_factory_.GetWeakPtr(); |
| 176 io_message_loop_proxy_->PostTask( | 174 io_task_runner_->PostTask( |
| 177 FROM_HERE, | 175 FROM_HERE, |
| 178 base::Bind(&MediaChannelProxy::Open, media_channel_proxy_, | 176 base::Bind(&MediaChannelProxy::Open, media_channel_proxy_, load_type)); |
| 179 load_type)); | |
| 180 thread_checker_.DetachFromThread(); | 177 thread_checker_.DetachFromThread(); |
| 181 } | 178 } |
| 182 | 179 |
| 183 MediaPipelineProxy::~MediaPipelineProxy() { | 180 MediaPipelineProxy::~MediaPipelineProxy() { |
| 184 io_message_loop_proxy_->PostTask( | 181 io_task_runner_->PostTask( |
| 185 FROM_HERE, | 182 FROM_HERE, |
| 186 base::Bind(&MediaPipelineProxyInternal::Release, base::Passed(&proxy_))); | 183 base::Bind(&MediaPipelineProxyInternal::Release, base::Passed(&proxy_))); |
| 187 io_message_loop_proxy_->PostTask( | 184 io_task_runner_->PostTask( |
| 188 FROM_HERE, | 185 FROM_HERE, base::Bind(&MediaChannelProxy::Close, media_channel_proxy_)); |
| 189 base::Bind(&MediaChannelProxy::Close, media_channel_proxy_)); | |
| 190 } | 186 } |
| 191 | 187 |
| 192 void MediaPipelineProxy::SetClient( | 188 void MediaPipelineProxy::SetClient( |
| 193 const MediaPipelineClient& client) { | 189 const MediaPipelineClient& client) { |
| 194 DCHECK(thread_checker_.CalledOnValidThread()); | 190 DCHECK(thread_checker_.CalledOnValidThread()); |
| 195 FORWARD_ON_IO_THREAD(SetClient, client); | 191 FORWARD_ON_IO_THREAD(SetClient, client); |
| 196 } | 192 } |
| 197 | 193 |
| 198 void MediaPipelineProxy::SetCdm(int cdm_id) { | 194 void MediaPipelineProxy::SetCdm(int cdm_id) { |
| 199 DCHECK(thread_checker_.CalledOnValidThread()); | 195 DCHECK(thread_checker_.CalledOnValidThread()); |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 FORWARD_ON_IO_THREAD(Stop); | 270 FORWARD_ON_IO_THREAD(Stop); |
| 275 } | 271 } |
| 276 | 272 |
| 277 void MediaPipelineProxy::SetPlaybackRate(double playback_rate) { | 273 void MediaPipelineProxy::SetPlaybackRate(double playback_rate) { |
| 278 DCHECK(thread_checker_.CalledOnValidThread()); | 274 DCHECK(thread_checker_.CalledOnValidThread()); |
| 279 FORWARD_ON_IO_THREAD(SetPlaybackRate, playback_rate); | 275 FORWARD_ON_IO_THREAD(SetPlaybackRate, playback_rate); |
| 280 } | 276 } |
| 281 | 277 |
| 282 } // namespace cma | 278 } // namespace cma |
| 283 } // namespace chromecast | 279 } // namespace chromecast |
| OLD | NEW |