| OLD | NEW |
| (Empty) |
| 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 | |
| 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 #include <map> | |
| 10 | |
| 11 #include "base/shared_memory.h" | |
| 12 #include "base/singleton.h" | |
| 13 #include "chrome/renderer/gpu_channel_host.h" | |
| 14 #include "ipc/ipc_message.h" | |
| 15 #include "media/base/buffers.h" | |
| 16 #include "media/base/video_frame.h" | |
| 17 #include "media/video/video_decode_engine.h" | |
| 18 | |
| 19 using media::VideoFrame; | |
| 20 using media::Buffer; | |
| 21 | |
| 22 class MessageRouter; | |
| 23 struct GpuVideoDecoderInitDoneParam; | |
| 24 | |
| 25 // This class is used to talk to GpuVideoDecoder in the GPU process through | |
| 26 // IPC messages. It implements the interface of VideoDecodeEngine so users | |
| 27 // view it as a regular video decode engine, the implementation is a portal | |
| 28 // to the GPU process. | |
| 29 // | |
| 30 // THREAD SEMANTICS | |
| 31 // | |
| 32 // All methods of this class can be accessed on any thread. A message loop | |
| 33 // needs to be provided to class through Initialize() for accessing the | |
| 34 // IPC channel. Event handlers are called on that message loop. | |
| 35 // | |
| 36 // Since this class is not refcounted, it is important to delete this | |
| 37 // object only after OnUninitializeCompelte() is called. | |
| 38 class GpuVideoDecoderHost : public media::VideoDecodeEngine, | |
| 39 public IPC::Channel::Listener { | |
| 40 public: | |
| 41 // |router| is used to dispatch IPC messages to this object. | |
| 42 // |ipc_sender| is used to send IPC messages to GPU process. | |
| 43 // It is important that the above two objects are accessed on the | |
| 44 // |message_loop_|. | |
| 45 GpuVideoDecoderHost(MessageRouter* router, | |
| 46 IPC::Message::Sender* ipc_sender, | |
| 47 int context_route_id, | |
| 48 int32 decoder_host_id); | |
| 49 virtual ~GpuVideoDecoderHost(); | |
| 50 | |
| 51 // IPC::Channel::Listener. | |
| 52 virtual void OnChannelConnected(int32 peer_pid) {} | |
| 53 virtual void OnChannelError(); | |
| 54 virtual bool OnMessageReceived(const IPC::Message& message); | |
| 55 | |
| 56 // media::VideoDecodeEngine implementation. | |
| 57 virtual void Initialize(MessageLoop* message_loop, | |
| 58 VideoDecodeEngine::EventHandler* event_handler, | |
| 59 media::VideoDecodeContext* context, | |
| 60 const media::VideoCodecConfig& config); | |
| 61 virtual void ConsumeVideoSample(scoped_refptr<Buffer> buffer); | |
| 62 virtual void ProduceVideoFrame(scoped_refptr<VideoFrame> frame); | |
| 63 virtual void Uninitialize(); | |
| 64 virtual void Flush(); | |
| 65 virtual void Seek(); | |
| 66 | |
| 67 private: | |
| 68 typedef std::map<int32, scoped_refptr<media::VideoFrame> > VideoFrameMap; | |
| 69 | |
| 70 // Internal states. | |
| 71 enum GpuVideoDecoderHostState { | |
| 72 kStateUninitialized, | |
| 73 kStateNormal, | |
| 74 kStateError, | |
| 75 kStateFlushing, | |
| 76 }; | |
| 77 | |
| 78 // Takes care of sending IPC message to create a video decoder. | |
| 79 void CreateVideoDecoder(); | |
| 80 | |
| 81 // Handlers for messages received from the GPU process. | |
| 82 void OnCreateVideoDecoderDone(int32 decoder_id); | |
| 83 void OnInitializeDone(const GpuVideoDecoderInitDoneParam& param); | |
| 84 void OnUninitializeDone(); | |
| 85 void OnFlushDone(); | |
| 86 void OnPrerollDone(); | |
| 87 void OnEmptyThisBufferACK(); | |
| 88 void OnProduceVideoSample(); | |
| 89 void OnConsumeVideoFrame(int32 frame_id, int64 timestamp, | |
| 90 int64 duration, int32 flags); | |
| 91 void OnAllocateVideoFrames(int32 n, uint32 width, | |
| 92 uint32 height, int32 format); | |
| 93 void OnReleaseAllVideoFrames(); | |
| 94 | |
| 95 // Handler for VideoDecodeContext. This method is called when video frames | |
| 96 // allocation is done. | |
| 97 void OnAllocateVideoFramesDone(); | |
| 98 | |
| 99 // Send a message to the GPU process to inform that a video frame is | |
| 100 // allocated. | |
| 101 void SendVideoFrameAllocated(int32 frame_id, | |
| 102 scoped_refptr<media::VideoFrame> frame); | |
| 103 | |
| 104 // Send a video sample to the GPU process and tell it to use the buffer for | |
| 105 // video decoding. | |
| 106 void SendConsumeVideoSample(); | |
| 107 | |
| 108 // Look up the frame_id for |frame| and send a message to the GPU process | |
| 109 // to use that video frame to produce an output. | |
| 110 void SendProduceVideoFrame(scoped_refptr<media::VideoFrame> frame); | |
| 111 | |
| 112 // A router used to send us IPC messages. | |
| 113 MessageRouter* router_; | |
| 114 | |
| 115 // Sends IPC messages to the GPU process. | |
| 116 IPC::Message::Sender* ipc_sender_; | |
| 117 | |
| 118 // Route ID of the GLES2 context in the GPU process. | |
| 119 int context_route_id_; | |
| 120 | |
| 121 // Message loop that this object runs on. | |
| 122 MessageLoop* message_loop_; | |
| 123 | |
| 124 // We expect that the client of us will always available during our life span. | |
| 125 EventHandler* event_handler_; | |
| 126 | |
| 127 // A Context for allocating video frame textures. | |
| 128 media::VideoDecodeContext* context_; | |
| 129 | |
| 130 // Dimensions of the video. | |
| 131 int width_; | |
| 132 int height_; | |
| 133 | |
| 134 // Current state of video decoder. | |
| 135 GpuVideoDecoderHostState state_; | |
| 136 | |
| 137 // ID of this GpuVideoDecoderHost. | |
| 138 int32 decoder_host_id_; | |
| 139 | |
| 140 // ID of GpuVideoDecoder in the GPU process. | |
| 141 int32 decoder_id_; | |
| 142 | |
| 143 // We are not able to push all received buffer to gpu process at once. | |
| 144 std::deque<scoped_refptr<Buffer> > input_buffer_queue_; | |
| 145 | |
| 146 // Currently we do not use ring buffer in input buffer, therefore before | |
| 147 // GPU process had finished access it, we should not touch it. | |
| 148 bool input_buffer_busy_; | |
| 149 | |
| 150 // Transfer buffers for both input and output. | |
| 151 // TODO(jiesun): remove output buffer when hardware composition is ready. | |
| 152 scoped_ptr<base::SharedMemory> input_transfer_buffer_; | |
| 153 | |
| 154 // Frame ID for the newly generated video frame. | |
| 155 int32 current_frame_id_; | |
| 156 | |
| 157 // The list of video frames allocated by VideoDecodeContext. | |
| 158 std::vector<scoped_refptr<media::VideoFrame> > video_frames_; | |
| 159 | |
| 160 // The mapping between video frame ID and a video frame. | |
| 161 VideoFrameMap video_frame_map_; | |
| 162 | |
| 163 DISALLOW_COPY_AND_ASSIGN(GpuVideoDecoderHost); | |
| 164 }; | |
| 165 | |
| 166 #endif // CHROME_RENDERER_GPU_VIDEO_DECODER_HOST_H_ | |
| OLD | NEW |