component.h 26 KB

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