1/*
2Copyright (c) 2012, Broadcom Europe Ltd
3All rights reserved.
4
5Redistribution and use in source and binary forms, with or without
6modification, 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
16THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23ON 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
25SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26*/
27
28/** \file
29 * OpenMAX IL adaptation layer for MMAL - Parameters related functions
30 */
31
32#include "interface/vmcs_host/khronos/IL/OMX_Broadcom.h"
33#include "mmalomx_util_params.h"
34#include "util/mmal_util_rational.h"
35
36/* Sanity check that OMX is defining the right int32 types */
37vcos_static_assert(sizeof(OMX_U32) == 4);
38
39MMAL_STATUS_T mmalomx_param_enum_generic(MMALOMX_PARAM_MAPPING_DIRECTION dir,
40 const struct MMALOMX_PARAM_TRANSLATION_T *xlat,
41 MMAL_PARAMETER_HEADER_T *mmal, OMX_PTR omx, MMAL_PORT_T *mmal_port);
42MMAL_STATUS_T mmalomx_param_rational_generic(MMALOMX_PARAM_MAPPING_DIRECTION dir,
43 const struct MMALOMX_PARAM_TRANSLATION_T *xlat,
44 MMAL_PARAMETER_HEADER_T *mmal, OMX_PTR omx, MMAL_PORT_T *mmal_port);
45MMAL_STATUS_T mmalomx_param_mapping_generic(MMALOMX_PARAM_MAPPING_DIRECTION dir,
46 const struct MMALOMX_PARAM_TRANSLATION_T *xlat,
47 MMAL_PARAMETER_HEADER_T *mmal, OMX_PTR omx, MMAL_PORT_T *mmal_port);
48
49extern const MMALOMX_PARAM_TRANSLATION_T mmalomx_param_xlator_audio[];
50extern const MMALOMX_PARAM_TRANSLATION_T mmalomx_param_xlator_video[];
51extern const MMALOMX_PARAM_TRANSLATION_T mmalomx_param_xlator_camera[];
52extern const MMALOMX_PARAM_TRANSLATION_T mmalomx_param_xlator_misc[];
53
54#define MMALOMX_PARAM_ENUM_FIND(TYPE, VAR, TABLE, DIR, MMAL, OMX) \
55 const TYPE *VAR = TABLE; \
56 const TYPE *VAR##_end = VAR + MMAL_COUNTOF(TABLE); \
57 if (DIR == MMALOMX_PARAM_MAPPING_TO_MMAL) \
58 while (VAR < VAR##_end && VAR->omx != OMX) VAR++; \
59 else \
60 while (VAR < VAR##_end && VAR->mmal != MMAL) VAR++; \
61 do { if (VAR == VAR##_end) { \
62 VAR = 0; \
63 if (DIR == MMALOMX_PARAM_MAPPING_TO_MMAL) \
64 VCOS_ALERT("omx enum value %u not supported", (unsigned int)OMX); \
65 else \
66 VCOS_ALERT("mmal enum value %u not supported", (unsigned int)MMAL); \
67 } } while(0)
68
69#define mmalomx_ct_assert(e) (sizeof(char[1 - 2*!(e)]))
70
71/** List of macros used to define parameters mapping */
72#define MMALOMX_PARAM_PASSTHROUGH(a,b,c,d) \
73 {a, (uint32_t)c, sizeof(b), sizeof(d), \
74 !(offsetof(d, nPortIndex) | mmalomx_ct_assert(sizeof(b)+4==sizeof(d))), \
75 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_mapping_generic, 0, 0}, 0, 0, \
76 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
77#define MMALOMX_PARAM_BOOLEAN(a, b) \
78 MMALOMX_PARAM_PASSTHROUGH(a, MMAL_PARAMETER_BOOLEAN_T, b, OMX_CONFIG_PORTBOOLEANTYPE)
79#define MMALOMX_PARAM_PASSTHROUGH_PORTLESS(a,b,c,d) \
80 {a, (uint32_t)c, sizeof(b), sizeof(d), \
81 !!(mmalomx_ct_assert(sizeof(b)==sizeof(d))), \
82 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_mapping_generic, 0, 0}, 0, 0, \
83 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
84#define MMALOMX_PARAM_BOOLEAN_PORTLESS(a, b) \
85 MMALOMX_PARAM_PASSTHROUGH_PORTLESS(a, MMAL_PARAMETER_BOOLEAN_T, b, OMX_CONFIG_BOOLEANTYPE)
86#define MMALOMX_PARAM_PASSTHROUGH_PORTLESS_DOUBLE_TRANSLATION(a,b,c,d) \
87 {a, (uint32_t)c, sizeof(b), sizeof(d), \
88 !!(mmalomx_ct_assert(sizeof(b)==sizeof(d))), \
89 1, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_mapping_generic, 0, 0}, 0, 0, \
90 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
91#define MMALOMX_PARAM_DIRECT_PORTLESS(a,b,c,d) \
92 {a, (uint32_t)c, sizeof(b), sizeof(d), 1, \
93 0, MMALOMX_PARAM_TRANSLATION_TYPE_DIRECT, {0, 0, 0, 0}, 0, 0, \
94 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
95#define MMALOMX_PARAM_STRAIGHT_MAPPING(a,b,c,d,e) \
96 {a, (uint32_t)c, sizeof(b), sizeof(d), \
97 !offsetof(d, nPortIndex), \
98 0, MMALOMX_PARAM_TRANSLATION_TYPE_SIMPLE, {e, 0, 0, 0}, 0, 0, \
99 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
100#define MMALOMX_PARAM_STRAIGHT_MAPPING_PORTLESS(a,b,c,d,e) \
101 {a, (uint32_t)c, sizeof(b), sizeof(d), 1, \
102 0, MMALOMX_PARAM_TRANSLATION_TYPE_SIMPLE, {e, 0, 0, 0}, 0, 0, \
103 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
104#define MMALOMX_PARAM_STRAIGHT_MAPPING_DOUBLE_TRANSLATION(a,b,c,d,e) \
105 {a, (uint32_t)c, sizeof(b), sizeof(d), 0, \
106 1, MMALOMX_PARAM_TRANSLATION_TYPE_SIMPLE, {e, 0, 0, 0}, 0, 0, \
107 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
108#define MMALOMX_PARAM_ENUM(a,b,c,d,e) \
109 {a, (uint32_t)c, sizeof(b), sizeof(d), 0, \
110 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_enum_generic, 0, 0}, e, MMAL_COUNTOF(e), \
111 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
112#define MMALOMX_PARAM_ENUM_PORTLESS(a,b,c,d,e) \
113 {a, (uint32_t)c, sizeof(b), sizeof(d), 1, \
114 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_enum_generic, 0, 0}, e, MMAL_COUNTOF(e), \
115 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
116#define MMALOMX_PARAM_RATIONAL(a,b,c,d,e) \
117 {a, (uint32_t)c, sizeof(b), sizeof(d), 0, \
118 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_rational_generic, 0, 0}, 0, e, \
119 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
120#define MMALOMX_PARAM_RATIONAL_PORTLESS(a,b,c,d,e) \
121 {a, (uint32_t)c, sizeof(b), sizeof(d), 1, \
122 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, mmalomx_param_rational_generic, 0, 0}, 0, e, \
123 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
124#define MMALOMX_PARAM_CUSTOM(a,b,c,d,e) \
125 {a, (uint32_t)c, sizeof(b), sizeof(d), 0, \
126 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, e, 0, 0}, 0, 0, \
127 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
128#define MMALOMX_PARAM_LIST(a,b,c,d,e,f) \
129 {a, (uint32_t)c, sizeof(b), sizeof(d), 0, \
130 0, MMALOMX_PARAM_TRANSLATION_TYPE_CUSTOM, {0, 0, f, 0}, 0, offsetof(d,e), \
131 MMAL_TO_STRING(a), MMAL_TO_STRING(c)}
132#define MMALOMX_PARAM_TERMINATE() \
133 {MMAL_PARAMETER_UNUSED, 0, 0, 0, 0, 0, 0, {0, 0, 0, 0}, 0, 0, 0, 0}
134