1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
3 | All rights reserved. |
4 | |
5 | Redistribution and use in source and binary forms, with or without |
6 | modification, are permitted provided that the following conditions are met: |
7 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | /** \file |
29 | * OpenMAX IL adaptation layer for MMAL |
30 | */ |
31 | |
32 | #include "interface/vmcs_host/khronos/IL/OMX_Core.h" |
33 | #include "interface/vmcs_host/khronos/IL/OMX_Component.h" |
34 | #include "interface/vmcs_host/khronos/IL/OMX_Video.h" |
35 | #include "interface/vmcs_host/khronos/IL/OMX_Audio.h" |
36 | #include <mmal.h> |
37 | #include <util/mmal_il.h> |
38 | |
39 | /* Define this to 1 if you want to log all buffer transfers */ |
40 | #define 0 |
41 | |
42 | #ifndef MMALOMX_EXPORT |
43 | # define MMALOMX_EXPORT(a) a |
44 | #endif |
45 | #ifndef MMALOMX_IMPORT |
46 | # define MMALOMX_IMPORT(a) a |
47 | #endif |
48 | |
49 | #define MAX_MARKS_NUM 2 |
50 | #define MAX_ENCODINGS_NUM 20 |
51 | |
52 | /** Per-port context data */ |
53 | typedef struct MMALOMX_PORT_T |
54 | { |
55 | struct MMALOMX_COMPONENT_T *component; |
56 | MMAL_PORT_T *mmal; |
57 | OMX_DIRTYPE direction; |
58 | unsigned int index; |
59 | unsigned int buffers; |
60 | unsigned int buffers_in_transit; |
61 | |
62 | MMAL_BOOL_T buffers_allocated:1; |
63 | MMAL_BOOL_T enabled:1; |
64 | MMAL_BOOL_T populated:1; |
65 | MMAL_BOOL_T zero_copy:1; |
66 | MMAL_BOOL_T no_cropping:1; |
67 | MMAL_BOOL_T format_changed:1; |
68 | MMAL_POOL_T *pool; |
69 | |
70 | uint32_t actions; |
71 | |
72 | OMX_MARKTYPE marks[MAX_MARKS_NUM]; |
73 | unsigned int marks_first:8; |
74 | unsigned int marks_num:8; |
75 | |
76 | OMX_FORMAT_PARAM_TYPE format_param; |
77 | |
78 | MMAL_PARAMETER_HEADER_T ; |
79 | MMAL_FOURCC_T encodings[MAX_ENCODINGS_NUM]; |
80 | unsigned int encodings_num; |
81 | |
82 | } MMALOMX_PORT_T; |
83 | |
84 | /** Component context data */ |
85 | typedef struct MMALOMX_COMPONENT_T { |
86 | OMX_COMPONENTTYPE omx; /**< OMX component type structure */ |
87 | |
88 | unsigned int registry_id; |
89 | const char *name; |
90 | uint32_t role; |
91 | OMX_CALLBACKTYPE callbacks; |
92 | OMX_PTR callbacks_data; |
93 | |
94 | struct MMAL_COMPONENT_T *mmal; |
95 | OMX_STATETYPE state; |
96 | unsigned int state_transition; |
97 | |
98 | MMALOMX_PORT_T *ports; |
99 | unsigned int ports_num; |
100 | unsigned int ports_domain_num[4]; |
101 | |
102 | MMAL_BOOL_T actions_running; |
103 | |
104 | OMX_U32 group_id; |
105 | OMX_U32 group_priority; |
106 | |
107 | /* Support for command queues */ |
108 | MMAL_POOL_T *cmd_pool; |
109 | MMAL_QUEUE_T *cmd_queue; |
110 | VCOS_THREAD_T cmd_thread; |
111 | MMAL_BOOL_T cmd_thread_used; |
112 | VCOS_SEMAPHORE_T cmd_sema; |
113 | |
114 | VCOS_MUTEX_T lock; /**< Used to protect component state */ |
115 | VCOS_MUTEX_T lock_port; /**< Used to protect port state */ |
116 | |
117 | } MMALOMX_COMPONENT_T; |
118 | |
119 | OMX_ERRORTYPE mmalomx_callback_event_handler( |
120 | MMALOMX_COMPONENT_T *component, |
121 | OMX_EVENTTYPE eEvent, |
122 | OMX_U32 nData1, |
123 | OMX_U32 nData2, |
124 | OMX_PTR pEventData); |
125 | |
126 | #define MMALOMX_LOCK(a) vcos_mutex_lock(&a->lock) |
127 | #define MMALOMX_UNLOCK(a) vcos_mutex_unlock(&a->lock) |
128 | #define MMALOMX_LOCK_PORT(a,b) vcos_mutex_lock(&a->lock_port) |
129 | #define MMALOMX_UNLOCK_PORT(a,b) vcos_mutex_unlock(&a->lock_port) |
130 | |
131 | |