Projektarbeit Line Following Robot bei Prof. Chowanetz im WS22/23
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mmalomx_parameters.c 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  1. /*
  2. Copyright (c) 2012, Broadcom Europe Ltd
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are met:
  6. * Redistributions of source code must retain the above copyright
  7. notice, this list of conditions and the following disclaimer.
  8. * Redistributions in binary form must reproduce the above copyright
  9. notice, this list of conditions and the following disclaimer in the
  10. documentation and/or other materials provided with the distribution.
  11. * Neither the name of the copyright holder nor the
  12. names of its contributors may be used to endorse or promote products
  13. derived from this software without specific prior written permission.
  14. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  15. ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  16. WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  17. DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
  18. DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  19. (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  20. LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  21. ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  22. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  23. SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  24. */
  25. #include "interface/vmcs_host/khronos/IL/OMX_Broadcom.h"
  26. #include "mmalomx.h"
  27. #include "mmalomx_parameters.h"
  28. #include "mmalomx_util_params.h"
  29. #include "mmalomx_roles.h"
  30. #include "mmalomx_registry.h"
  31. #include "mmalomx_logging.h"
  32. #include <util/mmal_util.h>
  33. #include <util/mmal_util_params.h>
  34. #include <util/mmal_util_rational.h>
  35. #define PARAM_GET_PORT(port, component, index) \
  36. if (index >= component->ports_num) return OMX_ErrorBadPortIndex; \
  37. port = &component->ports[index]
  38. #define MMALOMX_PARAM_GENERIC_MAX 256
  39. /** A structure capable of holding any OMX parameter that contains a port */
  40. typedef struct MMALOMX_PARAM_OMX_GENERIC_T
  41. {
  42. MMALOMX_PARAM_OMX_HEADER_T header;
  43. uint8_t data[MMALOMX_PARAM_GENERIC_MAX];
  44. } MMALOMX_PARAM_OMX_GENERIC_T;
  45. /** A structure capable of holding any OMX parameter that doesn't contain a port */
  46. typedef struct MMALOMX_PARAM_OMX_GENERIC_PORTLESS_T
  47. {
  48. MMALOMX_PARAM_OMX_HEADER_PORTLESS_T hdr;
  49. uint8_t data[MMALOMX_PARAM_GENERIC_MAX];
  50. } MMALOMX_PARAM_OMX_GENERIC_PORTLESS_T;
  51. /** A structure capable of holding any MMAL parameter */
  52. typedef struct MMALOMX_PARAM_MMAL_GENERIC_T
  53. {
  54. MMAL_PARAMETER_HEADER_T header;
  55. uint8_t data[MMALOMX_PARAM_GENERIC_MAX];
  56. } MMALOMX_PARAM_MMAL_GENERIC_T;
  57. static OMX_ERRORTYPE mmalomx_parameter_set_xlat(MMALOMX_COMPONENT_T *component,
  58. OMX_INDEXTYPE nParamIndex, OMX_PTR pParam)
  59. {
  60. const MMALOMX_PARAM_TRANSLATION_T *xlat = mmalomx_find_parameter_from_omx_id(nParamIndex);
  61. MMALOMX_PARAM_OMX_HEADER_T *omx_header = (MMALOMX_PARAM_OMX_HEADER_T *)pParam;
  62. MMALOMX_PARAM_MMAL_GENERIC_T mmal_generic;
  63. MMAL_PARAMETER_HEADER_T *mmal_header = &mmal_generic.header;
  64. MMAL_PORT_T *mmal_port = component->mmal->control;
  65. MMAL_STATUS_T status;
  66. if (!xlat)
  67. {
  68. LOG_DEBUG("no translation for omx id 0x%08x", nParamIndex);
  69. return OMX_ErrorNotImplemented;
  70. }
  71. if (!xlat->portless)
  72. {
  73. if (omx_header->nSize < sizeof(*omx_header))
  74. return OMX_ErrorBadParameter;
  75. if (omx_header->nPortIndex >= component->ports_num)
  76. return OMX_ErrorBadPortIndex;
  77. mmal_port = component->ports[omx_header->nPortIndex].mmal;
  78. }
  79. if (omx_header->nSize < xlat->omx_size)
  80. return OMX_ErrorBadParameter;
  81. /* Handle the direct case first */
  82. if (xlat->type == MMALOMX_PARAM_TRANSLATION_TYPE_DIRECT)
  83. {
  84. mmal_header = (MMAL_PARAMETER_HEADER_T *)(((uint8_t *)pParam) + (xlat->portless ? 0 : 4));
  85. mmal_generic.header = *mmal_header;
  86. mmal_header->size = omx_header->nSize - (xlat->portless ? 0 : 4);
  87. mmal_header->id = xlat->mmal_id;
  88. status = mmal_port_parameter_set(mmal_port, mmal_header);
  89. *mmal_header = mmal_generic.header;
  90. return mmalil_error_to_omx(status);
  91. }
  92. if (!xlat->fn.generic && !xlat->fn.simple)
  93. {
  94. // FIXME
  95. return OMX_ErrorNotImplemented;
  96. }
  97. // FIXME: check size of mmal_generic is sufficient
  98. if (sizeof(mmal_generic) < xlat->mmal_size)
  99. return OMX_ErrorBadParameter;
  100. mmal_header->size = xlat->mmal_size;
  101. mmal_header->id = xlat->mmal_id;
  102. if (xlat->fn.generic)
  103. status = xlat->fn.generic(MMALOMX_PARAM_MAPPING_TO_MMAL, xlat, mmal_header, pParam, mmal_port);
  104. else
  105. status = xlat->fn.simple(MMALOMX_PARAM_MAPPING_TO_MMAL, mmal_header, pParam);
  106. if (status != MMAL_SUCCESS)
  107. goto error;
  108. status = mmal_port_parameter_set(mmal_port, mmal_header);
  109. error:
  110. return mmalil_error_to_omx(status);
  111. }
  112. static OMX_ERRORTYPE mmalomx_parameter_get_xlat(MMALOMX_COMPONENT_T *component,
  113. OMX_INDEXTYPE nParamIndex, OMX_PTR pParam)
  114. {
  115. const MMALOMX_PARAM_TRANSLATION_T *xlat = mmalomx_find_parameter_from_omx_id(nParamIndex);
  116. MMALOMX_PARAM_OMX_HEADER_T *omx_header = (MMALOMX_PARAM_OMX_HEADER_T *)pParam;
  117. MMALOMX_PARAM_MMAL_GENERIC_T mmal_generic;
  118. MMAL_PARAMETER_HEADER_T *mmal_header = &mmal_generic.header;
  119. MMAL_PORT_T *mmal_port = component->mmal->control;
  120. MMAL_STATUS_T status = MMAL_SUCCESS;
  121. if (!xlat)
  122. return OMX_ErrorNotImplemented;
  123. if (!xlat->portless)
  124. {
  125. if (omx_header->nSize < sizeof(*omx_header))
  126. return OMX_ErrorBadParameter;
  127. if (omx_header->nPortIndex >= component->ports_num)
  128. return OMX_ErrorBadPortIndex;
  129. mmal_port = component->ports[omx_header->nPortIndex].mmal;
  130. }
  131. if (omx_header->nSize < xlat->omx_size)
  132. return OMX_ErrorBadParameter;
  133. /* Handle the direct case first */
  134. if (xlat->type == MMALOMX_PARAM_TRANSLATION_TYPE_DIRECT)
  135. {
  136. OMX_U32 size;
  137. mmal_header = (MMAL_PARAMETER_HEADER_T *)(((uint8_t *)pParam) + (xlat->portless ? 0 : 4));
  138. mmal_generic.header = *mmal_header;
  139. mmal_header->size = omx_header->nSize - (xlat->portless ? 0 : 4);
  140. mmal_header->id = xlat->mmal_id;
  141. status = mmal_port_parameter_get(mmal_port, mmal_header);
  142. *mmal_header = mmal_generic.header;
  143. size = mmal_header->size + (xlat->portless ? 0 : 4);
  144. omx_header->nSize = size;
  145. return mmalil_error_to_omx(status);
  146. }
  147. if (xlat->fn.custom)
  148. {
  149. return xlat->fn.custom(MMALOMX_PARAM_MAPPING_TO_OMX, xlat, mmal_header,
  150. pParam, mmal_port);
  151. }
  152. if (xlat->fn.list)
  153. {
  154. OMX_U32 index, elements;
  155. mmal_header = mmal_port_parameter_alloc_get(mmal_port, xlat->mmal_id,
  156. 10*xlat->mmal_size, &status);
  157. if (!mmal_header)
  158. return OMX_ErrorInsufficientResources;
  159. /* Check we're not requesting too much */
  160. index = *(OMX_U32 *)(((uint8_t *)pParam) + xlat->xlat_enum_num);
  161. elements = (mmal_header->size - sizeof(MMAL_PARAMETER_HEADER_T)) /
  162. (xlat->mmal_size - sizeof(MMAL_PARAMETER_HEADER_T));
  163. if (index >= elements)
  164. {
  165. vcos_free(mmal_header);
  166. return OMX_ErrorNoMore;
  167. }
  168. status = xlat->fn.list(MMALOMX_PARAM_MAPPING_TO_OMX, xlat, index, mmal_header, pParam, mmal_port);
  169. vcos_free(mmal_header);
  170. return mmalil_error_to_omx(status);
  171. }
  172. if (!xlat->fn.generic && !xlat->fn.simple)
  173. {
  174. // FIXME
  175. return OMX_ErrorNotImplemented;
  176. }
  177. // FIXME: check size of mmal_generic is sufficient
  178. if (sizeof(mmal_generic) < xlat->mmal_size)
  179. return OMX_ErrorBadParameter;
  180. mmal_header->size = xlat->mmal_size;
  181. mmal_header->id = xlat->mmal_id;
  182. if (xlat->double_translation)
  183. {
  184. if (xlat->fn.generic)
  185. status = xlat->fn.generic(MMALOMX_PARAM_MAPPING_TO_MMAL, xlat, mmal_header, pParam, mmal_port);
  186. else
  187. status = xlat->fn.simple(MMALOMX_PARAM_MAPPING_TO_MMAL, mmal_header, pParam);
  188. }
  189. if (status != MMAL_SUCCESS)
  190. goto error;
  191. status = mmal_port_parameter_get(mmal_port, mmal_header);
  192. if (status != MMAL_SUCCESS)
  193. goto error;
  194. if (xlat->fn.generic)
  195. status = xlat->fn.generic(MMALOMX_PARAM_MAPPING_TO_OMX, xlat, mmal_header, pParam, mmal_port);
  196. else
  197. status = xlat->fn.simple(MMALOMX_PARAM_MAPPING_TO_OMX, mmal_header, pParam);
  198. error:
  199. return mmalil_error_to_omx(status);
  200. }
  201. OMX_ERRORTYPE mmalomx_parameter_extension_index_get(OMX_STRING cParameterName,
  202. OMX_INDEXTYPE *pIndex)
  203. {
  204. const MMALOMX_PARAM_TRANSLATION_T *xlat;
  205. MMAL_BOOL_T config = MMAL_FALSE;
  206. unsigned int i = 0;
  207. /* Check we're dealing with our extensions */
  208. if (!vcos_strncasecmp(cParameterName, MMALOMX_COMPONENT_PREFIX, sizeof(MMALOMX_COMPONENT_PREFIX)-1))
  209. return OMX_ErrorNotImplemented;
  210. cParameterName += sizeof(MMALOMX_COMPONENT_PREFIX)-1;
  211. /* Check if we're dealing with a config or param */
  212. if (!vcos_strncasecmp(cParameterName, "index.config.", sizeof("index.config.")-1))
  213. config = MMAL_TRUE;
  214. if (!config && vcos_strncasecmp(cParameterName, "index.param.", sizeof("index.param.")-1))
  215. return OMX_ErrorNotImplemented;
  216. if (config)
  217. cParameterName += sizeof("index.config.")-1;
  218. else
  219. cParameterName += sizeof("index.param.")-1;
  220. /* Loop through all the */
  221. while ((xlat = mmalomx_find_parameter_enum(i++)) != NULL)
  222. {
  223. const char *name = xlat->omx_name;
  224. /* We only report vendor extensions */
  225. if (xlat->omx_id < OMX_IndexVendorStartUnused)
  226. continue;
  227. /* Strip out the standard prefix */
  228. if (config)
  229. {
  230. if (!strncmp(name, "OMX_IndexConfigBrcm", sizeof("OMX_IndexConfigBrcm")-1))
  231. name += sizeof("OMX_IndexConfigBrcm")-1;
  232. else if (!strncmp(name, "OMX_IndexConfig", sizeof("OMX_IndexConfig")-1))
  233. name += sizeof("OMX_IndexConfig")-1;
  234. else continue;
  235. }
  236. else
  237. {
  238. if (!strncmp(name, "OMX_IndexParamBrcm", sizeof("OMX_IndexParamBrcm")-1))
  239. name += sizeof("OMX_IndexParamBrcm")-1;
  240. else if (!strncmp(name, "OMX_IndexParam", sizeof("OMX_IndexParam")-1))
  241. name += sizeof("OMX_IndexParam")-1;
  242. else continue;
  243. }
  244. /* Compare the last part of the name */
  245. if (!vcos_strcasecmp(name, cParameterName))
  246. {
  247. *pIndex = xlat->omx_id;
  248. return OMX_ErrorNone;
  249. }
  250. }
  251. return OMX_ErrorNotImplemented;
  252. }
  253. /*****************************************************************************/
  254. static OMX_ERRORTYPE mmalomx_get_video_param(MMALOMX_PORT_T *port,
  255. uint32_t *profile, uint32_t *level, uint32_t *intraperiod)
  256. {
  257. MMAL_PARAMETER_VIDEO_PROFILE_T mmal_param = {{MMAL_PARAMETER_PROFILE, sizeof(mmal_param)},
  258. {{(MMAL_VIDEO_PROFILE_T)0, (MMAL_VIDEO_LEVEL_T)0}}};
  259. *profile = *level = *intraperiod = 0;
  260. mmal_port_parameter_get_uint32(port->mmal, MMAL_PARAMETER_INTRAPERIOD, intraperiod);
  261. if (mmal_port_parameter_get(port->mmal, &mmal_param.hdr) == MMAL_SUCCESS)
  262. {
  263. *profile = mmalil_video_profile_to_omx(mmal_param.profile[0].profile);
  264. *level = mmalil_video_level_to_omx(mmal_param.profile[0].level);
  265. }
  266. return OMX_ErrorNone;
  267. }
  268. /*****************************************************************************/
  269. OMX_ERRORTYPE mmalomx_parameter_get(MMALOMX_COMPONENT_T *component,
  270. OMX_INDEXTYPE nParamIndex, OMX_PTR pParam)
  271. {
  272. MMALOMX_PORT_T *port = NULL;
  273. switch(nParamIndex)
  274. {
  275. /* All OMX_IndexParamVideo parameters are only partially implemented
  276. * and we try and use sensible hard-coded values for the rest. */
  277. case OMX_IndexParamVideoAvc:
  278. {
  279. OMX_VIDEO_PARAM_AVCTYPE *param = (OMX_VIDEO_PARAM_AVCTYPE *)pParam;
  280. uint32_t profile, level, intraperiod;
  281. PARAM_GET_PORT(port, component, param->nPortIndex);
  282. if (param->nSize < sizeof(*param))
  283. return OMX_ErrorBadParameter;
  284. memset(&param->nSliceHeaderSpacing, 0,
  285. param->nSize - offsetof(OMX_VIDEO_PARAM_AVCTYPE, nSliceHeaderSpacing));
  286. mmalomx_get_video_param(port, &profile, &level, &intraperiod);
  287. param->eProfile = (OMX_VIDEO_AVCPROFILETYPE)profile;
  288. param->eLevel = (OMX_VIDEO_AVCLEVELTYPE)level;
  289. param->nPFrames = intraperiod - 1;
  290. param->bUseHadamard = OMX_TRUE;
  291. param->nRefFrames = 1;
  292. param->nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
  293. param->bFrameMBsOnly = OMX_TRUE;
  294. if (param->eProfile != OMX_VIDEO_AVCProfileBaseline)
  295. param->bEntropyCodingCABAC = OMX_TRUE;
  296. param->eLoopFilterMode = OMX_VIDEO_AVCLoopFilterEnable;
  297. }
  298. return OMX_ErrorNone;
  299. case OMX_IndexParamVideoMpeg4:
  300. {
  301. OMX_VIDEO_PARAM_MPEG4TYPE *param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pParam;
  302. uint32_t profile, level, intraperiod;
  303. PARAM_GET_PORT(port, component, param->nPortIndex);
  304. if (param->nSize < sizeof(*param))
  305. return OMX_ErrorBadParameter;
  306. memset(&param->nSliceHeaderSpacing, 0,
  307. param->nSize - offsetof(OMX_VIDEO_PARAM_MPEG4TYPE, nSliceHeaderSpacing));
  308. mmalomx_get_video_param(port, &profile, &level, &intraperiod);
  309. param->eProfile = (OMX_VIDEO_MPEG4PROFILETYPE)profile;
  310. param->eLevel = (OMX_VIDEO_MPEG4LEVELTYPE)level;
  311. param->nPFrames = intraperiod - 1;
  312. param->bACPred = OMX_TRUE;
  313. param->nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
  314. }
  315. return OMX_ErrorNone;
  316. case OMX_IndexParamVideoH263:
  317. {
  318. OMX_VIDEO_PARAM_H263TYPE *param = (OMX_VIDEO_PARAM_H263TYPE *)pParam;
  319. uint32_t profile, level, intraperiod;
  320. PARAM_GET_PORT(port, component, param->nPortIndex);
  321. if (param->nSize < sizeof(*param))
  322. return OMX_ErrorBadParameter;
  323. memset(&param->nPFrames, 0,
  324. param->nSize - offsetof(OMX_VIDEO_PARAM_H263TYPE, nPFrames));
  325. mmalomx_get_video_param(port, &profile, &level, &intraperiod);
  326. param->eProfile = (OMX_VIDEO_H263PROFILETYPE)profile;
  327. param->eLevel = (OMX_VIDEO_H263LEVELTYPE)level;
  328. param->nPFrames = intraperiod - 1;
  329. param->nAllowedPictureTypes = OMX_VIDEO_PictureTypeI | OMX_VIDEO_PictureTypeP;
  330. }
  331. return OMX_ErrorNone;
  332. case OMX_IndexParamVideoMpeg2:
  333. case OMX_IndexParamVideoWmv:
  334. case OMX_IndexParamVideoRv:
  335. {
  336. OMX_FORMAT_PARAM_TYPE *param = (OMX_FORMAT_PARAM_TYPE *)pParam;
  337. PARAM_GET_PORT(port, component, param->common.nPortIndex);
  338. OMX_U32 offset = offsetof(OMX_PARAM_U32TYPE, nU32);
  339. if (param->common.nSize > sizeof(port->format_param) ||
  340. param->common.nSize < offset)
  341. return OMX_ErrorBadParameter;
  342. memcpy(&param->common.nU32, &port->format_param.common.nU32,
  343. param->common.nSize - offset);
  344. return OMX_ErrorNone;
  345. }
  346. case OMX_IndexParamAudioPcm:
  347. case OMX_IndexParamAudioAac:
  348. case OMX_IndexParamAudioMp3:
  349. case OMX_IndexParamAudioDdp:
  350. {
  351. OMX_FORMAT_PARAM_TYPE *param = (OMX_FORMAT_PARAM_TYPE *)pParam;
  352. PARAM_GET_PORT(port, component, param->common.nPortIndex);
  353. OMX_U32 offset = offsetof(OMX_PARAM_U32TYPE, nU32);
  354. if (param->common.nSize > sizeof(port->format_param) ||
  355. param->common.nSize < offset)
  356. return OMX_ErrorBadParameter;
  357. memcpy(&param->common.nU32, &port->format_param.common.nU32,
  358. param->common.nSize - offset);
  359. mmalil_format_to_omx_audio_param(param, NULL, port->mmal->format);
  360. return OMX_ErrorNone;
  361. }
  362. case OMX_IndexParamBrcmPixelAspectRatio:
  363. {
  364. OMX_CONFIG_POINTTYPE *param = (OMX_CONFIG_POINTTYPE *)pParam;
  365. PARAM_GET_PORT(port, component, param->nPortIndex);
  366. param->nX = port->mmal->format->es->video.par.num;
  367. param->nY = port->mmal->format->es->video.par.den;
  368. return OMX_ErrorNone;
  369. }
  370. case OMX_IndexParamColorSpace:
  371. {
  372. OMX_PARAM_COLORSPACETYPE *param = (OMX_PARAM_COLORSPACETYPE *)pParam;
  373. PARAM_GET_PORT(port, component, param->nPortIndex);
  374. param->eColorSpace = mmalil_color_space_to_omx(port->mmal->format->es->video.color_space);
  375. return OMX_ErrorNone;
  376. }
  377. case OMX_IndexConfigCommonOutputCrop:
  378. {
  379. OMX_CONFIG_RECTTYPE *param = (OMX_CONFIG_RECTTYPE *)pParam;
  380. PARAM_GET_PORT(port, component, param->nPortIndex);
  381. param->nLeft = port->mmal->format->es->video.crop.x;
  382. param->nTop = port->mmal->format->es->video.crop.y;
  383. param->nWidth = port->mmal->format->es->video.width;
  384. if (port->mmal->format->es->video.crop.width)
  385. param->nWidth = port->mmal->format->es->video.crop.width;
  386. param->nHeight = port->mmal->format->es->video.height;
  387. if (port->mmal->format->es->video.crop.height)
  388. param->nHeight = port->mmal->format->es->video.crop.height;
  389. return OMX_ErrorNone;
  390. }
  391. case OMX_IndexConfigCommonScale:
  392. {
  393. OMX_CONFIG_SCALEFACTORTYPE *param = (OMX_CONFIG_SCALEFACTORTYPE *)pParam;
  394. PARAM_GET_PORT(port, component, param->nPortIndex);
  395. param->xWidth = param->xHeight = 1<<16;
  396. if (port->mmal->format->es->video.par.num &&
  397. port->mmal->format->es->video.par.den)
  398. param->xWidth = mmal_rational_to_fixed_16_16(port->mmal->format->es->video.par);
  399. return OMX_ErrorNone;
  400. }
  401. default:
  402. return mmalomx_parameter_get_xlat(component, nParamIndex, pParam);
  403. }
  404. return OMX_ErrorNotImplemented;
  405. }
  406. /*****************************************************************************/
  407. static OMX_ERRORTYPE mmalomx_set_video_param(MMALOMX_PORT_T *port,
  408. uint32_t profile, uint32_t level, uint32_t intraperiod)
  409. {
  410. MMAL_PARAMETER_VIDEO_PROFILE_T mmal_param = {{MMAL_PARAMETER_PROFILE, sizeof(mmal_param)},
  411. {{(MMAL_VIDEO_PROFILE_T)0, (MMAL_VIDEO_LEVEL_T)0}}};
  412. OMX_VIDEO_CODINGTYPE coding =
  413. mmalil_encoding_to_omx_video_coding(port->mmal->format->encoding);
  414. if (mmal_port_parameter_set_uint32(port->mmal, MMAL_PARAMETER_INTRAPERIOD,
  415. intraperiod) != MMAL_SUCCESS)
  416. return OMX_ErrorBadParameter;
  417. mmal_param.profile[0].profile = (MMAL_VIDEO_PROFILE_T)
  418. mmalil_omx_video_profile_to_mmal(profile, coding);
  419. mmal_param.profile[0].level = (MMAL_VIDEO_LEVEL_T)
  420. mmalil_omx_video_level_to_mmal(level, coding);
  421. if (mmal_port_parameter_set(port->mmal, &mmal_param.hdr) != MMAL_SUCCESS)
  422. return OMX_ErrorBadParameter;
  423. return OMX_ErrorNone;
  424. }
  425. /*****************************************************************************/
  426. OMX_ERRORTYPE mmalomx_parameter_set(MMALOMX_COMPONENT_T *component,
  427. OMX_INDEXTYPE nParamIndex, OMX_PTR pParam)
  428. {
  429. MMALOMX_PORT_T *port = NULL;
  430. switch(nParamIndex)
  431. {
  432. /* All OMX_IndexParamVideo parameters are only partially implemented */
  433. case OMX_IndexParamVideoAvc:
  434. {
  435. OMX_VIDEO_PARAM_AVCTYPE *param = (OMX_VIDEO_PARAM_AVCTYPE *)pParam;
  436. PARAM_GET_PORT(port, component, param->nPortIndex);
  437. if (param->nSize < sizeof(*param))
  438. return OMX_ErrorBadParameter;
  439. return mmalomx_set_video_param(port, param->eProfile, param->eLevel,
  440. param->nPFrames + 1);
  441. }
  442. case OMX_IndexParamVideoMpeg4:
  443. {
  444. OMX_VIDEO_PARAM_MPEG4TYPE *param = (OMX_VIDEO_PARAM_MPEG4TYPE *)pParam;
  445. PARAM_GET_PORT(port, component, param->nPortIndex);
  446. if (param->nSize < sizeof(*param))
  447. return OMX_ErrorBadParameter;
  448. return mmalomx_set_video_param(port, param->eProfile, param->eLevel,
  449. param->nPFrames + 1);
  450. }
  451. case OMX_IndexParamVideoH263:
  452. {
  453. OMX_VIDEO_PARAM_H263TYPE *param = (OMX_VIDEO_PARAM_H263TYPE *)pParam;
  454. PARAM_GET_PORT(port, component, param->nPortIndex);
  455. if (param->nSize < sizeof(*param))
  456. return OMX_ErrorBadParameter;
  457. return mmalomx_set_video_param(port, param->eProfile, param->eLevel,
  458. param->nPFrames + 1);
  459. }
  460. case OMX_IndexParamVideoMpeg2:
  461. case OMX_IndexParamVideoWmv:
  462. case OMX_IndexParamVideoRv:
  463. {
  464. OMX_FORMAT_PARAM_TYPE *param = (OMX_FORMAT_PARAM_TYPE *)pParam;
  465. OMX_U32 offset = offsetof(OMX_PARAM_U32TYPE, nU32);
  466. PARAM_GET_PORT(port, component, param->common.nPortIndex);
  467. if (param->common.nSize > sizeof(port->format_param) ||
  468. param->common.nSize < offset)
  469. return OMX_ErrorBadParameter;
  470. memcpy(&port->format_param.common.nU32, &param->common.nU32,
  471. param->common.nSize - offset);
  472. return OMX_ErrorNone;
  473. }
  474. case OMX_IndexParamAudioPcm:
  475. case OMX_IndexParamAudioAac:
  476. case OMX_IndexParamAudioMp3:
  477. case OMX_IndexParamAudioDdp:
  478. {
  479. OMX_FORMAT_PARAM_TYPE *param = (OMX_FORMAT_PARAM_TYPE *)pParam;
  480. OMX_U32 offset = offsetof(OMX_PARAM_U32TYPE, nU32);
  481. PARAM_GET_PORT(port, component, param->common.nPortIndex);
  482. if (param->common.nSize > sizeof(port->format_param) ||
  483. param->common.nSize < offset)
  484. return OMX_ErrorBadParameter;
  485. memcpy(&port->format_param.common.nU32, &param->common.nU32,
  486. param->common.nSize - offset);
  487. mmalil_omx_audio_param_to_format(port->mmal->format,
  488. mmalil_omx_audio_param_index_to_coding(nParamIndex), param);
  489. mmal_port_format_commit(port->mmal);
  490. return OMX_ErrorNone;
  491. }
  492. case OMX_IndexParamBrcmPixelAspectRatio:
  493. {
  494. OMX_CONFIG_POINTTYPE *param = (OMX_CONFIG_POINTTYPE *)pParam;
  495. PARAM_GET_PORT(port, component, param->nPortIndex);
  496. port->mmal->format->es->video.par.num = param->nX;
  497. port->mmal->format->es->video.par.den = param->nY;
  498. mmal_rational_simplify(&port->mmal->format->es->video.par);
  499. return mmal_port_format_commit(port->mmal);
  500. }
  501. case OMX_IndexParamColorSpace:
  502. {
  503. OMX_PARAM_COLORSPACETYPE *param = (OMX_PARAM_COLORSPACETYPE *)pParam;
  504. PARAM_GET_PORT(port, component, param->nPortIndex);
  505. port->mmal->format->es->video.color_space = mmalil_omx_color_space_to_mmal(param->eColorSpace);
  506. return mmal_port_format_commit(port->mmal);
  507. }
  508. case OMX_IndexParamBrcmVideoCroppingDisable:
  509. {
  510. OMX_CONFIG_PORTBOOLEANTYPE *param = (OMX_CONFIG_PORTBOOLEANTYPE *)pParam;
  511. PARAM_GET_PORT(port, component, param->nPortIndex);
  512. port->no_cropping = param->bEnabled;
  513. return OMX_ErrorNone;
  514. }
  515. default:
  516. return mmalomx_parameter_set_xlat(component, nParamIndex, pParam);
  517. }
  518. return OMX_ErrorNotImplemented;
  519. }