1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ 6 #define CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ 7 8 #include <vector> 9 10 #include "base/memory/weak_ptr.h" 11 #include "base/threading/non_thread_safe.h" 12 #include "content/common/gpu/client/command_buffer_proxy_impl.h" 13 #include "ipc/ipc_listener.h" 14 #include "media/video/video_decode_accelerator.h" 15 #include "ui/gfx/size.h" 16 17 namespace content { 18 class GpuChannelHost; 19 20 // This class is used to talk to VideoDecodeAccelerator in the Gpu process 21 // through IPC messages. 22 class GpuVideoDecodeAcceleratorHost 23 : public IPC::Listener, 24 public media::VideoDecodeAccelerator, 25 public CommandBufferProxyImpl::DeletionObserver, 26 public base::NonThreadSafe { 27 public: 28 // |channel| is used to send IPC messages to GPU process. 29 GpuVideoDecodeAcceleratorHost(GpuChannelHost* channel, 30 int32 decoder_route_id, 31 media::VideoDecodeAccelerator::Client* client, 32 CommandBufferProxyImpl* impl); 33 34 // IPC::Listener implementation. 35 virtual void OnChannelError() OVERRIDE; 36 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE; 37 38 // media::VideoDecodeAccelerator implementation. 39 virtual bool Initialize(media::VideoCodecProfile profile) OVERRIDE; 40 virtual void Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; 41 virtual void AssignPictureBuffers( 42 const std::vector<media::PictureBuffer>& buffers) OVERRIDE; 43 virtual void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; 44 virtual void Flush() OVERRIDE; 45 virtual void Reset() OVERRIDE; 46 virtual void Destroy() OVERRIDE; 47 48 // CommandBufferProxyImpl::DeletionObserver implemetnation. 49 virtual void OnWillDeleteImpl() OVERRIDE; 50 51 private: 52 // Only Destroy() should be deleting |this|. 53 virtual ~GpuVideoDecodeAcceleratorHost(); 54 55 void Send(IPC::Message* message); 56 57 void OnBitstreamBufferProcessed(int32 bitstream_buffer_id); 58 void OnProvidePictureBuffer(uint32 num_requested_buffers, 59 const gfx::Size& dimensions, 60 uint32 texture_target); 61 void OnDismissPictureBuffer(int32 picture_buffer_id); 62 void OnPictureReady(int32 picture_buffer_id, int32 bitstream_buffer_id); 63 void OnFlushDone(); 64 void OnResetDone(); 65 void OnErrorNotification(uint32 error); 66 67 // Sends IPC messages to the Gpu process. 68 GpuChannelHost* channel_; 69 70 // Route ID for the associated decoder in the GPU process. 71 int32 decoder_route_id_; 72 73 // Reference to the client that will receive callbacks from the decoder. 74 media::VideoDecodeAccelerator::Client* client_; 75 76 // Unowned reference to the CommandBufferProxyImpl that created us. 77 CommandBufferProxyImpl* impl_; 78 79 // Requested dimensions of the buffer, from ProvidePictureBuffers(). 80 gfx::Size picture_buffer_dimensions_; 81 82 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecodeAcceleratorHost); 83 }; 84 85 } // namespace content 86 87 #endif // CONTENT_COMMON_GPU_CLIENT_GPU_VIDEO_DECODE_ACCELERATOR_HOST_H_ 88