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/audio_pipeline_proxy.h" | 5 #include "chromecast/renderer/media/audio_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" |
(...skipping 22 matching lines...) Expand all Loading... |
33 void IgnoreResult() { | 33 void IgnoreResult() { |
34 } | 34 } |
35 | 35 |
36 } // namespace | 36 } // namespace |
37 | 37 |
38 // AudioPipelineProxyInternal - | 38 // AudioPipelineProxyInternal - |
39 // This class is not thread safe and should run on the same thread | 39 // This class is not thread safe and should run on the same thread |
40 // as the media channel proxy. | 40 // as the media channel proxy. |
41 class AudioPipelineProxyInternal { | 41 class AudioPipelineProxyInternal { |
42 public: | 42 public: |
43 typedef base::Callback<void(scoped_ptr<base::SharedMemory>)> SharedMemCB; | 43 typedef base::Callback<void(std::unique_ptr<base::SharedMemory>)> SharedMemCB; |
44 | 44 |
45 static void Release(scoped_ptr<AudioPipelineProxyInternal> proxy); | 45 static void Release(std::unique_ptr<AudioPipelineProxyInternal> proxy); |
46 | 46 |
47 explicit AudioPipelineProxyInternal( | 47 explicit AudioPipelineProxyInternal( |
48 scoped_refptr<MediaChannelProxy> media_channel_proxy); | 48 scoped_refptr<MediaChannelProxy> media_channel_proxy); |
49 virtual ~AudioPipelineProxyInternal(); | 49 virtual ~AudioPipelineProxyInternal(); |
50 | 50 |
51 // Notify the other side (browser process) of some activity on the audio pipe. | 51 // Notify the other side (browser process) of some activity on the audio pipe. |
52 // TODO(erickung): either send an IPC message or write a byte on the | 52 // TODO(erickung): either send an IPC message or write a byte on the |
53 // SyncSocket. | 53 // SyncSocket. |
54 void NotifyPipeWrite(); | 54 void NotifyPipeWrite(); |
55 | 55 |
(...skipping 23 matching lines...) Expand all Loading... |
79 // Store the callback for a pending state transition. | 79 // Store the callback for a pending state transition. |
80 ::media::PipelineStatusCB status_cb_; | 80 ::media::PipelineStatusCB status_cb_; |
81 | 81 |
82 SharedMemCB shared_mem_cb_; | 82 SharedMemCB shared_mem_cb_; |
83 | 83 |
84 DISALLOW_COPY_AND_ASSIGN(AudioPipelineProxyInternal); | 84 DISALLOW_COPY_AND_ASSIGN(AudioPipelineProxyInternal); |
85 }; | 85 }; |
86 | 86 |
87 // static | 87 // static |
88 void AudioPipelineProxyInternal::Release( | 88 void AudioPipelineProxyInternal::Release( |
89 scoped_ptr<AudioPipelineProxyInternal> proxy) { | 89 std::unique_ptr<AudioPipelineProxyInternal> proxy) { |
90 proxy->Shutdown(); | 90 proxy->Shutdown(); |
91 } | 91 } |
92 | 92 |
93 AudioPipelineProxyInternal::AudioPipelineProxyInternal( | 93 AudioPipelineProxyInternal::AudioPipelineProxyInternal( |
94 scoped_refptr<MediaChannelProxy> media_channel_proxy) | 94 scoped_refptr<MediaChannelProxy> media_channel_proxy) |
95 : media_channel_proxy_(media_channel_proxy) { | 95 : media_channel_proxy_(media_channel_proxy) { |
96 DCHECK(media_channel_proxy.get()); | 96 DCHECK(media_channel_proxy.get()); |
97 | 97 |
98 // Creation can be done on a different thread. | 98 // Creation can be done on a different thread. |
99 thread_checker_.DetachFromThread(); | 99 thread_checker_.DetachFromThread(); |
100 } | 100 } |
101 | 101 |
102 AudioPipelineProxyInternal::~AudioPipelineProxyInternal() { | 102 AudioPipelineProxyInternal::~AudioPipelineProxyInternal() { |
103 } | 103 } |
104 | 104 |
105 void AudioPipelineProxyInternal::Shutdown() { | 105 void AudioPipelineProxyInternal::Shutdown() { |
106 DCHECK(thread_checker_.CalledOnValidThread()); | 106 DCHECK(thread_checker_.CalledOnValidThread()); |
107 | 107 |
108 // Remove any callback on AudioPipelineProxyInternal. | 108 // Remove any callback on AudioPipelineProxyInternal. |
109 media_channel_proxy_->SetAudioDelegate( | 109 media_channel_proxy_->SetAudioDelegate( |
110 CmaMessageFilterProxy::AudioDelegate()); | 110 CmaMessageFilterProxy::AudioDelegate()); |
111 } | 111 } |
112 | 112 |
113 void AudioPipelineProxyInternal::NotifyPipeWrite() { | 113 void AudioPipelineProxyInternal::NotifyPipeWrite() { |
114 DCHECK(thread_checker_.CalledOnValidThread()); | 114 DCHECK(thread_checker_.CalledOnValidThread()); |
115 | 115 |
116 // TODO(erickung): An alternative way would be to use a dedicated socket for | 116 // TODO(erickung): An alternative way would be to use a dedicated socket for |
117 // this event. | 117 // this event. |
118 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 118 bool success = media_channel_proxy_->Send( |
119 new CmaHostMsg_NotifyPipeWrite( | 119 std::unique_ptr<IPC::Message>(new CmaHostMsg_NotifyPipeWrite( |
120 media_channel_proxy_->GetId(), kAudioTrackId))); | 120 media_channel_proxy_->GetId(), kAudioTrackId))); |
121 VLOG_IF(4, !success) << "Sending msg failed"; | 121 VLOG_IF(4, !success) << "Sending msg failed"; |
122 } | 122 } |
123 | 123 |
124 void AudioPipelineProxyInternal::SetClient(const base::Closure& pipe_read_cb, | 124 void AudioPipelineProxyInternal::SetClient(const base::Closure& pipe_read_cb, |
125 const AvPipelineClient& client) { | 125 const AvPipelineClient& client) { |
126 DCHECK(thread_checker_.CalledOnValidThread()); | 126 DCHECK(thread_checker_.CalledOnValidThread()); |
127 | 127 |
128 CmaMessageFilterProxy::AudioDelegate delegate; | 128 CmaMessageFilterProxy::AudioDelegate delegate; |
129 delegate.av_pipe_cb = | 129 delegate.av_pipe_cb = |
130 base::Bind(&AudioPipelineProxyInternal::OnAvPipeCreated, | 130 base::Bind(&AudioPipelineProxyInternal::OnAvPipeCreated, |
131 base::Unretained(this)); | 131 base::Unretained(this)); |
132 delegate.state_changed_cb = | 132 delegate.state_changed_cb = |
133 base::Bind(&AudioPipelineProxyInternal::OnStateChanged, | 133 base::Bind(&AudioPipelineProxyInternal::OnStateChanged, |
134 base::Unretained(this)); | 134 base::Unretained(this)); |
135 delegate.pipe_read_cb = pipe_read_cb; | 135 delegate.pipe_read_cb = pipe_read_cb; |
136 delegate.client = client; | 136 delegate.client = client; |
137 bool success = media_channel_proxy_->SetAudioDelegate(delegate); | 137 bool success = media_channel_proxy_->SetAudioDelegate(delegate); |
138 CHECK(success); | 138 CHECK(success); |
139 } | 139 } |
140 | 140 |
141 void AudioPipelineProxyInternal::CreateAvPipe( | 141 void AudioPipelineProxyInternal::CreateAvPipe( |
142 const SharedMemCB& shared_mem_cb) { | 142 const SharedMemCB& shared_mem_cb) { |
143 DCHECK(thread_checker_.CalledOnValidThread()); | 143 DCHECK(thread_checker_.CalledOnValidThread()); |
144 DCHECK(shared_mem_cb_.is_null()); | 144 DCHECK(shared_mem_cb_.is_null()); |
145 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 145 bool success = media_channel_proxy_->Send( |
146 new CmaHostMsg_CreateAvPipe( | 146 std::unique_ptr<IPC::Message>(new CmaHostMsg_CreateAvPipe( |
147 media_channel_proxy_->GetId(), kAudioTrackId, kAppAudioBufferSize))); | 147 media_channel_proxy_->GetId(), kAudioTrackId, kAppAudioBufferSize))); |
148 if (!success) { | 148 if (!success) { |
149 shared_mem_cb.Run(scoped_ptr<base::SharedMemory>()); | 149 shared_mem_cb.Run(std::unique_ptr<base::SharedMemory>()); |
150 return; | 150 return; |
151 } | 151 } |
152 shared_mem_cb_ = shared_mem_cb; | 152 shared_mem_cb_ = shared_mem_cb; |
153 } | 153 } |
154 | 154 |
155 void AudioPipelineProxyInternal::OnAvPipeCreated( | 155 void AudioPipelineProxyInternal::OnAvPipeCreated( |
156 bool success, | 156 bool success, |
157 base::SharedMemoryHandle shared_mem_handle, | 157 base::SharedMemoryHandle shared_mem_handle, |
158 base::FileDescriptor socket) { | 158 base::FileDescriptor socket) { |
159 DCHECK(thread_checker_.CalledOnValidThread()); | 159 DCHECK(thread_checker_.CalledOnValidThread()); |
160 DCHECK(!shared_mem_cb_.is_null()); | 160 DCHECK(!shared_mem_cb_.is_null()); |
161 if (!success) { | 161 if (!success) { |
162 shared_mem_cb_.Run(scoped_ptr<base::SharedMemory>()); | 162 shared_mem_cb_.Run(std::unique_ptr<base::SharedMemory>()); |
163 return; | 163 return; |
164 } | 164 } |
165 | 165 |
166 CHECK(base::SharedMemory::IsHandleValid(shared_mem_handle)); | 166 CHECK(base::SharedMemory::IsHandleValid(shared_mem_handle)); |
167 shared_mem_cb_.Run(scoped_ptr<base::SharedMemory>( | 167 shared_mem_cb_.Run(std::unique_ptr<base::SharedMemory>( |
168 new base::SharedMemory(shared_mem_handle, false))); | 168 new base::SharedMemory(shared_mem_handle, false))); |
169 } | 169 } |
170 | 170 |
171 void AudioPipelineProxyInternal::Initialize( | 171 void AudioPipelineProxyInternal::Initialize( |
172 const ::media::AudioDecoderConfig& config, | 172 const ::media::AudioDecoderConfig& config, |
173 const ::media::PipelineStatusCB& status_cb) { | 173 const ::media::PipelineStatusCB& status_cb) { |
174 DCHECK(thread_checker_.CalledOnValidThread()); | 174 DCHECK(thread_checker_.CalledOnValidThread()); |
175 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 175 bool success = media_channel_proxy_->Send( |
176 new CmaHostMsg_AudioInitialize( | 176 std::unique_ptr<IPC::Message>(new CmaHostMsg_AudioInitialize( |
177 media_channel_proxy_->GetId(), kAudioTrackId, config))); | 177 media_channel_proxy_->GetId(), kAudioTrackId, config))); |
178 if (!success) { | 178 if (!success) { |
179 status_cb.Run( ::media::PIPELINE_ERROR_INITIALIZATION_FAILED); | 179 status_cb.Run( ::media::PIPELINE_ERROR_INITIALIZATION_FAILED); |
180 return; | 180 return; |
181 } | 181 } |
182 DCHECK(status_cb_.is_null()); | 182 DCHECK(status_cb_.is_null()); |
183 status_cb_ = status_cb; | 183 status_cb_ = status_cb; |
184 } | 184 } |
185 | 185 |
186 void AudioPipelineProxyInternal::SetVolume(float volume) { | 186 void AudioPipelineProxyInternal::SetVolume(float volume) { |
187 DCHECK(thread_checker_.CalledOnValidThread()); | 187 DCHECK(thread_checker_.CalledOnValidThread()); |
188 media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 188 media_channel_proxy_->Send( |
189 new CmaHostMsg_SetVolume(media_channel_proxy_->GetId(), | 189 std::unique_ptr<IPC::Message>(new CmaHostMsg_SetVolume( |
190 kAudioTrackId, volume))); | 190 media_channel_proxy_->GetId(), kAudioTrackId, volume))); |
191 } | 191 } |
192 | 192 |
193 void AudioPipelineProxyInternal::OnStateChanged( | 193 void AudioPipelineProxyInternal::OnStateChanged( |
194 ::media::PipelineStatus status) { | 194 ::media::PipelineStatus status) { |
195 DCHECK(thread_checker_.CalledOnValidThread()); | 195 DCHECK(thread_checker_.CalledOnValidThread()); |
196 DCHECK(!status_cb_.is_null()); | 196 DCHECK(!status_cb_.is_null()); |
197 base::ResetAndReturn(&status_cb_).Run(status); | 197 base::ResetAndReturn(&status_cb_).Run(status); |
198 } | 198 } |
199 | 199 |
200 // A macro runs current member function on |io_task_runner_| thread. | 200 // A macro runs current member function on |io_task_runner_| thread. |
(...skipping 24 matching lines...) Expand all Loading... |
225 | 225 |
226 void AudioPipelineProxy::SetClient(const AvPipelineClient& client) { | 226 void AudioPipelineProxy::SetClient(const AvPipelineClient& client) { |
227 DCHECK(thread_checker_.CalledOnValidThread()); | 227 DCHECK(thread_checker_.CalledOnValidThread()); |
228 base::Closure pipe_read_cb = ::media::BindToCurrentLoop( | 228 base::Closure pipe_read_cb = ::media::BindToCurrentLoop( |
229 base::Bind(&AudioPipelineProxy::OnPipeRead, weak_this_)); | 229 base::Bind(&AudioPipelineProxy::OnPipeRead, weak_this_)); |
230 FORWARD_ON_IO_THREAD(SetClient, pipe_read_cb, client); | 230 FORWARD_ON_IO_THREAD(SetClient, pipe_read_cb, client); |
231 } | 231 } |
232 | 232 |
233 void AudioPipelineProxy::Initialize( | 233 void AudioPipelineProxy::Initialize( |
234 const ::media::AudioDecoderConfig& config, | 234 const ::media::AudioDecoderConfig& config, |
235 scoped_ptr<CodedFrameProvider> frame_provider, | 235 std::unique_ptr<CodedFrameProvider> frame_provider, |
236 const ::media::PipelineStatusCB& status_cb) { | 236 const ::media::PipelineStatusCB& status_cb) { |
237 CMALOG(kLogControl) << "AudioPipelineProxy::Initialize"; | 237 CMALOG(kLogControl) << "AudioPipelineProxy::Initialize"; |
238 DCHECK(thread_checker_.CalledOnValidThread()); | 238 DCHECK(thread_checker_.CalledOnValidThread()); |
239 audio_streamer_->SetCodedFrameProvider(std::move(frame_provider)); | 239 audio_streamer_->SetCodedFrameProvider(std::move(frame_provider)); |
240 | 240 |
241 AudioPipelineProxyInternal::SharedMemCB shared_mem_cb = | 241 AudioPipelineProxyInternal::SharedMemCB shared_mem_cb = |
242 ::media::BindToCurrentLoop(base::Bind( | 242 ::media::BindToCurrentLoop(base::Bind( |
243 &AudioPipelineProxy::OnAvPipeCreated, weak_this_, | 243 &AudioPipelineProxy::OnAvPipeCreated, weak_this_, |
244 config, status_cb)); | 244 config, status_cb)); |
245 FORWARD_ON_IO_THREAD(CreateAvPipe, shared_mem_cb); | 245 FORWARD_ON_IO_THREAD(CreateAvPipe, shared_mem_cb); |
246 } | 246 } |
247 | 247 |
248 void AudioPipelineProxy::OnAvPipeCreated( | 248 void AudioPipelineProxy::OnAvPipeCreated( |
249 const ::media::AudioDecoderConfig& config, | 249 const ::media::AudioDecoderConfig& config, |
250 const ::media::PipelineStatusCB& status_cb, | 250 const ::media::PipelineStatusCB& status_cb, |
251 scoped_ptr<base::SharedMemory> shared_memory) { | 251 std::unique_ptr<base::SharedMemory> shared_memory) { |
252 CMALOG(kLogControl) << "AudioPipelineProxy::OnAvPipeCreated"; | 252 CMALOG(kLogControl) << "AudioPipelineProxy::OnAvPipeCreated"; |
253 DCHECK(thread_checker_.CalledOnValidThread()); | 253 DCHECK(thread_checker_.CalledOnValidThread()); |
254 if (!shared_memory || | 254 if (!shared_memory || |
255 !shared_memory->Map(kAppAudioBufferSize)) { | 255 !shared_memory->Map(kAppAudioBufferSize)) { |
256 status_cb.Run(::media::PIPELINE_ERROR_INITIALIZATION_FAILED); | 256 status_cb.Run(::media::PIPELINE_ERROR_INITIALIZATION_FAILED); |
257 return; | 257 return; |
258 } | 258 } |
259 CHECK(shared_memory->memory()); | 259 CHECK(shared_memory->memory()); |
260 | 260 |
261 scoped_ptr<MediaMemoryChunk> shared_memory_chunk( | 261 std::unique_ptr<MediaMemoryChunk> shared_memory_chunk( |
262 new SharedMemoryChunk(std::move(shared_memory), kAppAudioBufferSize)); | 262 new SharedMemoryChunk(std::move(shared_memory), kAppAudioBufferSize)); |
263 scoped_ptr<MediaMessageFifo> audio_pipe( | 263 std::unique_ptr<MediaMessageFifo> audio_pipe( |
264 new MediaMessageFifo(std::move(shared_memory_chunk), false)); | 264 new MediaMessageFifo(std::move(shared_memory_chunk), false)); |
265 audio_pipe->ObserveWriteActivity( | 265 audio_pipe->ObserveWriteActivity( |
266 base::Bind(&AudioPipelineProxy::OnPipeWrite, weak_this_)); | 266 base::Bind(&AudioPipelineProxy::OnPipeWrite, weak_this_)); |
267 | 267 |
268 audio_streamer_->SetMediaMessageFifo(std::move(audio_pipe)); | 268 audio_streamer_->SetMediaMessageFifo(std::move(audio_pipe)); |
269 | 269 |
270 // Now proceed to the decoder/renderer initialization. | 270 // Now proceed to the decoder/renderer initialization. |
271 FORWARD_ON_IO_THREAD(Initialize, config, status_cb); | 271 FORWARD_ON_IO_THREAD(Initialize, config, status_cb); |
272 } | 272 } |
273 | 273 |
(...skipping 27 matching lines...) Expand all Loading... |
301 } | 301 } |
302 | 302 |
303 void AudioPipelineProxy::OnPipeRead() { | 303 void AudioPipelineProxy::OnPipeRead() { |
304 DCHECK(thread_checker_.CalledOnValidThread()); | 304 DCHECK(thread_checker_.CalledOnValidThread()); |
305 if (audio_streamer_) | 305 if (audio_streamer_) |
306 audio_streamer_->OnFifoReadEvent(); | 306 audio_streamer_->OnFifoReadEvent(); |
307 } | 307 } |
308 | 308 |
309 } // namespace cma | 309 } // namespace cma |
310 } // namespace chromecast | 310 } // namespace chromecast |
OLD | NEW |