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 CONTENT_COMMON_GPU_OMX_VIDEO_DECODE_ACCELERATOR_H_ | |
6 #define CONTENT_COMMON_GPU_OMX_VIDEO_DECODE_ACCELERATOR_H_ | |
7 | |
8 #include <dlfcn.h> | |
9 #include <map> | |
10 #include <queue> | |
11 #include <string> | |
12 #include <utility> | |
13 #include <vector> | |
14 | |
15 #include "base/bind.h" | |
16 #include "base/callback.h" | |
17 #include "base/logging.h" | |
18 #include "base/message_loop.h" | |
19 #include "base/shared_memory.h" | |
20 #include "media/video/video_decode_accelerator.h" | |
21 #include "third_party/openmax/il/OMX_Component.h" | |
22 #include "third_party/openmax/il/OMX_Core.h" | |
23 #include "third_party/openmax/il/OMX_Video.h" | |
24 | |
25 // Class to wrap OpenMAX IL accelerator behind VideoDecodeAccelerator interface. | |
26 class OmxVideoDecodeAccelerator : public media::VideoDecodeAccelerator { | |
27 public: | |
28 OmxVideoDecodeAccelerator(media::VideoDecodeAccelerator::Client* client, | |
29 MessageLoop* message_loop); | |
30 virtual ~OmxVideoDecodeAccelerator(); | |
31 | |
32 // media::VideoDecodeAccelerator implementation. | |
33 void GetConfigs(const std::vector<uint32>& requested_configs, | |
34 std::vector<uint32>* matched_configs) OVERRIDE; | |
35 bool Initialize(const std::vector<uint32>& config) OVERRIDE; | |
36 bool Decode(const media::BitstreamBuffer& bitstream_buffer) OVERRIDE; | |
37 virtual void AssignGLESBuffers( | |
38 const std::vector<media::GLESBuffer>& buffers) OVERRIDE; | |
39 virtual void AssignSysmemBuffers( | |
40 const std::vector<media::SysmemBuffer>& buffers) OVERRIDE; | |
41 void ReusePictureBuffer(int32 picture_buffer_id) OVERRIDE; | |
42 bool Flush() OVERRIDE; | |
43 bool Abort() OVERRIDE; | |
44 | |
45 private: | |
46 MessageLoop* message_loop_; | |
47 OMX_HANDLETYPE component_handle_; | |
48 | |
49 // Common initialization code for Assign{GLES,Sysmem}Buffers. | |
50 void AssignBuffersHelper(const std::vector<media::BaseBuffer*>& buffers); | |
51 | |
52 // Create the Component for OMX. Handles all OMX initialization. | |
53 bool CreateComponent(); | |
54 // Buffer allocation/free methods for input and output buffers. | |
55 bool AllocateInputBuffers(); | |
56 bool AllocateOutputBuffers(); | |
57 void FreeInputBuffers(); | |
58 void FreeOutputBuffers(); | |
59 | |
60 // Methods to handle OMX state transitions. | |
61 bool TransitionToState(OMX_STATETYPE new_state); | |
62 void OnStateChangeLoadedToIdle(OMX_STATETYPE state); | |
63 void OnStateChangeIdleToExecuting(OMX_STATETYPE state); | |
64 void OnPortCommandFlush(OMX_STATETYPE state); | |
65 void OnStateChangeExecutingToIdle(OMX_STATETYPE state); | |
66 void OnStateChangeIdleToLoaded(OMX_STATETYPE state); | |
67 // Stop the components when error is detected. | |
68 void StopOnError(); | |
69 // Trigger the initial call to FillBuffers to start the decoding process. | |
70 void InitialFillBuffer(); | |
71 // Methods for shutdown | |
72 void PauseFromExecuting(OMX_STATETYPE ignored); | |
73 void FlushIOPorts(); | |
74 void PortFlushDone(int port); | |
75 void FlushBegin(); | |
76 | |
77 // Determine whether we actually start decoding the bitstream. | |
78 bool CanAcceptInput(); | |
79 // Determine whether we can issue fill buffer or empty buffer | |
80 // to the decoder based on the current state and port state. | |
81 bool CanEmptyBuffer(); | |
82 bool CanFillBuffer(); | |
83 void OnPortSettingsChangedRun(int port, OMX_INDEXTYPE index); | |
84 | |
85 // Decoded width/height from bitstream. | |
86 int width_; | |
87 int height_; | |
88 std::vector<uint32> component_config_; | |
89 | |
90 // IL-client state. | |
91 OMX_STATETYPE client_state_; | |
92 | |
93 // Following are input port related variables. | |
94 int input_buffer_count_; | |
95 int input_buffer_size_; | |
96 int input_port_; | |
97 int input_buffers_at_component_; | |
98 | |
99 // Following are output port related variables. | |
100 int output_buffer_count_; | |
101 int output_buffer_size_; | |
102 int output_port_; | |
103 int output_buffers_at_component_; | |
104 | |
105 bool uses_egl_image_; | |
106 // Free input OpenMAX buffers that can be used to take bitstream from demuxer. | |
107 std::queue<OMX_BUFFERHEADERTYPE*> free_input_buffers_; | |
108 | |
109 // For output buffer recycling cases. | |
110 std::vector<media::BaseBuffer*> assigned_picture_buffers_; | |
111 typedef std::pair<int32, OMX_BUFFERHEADERTYPE*> OutputPicture; | |
112 std::vector<OutputPicture> output_pictures_; | |
113 | |
114 // To expose client callbacks from VideoDecodeAccelerator. | |
115 Client* client_; | |
116 | |
117 std::vector<uint32> texture_ids_; | |
118 std::vector<uint32> context_ids_; | |
119 // Method to handle events | |
120 void EventHandlerCompleteTask(OMX_EVENTTYPE event, | |
121 OMX_U32 data1, | |
122 OMX_U32 data2); | |
123 | |
124 // Method to receive buffers from component's input port | |
125 void EmptyBufferDoneTask(OMX_BUFFERHEADERTYPE* buffer); | |
126 | |
127 // Method to receive buffers from component's output port | |
128 void FillBufferDoneTask(OMX_BUFFERHEADERTYPE* buffer); | |
129 typedef std::pair<OMX_BUFFERHEADERTYPE*, uint32> OMXbufferTexture; | |
130 | |
131 typedef std::map<OMX_BUFFERHEADERTYPE*, | |
132 std::pair<base::SharedMemory*, int32> > OMXBufferIdMap; | |
133 OMXBufferIdMap omx_buff_ids_; | |
134 | |
135 // Method used the change the state of the port. | |
136 void ChangePort(OMX_COMMANDTYPE cmd, int port_index); | |
137 | |
138 // Member function pointers to respond to events | |
139 void (OmxVideoDecodeAccelerator::*on_port_disable_event_func_)(int port); | |
140 void (OmxVideoDecodeAccelerator::*on_port_enable_event_func_)(int port); | |
141 void (OmxVideoDecodeAccelerator::*on_state_event_func_)(OMX_STATETYPE state); | |
142 void (OmxVideoDecodeAccelerator::*on_flush_event_func_)(int port); | |
143 void (OmxVideoDecodeAccelerator::*on_buffer_flag_event_func_)(); | |
144 | |
145 // Callback methods for the OMX component. | |
146 // When these callbacks are received, the | |
147 // call is delegated to the three internal methods above. | |
148 static OMX_ERRORTYPE EventHandler(OMX_HANDLETYPE component, | |
149 OMX_PTR priv_data, | |
150 OMX_EVENTTYPE event, | |
151 OMX_U32 data1, OMX_U32 data2, | |
152 OMX_PTR event_data); | |
153 static OMX_ERRORTYPE EmptyBufferCallback(OMX_HANDLETYPE component, | |
154 OMX_PTR priv_data, | |
155 OMX_BUFFERHEADERTYPE* buffer); | |
156 static OMX_ERRORTYPE FillBufferCallback(OMX_HANDLETYPE component, | |
157 OMX_PTR priv_data, | |
158 OMX_BUFFERHEADERTYPE* buffer); | |
159 }; | |
160 | |
161 #endif // CONTENT_COMMON_GPU_OMX_VIDEO_DECODE_ACCELERATOR_H_ | |
OLD | NEW |