component.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608
  1. /* SPDX-License-Identifier: LGPL-2.1 OR BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2019, Chips&Media
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are met:
  8. *
  9. * 1. Redistributions of source code must retain the above copyright notice, this
  10. * list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  16. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  17. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
  19. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  20. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  21. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  22. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  24. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef _COMPONENT_H_
  27. #define _COMPONENT_H_
  28. #ifdef USE_FEEDING_METHOD_BUFFER
  29. #include "wave511/config.h"
  30. #include "wave511/vpuapi/vpuapifunc.h"
  31. #include "wave511/sample_v2/helper/main_helper.h"
  32. #else
  33. #include "config.h"
  34. #include "vpuapifunc.h"
  35. #include "main_helper.h"
  36. #endif
  37. #define MAX_QUEUE_NUM 5
  38. typedef void* Component;
  39. typedef enum {
  40. GET_PARAM_COM_STATE, /*!<< It returns state of component. Param: ComponentState* */
  41. GET_PARAM_COM_IS_CONTAINER_CONUSUMED, /*!<< pointer of PortContainer */
  42. GET_PARAM_FEEDER_BITSTREAM_BUF, /*!<< to a feeder component : ParamDecBitstreamBuffer */
  43. GET_PARAM_FEEDER_EOS, /*!<< to a feeder component : BOOL */
  44. GET_PARAM_VPU_STATUS, /*!<< to a component. Get status information of the VPU : ParamVpuStatus. */
  45. GET_PARAM_DEC_HANDLE,
  46. GET_PARAM_DEC_CODEC_INFO, /*!<< It returns a codec information. Param: DecInitialInfo */
  47. GET_PARAM_DEC_BITSTREAM_BUF_POS, /*!<< to a decoder component in ring-buffer mode. */
  48. GET_PARAM_DEC_FRAME_BUF_NUM, /*!<< to a decoder component : ParamDecNeedFrameBufferNum*/
  49. GET_PARAM_RENDERER_FRAME_BUF, /*!<< to a renderer component. ParamDecFrameBuffer */
  50. GET_PARAM_RENDERER_PPU_FRAME_BUF, /*!<< to a renderer component. ParamDecPPUFrameBuffer */
  51. GET_PARAM_ENC_HANDLE,
  52. GET_PARAM_ENC_FRAME_BUF_NUM,
  53. GET_PARAM_ENC_FRAME_BUF_REGISTERED,
  54. GET_PARAM_YUVFEEDER_FRAME_BUF,
  55. GET_PARAM_READER_BITSTREAM_BUF,
  56. #ifdef SUPPORT_LOOK_AHEAD_RC
  57. GET_PARAM_ENC_LARC_INFO,
  58. #endif
  59. GET_PARAM_MAX
  60. } GetParameterCMD;
  61. typedef enum {
  62. // Common commands
  63. SET_PARAM_COM_PAUSE, /*!<< Makes a component pause. A concrete component needs to implement its own pause state. */
  64. // Decoder commands
  65. SET_PARAM_DEC_SKIP_COMMAND, /*!<< Send a skip command to a decoder component. */
  66. SET_PARAM_DEC_TARGET_TID, /*!<< Send a target temporal id to a decoder component.
  67. A parameter is pointer of ParamDecTargetTid structure. */
  68. SET_PARAM_DEC_RESET, /*!<< Reset VPU */
  69. SET_PARAM_DEC_FLUSH, /*!<< Flush command */
  70. //Encoder commands
  71. SET_PARAM_ENC_READ_BS_WHEN_FULL_INTERRUPT, /*!<< Consume the bitstream buffer when the bitstream buffer full interrupt is asserted.
  72. The parameter is a pointer of BOOL(TRUE or FALSE)
  73. */
  74. // Renderer commands
  75. SET_PARAM_RENDERER_FLUSH, /*!<< Drop all frames in the internal queue depending on the ParamDecFlush struct*/
  76. SET_PARAM_RENDERER_ALLOC_FRAMEBUFFERS,
  77. SET_PARAM_RENDERER_REALLOC_FRAMEBUFFER, /*!<< Re-allocate a framebuffer with given parameters.
  78. A component which is linked with a decoder as a sink component MUST implement this command. : ParamReallocFB
  79. */
  80. SET_PARAM_RENDERER_FREE_FRAMEBUFFERS, /*!<< A command to free framebuffers */
  81. SET_PARAM_RENDERER_CHANGE_COM_STATE, /*!<< A command to change a component state for renderer */
  82. // Feeder commands
  83. SET_PARAM_FEEDER_START_INJECT_ERROR, /* The parameter is null. */
  84. SET_PARAM_FEEDER_STOP_INJECT_ERROR, /* The parameter is null. */
  85. SET_PARAM_FEEDER_RESET,
  86. SET_PARAM_MAX
  87. } SetParameterCMD;
  88. typedef enum {
  89. COMPONENT_STATE_NONE,
  90. COMPONENT_STATE_CREATED,
  91. COMPONENT_STATE_PREPARED,
  92. COMPONENT_STATE_EXECUTED,
  93. COMPONENT_STATE_TERMINATED,
  94. COMPONENT_STATE_MAX
  95. } ComponentState;
  96. typedef enum {
  97. CNM_COMPONENT_PARAM_FAILURE,
  98. CNM_COMPONENT_PARAM_SUCCESS,
  99. CNM_COMPONENT_PARAM_NOT_READY,
  100. CNM_COMPONENT_PARAM_NOT_FOUND,
  101. CNM_COMPONENT_PARAM_TERMINATED,
  102. CNM_COMPONENT_PARAM_MAX
  103. } CNMComponentParamRet;
  104. typedef enum {
  105. CNM_COMPONENT_TYPE_NONE,
  106. CNM_COMPONENT_TYPE_ISOLATION,
  107. CNM_COMPONENT_TYPE_SOURCE,
  108. CNM_COMPONENT_TYPE_FILTER,
  109. CNM_COMPONENT_TYPE_SINK,
  110. } CNMComponentType;
  111. typedef enum {
  112. CNM_PORT_CONTAINER_TYPE_DATA,
  113. CNM_PORT_CONTAINER_TYPE_CLOCK,
  114. CNM_PORT_CONTAINER_TYPE_MAX
  115. } CNMPortContainerType;
  116. #ifdef __cplusplus
  117. extern "C" {
  118. #endif /* __cplusplus */
  119. typedef struct PortContainer {
  120. Uint32 packetNo;
  121. BOOL consumed;
  122. BOOL reuse;
  123. BOOL last;
  124. Uint32 type;
  125. } PortContainer;
  126. typedef struct PortContainerClock {
  127. Uint32 packetNo;
  128. BOOL consumed;
  129. BOOL reuse;
  130. BOOL last;
  131. Uint32 type;
  132. } PortContainerClock;
  133. /** @ingroup buf */
  134. typedef struct PortContainerExternal
  135. {
  136. Uint32 nSize; /**< size of the structure in bytes */
  137. Uint8* pBuffer; /**< Pointer to actual block of memory
  138. that is acting as the buffer */
  139. Uint32 nAllocLen; /**< size of the buffer allocated, in bytes */
  140. Uint32 nFilledLen; /**< number of bytes currently in the
  141. buffer */
  142. Uint32 nOffset; /**< start offset of valid data in bytes from
  143. the start of the buffer */
  144. void* pAppPrivate; /**< pointer to any data the application
  145. wants to associate with this buffer */
  146. Uint32 nBufferIndex;
  147. Uint32 nTickCount; /**< Optional entry that the component and
  148. application can update with a tick count
  149. when they access the component. This
  150. value should be in microseconds. Since
  151. this is a value relative to an arbitrary
  152. starting point, this value cannot be used
  153. to determine absolute time. This is an
  154. optional entry and not all components
  155. will update it.*/
  156. Uint64 nTimeStamp; /**< Timestamp corresponding to the sample
  157. starting at the first logical sample
  158. boundary in the buffer. Timestamps of
  159. successive samples within the buffer may
  160. be inferred by adding the duration of the
  161. of the preceding buffer to the timestamp
  162. of the preceding buffer.*/
  163. Uint32 nFlags; /**< buffer specific flags */
  164. Uint32 index;
  165. } PortContainerExternal;
  166. typedef struct PortContainerES {
  167. Uint32 packetNo;
  168. BOOL consumed;
  169. BOOL reuse; /*!<< If data in container wasn't consumed then @reuse is assigned to 1. */
  170. BOOL last;
  171. Uint32 type;
  172. /* ---- DO NOT TOUCH THE ABOVE FIELDS ---- */
  173. vpu_buffer_t buf;
  174. Uint32 size;
  175. Uint32 streamBufFull;
  176. /* ---- Belows vairables are for ringbuffer ---- */
  177. PhysicalAddress rdPtr;
  178. PhysicalAddress wrPtr;
  179. PhysicalAddress paBsBufStart;
  180. PhysicalAddress paBsBufEnd;
  181. vpu_buffer_t newBsBuf;
  182. } PortContainerES;
  183. typedef struct PortContainerDisplay {
  184. Uint32 packetNo;
  185. BOOL consumed;
  186. BOOL reuse;
  187. BOOL last;
  188. Uint32 type;
  189. /* ---- DO NOT TOUCH THE ABOVE FIELDS ---- */
  190. DecOutputInfo decInfo;
  191. } PortContainerDisplay;
  192. typedef struct ParamEncNeedFrameBufferNum {
  193. Uint32 reconFbNum;
  194. Uint32 srcFbNum;
  195. } ParamEncNeedFrameBufferNum;
  196. typedef struct ParamEncFrameBuffer {
  197. Uint32 reconFbStride;
  198. Uint32 reconFbHeight;
  199. FrameBuffer* reconFb;
  200. FrameBuffer* srcFb;
  201. FrameBufferAllocInfo reconFbAllocInfo;
  202. FrameBufferAllocInfo srcFbAllocInfo;
  203. } ParamEncFrameBuffer;
  204. typedef struct ParamEncBitstreamBuffer {
  205. Uint32 num;
  206. vpu_buffer_t* bs;
  207. } ParamEncBitstreamBuffer;
  208. typedef struct {
  209. BOOL ringBufferEnable;
  210. Uint8* encodedStreamBuf;
  211. Int32 encodedStreamBufSize;
  212. Int32 encodedStreamBufLength;
  213. } EncodedStreamBufInfo;
  214. typedef struct {
  215. Uint8* encodedHeaderBuf;
  216. Int32 encodedHeaderBufSize;
  217. osal_file_t *fp;
  218. } EncodedHeaderBufInfo;
  219. typedef struct {
  220. BOOL ret;
  221. BOOL success;
  222. BOOL isConnectedEnc;
  223. ParamEncNeedFrameBufferNum fbCnt;
  224. } ParamRenderAllocInfo;
  225. typedef struct PortContainerYuv {
  226. Uint32 packetNo;
  227. BOOL consumed;
  228. BOOL reuse;
  229. BOOL last;
  230. Uint32 type;
  231. /* ---- DO NOT TOUCH THE ABOVE FIELDS ---- */
  232. FrameBuffer fb;
  233. FrameBuffer fbOffsetTbl;
  234. Int32 srcFbIndex;
  235. BOOL prevMapReuse;
  236. } PortContainerYuv;
  237. typedef struct ParamDecBitstreamBuffer {
  238. Uint32 num;
  239. vpu_buffer_t* bs;
  240. } ParamDecBitstreamBuffer;
  241. typedef struct ParamDecNeedFrameBufferNum {
  242. Uint32 linearNum; /*!<< the number of framebuffers which are used to decompress or converter to linear data */
  243. Uint32 nonLinearNum; /*!<< the number of tiled or compressed framebuffers which are used as a reconstruction */
  244. } ParamDecNeedFrameBufferNum;
  245. typedef struct ParamDecFrameBuffer {
  246. Uint32 stride;
  247. Uint32 linearNum; /*!<< the number of framebuffers which are used to decompress or converter to linear data */
  248. Uint32 nonLinearNum; /*!<< the number of tiled or compressed framebuffers which are used as a reconstruction */
  249. FrameBuffer* fb;
  250. } ParamDecFrameBuffer;
  251. typedef struct ParamDecPPUFrameBuffer {
  252. BOOL enablePPU;
  253. Queue* ppuQ;
  254. FrameBuffer* fb;
  255. } ParamDecPPUFrameBuffer;
  256. typedef struct ParamDecReallocFB {
  257. Int32 linearIdx;
  258. Int32 compressedIdx;
  259. Uint32 width; /*!<< New picture width */
  260. Uint32 height; /*!<< New picture hieght */
  261. FrameBuffer newFbs[2]; /*!<< Reallocated framebuffers. newFbs[0] for compressed fb, newFbs[1] for linear fb */
  262. } ParamDecReallocFB;
  263. /* ParamDecBitStreamBufPos is used to get or set read pointer and write pointer of a bitstream buffer.
  264. */
  265. typedef struct ParamDecBitstreamBufPos {
  266. PhysicalAddress rdPtr;
  267. PhysicalAddress wrPtr;
  268. Uint32 avail; /*!<< the available size */
  269. } ParamDecBitstreamBufPos;
  270. typedef struct ParamVpuStatus {
  271. QueueStatusInfo cq; /*!<< The command queue status */
  272. } ParamVpuStatus;
  273. typedef struct ParamDecTargetTid {
  274. Int32 targetTid;
  275. Int32 tidMode; /*!<< 0 - targetTid is used as an absolute value, 1 - targetTid is used as an relative value */
  276. } ParamDecTargetTid;
  277. typedef struct ParamReallocFrameBuffer {
  278. Uint32 tiledIndex;
  279. Uint32 linearIndex;
  280. } FrameReallocFrameBuffer;
  281. typedef struct {
  282. Queue* inputQ;
  283. Queue* outputQ;
  284. Component owner;
  285. Component connectedComponent; /*!<< NOTE: DO NOT ACCESS THIS VARIABLE DIRECTLY */
  286. Uint32 sequenceNo; /*!<< The sequential number of transferred data */
  287. } Port;
  288. typedef struct {
  289. Uint8* bitcode;
  290. Uint32 sizeOfBitcode; /*!<< size of bitcode in word(2byte) */
  291. TestDecConfig testDecConfig;
  292. DecOpenParam decOpenParam;
  293. TestEncConfig testEncConfig;
  294. EncOpenParam encOpenParam;
  295. ENC_CFG encCfg;
  296. #ifdef USE_FEEDING_METHOD_BUFFER
  297. BOOL MemoryOptimization;
  298. #endif
  299. } CNMComponentConfig;
  300. #define COMPONENT_EVENT_NONE 0
  301. /* ------------------------------------------------ */
  302. /* ---------------- COMMON EVENTS ---------------- */
  303. /* ------------------------------------------------ */
  304. #define COMPONENT_EVENT_SLEEP (1ULL<<0) /*!<< The third parameter of listener is NULL. */
  305. #define COMPONENT_EVENT_WAKEUP (1ULL<<1) /*!<< The third parameter of listener is NULL. */
  306. #define COMPONENT_EVENT_TERMINATED (1ULL<<2)
  307. #define COMPONENT_EVENT_COMMON_ALL 0xffffULL
  308. /* ------------------------------------------------ */
  309. /* ---------------- DECODER EVENTS ---------------- */
  310. /* ------------------------------------------------ */
  311. #define COMPONENT_EVENT_DEC_OPEN (1ULL<<16) /*!<< The third parameter of listener is a pointer of CNMComListenerDecOpen. */
  312. #define COMPONENT_EVENT_DEC_ISSUE_SEQ (1ULL<<17) /*!<< The third parameter of listener is a pointer of CNMComListenerDecIssueSeq */
  313. #define COMPONENT_EVENT_DEC_COMPLETE_SEQ (1ULL<<18) /*!<< The third parameter of listener is a pointer of CNMComListenerDecCompleteSeq */
  314. #define COMPONENT_EVENT_DEC_REGISTER_FB (1ULL<<19) /*!<< The third parameter of listener is a pointer of CNMComListenerDecRegisterFb */
  315. #define COMPONENT_EVENT_DEC_READY_ONE_FRAME (1ULL<<20) /*!<< The third parameter of listener is a pointer of CNMComListenerDecReadyOneFrame */
  316. #define COMPONENT_EVENT_DEC_START_ONE_FRAME (1ULL<<21) /*!<< The third parameter of listener is a pointer of CNMComListenerStartDecOneFrame. */
  317. #define COMPONENT_EVENT_DEC_INTERRUPT (1ULL<<22) /*!<< The third parameter of listener is a pointer of CNMComListenerHandlingInt */
  318. #define COMPONENT_EVENT_DEC_GET_OUTPUT_INFO (1ULL<<23) /*!<< The third parameter of listener is a pointer of CNMComListenerDecDone. */
  319. #define COMPONENT_EVENT_DEC_DECODED_ALL (1ULL<<24) /*!<< The third parameter of listener is a pointer of CNMComListenerDecClose . */
  320. #define COMPONENT_EVENT_DEC_CLOSE (1ULL<<25) /*!<< The third parameter of listener is NULL. */
  321. #define COMPONENT_EVENT_DEC_RESET_DONE (1ULL<<26) /*!<< The third parameter of listener is NULL. */
  322. #define COMPONENT_EVENT_DEC_EMPTY_BUFFER_DONE (1ULL<<27)
  323. #define COMPONENT_EVENT_DEC_FILL_BUFFER_DONE (1ULL<<28)
  324. #define COMPONENT_EVENT_DEC_INSUFFIC_RESOURCE (1ULL<<29)
  325. #define COMPONENT_EVENT_DEC_ALL 0xffff0000ULL
  326. /* ------------------------------------------------ */
  327. /* ---------------- RENDERER EVENTS ----------------*/
  328. /* ------------------------------------------------ */
  329. typedef enum {
  330. COMPONENT_EVENT_RENDER_ALLOCATE_FRAMEBUFER = (1<<0),
  331. COMPONENT_EVENT_RENDER_ALL = 0xffffffff
  332. } ComponentEventRenderer;
  333. typedef struct CNMComListenerDecOpen {
  334. DecHandle handle;
  335. RetCode ret;
  336. } CNMComListenerDecOpen;
  337. typedef struct CNMComListenerDecIssueSeq {
  338. DecHandle handle;
  339. RetCode ret;
  340. } CNMComListenerDecIssueSeq;
  341. typedef struct CNMComListenerDecCompleteSeq {
  342. DecInitialInfo* initialInfo;
  343. FrameBufferFormat wtlFormat;
  344. Uint32 cbcrInterleave;
  345. CodStd bitstreamFormat;
  346. char refYuvPath[MAX_FILE_PATH];
  347. RetCode ret;
  348. } CNMComListenerDecCompleteSeq;
  349. typedef struct CNMComListenerDecRegisterFb {
  350. DecHandle handle;
  351. Uint32 numNonLinearFb;
  352. Uint32 numLinearFb;
  353. } CNMComListenerDecRegisterFb;
  354. typedef struct CNMComListenerDecReadyOneFrame {
  355. DecHandle handle;
  356. } CNMComListenerDecReadyOneFrame;
  357. typedef struct CNMComListenerStartDecOneFrame {
  358. DecHandle handle;
  359. RetCode result;
  360. DecParam decParam;
  361. } CNMComListenerStartDecOneFrame;
  362. typedef struct CNMComListenerDecInt {
  363. DecHandle handle;
  364. Int32 flag;
  365. Uint32 decIndex;
  366. } CNMComListenerDecInt;
  367. typedef struct CNMComListenerDecDone {
  368. DecHandle handle;
  369. RetCode ret;
  370. DecParam* decParam;
  371. DecOutputInfo* output;
  372. Uint32 numDecoded;
  373. vpu_buffer_t vbUser;
  374. CodStd bitstreamFormat; /* codec */
  375. BOOL enableScaler;
  376. #if defined(SUPPORT_VCPU_FPGA) || defined(SUPPORT_VCORE_FPGA)
  377. VcoreTestData* vcoreData;
  378. #endif /* SUPPORT_VCPU_FPGA || SUPPORT_VCORE_FPGA */
  379. } CNMComListenerDecDone;
  380. typedef struct CNMComListenerDecClose {
  381. DecHandle handle;
  382. } CNMComListenerDecClose;
  383. /* ------------------------------------------------ */
  384. /* ---------------- ENCODER EVENTS ---------------- */
  385. /* ------------------------------------------------ */
  386. #define COMPONENT_EVENT_ENC_OPEN (1ULL<<32) /*!<< The third parameter of listener is a pointer of CNMComListenerEncOpen. */
  387. #define COMPONENT_EVENT_ENC_ISSUE_SEQ (1ULL<<33) /*!<< The third parameter of listener is NULL */
  388. #define COMPONENT_EVENT_ENC_COMPLETE_SEQ (1ULL<<34) /*!<< The third parameter of listener is a pointer of CNMComListenerEncCompleteSeq */
  389. #define COMPONENT_EVENT_ENC_REGISTER_FB (1ULL<<35) /*!<< The third parameter of listener is NULL */
  390. #define COMPONENT_EVENT_ENC_READY_ONE_FRAME (1ULL<<36) /*!<< The third parameter of listener is a pointer of CNMComListenerEncReadyOneFrame */
  391. #define COMPONENT_EVENT_ENC_START_ONE_FRAME (1ULL<<37) /*!<< The third parameter of listener is a pointer of CNMComListenerEncStartOneFrame */
  392. #define COMPONENT_EVENT_ENC_HANDLING_INT (1ULL<<38) /*!<< The third parameter of listener is a pointer of CNMComListenerHandlingInt */
  393. #define COMPONENT_EVENT_ENC_GET_OUTPUT_INFO (1ULL<<39) /*!<< The third parameter of listener is a pointer of CNMComListenerEncDone. */
  394. #define COMPONENT_EVENT_ENC_CLOSE (1ULL<<40) /*!<< The third parameter of listener is a pointer of CNMComListenerEncClose. */
  395. #define COMPONENT_EVENT_ENC_FULL_INTERRUPT (1ULL<<41) /*!<< The third parameter of listener is a pointer of CNMComListenerEncFull . */
  396. #define COMPONENT_EVENT_ENC_ENCODED_ALL (1ULL<<42) /*!<< The third parameter of listener is a pointer of EncHandle. */
  397. #define COMPONENT_EVENT_ENC_RESET (1ULL<<43) /*!<< The third parameter of listener is a pointer of EncHandle. */
  398. #define COMPONENT_EVENT_CODA9_ENC_MAKE_HEADER (1ULL<<44) /*!<< The third parameter of listener is a pointer of CNMComListenerEncDone. */
  399. #define COMPONENT_EVENT_ENC_EMPTY_BUFFER_DONE (1ULL<<45)
  400. #define COMPONENT_EVENT_ENC_FILL_BUFFER_DONE (1ULL<<46)
  401. #define COMPONENT_EVENT_ENC_ALL 0xffff00000000ULL
  402. /* ------------------------------------------------ */
  403. /* ---------------- ENC FEEDER EVENTS ----------------*/
  404. /* ------------------------------------------------ */
  405. typedef enum {
  406. COMPONENT_EVENT_ENC_FEEDER_PREPARE = (1<<0),
  407. COMPONENT_EVENT_ENC_FEEDER_ALL = 0xffffffff
  408. } ComponentEventEncFeeder;
  409. typedef struct CNMComListenerEncOpen{
  410. EncHandle handle;
  411. } CNMComListenerEncOpen;
  412. typedef struct CNMComListenerEncCompleteSeq {
  413. EncHandle handle;
  414. } CNMComListenerEncCompleteSeq;
  415. typedef struct CNMComListenerHandlingInt {
  416. EncHandle handle;
  417. } CNMComListenerHandlingInt;
  418. typedef struct CNMComListenerEncMakeHeader{
  419. EncHandle handle;
  420. EncodedHeaderBufInfo encHeaderInfo;
  421. } CNMComListenerEncMakeHeader;
  422. typedef struct CNMComListenerEncReadyOneFrame{
  423. EncHandle handle;
  424. RetCode result;
  425. } CNMComListenerEncReadyOneFrame;
  426. typedef struct CNMComListenerEncStartOneFrame{
  427. EncHandle handle;
  428. RetCode result;
  429. } CNMComListenerEncStartOneFrame;
  430. typedef struct CNMComListenerEncDone {
  431. EncHandle handle;
  432. EncOutputInfo* output;
  433. BOOL fullInterrupted;
  434. EncodedStreamBufInfo encodedStreamInfo;
  435. PhysicalAddress bitstreamBuffer;
  436. Uint32 bitstreamBufferSize;
  437. } CNMComListenerEncDone;
  438. typedef struct CNMComListenerEncFull {
  439. EncHandle handle;
  440. } CNMComListenerEncFull;
  441. typedef struct CNMComListenerEncClose {
  442. EncHandle handle;
  443. } CNMComListenerEncClose;
  444. typedef Int32 (*ListenerFuncType)(Component, Port*, void*);
  445. typedef void (*ComponentListenerFunc)(Component com, Uint64 event, void* data, void* context);
  446. typedef struct {
  447. Uint64 events; /*!<< See COMPONENT_EVENT_XXXX, It can be ORed with other events. */
  448. ComponentListenerFunc update;
  449. void* context;
  450. } ComponentListener;
  451. #define MAX_NUM_LISTENERS 32
  452. typedef struct ComponentImpl {
  453. char* name;
  454. void* context;
  455. Port sinkPort;
  456. Port srcPort;
  457. Uint32 containerSize;
  458. Uint32 numSinkPortQueue;
  459. Component (*Create)(struct ComponentImpl*, CNMComponentConfig*);
  460. CNMComponentParamRet (*GetParameter)(struct ComponentImpl*, struct ComponentImpl*, GetParameterCMD, void*);
  461. CNMComponentParamRet (*SetParameter)(struct ComponentImpl*, struct ComponentImpl*, SetParameterCMD, void*);
  462. BOOL (*Prepare)(struct ComponentImpl*, BOOL*);
  463. /* \brief process input data and return output.
  464. * \return TRUE - process done
  465. */
  466. BOOL (*Execute)(struct ComponentImpl*, PortContainer*, PortContainer*);
  467. /* \brief release all memories that are allocated by vdi_dma_allocate_memory().
  468. */
  469. void (*Release)(struct ComponentImpl*);
  470. BOOL (*Destroy)(struct ComponentImpl*);
  471. BOOL success;
  472. osal_thread_t thread;
  473. ComponentState state;
  474. BOOL terminate;
  475. ComponentListener listeners[MAX_NUM_LISTENERS];
  476. Uint32 numListeners;
  477. Queue* usingQ; /*<<! NOTE: DO NOT USE Enqueue() AND Dequeue() IN YOUR COMPONENT.
  478. BUT, YOU CAN USE Peek() FUNCTION.
  479. */
  480. CNMComponentType type;
  481. Uint32 updateTime;
  482. Uint32 Hz; /* Use clock signal ex) 30Hz, A component will receive 30 clock signals per second. */
  483. void* internalData;
  484. BOOL pause;
  485. BOOL portFlush;
  486. } ComponentImpl;
  487. Component ComponentCreate(const char* componentName, CNMComponentConfig* componentParam);
  488. BOOL ComponentSetupTunnel(Component fromComponent, Component toComponent);
  489. ComponentState ComponentExecute(Component component);
  490. /* @return 0 - done
  491. * 1 - running
  492. * 2 - error
  493. */
  494. Int32 ComponentWait(Component component);
  495. void ComponentStop(Component component);
  496. void ComponentRelease(Component component);
  497. BOOL ComponentChangeState(Component component, Uint32 state);
  498. /* \brief Release all resources of the component
  499. * \param ret The output variable that has status of success or failure.
  500. */
  501. BOOL ComponentDestroy(Component component, BOOL* ret);
  502. CNMComponentParamRet ComponentGetParameter(Component from, Component to, GetParameterCMD commandType, void* data);
  503. CNMComponentParamRet ComponentSetParameter(Component from, Component to, SetParameterCMD commandType, void* data);
  504. void ComponentNotifyListeners(Component component, Uint64 event, void* data);
  505. BOOL ComponentRegisterListener(Component component, Uint64 events, ComponentListenerFunc func, void* context);
  506. /* \brief Create a port
  507. * \param size The size of PortStruct of the component
  508. * depth The size of internal input queue and output queue.
  509. */
  510. void ComponentPortCreate(Port* port, Component owner, Uint32 depth, Uint32 size);
  511. /* \brief Fill data into the output queue.
  512. */
  513. void ComponentPortSetData(Port* port, PortContainer* portData);
  514. /* \brief Peek data from the input queue.
  515. */
  516. PortContainer* ComponentPortPeekData(Port* port);
  517. /* \brief Get data from the input queue.
  518. */
  519. PortContainer* ComponentPortGetData(Port* port);
  520. /* \brief Wait before get data from the input queue.
  521. */
  522. void* WaitBeforeComponentPortGetData(Port* port);
  523. /* \brief Ready status: the output queue is empty.
  524. */
  525. void ComponentPortWaitReadyStatus(Port* port);
  526. /* \brief Destroy port instance
  527. */
  528. void ComponentPortDestroy(Port* port);
  529. /* \brief If a port has input data, it returns true.
  530. */
  531. BOOL ComponentPortHasInputData(Port* port);
  532. Uint32 ComponentPortGetSize(Port* port);
  533. /* \brief Clear input data
  534. */
  535. void ComponentPortFlush(Component component);
  536. ComponentState ComponentGetState(Component component);
  537. BOOL ComponentParamReturnTest(CNMComponentParamRet ret, BOOL* retry);
  538. #ifdef __cplusplus
  539. }
  540. #endif /* __cplusplus */
  541. #endif // _COMPONENT_H_