-
Notifications
You must be signed in to change notification settings - Fork 87
/
tiztc.c
221 lines (188 loc) · 6.79 KB
/
tiztc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
/**
* Copyright (C) 2011-2020 Aratelia Limited - Juan A. Rubio and contributors
*
* This file is part of Tizonia
*
* Tizonia is free software: you can redistribute it and/or modify it under the
* terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option)
* any later version.
*
* Tizonia is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
* more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Tizonia. If not, see <http://www.gnu.org/licenses/>.
*/
/**
* @file tiztc.c
* @author Juan A. Rubio <[email protected]>
*
* @brief Tizonia OpenMAX IL - Test IL Component
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include "tiztcproc.h"
#include "tizscheduler.h"
#include "tizport.h"
#include "tizpcmport.h"
#include "tizconfigport.h"
#include "tizplatform.h"
#include "OMX_Core.h"
#include "OMX_Component.h"
#include "OMX_Types.h"
#include <assert.h>
#include <string.h>
#ifdef TIZ_LOG_CATEGORY_NAME
#undef TIZ_LOG_CATEGORY_NAME
#define TIZ_LOG_CATEGORY_NAME "tiz.tizonia.test_comp"
#endif
#define TC_DEFAULT_ROLE1 "tizonia_test_component.role1"
#define TC_DEFAULT_ROLE2 "tizonia_test_component.role2"
#define TC_COMPONENT_NAME "OMX.Aratelia.tizonia.test_component"
#define TC_PORT_MIN_BUF_COUNT 1
#define TC_PORT_MIN_BUF_SIZE 1024
#define TC_PORT_NONCONTIGUOUS OMX_FALSE
#define TC_PORT_ALIGNMENT 0
#define TC_PORT_SUPPLIERPREF OMX_BufferSupplyInput
static OMX_VERSIONTYPE tc_comp_version = { {1, 0, 0, 0} };
static OMX_U8 *
pcm_port_alloc_hook (OMX_U32 * ap_size,
OMX_PTR * app_port_priv, void *ap_args)
{
OMX_U8 *p = NULL;
assert (ap_size);
p = tiz_mem_alloc (*ap_size * sizeof (OMX_U8));
TIZ_LOG (TIZ_PRIORITY_TRACE, "Test Component Alloc Hook :size[%u] p=[%p]",
*ap_size, p);
return p;
}
static void
pcm_port_free_hook (OMX_PTR ap_buf, OMX_PTR ap_port_priv, void *ap_args)
{
TIZ_LOG (TIZ_PRIORITY_TRACE, "Test Component Free Hook : ap_buf[%p]", ap_buf);
assert (ap_buf);
tiz_mem_free (ap_buf);
}
static OMX_BOOL
egl_image_validation_hook (const OMX_HANDLETYPE ap_hdl,
OMX_U32 pid, OMX_PTR ap_eglimage,
void *ap_args)
{
assert (ap_hdl);
assert (ap_eglimage);
assert (!ap_args);
TIZ_LOG (TIZ_PRIORITY_TRACE,
"Test Component EGLImage Hook : ap_eglimage=[%p]", ap_eglimage);
return OMX_TRUE;
}
static OMX_PTR
instantiate_pcm_port (OMX_HANDLETYPE ap_hdl)
{
OMX_AUDIO_PARAM_PCMMODETYPE pcmmode;
OMX_AUDIO_CONFIG_VOLUMETYPE volume;
OMX_AUDIO_CONFIG_MUTETYPE mute;
OMX_AUDIO_CODINGTYPE encodings[] = {
OMX_AUDIO_CodingPCM,
OMX_AUDIO_CodingMax
};
tiz_port_options_t port_opts = {
OMX_PortDomainAudio,
OMX_DirInput,
TC_PORT_MIN_BUF_COUNT,
TC_PORT_MIN_BUF_SIZE,
TC_PORT_NONCONTIGUOUS,
TC_PORT_ALIGNMENT,
TC_PORT_SUPPLIERPREF,
{0, pcm_port_alloc_hook, pcm_port_free_hook, NULL},
-1
};
TIZ_LOG (TIZ_PRIORITY_TRACE, "Inititializing the test component's pcm port");
/* Instantiate the pcm port */
pcmmode.nSize = sizeof (OMX_AUDIO_PARAM_PCMMODETYPE);
pcmmode.nVersion.nVersion = OMX_VERSION;
pcmmode.nPortIndex = 0;
pcmmode.nChannels = 2;
pcmmode.eNumData = OMX_NumericalDataSigned;
pcmmode.eEndian = OMX_EndianLittle;
pcmmode.bInterleaved = OMX_TRUE;
pcmmode.nBitPerSample = 16;
pcmmode.nSamplingRate = 48000;
pcmmode.ePCMMode = OMX_AUDIO_PCMModeLinear;
pcmmode.eChannelMapping[0] = OMX_AUDIO_ChannelLF;
pcmmode.eChannelMapping[1] = OMX_AUDIO_ChannelRF;
volume.nSize = sizeof (OMX_AUDIO_CONFIG_VOLUMETYPE);
volume.nVersion.nVersion = OMX_VERSION;
volume.nPortIndex = 0;
volume.bLinear = OMX_FALSE;
volume.sVolume.nValue = 75;
volume.sVolume.nMin = 0;
volume.sVolume.nMax = 100;
mute.nSize = sizeof (OMX_AUDIO_CONFIG_MUTETYPE);
mute.nVersion.nVersion = OMX_VERSION;
mute.nPortIndex = 0;
mute.bMute = OMX_FALSE;
return factory_new (tiz_get_type (ap_hdl, "tizpcmport"), &port_opts,
&encodings, &pcmmode, &volume, &mute);
}
static OMX_PTR
instantiate_config_port (OMX_HANDLETYPE ap_hdl)
{
return factory_new (tiz_get_type (ap_hdl, "tizconfigport"),
NULL, /* this port does not take options */
TC_COMPONENT_NAME, tc_comp_version);
}
static OMX_PTR
instantiate_processor (OMX_HANDLETYPE ap_hdl)
{
return factory_new (tiz_get_type (ap_hdl, "tiztcprc"));
}
OMX_ERRORTYPE
OMX_ComponentInit (OMX_HANDLETYPE ap_hdl)
{
tiz_role_factory_t role_factory1, role_factory2;
const tiz_role_factory_t *rf_list[] = { &role_factory1, &role_factory2 };
tiz_type_factory_t type_factory;
const tiz_type_factory_t *tf_list[] = { &type_factory};
const tiz_alloc_hooks_t new_hooks =
{ 0, pcm_port_alloc_hook, pcm_port_free_hook, NULL };
tiz_alloc_hooks_t old_hooks = { 0, NULL, NULL, NULL };
const tiz_eglimage_hook_t egl_validation_hook =
{ 0, egl_image_validation_hook, NULL };
strcpy ((OMX_STRING) role_factory1.role, TC_DEFAULT_ROLE1);
role_factory1.pf_cport = instantiate_config_port;
role_factory1.pf_port[0] = instantiate_pcm_port;
role_factory1.nports = 1;
role_factory1.pf_proc = instantiate_processor;
strcpy ((OMX_STRING) role_factory2.role, TC_DEFAULT_ROLE2);
role_factory2.pf_cport = instantiate_config_port;
role_factory2.pf_port[0] = instantiate_pcm_port;
role_factory2.nports = 1;
role_factory2.pf_proc = instantiate_processor;
strcpy ((OMX_STRING) type_factory.class_name, "tiztcprc_class");
type_factory.pf_class_init = tiz_tcprc_class_init;
strcpy ((OMX_STRING) type_factory.object_name, "tiztcprc");
type_factory.pf_object_init = tiz_tcprc_init;
TIZ_LOG (TIZ_PRIORITY_TRACE, "OMX_ComponentInit: "
"Inititializing the test component");
assert (ap_hdl);
/* Initialize the component infrastructure */
tiz_check_omx (tiz_comp_init (ap_hdl, TC_COMPONENT_NAME));
/* Register the "tiztcprc" class */
tiz_check_omx (tiz_comp_register_types (ap_hdl, tf_list, 1));
/* Register two roles */
tiz_check_omx (tiz_comp_register_roles (ap_hdl, rf_list, 2));
/* Register alloc hooks */
tiz_check_omx (tiz_comp_register_alloc_hooks
(ap_hdl, &new_hooks, &old_hooks));
/* Register egl image validation hook */
tiz_check_omx (tiz_comp_register_eglimage_hook
(ap_hdl, &egl_validation_hook));
/* Verify that the old hooks have been returned */
assert (old_hooks.pf_alloc);
assert (old_hooks.pf_free);
return OMX_ErrorNone;
}