| 1 | /******************************************************************** |
|---|
| 2 | * |
|---|
| 3 | * PSI_Process.h - PSI Section Processing. (PSI). |
|---|
| 4 | * |
|---|
| 5 | * Copyright 2004~ DigitalSTREAMTechnology, Inc. |
|---|
| 6 | * All Rights Reserved |
|---|
| 7 | * |
|---|
| 8 | * _Id: PSI_PsiSectGather.h ,v 1.0 2004/015/28 jina Exp |
|---|
| 9 | ********************************************************************/ |
|---|
| 10 | |
|---|
| 11 | #ifndef DST_PSI_SECTGATHER_H_ |
|---|
| 12 | #define DST_PSI_SECTGATHER_H_ |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #ifdef __cplusplus |
|---|
| 16 | extern "C" { |
|---|
| 17 | #endif |
|---|
| 18 | |
|---|
| 19 | |
|---|
| 20 | #if !defined (_DSTHALERROR_H_) |
|---|
| 21 | #include "dsthalerror.h" |
|---|
| 22 | #endif |
|---|
| 23 | |
|---|
| 24 | /* |
|---|
| 25 | * Section syntax macro definitions |
|---|
| 26 | */ |
|---|
| 27 | |
|---|
| 28 | #define SECTION_TID 0 /* TID index */ |
|---|
| 29 | #define SECTION_LEN_HI 1 /* length hi index */ |
|---|
| 30 | #define SECTION_LEN_LO 2 /* length lo index */ |
|---|
| 31 | #define SECTION_TID_EXT_HI 3 /* Table ID extension high index*/ |
|---|
| 32 | #define SECTION_TID_EXT_LO 4 /* Table ID extension low index */ |
|---|
| 33 | #define SECTION_VERSION 5 /* version number index */ |
|---|
| 34 | #define SECTION_NUM 6 /* section number index */ |
|---|
| 35 | #define SECTION_NUM_LAST 7 /* last section number index */ |
|---|
| 36 | #define SECTION_HEADER_LENGTH 8 /* number of bytes in section header */ |
|---|
| 37 | |
|---|
| 38 | #define SECTION_LEN_MASK 0x0FFF /* length bit mask */ |
|---|
| 39 | #define SECTION_VERSION_MASK 0x3E /* version number bit mask */ |
|---|
| 40 | #define SECTION_VERSION_SHIFT 1 /* version number bit shift */ |
|---|
| 41 | #define SECTION_CNI_MASK 0x01 /* current next indicator mask */ |
|---|
| 42 | |
|---|
| 43 | #define PID_MASK 0x1FFF /* Mask for various places a PID is used */ |
|---|
| 44 | #define PSIMODE_EAGER_FLAG 8 |
|---|
| 45 | |
|---|
| 46 | |
|---|
| 47 | /*Independency¸¦ À§ÇØ Á¤ÀÇ ÇÑ´Ù.*/ |
|---|
| 48 | //#define PSI_Printf |
|---|
| 49 | |
|---|
| 50 | #ifdef DMALLOC |
|---|
| 51 | #define PSI_Malloc malloc |
|---|
| 52 | #define PSI_Free free |
|---|
| 53 | #else |
|---|
| 54 | void * PSI_Malloc( int iSize ); |
|---|
| 55 | void PSI_Free( void *memBlock ); |
|---|
| 56 | #endif //#if 0 |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | /* |
|---|
| 60 | * PSImode defines the type of PSI processing to do |
|---|
| 61 | */ |
|---|
| 62 | typedef enum { |
|---|
| 63 | privateMode = 0, /* Takes data not in section syntax */ |
|---|
| 64 | sectionMode = 1, /* Take a single section */ |
|---|
| 65 | tableMode = 2, /* Take a table made of multiple sections */ |
|---|
| 66 | eagerTableMode = 10, /* Same as tableMode but also send psiSectionReceived events */ |
|---|
| 67 | segmentTableMode = 11, /* Same as tableMode but also checks segment_last_section_number */ |
|---|
| 68 | segmentOnlyMode = 12, /* Same as tableMode but receive only 1 segment */ |
|---|
| 69 | segmentEagerMode = 13, |
|---|
| 70 | |
|---|
| 71 | si_privateTableMode_RD = 16, |
|---|
| 72 | si_eagerPrivateTableMode_RD = 32 |
|---|
| 73 | |
|---|
| 74 | }PSIMode; |
|---|
| 75 | |
|---|
| 76 | /* |
|---|
| 77 | * PSIUpdateMode defines what to do when an event is sent to the client |
|---|
| 78 | */ |
|---|
| 79 | typedef enum { |
|---|
| 80 | psiOneShot = 1, /* Filter must be reset for more data to come in. */ |
|---|
| 81 | psiVersionChange, /* Event is sent every time the version changes */ |
|---|
| 82 | psiCRCChange, /* Event is sent every time any CRC changes */ |
|---|
| 83 | psiContinuous, /* Event is sent every time filter matches */ |
|---|
| 84 | }PSIUpdateMode; |
|---|
| 85 | |
|---|
| 86 | /* |
|---|
| 87 | * PSI events |
|---|
| 88 | */ |
|---|
| 89 | typedef enum { |
|---|
| 90 | psiNoEvent = 0, /* Null event used internally and is never sent */ |
|---|
| 91 | /* The following events are sent to all eventProcs monitoring a given PID */ |
|---|
| 92 | /* They are the same as the corresponding pes events */ |
|---|
| 93 | psiDup3Packet, /* Three duplicate transport packets */ |
|---|
| 94 | psiLostPacket, /* Lost transport packet */ |
|---|
| 95 | psiDiscontinuity, /* Discontinuity_indicator set at transport */ |
|---|
| 96 | psiSplicingPoint, /* Splicing point reached */ |
|---|
| 97 | psiSyncErr, /* Section straddling transport packets incorrectly terminated */ |
|---|
| 98 | psiScrambledErr, /* Sections are scrambled. DemuxDev disabled */ |
|---|
| 99 | /* The following events are sent to only one eventProc */ |
|---|
| 100 | psiSectionReceived = 10,/* Eager only - A section has been received within a table. More to come */ |
|---|
| 101 | psiDataReceived, /* Data is available. Load is complete */ |
|---|
| 102 | psiMemoryError, /* Out of CPU memory trying to allocate buffer space */ |
|---|
| 103 | psiSectionTooBig, /* A section was received which was larger than maxData */ |
|---|
| 104 | psiCRCError, /* CRC error occurred.*/ |
|---|
| 105 | psiVersionChanged, /* Eager only - Version changed, restarting table collection */ |
|---|
| 106 | psiCRCUnchanged, /* Eager sectionMode psiCRCChange only - The CRC is the same as for the last table */ |
|---|
| 107 | psiMaxSectionOverflow, /* Table mode only - Actual # of sections > requested maxSections */ |
|---|
| 108 | psiLastSectionOverflow, /* Table mode only - section # > last_section # */ |
|---|
| 109 | psiARIBEmmReceived, /* Event for ARIB EMM messages */ |
|---|
| 110 | psiARIBIndivEmmReceived, /* Event for ARIB EMM individual messages */ |
|---|
| 111 | psiARIBCommonEmmReceived, /* Event for ARIB EMM common messages */ |
|---|
| 112 | psiFifoFullEvent, /* Event for FIFO full condition in Linux */ |
|---|
| 113 | killUserTask = 1000 /* Linux event notification to user space to terminate task */ |
|---|
| 114 | }PSIEvent; |
|---|
| 115 | |
|---|
| 116 | |
|---|
| 117 | |
|---|
| 118 | |
|---|
| 119 | #define DYNARRAY_SECTPTR 256 /* Debugger thinks there is this many anreies */ |
|---|
| 120 | typedef struct PSIDataArray_t |
|---|
| 121 | { |
|---|
| 122 | struct PSIContext_t *context; /* request ID */ |
|---|
| 123 | DS_U16 pid; /* pid which this section came from */ |
|---|
| 124 | DS_S32 numSections; /* number of section */ |
|---|
| 125 | DS_S32 maxSections; /* max number of sections structure can hold */ |
|---|
| 126 | DS_U8 *sectPtr[DYNARRAY_SECTPTR]; /* dynamic array of 1 or more section pointers */ |
|---|
| 127 | DS_U8 lastSegmentNumber[DYNARRAY_SECTPTR]; |
|---|
| 128 | }PSIDataArray_t; |
|---|
| 129 | |
|---|
| 130 | |
|---|
| 131 | |
|---|
| 132 | |
|---|
| 133 | |
|---|
| 134 | |
|---|
| 135 | typedef struct PSIEventProcData_t { |
|---|
| 136 | PSIDataArray_t *desc; |
|---|
| 137 | DS_U32 err; |
|---|
| 138 | DS_U32 hEvent; |
|---|
| 139 | }PSIEventProcData_t; |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | #define PSIDescriptorSize(nelem) (sizeof(PSIDataArray_t) + \ |
|---|
| 143 | ((nelem)-DYNARRAY_SECTPTR)*sizeof(DS_U8 *)) |
|---|
| 144 | #define PSISectionLength(ptr) ((((ptr[1])<<8)+(ptr[2]))&0x0FFF) |
|---|
| 145 | |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | typedef enum PSIFieldSelect_k { |
|---|
| 150 | TOP_FIELD = 0x00, |
|---|
| 151 | BOTTOM_FIELD = 0x10, |
|---|
| 152 | BOTH_FIELDS = 0x02 |
|---|
| 153 | } PSIFieldSelect_k; |
|---|
| 154 | |
|---|
| 155 | |
|---|
| 156 | typedef struct PSIMaskByte_t { |
|---|
| 157 | DS_U8 value; |
|---|
| 158 | DS_U8 matchMask; |
|---|
| 159 | DS_U8 noMatchMask; |
|---|
| 160 | }PSIMaskByte_t; |
|---|
| 161 | |
|---|
| 162 | #define DYNARRAY_PSIMaskEntry 16 /* Debugger thinks there is this many entries */ |
|---|
| 163 | typedef struct PSIMask_t |
|---|
| 164 | { |
|---|
| 165 | int numEntries; /* size of psiFilter */ |
|---|
| 166 | PSIMaskByte_t entries[DYNARRAY_PSIMaskEntry]; /* Variable number of filter entries */ |
|---|
| 167 | } PSIMask_t; |
|---|
| 168 | |
|---|
| 169 | #define PSIMaskSize(nelem) (sizeof(PSIMask_t) + \ |
|---|
| 170 | ((nelem)-DYNARRAY_PSIMaskEntry)*sizeof(PSIMaskByte_t)) |
|---|
| 171 | |
|---|
| 172 | |
|---|
| 173 | |
|---|
| 174 | |
|---|
| 175 | |
|---|
| 176 | //typedef void (*PSIEventProc)(PSIEvent event, PSIControl *psiCtl, DS_U32 userParam); |
|---|
| 177 | typedef void (*PSIEventProc_f)(PSIEvent event , void* pPsiInfo , DS_U32 userParam ); |
|---|
| 178 | typedef void (*PSIRegisterProc_f)( DS_U32 userParam1 , DS_U32 userParam2 ); |
|---|
| 179 | |
|---|
| 180 | //JFET_20050614 |
|---|
| 181 | //FOR THE GEMSTAR EPG |
|---|
| 182 | typedef void (*GemstarUserCallBack)(DS_U8* sectPtr); |
|---|
| 183 | |
|---|
| 184 | |
|---|
| 185 | typedef struct PSIContext_t |
|---|
| 186 | { |
|---|
| 187 | void *pParent; |
|---|
| 188 | DS_U16 pid; |
|---|
| 189 | DS_S32 selfIndex; /* start section index or self */ |
|---|
| 190 | PSIMode psiMode; /* The PSI data collection mode */ |
|---|
| 191 | PSIUpdateMode updateMode; /* The PSI update mode */ |
|---|
| 192 | DS_S32 maxData; /* Max bytes per section */ |
|---|
| 193 | DS_S32 maxSections; /* Max number of sections to collect */ |
|---|
| 194 | DS_S32 curSection; /* The last section received */ |
|---|
| 195 | DS_S32 version; /* Version number for table being gathered */ |
|---|
| 196 | PSIEventProc_f eventProc; /* The event upcall */ |
|---|
| 197 | DS_U32 userParam; /* User data to pass to upcall */ |
|---|
| 198 | DS_U32 lastCRC; /* Used for siCRCChange */ |
|---|
| 199 | DS_U32 runningCRC; /* Used to combine all CRC's for sections in table */ |
|---|
| 200 | DS_BOOL lastCRCValid; /* TRUE if lastCRC has valid data */ |
|---|
| 201 | DS_BOOL oneShot; /* whether or not this is a oneShot */ |
|---|
| 202 | PSIDataArray_t *curDataArray; /* A complete descriptor waiting to be taken */ |
|---|
| 203 | PSIDataArray_t *nextDataArray; /* An incomplete descriptor for data still being gathered */ |
|---|
| 204 | |
|---|
| 205 | DS_U8 lastVersion; |
|---|
| 206 | |
|---|
| 207 | PSIMask_t *psiMask; |
|---|
| 208 | |
|---|
| 209 | PSIRegisterProc_f stopProc; |
|---|
| 210 | DS_U32 userParamStop; |
|---|
| 211 | DS_BOOL bRegistered; |
|---|
| 212 | |
|---|
| 213 | DS_U8 segment_number; |
|---|
| 214 | }PSIContext_t; |
|---|
| 215 | |
|---|
| 216 | |
|---|
| 217 | |
|---|
| 218 | |
|---|
| 219 | struct PSIContext_t *DD_PSI_AllocPSIContext(void); |
|---|
| 220 | |
|---|
| 221 | void DD_PSI_FreePSIContext( struct PSIContext_t *pPsiContext ); |
|---|
| 222 | |
|---|
| 223 | DHL_RESULT DD_PSI_GetEmptyPSIMask( DS_S32 numEntries, PSIMask_t **ppMask ); |
|---|
| 224 | |
|---|
| 225 | DHL_RESULT DD_PSI_GetTIDPSIMask(struct PSIMask_t **ppMask, DS_U8 TID, DS_BOOL current_next_indicator); |
|---|
| 226 | |
|---|
| 227 | DHL_RESULT DD_PSI_GetExTIDPSIMask(struct PSIMask_t **ppMask, |
|---|
| 228 | DS_U8 TID, |
|---|
| 229 | DS_U16 TIDExtension, |
|---|
| 230 | DS_BOOL current_next_indicator); |
|---|
| 231 | |
|---|
| 232 | DHL_RESULT DD_PSI_GetExTIDFieldPSIMask( struct PSIMask_t **ppMask, |
|---|
| 233 | DS_U8 TID, |
|---|
| 234 | DS_U16 TIDExtension, |
|---|
| 235 | PSIFieldSelect_k whichField, |
|---|
| 236 | DS_BOOL current_next_indicator); |
|---|
| 237 | |
|---|
| 238 | |
|---|
| 239 | DHL_RESULT DD_PSI_GetDvbEitMask( PSIMask_t **ppMask, |
|---|
| 240 | DS_U8 TID, |
|---|
| 241 | DS_U16 TIDExtension, |
|---|
| 242 | DS_U8 segment_number, |
|---|
| 243 | DS_BOOL current_next_indicator); |
|---|
| 244 | |
|---|
| 245 | DHL_RESULT DD_PSI_GetETTPSIMask( struct PSIMask_t **ppMask, |
|---|
| 246 | DS_U8 TID, |
|---|
| 247 | DS_U32 ETM_id, |
|---|
| 248 | DS_BOOL current_next_indicator); |
|---|
| 249 | |
|---|
| 250 | DHL_RESULT DD_PSI_GetDsmccPSIMask( PSIMask_t **ppMask, |
|---|
| 251 | DS_U8 TID, |
|---|
| 252 | DS_U32 DsmccMessageId, |
|---|
| 253 | DS_BOOL current_next_indicator); |
|---|
| 254 | |
|---|
| 255 | DHL_RESULT DD_PSI_GetDsmccPSIMaskEx( PSIMask_t **ppMask, |
|---|
| 256 | DS_U8 TID, |
|---|
| 257 | DS_U32 DsmccMessageId, |
|---|
| 258 | DS_BOOL current_next_indicator, |
|---|
| 259 | int segment_number); |
|---|
| 260 | |
|---|
| 261 | DHL_RESULT DD_PSI_ReadPSIArray( struct PSIContext_t *psi , struct PSIDataArray_t **returnArray); |
|---|
| 262 | void DD_PSI_FreePSIArray(PSIDataArray_t *psi); |
|---|
| 263 | |
|---|
| 264 | DHL_RESULT DD_PSI_GetLastReceivedSection( PSIContext_t *psiCtl, |
|---|
| 265 | DS_BOOL detach, |
|---|
| 266 | DS_S32 *returnSectionNumber, |
|---|
| 267 | DS_S32 *returnLastSectionNumber, |
|---|
| 268 | DS_U8 **returnSectionData); |
|---|
| 269 | |
|---|
| 270 | typedef DS_U8 *P_DS_U8; |
|---|
| 271 | |
|---|
| 272 | DHL_RESULT DD_PSI_GetLastReceivedSegment( PSIContext_t *psiCtl, |
|---|
| 273 | DS_BOOL detach, |
|---|
| 274 | DS_S32 *returnSegmentNumber, |
|---|
| 275 | DS_S32 *returnSegmentCount, |
|---|
| 276 | P_DS_U8 returnSectionData[]); |
|---|
| 277 | |
|---|
| 278 | DHL_RESULT DD_PSI_RegisterPSICtx( void *pParent, |
|---|
| 279 | DS_U16 pid, |
|---|
| 280 | PSIMode psiMode, |
|---|
| 281 | PSIUpdateMode updateMode, |
|---|
| 282 | PSIMask_t *prefList, |
|---|
| 283 | DS_U16 maxData, |
|---|
| 284 | DS_U16 maxSections, |
|---|
| 285 | PSIEventProc_f eventProc, |
|---|
| 286 | DS_U32 userParam , |
|---|
| 287 | PSIRegisterProc_f stopFuncPtr, |
|---|
| 288 | DS_U32 usrParamStop, |
|---|
| 289 | DS_BOOL bRegister, |
|---|
| 290 | void **returnPSIControl ); |
|---|
| 291 | |
|---|
| 292 | void DD_PSI_ReleasePSICtx( void * pPSICtx ); |
|---|
| 293 | void DD_PSI_DataReceived( struct PSIContext_t *master , DS_U8 *data, int len); |
|---|
| 294 | |
|---|
| 295 | DHL_RESULT DD_PSI_GetTIDPSISimpleMask(PSIMask_t **ppMask, DS_U8 TID ); |
|---|
| 296 | DHL_RESULT DD_PSI_GetTIDPrivateSubtypePSIMask( PSIMask_t **ppMask, |
|---|
| 297 | DS_U8 TID, |
|---|
| 298 | DS_U8 byteToSee, |
|---|
| 299 | DS_U8 byteValue, |
|---|
| 300 | PSIFieldSelect_k whichField); |
|---|
| 301 | PSIContext_t *DD_PSI_DoSWSectionFiltering( DS_U16 pid , DS_U8 *pData , int iLen); |
|---|
| 302 | |
|---|
| 303 | void DD_PSI_ResetRegisteredMonitorFilters(void); |
|---|
| 304 | void DD_PSI_ClearRegisteredMonitorFilters(void); |
|---|
| 305 | void DD_PSI_ResetRegisteredMonitorFiltersExcludingOne( DS_U8 tid , DS_U8 byteIndex , DS_U8 byteMask , DS_U8 byteValue); |
|---|
| 306 | |
|---|
| 307 | |
|---|
| 308 | |
|---|
| 309 | DHL_RESULT DHL_PSI_ReadPSIDataSw( void * hTblHandle , struct PSIDataArray_t **returnPsi ); |
|---|
| 310 | DHL_RESULT DHL_PSI_MonitorPSIPidSw( DS_U16 pid, |
|---|
| 311 | PSIMode psiMode, |
|---|
| 312 | PSIUpdateMode updateMode, |
|---|
| 313 | PSIMask_t *prefList, |
|---|
| 314 | DS_U16 maxData, |
|---|
| 315 | DS_U16 maxSections, |
|---|
| 316 | PSIEventProc_f eventProc, |
|---|
| 317 | DS_U32 userParam, |
|---|
| 318 | void **returnPSIControl ); |
|---|
| 319 | DHL_RESULT DHL_PSI_CancelMonitorSw( void * hPsiCtl ); |
|---|
| 320 | void DHL_PSI_FreePSIArray( PSIDataArray_t *psi ); |
|---|
| 321 | #ifdef __cplusplus |
|---|
| 322 | } |
|---|
| 323 | #endif |
|---|
| 324 | |
|---|
| 325 | |
|---|
| 326 | #endif /*ifndef DST_PSI_SECTGATHER_H_*/ |
|---|
| 327 | |
|---|
| 328 | |
|---|