| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "content/renderer/gpu/gpu_video_service_host.h" | 5 #include "content/renderer/gpu/gpu_video_service_host.h" |
| 6 | 6 |
| 7 #include "content/common/gpu/gpu_messages.h" | 7 #include "content/common/gpu/gpu_messages.h" |
| 8 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" | 8 #include "content/renderer/gpu/gpu_video_decode_accelerator_host.h" |
| 9 #include "content/renderer/render_thread.h" | 9 #include "content/renderer/render_thread.h" |
| 10 #include "media/video/video_decode_accelerator.h" | 10 #include "media/video/video_decode_accelerator.h" |
| 11 | 11 |
| 12 GpuVideoServiceHost::GpuVideoServiceHost() | 12 GpuVideoServiceHost::GpuVideoServiceHost() |
| 13 : channel_(NULL), | 13 : channel_(NULL), |
| 14 next_decoder_host_id_(0) { | 14 next_decoder_host_id_(0) { |
| 15 DCHECK(RenderThread::current()); |
| 16 DCHECK_EQ(RenderThread::current()->message_loop(), MessageLoop::current()); |
| 15 } | 17 } |
| 16 | 18 |
| 17 GpuVideoServiceHost::~GpuVideoServiceHost() { | 19 GpuVideoServiceHost::~GpuVideoServiceHost() { |
| 18 } | 20 } |
| 19 | 21 |
| 20 void GpuVideoServiceHost::OnFilterAdded(IPC::Channel* channel) { | 22 void GpuVideoServiceHost::set_channel(IPC::SyncChannel* channel) { |
| 21 base::Closure on_initialized; | 23 DCHECK(CalledOnValidThread()); |
| 22 { | 24 DCHECK(!channel_); |
| 23 base::AutoLock auto_lock(lock_); | 25 channel_ = channel; |
| 24 DCHECK(!channel_); | 26 if (!on_initialized_.is_null()) |
| 25 channel_ = channel; | 27 on_initialized_.Run(); |
| 26 on_initialized = on_initialized_; | |
| 27 } | |
| 28 if (!on_initialized.is_null()) | |
| 29 on_initialized.Run(); | |
| 30 } | |
| 31 | |
| 32 void GpuVideoServiceHost::OnFilterRemoved() { | |
| 33 // TODO(hclam): Implement. | |
| 34 } | |
| 35 | |
| 36 void GpuVideoServiceHost::OnChannelClosing() { | |
| 37 // TODO(hclam): Implement. | |
| 38 } | 28 } |
| 39 | 29 |
| 40 bool GpuVideoServiceHost::OnMessageReceived(const IPC::Message& msg) { | 30 bool GpuVideoServiceHost::OnMessageReceived(const IPC::Message& msg) { |
| 31 DCHECK(CalledOnValidThread()); |
| 32 if (!channel_) |
| 33 return false; |
| 41 switch (msg.type()) { | 34 switch (msg.type()) { |
| 42 case AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed::ID: | 35 case AcceleratedVideoDecoderHostMsg_BitstreamBufferProcessed::ID: |
| 43 case AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers::ID: | 36 case AcceleratedVideoDecoderHostMsg_ProvidePictureBuffers::ID: |
| 44 case AcceleratedVideoDecoderHostMsg_CreateDone::ID: | 37 case AcceleratedVideoDecoderHostMsg_CreateDone::ID: |
| 45 case AcceleratedVideoDecoderHostMsg_InitializeDone::ID: | 38 case AcceleratedVideoDecoderHostMsg_InitializeDone::ID: |
| 46 case AcceleratedVideoDecoderHostMsg_DismissPictureBuffer::ID: | 39 case AcceleratedVideoDecoderHostMsg_DismissPictureBuffer::ID: |
| 47 case AcceleratedVideoDecoderHostMsg_PictureReady::ID: | 40 case AcceleratedVideoDecoderHostMsg_PictureReady::ID: |
| 48 case AcceleratedVideoDecoderHostMsg_FlushDone::ID: | 41 case AcceleratedVideoDecoderHostMsg_FlushDone::ID: |
| 49 case AcceleratedVideoDecoderHostMsg_AbortDone::ID: | 42 case AcceleratedVideoDecoderHostMsg_AbortDone::ID: |
| 50 case AcceleratedVideoDecoderHostMsg_EndOfStream::ID: | 43 case AcceleratedVideoDecoderHostMsg_EndOfStream::ID: |
| 51 case AcceleratedVideoDecoderHostMsg_ErrorNotification::ID: | 44 case AcceleratedVideoDecoderHostMsg_ErrorNotification::ID: |
| 52 if (router_.RouteMessage(msg)) | 45 if (router_.RouteMessage(msg)) |
| 53 return true; | 46 return true; |
| 54 LOG(ERROR) << "AcceleratedVideoDecoderHostMsg cannot be dispatched."; | 47 LOG(ERROR) << "AcceleratedVideoDecoderHostMsg cannot be dispatched."; |
| 55 default: | 48 default: |
| 56 return false; | 49 return false; |
| 57 } | 50 } |
| 58 } | 51 } |
| 59 | 52 |
| 53 void GpuVideoServiceHost::OnChannelError() { |
| 54 DCHECK(CalledOnValidThread()); |
| 55 channel_ = NULL; |
| 56 } |
| 57 |
| 60 void GpuVideoServiceHost::SetOnInitialized( | 58 void GpuVideoServiceHost::SetOnInitialized( |
| 61 const base::Closure& on_initialized) { | 59 const base::Closure& on_initialized) { |
| 62 IPC::Channel* channel; | 60 DCHECK(CalledOnValidThread()); |
| 63 { | 61 DCHECK(on_initialized_.is_null()); |
| 64 base::AutoLock auto_lock(lock_); | 62 on_initialized_ = on_initialized; |
| 65 DCHECK(on_initialized_.is_null()); | 63 if (channel_) |
| 66 on_initialized_ = on_initialized; | |
| 67 channel = channel_; | |
| 68 } | |
| 69 if (channel) | |
| 70 on_initialized.Run(); | 64 on_initialized.Run(); |
| 71 } | 65 } |
| 72 | 66 |
| 73 GpuVideoDecodeAcceleratorHost* GpuVideoServiceHost::CreateVideoAccelerator( | 67 GpuVideoDecodeAcceleratorHost* GpuVideoServiceHost::CreateVideoAccelerator( |
| 74 media::VideoDecodeAccelerator::Client* client, | 68 media::VideoDecodeAccelerator::Client* client, |
| 75 int command_buffer_route_id) { | 69 int32 command_buffer_route_id, |
| 76 base::AutoLock auto_lock(lock_); | 70 gpu::CommandBufferHelper* cmd_buffer_helper) { |
| 71 DCHECK(CalledOnValidThread()); |
| 77 DCHECK(channel_); | 72 DCHECK(channel_); |
| 78 return new GpuVideoDecodeAcceleratorHost( | 73 return new GpuVideoDecodeAcceleratorHost( |
| 79 &router_, channel_, next_decoder_host_id_++, | 74 &router_, channel_, next_decoder_host_id_++, |
| 80 command_buffer_route_id, client); | 75 command_buffer_route_id, cmd_buffer_helper, client); |
| 81 } | 76 } |
| OLD | NEW |