Tizen 2.1 base
[profile/ivi/gst-openmax0.10.git] / omx / gstomx_util.h
1 /*
2  * Copyright (C) 2006-2007 Texas Instruments, Incorporated
3  * Copyright (C) 2007-2009 Nokia Corporation.
4  *
5  * Author: Felipe Contreras <felipe.contreras@nokia.com>
6  *
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.
11  *
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.
16  *
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
20  *
21  */
22
23 #ifndef GSTOMX_UTIL_H
24 #define GSTOMX_UTIL_H
25
26 #include <glib.h>
27 #include <OMX_Core.h>
28 #include <OMX_Component.h>
29
30 #include <async_queue.h>
31 #include <sem.h>
32
33 /* Typedefs. */
34
35 typedef struct GOmxCore GOmxCore;
36 typedef struct GOmxPort GOmxPort;
37 typedef struct GOmxImp GOmxImp;
38 typedef struct GOmxSymbolTable GOmxSymbolTable;
39 typedef enum GOmxPortType GOmxPortType;
40 /* MODIFICATION: omx vender */
41 typedef enum GOmxVendor GOmxVendor;
42
43 typedef void (*GOmxCb) (GOmxCore * core);
44 typedef void (*GOmxPortCb) (GOmxPort * port);
45
46 /* Enums. */
47
48 enum GOmxPortType
49 {
50   GOMX_PORT_INPUT,
51   GOMX_PORT_OUTPUT
52 };
53
54 /* Add_component_vendor */
55 enum GOmxVendor
56 {
57   GOMX_VENDOR_DEFAULT,
58   GOMX_VENDOR_SLSI,
59   GOMX_VENDOR_QCT
60 };
61
62 /* Structures. */
63
64 struct GOmxSymbolTable
65 {
66   OMX_ERRORTYPE (*init) (void);
67   OMX_ERRORTYPE (*deinit) (void);
68   OMX_ERRORTYPE (*get_handle) (OMX_HANDLETYPE * handle,
69       OMX_STRING name, OMX_PTR data, OMX_CALLBACKTYPE * callbacks);
70   OMX_ERRORTYPE (*free_handle) (OMX_HANDLETYPE handle);
71 };
72
73 struct GOmxImp
74 {
75   guint client_count;
76   void *dl_handle;
77   GOmxSymbolTable sym_table;
78   GMutex *mutex;
79 };
80
81 struct GOmxCore
82 {
83   gpointer object;   /**< GStreamer element. */
84
85   OMX_HANDLETYPE omx_handle;
86   OMX_ERRORTYPE omx_error;
87
88   OMX_STATETYPE omx_state;
89   GCond *omx_state_condition;
90   GMutex *omx_state_mutex;
91
92   GPtrArray *ports;
93
94   GSem *done_sem;
95   GSem *flush_sem;
96   GSem *port_sem;
97
98   GOmxCb settings_changed_cb;
99   GOmxImp *imp;
100
101   gboolean done;
102
103   gchar *library_name;
104   gchar *component_name;
105   gchar *component_role;
106   /* MODIFICATION: omx vender */
107   GOmxVendor component_vendor;
108 };
109
110 struct GOmxPort
111 {
112   GOmxCore *core;
113   GOmxPortType type;
114
115   guint num_buffers;
116   gulong buffer_size;
117   guint port_index;
118   OMX_BUFFERHEADERTYPE **buffers;
119
120   GMutex *mutex;
121   gboolean enabled;
122   gboolean omx_allocate;   /**< Setup with OMX_AllocateBuffer rather than OMX_UseBuffer */
123   AsyncQueue *queue;
124
125   gboolean shared_buffer; /* Modification */
126 };
127
128 /* Functions. */
129
130 void g_omx_init (void);
131 void g_omx_deinit (void);
132
133 GOmxCore *g_omx_core_new (void *object);
134 void g_omx_core_free (GOmxCore * core);
135 void g_omx_core_init (GOmxCore * core);
136 void g_omx_core_prepare (GOmxCore * core);
137 void g_omx_core_start (GOmxCore * core);
138 void g_omx_core_pause (GOmxCore * core);
139 void g_omx_core_stop (GOmxCore * core);
140 void g_omx_core_unload (GOmxCore * core);
141 void g_omx_core_set_done (GOmxCore * core);
142 void g_omx_core_wait_for_done (GOmxCore * core);
143 void g_omx_core_flush_start (GOmxCore * core);
144 void g_omx_core_flush_stop (GOmxCore * core);
145 GOmxPort *g_omx_core_new_port (GOmxCore * core, guint index);
146
147 GOmxPort *g_omx_port_new (GOmxCore * core, guint index);
148 void g_omx_port_free (GOmxPort * port);
149 void g_omx_port_setup (GOmxPort * port);
150 void g_omx_port_push_buffer (GOmxPort * port,
151     OMX_BUFFERHEADERTYPE * omx_buffer);
152 OMX_BUFFERHEADERTYPE *g_omx_port_request_buffer (GOmxPort * port);
153 void g_omx_port_release_buffer (GOmxPort * port,
154     OMX_BUFFERHEADERTYPE * omx_buffer);
155 void g_omx_port_resume (GOmxPort * port);
156 void g_omx_port_pause (GOmxPort * port);
157 void g_omx_port_flush (GOmxPort * port);
158 void g_omx_port_enable (GOmxPort * port);
159 void g_omx_port_disable (GOmxPort * port);
160 void g_omx_port_finish (GOmxPort * port);
161
162 /* Utility Macros */
163
164 /**
165  * Basically like GST_BOILERPLATE / GST_BOILERPLATE_FULL, but follows the
166  * init fxn naming conventions used by gst-openmax.  It expects the following
167  * functions to be defined in the same src file following this macro
168  * <ul>
169  *   <li> type_base_init(gpointer g_class)
170  *   <li> type_class_init(gpointer g_class, gpointer class_data)
171  *   <li> type_instance_init(GTypeInstance *instance, gpointer g_class)
172  * </ul>
173  */
174 #define GSTOMX_BOILERPLATE_FULL(type, type_as_function, parent_type, parent_type_macro, additional_initializations) \
175 static void type_base_init (gpointer g_class);                                \
176 static void type_class_init (gpointer g_class, gpointer class_data);          \
177 static void type_instance_init (GTypeInstance *instance, gpointer g_class);   \
178 static parent_type ## Class *parent_class;                                    \
179 static void type_class_init_trampoline (gpointer g_class, gpointer class_data)\
180 {                                                                             \
181     parent_class = g_type_class_ref (parent_type_macro);                      \
182     type_class_init (g_class, class_data);                                    \
183 }                                                                             \
184 GType type_as_function ## _get_type (void)                                    \
185 {                                                                             \
186     /* The typedef for GType may be gulong or gsize, depending on the         \
187      * system and whether the compiler is c++ or not. The g_once_init_*       \
188      * functions always take a gsize * though ... */                          \
189     static volatile gsize gonce_data = 0;                                     \
190     if (g_once_init_enter (&gonce_data)) {                                    \
191         GType _type;                                                          \
192         GTypeInfo *type_info;                                                 \
193         type_info = g_new0 (GTypeInfo, 1);                                    \
194         type_info->class_size = sizeof (type ## Class);                       \
195         type_info->base_init = type_base_init;                                \
196         type_info->class_init = type_class_init_trampoline;                   \
197         type_info->instance_size = sizeof (type);                             \
198         type_info->instance_init = type_instance_init;                        \
199         _type = g_type_register_static (parent_type_macro, #type, type_info, 0);\
200         g_free (type_info);                                                   \
201         additional_initializations (_type);                                   \
202         g_once_init_leave (&gonce_data, (gsize) _type);                       \
203     }                                                                         \
204     return (GType) gonce_data;                                                \
205 }
206
207 #define GSTOMX_BOILERPLATE(type,type_as_function,parent_type,parent_type_macro)    \
208   GSTOMX_BOILERPLATE_FULL (type, type_as_function, parent_type, parent_type_macro, \
209       __GST_DO_NOTHING)
210
211 #include <string.h>             /* for memset */
212 #define G_OMX_INIT_PARAM(param) G_STMT_START {                                \
213         memset (&(param), 0, sizeof ((param)));                               \
214         (param).nSize = sizeof (param);                                       \
215         (param).nVersion.s.nVersionMajor = 1;                                 \
216         (param).nVersion.s.nVersionMinor = 1;                                 \
217     } G_STMT_END
218
219
220 #endif /* GSTOMX_UTIL_H */