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.

ilclient.h 44 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039
  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. /*
  26. * \file
  27. *
  28. * \brief This API defines helper functions for writing IL clients.
  29. *
  30. * This file defines an IL client side library. This is useful when
  31. * writing IL clients, since there tends to be much repeated and
  32. * common code across both single and multiple clients. This library
  33. * seeks to remove that common code and abstract some of the
  34. * interactions with components. There is a wrapper around a
  35. * component and tunnel, and some operations can be done on lists of
  36. * these. The callbacks from components are handled, and specific
  37. * events can be checked or waited for.
  38. */
  39. #ifndef _IL_CLIENT_H
  40. #define _IL_CLIENT_H
  41. #include "IL/OMX_Broadcom.h"
  42. #include "interface/vcos/vcos.h"
  43. /**
  44. * The <DFN>ILCLIENT_T</DFN> structure encapsulates the state needed for the IL
  45. * Client API. It contains a set of callback functions used to
  46. * communicate with the user. It also includes a linked list of free
  47. * event structures.
  48. ***********************************************************/
  49. typedef struct _ILCLIENT_T ILCLIENT_T;
  50. /**
  51. * Each <DFN>ILEVENT_T</DFN> structure stores the result of an <DFN>EventHandler</DFN>
  52. * callback from a component, storing the event message type and any
  53. * parameters returned.
  54. ***********************************************************/
  55. typedef struct _ILEVENT_T ILEVENT_T;
  56. struct _COMPONENT_T;
  57. /**
  58. * The <DFN>COMPONENT_T</DFN> structure represents an IL component,
  59. * together with the necessary extra information required by the IL
  60. * Client API. This structure stores the handle to the OMX component,
  61. * as well as the event list containing all events sent by this
  62. * component. The component state structure also holds a pair of
  63. * buffer queues, for input and output buffers returned to the client
  64. * by the <DFN>FillBufferDone</DFN> and <DFN>EmptyBufferDone</DFN>
  65. * callbacks. As some operations result in error callbacks that can
  66. * be ignored, an error mask is maintained to allow some errors to be
  67. * ignored. A pointer to the client state structure is also added.
  68. ***********************************************************/
  69. typedef struct _COMPONENT_T COMPONENT_T;
  70. /**
  71. * The generic callback function is used for communicating events from
  72. * a particular component to the user.
  73. *
  74. * @param userdata The data returned from when the callback was registered.
  75. *
  76. * @param comp The component structure representing the component that
  77. * originated this event.
  78. *
  79. * @param data The relevant data field from the event.
  80. *
  81. * @return Void.
  82. ***********************************************************/
  83. typedef void (*ILCLIENT_CALLBACK_T)(void *userdata, COMPONENT_T *comp, OMX_U32 data);
  84. /**
  85. * The buffer callback function is used for indicating that a
  86. * component has returned a buffer on a port using client buffer
  87. * communication.
  88. *
  89. * @param data The data returned from when the callback was registered.
  90. *
  91. * @param comp The component from which the buffer originated.
  92. *
  93. * @return Void.
  94. ***********************************************************/
  95. typedef void (*ILCLIENT_BUFFER_CALLBACK_T)(void *data, COMPONENT_T *comp);
  96. /**
  97. * The malloc function is passed into
  98. * <DFN>ilclient_enable_port_buffers()</DFN> and used for allocating the
  99. * buffer payload.
  100. *
  101. * @param userdata Private pointer passed into
  102. * <DFN>ilclient_enable_port_buffers()</DFN> call.
  103. *
  104. * @param size Size in bytes of the requested memory region.
  105. *
  106. * @param align Alignment requirement in bytes for the base memory address.
  107. *
  108. * @param description Text description of the memory being allocated.
  109. *
  110. * @return The memory address on success, <DFN>NULL</DFN> on failure.
  111. ***********************************************************/
  112. typedef void *(*ILCLIENT_MALLOC_T)(void *userdata, VCOS_UNSIGNED size, VCOS_UNSIGNED align, const char *description);
  113. /**
  114. * The free function is passed into
  115. * <DFN>ilclient_enable_port_buffers()</DFN> and
  116. * <DFN>ilclient_disable_port_buffers()</DFN> and used for freeing the
  117. * buffer payload.
  118. *
  119. * @param userdata Private pointer passed into
  120. * <DFN>ilclient_enable_port_buffers()</DFN> and
  121. * <DFN>ilclient_disable_port_buffers()</DFN>.
  122. *
  123. * @param pointer Memory address to free, that was previously returned
  124. * from <DFN>ILCLIENT_MALLOC_T</DFN> function.
  125. *
  126. * @return Void.
  127. ***********************************************************/
  128. typedef void (*ILCLIENT_FREE_T)(void *userdata, void *pointer);
  129. /**
  130. * The event mask enumeration describes the possible events that the
  131. * user can ask to wait for when waiting for a particular event.
  132. ***********************************************************/
  133. typedef enum {
  134. ILCLIENT_EMPTY_BUFFER_DONE = 0x1, /**< Set when a buffer is
  135. returned from an input
  136. port */
  137. ILCLIENT_FILL_BUFFER_DONE = 0x2, /**< Set when a buffer is
  138. returned from an output
  139. port */
  140. ILCLIENT_PORT_DISABLED = 0x4, /**< Set when a port indicates
  141. it has completed a disable
  142. command. */
  143. ILCLIENT_PORT_ENABLED = 0x8, /**< Set when a port indicates
  144. is has completed an enable
  145. command. */
  146. ILCLIENT_STATE_CHANGED = 0x10, /**< Set when a component
  147. indicates it has completed
  148. a state change command. */
  149. ILCLIENT_BUFFER_FLAG_EOS = 0x20, /**< Set when a port signals
  150. an EOS event. */
  151. ILCLIENT_PARAMETER_CHANGED = 0x40, /**< Set when a port signals a
  152. port settings changed
  153. event. */
  154. ILCLIENT_EVENT_ERROR = 0x80, /**< Set when a component
  155. indicates an error. */
  156. ILCLIENT_PORT_FLUSH = 0x100, /**< Set when a port indicates
  157. is has completed a flush
  158. command. */
  159. ILCLIENT_MARKED_BUFFER = 0x200, /**< Set when a port indicates
  160. it has marked a buffer. */
  161. ILCLIENT_BUFFER_MARK = 0x400, /**< Set when a port indicates
  162. it has received a buffer
  163. mark. */
  164. ILCLIENT_CONFIG_CHANGED = 0x800 /**< Set when a config parameter
  165. changed. */
  166. } ILEVENT_MASK_T;
  167. /**
  168. * On component creation the user can set flags to control the
  169. * creation of that component.
  170. ***********************************************************/
  171. typedef enum {
  172. ILCLIENT_FLAGS_NONE = 0x0, /**< Used if no flags are
  173. set. */
  174. ILCLIENT_ENABLE_INPUT_BUFFERS = 0x1, /**< If set we allow the
  175. client to communicate with
  176. input ports via buffer
  177. communication, rather than
  178. tunneling with another
  179. component. */
  180. ILCLIENT_ENABLE_OUTPUT_BUFFERS = 0x2, /**< If set we allow the
  181. client to communicate with
  182. output ports via buffer
  183. communication, rather than
  184. tunneling with another
  185. component. */
  186. ILCLIENT_DISABLE_ALL_PORTS = 0x4, /**< If set we disable all
  187. ports on creation. */
  188. ILCLIENT_HOST_COMPONENT = 0x8, /**< Create a host component.
  189. The default host ilcore
  190. only can create host components
  191. by being locally hosted
  192. so should only be used for testing
  193. purposes. */
  194. ILCLIENT_OUTPUT_ZERO_BUFFERS = 0x10 /**< All output ports will have
  195. nBufferCountActual set to zero,
  196. if supported by the component. */
  197. } ILCLIENT_CREATE_FLAGS_T;
  198. /**
  199. * \brief This structure represents a tunnel in the OpenMAX IL API.
  200. *
  201. * Some operations in this API act on a tunnel, so the tunnel state
  202. * structure (<DFN>TUNNEL_T</DFN>) is a convenient store of the source and sink
  203. * of the tunnel. For each, a pointer to the relevant component state
  204. * structure and the port index is stored.
  205. ***********************************************************/
  206. typedef struct {
  207. COMPONENT_T *source; /**< The source component */
  208. int source_port; /**< The output port index on the source component */
  209. COMPONENT_T *sink; /**< The sink component */
  210. int sink_port; /**< The input port index on the sink component */
  211. } TUNNEL_T;
  212. /**
  213. * The <DFN>set_tunnel</DFN> macro is a useful function that initialises a
  214. * <DFN>TUNNEL_T</DFN> structure.
  215. ***********************************************************/
  216. #define set_tunnel(t,a,b,c,d) do {TUNNEL_T *_ilct = (t); \
  217. _ilct->source = (a); _ilct->source_port = (b); \
  218. _ilct->sink = (c); _ilct->sink_port = (d);} while(0)
  219. /**
  220. * For calling OpenMAX IL methods directory, we need to access the
  221. * <DFN>OMX_HANDLETYPE</DFN> corresponding to the <DFN>COMPONENT_T</DFN> structure. This
  222. * macro enables this while keeping the <DFN>COMPONENT_T</DFN> structure opaque.
  223. * The parameter <DFN>x</DFN> should be of the type <DFN>*COMPONENT_T</DFN>.
  224. ***********************************************************/
  225. #define ILC_GET_HANDLE(x) ilclient_get_handle(x)
  226. /**
  227. * An IL Client structure is created by the <DFN>ilclient_init()</DFN>
  228. * method. This structure is used when creating components, but
  229. * otherwise is not needed in other API functions as a pointer to this
  230. * structure is maintained in the <DFN>COMPONENT_T</DFN> structure.
  231. *
  232. * @return pointer to client structure
  233. ***********************************************************/
  234. VCHPRE_ ILCLIENT_T VCHPOST_ *ilclient_init(void);
  235. /**
  236. * When all components have been deleted, the IL Client structure can
  237. * be destroyed by calling the <DFN>ilclient_destroy()</DFN> function.
  238. *
  239. * @param handle The client handle. After calling this function, this
  240. * handle should not be used.
  241. *
  242. * @return void
  243. ***********************************************************/
  244. VCHPRE_ void VCHPOST_ ilclient_destroy(ILCLIENT_T *handle);
  245. /**
  246. * The <DFN>ilclient_set_port_settings_callback()</DFN> function registers a
  247. * callback to be used when the <DFN>OMX_EventPortSettingsChanged</DFN> event is
  248. * received. When the event is received, a pointer to the component
  249. * structure and port index is returned by the callback.
  250. *
  251. * @param handle The client handle
  252. *
  253. * @param func The callback function to use. Calling this function
  254. * with a <DFN>NULL</DFN> function pointer will deregister any existing
  255. * registered callback.
  256. *
  257. * @param userdata Data to be passed back when calling the callback
  258. * function.
  259. *
  260. * @return void
  261. ***********************************************************/
  262. VCHPRE_ void VCHPOST_ ilclient_set_port_settings_callback(ILCLIENT_T *handle,
  263. ILCLIENT_CALLBACK_T func,
  264. void *userdata);
  265. /**
  266. * The <DFN>ilclient_set_eos_callback()</DFN> function registers a callback to be
  267. * used when the <DFN>OMX_EventBufferFlag</DFN> is received with the
  268. * <DFN>OMX_BUFFERFLAG_EOS</DFN> flag set. When the event is received, a pointer
  269. * to the component structure and port index is returned by the
  270. * callback.
  271. *
  272. * @param handle The client handle
  273. *
  274. * @param func The callback function to use. Calling this function
  275. * with a <DFN>NULL</DFN> function pointer will deregister any existing
  276. * registered callback.
  277. *
  278. * @param userdata Data to be passed back when calling the callback
  279. * function.
  280. *
  281. * @return void
  282. ***********************************************************/
  283. VCHPRE_ void VCHPOST_ ilclient_set_eos_callback(ILCLIENT_T *handle,
  284. ILCLIENT_CALLBACK_T func,
  285. void *userdata);
  286. /**
  287. * The <DFN>ilclient_set_error_callback()</DFN> function registers a callback to be
  288. * used when the <DFN>OMX_EventError</DFN> is received from a component. When
  289. * the event is received, a pointer to the component structure and the
  290. * error code are reported by the callback.
  291. *
  292. * @param handle The client handle
  293. *
  294. * @param func The callback function to use. Calling this function
  295. * with a <DFN>NULL</DFN> function pointer will deregister any existing
  296. * registered callback.
  297. *
  298. * @param userdata Data to be passed back when calling the callback
  299. * function.
  300. *
  301. * @return void
  302. ***********************************************************/
  303. VCHPRE_ void VCHPOST_ ilclient_set_error_callback(ILCLIENT_T *handle,
  304. ILCLIENT_CALLBACK_T func,
  305. void *userdata);
  306. /**
  307. * The <DFN>ilclient_set_configchanged_callback()</DFN> function
  308. * registers a callback to be used when an
  309. * <DFN>OMX_EventParamOrConfigChanged</DFN> event occurs. When the
  310. * event is received, a pointer to the component structure and the
  311. * index value that has changed are reported by the callback. The
  312. * user may then use an <DFN>OMX_GetConfig</DFN> call with the index
  313. * as specified to retrieve the updated information.
  314. *
  315. * @param handle The client handle
  316. *
  317. * @param func The callback function to use. Calling this function
  318. * with a <DFN>NULL</DFN> function pointer will deregister any existing
  319. * registered callback.
  320. *
  321. * @param userdata Data to be passed back when calling the callback
  322. * function.
  323. *
  324. * @return void
  325. ***********************************************************/
  326. VCHPRE_ void VCHPOST_ ilclient_set_configchanged_callback(ILCLIENT_T *handle,
  327. ILCLIENT_CALLBACK_T func,
  328. void *userdata);
  329. /**
  330. * The <DFN>ilclient_set_fill_buffer_done_callback()</DFN> function registers a
  331. * callback to be used when a buffer passed to an output port using the
  332. * <DFN>OMX_FillBuffer</DFN> call is returned with the <DFN>OMX_FillBufferDone</DFN>
  333. * callback. When the event is received, a pointer to the component
  334. * structure is returned by the callback. The user may then use the
  335. * <DFN>ilclient_get_output_buffer()</DFN> function to retrieve the buffer.
  336. *
  337. * @param handle The client handle
  338. *
  339. * @param func The callback function to use. Calling this function
  340. * with a <DFN>NULL</DFN> function pointer will deregister any existing
  341. * registered callback.
  342. *
  343. * @param userdata Data to be passed back when calling the callback
  344. * function.
  345. *
  346. * @return void
  347. ***********************************************************/
  348. VCHPRE_ void VCHPOST_ ilclient_set_fill_buffer_done_callback(ILCLIENT_T *handle,
  349. ILCLIENT_BUFFER_CALLBACK_T func,
  350. void *userdata);
  351. /**
  352. * The <DFN>ilclient_set_empty_buffer_done_callback()</DFN> function registers a
  353. * callback to be used when a buffer passed to an input port using the
  354. * <DFN>OMX_EmptyBuffer</DFN> call is returned with the <DFN>OMX_EmptyBufferDone</DFN>
  355. * callback. When the event is received, a pointer to the component
  356. * structure is returned by the callback. The user may then use the
  357. * <DFN>ilclient_get_input_buffer()</DFN> function to retrieve the buffer.
  358. *
  359. * @param handle The client handle
  360. *
  361. * @param func The callback function to use. Calling this function
  362. * with a <DFN>NULL</DFN> function pointer will deregister any existing
  363. * registered callback.
  364. *
  365. * @param userdata Data to be passed back when calling the callback
  366. * function.
  367. *
  368. * @return void
  369. ***********************************************************/
  370. VCHPRE_ void VCHPOST_ ilclient_set_empty_buffer_done_callback(ILCLIENT_T *handle,
  371. ILCLIENT_BUFFER_CALLBACK_T func,
  372. void *userdata);
  373. /**
  374. * Components are created using the <DFN>ilclient_create_component()</DFN>
  375. * function.
  376. *
  377. * @param handle The client handle
  378. *
  379. * @param comp On successful creation, the component structure pointer
  380. * will be written back into <DFN>comp</DFN>.
  381. *
  382. * @param name The name of the component to be created. Component
  383. * names as provided are automatically prefixed with
  384. * <DFN>"OMX.broadcom."</DFN> before passing to the IL core. The name
  385. * provided will also be used in debugging messages added about this
  386. * component.
  387. *
  388. * @param flags The client can specify some creation behaviour by using
  389. * the <DFN>flags</DFN> field. The meaning of each flag is defined
  390. * by the <DFN>ILCLIENT_CREATE_FLAGS_T</DFN> type.
  391. *
  392. * @return 0 on success, -1 on failure
  393. ***********************************************************/
  394. VCHPRE_ int VCHPOST_ ilclient_create_component(ILCLIENT_T *handle,
  395. COMPONENT_T **comp,
  396. char *name,
  397. ILCLIENT_CREATE_FLAGS_T flags);
  398. /**
  399. * The <DFN>ilclient_cleanup_components()</DFN> function deallocates all
  400. * state associated with components and frees the OpenMAX component
  401. * handles. All tunnels connecting components should have been torn
  402. * down explicitly, and all components must be in loaded state.
  403. *
  404. * @param list A null-terminated list of component pointers to be
  405. * deallocated.
  406. *
  407. * @return void
  408. ***********************************************************/
  409. VCHPRE_ void VCHPOST_ ilclient_cleanup_components(COMPONENT_T *list[]);
  410. /**
  411. * The <DFN>ilclient_change_component_state()</DFN> function changes the
  412. * state of an individual component. This will trigger the state
  413. * change, and also wait for that state change to be completed. It
  414. * should not be called if this state change has dependencies on other
  415. * components also changing states. Trying to change a component to
  416. * its current state is treated as success.
  417. *
  418. * @param comp The component to change.
  419. *
  420. * @param state The new state to transition to.
  421. *
  422. * @return 0 on success, -1 on failure.
  423. ***********************************************************/
  424. VCHPRE_ int VCHPOST_ ilclient_change_component_state(COMPONENT_T *comp,
  425. OMX_STATETYPE state);
  426. /**
  427. * The <DFN>ilclient_state_transition()</DFN> function transitions a set of
  428. * components that need to perform a simultaneous state transition;
  429. * for example, when two components are tunnelled and the buffer
  430. * supplier port needs to allocate and pass buffers to a non-supplier
  431. * port. All components are sent a command to change state, then the
  432. * function will wait for all components to signal that they have
  433. * changed state.
  434. *
  435. * @param list A null-terminated list of component pointers.
  436. *
  437. * @param state The new state to which to transition all components.
  438. *
  439. * @return void
  440. ***********************************************************/
  441. VCHPRE_ void VCHPOST_ ilclient_state_transition(COMPONENT_T *list[],
  442. OMX_STATETYPE state);
  443. /**
  444. * The <DFN>ilclient_disable_port()</DFN> function disables a port on a
  445. * given component. This function sends the disable port message to
  446. * the component and waits for the component to signal that this has
  447. * taken place. If the port is already disabled, this is treated as a
  448. * sucess.
  449. *
  450. * @param comp The component containing the port to disable.
  451. *
  452. * @param portIndex The port index of the port to disable. This must
  453. * be a named port index, rather than a <DFN>OMX_ALL</DFN> value.
  454. *
  455. * @return void
  456. ***********************************************************/
  457. VCHPRE_ void VCHPOST_ ilclient_disable_port(COMPONENT_T *comp,
  458. int portIndex);
  459. /**
  460. * The <DFN>ilclient_enable_port()</DFN> function enables a port on a
  461. * given component. This function sends the enable port message to
  462. * the component and waits for the component to signal that this has
  463. * taken place. If the port is already disabled, this is treated as a
  464. * sucess.
  465. *
  466. * @param comp The component containing the port to enable.
  467. *
  468. * @param portIndex The port index of the port to enable. This must
  469. * be a named port index, rather than a <DFN>OMX_ALL</DFN> value.
  470. *
  471. * @return void
  472. ***********************************************************/
  473. VCHPRE_ void VCHPOST_ ilclient_enable_port(COMPONENT_T *comp,
  474. int portIndex);
  475. /**
  476. * The <DFN>ilclient_enable_port_buffers()</DFN> function enables a port
  477. * in base profile mode on a given component. The port is not
  478. * tunneled, so requires buffers to be allocated.
  479. *
  480. * @param comp The component containing the port to enable.
  481. *
  482. * @param portIndex The port index of the port to enable. This must
  483. * be a named port index, rather than a <DFN>OMX_ALL</DFN> value.
  484. *
  485. * @param ilclient_malloc This function will be used to allocate
  486. * buffer payloads. If <DFN>NULL</DFN> then
  487. * <DFN>vcos_malloc_aligned</DFN> will be used.
  488. *
  489. * @param ilclient_free If an error occurs, this function is used to
  490. * free previously allocated payloads. If <DFN>NULL</DFN> then
  491. * <DFN>vcos_free</DFN> will be used.
  492. *
  493. * @param userdata The first argument to calls to
  494. * <DFN>ilclient_malloc</DFN> and <DFN>ilclient_free</DFN>, if these
  495. * arguments are not <DFN>NULL</DFN>.
  496. *
  497. * @return 0 indicates success. -1 indicates failure.
  498. ***********************************************************/
  499. VCHPRE_ int VCHPOST_ ilclient_enable_port_buffers(COMPONENT_T *comp,
  500. int portIndex,
  501. ILCLIENT_MALLOC_T ilclient_malloc,
  502. ILCLIENT_FREE_T ilclient_free,
  503. void *userdata);
  504. /**
  505. * The <DFN>ilclient_disable_port_buffers()</DFN> function disables a
  506. * port in base profile mode on a given component. The port is not
  507. * tunneled, and has been supplied with buffers by the client.
  508. *
  509. * @param comp The component containing the port to disable.
  510. *
  511. * @param portIndex The port index of the port to disable. This must
  512. * be a named port index, rather than a <DFN>OMX_ALL</DFN> value.
  513. *
  514. * @param bufferList A list of buffers, using <DFN>pAppPrivate</DFN>
  515. * as the next pointer that were allocated on this port, and currently
  516. * held by the application. If buffers on this port are held by IL
  517. * client or the component then these are automatically freed.
  518. *
  519. * @param ilclient_free This function is used to free the buffer payloads.
  520. * If <DFN>NULL</DFN> then <DFN>vcos_free</DFN> will be used.
  521. *
  522. * @param userdata The first argument to calls to
  523. * <DFN>ilclient_free</DFN>.
  524. *
  525. * @return void
  526. */
  527. VCHPRE_ void VCHPOST_ ilclient_disable_port_buffers(COMPONENT_T *comp,
  528. int portIndex,
  529. OMX_BUFFERHEADERTYPE *bufferList,
  530. ILCLIENT_FREE_T ilclient_free,
  531. void *userdata);
  532. /**
  533. * With a populated tunnel structure, the
  534. * <DFN>ilclient_setup_tunnel()</DFN> function connects the tunnel. It
  535. * first transitions the source component to idle if currently in
  536. * loaded state, and then optionally checks the source event list for
  537. * a port settings changed event from the source port. If this event
  538. * is not in the event queue then this function optionally waits for
  539. * it to arrive. To disable this check for the port settings changed
  540. * event, set <DFN>timeout</DFN> to zero.
  541. *
  542. * Both ports are then disabled, and the source port is inspected for
  543. * a port streams parameter. If this is supported, then the
  544. * <DFN>portStream</DFN> argument is used to select which port stream
  545. * to use. The two ports are then tunnelled using the
  546. * <DFN>OMX_SetupTunnel</DFN> function. If this is successful, then
  547. * both ports are enabled. Note that for disabling and enabling the
  548. * tunnelled ports, the functions <DFN>ilclient_disable_tunnel()</DFN>
  549. * and <DFN>ilclient_enable_tunnel()</DFN> are used, so the relevant
  550. * documentation for those functions applies here.
  551. *
  552. * @param tunnel The tunnel structure representing the tunnel to
  553. * set up.
  554. *
  555. * @param portStream If port streams are supported on the output port
  556. * of the tunnel, then this parameter indicates the port stream to
  557. * select on this port.
  558. *
  559. * @param timeout The time duration in milliseconds to wait for the
  560. * output port to signal a port settings changed event before
  561. * returning a timeout failure. If this is 0, then we do not check
  562. * for a port settings changed before setting up the tunnel.
  563. *
  564. * @return 0 indicates success, negative indicates failure:
  565. * - -1: a timeout waiting for the parameter changed
  566. * - -2: an error was returned instead of parameter changed
  567. * - -3: no streams are available from this port
  568. * - -4: requested stream is not available from this port
  569. * - -5: the data format was not acceptable to the sink
  570. ***********************************************************/
  571. VCHPRE_ int VCHPOST_ ilclient_setup_tunnel(TUNNEL_T *tunnel,
  572. unsigned int portStream,
  573. int timeout);
  574. /**
  575. * The <DFN>ilclient_disable_tunnel()</DFN> function disables both ports listed in
  576. * the tunnel structure. It will send a port disable command to each
  577. * port, then waits for both to indicate they have completed the
  578. * transition. The errors <DFN>OMX_ErrorPortUnpopulated</DFN> and
  579. * <DFN>OMX_ErrorSameState</DFN> are both ignored by this function; the former
  580. * since the first port to disable may deallocate buffers before the
  581. * second port has been disabled, leading to the second port reporting
  582. * the unpopulated error.
  583. *
  584. * @param tunnel The tunnel to disable.
  585. *
  586. * @return void
  587. ***********************************************************/
  588. VCHPRE_ void VCHPOST_ ilclient_disable_tunnel(TUNNEL_T *tunnel);
  589. /**
  590. * The <DFN>ilclient_enable_tunnel()</DFN> function enables both ports listed in
  591. * the tunnel structure. It will first send a port enable command to
  592. * each port. It then checks whether the sink component is not in
  593. * loaded state - if so, the function waits for both ports to complete
  594. * the requested port enable. If the sink component was in loaded
  595. * state, then this component is transitioned to idle to allow the
  596. * ports to exchange buffers and enable the ports. This is since
  597. * typically this function is used when creating a tunnel between two
  598. * components, where the source component is processing data to enable
  599. * it to report the port settings changed event, and the sink port has
  600. * yet to be used. Before transitioning the sink component to idle,
  601. * this function waits for the sink port to be enabled - since the
  602. * component is in loaded state, this will happen quickly. If the
  603. * transition to idle fails, the sink component is transitioned back
  604. * to loaded and the source port disabled. If the transition
  605. * succeeds, the function then waits for the source port to complete
  606. * the requested port enable.
  607. *
  608. * @param tunnel The tunnel to enable.
  609. *
  610. * @return 0 on success, -1 on failure.
  611. ***********************************************************/
  612. VCHPRE_ int VCHPOST_ ilclient_enable_tunnel(TUNNEL_T *tunnel);
  613. /**
  614. * The <DFN>ilclient_flush_tunnels()</DFN> function will flush a number of tunnels
  615. * from the list of tunnels presented. For each tunnel that is to be
  616. * flushed, both source and sink ports are sent a flush command. The
  617. * function then waits for both ports to report they have completed
  618. * the flush operation.
  619. *
  620. * @param tunnel List of tunnels. The list must be terminated with a
  621. * tunnel structure with <DFN>NULL</DFN> component entries.
  622. *
  623. * @param max The maximum number of tunnels to flush from the list.
  624. * A value of 0 indicates that all tunnels in the list are flushed.
  625. *
  626. * @return void
  627. ***********************************************************/
  628. VCHPRE_ void VCHPOST_ ilclient_flush_tunnels(TUNNEL_T *tunnel,
  629. int max);
  630. /**
  631. * The <DFN>ilclient_teardown_tunnels()</DFN> function tears down all tunnels in
  632. * the list of tunnels presented. For each tunnel in the list, the
  633. * <DFN>OMX_SetupTunnel</DFN> is called on the source port and on the sink port,
  634. * where for both calls the destination component is <DFN>NULL</DFN> and the
  635. * destination port is zero. The VMCSX IL implementation requires
  636. * that all tunnels are torn down in this manner before components are
  637. * freed.
  638. *
  639. * @param tunnels List of tunnels to teardown. The list must be
  640. * terminated with a tunnel structure with <DFN>NULL</DFN> component entries.
  641. *
  642. * @return void
  643. ***********************************************************/
  644. VCHPRE_ void VCHPOST_ ilclient_teardown_tunnels(TUNNEL_T *tunnels);
  645. /**
  646. * The <DFN>ilclient_get_output_buffer()</DFN> function returns a buffer
  647. * that was sent to an output port and that has been returned from a
  648. * component using the <DFN>OMX_FillBufferDone</DFN> callback.
  649. *
  650. * @param comp The component that returned the buffer.
  651. *
  652. * @param portIndex The port index on the component that the buffer
  653. * was returned from.
  654. *
  655. * @param block If non-zero, the function will block until a buffer is available.
  656. *
  657. * @return Pointer to buffer if available, otherwise <DFN>NULL</DFN>.
  658. ***********************************************************/
  659. VCHPRE_ OMX_BUFFERHEADERTYPE* VCHPOST_ ilclient_get_output_buffer(COMPONENT_T *comp,
  660. int portIndex,
  661. int block);
  662. /**
  663. * The <DFN>ilclient_get_input_buffer()</DFN> function returns a buffer
  664. * that was sent to an input port and that has been returned from a
  665. * component using the <DFN>OMX_EmptyBufferDone</DFN> callback.
  666. *
  667. * @param comp The component that returned the buffer.
  668. *
  669. * @param portIndex The port index on the component from which the buffer
  670. * was returned.
  671. *
  672. * @param block If non-zero, the function will block until a buffer is available.
  673. *
  674. * @return pointer to buffer if available, otherwise <DFN>NULL</DFN>
  675. ***********************************************************/
  676. VCHPRE_ OMX_BUFFERHEADERTYPE* VCHPOST_ ilclient_get_input_buffer(COMPONENT_T *comp,
  677. int portIndex,
  678. int block);
  679. /**
  680. * The <DFN>ilclient_remove_event()</DFN> function queries the event list for the
  681. * given component, matching against the given criteria. If a matching
  682. * event is found, it is removed and added to the free event list.
  683. *
  684. * @param comp The component that returned the matching event.
  685. *
  686. * @param event The event type of the matching event.
  687. *
  688. * @param nData1 The <DFN>nData1</DFN> field of the matching event.
  689. *
  690. * @param ignore1 Whether to ignore the <DFN>nData1</DFN> field when finding a
  691. * matching event. A value of 0 indicates that <DFN>nData1</DFN> must match, a
  692. * value of 1 indicates that <DFN>nData1</DFN> does not have to match.
  693. *
  694. * @param nData2 The <DFN>nData2</DFN> field of the matching event.
  695. *
  696. * @param ignore2 Whether to ignore the <DFN>nData2</DFN> field when finding a
  697. * matching event. A value of 0 indicates that <DFN>nData2</DFN> must match, a
  698. * value of 1 indicates that <DFN>nData2</DFN> does not have to match.
  699. *
  700. * @return 0 if the event was removed. -1 if no matching event was
  701. * found.
  702. ***********************************************************/
  703. VCHPRE_ int VCHPOST_ ilclient_remove_event(COMPONENT_T *comp,
  704. OMX_EVENTTYPE event,
  705. OMX_U32 nData1,
  706. int ignore1,
  707. OMX_U32 nData2,
  708. int ignore2);
  709. /**
  710. * The <DFN>ilclient_return_events()</DFN> function removes all events
  711. * from a component event list and adds them to the IL client free
  712. * event list. This function is automatically called when components
  713. * are freed.
  714. *
  715. * @param comp The component from which all events should be moved to
  716. * the free list.
  717. *
  718. * @return void
  719. ***********************************************************/
  720. VCHPRE_ void VCHPOST_ ilclient_return_events(COMPONENT_T *comp);
  721. /**
  722. * The <DFN>ilclient_wait_for_event()</DFN> function is similar to
  723. * <DFN>ilclient_remove_event()</DFN>, but allows the caller to block until that
  724. * event arrives.
  725. *
  726. * @param comp The component that returned the matching event.
  727. *
  728. * @param event The event type of the matching event.
  729. *
  730. * @param nData1 The <DFN>nData1</DFN> field of the matching event.
  731. *
  732. * @param ignore1 Whether to ignore the <DFN>nData1</DFN> field when finding a
  733. * matching event. A value of 0 indicates that <DFN>nData1</DFN> must match, a
  734. * value of 1 indicates that <DFN>nData1</DFN> does not have to match.
  735. *
  736. * @param nData2 The <DFN>nData2</DFN> field of the matching event.
  737. *
  738. * @param ignore2 Whether to ignore the <DFN>nData2</DFN> field when finding a
  739. * matching event. A value of 0 indicates that <DFN>nData2</DFN> must match, a
  740. * value of 1 indicates that <DFN>nData2</DFN> does not have to match.
  741. *
  742. * @param event_flag Specifies a bitfield of IL client events to wait
  743. * for, given in <DFN>ILEVENT_MASK_T</DFN>. If any of these events
  744. * are signalled by the component, the event list is then re-checked
  745. * for a matching event. If the <DFN>ILCLIENT_EVENT_ERROR</DFN> bit
  746. * is included, and an error is signalled by the component, then the
  747. * function will return an error code. If the
  748. * <DFN>ILCLIENT_CONFIG_CHANGED</DFN> bit is included, and this bit is
  749. * signalled by the component, then the function will return an error
  750. * code.
  751. *
  752. * @param timeout Specifies how long to block for in milliseconds
  753. * before returning a failure.
  754. *
  755. * @return 0 indicates success, a matching event has been removed from
  756. * the component's event queue. A negative return indicates failure,
  757. * in this case no events have been removed from the component's event
  758. * queue.
  759. * - -1: a timeout was received.
  760. * - -2: an error event was received.
  761. * - -3: a config changed event was received.
  762. ***********************************************************/
  763. VCHPRE_ int VCHPOST_ ilclient_wait_for_event(COMPONENT_T *comp,
  764. OMX_EVENTTYPE event,
  765. OMX_U32 nData1,
  766. int ignore1,
  767. OMX_U32 nData2,
  768. int ignore2,
  769. int event_flag,
  770. int timeout);
  771. /**
  772. * The <DFN>ilclient_wait_for_command_complete()</DFN> function waits
  773. * for a message from a component that indicates that the command
  774. * has completed. This is either a command success message, or an
  775. * error message that signals the completion of an event.
  776. *
  777. * @param comp The component currently processing a command.
  778. *
  779. * @param command The command being processed. This must be either
  780. * <DFN>OMX_CommandStateSet</DFN>, <DFN>OMX_CommandPortDisable</DFN>
  781. * or <DFN>OMX_CommandPortEnable</DFN>.
  782. *
  783. * @param nData2 The expected value of <DFN>nData2</DFN> in the
  784. * command complete message.
  785. *
  786. * @return 0 indicates success, either the command successfully completed
  787. * or the <DFN>OMX_ErrorSameState</DFN> was returned. -1 indicates
  788. * that the command terminated with a different error message.
  789. ***********************************************************/
  790. VCHPRE_ int VCHPOST_ ilclient_wait_for_command_complete(COMPONENT_T *comp,
  791. OMX_COMMANDTYPE command,
  792. OMX_U32 nData2);
  793. /**
  794. * The <DFN>ilclient_wait_for_command_complete_dual()</DFN> function
  795. * is similar to <DFN>ilclient_wait_for_command_complete()</DFN>. The
  796. * difference is that while waiting for the component to complete the
  797. * event or raise an error, we can also report if another reports an
  798. * error that terminates a command. This is useful if the two
  799. * components are tunneled, and we need to wait for one component to
  800. * enable a port, or change state to <DFN>OMX_StateIdle</DFN>. If the
  801. * other component is the buffer supplier and reports an error, then
  802. * it will not allocate buffers, so our first component may stall.
  803. *
  804. * @param comp The component currently processing a command.
  805. *
  806. * @param command The command being processed. This must be either
  807. * <DFN>OMX_CommandStateSet</DFN>, <DFN>OMX_CommandPortDisable</DFN>
  808. * or <DFN>OMX_CommandPortEnable</DFN>.
  809. *
  810. * @param nData2 The expected value of <DFN>nData2</DFN> in the
  811. * command complete message.
  812. *
  813. * @param related Another component, where we will return if this
  814. * component raises an error that terminates a command.
  815. *
  816. * @return 0 indicates success, either the command successfully
  817. * completed or the <DFN>OMX_ErrorSameState</DFN> was returned. -1
  818. * indicates that the command terminated with a different error
  819. * message. -2 indicates that the related component raised an error.
  820. * In this case, the error is not cleared from the related
  821. * component's event list.
  822. ***********************************************************/
  823. VCHPRE_ int VCHPOST_ ilclient_wait_for_command_complete_dual(COMPONENT_T *comp,
  824. OMX_COMMANDTYPE command,
  825. OMX_U32 nData2,
  826. COMPONENT_T *related);
  827. /**
  828. * The <DFN>ilclient_debug_output()</DFN> function adds a message to a
  829. * host-specific debug display. For a local VideoCore host the message is
  830. * added to the internal message log. For a Win32 host the message is
  831. * printed to the debug display. This function should be customised
  832. * when IL client is ported to another platform.
  833. *
  834. * @param format A message to add, together with the variable
  835. * argument list similar to <DFN>printf</DFN> and other standard C functions.
  836. *
  837. * @return void
  838. ***********************************************************/
  839. VCHPRE_ void VCHPOST_ ilclient_debug_output(char *format, ...);
  840. /**
  841. * The <DFN>ilclient_get_handle()</DFN> function returns the
  842. * underlying OMX component held by an IL component handle. This is
  843. * needed when calling methods such as <DFN>OMX_SetParameter</DFN> on
  844. * a component created using the IL client library.
  845. *
  846. * @param comp IL component handle
  847. *
  848. * @return The <DFN>OMX_HANDLETYPE</DFN> value for the component.
  849. ***********************************************************/
  850. VCHPRE_ OMX_HANDLETYPE VCHPOST_ ilclient_get_handle(COMPONENT_T *comp);
  851. #ifndef OMX_SKIP64BIT
  852. /**
  853. * Macro to return <DFN>OMX_TICKS</DFN> from a signed 64 bit value.
  854. * This is the version where <DFN>OMX_TICKS</DFN> is a signed 64 bit
  855. * value, an alternative definition is used when <DFN>OMX_TICKS</DFN>
  856. * is a structure.
  857. */
  858. #define ilclient_ticks_from_s64(s) (s)
  859. /**
  860. * Macro to return signed 64 bit value from <DFN>OMX_TICKS</DFN>.
  861. * This is the version where <DFN>OMX_TICKS</DFN> is a signed 64 bit
  862. * value, an alternative definition is used when <DFN>OMX_TICKS</DFN>
  863. * is a structure.
  864. */
  865. #define ilclient_ticks_to_s64(t) (t)
  866. #else
  867. /**
  868. * Inline function to return <DFN>OMX_TICKS</DFN> from a signed 64 bit
  869. * value. This is the version where <DFN>OMX_TICKS</DFN> is a
  870. * structure, an alternative definition is used when
  871. * <DFN>OMX_TICKS</DFN> is a signed 64 bit value.
  872. */
  873. static inline OMX_TICKS ilclient_ticks_from_s64(int64_t s) {
  874. OMX_TICKS ret;
  875. ret.nLowPart = s;
  876. ret.nHighPart = s>>32;
  877. return ret;
  878. }
  879. /**
  880. * Inline function to return signed 64 bit value from
  881. * <DFN>OMX_TICKS</DFN>. This is the version where
  882. * <DFN>OMX_TICKS</DFN> is a structure, an alternative definition is
  883. * used when <DFN>OMX_TICKS</DFN> is a signed 64 bit value.
  884. */
  885. static inline int64_t ilclient_ticks_to_s64(OMX_TICKS t) {
  886. uint64_t u = t.nLowPart | ((uint64_t)t.nHighPart << 32);
  887. return u;
  888. }
  889. #endif /* OMX_SKIP64BIT */
  890. /**
  891. * The <DFN>ilclient_get_port_index()</DFN> function returns the n'th
  892. * port index of the specified type and direction for the given
  893. * component.
  894. *
  895. * @param comp The component of interest
  896. * @param dir The direction
  897. * @param type The type, or -1 for any type.
  898. * @param index Which port (counting from 0).
  899. *
  900. * @return The port index, or -1 if not found.
  901. ***********************************************************/
  902. VCHPRE_ int VCHPOST_ ilclient_get_port_index(COMPONENT_T *comp,
  903. OMX_DIRTYPE dir,
  904. OMX_PORTDOMAINTYPE type,
  905. int index);
  906. /**
  907. * The <DFN>ilclient_suggest_bufsize()</DFN> function gives a
  908. * component a hint about the size of buffer it should use. This size
  909. * is set on the component by setting the
  910. * <DFN>OMX_IndexParamBrcmOutputBufferSize</DFN> index on the given
  911. * component.
  912. *
  913. * @param comp IL component handle
  914. * @param nBufSizeHint Size of buffer in bytes
  915. *
  916. * @return 0 indicates success, -1 indicates failure.
  917. ***********************************************************/
  918. VCHPRE_ int VCHPOST_ ilclient_suggest_bufsize(COMPONENT_T *comp,
  919. OMX_U32 nBufSizeHint);
  920. /**
  921. * The <DFN>ilclient_stack_size()</DFN> function suggests a minimum
  922. * stack size that tasks calling into with API will require.
  923. *
  924. * @return Suggested stack size in bytes.
  925. ***********************************************************/
  926. VCHPRE_ unsigned int VCHPOST_ ilclient_stack_size(void);
  927. #endif /* ILCLIENT_H */