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 <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/callback_helpers.h" | 10 #include "base/callback_helpers.h" |
11 #include "base/location.h" | 11 #include "base/location.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/single_thread_task_runner.h" | 14 #include "base/single_thread_task_runner.h" |
15 #include "chromecast/common/media/cma_messages.h" | 15 #include "chromecast/common/media/cma_messages.h" |
16 #include "chromecast/media/cma/base/coded_frame_provider.h" | 16 #include "chromecast/media/cma/base/coded_frame_provider.h" |
17 #include "chromecast/renderer/media/audio_pipeline_proxy.h" | 17 #include "chromecast/renderer/media/audio_pipeline_proxy.h" |
18 #include "chromecast/renderer/media/media_channel_proxy.h" | 18 #include "chromecast/renderer/media/media_channel_proxy.h" |
19 #include "chromecast/renderer/media/video_pipeline_proxy.h" | 19 #include "chromecast/renderer/media/video_pipeline_proxy.h" |
20 | 20 |
21 namespace chromecast { | 21 namespace chromecast { |
22 namespace media { | 22 namespace media { |
23 | 23 |
24 // MediaPipelineProxyInternal - | 24 // MediaPipelineProxyInternal - |
25 // This class is not thread safe and should run on the same thread | 25 // This class is not thread safe and should run on the same thread |
26 // as the media channel proxy. | 26 // as the media channel proxy. |
27 class MediaPipelineProxyInternal { | 27 class MediaPipelineProxyInternal { |
28 public: | 28 public: |
29 static void Release(scoped_ptr<MediaPipelineProxyInternal> proxy); | 29 static void Release(std::unique_ptr<MediaPipelineProxyInternal> proxy); |
30 | 30 |
31 explicit MediaPipelineProxyInternal( | 31 explicit MediaPipelineProxyInternal( |
32 scoped_refptr<MediaChannelProxy> media_channel_proxy); | 32 scoped_refptr<MediaChannelProxy> media_channel_proxy); |
33 virtual ~MediaPipelineProxyInternal(); | 33 virtual ~MediaPipelineProxyInternal(); |
34 | 34 |
35 void SetClient(const MediaPipelineClient& client); | 35 void SetClient(const MediaPipelineClient& client); |
36 void SetCdm(int render_frame_id, int cdm_id); | 36 void SetCdm(int render_frame_id, int cdm_id); |
37 void StartPlayingFrom(const base::TimeDelta& time); | 37 void StartPlayingFrom(const base::TimeDelta& time); |
38 void Flush(const base::Closure& flush_cb); | 38 void Flush(const base::Closure& flush_cb); |
39 void Stop(); | 39 void Stop(); |
(...skipping 12 matching lines...) Expand all Loading... |
52 MediaPipelineClient client_; | 52 MediaPipelineClient client_; |
53 | 53 |
54 // Store the callback for a flush. | 54 // Store the callback for a flush. |
55 base::Closure flush_cb_; | 55 base::Closure flush_cb_; |
56 | 56 |
57 DISALLOW_COPY_AND_ASSIGN(MediaPipelineProxyInternal); | 57 DISALLOW_COPY_AND_ASSIGN(MediaPipelineProxyInternal); |
58 }; | 58 }; |
59 | 59 |
60 // static | 60 // static |
61 void MediaPipelineProxyInternal::Release( | 61 void MediaPipelineProxyInternal::Release( |
62 scoped_ptr<MediaPipelineProxyInternal> proxy) { | 62 std::unique_ptr<MediaPipelineProxyInternal> proxy) { |
63 proxy->Shutdown(); | 63 proxy->Shutdown(); |
64 } | 64 } |
65 | 65 |
66 MediaPipelineProxyInternal::MediaPipelineProxyInternal( | 66 MediaPipelineProxyInternal::MediaPipelineProxyInternal( |
67 scoped_refptr<MediaChannelProxy> media_channel_proxy) | 67 scoped_refptr<MediaChannelProxy> media_channel_proxy) |
68 : media_channel_proxy_(media_channel_proxy) { | 68 : media_channel_proxy_(media_channel_proxy) { |
69 DCHECK(media_channel_proxy.get()); | 69 DCHECK(media_channel_proxy.get()); |
70 | 70 |
71 // Creation can be done on a different thread. | 71 // Creation can be done on a different thread. |
72 thread_checker_.DetachFromThread(); | 72 thread_checker_.DetachFromThread(); |
(...skipping 19 matching lines...) Expand all Loading... |
92 CmaMessageFilterProxy::MediaDelegate delegate; | 92 CmaMessageFilterProxy::MediaDelegate delegate; |
93 delegate.flush_cb = base::Bind(&MediaPipelineProxyInternal::OnFlushDone, | 93 delegate.flush_cb = base::Bind(&MediaPipelineProxyInternal::OnFlushDone, |
94 base::Unretained(this)); | 94 base::Unretained(this)); |
95 delegate.client = client; | 95 delegate.client = client; |
96 bool success = media_channel_proxy_->SetMediaDelegate(delegate); | 96 bool success = media_channel_proxy_->SetMediaDelegate(delegate); |
97 CHECK(success); | 97 CHECK(success); |
98 } | 98 } |
99 | 99 |
100 void MediaPipelineProxyInternal::SetCdm(int render_frame_id, int cdm_id) { | 100 void MediaPipelineProxyInternal::SetCdm(int render_frame_id, int cdm_id) { |
101 DCHECK(thread_checker_.CalledOnValidThread()); | 101 DCHECK(thread_checker_.CalledOnValidThread()); |
102 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 102 bool success = media_channel_proxy_->Send( |
103 new CmaHostMsg_SetCdm(media_channel_proxy_->GetId(), | 103 std::unique_ptr<IPC::Message>(new CmaHostMsg_SetCdm( |
104 render_frame_id, | 104 media_channel_proxy_->GetId(), render_frame_id, cdm_id))); |
105 cdm_id))); | |
106 LOG_IF(ERROR, !success) << "Failed to send SetCdm=" << cdm_id; | 105 LOG_IF(ERROR, !success) << "Failed to send SetCdm=" << cdm_id; |
107 } | 106 } |
108 | 107 |
109 void MediaPipelineProxyInternal::Flush(const base::Closure& flush_cb) { | 108 void MediaPipelineProxyInternal::Flush(const base::Closure& flush_cb) { |
110 DCHECK(thread_checker_.CalledOnValidThread()); | 109 DCHECK(thread_checker_.CalledOnValidThread()); |
111 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 110 bool success = media_channel_proxy_->Send(std::unique_ptr<IPC::Message>( |
112 new CmaHostMsg_Flush(media_channel_proxy_->GetId()))); | 111 new CmaHostMsg_Flush(media_channel_proxy_->GetId()))); |
113 if (!success) { | 112 if (!success) { |
114 LOG(ERROR) << "Failed to send Flush"; | 113 LOG(ERROR) << "Failed to send Flush"; |
115 return; | 114 return; |
116 } | 115 } |
117 DCHECK(flush_cb_.is_null()); | 116 DCHECK(flush_cb_.is_null()); |
118 flush_cb_ = flush_cb; | 117 flush_cb_ = flush_cb; |
119 } | 118 } |
120 | 119 |
121 void MediaPipelineProxyInternal::Stop() { | 120 void MediaPipelineProxyInternal::Stop() { |
122 DCHECK(thread_checker_.CalledOnValidThread()); | 121 DCHECK(thread_checker_.CalledOnValidThread()); |
123 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 122 bool success = media_channel_proxy_->Send(std::unique_ptr<IPC::Message>( |
124 new CmaHostMsg_Stop(media_channel_proxy_->GetId()))); | 123 new CmaHostMsg_Stop(media_channel_proxy_->GetId()))); |
125 if (!success) | 124 if (!success) |
126 client_.error_cb.Run(::media::PIPELINE_ERROR_ABORT); | 125 client_.error_cb.Run(::media::PIPELINE_ERROR_ABORT); |
127 } | 126 } |
128 | 127 |
129 void MediaPipelineProxyInternal::StartPlayingFrom(const base::TimeDelta& time) { | 128 void MediaPipelineProxyInternal::StartPlayingFrom(const base::TimeDelta& time) { |
130 DCHECK(thread_checker_.CalledOnValidThread()); | 129 DCHECK(thread_checker_.CalledOnValidThread()); |
131 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 130 bool success = media_channel_proxy_->Send(std::unique_ptr<IPC::Message>( |
132 new CmaHostMsg_StartPlayingFrom( | 131 new CmaHostMsg_StartPlayingFrom(media_channel_proxy_->GetId(), time))); |
133 media_channel_proxy_->GetId(), time))); | |
134 if (!success) | 132 if (!success) |
135 client_.error_cb.Run(::media::PIPELINE_ERROR_ABORT); | 133 client_.error_cb.Run(::media::PIPELINE_ERROR_ABORT); |
136 } | 134 } |
137 | 135 |
138 void MediaPipelineProxyInternal::SetPlaybackRate(double playback_rate) { | 136 void MediaPipelineProxyInternal::SetPlaybackRate(double playback_rate) { |
139 DCHECK(thread_checker_.CalledOnValidThread()); | 137 DCHECK(thread_checker_.CalledOnValidThread()); |
140 media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 138 media_channel_proxy_->Send( |
141 new CmaHostMsg_SetPlaybackRate( | 139 std::unique_ptr<IPC::Message>(new CmaHostMsg_SetPlaybackRate( |
142 media_channel_proxy_->GetId(), playback_rate))); | 140 media_channel_proxy_->GetId(), playback_rate))); |
143 } | 141 } |
144 | 142 |
145 void MediaPipelineProxyInternal::OnFlushDone() { | 143 void MediaPipelineProxyInternal::OnFlushDone() { |
146 DCHECK(thread_checker_.CalledOnValidThread()); | 144 DCHECK(thread_checker_.CalledOnValidThread()); |
147 DCHECK(!flush_cb_.is_null()); | 145 DCHECK(!flush_cb_.is_null()); |
148 base::ResetAndReturn(&flush_cb_).Run(); | 146 base::ResetAndReturn(&flush_cb_).Run(); |
149 } | 147 } |
150 | 148 |
151 // A macro runs current member function on |io_task_runner_| thread. | 149 // A macro runs current member function on |io_task_runner_| thread. |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 AudioPipelineProxy* MediaPipelineProxy::GetAudioPipeline() const { | 195 AudioPipelineProxy* MediaPipelineProxy::GetAudioPipeline() const { |
198 return audio_pipeline_.get(); | 196 return audio_pipeline_.get(); |
199 } | 197 } |
200 | 198 |
201 VideoPipelineProxy* MediaPipelineProxy::GetVideoPipeline() const { | 199 VideoPipelineProxy* MediaPipelineProxy::GetVideoPipeline() const { |
202 return video_pipeline_.get(); | 200 return video_pipeline_.get(); |
203 } | 201 } |
204 | 202 |
205 void MediaPipelineProxy::InitializeAudio( | 203 void MediaPipelineProxy::InitializeAudio( |
206 const ::media::AudioDecoderConfig& config, | 204 const ::media::AudioDecoderConfig& config, |
207 scoped_ptr<CodedFrameProvider> frame_provider, | 205 std::unique_ptr<CodedFrameProvider> frame_provider, |
208 const ::media::PipelineStatusCB& status_cb) { | 206 const ::media::PipelineStatusCB& status_cb) { |
209 DCHECK(thread_checker_.CalledOnValidThread()); | 207 DCHECK(thread_checker_.CalledOnValidThread()); |
210 has_audio_ = true; | 208 has_audio_ = true; |
211 audio_pipeline_->Initialize(config, std::move(frame_provider), status_cb); | 209 audio_pipeline_->Initialize(config, std::move(frame_provider), status_cb); |
212 } | 210 } |
213 | 211 |
214 void MediaPipelineProxy::InitializeVideo( | 212 void MediaPipelineProxy::InitializeVideo( |
215 const std::vector<::media::VideoDecoderConfig>& configs, | 213 const std::vector<::media::VideoDecoderConfig>& configs, |
216 scoped_ptr<CodedFrameProvider> frame_provider, | 214 std::unique_ptr<CodedFrameProvider> frame_provider, |
217 const ::media::PipelineStatusCB& status_cb) { | 215 const ::media::PipelineStatusCB& status_cb) { |
218 DCHECK(thread_checker_.CalledOnValidThread()); | 216 DCHECK(thread_checker_.CalledOnValidThread()); |
219 has_video_ = true; | 217 has_video_ = true; |
220 video_pipeline_->Initialize(configs, std::move(frame_provider), status_cb); | 218 video_pipeline_->Initialize(configs, std::move(frame_provider), status_cb); |
221 } | 219 } |
222 | 220 |
223 void MediaPipelineProxy::StartPlayingFrom(base::TimeDelta time) { | 221 void MediaPipelineProxy::StartPlayingFrom(base::TimeDelta time) { |
224 DCHECK(thread_checker_.CalledOnValidThread()); | 222 DCHECK(thread_checker_.CalledOnValidThread()); |
225 if (has_audio_) | 223 if (has_audio_) |
226 audio_pipeline_->StartFeeding(); | 224 audio_pipeline_->StartFeeding(); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
272 FORWARD_ON_IO_THREAD(Stop); | 270 FORWARD_ON_IO_THREAD(Stop); |
273 } | 271 } |
274 | 272 |
275 void MediaPipelineProxy::SetPlaybackRate(double playback_rate) { | 273 void MediaPipelineProxy::SetPlaybackRate(double playback_rate) { |
276 DCHECK(thread_checker_.CalledOnValidThread()); | 274 DCHECK(thread_checker_.CalledOnValidThread()); |
277 FORWARD_ON_IO_THREAD(SetPlaybackRate, playback_rate); | 275 FORWARD_ON_IO_THREAD(SetPlaybackRate, playback_rate); |
278 } | 276 } |
279 | 277 |
280 } // namespace cma | 278 } // namespace cma |
281 } // namespace chromecast | 279 } // namespace chromecast |
OLD | NEW |