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/video_pipeline_proxy.h" | 5 #include "chromecast/renderer/media/video_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/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
49 // TODO(erickung): either send an IPC message or write a byte on the | 49 // TODO(erickung): either send an IPC message or write a byte on the |
50 // SyncSocket. | 50 // SyncSocket. |
51 void NotifyPipeWrite(); | 51 void NotifyPipeWrite(); |
52 | 52 |
53 // These functions are almost a one to one correspondence with VideoPipeline | 53 // These functions are almost a one to one correspondence with VideoPipeline |
54 // but this is an internal class and there is no reason to derive from | 54 // but this is an internal class and there is no reason to derive from |
55 // VideoPipeline. | 55 // VideoPipeline. |
56 void SetClient(const base::Closure& pipe_read_cb, | 56 void SetClient(const base::Closure& pipe_read_cb, |
57 const VideoPipelineClient& client); | 57 const VideoPipelineClient& client); |
58 void CreateAvPipe(const SharedMemCB& shared_mem_cb); | 58 void CreateAvPipe(const SharedMemCB& shared_mem_cb); |
59 void Initialize(const ::media::VideoDecoderConfig& config, | 59 void Initialize(const std::vector<::media::VideoDecoderConfig>& configs, |
60 const ::media::PipelineStatusCB& status_cb); | 60 const ::media::PipelineStatusCB& status_cb); |
61 | 61 |
62 private: | 62 private: |
63 void Shutdown(); | 63 void Shutdown(); |
64 | 64 |
65 // Callbacks for CmaMessageFilterHost::VideoDelegate. | 65 // Callbacks for CmaMessageFilterHost::VideoDelegate. |
66 void OnAvPipeCreated(bool status, | 66 void OnAvPipeCreated(bool status, |
67 base::SharedMemoryHandle shared_mem_handle, | 67 base::SharedMemoryHandle shared_mem_handle, |
68 base::FileDescriptor socket); | 68 base::FileDescriptor socket); |
69 void OnStateChanged(::media::PipelineStatus status); | 69 void OnStateChanged(::media::PipelineStatus status); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 shared_mem_cb_.Run(scoped_ptr<base::SharedMemory>()); | 159 shared_mem_cb_.Run(scoped_ptr<base::SharedMemory>()); |
160 return; | 160 return; |
161 } | 161 } |
162 | 162 |
163 CHECK(base::SharedMemory::IsHandleValid(shared_mem_handle)); | 163 CHECK(base::SharedMemory::IsHandleValid(shared_mem_handle)); |
164 shared_mem_cb_.Run(scoped_ptr<base::SharedMemory>( | 164 shared_mem_cb_.Run(scoped_ptr<base::SharedMemory>( |
165 new base::SharedMemory(shared_mem_handle, false))); | 165 new base::SharedMemory(shared_mem_handle, false))); |
166 } | 166 } |
167 | 167 |
168 void VideoPipelineProxyInternal::Initialize( | 168 void VideoPipelineProxyInternal::Initialize( |
169 const ::media::VideoDecoderConfig& arg1, | 169 const std::vector<::media::VideoDecoderConfig>& configs, |
170 const ::media::PipelineStatusCB& status_cb) { | 170 const ::media::PipelineStatusCB& status_cb) { |
171 DCHECK(thread_checker_.CalledOnValidThread()); | 171 DCHECK(thread_checker_.CalledOnValidThread()); |
172 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( | 172 bool success = media_channel_proxy_->Send(scoped_ptr<IPC::Message>( |
173 new CmaHostMsg_VideoInitialize(media_channel_proxy_->GetId(), | 173 new CmaHostMsg_VideoInitialize(media_channel_proxy_->GetId(), |
174 kVideoTrackId, arg1))); | 174 kVideoTrackId, configs))); |
175 if (!success) { | 175 if (!success) { |
176 status_cb.Run( ::media::PIPELINE_ERROR_INITIALIZATION_FAILED); | 176 status_cb.Run( ::media::PIPELINE_ERROR_INITIALIZATION_FAILED); |
177 return; | 177 return; |
178 } | 178 } |
179 DCHECK(status_cb_.is_null()); | 179 DCHECK(status_cb_.is_null()); |
180 status_cb_ = status_cb; | 180 status_cb_ = status_cb; |
181 } | 181 } |
182 | 182 |
183 void VideoPipelineProxyInternal::OnStateChanged( | 183 void VideoPipelineProxyInternal::OnStateChanged( |
184 ::media::PipelineStatus status) { | 184 ::media::PipelineStatus status) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 void VideoPipelineProxy::SetClient( | 216 void VideoPipelineProxy::SetClient( |
217 const VideoPipelineClient& video_client) { | 217 const VideoPipelineClient& video_client) { |
218 DCHECK(thread_checker_.CalledOnValidThread()); | 218 DCHECK(thread_checker_.CalledOnValidThread()); |
219 base::Closure pipe_read_cb = | 219 base::Closure pipe_read_cb = |
220 ::media::BindToCurrentLoop( | 220 ::media::BindToCurrentLoop( |
221 base::Bind(&VideoPipelineProxy::OnPipeRead, weak_this_)); | 221 base::Bind(&VideoPipelineProxy::OnPipeRead, weak_this_)); |
222 FORWARD_ON_IO_THREAD(SetClient, pipe_read_cb, video_client); | 222 FORWARD_ON_IO_THREAD(SetClient, pipe_read_cb, video_client); |
223 } | 223 } |
224 | 224 |
225 void VideoPipelineProxy::Initialize( | 225 void VideoPipelineProxy::Initialize( |
226 const ::media::VideoDecoderConfig& config, | 226 const std::vector<::media::VideoDecoderConfig>& configs, |
227 scoped_ptr<CodedFrameProvider> frame_provider, | 227 scoped_ptr<CodedFrameProvider> frame_provider, |
228 const ::media::PipelineStatusCB& status_cb) { | 228 const ::media::PipelineStatusCB& status_cb) { |
229 CMALOG(kLogControl) << "VideoPipelineProxy::Initialize"; | 229 CMALOG(kLogControl) << "VideoPipelineProxy::Initialize"; |
230 DCHECK(thread_checker_.CalledOnValidThread()); | 230 DCHECK(thread_checker_.CalledOnValidThread()); |
231 video_streamer_->SetCodedFrameProvider(frame_provider.Pass()); | 231 video_streamer_->SetCodedFrameProvider(frame_provider.Pass()); |
232 | 232 |
233 VideoPipelineProxyInternal::SharedMemCB shared_mem_cb = | 233 VideoPipelineProxyInternal::SharedMemCB shared_mem_cb = |
234 ::media::BindToCurrentLoop(base::Bind( | 234 ::media::BindToCurrentLoop(base::Bind( |
235 &VideoPipelineProxy::OnAvPipeCreated, weak_this_, | 235 &VideoPipelineProxy::OnAvPipeCreated, weak_this_, |
236 config, status_cb)); | 236 configs, status_cb)); |
237 FORWARD_ON_IO_THREAD(CreateAvPipe, shared_mem_cb); | 237 FORWARD_ON_IO_THREAD(CreateAvPipe, shared_mem_cb); |
238 } | 238 } |
239 | 239 |
240 void VideoPipelineProxy::OnAvPipeCreated( | 240 void VideoPipelineProxy::OnAvPipeCreated( |
241 const ::media::VideoDecoderConfig& config, | 241 const std::vector<::media::VideoDecoderConfig>& configs, |
242 const ::media::PipelineStatusCB& status_cb, | 242 const ::media::PipelineStatusCB& status_cb, |
243 scoped_ptr<base::SharedMemory> shared_memory) { | 243 scoped_ptr<base::SharedMemory> shared_memory) { |
244 CMALOG(kLogControl) << "VideoPipelineProxy::OnAvPipeCreated"; | 244 CMALOG(kLogControl) << "VideoPipelineProxy::OnAvPipeCreated"; |
245 DCHECK(thread_checker_.CalledOnValidThread()); | 245 DCHECK(thread_checker_.CalledOnValidThread()); |
246 if (!shared_memory || | 246 if (!shared_memory || |
247 !shared_memory->Map(kAppVideoBufferSize)) { | 247 !shared_memory->Map(kAppVideoBufferSize)) { |
248 status_cb.Run(::media::PIPELINE_ERROR_INITIALIZATION_FAILED); | 248 status_cb.Run(::media::PIPELINE_ERROR_INITIALIZATION_FAILED); |
249 return; | 249 return; |
250 } | 250 } |
251 CHECK(shared_memory->memory()); | 251 CHECK(shared_memory->memory()); |
252 | 252 |
253 scoped_ptr<MediaMemoryChunk> shared_memory_chunk( | 253 scoped_ptr<MediaMemoryChunk> shared_memory_chunk( |
254 new SharedMemoryChunk(shared_memory.Pass(), kAppVideoBufferSize)); | 254 new SharedMemoryChunk(shared_memory.Pass(), kAppVideoBufferSize)); |
255 scoped_ptr<MediaMessageFifo> video_pipe( | 255 scoped_ptr<MediaMessageFifo> video_pipe( |
256 new MediaMessageFifo(shared_memory_chunk.Pass(), false)); | 256 new MediaMessageFifo(shared_memory_chunk.Pass(), false)); |
257 video_pipe->ObserveWriteActivity( | 257 video_pipe->ObserveWriteActivity( |
258 base::Bind(&VideoPipelineProxy::OnPipeWrite, weak_this_)); | 258 base::Bind(&VideoPipelineProxy::OnPipeWrite, weak_this_)); |
259 | 259 |
260 video_streamer_->SetMediaMessageFifo(video_pipe.Pass()); | 260 video_streamer_->SetMediaMessageFifo(video_pipe.Pass()); |
261 | 261 |
262 // Now proceed to the decoder/renderer initialization. | 262 // Now proceed to the decoder/renderer initialization. |
263 FORWARD_ON_IO_THREAD(Initialize, config, status_cb); | 263 FORWARD_ON_IO_THREAD(Initialize, configs, status_cb); |
264 } | 264 } |
265 | 265 |
266 void VideoPipelineProxy::StartFeeding() { | 266 void VideoPipelineProxy::StartFeeding() { |
267 DCHECK(thread_checker_.CalledOnValidThread()); | 267 DCHECK(thread_checker_.CalledOnValidThread()); |
268 DCHECK(video_streamer_); | 268 DCHECK(video_streamer_); |
269 video_streamer_->Start(); | 269 video_streamer_->Start(); |
270 } | 270 } |
271 | 271 |
272 void VideoPipelineProxy::Flush(const base::Closure& done_cb) { | 272 void VideoPipelineProxy::Flush(const base::Closure& done_cb) { |
273 DCHECK(thread_checker_.CalledOnValidThread()); | 273 DCHECK(thread_checker_.CalledOnValidThread()); |
(...skipping 14 matching lines...) Expand all Loading... |
288 } | 288 } |
289 | 289 |
290 void VideoPipelineProxy::OnPipeRead() { | 290 void VideoPipelineProxy::OnPipeRead() { |
291 DCHECK(thread_checker_.CalledOnValidThread()); | 291 DCHECK(thread_checker_.CalledOnValidThread()); |
292 if (video_streamer_) | 292 if (video_streamer_) |
293 video_streamer_->OnFifoReadEvent(); | 293 video_streamer_->OnFifoReadEvent(); |
294 } | 294 } |
295 | 295 |
296 } // namespace media | 296 } // namespace media |
297 } // namespace chromecast | 297 } // namespace chromecast |
OLD | NEW |