2 #ifndef IODATA_H
3 #define IODATA_H
5 #include <stdint.h>
6 #include "ioBuff.h"
8 // I/O DATA error code
9 enum {
10 IODATA_NO_ERR,
11 IODATA_ERR_MEMORY,
12 IODATA_ERR_BAD_PARAMS,
13 IODATA_ERR_IOBUF_UNDERFLOW,
14 IODATA_ERR_IOBUF_OVERFLOW
15 };
17 // define a type for I/O DATA handle
18 typedef void * ioDataHandle_t;
20 // I/O DATA configuration parameters
21 typedef struct ioDataParam_s{
22 ioBuffHandle_t ioBuffHandle; // handle to the associated I/O BUFF
23 uint_least16_t *frameLengthsIEC; // pointer to array of supported IEC frame lengths
24 uint_least16_t frameLengthPCM; // frame length for PCM input
25 uint_least16_t frameLengthDef; // default frame length for SYNC search
26 int_least32_t unknownSourceTimeOut; // time out value to declare unknown source
27 uint_least32_t zeroRunTrigger; // threshold to declare zero run
28 uint_least32_t zeroRunRestart; // threshold to restart auto-detection under zero run
29 int8_t ibMode; // IB Mode
30 } ioDataParam_t;
32 // Information needed for decoders to read a bitstream frame
33 typedef struct ioDataReadInfo_s {
34 void *buffBase; // base address of the buffer holding the bitstream data
35 uint_least32_t buffSize; // size of the buffer holding the bitstream data
36 void *startAddress; // start address of next complete frame to read
37 uint_least32_t frameSize; // size of the frame in bytes
38 } ioDataReadInfo_t;
40 // Control commands for ioDataControl
41 enum {
42 IODATA_CTL_SET_ELEMENT_SIZE,
43 IODATA_CTL_SET_FRAME_LENGTH,
44 IODATA_CTL_GET_INPBUFFINFO,
45 IODATA_CTL_GET_AUTODET_STATUS,
46 };
48 // SYNC search/detection status
49 enum
50 {
51 IODATA_SYNC_NONE,
52 IODATA_SYNC_ONE,
53 // IODATA_SYNC_CHECK,
54 IODATA_SYNC_BITSTREAM,
55 IODATA_SYNC_PCM,
56 IODATA_SYNC_PCM_FORCED,
57 IODATA_SYNC_PCM_ZERORUN,
58 IODATA_SYNC_AUTO
59 };
61 // Frame information
62 typedef struct ioDataFrameInfo_s {
63 uint_fast32_t frameLength; // length in units of elements
64 int8_t elementSize; // size of elements in bytes
65 } ioDataFrameInfo_t;
67 // Auto-detection status
68 typedef struct ioDataAutoDetStat_s {
69 uint_least16_t syncState; // SYNC state
70 uint_least16_t bitStreamInfo; // bit stream information - value of IEC_PC
71 uint8_t deliverZeros; // flag to indicate whether zeros should be sent to output
72 } ioDataAutoDetStat_t;
74 // I/O DATA control structure
75 typedef struct ioDataCtl_s {
76 uint_fast16_t code;
77 union {
78 ioDataReadInfo_t dataReadInfo; // IODATA_CTL_GET_INPBUFFINFO
79 ioDataFrameInfo_t frameInfo; // IODATA_CTL_SET_ELEMENT_SIZE or IODATA_CTL_SET_FRAME_LENGTH
80 ioDataAutoDetStat_t autoDetStats; // IODATA_CTL_GET_AUTODET_STATUS
81 } param;
82 } ioDataCtl_t;
84 /**
85 * @brief ioDataNumAlloc
86 * Returns the maximum number of memory allocation requests that ioDataAlloc()
87 * requires.
88 */
89 int ioDataNumAlloc(void);
91 /**
92 * @brief ioDataAlloc
93 * Returns a table of memory records that describe the size, alignment, type
94 * and memory space of all buffers required by I/O DATA component.
95 */
96 int ioDataAlloc(lib_mem_rec_t *mem_tbl);
98 /**
99 * @brief ioDataCreate
100 * Based on the provided memory blocks, this function creates an I/O DATA
101 * instance and returns a handle. This handle points to the memory block
102 * that contains the instance.
103 */
104 int ioDataCreate(ioDataHandle_t *handle, const lib_mem_rec_t *mem_tbl);
106 /**
107 * @brief ioDATAInit
108 * Initializes the I/O DATA instance.
109 */
110 int ioDataInit(ioDataHandle_t handle, ioDataParam_t *cfgParams);
112 /**
113 * @brief ioDataProcess
114 * The main function of I/O DATA processing, i.e. auto-detection.
115 */
116 int ioDataProcess(ioDataHandle_t handle);
118 /**
119 * @brief ioDataReadComplete
120 * This function marks as read complete the data in the input buffer that has
121 * been processed by ioDataProcess and the decoder. It should be called after
122 * ioDataProcess() is called and after the decoder finishes reading current
123 * frame in the input buffer.
124 */
125 int ioDataReadComplete(ioDataHandle_t handle);
128 /**
129 * @brief ioDataControl
130 * This function allows run-time control of I/O DATA components through control
131 * command IODATA_CTL_XXX and control structure ioDataCtl_t.
132 */
133 int ioDataControl(ioDataHandle_t handle, ioDataCtl_t *ctlParams);
136 #endif