2 * Copyright (C) 2011, Hewlett-Packard Development Company, L.P.
3 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>, Collabora Ltd.
4 * Copyright (C) 2013, Collabora Ltd.
5 * Author: Sebastian Dröge <sebastian.droege@collabora.co.uk>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation
10 * version 2.1 of the License.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 #ifdef GST_OMX_STRUCT_PACKING
36 # if GST_OMX_STRUCT_PACKING == 1
38 # elif GST_OMX_STRUCT_PACKING == 2
40 # elif GST_OMX_STRUCT_PACKING == 4
42 # elif GST_OMX_STRUCT_PACKING == 8
45 # error "Unsupported struct packing value"
49 /* If the component may signal EOS before it has finished pushing
50 * out all of its buffers. Happens with egl_render on the rpi.
52 #define GST_OMX_HACK_SIGNALS_PREMATURE_EOS G_GUINT64_CONSTANT (0x0000000000000400)
55 #include <OMX_Component.h>
57 #ifdef TIZEN_FEATURE_OMX
59 #include <tbm_surface.h>
60 #include <tbm_bufmgr.h>
64 #ifdef USE_OMX_TARGET_RPI
65 #include <OMX_Broadcom.h>
69 #include <OMX_VideoExt.h>
72 #ifdef GST_OMX_STRUCT_PACKING
78 #define GST_OMX_INIT_STRUCT(st) G_STMT_START { \
79 memset ((st), 0, sizeof (*(st))); \
80 (st)->nSize = sizeof (*(st)); \
81 (st)->nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
82 (st)->nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
83 (st)->nVersion.s.nRevision = OMX_VERSION_REVISION; \
84 (st)->nVersion.s.nStep = OMX_VERSION_STEP; \
87 #if defined(USE_OMX_TARGET_EXYNOS) || defined(USE_OMX_TARGET_EXYNOS64)
88 #define OMX_INIT_PARAM(param) G_STMT_START { \
89 memset (&(param), 0, sizeof ((param))); \
90 (param).nSize = sizeof (param); \
91 (param).nVersion.s.nVersionMajor = 1; \
92 (param).nVersion.s.nVersionMinor = 1; \
96 /* Different hacks that are required to work around
97 * bugs in different OpenMAX implementations
99 /* In the EventSettingsChanged callback use nData2 instead of nData1 for
100 * the port index. Happens with Bellagio.
102 #define GST_OMX_HACK_EVENT_PORT_SETTINGS_CHANGED_NDATA_PARAMETER_SWAP G_GUINT64_CONSTANT (0x0000000000000001)
103 /* In the EventSettingsChanged callback assume that port index 0 really
104 * means port index 1. Happens with the Bellagio ffmpegdist video decoder.
106 #define GST_OMX_HACK_EVENT_PORT_SETTINGS_CHANGED_PORT_0_TO_1 G_GUINT64_CONSTANT (0x0000000000000002)
107 /* If the video framerate is not specified as fraction (Q.16) but as
108 * integer number. Happens with the Bellagio ffmpegdist video encoder.
110 #define GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER G_GUINT64_CONSTANT (0x0000000000000004)
111 /* If the SYNCFRAME flag on encoder output buffers is not used and we
112 * have to assume that all frames are sync frames.
113 * Happens with the Bellagio ffmpegdist video encoder.
115 #define GST_OMX_HACK_SYNCFRAME_FLAG_NOT_USED G_GUINT64_CONSTANT (0x0000000000000008)
116 /* If the component needs to be re-created if the caps change.
117 * Happens with Qualcomm's OpenMAX implementation.
119 #define GST_OMX_HACK_NO_COMPONENT_RECONFIGURE G_GUINT64_CONSTANT (0x0000000000000010)
121 /* If the component does not accept empty EOS buffers.
122 * Happens with Qualcomm's OpenMAX implementation.
124 #define GST_OMX_HACK_NO_EMPTY_EOS_BUFFER G_GUINT64_CONSTANT (0x0000000000000020)
126 /* If the component might not acknowledge a drain.
127 * Happens with TI's Ducati OpenMAX implementation.
129 #define GST_OMX_HACK_DRAIN_MAY_NOT_RETURN G_GUINT64_CONSTANT (0x0000000000000040)
131 /* If the component doesn't allow any component role to be set.
132 * Happens with Broadcom's OpenMAX implementation.
134 #define GST_OMX_HACK_NO_COMPONENT_ROLE G_GUINT64_CONSTANT (0x0000000000000080)
136 /* If the component doesn't allow disabling the outport while
137 * when setting the format until the output format is known.
139 #define GST_OMX_HACK_NO_DISABLE_OUTPORT G_GUINT64_CONSTANT (0x0000000000000100)
141 /* If the encoder requires input buffers that have a height
142 * which is a multiple of 16 pixels
144 #define GST_OMX_HACK_HEIGHT_MULTIPLE_16 G_GUINT64_CONSTANT (0x0000000000000200)
146 /* If we should pass the profile/level information from upstream to the
147 * OMX decoder. This is a violation of the OMX spec as
148 * OMX_IndexParamVideoProfileLevelCurrent is supposed to be r-o so
149 * do it as a platform specific hack.
151 #define GST_OMX_HACK_PASS_PROFILE_TO_DECODER G_GUINT64_CONSTANT (0x0000000000000800)
153 typedef struct _GstOMXCore GstOMXCore;
154 typedef struct _GstOMXPort GstOMXPort;
155 typedef enum _GstOMXPortDirection GstOMXPortDirection;
156 typedef struct _GstOMXComponent GstOMXComponent;
157 typedef struct _GstOMXBuffer GstOMXBuffer;
158 typedef struct _GstOMXClassData GstOMXClassData;
159 typedef struct _GstOMXMessage GstOMXMessage;
162 typedef enum GOmxVendor GOmxVendor; /* check omx vender */
164 #ifdef TIZEN_FEATURE_OMX
166 #define MFC_INPUT_BUFFER_PLANE 1
167 #define MFC_OUTPUT_BUFFER_PLANE 2
168 #define MAX_BUFFER_PLANE 3
170 #define MAX_INPUT_BUFFER 16
171 #define MAX_OUTPUT_BUFFER 16
173 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
175 typedef struct _TBMBuffer TBMBuffer;
176 typedef struct _TBMInputBuffer TBMInputBuffer;
177 typedef struct _TBMOutputBuffer TBMOutputBuffer;
178 typedef struct _EnableGemBuffersParams EnableGemBuffersParams;
188 struct _TBMInputBuffer
190 struct _TBMBuffer tbmBuffer[MAX_INPUT_BUFFER];
191 OMX_U32 allocatedCount;
195 struct _TBMOutputBuffer
197 MMVideoBuffer *tbmBuffer[MAX_OUTPUT_BUFFER];
198 OMX_U32 allocatedCount;
202 struct _EnableGemBuffersParams
205 OMX_VERSIONTYPE nVersion;
212 /* Everything good and the buffer is valid */
213 GST_OMX_ACQUIRE_BUFFER_OK = 0,
214 /* The port is flushing, exit ASAP */
215 GST_OMX_ACQUIRE_BUFFER_FLUSHING,
216 /* The port must be reconfigured */
217 GST_OMX_ACQUIRE_BUFFER_RECONFIGURE,
218 /* The port is EOS */
219 GST_OMX_ACQUIRE_BUFFER_EOS,
220 /* A fatal error happened */
221 GST_OMX_ACQUIRE_BUFFER_ERROR
222 } GstOMXAcquireBufferReturn;
225 /* Handle to the OpenMAX IL core shared library */
228 /* Current number of users, transitions from/to 0
229 * call init/deinit */
231 gint user_count; /* LOCK */
234 gboolean secure; /* trust zone */
236 /* OpenMAX core library functions, protected with LOCK */
237 OMX_ERRORTYPE (*init) (void);
238 OMX_ERRORTYPE (*deinit) (void);
239 OMX_ERRORTYPE (*get_handle) (OMX_HANDLETYPE * handle,
240 OMX_STRING name, OMX_PTR data, OMX_CALLBACKTYPE * callbacks);
241 OMX_ERRORTYPE (*free_handle) (OMX_HANDLETYPE handle);
242 OMX_ERRORTYPE (*setup_tunnel) (OMX_HANDLETYPE output, OMX_U32 outport, OMX_HANDLETYPE input, OMX_U32 inport);
246 GST_OMX_MESSAGE_STATE_SET,
247 GST_OMX_MESSAGE_FLUSH,
248 GST_OMX_MESSAGE_ERROR,
249 GST_OMX_MESSAGE_PORT_ENABLE,
250 GST_OMX_MESSAGE_PORT_SETTINGS_CHANGED,
251 GST_OMX_MESSAGE_BUFFER_FLAG,
252 GST_OMX_MESSAGE_BUFFER_DONE,
256 GST_OMX_COMPONENT_TYPE_SINK,
257 GST_OMX_COMPONENT_TYPE_SOURCE,
258 GST_OMX_COMPONENT_TYPE_FILTER
259 } GstOmxComponentType;
261 struct _GstOMXMessage {
262 GstOMXMessageType type;
280 } port_settings_changed;
286 OMX_HANDLETYPE component;
288 OMX_BUFFERHEADERTYPE *buffer;
295 GstOMXComponent *comp;
300 OMX_PARAM_PORTDEFINITIONTYPE port_def;
301 GPtrArray *buffers; /* Contains GstOMXBuffer* */
302 GQueue pending_buffers; /* Contains GstOMXBuffer* */
304 gboolean flushed; /* TRUE after OMX_CommandFlush was done */
305 gboolean enabled_pending; /* TRUE after OMX_Command{En,Dis}able */
306 gboolean disabled_pending; /* was done until it took effect */
307 gboolean eos; /* TRUE after a buffer with EOS flag was received */
308 #ifdef TIZEN_FEATURE_OMX
310 gboolean flush_start;
313 /* Increased whenever the settings of these port change.
314 * If settings_cookie != configured_settings_cookie
315 * the port has to be reconfigured.
317 gint settings_cookie;
318 gint configured_settings_cookie;
321 struct _GstOMXComponent {
324 gchar *name; /* for debugging mostly */
326 OMX_HANDLETYPE handle;
329 guint64 hacks; /* Flags, GST_OMX_HACK_* */
331 /* Added once, never changed. No locks necessary */
332 GPtrArray *ports; /* Contains GstOMXPort* */
333 gint n_in_ports, n_out_ports;
335 /* Locking order: lock -> messages_lock
337 * Never hold lock while waiting for messages_cond
338 * Always check that messages is empty before waiting */
341 GQueue messages; /* Queue of GstOMXMessages */
342 GMutex messages_lock;
346 /* OMX_StateInvalid if no pending state */
347 OMX_STATETYPE pending_state;
348 /* OMX_ErrorNone usually, if different nothing will work */
349 OMX_ERRORTYPE last_error;
351 GList *pending_reconfigure_outports;
354 struct _GstOMXBuffer {
356 OMX_BUFFERHEADERTYPE *omx_buf;
358 /* TRUE if the buffer is used by the port, i.e.
359 * between {Empty,Fill}ThisBuffer and the callback
363 /* Cookie of the settings when this buffer was allocated */
364 gint settings_cookie;
366 /* TRUE if this is an EGLImage */
369 #ifdef TIZEN_FEATURE_OMX
370 /* MMVideoBuffer array to use TBM buffers */
371 MMVideoBuffer *mm_vbuffer;
375 struct _GstOMXClassData {
376 const gchar *core_name;
377 const gchar *component_name;
378 const gchar *component_role;
380 const gchar *default_src_template_caps;
381 const gchar *default_sink_template_caps;
383 guint32 in_port_index, out_port_index;
384 #ifdef TIZEN_FEATURE_OMX
385 guint32 in_port_usebuffer, out_port_usebuffer;
390 GstOmxComponentType type;
393 GKeyFile * gst_omx_get_configuration (void);
395 const gchar * gst_omx_error_to_string (OMX_ERRORTYPE err);
396 const gchar * gst_omx_state_to_string (OMX_STATETYPE state);
397 const gchar * gst_omx_command_to_string (OMX_COMMANDTYPE cmd);
399 guint64 gst_omx_parse_hacks (gchar ** hacks);
401 GstOMXCore * gst_omx_core_acquire (const gchar * filename);
402 void gst_omx_core_release (GstOMXCore * core);
405 GstOMXComponent * gst_omx_component_new (GstObject * parent, const gchar *core_name, const gchar *component_name, const gchar * component_role, guint64 hacks);
406 void gst_omx_component_free (GstOMXComponent * comp);
408 OMX_ERRORTYPE gst_omx_component_set_state (GstOMXComponent * comp, OMX_STATETYPE state);
409 OMX_STATETYPE gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout);
411 OMX_ERRORTYPE gst_omx_component_get_last_error (GstOMXComponent * comp);
412 const gchar * gst_omx_component_get_last_error_string (GstOMXComponent * comp);
414 GstOMXPort * gst_omx_component_add_port (GstOMXComponent * comp, guint32 index);
415 GstOMXPort * gst_omx_component_get_port (GstOMXComponent * comp, guint32 index);
417 OMX_ERRORTYPE gst_omx_component_get_parameter (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer param);
418 OMX_ERRORTYPE gst_omx_component_set_parameter (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer param);
420 OMX_ERRORTYPE gst_omx_component_get_config (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer config);
421 OMX_ERRORTYPE gst_omx_component_set_config (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer config);
423 OMX_ERRORTYPE gst_omx_setup_tunnel (GstOMXPort * port1, GstOMXPort * port2);
424 OMX_ERRORTYPE gst_omx_close_tunnel (GstOMXPort * port1, GstOMXPort * port2);
427 OMX_ERRORTYPE gst_omx_port_get_port_definition (GstOMXPort * port, OMX_PARAM_PORTDEFINITIONTYPE * port_def);
428 OMX_ERRORTYPE gst_omx_port_update_port_definition (GstOMXPort *port, OMX_PARAM_PORTDEFINITIONTYPE *port_definition);
430 GstOMXAcquireBufferReturn gst_omx_port_acquire_buffer (GstOMXPort *port, GstOMXBuffer **buf);
431 OMX_ERRORTYPE gst_omx_port_release_buffer (GstOMXPort *port, GstOMXBuffer *buf);
433 OMX_ERRORTYPE gst_omx_port_set_flushing (GstOMXPort *port, GstClockTime timeout, gboolean flush);
434 gboolean gst_omx_port_is_flushing (GstOMXPort *port);
436 OMX_ERRORTYPE gst_omx_port_allocate_buffers (GstOMXPort *port);
437 #ifdef TIZEN_FEATURE_OMX
438 OMX_ERRORTYPE gst_omx_port_tbm_allocate_dec_buffers (GstOMXPort * port, tbm_bufmgr bufmgr, gboolean use_buffer);
439 OMX_ERRORTYPE gst_omx_port_tbm_allocate_enc_buffers (GstOMXPort * port, tbm_bufmgr bufmgr, gboolean use_buffer);
440 OMX_ERRORTYPE gst_omx_component_get_extension_index (GstOMXComponent * comp, OMX_STRING name, gpointer index);
441 void gst_omx_port_flush_start (GstOMXPort * port, gboolean flush);
443 OMX_ERRORTYPE gst_omx_port_use_buffers (GstOMXPort *port, const GList *buffers);
444 OMX_ERRORTYPE gst_omx_port_use_eglimages (GstOMXPort *port, const GList *images);
445 OMX_ERRORTYPE gst_omx_port_deallocate_buffers (GstOMXPort *port);
446 OMX_ERRORTYPE gst_omx_port_populate (GstOMXPort *port);
447 OMX_ERRORTYPE gst_omx_port_wait_buffers_released (GstOMXPort * port, GstClockTime timeout);
449 OMX_ERRORTYPE gst_omx_port_mark_reconfigured (GstOMXPort * port);
451 OMX_ERRORTYPE gst_omx_port_set_enabled (GstOMXPort * port, gboolean enabled);
452 OMX_ERRORTYPE gst_omx_port_wait_enabled (GstOMXPort * port, GstClockTime timeout);
453 gboolean gst_omx_port_is_enabled (GstOMXPort * port);
456 void gst_omx_set_default_role (GstOMXClassData *class_data, const gchar *default_role);
458 /* refered by plugin_init */
459 GST_DEBUG_CATEGORY_EXTERN (gst_omx_video_debug_category);
463 #endif /* __GST_OMX_H__ */