2 * Copyright (C) 2008-2009 Nokia Corporation.
4 * Author: Felipe Contreras <felipe.contreras@nokia.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <OMX_Component.h>
29 static const char *lib_name;
30 static void *dl_handle;
31 static OMX_ERRORTYPE (*init) (void);
32 static OMX_ERRORTYPE (*deinit) (void);
33 static OMX_ERRORTYPE (*get_handle) (OMX_HANDLETYPE * handle,
34 OMX_STRING name, OMX_PTR data, OMX_CALLBACKTYPE * callbacks);
35 static OMX_ERRORTYPE (*free_handle) (OMX_HANDLETYPE handle);
37 typedef struct CustomData CustomData;
41 OMX_HANDLETYPE omx_handle;
42 OMX_STATETYPE omx_state;
43 GCond *omx_state_condition;
44 GMutex *omx_state_mutex;
48 custom_data_new (void)
50 CustomData *custom_data;
51 custom_data = g_new0 (CustomData, 1);
52 custom_data->omx_state_condition = g_cond_new ();
53 custom_data->omx_state_mutex = g_mutex_new ();
58 custom_data_free (CustomData * custom_data)
60 g_mutex_free (custom_data->omx_state_mutex);
61 g_cond_free (custom_data->omx_state_condition);
66 change_state (CustomData * core, OMX_STATETYPE state)
68 fail_if (OMX_SendCommand (core->omx_handle, OMX_CommandStateSet, state,
69 NULL) != OMX_ErrorNone);
73 complete_change_state (CustomData * core, OMX_STATETYPE state)
75 g_mutex_lock (core->omx_state_mutex);
77 core->omx_state = state;
78 g_cond_signal (core->omx_state_condition);
80 g_mutex_unlock (core->omx_state_mutex);
84 wait_for_state (CustomData * core, OMX_STATETYPE state)
86 g_mutex_lock (core->omx_state_mutex);
88 while (core->omx_state != state)
89 g_cond_wait (core->omx_state_condition, core->omx_state_mutex);
91 g_mutex_unlock (core->omx_state_mutex);
95 EventHandler (OMX_HANDLETYPE omx_handle,
97 OMX_EVENTTYPE event, OMX_U32 data_1, OMX_U32 data_2, OMX_PTR event_data)
104 case OMX_EventCmdComplete:
108 cmd = (OMX_COMMANDTYPE) data_1;
111 case OMX_CommandStateSet:
112 complete_change_state (core, data_2);
123 return OMX_ErrorNone;
126 static OMX_CALLBACKTYPE callbacks = { EventHandler, NULL, NULL };
128 START_TEST (test_basic)
130 OMX_ERRORTYPE omx_error;
132 fail_if (omx_error != OMX_ErrorNone);
133 omx_error = deinit ();
134 fail_if (omx_error != OMX_ErrorNone);
138 START_TEST (test_handle)
140 OMX_ERRORTYPE omx_error;
141 OMX_HANDLETYPE omx_handle;
144 fail_if (omx_error != OMX_ErrorNone);
146 omx_error = get_handle (&omx_handle, "OMX.check.dummy", NULL, NULL);
147 fail_if (omx_error != OMX_ErrorNone);
149 omx_error = free_handle (omx_handle);
150 fail_if (omx_error != OMX_ErrorNone);
152 omx_error = deinit ();
153 fail_if (omx_error != OMX_ErrorNone);
157 START_TEST (test_idle)
159 CustomData *custom_data;
160 OMX_ERRORTYPE omx_error;
161 OMX_HANDLETYPE omx_handle;
163 custom_data = custom_data_new ();
166 fail_if (omx_error != OMX_ErrorNone);
169 get_handle (&omx_handle, "OMX.check.dummy", custom_data, &callbacks);
170 fail_if (omx_error != OMX_ErrorNone);
172 custom_data->omx_handle = omx_handle;
174 change_state (custom_data, OMX_StateIdle);
176 /* allocate_buffers */
178 wait_for_state (custom_data, OMX_StateIdle);
180 change_state (custom_data, OMX_StateLoaded);
184 wait_for_state (custom_data, OMX_StateLoaded);
186 omx_error = free_handle (omx_handle);
187 fail_if (omx_error != OMX_ErrorNone);
189 omx_error = deinit ();
190 fail_if (omx_error != OMX_ErrorNone);
192 custom_data_free (custom_data);
195 END_TEST static Suite *
198 Suite *s = suite_create ("libomxil");
199 TCase *tc_chain = tcase_create ("general");
201 lib_name = "libomxil-foo.so";
203 if (!g_thread_supported ())
204 g_thread_init (NULL);
207 dl_handle = dlopen (lib_name, RTLD_LAZY);
209 /** @todo report error. */
212 init = dlsym (dl_handle, "OMX_Init");
213 deinit = dlsym (dl_handle, "OMX_Deinit");
214 get_handle = dlsym (dl_handle, "OMX_GetHandle");
215 free_handle = dlsym (dl_handle, "OMX_FreeHandle");
218 tcase_add_test (tc_chain, test_basic);
219 tcase_add_test (tc_chain, test_handle);
220 tcase_add_test (tc_chain, test_idle);
221 suite_add_tcase (s, tc_chain);
234 sr = srunner_create (s);
235 srunner_run_all (sr, CK_NORMAL);
236 number_failed = srunner_ntests_failed (sr);
239 return (number_failed == 0) ? 0 : 1;