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"
50 #include <OMX_Component.h>
52 #ifdef USE_OMX_TARGET_EXYNOS
54 #include <tbm_surface.h>
55 #include <tbm_bufmgr.h>
58 #ifdef USE_OMX_TARGET_RPI
59 #include <OMX_Broadcom.h>
63 #include <OMX_VideoExt.h>
66 #ifdef GST_OMX_STRUCT_PACKING
72 #define GST_OMX_INIT_STRUCT(st) G_STMT_START { \
73 memset ((st), 0, sizeof (*(st))); \
74 (st)->nSize = sizeof (*(st)); \
75 (st)->nVersion.s.nVersionMajor = OMX_VERSION_MAJOR; \
76 (st)->nVersion.s.nVersionMinor = OMX_VERSION_MINOR; \
77 (st)->nVersion.s.nRevision = OMX_VERSION_REVISION; \
78 (st)->nVersion.s.nStep = OMX_VERSION_STEP; \
81 /* Different hacks that are required to work around
82 * bugs in different OpenMAX implementations
84 /* In the EventSettingsChanged callback use nData2 instead of nData1 for
85 * the port index. Happens with Bellagio.
87 #define GST_OMX_HACK_EVENT_PORT_SETTINGS_CHANGED_NDATA_PARAMETER_SWAP G_GUINT64_CONSTANT (0x0000000000000001)
88 /* In the EventSettingsChanged callback assume that port index 0 really
89 * means port index 1. Happens with the Bellagio ffmpegdist video decoder.
91 #define GST_OMX_HACK_EVENT_PORT_SETTINGS_CHANGED_PORT_0_TO_1 G_GUINT64_CONSTANT (0x0000000000000002)
92 /* If the video framerate is not specified as fraction (Q.16) but as
93 * integer number. Happens with the Bellagio ffmpegdist video encoder.
95 #define GST_OMX_HACK_VIDEO_FRAMERATE_INTEGER G_GUINT64_CONSTANT (0x0000000000000004)
96 /* If the SYNCFRAME flag on encoder output buffers is not used and we
97 * have to assume that all frames are sync frames.
98 * Happens with the Bellagio ffmpegdist video encoder.
100 #define GST_OMX_HACK_SYNCFRAME_FLAG_NOT_USED G_GUINT64_CONSTANT (0x0000000000000008)
101 /* If the component needs to be re-created if the caps change.
102 * Happens with Qualcomm's OpenMAX implementation.
104 #define GST_OMX_HACK_NO_COMPONENT_RECONFIGURE G_GUINT64_CONSTANT (0x0000000000000010)
106 /* If the component does not accept empty EOS buffers.
107 * Happens with Qualcomm's OpenMAX implementation.
109 #define GST_OMX_HACK_NO_EMPTY_EOS_BUFFER G_GUINT64_CONSTANT (0x0000000000000020)
111 /* If the component might not acknowledge a drain.
112 * Happens with TI's Ducati OpenMAX implementation.
114 #define GST_OMX_HACK_DRAIN_MAY_NOT_RETURN G_GUINT64_CONSTANT (0x0000000000000040)
116 /* If the component doesn't allow any component role to be set.
117 * Happens with Broadcom's OpenMAX implementation.
119 #define GST_OMX_HACK_NO_COMPONENT_ROLE G_GUINT64_CONSTANT (0x0000000000000080)
121 /* If the component doesn't allow disabling the outport while
122 * when setting the format until the output format is known.
124 #define GST_OMX_HACK_NO_DISABLE_OUTPORT G_GUINT64_CONSTANT (0x0000000000000100)
126 typedef struct _GstOMXCore GstOMXCore;
127 typedef struct _GstOMXPort GstOMXPort;
128 typedef enum _GstOMXPortDirection GstOMXPortDirection;
129 typedef struct _GstOMXComponent GstOMXComponent;
130 typedef struct _GstOMXBuffer GstOMXBuffer;
131 typedef struct _GstOMXClassData GstOMXClassData;
132 typedef struct _GstOMXMessage GstOMXMessage;
135 typedef enum GOmxVendor GOmxVendor; /* check omx vender */
137 #ifdef GST_TIZEN_MODIFICATION
139 #define MFC_INPUT_BUFFER_PLANE 1
140 #define MFC_OUTPUT_BUFFER_PLANE 2
142 #define MAX_INPUT_BUFFER 16
143 #define MAX_OUTPUT_BUFFER 16
145 typedef struct _TBMBuffer TBMBuffer;
146 typedef struct _TBMInputBuffer TBMInputBuffer;
147 typedef struct _TBMOutputBuffer TBMOutputBuffer;
157 struct _TBMInputBuffer
159 struct _TBMBuffer tbmBuffer[MAX_INPUT_BUFFER];
160 OMX_U32 allocatedCount;
164 struct _TBMOutputBuffer
166 MMVideoBuffer *tbmBuffer[MAX_OUTPUT_BUFFER];
167 OMX_U32 allocatedCount;
171 typedef struct _EnableGemBuffersParams EnableGemBuffersParams;
173 struct _EnableGemBuffersParams
176 OMX_VERSIONTYPE nVersion;
184 BUF_SHARE_METHOD_PADDR = 0,
185 BUF_SHARE_METHOD_FD = 1,
186 BUF_SHARE_METHOD_TIZEN_BUFFER = 2,
187 BUF_SHARE_METHOD_FLUSH_BUFFER = 3,
188 }; /* buf_share_method */
190 /* Extended color formats */
192 OMX_EXT_COLOR_FormatNV12TPhysicalAddress = 0x7F000001, /**< Reserved region for introducing Vendor Extensions */
193 OMX_EXT_COLOR_FormatNV12LPhysicalAddress = 0x7F000002,
194 OMX_EXT_COLOR_FormatNV12Tiled = 0x7FC00002,
195 OMX_EXT_COLOR_FormatNV12TFdValue = 0x7F000012,
196 OMX_EXT_COLOR_FormatNV12LFdValue = 0x7F000013
199 #ifdef GST_TIZEN_MODIFICATION
200 /* Extended port settings. */
202 OMX_IndexParamEnablePlatformSpecificBuffers = 0x7F000011
206 /* modification: Add_component_vendor */
210 GOMX_VENDOR_SLSI_SEC,
211 GOMX_VENDOR_SLSI_EXYNOS,
217 /* Everything good and the buffer is valid */
218 GST_OMX_ACQUIRE_BUFFER_OK = 0,
219 /* The port is flushing, exit ASAP */
220 GST_OMX_ACQUIRE_BUFFER_FLUSHING,
221 /* The port must be reconfigured */
222 GST_OMX_ACQUIRE_BUFFER_RECONFIGURE,
223 /* The port is EOS */
224 GST_OMX_ACQUIRE_BUFFER_EOS,
225 /* A fatal error happened */
226 GST_OMX_ACQUIRE_BUFFER_ERROR
227 } GstOMXAcquireBufferReturn;
230 /* Handle to the OpenMAX IL core shared library */
233 /* Current number of users, transitions from/to 0
234 * call init/deinit */
236 gint user_count; /* LOCK */
239 GOmxVendor component_vendor; /* to check omx vender */
240 gboolean secure; /* trust zone */
242 /* OpenMAX core library functions, protected with LOCK */
243 OMX_ERRORTYPE (*init) (void);
244 OMX_ERRORTYPE (*deinit) (void);
245 OMX_ERRORTYPE (*get_handle) (OMX_HANDLETYPE * handle,
246 OMX_STRING name, OMX_PTR data, OMX_CALLBACKTYPE * callbacks);
247 OMX_ERRORTYPE (*free_handle) (OMX_HANDLETYPE handle);
248 OMX_ERRORTYPE (*setup_tunnel) (OMX_HANDLETYPE output, OMX_U32 outport, OMX_HANDLETYPE input, OMX_U32 inport);
252 GST_OMX_MESSAGE_STATE_SET,
253 GST_OMX_MESSAGE_FLUSH,
254 GST_OMX_MESSAGE_ERROR,
255 GST_OMX_MESSAGE_PORT_ENABLE,
256 GST_OMX_MESSAGE_PORT_SETTINGS_CHANGED,
257 GST_OMX_MESSAGE_BUFFER_FLAG,
258 GST_OMX_MESSAGE_BUFFER_DONE,
262 GST_OMX_COMPONENT_TYPE_SINK,
263 GST_OMX_COMPONENT_TYPE_SOURCE,
264 GST_OMX_COMPONENT_TYPE_FILTER
265 } GstOmxComponentType;
267 struct _GstOMXMessage {
268 GstOMXMessageType type;
286 } port_settings_changed;
292 OMX_HANDLETYPE component;
294 OMX_BUFFERHEADERTYPE *buffer;
301 GstOMXComponent *comp;
306 OMX_PARAM_PORTDEFINITIONTYPE port_def;
307 GPtrArray *buffers; /* Contains GstOMXBuffer* */
308 GQueue pending_buffers; /* Contains GstOMXBuffer* */
310 gboolean flushed; /* TRUE after OMX_CommandFlush was done */
311 gboolean enabled_pending; /* TRUE after OMX_Command{En,Dis}able */
312 gboolean disabled_pending; /* was done until it took effect */
313 gboolean eos; /* TRUE after a buffer with EOS flag was received */
315 /* Increased whenever the settings of these port change.
316 * If settings_cookie != configured_settings_cookie
317 * the port has to be reconfigured.
319 gint settings_cookie;
320 gint configured_settings_cookie;
323 struct _GstOMXComponent {
326 gchar *name; /* for debugging mostly */
328 OMX_HANDLETYPE handle;
331 guint64 hacks; /* Flags, GST_OMX_HACK_* */
333 /* Added once, never changed. No locks necessary */
334 GPtrArray *ports; /* Contains GstOMXPort* */
335 gint n_in_ports, n_out_ports;
337 /* Locking order: lock -> messages_lock
339 * Never hold lock while waiting for messages_cond
340 * Always check that messages is empty before waiting */
343 GQueue messages; /* Queue of GstOMXMessages */
344 GMutex messages_lock;
348 /* OMX_StateInvalid if no pending state */
349 OMX_STATETYPE pending_state;
350 /* OMX_ErrorNone usually, if different nothing will work */
351 OMX_ERRORTYPE last_error;
353 GList *pending_reconfigure_outports;
356 struct _GstOMXBuffer {
358 OMX_BUFFERHEADERTYPE *omx_buf;
360 /* TRUE if the buffer is used by the port, i.e.
361 * between {Empty,Fill}ThisBuffer and the callback
365 /* Cookie of the settings when this buffer was allocated */
366 gint settings_cookie;
368 /* TRUE if this is an EGLImage */
371 #ifdef GST_TIZEN_MODIFICATION
372 /* MMVideoBuffer array to use TBM buffers */
373 MMVideoBuffer *mm_vbuffer;
377 struct _GstOMXClassData {
378 const gchar *core_name;
379 const gchar *component_name;
380 const gchar *component_role;
382 const gchar *default_src_template_caps;
383 const gchar *default_sink_template_caps;
385 guint32 in_port_index, out_port_index;
389 GstOmxComponentType type;
392 GKeyFile * gst_omx_get_configuration (void);
394 const gchar * gst_omx_error_to_string (OMX_ERRORTYPE err);
395 const gchar * gst_omx_state_to_string (OMX_STATETYPE state);
396 const gchar * gst_omx_command_to_string (OMX_COMMANDTYPE cmd);
398 guint64 gst_omx_parse_hacks (gchar ** hacks);
400 GstOMXCore * gst_omx_core_acquire (const gchar * filename);
401 void gst_omx_core_release (GstOMXCore * core);
404 GstOMXComponent * gst_omx_component_new (GstObject * parent, const gchar *core_name, const gchar *component_name, const gchar * component_role, guint64 hacks);
405 void gst_omx_component_free (GstOMXComponent * comp);
407 OMX_ERRORTYPE gst_omx_component_set_state (GstOMXComponent * comp, OMX_STATETYPE state);
408 OMX_STATETYPE gst_omx_component_get_state (GstOMXComponent * comp, GstClockTime timeout);
410 OMX_ERRORTYPE gst_omx_component_get_last_error (GstOMXComponent * comp);
411 const gchar * gst_omx_component_get_last_error_string (GstOMXComponent * comp);
413 GstOMXPort * gst_omx_component_add_port (GstOMXComponent * comp, guint32 index);
414 GstOMXPort * gst_omx_component_get_port (GstOMXComponent * comp, guint32 index);
416 OMX_ERRORTYPE gst_omx_component_get_parameter (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer param);
417 OMX_ERRORTYPE gst_omx_component_set_parameter (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer param);
419 OMX_ERRORTYPE gst_omx_component_get_config (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer config);
420 OMX_ERRORTYPE gst_omx_component_set_config (GstOMXComponent * comp, OMX_INDEXTYPE index, gpointer config);
422 OMX_ERRORTYPE gst_omx_setup_tunnel (GstOMXPort * port1, GstOMXPort * port2);
423 OMX_ERRORTYPE gst_omx_close_tunnel (GstOMXPort * port1, GstOMXPort * port2);
426 OMX_ERRORTYPE gst_omx_port_get_port_definition (GstOMXPort * port, OMX_PARAM_PORTDEFINITIONTYPE * port_def);
427 OMX_ERRORTYPE gst_omx_port_update_port_definition (GstOMXPort *port, OMX_PARAM_PORTDEFINITIONTYPE *port_definition);
429 GstOMXAcquireBufferReturn gst_omx_port_acquire_buffer (GstOMXPort *port, GstOMXBuffer **buf);
430 OMX_ERRORTYPE gst_omx_port_release_buffer (GstOMXPort *port, GstOMXBuffer *buf);
432 OMX_ERRORTYPE gst_omx_port_set_flushing (GstOMXPort *port, GstClockTime timeout, gboolean flush);
433 gboolean gst_omx_port_is_flushing (GstOMXPort *port);
435 OMX_ERRORTYPE gst_omx_port_allocate_buffers (GstOMXPort *port);
436 #ifdef GST_TIZEN_MODIFICATION
437 OMX_ERRORTYPE gst_omx_port_tbm_allocate_dec_buffers (GstOMXPort * port, tbm_bufmgr bufMgr, int eCompressionFormat);
438 OMX_ERRORTYPE gst_omx_port_tbm_allocate_enc_buffers (GstOMXPort * port, tbm_bufmgr bufMgr, int eCompressionFormat);
440 OMX_ERRORTYPE gst_omx_port_use_buffers (GstOMXPort *port, const GList *buffers);
441 OMX_ERRORTYPE gst_omx_port_use_eglimages (GstOMXPort *port, const GList *images);
442 OMX_ERRORTYPE gst_omx_port_deallocate_buffers (GstOMXPort *port);
443 OMX_ERRORTYPE gst_omx_port_populate (GstOMXPort *port);
444 OMX_ERRORTYPE gst_omx_port_wait_buffers_released (GstOMXPort * port, GstClockTime timeout);
446 OMX_ERRORTYPE gst_omx_port_mark_reconfigured (GstOMXPort * port);
448 OMX_ERRORTYPE gst_omx_port_set_enabled (GstOMXPort * port, gboolean enabled);
449 OMX_ERRORTYPE gst_omx_port_wait_enabled (GstOMXPort * port, GstClockTime timeout);
450 gboolean gst_omx_port_is_enabled (GstOMXPort * port);
453 void gst_omx_set_default_role (GstOMXClassData *class_data, const gchar *default_role);
455 #ifdef GST_TIZEN_MODIFICATION
457 /*MFC Buffer alignment macros*/
458 #define S5P_FIMV_DEC_BUF_ALIGN (8 * 1024)
459 #define S5P_FIMV_ENC_BUF_ALIGN (8 * 1024)
460 #define S5P_FIMV_NV12M_HALIGN 16
461 #define S5P_FIMV_NV12M_LVALIGN 16
462 #define S5P_FIMV_NV12M_CVALIGN 8
463 #define S5P_FIMV_NV12MT_HALIGN 128
464 #define S5P_FIMV_NV12MT_VALIGN 64
465 #define S5P_FIMV_NV12M_SALIGN 2048
466 #define S5P_FIMV_NV12MT_SALIGN 8192
468 #define ALIGN(x, a) (((x) + (a) - 1) & ~((a) - 1))
470 /* Buffer alignment defines */
471 #define SZ_1M 0x00100000
472 #define S5P_FIMV_D_ALIGN_PLANE_SIZE 64
474 #define S5P_FIMV_MAX_FRAME_SIZE (2 * SZ_1M)
475 #define S5P_FIMV_NUM_PIXELS_IN_MB_ROW 16
476 #define S5P_FIMV_NUM_PIXELS_IN_MB_COL 16
479 #define ALIGN_TO_4KB(x) ((((x) + (1 << 12) - 1) >> 12) << 12)
480 #define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))
481 #define CHOOSE_MAX_SIZE(a,b) ((a) > (b) ? (a) : (b))
483 int new_calc_plane(int width, int height);
484 int new_calc_yplane(int width, int height);
485 int new_calc_uvplane(int width, int height);
487 int calc_plane(int width, int height);
488 int calc_yplane(int width, int height);
489 int calc_uvplane(int width, int height);
490 int gst_omx_calculate_y_size(int compressionFormat, int width, int height);
491 int gst_omx_calculate_uv_size(int compressionFormat, int width, int height);
493 tbm_bo gst_omx_tbm_allocate_bo(tbm_bufmgr hBufmgr, int size);
494 void gst_omx_tbm_deallocate_bo(tbm_bo bo);
495 OMX_U32 gst_omx_tbm_get_bo_fd(tbm_bo bo);
496 OMX_PTR gst_omx_tbm_get_bo_ptr(tbm_bo bo);
499 /* refered by plugin_init */
500 GST_DEBUG_CATEGORY_EXTERN (gst_omx_video_debug_category);
504 #endif /* __GST_OMX_H__ */