OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2010 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 CHROME_RENDERER_GPU_VIDEO_DECODER_HOST_H_ |
| 6 #define CHROME_RENDERER_GPU_VIDEO_DECODER_HOST_H_ |
| 7 |
| 8 #include <deque> |
| 9 |
| 10 #include "base/singleton.h" |
| 11 #include "chrome/common/gpu_video_common.h" |
| 12 #include "chrome/renderer/gpu_channel_host.h" |
| 13 #include "ipc/ipc_channel_proxy.h" |
| 14 #include "media/base/buffers.h" |
| 15 #include "media/base/video_frame.h" |
| 16 |
| 17 using media::VideoFrame; |
| 18 using media::Buffer; |
| 19 |
| 20 class GpuVideoServiceHost; |
| 21 |
| 22 class GpuVideoDecoderHost |
| 23 : public base::RefCountedThreadSafe<GpuVideoDecoderHost>, |
| 24 public IPC::Channel::Listener { |
| 25 public: |
| 26 class EventHandler { |
| 27 public: |
| 28 virtual void OnInitializeDone( |
| 29 bool success, |
| 30 const GpuVideoDecoderInitDoneParam& param) = 0; |
| 31 virtual void OnUninitializeDone() = 0; |
| 32 virtual void OnFlushDone() = 0; |
| 33 virtual void OnEmptyBufferDone(scoped_refptr<Buffer> buffer) = 0; |
| 34 virtual void OnFillBufferDone(scoped_refptr<VideoFrame> frame) = 0; |
| 35 virtual void OnDeviceError() = 0; |
| 36 }; |
| 37 |
| 38 typedef enum { |
| 39 kStateUninitialized, |
| 40 kStateNormal, |
| 41 kStateError, |
| 42 kStateFlushing, |
| 43 } GpuVideoDecoderHostState; |
| 44 |
| 45 // IPC::Channel::Listener. |
| 46 virtual void OnChannelConnected(int32 peer_pid) {} |
| 47 virtual void OnChannelError(); |
| 48 virtual void OnMessageReceived(const IPC::Message& message); |
| 49 |
| 50 bool Initialize(const GpuVideoDecoderInitParam& param); |
| 51 bool Uninitialize(); |
| 52 void EmptyThisBuffer(scoped_refptr<Buffer> buffer); |
| 53 void FillThisBuffer(scoped_refptr<VideoFrame> frame); |
| 54 bool Flush(); |
| 55 |
| 56 int32 decoder_id() { return decoder_info_.decoder_id_; } |
| 57 int32 route_id() { return decoder_info_.decoder_route_id_; } |
| 58 int32 my_route_id() { return decoder_info_.decoder_host_route_id_; } |
| 59 |
| 60 virtual ~GpuVideoDecoderHost() {} |
| 61 |
| 62 private: |
| 63 GpuVideoDecoderHost(GpuVideoServiceHost* service_host, |
| 64 GpuChannelHost* channel_host, |
| 65 EventHandler* event_handler, |
| 66 GpuVideoDecoderInfoParam decoder_info) |
| 67 : gpu_video_service_host_(service_host), |
| 68 channel_host_(channel_host), |
| 69 event_handler_(event_handler), |
| 70 decoder_info_(decoder_info), |
| 71 buffer_id_serial_(0), |
| 72 state_(kStateUninitialized), |
| 73 input_buffer_busy_(false) {} |
| 74 friend class GpuVideoServiceHost; |
| 75 |
| 76 // Input message handler. |
| 77 void OnInitializeDone(const GpuVideoDecoderInitDoneParam& param); |
| 78 void OnUninitializeDone(); |
| 79 void OnFlushDone(); |
| 80 void OnEmptyThisBufferDone(); |
| 81 void OnFillThisBufferDone(const GpuVideoDecoderOutputBufferParam& param); |
| 82 void OnEmptyThisBufferACK(); |
| 83 |
| 84 // Helper function. |
| 85 void SendInputBufferToGpu(); |
| 86 |
| 87 // We expect that GpuVideoServiceHost's always available during our life span. |
| 88 GpuVideoServiceHost* gpu_video_service_host_; |
| 89 |
| 90 scoped_refptr<GpuChannelHost> channel_host_; |
| 91 |
| 92 // We expect that the client of us will always available during our life span. |
| 93 EventHandler* event_handler_; |
| 94 |
| 95 // Globally identify this decoder in the GPU process. |
| 96 GpuVideoDecoderInfoParam decoder_info_; |
| 97 |
| 98 // Input buffer id serial number generator. |
| 99 int32 buffer_id_serial_; |
| 100 |
| 101 // Hold information about GpuVideoDecoder configuration. |
| 102 GpuVideoDecoderInitParam init_param_; |
| 103 |
| 104 // Hold information about output surface format, etc. |
| 105 GpuVideoDecoderInitDoneParam done_param_; |
| 106 |
| 107 // Current state of video decoder. |
| 108 GpuVideoDecoderHostState state_; |
| 109 |
| 110 // We are not able to push all received buffer to gpu process at once. |
| 111 std::deque<scoped_refptr<Buffer> > input_buffer_queue_; |
| 112 |
| 113 // Currently we do not use ring buffer in input buffer, therefore before |
| 114 // GPU process had finished access it, we should not touch it. |
| 115 bool input_buffer_busy_; |
| 116 |
| 117 // Transfer buffers for both input and output. |
| 118 // TODO(jiesun): remove output buffer when hardware composition is ready. |
| 119 scoped_ptr<base::SharedMemory> input_transfer_buffer_; |
| 120 scoped_ptr<base::SharedMemory> output_transfer_buffer_; |
| 121 |
| 122 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoderHost); |
| 123 }; |
| 124 |
| 125 #endif // CHROME_RENDERER_GPU_VIDEO_DECODER_HOST_H_ |
| 126 |
OLD | NEW |