| 1 | /***************************************************************************** |
|---|
| 2 | *_Copyright (c) 2004 DST Technologies Inc. All Rights Reserved. |
|---|
| 3 | * |
|---|
| 4 | * file name: dstddPsiProcess.c |
|---|
| 5 | * |
|---|
| 6 | * Description: Platform-Specific PID/Section Filter Management |
|---|
| 7 | * |
|---|
| 8 | *****************************************************************************/ |
|---|
| 9 | |
|---|
| 10 | #include <stdarg.h> |
|---|
| 11 | #include <stdio.h> |
|---|
| 12 | #include <stdlib.h> |
|---|
| 13 | #include <string.h> |
|---|
| 14 | #include <unistd.h> |
|---|
| 15 | |
|---|
| 16 | #include "dsthalcommon.h" |
|---|
| 17 | #include "dsthalPsiAtscPsip.h" |
|---|
| 18 | #include "dsthalPsiMpegSi.h" |
|---|
| 19 | #include "dstdddmx.h" |
|---|
| 20 | |
|---|
| 21 | /* |
|---|
| 22 | * Driver Includes. |
|---|
| 23 | */ |
|---|
| 24 | #include "pd_dmx.h" |
|---|
| 25 | |
|---|
| 26 | #ifdef DMALLOC |
|---|
| 27 | #include <dmalloc.h> |
|---|
| 28 | #endif |
|---|
| 29 | |
|---|
| 30 | int gddPsiDbgLvl = 2; |
|---|
| 31 | |
|---|
| 32 | #if 0 |
|---|
| 33 | ___Definitions_______________() |
|---|
| 34 | #endif |
|---|
| 35 | |
|---|
| 36 | #if 1 |
|---|
| 37 | #define PRINT_PREF_FILTER(pref) do { int i; printf("Filter/Mask\n"); \ |
|---|
| 38 | for (i=0; i<((pref)->numEntries); i++) { \ |
|---|
| 39 | if ( i==(((pref)->numEntries)-1) ) \ |
|---|
| 40 | printf("%02X\n", (pref)->entries[i].value);\ |
|---|
| 41 | else \ |
|---|
| 42 | printf("%02X-", (pref)->entries[i].value);\ |
|---|
| 43 | } \ |
|---|
| 44 | for (i=0; i<((pref)->numEntries); i++) { \ |
|---|
| 45 | if ( i==(((pref)->numEntries)-1) ) \ |
|---|
| 46 | printf("%02X\n", (pref)->entries[i].matchMask);\ |
|---|
| 47 | else \ |
|---|
| 48 | printf( "%02X-", (pref)->entries[i].matchMask);\ |
|---|
| 49 | } \ |
|---|
| 50 | } while(0) |
|---|
| 51 | |
|---|
| 52 | #define PRINT_FILTER(byte,size) do { int i; DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "Filter-%d(%d): ", pSectCtl->iSelfIndex, __LINE__); \ |
|---|
| 53 | for (i=0; i<(size); i++) { \ |
|---|
| 54 | if ( i==((size)-1) ) \ |
|---|
| 55 | printf("%02X\n", (byte)[i]);\ |
|---|
| 56 | else \ |
|---|
| 57 | printf("%02X-", (byte)[i]); \ |
|---|
| 58 | } \ |
|---|
| 59 | } while(0) |
|---|
| 60 | |
|---|
| 61 | #define PRINT_MASK(byte,size) do { int i; DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "Mask (%d): ", __LINE__); \ |
|---|
| 62 | for (i=0; i<(size); i++) { \ |
|---|
| 63 | if ( i==((size)-1) ) \ |
|---|
| 64 | printf("%02X\n", (byte)[i]);\ |
|---|
| 65 | else \ |
|---|
| 66 | printf( "%02X-", (byte)[i]); \ |
|---|
| 67 | } \ |
|---|
| 68 | } while(0) |
|---|
| 69 | #else |
|---|
| 70 | #define PRINT_FILTER(byte,size) |
|---|
| 71 | #define PRINT_MASK(byte,size) |
|---|
| 72 | #endif |
|---|
| 73 | |
|---|
| 74 | //========================================================================================= |
|---|
| 75 | // Configuration Definitions |
|---|
| 76 | //========================================================================================= |
|---|
| 77 | #if (BOG_SW_VERSION>=0x0031A000) |
|---|
| 78 | #define NEW_API // Demux API º¯°æ °ü·Ã. |
|---|
| 79 | #endif |
|---|
| 80 | |
|---|
| 81 | //========================================================================================= |
|---|
| 82 | // PID/Section Filter Size |
|---|
| 83 | //========================================================================================= |
|---|
| 84 | #define SECTION_FILTER_SIZE 16 // ½ÇÁ¦·Î´Â Á¦ÇÑÀÌ ÀÖÀ¸³ª 16À¸·Î »ç¿ë. |
|---|
| 85 | |
|---|
| 86 | #define MAX_PID_FILTER_CNT 64 // ÃÖ´ë 64°³. |
|---|
| 87 | #define MAX_SECTION_FILTER_CNT 64 // ÃÖ´ë 256°³À̳ª, PID Filter Cnt¿¡ Á¾¼ÓÀûÀ̱⿡ 64°³. |
|---|
| 88 | |
|---|
| 89 | //========================================================================================= |
|---|
| 90 | // Local Definitions |
|---|
| 91 | //========================================================================================= |
|---|
| 92 | #define USE_ONESHOT 0 |
|---|
| 93 | #define MAX_PSI_EVENT 4 // PSI Callback Events |
|---|
| 94 | typedef enum tag_PSI_EVENT_t { |
|---|
| 95 | PSI_EVENT__RCVD_NO_ERROR=0x01, |
|---|
| 96 | PSI_EVENT__RCVD_OVERFLOW=0x02, |
|---|
| 97 | } PSI_EVENT_t; |
|---|
| 98 | |
|---|
| 99 | #define MSG_STOP (0xDEADBEEF) // PSI Monitor Stop Message |
|---|
| 100 | |
|---|
| 101 | int g_FilterCount_4Kb = 0; |
|---|
| 102 | int g_FilterCount_1Kb = 0; |
|---|
| 103 | int g_Demux_Debug = 0; |
|---|
| 104 | |
|---|
| 105 | int g_Temp_Debug = 0; |
|---|
| 106 | |
|---|
| 107 | |
|---|
| 108 | int g_TotalLeakSize = 0; |
|---|
| 109 | int g_TotalLeakCnt = 0; |
|---|
| 110 | |
|---|
| 111 | // |
|---|
| 112 | // Filter State |
|---|
| 113 | // |
|---|
| 114 | typedef enum{ |
|---|
| 115 | PCS_RAW = 0x00, |
|---|
| 116 | PCS_INIT = 0x01, |
|---|
| 117 | PCS_RUNNING = 0x03 |
|---|
| 118 | } PSI_CTL_State_e; |
|---|
| 119 | |
|---|
| 120 | // |
|---|
| 121 | // Structure for managing PID Filter |
|---|
| 122 | // |
|---|
| 123 | typedef struct PSI_PID_CTL_t { |
|---|
| 124 | int nRefCount; |
|---|
| 125 | int nRefCountRunning; |
|---|
| 126 | PSI_CTL_State_e eState; /* two state : PCS_INIT , PCS_RAW. */ |
|---|
| 127 | unsigned int uiPid; |
|---|
| 128 | |
|---|
| 129 | } PSI_PID_CTL_t; |
|---|
| 130 | |
|---|
| 131 | // |
|---|
| 132 | // Structure for managing Section Filter |
|---|
| 133 | // |
|---|
| 134 | typedef void (*PSI_CB_FUNC_t)( PSI_EVENT_t Event, DS_U32 Arg, DS_U8 *pBuf, DS_U32 Len ); |
|---|
| 135 | |
|---|
| 136 | typedef struct PSI_SECTION_CTL_t |
|---|
| 137 | { |
|---|
| 138 | unsigned char iSelfIndex; |
|---|
| 139 | struct PSI_INFRA_CTL_t *pParent; |
|---|
| 140 | int iPidCtlIndex; |
|---|
| 141 | DS_U32 Pid; |
|---|
| 142 | |
|---|
| 143 | OS_SEMAPHORE_ID hSectionSema4; |
|---|
| 144 | PSI_CTL_State_e eState; /*three state : PCS_RAW , PCS_INIT , PCS_RUNNING. */ |
|---|
| 145 | PSIContext_t *pContext; /*user request°¡ ÀÖÀ» ¶§¸¸ µ¿ÀûÀ¸·Î »ý¼º,Á¦°Å.*/ |
|---|
| 146 | |
|---|
| 147 | DS_U8 filterBytes[SECTION_FILTER_SIZE]; |
|---|
| 148 | DS_U8 filterMasks[SECTION_FILTER_SIZE]; |
|---|
| 149 | DS_U8 filterInvert[SECTION_FILTER_SIZE]; |
|---|
| 150 | DS_U32 filtCount; |
|---|
| 151 | |
|---|
| 152 | DS_U8 nLockCount; |
|---|
| 153 | DS_U32 iCurLockedTask; |
|---|
| 154 | |
|---|
| 155 | OS_TASK_ID taskId; |
|---|
| 156 | DS_U8 isMonitorStarted; |
|---|
| 157 | DS_U8 isMonitorError; |
|---|
| 158 | |
|---|
| 159 | PD_SECFILTER *pDrvSecFilter; |
|---|
| 160 | |
|---|
| 161 | DS_U8 Matched; |
|---|
| 162 | } PSI_SECTION_CTL_t; |
|---|
| 163 | |
|---|
| 164 | typedef struct PSI_LIST_ELEM_t |
|---|
| 165 | { |
|---|
| 166 | struct PSI_LIST_ELEM_t *pPrev; |
|---|
| 167 | struct PSI_LIST_ELEM_t *pNext; |
|---|
| 168 | }PSI_LIST_ELEM_t; |
|---|
| 169 | |
|---|
| 170 | typedef struct PSI_LIST_HEADER_t |
|---|
| 171 | { |
|---|
| 172 | int nCount; |
|---|
| 173 | PSI_LIST_ELEM_t *pElem; |
|---|
| 174 | OS_SEMAPHORE_ID hAccessSema4; |
|---|
| 175 | |
|---|
| 176 | }PSI_LIST_HEADER_t; |
|---|
| 177 | |
|---|
| 178 | |
|---|
| 179 | /*the base structure for PSI resources*/ |
|---|
| 180 | typedef struct PSI_INFRA_CTL_t |
|---|
| 181 | { |
|---|
| 182 | PSI_PID_CTL_t aPidCtl[MAX_PID_FILTER_CNT]; |
|---|
| 183 | OS_SEMAPHORE_ID hPidCtlAccessSema4; |
|---|
| 184 | |
|---|
| 185 | PSI_LIST_HEADER_t lhSectCtl; /*section ctl list¸¦ À§ÇÑ header.*/ |
|---|
| 186 | |
|---|
| 187 | DS_BOOL aSectCtlUsedList[MAX_SECTION_FILTER_CNT]; |
|---|
| 188 | PSI_SECTION_CTL_t aSectCtl[MAX_SECTION_FILTER_CNT]; |
|---|
| 189 | OS_SEMAPHORE_ID hSectCtlAccessSema4; |
|---|
| 190 | }PSI_INFRA_CTL_t; |
|---|
| 191 | |
|---|
| 192 | #if 0 |
|---|
| 193 | ___Local_Variables_______________() |
|---|
| 194 | #endif |
|---|
| 195 | static void DD_PSI_DeleteAllSectCtls( PSI_INFRA_CTL_t *pPsiInfra ); |
|---|
| 196 | static void DD_PSI_ReleaseAllPidCtls( PSI_INFRA_CTL_t *pPsiInfra ); |
|---|
| 197 | static void cbReceiveSection(PD_SECFILTER *psec, DS_U8 *pSecData, int Size); |
|---|
| 198 | |
|---|
| 199 | DHL_RESULT DD_PSI_StartPidCtl ( PSI_INFRA_CTL_t *pPsiInfra, int iPidCtlIndex ); |
|---|
| 200 | DHL_RESULT DD_PSI_StopPidCtl ( PSI_INFRA_CTL_t *pPsiInfra , int iPidCtlIndex ); |
|---|
| 201 | DHL_RESULT DD_PSI_GetPidCtl( PSI_INFRA_CTL_t *pPsiInfra , unsigned int pid, int *iPidCtlIndex ); |
|---|
| 202 | DHL_RESULT DD_PSI_LockPidCtlArray ( PSI_INFRA_CTL_t *pPsiInfra , int timeOut ); |
|---|
| 203 | DHL_RESULT DD_PSI_UnlockPidCtlArray ( PSI_INFRA_CTL_t *pPsiInfra ); |
|---|
| 204 | DHL_RESULT DD_PSI_ReleasePidCtl ( PSI_INFRA_CTL_t *pPsiInfra , int iPidCtlIndex ); |
|---|
| 205 | |
|---|
| 206 | PSI_SECTION_CTL_t* DD_PSI_GetSectCtlFromArray( PSI_INFRA_CTL_t *pPsiInfra ); |
|---|
| 207 | void DD_PSI_ReleaseSectCtlFromArray( PSI_INFRA_CTL_t *pPsiInfra, int iSectIndex ); |
|---|
| 208 | void DD_PSI_ReleaseSectionCtl ( PSI_SECTION_CTL_t *pSectCtl ); |
|---|
| 209 | DS_BOOL DD_PSI_ExistSectionFilter( void *pPsiInfo, DS_U16 pid, PSI_SECTION_CTL_t *pCtrlToFind, PSI_SECTION_CTL_t **returnSectCtl ); |
|---|
| 210 | void DD_PSI_ResetSectionCtl( PSI_SECTION_CTL_t *pSectCtl , int iSelfIndex ); |
|---|
| 211 | |
|---|
| 212 | #if 0 |
|---|
| 213 | ___Common_APIs___________________() |
|---|
| 214 | #endif |
|---|
| 215 | static PSI_INFRA_CTL_t *g_pPsiInfra; |
|---|
| 216 | DHL_RESULT DD_PSI_Init( void **arg4 /*returned psi handle*/ ) |
|---|
| 217 | { |
|---|
| 218 | int i = 0; |
|---|
| 219 | |
|---|
| 220 | PSI_INFRA_CTL_t *pPsiInfra = (PSI_INFRA_CTL_t *)PSI_Malloc( sizeof(PSI_INFRA_CTL_t) ); |
|---|
| 221 | |
|---|
| 222 | if( pPsiInfra == NULL ) |
|---|
| 223 | return DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 224 | |
|---|
| 225 | memset( pPsiInfra , 0 , sizeof(PSI_INFRA_CTL_t) ); |
|---|
| 226 | |
|---|
| 227 | pPsiInfra->hPidCtlAccessSema4 = OS_CreateCountingSemaphore( "pidSema4", 0, 1 ); |
|---|
| 228 | pPsiInfra->hSectCtlAccessSema4 = OS_CreateCountingSemaphore( "sectSema4", 0, 1 ); |
|---|
| 229 | |
|---|
| 230 | for ( i = 0 ; i < MAX_SECTION_FILTER_CNT ; i++ ) { |
|---|
| 231 | DD_PSI_ResetSectionCtl(&(pPsiInfra->aSectCtl[i]) , i ); |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | PD_DMX_SetSectionFilterCallback( cbReceiveSection, 0 ); |
|---|
| 235 | |
|---|
| 236 | g_pPsiInfra = pPsiInfra; |
|---|
| 237 | *arg4 = (void *)pPsiInfra; |
|---|
| 238 | return DHL_OK; |
|---|
| 239 | } |
|---|
| 240 | |
|---|
| 241 | DHL_RESULT DD_PSI_Close( void *pPsiHandle ) |
|---|
| 242 | { |
|---|
| 243 | PSI_INFRA_CTL_t *pPsiInfra = (PSI_INFRA_CTL_t *)pPsiHandle; |
|---|
| 244 | |
|---|
| 245 | if( !pPsiInfra ) |
|---|
| 246 | return DHL_FAIL_NULL_POINTER; |
|---|
| 247 | |
|---|
| 248 | DD_PSI_DeleteAllSectCtls( pPsiHandle); |
|---|
| 249 | |
|---|
| 250 | /*for exception cases.*/ |
|---|
| 251 | DD_PSI_ReleaseAllPidCtls( pPsiInfra ); |
|---|
| 252 | |
|---|
| 253 | if(pPsiInfra->hPidCtlAccessSema4) |
|---|
| 254 | OS_DeleteSemaphore( pPsiInfra->hPidCtlAccessSema4 ); |
|---|
| 255 | pPsiInfra->hPidCtlAccessSema4 = 0; |
|---|
| 256 | |
|---|
| 257 | if(pPsiInfra->hSectCtlAccessSema4) |
|---|
| 258 | OS_DeleteSemaphore( pPsiInfra->hSectCtlAccessSema4); |
|---|
| 259 | pPsiInfra->hSectCtlAccessSema4 = 0; |
|---|
| 260 | |
|---|
| 261 | PSI_Free(pPsiInfra); |
|---|
| 262 | |
|---|
| 263 | return DHL_OK; |
|---|
| 264 | } |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | |
|---|
| 268 | #if 0 |
|---|
| 269 | ___Section_Filter_API____________() |
|---|
| 270 | #endif |
|---|
| 271 | DHL_RESULT DD_PSI_CreateAndSetFilter( PSI_SECTION_CTL_t *pSectCtl, |
|---|
| 272 | DS_U32 Pid, |
|---|
| 273 | DS_U8 *pFilterBytes, |
|---|
| 274 | DS_U8 *pFilterMask, |
|---|
| 275 | DS_U8 *pFilterInvert, |
|---|
| 276 | DS_U32 filtSize ) |
|---|
| 277 | { |
|---|
| 278 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 279 | PSIContext_t *pPsiContext = pSectCtl->pContext; |
|---|
| 280 | |
|---|
| 281 | // |
|---|
| 282 | // Set Filter Settings. |
|---|
| 283 | // |
|---|
| 284 | pSectCtl->Pid = Pid; |
|---|
| 285 | pSectCtl->Matched = 0; |
|---|
| 286 | |
|---|
| 287 | //DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "|%d-0x%x| [%d]\n", __LINE__, (unsigned int)pSectCtl, (int)OS_GetTickCount() ); |
|---|
| 288 | // |
|---|
| 289 | // Init PSI Monitor Thread. |
|---|
| 290 | // |
|---|
| 291 | pSectCtl->isMonitorStarted = 0; |
|---|
| 292 | pSectCtl->isMonitorError = 0; |
|---|
| 293 | |
|---|
| 294 | if ( pSectCtl->isMonitorError ) |
|---|
| 295 | dhlResult = DHL_FAIL; |
|---|
| 296 | |
|---|
| 297 | if ( g_Demux_Debug ) |
|---|
| 298 | { |
|---|
| 299 | DHL_DbgPrintf(0,DDDBG_AV, "++ [4k:%d, 1k:%d] PID = 0x%x [%s]\n", |
|---|
| 300 | g_FilterCount_4Kb, |
|---|
| 301 | g_FilterCount_1Kb, |
|---|
| 302 | (unsigned int)pSectCtl->Pid, |
|---|
| 303 | pPsiContext->oneShot ? "OneShot" : "Conti" ); |
|---|
| 304 | |
|---|
| 305 | PRINT_FILTER( pSectCtl->filterBytes, pSectCtl->filtCount); |
|---|
| 306 | PRINT_MASK( pSectCtl->filterMasks, pSectCtl->filtCount); |
|---|
| 307 | } |
|---|
| 308 | |
|---|
| 309 | pSectCtl->pDrvSecFilter = PD_DMX_CreateSectionFilter( Pid, pFilterBytes, pFilterMask, (int)filtSize, 1024, 0 ); |
|---|
| 310 | if ( pSectCtl->pDrvSecFilter == (PD_SECFILTER *)NULL ) |
|---|
| 311 | printf("|%s:%d| ERROR.\n", __FUNCTION__, __LINE__); |
|---|
| 312 | |
|---|
| 313 | /* |
|---|
| 314 | * Just to avoid WARNING message. |
|---|
| 315 | */ |
|---|
| 316 | pPsiContext = pPsiContext; |
|---|
| 317 | |
|---|
| 318 | return dhlResult; |
|---|
| 319 | } |
|---|
| 320 | |
|---|
| 321 | DHL_RESULT DD_PSI_StopAndDeleteFilter( PSI_SECTION_CTL_t *pSectCtl ) |
|---|
| 322 | { |
|---|
| 323 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 324 | PSIContext_t *pPsiContext = pSectCtl->pContext; |
|---|
| 325 | int retVal = PD_DMX_SUCCESS; |
|---|
| 326 | |
|---|
| 327 | if ( g_Demux_Debug ) |
|---|
| 328 | { |
|---|
| 329 | DHL_DbgPrintf(0,DDDBG_AV, "-- [4k:%d, 1k:%d] PID = 0x%x [%s]\n", |
|---|
| 330 | g_FilterCount_4Kb, |
|---|
| 331 | g_FilterCount_1Kb, |
|---|
| 332 | (unsigned int)pSectCtl->Pid, |
|---|
| 333 | pPsiContext->oneShot ? "OneShot" : "Conti" ); |
|---|
| 334 | |
|---|
| 335 | PRINT_FILTER( pSectCtl->filterBytes, pSectCtl->filtCount); |
|---|
| 336 | PRINT_MASK( pSectCtl->filterMasks, pSectCtl->filtCount); |
|---|
| 337 | } |
|---|
| 338 | |
|---|
| 339 | retVal = PD_DMX_DeleteSectionFilter( pSectCtl->pDrvSecFilter ); |
|---|
| 340 | SysASSERT( PD_DMX_OK(retVal) ); |
|---|
| 341 | |
|---|
| 342 | return dhlResult; |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | #if 0 |
|---|
| 346 | ___Section_Control_API__________() |
|---|
| 347 | #endif |
|---|
| 348 | DHL_RESULT DD_PSI_InitSectionCtl( PSI_SECTION_CTL_t *pSectionCtl ) |
|---|
| 349 | { |
|---|
| 350 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 351 | |
|---|
| 352 | if( !pSectionCtl ) |
|---|
| 353 | return DHL_FAIL_NULL_POINTER; |
|---|
| 354 | |
|---|
| 355 | if( !pSectionCtl->hSectionSema4 ) { |
|---|
| 356 | pSectionCtl->hSectionSema4 = OS_CreateCountingSemaphore( "PSISema4", 0, 1 ); |
|---|
| 357 | } |
|---|
| 358 | if( !pSectionCtl->hSectionSema4) |
|---|
| 359 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_InitSectionCtl : OS_CreateCountingSemaphore fail.\n"); |
|---|
| 360 | |
|---|
| 361 | //pSectionCtl->taskId = (gmtCL_ThreadID)-1; |
|---|
| 362 | |
|---|
| 363 | return dhlResult; |
|---|
| 364 | } |
|---|
| 365 | |
|---|
| 366 | DHL_RESULT DD_PSI_InitSectionCtlBig( PSI_SECTION_CTL_t *pSectionCtl ) |
|---|
| 367 | { |
|---|
| 368 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 369 | |
|---|
| 370 | if( !pSectionCtl ) |
|---|
| 371 | return DHL_FAIL_NULL_POINTER; |
|---|
| 372 | |
|---|
| 373 | if( !pSectionCtl->hSectionSema4 ) |
|---|
| 374 | pSectionCtl->hSectionSema4 = OS_CreateCountingSemaphore( "psiSecSema4", 0, 1 ); |
|---|
| 375 | |
|---|
| 376 | if( !pSectionCtl->hSectionSema4) |
|---|
| 377 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_InitSectionCtlBig : OS_CreateCountingSemaphore fail.\n"); |
|---|
| 378 | |
|---|
| 379 | return dhlResult; |
|---|
| 380 | } |
|---|
| 381 | |
|---|
| 382 | DHL_RESULT DD_PSI_OpenSectionCtl( PSI_INFRA_CTL_t *pPsiInfra, |
|---|
| 383 | PSI_SECTION_CTL_t *pSectionCtl , |
|---|
| 384 | DS_U32 uPidCtlIndex, |
|---|
| 385 | DS_U32 uSectionFilterName, |
|---|
| 386 | DS_U32 uSIName) |
|---|
| 387 | { |
|---|
| 388 | |
|---|
| 389 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 390 | |
|---|
| 391 | if(!pPsiInfra) |
|---|
| 392 | return DHL_FAIL_NULL_POINTER; |
|---|
| 393 | |
|---|
| 394 | if(!pSectionCtl) |
|---|
| 395 | return DHL_FAIL_NULL_POINTER; |
|---|
| 396 | |
|---|
| 397 | /*1.set a PID-Ctl Index==============================*/ |
|---|
| 398 | pSectionCtl->iPidCtlIndex = uPidCtlIndex; |
|---|
| 399 | |
|---|
| 400 | /*2.Open a Section Filter===============================*/ |
|---|
| 401 | |
|---|
| 402 | /*3.Open a Streaming Interface ========================*/ |
|---|
| 403 | |
|---|
| 404 | return(dhlResult); |
|---|
| 405 | } |
|---|
| 406 | |
|---|
| 407 | DHL_RESULT DD_PSI_StartSectionCtl( PSI_SECTION_CTL_t * pSectionCtl , |
|---|
| 408 | PSIMask_t *prefList ) |
|---|
| 409 | { |
|---|
| 410 | int i , j; |
|---|
| 411 | int maxCnt = 0; |
|---|
| 412 | DHL_RESULT dhlResult; |
|---|
| 413 | PSI_INFRA_CTL_t *pPsiInfra = NULL; |
|---|
| 414 | PSI_PID_CTL_t *pPidCtl = NULL; |
|---|
| 415 | |
|---|
| 416 | if( !pSectionCtl ) |
|---|
| 417 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 418 | |
|---|
| 419 | pPsiInfra = (PSI_INFRA_CTL_t *)pSectionCtl->pParent; |
|---|
| 420 | pPidCtl = &(pPsiInfra->aPidCtl[pSectionCtl->iPidCtlIndex]); |
|---|
| 421 | |
|---|
| 422 | /*first, check the current state.*/ |
|---|
| 423 | if( !(pSectionCtl->eState == PCS_INIT) ) |
|---|
| 424 | { |
|---|
| 425 | dhlResult = DHL_FAIL_INVALID_PARAM; |
|---|
| 426 | goto GOOUT; |
|---|
| 427 | } |
|---|
| 428 | |
|---|
| 429 | |
|---|
| 430 | /*third, set the hardware pid , section filtering parameters & start si.*/ |
|---|
| 431 | /* notification setting */ |
|---|
| 432 | |
|---|
| 433 | if( prefList->numEntries > SECTION_FILTER_SIZE ) |
|---|
| 434 | maxCnt = SECTION_FILTER_SIZE; |
|---|
| 435 | else |
|---|
| 436 | maxCnt = prefList->numEntries; |
|---|
| 437 | |
|---|
| 438 | for ( i = 0 , j = 0 ; i < maxCnt ; ++i ) |
|---|
| 439 | { |
|---|
| 440 | #if USE_FILTER1 |
|---|
| 441 | if ( i == 2 || i == 7 ) /*index°¡ 2,7ÀÎ byte´Â ¹«½Ã.*/ |
|---|
| 442 | continue; |
|---|
| 443 | #endif // #if USE_FILTER1 |
|---|
| 444 | |
|---|
| 445 | pSectionCtl->filterBytes [j] = prefList->entries[i].value; |
|---|
| 446 | pSectionCtl->filterMasks [j] = prefList->entries[i].matchMask; |
|---|
| 447 | pSectionCtl->filterInvert[j] = prefList->entries[i].noMatchMask; |
|---|
| 448 | |
|---|
| 449 | ++j; |
|---|
| 450 | } |
|---|
| 451 | |
|---|
| 452 | maxCnt = j; |
|---|
| 453 | pSectionCtl->filtCount = maxCnt; |
|---|
| 454 | |
|---|
| 455 | #if DEBUG |
|---|
| 456 | { |
|---|
| 457 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "\r\nFILTER_BYTE :"); |
|---|
| 458 | for( i = 0 ; i < maxCnt ; i++ ) |
|---|
| 459 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, " 0x%x" , pSectionCtl->filterBytes [i]); |
|---|
| 460 | |
|---|
| 461 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "\r\nFILTER_MASK :"); |
|---|
| 462 | for( i = 0 ; i < maxCnt ; i++ ) |
|---|
| 463 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, " 0x%x" , pSectionCtl->filterMasks [i]); |
|---|
| 464 | |
|---|
| 465 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "\r\nFILTER_INVERT :"); |
|---|
| 466 | for( i = 0 ; i < maxCnt ; i++ ) |
|---|
| 467 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, " 0x%x" , pSectionCtl->filterInvert[i]); |
|---|
| 468 | |
|---|
| 469 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "\r\nFILTER_COUNT : %ld\r\n", pSectionCtl->filtCount); |
|---|
| 470 | } |
|---|
| 471 | #endif |
|---|
| 472 | |
|---|
| 473 | dhlResult = DD_PSI_CreateAndSetFilter( pSectionCtl, |
|---|
| 474 | pPidCtl->uiPid, |
|---|
| 475 | pSectionCtl->filterBytes, |
|---|
| 476 | pSectionCtl->filterMasks, |
|---|
| 477 | pSectionCtl->filterInvert, |
|---|
| 478 | pSectionCtl->filtCount ); |
|---|
| 479 | if (DHL_ERROR(dhlResult)) { |
|---|
| 480 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 481 | goto GOOUT; |
|---|
| 482 | } |
|---|
| 483 | pSectionCtl->eState = PCS_RUNNING; |
|---|
| 484 | |
|---|
| 485 | dhlResult = DD_PSI_StartPidCtl ( pPsiInfra , pSectionCtl->iPidCtlIndex ); |
|---|
| 486 | if ( dhlResult != DHL_OK ) { |
|---|
| 487 | pSectionCtl->eState = PCS_INIT; |
|---|
| 488 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | GOOUT: |
|---|
| 492 | return dhlResult; |
|---|
| 493 | } |
|---|
| 494 | |
|---|
| 495 | DHL_RESULT DD_PSI_StopSectionCtl( PSI_SECTION_CTL_t *pSectionCtl ) |
|---|
| 496 | { |
|---|
| 497 | DHL_RESULT dhlResult; |
|---|
| 498 | PSI_INFRA_CTL_t *pPsiInfra = NULL; |
|---|
| 499 | |
|---|
| 500 | if (!pSectionCtl) { |
|---|
| 501 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "NULL SectionCtl.\r\n"); |
|---|
| 502 | return DHL_FAIL_NULL_POINTER; |
|---|
| 503 | } |
|---|
| 504 | |
|---|
| 505 | pPsiInfra = (PSI_INFRA_CTL_t *)pSectionCtl->pParent; |
|---|
| 506 | |
|---|
| 507 | if (pSectionCtl->eState != PCS_RUNNING) { |
|---|
| 508 | #if DEBUG |
|---|
| 509 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "It is not started. skipped.\r\n"); |
|---|
| 510 | #endif |
|---|
| 511 | |
|---|
| 512 | return DHL_OK; |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | /*3.stop pid filter.**********************************************/ |
|---|
| 516 | dhlResult = DD_PSI_StopPidCtl ( pPsiInfra , pSectionCtl->iPidCtlIndex ); |
|---|
| 517 | if ( dhlResult != DHL_OK ) |
|---|
| 518 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 519 | /******************************************************************/ |
|---|
| 520 | |
|---|
| 521 | /*4.Stop SI component**********************************************/ |
|---|
| 522 | /******************************************************************/ |
|---|
| 523 | if ( PD_DMX_SUCCESS != PD_DMX_EnableSectionFilter( pSectionCtl->pDrvSecFilter, 0 ) ) |
|---|
| 524 | DHL_DbgPrintf(0, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 525 | |
|---|
| 526 | /*5. back to the init state.*/ |
|---|
| 527 | pSectionCtl->eState = PCS_INIT; |
|---|
| 528 | |
|---|
| 529 | return dhlResult; |
|---|
| 530 | } |
|---|
| 531 | |
|---|
| 532 | DHL_RESULT DD_PSI_GetSectionCtl( PSI_INFRA_CTL_t *pPsiInfra , DS_U16 pid , PSIMask_t *prefList, PSI_SECTION_CTL_t **retSectCtlPtr ) |
|---|
| 533 | { |
|---|
| 534 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 535 | PSI_SECTION_CTL_t *pSectionCtl = NULL; |
|---|
| 536 | int iPidCtlIndex = 0; |
|---|
| 537 | DS_BOOL bExist = _FALSE_; |
|---|
| 538 | DS_U16 tableId = 0; |
|---|
| 539 | *retSectCtlPtr = NULL; |
|---|
| 540 | |
|---|
| 541 | if( !pPsiInfra || !prefList || !retSectCtlPtr ) |
|---|
| 542 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 543 | |
|---|
| 544 | tableId = prefList->entries[0].value; /*tableId*/ |
|---|
| 545 | bExist = DD_PSI_ExistSectionCtl( pPsiInfra, pid, prefList ); |
|---|
| 546 | if( bExist == _TRUE_ ) |
|---|
| 547 | { |
|---|
| 548 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPid : it's already exist filter. so, reject your request. \r\n"); |
|---|
| 549 | PRINT_PREF_FILTER( prefList ); |
|---|
| 550 | return DHL_FAIL_NOT_AVAILABLE; |
|---|
| 551 | } |
|---|
| 552 | |
|---|
| 553 | dhlResult = DD_PSI_GetPidCtl( pPsiInfra ,pid, &iPidCtlIndex ); |
|---|
| 554 | if( dhlResult != DHL_OK ) |
|---|
| 555 | return dhlResult; |
|---|
| 556 | |
|---|
| 557 | pSectionCtl = DD_PSI_GetSectCtlFromArray( pPsiInfra ); |
|---|
| 558 | if( !pSectionCtl ) |
|---|
| 559 | { |
|---|
| 560 | DD_PSI_ReleasePidCtl ( pPsiInfra , iPidCtlIndex ); |
|---|
| 561 | return dhlResult; |
|---|
| 562 | } |
|---|
| 563 | |
|---|
| 564 | dhlResult = DD_PSI_OpenSectionCtl( pPsiInfra, |
|---|
| 565 | pSectionCtl , |
|---|
| 566 | iPidCtlIndex, |
|---|
| 567 | 0, |
|---|
| 568 | 0); |
|---|
| 569 | if( dhlResult != DHL_OK ) |
|---|
| 570 | { |
|---|
| 571 | DD_PSI_ReleaseSectCtlFromArray( pPsiInfra , pSectionCtl->iSelfIndex ); |
|---|
| 572 | return dhlResult; |
|---|
| 573 | } |
|---|
| 574 | |
|---|
| 575 | dhlResult = DD_PSI_InitSectionCtl( pSectionCtl ); |
|---|
| 576 | if( dhlResult != DHL_OK ) |
|---|
| 577 | { |
|---|
| 578 | DD_PSI_ReleaseSectionCtl(pSectionCtl); |
|---|
| 579 | //DD_PSI_FreeSectoinCtl( pSectionCtl ); |
|---|
| 580 | *retSectCtlPtr = NULL; |
|---|
| 581 | pSectionCtl = NULL; |
|---|
| 582 | } |
|---|
| 583 | |
|---|
| 584 | pSectionCtl->eState = PCS_INIT; |
|---|
| 585 | *retSectCtlPtr = pSectionCtl; |
|---|
| 586 | |
|---|
| 587 | return dhlResult; |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | DHL_RESULT DD_PSI_GetSectionCtlBig( PSI_INFRA_CTL_t *pPsiInfra , DS_U16 pid , PSIMask_t *prefList, PSI_SECTION_CTL_t **retSectCtlPtr ) |
|---|
| 591 | { |
|---|
| 592 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 593 | PSI_SECTION_CTL_t *pSectionCtl = NULL; |
|---|
| 594 | int iPidCtlIndex = 0; |
|---|
| 595 | DS_BOOL bExist = _FALSE_; |
|---|
| 596 | DS_U16 tableId = 0; |
|---|
| 597 | *retSectCtlPtr = NULL; |
|---|
| 598 | |
|---|
| 599 | if( !pPsiInfra || !prefList || !retSectCtlPtr ) |
|---|
| 600 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 601 | |
|---|
| 602 | tableId = prefList->entries[0].value; /*tableId*/ |
|---|
| 603 | |
|---|
| 604 | bExist = DD_PSI_ExistSectionCtl( pPsiInfra, pid, prefList ); |
|---|
| 605 | if( bExist == _TRUE_ ) |
|---|
| 606 | { |
|---|
| 607 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_GetSectionCtlBig : it's already exist filter. so, reject your request. \r\n"); |
|---|
| 608 | return DHL_FAIL_NOT_AVAILABLE; |
|---|
| 609 | } |
|---|
| 610 | |
|---|
| 611 | dhlResult = DD_PSI_GetPidCtl( pPsiInfra ,pid, &iPidCtlIndex ); |
|---|
| 612 | |
|---|
| 613 | if( dhlResult != DHL_OK ) |
|---|
| 614 | return dhlResult; |
|---|
| 615 | |
|---|
| 616 | #if DEBUG |
|---|
| 617 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_GetSectionCtlBig : iPidCtlIndex = %d , state = %d \r\n" , iPidCtlIndex , pPsiInfra->aPidCtl[iPidCtlIndex].eState ); |
|---|
| 618 | #endif |
|---|
| 619 | |
|---|
| 620 | pSectionCtl = DD_PSI_GetSectCtlFromArray( pPsiInfra ); |
|---|
| 621 | if( !pSectionCtl ) |
|---|
| 622 | { |
|---|
| 623 | DD_PSI_ReleasePidCtl ( pPsiInfra , iPidCtlIndex ); |
|---|
| 624 | return dhlResult; |
|---|
| 625 | } |
|---|
| 626 | |
|---|
| 627 | dhlResult = DD_PSI_OpenSectionCtl( pPsiInfra, |
|---|
| 628 | pSectionCtl , |
|---|
| 629 | iPidCtlIndex, |
|---|
| 630 | 0, |
|---|
| 631 | 0); |
|---|
| 632 | if( dhlResult != DHL_OK ) |
|---|
| 633 | { |
|---|
| 634 | DD_PSI_ReleaseSectCtlFromArray( pPsiInfra , pSectionCtl->iSelfIndex ); |
|---|
| 635 | return dhlResult; |
|---|
| 636 | } |
|---|
| 637 | |
|---|
| 638 | dhlResult = DD_PSI_InitSectionCtlBig( pSectionCtl ); |
|---|
| 639 | if( dhlResult != DHL_OK ) |
|---|
| 640 | { |
|---|
| 641 | DD_PSI_ReleaseSectionCtl(pSectionCtl); |
|---|
| 642 | //DD_PSI_FreeSectoinCtl( pSectionCtl ); |
|---|
| 643 | *retSectCtlPtr = NULL; |
|---|
| 644 | pSectionCtl = NULL; |
|---|
| 645 | } |
|---|
| 646 | |
|---|
| 647 | pSectionCtl->eState = PCS_INIT; |
|---|
| 648 | *retSectCtlPtr = pSectionCtl; |
|---|
| 649 | |
|---|
| 650 | return dhlResult; |
|---|
| 651 | } |
|---|
| 652 | |
|---|
| 653 | void DD_PSI_FreeSectionCtl ( PSI_SECTION_CTL_t *pSectCtl ) |
|---|
| 654 | { |
|---|
| 655 | if( !pSectCtl ) |
|---|
| 656 | return; |
|---|
| 657 | |
|---|
| 658 | /*If exists, delete sema4.*/ |
|---|
| 659 | if ( pSectCtl->hSectionSema4 != 0 ) { |
|---|
| 660 | #if DEBUG |
|---|
| 661 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "delete psectCtl->sema4. \n"); |
|---|
| 662 | #endif |
|---|
| 663 | |
|---|
| 664 | OS_DeleteSemaphore( pSectCtl->hSectionSema4 ); |
|---|
| 665 | pSectCtl->hSectionSema4 = 0; |
|---|
| 666 | } |
|---|
| 667 | } |
|---|
| 668 | |
|---|
| 669 | void DD_PSI_ResetSectionCtl( PSI_SECTION_CTL_t *pSectCtl , int iSelfIndex ) |
|---|
| 670 | { |
|---|
| 671 | if( !pSectCtl ) |
|---|
| 672 | return; |
|---|
| 673 | |
|---|
| 674 | pSectCtl->iSelfIndex = iSelfIndex; |
|---|
| 675 | pSectCtl->pParent = NULL; |
|---|
| 676 | pSectCtl->iPidCtlIndex = 0; |
|---|
| 677 | pSectCtl->eState = PCS_RAW; |
|---|
| 678 | pSectCtl->pContext = NULL; |
|---|
| 679 | |
|---|
| 680 | if( !(pSectCtl->hSectionSema4) ) |
|---|
| 681 | pSectCtl->hSectionSema4 = OS_CreateCountingSemaphore( "psiSectSema4", 0, 1 ); |
|---|
| 682 | |
|---|
| 683 | if( !(pSectCtl->hSectionSema4) ) { |
|---|
| 684 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ResetSectionCtl : fail create sema4.\r\n"); |
|---|
| 685 | } else { |
|---|
| 686 | #ifdef PIS_DBG |
|---|
| 687 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ResetSectionCtl : create section sema4 ok.\r\n"); |
|---|
| 688 | #endif |
|---|
| 689 | } |
|---|
| 690 | } |
|---|
| 691 | |
|---|
| 692 | void DD_PSI_ReleaseSectionCtl ( PSI_SECTION_CTL_t *pSectCtl ) |
|---|
| 693 | { |
|---|
| 694 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 695 | |
|---|
| 696 | if( !pSectCtl ) |
|---|
| 697 | return; |
|---|
| 698 | |
|---|
| 699 | if( pSectCtl->eState == PCS_RAW ) { |
|---|
| 700 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "|%d| WARING: Try to release section control not allocated.\n", __LINE__); |
|---|
| 701 | return; |
|---|
| 702 | } |
|---|
| 703 | |
|---|
| 704 | if( pSectCtl->eState == PCS_RUNNING) |
|---|
| 705 | DD_PSI_StopSectionCtl( pSectCtl ); |
|---|
| 706 | |
|---|
| 707 | dhlResult = DD_PSI_StopAndDeleteFilter( pSectCtl ); |
|---|
| 708 | if ( dhlResult != DHL_OK ) { |
|---|
| 709 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 710 | return; |
|---|
| 711 | } |
|---|
| 712 | |
|---|
| 713 | DD_PSI_ReleasePidCtl( (PSI_INFRA_CTL_t *)(pSectCtl->pParent) , pSectCtl->iPidCtlIndex ); |
|---|
| 714 | |
|---|
| 715 | if( pSectCtl->pContext ) |
|---|
| 716 | { |
|---|
| 717 | DD_PSI_ReleasePSICtx( pSectCtl->pContext ); |
|---|
| 718 | pSectCtl->pContext = NULL; |
|---|
| 719 | } |
|---|
| 720 | |
|---|
| 721 | //pSectCtl->filterId = -1; |
|---|
| 722 | pSectCtl->eState = PCS_INIT; |
|---|
| 723 | |
|---|
| 724 | DD_PSI_ReleaseSectCtlFromArray(pSectCtl->pParent ,pSectCtl->iSelfIndex); |
|---|
| 725 | } |
|---|
| 726 | |
|---|
| 727 | DS_BOOL DD_PSI_ExistSectionCtl( void *pPsiInfo, |
|---|
| 728 | DS_U16 pid, |
|---|
| 729 | PSIMask_t *prefList |
|---|
| 730 | ) |
|---|
| 731 | { |
|---|
| 732 | PSI_INFRA_CTL_t *pPsiInfra = (PSI_INFRA_CTL_t *)pPsiInfo; |
|---|
| 733 | PSI_SECTION_CTL_t * pSectionCtl = NULL; |
|---|
| 734 | DS_BOOL bFound = _FALSE_; |
|---|
| 735 | int i=0 ,j =0; |
|---|
| 736 | |
|---|
| 737 | if(!pPsiInfra || !prefList ) |
|---|
| 738 | return _FALSE_; |
|---|
| 739 | |
|---|
| 740 | for( i = 0 ; i < MAX_SECTION_FILTER_CNT ; i++ ) |
|---|
| 741 | { |
|---|
| 742 | if( pPsiInfra->aSectCtlUsedList[i] == _FALSE_ ) |
|---|
| 743 | continue; |
|---|
| 744 | |
|---|
| 745 | pSectionCtl = &(pPsiInfra->aSectCtl[i]); |
|---|
| 746 | |
|---|
| 747 | #if DEBUG |
|---|
| 748 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ExistSectionCtl : index = %d. filtCount = %d\r\n" , pSectionCtl->iPidCtlIndex , pSectionCtl->filtCount); |
|---|
| 749 | #endif |
|---|
| 750 | |
|---|
| 751 | if ( pPsiInfra->aPidCtl[pSectionCtl->iPidCtlIndex].uiPid == pid ) |
|---|
| 752 | { |
|---|
| 753 | int iFilterIndex = 0; |
|---|
| 754 | |
|---|
| 755 | for ( iFilterIndex = 0 , j = 0 ; iFilterIndex < pSectionCtl->filtCount; iFilterIndex++, j++ ) |
|---|
| 756 | { |
|---|
| 757 | #if DEBUG |
|---|
| 758 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ExistSectionCtl :filterBytes[%d] = 0x%x ,entries[%d] = 0x%x. \r\n" , |
|---|
| 759 | j , pSectionCtl->filterBytes[j], iFilterIndex , prefList->entries[iFilterIndex].value ); |
|---|
| 760 | #endif |
|---|
| 761 | |
|---|
| 762 | if( iFilterIndex == 2 || iFilterIndex == 7 ) /*2, 7 index °¡Áö´Â byte¹«½Ã.*/ |
|---|
| 763 | continue; |
|---|
| 764 | |
|---|
| 765 | if( pSectionCtl->filterBytes[j] != prefList->entries[iFilterIndex].value ) |
|---|
| 766 | break; /*for loop break*/ |
|---|
| 767 | |
|---|
| 768 | if ( pSectionCtl->filterMasks[j] != prefList->entries[iFilterIndex].matchMask ) |
|---|
| 769 | break; /*for loop break*/ |
|---|
| 770 | |
|---|
| 771 | //++j; |
|---|
| 772 | } |
|---|
| 773 | |
|---|
| 774 | if ( pSectionCtl->filtCount && iFilterIndex == pSectionCtl->filtCount ) /*filterCount ¸ðµÎ ºñ±³Çصµ ´Ù¸¥°Ô ¾ø´Ù¸é*/ |
|---|
| 775 | { |
|---|
| 776 | bFound = _TRUE_; |
|---|
| 777 | |
|---|
| 778 | #if DEBUG |
|---|
| 779 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ExistSectionCtl : already registered filter. so rejecjt it.\r\n"); |
|---|
| 780 | #endif |
|---|
| 781 | |
|---|
| 782 | break; /*while loop break*/ |
|---|
| 783 | } |
|---|
| 784 | } /*if ( pPsiInfra->aPidCtl[iPidCtlIndex] == pid )*/ |
|---|
| 785 | |
|---|
| 786 | } /*for*/ |
|---|
| 787 | |
|---|
| 788 | return bFound; |
|---|
| 789 | } |
|---|
| 790 | |
|---|
| 791 | DS_BOOL DD_PSI_ExistSectionFilter( void *pPsiInfo, |
|---|
| 792 | DS_U16 pid, |
|---|
| 793 | PSI_SECTION_CTL_t *pCtrlToFind, |
|---|
| 794 | PSI_SECTION_CTL_t **returnSectCtl |
|---|
| 795 | ) |
|---|
| 796 | { |
|---|
| 797 | PSI_INFRA_CTL_t *pPsiInfra = (PSI_INFRA_CTL_t *)pPsiInfo; |
|---|
| 798 | PSI_SECTION_CTL_t * pSectionCtl = NULL; |
|---|
| 799 | DS_BOOL bFound = _FALSE_; |
|---|
| 800 | int i=0 ,j =0; |
|---|
| 801 | |
|---|
| 802 | if(!pPsiInfra || !pCtrlToFind ) |
|---|
| 803 | return _FALSE_; |
|---|
| 804 | |
|---|
| 805 | for( i = 0 ; i < MAX_SECTION_FILTER_CNT ; i++ ) |
|---|
| 806 | { |
|---|
| 807 | if( pPsiInfra->aSectCtlUsedList[i] == _FALSE_ ) |
|---|
| 808 | continue; |
|---|
| 809 | |
|---|
| 810 | pSectionCtl = &(pPsiInfra->aSectCtl[i]); |
|---|
| 811 | |
|---|
| 812 | #if DEBUG |
|---|
| 813 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "index = %d. filtCount = %d\r\n" , pSectionCtl->iPidCtlIndex , pSectionCtl->filtCount); |
|---|
| 814 | #endif |
|---|
| 815 | |
|---|
| 816 | if ( pPsiInfra->aPidCtl[pSectionCtl->iPidCtlIndex].uiPid == pid ) |
|---|
| 817 | { |
|---|
| 818 | int iFilterIndex = 0; |
|---|
| 819 | |
|---|
| 820 | for ( iFilterIndex = 0 , j = 0 ; iFilterIndex < pSectionCtl->filtCount; iFilterIndex++ ) |
|---|
| 821 | { |
|---|
| 822 | #if DEBUG |
|---|
| 823 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ExistSectionCtl :filterBytes[%d] = 0x%x ,entries[%d] = 0x%x. \r\n" , |
|---|
| 824 | j , pSectionCtl->filterBytes[j], iFilterIndex, pCtrlToFind->filterBytes[iFilterIndex] ); |
|---|
| 825 | #endif |
|---|
| 826 | |
|---|
| 827 | if( iFilterIndex == 2 || iFilterIndex == 7 || iFilterIndex >= 9) /*2, 7 index °¡Áö´Â byte¹«½Ã.*/ |
|---|
| 828 | continue; |
|---|
| 829 | |
|---|
| 830 | if( pSectionCtl->filterBytes[j] != pCtrlToFind->filterBytes[j] ) |
|---|
| 831 | break; /*for loop break*/ |
|---|
| 832 | |
|---|
| 833 | if ( pSectionCtl->filterMasks[j] != pCtrlToFind->filterMasks[j] ) |
|---|
| 834 | break; /*for loop break*/ |
|---|
| 835 | |
|---|
| 836 | ++j; |
|---|
| 837 | } |
|---|
| 838 | |
|---|
| 839 | if ( pSectionCtl->filtCount && iFilterIndex == pSectionCtl->filtCount ) /*filterCount ¸ðµÎ ºñ±³Çصµ ´Ù¸¥°Ô ¾ø´Ù¸é*/ |
|---|
| 840 | { |
|---|
| 841 | if ( pSectionCtl != pCtrlToFind ) { |
|---|
| 842 | bFound = _TRUE_; |
|---|
| 843 | *returnSectCtl = pSectionCtl; |
|---|
| 844 | break; /*while loop break*/ |
|---|
| 845 | } |
|---|
| 846 | } |
|---|
| 847 | } /*if ( pPsiInfra->aPidCtl[iPidCtlIndex] == pid )*/ |
|---|
| 848 | |
|---|
| 849 | } /*for*/ |
|---|
| 850 | |
|---|
| 851 | return bFound; |
|---|
| 852 | } |
|---|
| 853 | |
|---|
| 854 | DS_BOOL DD_PSI_IsRunningSectionCtl( PSI_SECTION_CTL_t * pSectionCtl ) |
|---|
| 855 | { |
|---|
| 856 | if( pSectionCtl->eState == PCS_RUNNING ) |
|---|
| 857 | return _TRUE_; |
|---|
| 858 | else |
|---|
| 859 | return _FALSE_; |
|---|
| 860 | } |
|---|
| 861 | |
|---|
| 862 | static void DD_PSI_DeleteAllSectCtls( PSI_INFRA_CTL_t *pPsiInfra ) |
|---|
| 863 | { |
|---|
| 864 | int i = 0; |
|---|
| 865 | |
|---|
| 866 | #if DEBUG |
|---|
| 867 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_DeleteAllSectCtls.\n"); |
|---|
| 868 | #endif |
|---|
| 869 | |
|---|
| 870 | if(!pPsiInfra) |
|---|
| 871 | return; |
|---|
| 872 | |
|---|
| 873 | for ( i = 0 ; i < MAX_SECTION_FILTER_CNT ; i++ ) |
|---|
| 874 | { |
|---|
| 875 | if( pPsiInfra->aSectCtlUsedList[i] == _TRUE_ ) { |
|---|
| 876 | #if DEBUG |
|---|
| 877 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "%d th sectCtl is deleted.\n"); |
|---|
| 878 | #endif |
|---|
| 879 | |
|---|
| 880 | DD_PSI_CancelPSIPid( pPsiInfra ,(void *)(&( pPsiInfra->aSectCtl[i])) ); |
|---|
| 881 | } |
|---|
| 882 | |
|---|
| 883 | DD_PSI_FreeSectionCtl( &(pPsiInfra->aSectCtl[i]) ); |
|---|
| 884 | pPsiInfra->aSectCtlUsedList[i] = _TRUE_; |
|---|
| 885 | } |
|---|
| 886 | } |
|---|
| 887 | |
|---|
| 888 | DHL_RESULT DD_PSI_LockSectCtlArray( PSI_INFRA_CTL_t *pPsiInfra , int timeOut ) |
|---|
| 889 | { |
|---|
| 890 | int res = 0; |
|---|
| 891 | |
|---|
| 892 | #if DEBUG |
|---|
| 893 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_LockSectCtlArray.\r\n"); |
|---|
| 894 | #endif |
|---|
| 895 | |
|---|
| 896 | if( !pPsiInfra) |
|---|
| 897 | return DHL_FAIL_NULL_POINTER; |
|---|
| 898 | |
|---|
| 899 | if( !(pPsiInfra->hSectCtlAccessSema4) ) |
|---|
| 900 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 901 | |
|---|
| 902 | #if DEBUG |
|---|
| 903 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray. before sema lock\r\n"); |
|---|
| 904 | #endif |
|---|
| 905 | |
|---|
| 906 | res = OS_TakeSemaphore_Wait(pPsiInfra->hSectCtlAccessSema4 , timeOut); |
|---|
| 907 | if( res != 0 ) |
|---|
| 908 | { |
|---|
| 909 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray : OS_TakeSemaphore_Wait timeout.\n"); |
|---|
| 910 | /*return */ |
|---|
| 911 | return DHL_FAIL_TIMEOUT; |
|---|
| 912 | } |
|---|
| 913 | |
|---|
| 914 | #if DEBUG |
|---|
| 915 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray. after sema lock\r\n"); |
|---|
| 916 | #endif |
|---|
| 917 | |
|---|
| 918 | return DHL_OK; |
|---|
| 919 | } |
|---|
| 920 | |
|---|
| 921 | DHL_RESULT DD_PSI_UnlockSectCtlArray( PSI_INFRA_CTL_t *pPsiInfra ) |
|---|
| 922 | { |
|---|
| 923 | DS_U32 res; |
|---|
| 924 | |
|---|
| 925 | #if DEBUG |
|---|
| 926 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_UnlockSectCtlArra.\r\n"); |
|---|
| 927 | #endif |
|---|
| 928 | |
|---|
| 929 | if( !pPsiInfra ) |
|---|
| 930 | return DHL_FAIL_NULL_POINTER; |
|---|
| 931 | |
|---|
| 932 | if( !pPsiInfra->hSectCtlAccessSema4 ) |
|---|
| 933 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 934 | |
|---|
| 935 | |
|---|
| 936 | #if DEBUG |
|---|
| 937 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_UnlockSectCtlArray. before sema unlock\r\n"); |
|---|
| 938 | #endif |
|---|
| 939 | |
|---|
| 940 | res = OS_GiveSemaphore(pPsiInfra->hSectCtlAccessSema4); |
|---|
| 941 | if ( res ) |
|---|
| 942 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 943 | |
|---|
| 944 | #if DEBUG |
|---|
| 945 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_UnlockSectCtlArray. after sema unlock\r\n"); |
|---|
| 946 | #endif |
|---|
| 947 | |
|---|
| 948 | return DHL_OK; |
|---|
| 949 | } |
|---|
| 950 | |
|---|
| 951 | |
|---|
| 952 | |
|---|
| 953 | PSI_SECTION_CTL_t* DD_PSI_GetSectCtlFromArray( PSI_INFRA_CTL_t *pPsiInfra ) |
|---|
| 954 | { |
|---|
| 955 | #if !DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 956 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 957 | #endif |
|---|
| 958 | PSI_SECTION_CTL_t *pSectCtl = NULL; |
|---|
| 959 | int i = 0; |
|---|
| 960 | |
|---|
| 961 | #if DEBUG |
|---|
| 962 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_GetSectCtlFromArray...\r\n"); |
|---|
| 963 | #endif |
|---|
| 964 | |
|---|
| 965 | if( !pPsiInfra ) |
|---|
| 966 | return NULL; |
|---|
| 967 | |
|---|
| 968 | #if !DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 969 | dhlResult = DD_PSI_LockSectCtlArray( pPsiInfra , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 970 | if( dhlResult != DHL_OK ) |
|---|
| 971 | { |
|---|
| 972 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray... : timeout.\r\n"); |
|---|
| 973 | return NULL; |
|---|
| 974 | } |
|---|
| 975 | #endif |
|---|
| 976 | |
|---|
| 977 | for( i = 0 ; i < MAX_SECTION_FILTER_CNT ; i++ ) |
|---|
| 978 | { |
|---|
| 979 | if( pPsiInfra->aSectCtlUsedList[i] == _FALSE_ ) |
|---|
| 980 | { |
|---|
| 981 | pSectCtl = &(pPsiInfra->aSectCtl[i]); |
|---|
| 982 | pPsiInfra->aSectCtlUsedList[i] = _TRUE_; |
|---|
| 983 | break; |
|---|
| 984 | } |
|---|
| 985 | }/*for*/ |
|---|
| 986 | |
|---|
| 987 | if( pSectCtl ) |
|---|
| 988 | pSectCtl->pParent = pPsiInfra; |
|---|
| 989 | |
|---|
| 990 | #if !DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 991 | DD_PSI_UnlockSectCtlArray( pPsiInfra ); |
|---|
| 992 | #endif |
|---|
| 993 | |
|---|
| 994 | return pSectCtl; |
|---|
| 995 | |
|---|
| 996 | } |
|---|
| 997 | |
|---|
| 998 | void DD_PSI_ReleaseSectCtlFromArray( PSI_INFRA_CTL_t *pPsiInfra, int iSectIndex ) |
|---|
| 999 | { |
|---|
| 1000 | #if !DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 1001 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1002 | #endif |
|---|
| 1003 | |
|---|
| 1004 | #if DEBUG |
|---|
| 1005 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_ReleaseSectCtlFromArray...\r\n"); |
|---|
| 1006 | #endif |
|---|
| 1007 | |
|---|
| 1008 | if( !pPsiInfra || iSectIndex > MAX_SECTION_FILTER_CNT ) |
|---|
| 1009 | return; |
|---|
| 1010 | |
|---|
| 1011 | #if !DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 1012 | dhlResult = DD_PSI_LockSectCtlArray( pPsiInfra , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 1013 | if( dhlResult != DHL_OK ) |
|---|
| 1014 | { |
|---|
| 1015 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ReleaseSectCtlFromArray... : timeout.\r\n"); |
|---|
| 1016 | return; |
|---|
| 1017 | } |
|---|
| 1018 | #endif |
|---|
| 1019 | |
|---|
| 1020 | if ( pPsiInfra->aSectCtlUsedList[iSectIndex] == _TRUE_ ) |
|---|
| 1021 | { |
|---|
| 1022 | pPsiInfra->aSectCtlUsedList[iSectIndex] = _FALSE_; |
|---|
| 1023 | DD_PSI_ResetSectionCtl( &(pPsiInfra->aSectCtl[iSectIndex]) ,iSectIndex ); |
|---|
| 1024 | } |
|---|
| 1025 | |
|---|
| 1026 | #if !DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 1027 | DD_PSI_UnlockSectCtlArray( pPsiInfra ); |
|---|
| 1028 | #endif |
|---|
| 1029 | |
|---|
| 1030 | return; |
|---|
| 1031 | } |
|---|
| 1032 | DHL_RESULT DD_PSI_LockSectionCtl( PSI_SECTION_CTL_t *pSectionCtl , int timeOut ) |
|---|
| 1033 | { |
|---|
| 1034 | DS_U32 res; |
|---|
| 1035 | DS_U32 currTaskId = 0; |
|---|
| 1036 | |
|---|
| 1037 | currTaskId = OS_GetSelfTaskId(); |
|---|
| 1038 | |
|---|
| 1039 | if( !pSectionCtl ) |
|---|
| 1040 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1041 | |
|---|
| 1042 | if( !pSectionCtl->hSectionSema4 ) |
|---|
| 1043 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1044 | |
|---|
| 1045 | #if DEBUG |
|---|
| 1046 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_LockSectionCtl. lockCount = %d\r\n" , pSectionCtl->nLockCount); |
|---|
| 1047 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "lockedTask = 0x%x , curTaskId = 0x%x\r\n", pSectionCtl->iCurLockedTask, currTaskId); |
|---|
| 1048 | #endif |
|---|
| 1049 | |
|---|
| 1050 | if( pSectionCtl->iCurLockedTask != 0 ) |
|---|
| 1051 | { |
|---|
| 1052 | if( pSectionCtl->iCurLockedTask == currTaskId ) |
|---|
| 1053 | { |
|---|
| 1054 | pSectionCtl->nLockCount++; |
|---|
| 1055 | #if DEBUG |
|---|
| 1056 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "Same task sema4 lock. so no try lock.\r\n"); |
|---|
| 1057 | #endif |
|---|
| 1058 | return DHL_OK; |
|---|
| 1059 | } |
|---|
| 1060 | } |
|---|
| 1061 | |
|---|
| 1062 | #if DEBUG |
|---|
| 1063 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectionCtl[0x%lX]. before sema lock.\r\n", (DS_U32)pSectionCtl); |
|---|
| 1064 | #endif |
|---|
| 1065 | |
|---|
| 1066 | res = OS_TakeSemaphore_Wait(pSectionCtl->hSectionSema4 , timeOut ); |
|---|
| 1067 | if( res != 0 ) |
|---|
| 1068 | { |
|---|
| 1069 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_LockSectionCtl : OS_TakeSemaphore_Wait timeout.\n"); |
|---|
| 1070 | /*return */ |
|---|
| 1071 | return DHL_FAIL_TIMEOUT; |
|---|
| 1072 | } |
|---|
| 1073 | |
|---|
| 1074 | #if DEBUG |
|---|
| 1075 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectionCtl[0x%lX]. after sema lock.\r\n", (DS_U32)pSectionCtl); |
|---|
| 1076 | #endif |
|---|
| 1077 | |
|---|
| 1078 | pSectionCtl->iCurLockedTask = currTaskId; |
|---|
| 1079 | pSectionCtl->nLockCount++; |
|---|
| 1080 | return DHL_OK; |
|---|
| 1081 | } |
|---|
| 1082 | |
|---|
| 1083 | DHL_RESULT DD_PSI_UnlockSectionCtl ( PSI_SECTION_CTL_t *pSectionCtl ) |
|---|
| 1084 | { |
|---|
| 1085 | DS_U32 currTaskId = 0; |
|---|
| 1086 | |
|---|
| 1087 | currTaskId = OS_GetSelfTaskId(); |
|---|
| 1088 | |
|---|
| 1089 | #if DEBUG |
|---|
| 1090 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_UnlockSectionCtl.\r\n"); |
|---|
| 1091 | #endif |
|---|
| 1092 | |
|---|
| 1093 | if( !pSectionCtl ) |
|---|
| 1094 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1095 | |
|---|
| 1096 | if( !pSectionCtl->hSectionSema4 ) |
|---|
| 1097 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1098 | |
|---|
| 1099 | #if DEBUG |
|---|
| 1100 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_UnlockSectionCtl. before sema unlock. lockCount =%d. \r\n" , pSectionCtl->nLockCount); |
|---|
| 1101 | #endif |
|---|
| 1102 | |
|---|
| 1103 | pSectionCtl->nLockCount--; |
|---|
| 1104 | if(pSectionCtl->nLockCount == 0 ) |
|---|
| 1105 | { |
|---|
| 1106 | pSectionCtl->iCurLockedTask = 0; |
|---|
| 1107 | OS_GiveSemaphore(pSectionCtl->hSectionSema4); |
|---|
| 1108 | } |
|---|
| 1109 | else if( pSectionCtl->nLockCount <= 0 ) |
|---|
| 1110 | pSectionCtl->nLockCount = 0; |
|---|
| 1111 | |
|---|
| 1112 | #if DEBUG |
|---|
| 1113 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_UnlockSectionCtl. after sema unlock.\r\n"); |
|---|
| 1114 | #endif |
|---|
| 1115 | |
|---|
| 1116 | return DHL_OK; |
|---|
| 1117 | } |
|---|
| 1118 | |
|---|
| 1119 | |
|---|
| 1120 | /*ÁÖ¾îÁø setion¿¡ °üÇÑ pid,section,si component stop. pidFilter´Â option.*/ |
|---|
| 1121 | |
|---|
| 1122 | |
|---|
| 1123 | DHL_RESULT DD_PSI_ResetSectMask ( void *pParent ,PSIMask_t *prefList ) |
|---|
| 1124 | { |
|---|
| 1125 | int i , j; |
|---|
| 1126 | int maxCnt = 0; |
|---|
| 1127 | PSI_SECTION_CTL_t * pSectionCtl = NULL; |
|---|
| 1128 | PSI_PID_CTL_t *pPidCtl = NULL; |
|---|
| 1129 | |
|---|
| 1130 | DS_U8 filterBytes[SECTION_FILTER_SIZE]; |
|---|
| 1131 | DS_U8 filterMasks[SECTION_FILTER_SIZE]; |
|---|
| 1132 | DS_U8 filterInvert[SECTION_FILTER_SIZE]; |
|---|
| 1133 | |
|---|
| 1134 | pSectionCtl = (PSI_SECTION_CTL_t * )pParent; |
|---|
| 1135 | pPidCtl = &(pSectionCtl->pParent->aPidCtl[pSectionCtl->iPidCtlIndex]); |
|---|
| 1136 | |
|---|
| 1137 | /*1.remove pipe notification for section ************************/ |
|---|
| 1138 | /*****************************************************************/ |
|---|
| 1139 | |
|---|
| 1140 | |
|---|
| 1141 | /*2.stop section filter.******************************************/ |
|---|
| 1142 | /*****************************************************************/ |
|---|
| 1143 | |
|---|
| 1144 | |
|---|
| 1145 | /*4.Stop SI component**********************************************/ |
|---|
| 1146 | /******************************************************************/ |
|---|
| 1147 | |
|---|
| 1148 | /* notification setting */ |
|---|
| 1149 | memset( filterBytes, 0, SECTION_FILTER_SIZE ); |
|---|
| 1150 | memset( filterMasks, 0, SECTION_FILTER_SIZE ); |
|---|
| 1151 | memset( filterInvert, 0, SECTION_FILTER_SIZE ); |
|---|
| 1152 | |
|---|
| 1153 | if( prefList->numEntries > SECTION_FILTER_SIZE ) |
|---|
| 1154 | maxCnt = SECTION_FILTER_SIZE; |
|---|
| 1155 | else |
|---|
| 1156 | maxCnt = prefList->numEntries; |
|---|
| 1157 | |
|---|
| 1158 | for ( i = 0 , j = 0 ; i < maxCnt ; ++i ) |
|---|
| 1159 | { |
|---|
| 1160 | if ( i == 2 || i == 7 ) /*index°¡ 2,7ÀÎ byte´Â ¹«½Ã.*/ |
|---|
| 1161 | continue; |
|---|
| 1162 | |
|---|
| 1163 | pSectionCtl->filterBytes [j] = prefList->entries[i].value; |
|---|
| 1164 | pSectionCtl->filterMasks [j] = prefList->entries[i].matchMask; |
|---|
| 1165 | pSectionCtl->filterInvert[j] = prefList->entries[i].noMatchMask; |
|---|
| 1166 | |
|---|
| 1167 | ++j; |
|---|
| 1168 | } |
|---|
| 1169 | pSectionCtl->filtCount = j; |
|---|
| 1170 | |
|---|
| 1171 | #if 0 |
|---|
| 1172 | dhlResult = DD_PSI_CreateAndSetFilter( pSectionCtl, |
|---|
| 1173 | pPidCtl->uiPid, |
|---|
| 1174 | pSectionCtl->filterBytes, |
|---|
| 1175 | pSectionCtl->filterMasks, |
|---|
| 1176 | pSectionCtl->filterInvert, |
|---|
| 1177 | pSectionCtl->filtCount ); |
|---|
| 1178 | if(DHL_ERROR(dhlResult)) |
|---|
| 1179 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 1180 | #endif |
|---|
| 1181 | |
|---|
| 1182 | return DHL_OK; |
|---|
| 1183 | } |
|---|
| 1184 | |
|---|
| 1185 | void DD_PSI_SetSegmentNumber( void *p_section_ctl, int segment_number ) |
|---|
| 1186 | { |
|---|
| 1187 | PSI_SECTION_CTL_t *pSectCtl = (PSI_SECTION_CTL_t *)p_section_ctl; |
|---|
| 1188 | |
|---|
| 1189 | pSectCtl->pContext->segment_number = segment_number; |
|---|
| 1190 | } |
|---|
| 1191 | |
|---|
| 1192 | static int cbFilterNotification( PSI_EVENT_t Event, DS_U32 Arg, DS_U8 *pBuf, DS_U32 Len, DS_BOOL bNeedSWFilter ) |
|---|
| 1193 | { |
|---|
| 1194 | PSI_SECTION_CTL_t *pSectCtl = (PSI_SECTION_CTL_t *)Arg; |
|---|
| 1195 | int i; |
|---|
| 1196 | |
|---|
| 1197 | int bMatch = 0; |
|---|
| 1198 | |
|---|
| 1199 | if ( g_Demux_Debug >= 2 ) { |
|---|
| 1200 | printf( "Received Section: Len=%d\n", (int)Len); |
|---|
| 1201 | if ( g_Demux_Debug == 2 ) { |
|---|
| 1202 | for (i=0; i<16; i++) { |
|---|
| 1203 | if ( !(i%16) ) |
|---|
| 1204 | printf( "\n"); |
|---|
| 1205 | printf( "%02X ", pBuf[i] ); |
|---|
| 1206 | } |
|---|
| 1207 | } else { |
|---|
| 1208 | for (i=0; i<Len; i++) { |
|---|
| 1209 | if ( !(i%16) ) |
|---|
| 1210 | printf( "\n"); |
|---|
| 1211 | printf( "%02X ", pBuf[i] ); |
|---|
| 1212 | } |
|---|
| 1213 | } |
|---|
| 1214 | printf( "\n"); |
|---|
| 1215 | } |
|---|
| 1216 | |
|---|
| 1217 | // |
|---|
| 1218 | // SW FilteringÀÌ ÇÊ¿äÇÑ °æ¿ì. |
|---|
| 1219 | // |
|---|
| 1220 | if ( bNeedSWFilter ) { |
|---|
| 1221 | |
|---|
| 1222 | } else { |
|---|
| 1223 | |
|---|
| 1224 | // |
|---|
| 1225 | // SW FilterÀÌ ÇÊ¿ä¾ø´Â °æ¿ì, ´Ü¼øÈ÷ »óÀ§·Î ¿Ã¸². |
|---|
| 1226 | // |
|---|
| 1227 | bMatch = 1; |
|---|
| 1228 | if(pSectCtl->eState == PCS_RUNNING) |
|---|
| 1229 | { |
|---|
| 1230 | DD_PSI_LockSectionCtl( pSectCtl, OS_WAIT_FOREVER ); |
|---|
| 1231 | DD_PSI_DataReceived( pSectCtl->pContext, (DS_U8 *)pBuf, Len ); |
|---|
| 1232 | DD_PSI_UnlockSectionCtl( pSectCtl ); |
|---|
| 1233 | } |
|---|
| 1234 | else |
|---|
| 1235 | { |
|---|
| 1236 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "Invalid section state: %s (%d)\n", |
|---|
| 1237 | pSectCtl->eState == PCS_RUNNING ? "Running" : |
|---|
| 1238 | pSectCtl->eState == PCS_RAW ? "RAW" : |
|---|
| 1239 | pSectCtl->eState == PCS_INIT ? "INIT" : "Unknown", (int)pSectCtl->eState); |
|---|
| 1240 | } |
|---|
| 1241 | |
|---|
| 1242 | } |
|---|
| 1243 | |
|---|
| 1244 | return bMatch; |
|---|
| 1245 | } |
|---|
| 1246 | |
|---|
| 1247 | /****************************************************************************** |
|---|
| 1248 | * cbReceiveSection |
|---|
| 1249 | * Callback Function called by lower demux device driver. |
|---|
| 1250 | ******************************************************************************/ |
|---|
| 1251 | static void cbReceiveSection(PD_SECFILTER *p_sec, DS_U8 *pSecData, int Size) |
|---|
| 1252 | { |
|---|
| 1253 | PSI_INFRA_CTL_t *pPsiInfra = (PSI_INFRA_CTL_t *)g_pPsiInfra; |
|---|
| 1254 | PSI_SECTION_CTL_t * pSectionCtl = NULL; |
|---|
| 1255 | DS_U8 *pSectionBuffer = (DS_U8 *)NULL; |
|---|
| 1256 | int i; |
|---|
| 1257 | |
|---|
| 1258 | SysREQUIRE(Size<=4096); |
|---|
| 1259 | |
|---|
| 1260 | for( i = 0 ; i < MAX_SECTION_FILTER_CNT ; i++ ) |
|---|
| 1261 | { |
|---|
| 1262 | if( pPsiInfra->aSectCtlUsedList[i] == DS_FALSE ) |
|---|
| 1263 | continue; |
|---|
| 1264 | |
|---|
| 1265 | pSectionCtl = &(pPsiInfra->aSectCtl[i]); |
|---|
| 1266 | |
|---|
| 1267 | if ( pSectionCtl->pDrvSecFilter == p_sec /*&& pSectionCtl->eState == PCS_RUNNING*/ ) |
|---|
| 1268 | break; |
|---|
| 1269 | } |
|---|
| 1270 | |
|---|
| 1271 | if ( pSectionCtl->eState != PCS_RUNNING ) |
|---|
| 1272 | return; |
|---|
| 1273 | |
|---|
| 1274 | if ( i == MAX_SECTION_FILTER_CNT ) { |
|---|
| 1275 | printf("|%s| cannot find any matched section filter; pid: %d, filterid=0x%08lX\n", |
|---|
| 1276 | __FUNCTION__, p_sec->i_pid, (DS_U32)p_sec); |
|---|
| 1277 | return; |
|---|
| 1278 | } |
|---|
| 1279 | |
|---|
| 1280 | pSectionBuffer = (DS_U8 *)malloc(Size); |
|---|
| 1281 | SysASSERT( pSectionBuffer ); |
|---|
| 1282 | |
|---|
| 1283 | memcpy( pSectionBuffer, pSecData, Size ); |
|---|
| 1284 | |
|---|
| 1285 | cbFilterNotification( PSI_EVENT__RCVD_NO_ERROR, (DS_U32)pSectionCtl, pSectionBuffer, Size, 0 ); |
|---|
| 1286 | |
|---|
| 1287 | free( pSectionBuffer ); |
|---|
| 1288 | } |
|---|
| 1289 | |
|---|
| 1290 | static void cbStopSectionCtl( DS_U32 arg1 , DS_U32 arg2 ) |
|---|
| 1291 | { |
|---|
| 1292 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1293 | PSI_SECTION_CTL_t *pSectionCtl = (void *)arg1; |
|---|
| 1294 | PSI_INFRA_CTL_t *pPsiInfra = (void *)arg2; |
|---|
| 1295 | |
|---|
| 1296 | if(!pSectionCtl || !pPsiInfra) |
|---|
| 1297 | return; |
|---|
| 1298 | |
|---|
| 1299 | dhlResult = DD_PSI_LockSectionCtl(pSectionCtl , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 1300 | if ( dhlResult != DHL_OK ) { |
|---|
| 1301 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_cbStopSectonCtl : timeout.\r\n"); |
|---|
| 1302 | return; |
|---|
| 1303 | } |
|---|
| 1304 | |
|---|
| 1305 | dhlResult = DD_PSI_StopSectionCtl( pSectionCtl ); |
|---|
| 1306 | if( dhlResult != DHL_OK ) |
|---|
| 1307 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "cbStopSectionCtl :DD_PSI_StopSectionCtl has returned error(0x%x)\r\n" , dhlResult ); |
|---|
| 1308 | |
|---|
| 1309 | |
|---|
| 1310 | DD_PSI_UnlockSectionCtl(pSectionCtl); |
|---|
| 1311 | |
|---|
| 1312 | } |
|---|
| 1313 | |
|---|
| 1314 | #if 0 |
|---|
| 1315 | ___PID_Control__API__________() |
|---|
| 1316 | #endif |
|---|
| 1317 | DHL_RESULT DD_PSI_StartPidCtl ( PSI_INFRA_CTL_t *pPsiInfra, int iPidCtlIndex ) |
|---|
| 1318 | { |
|---|
| 1319 | PSI_PID_CTL_t *pPidCtl = NULL; |
|---|
| 1320 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1321 | |
|---|
| 1322 | if( iPidCtlIndex > MAX_PID_FILTER_CNT ) |
|---|
| 1323 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1324 | |
|---|
| 1325 | dhlResult = DD_PSI_LockPidCtlArray( pPsiInfra, OS_WAIT_FOREVER ); |
|---|
| 1326 | if( dhlResult != DHL_OK ) |
|---|
| 1327 | { |
|---|
| 1328 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : timeout.\r\n"); |
|---|
| 1329 | return dhlResult; |
|---|
| 1330 | } |
|---|
| 1331 | |
|---|
| 1332 | pPidCtl = &(pPsiInfra->aPidCtl[iPidCtlIndex]); |
|---|
| 1333 | |
|---|
| 1334 | /*its refCount should be more than one.*/ |
|---|
| 1335 | if(pPidCtl->nRefCount <= 0 || pPidCtl->eState != PCS_INIT) |
|---|
| 1336 | { |
|---|
| 1337 | dhlResult = DHL_FAIL_INVALID_STATE; |
|---|
| 1338 | goto GOOUT; |
|---|
| 1339 | } |
|---|
| 1340 | |
|---|
| 1341 | if( pPidCtl->nRefCountRunning == 0 ) |
|---|
| 1342 | ++(pPidCtl->nRefCountRunning); |
|---|
| 1343 | else if ( pPidCtl->nRefCountRunning > 0 ) |
|---|
| 1344 | ++(pPidCtl->nRefCountRunning); |
|---|
| 1345 | else |
|---|
| 1346 | dhlResult = DHL_FAIL_INVALID_STATE; |
|---|
| 1347 | |
|---|
| 1348 | GOOUT: |
|---|
| 1349 | DD_PSI_UnlockPidCtlArray( pPsiInfra ); |
|---|
| 1350 | |
|---|
| 1351 | return dhlResult; |
|---|
| 1352 | } |
|---|
| 1353 | |
|---|
| 1354 | /*nRefCountRunning Decrease.*/ |
|---|
| 1355 | DHL_RESULT DD_PSI_StopPidCtl ( PSI_INFRA_CTL_t *pPsiInfra , int iPidCtlIndex ) |
|---|
| 1356 | { |
|---|
| 1357 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1358 | PSI_PID_CTL_t *pPidCtl = NULL; |
|---|
| 1359 | |
|---|
| 1360 | if( iPidCtlIndex > MAX_PID_FILTER_CNT ) |
|---|
| 1361 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1362 | |
|---|
| 1363 | dhlResult = DD_PSI_LockPidCtlArray( pPsiInfra , OS_WAIT_FOREVER ); |
|---|
| 1364 | if ( dhlResult != DHL_OK ) { |
|---|
| 1365 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : timeout.\r\n"); |
|---|
| 1366 | return dhlResult; |
|---|
| 1367 | } |
|---|
| 1368 | |
|---|
| 1369 | pPidCtl = &(pPsiInfra->aPidCtl[iPidCtlIndex]); |
|---|
| 1370 | if( pPidCtl->nRefCountRunning <= 0 ) { |
|---|
| 1371 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_StopPidCtl : not running state.\r\n"); |
|---|
| 1372 | pPidCtl->nRefCountRunning = 0; |
|---|
| 1373 | dhlResult = DHL_FAIL_INVALID_STATE; |
|---|
| 1374 | goto GOOUT; |
|---|
| 1375 | } |
|---|
| 1376 | |
|---|
| 1377 | --(pPidCtl->nRefCountRunning); |
|---|
| 1378 | |
|---|
| 1379 | GOOUT: |
|---|
| 1380 | DD_PSI_UnlockPidCtlArray( pPsiInfra ); |
|---|
| 1381 | |
|---|
| 1382 | return dhlResult; |
|---|
| 1383 | } |
|---|
| 1384 | |
|---|
| 1385 | |
|---|
| 1386 | /* state change to PCS_RAW. : pidCtl LockÀ» ¹Ì¸® °É°í È£Ãâ*/ |
|---|
| 1387 | DHL_RESULT DD_PSI_ClosePidCtl ( PSI_INFRA_CTL_t *pPsiInfra , int iPidCtlIndex ) |
|---|
| 1388 | { |
|---|
| 1389 | PSI_PID_CTL_t *pPidCtl = NULL; |
|---|
| 1390 | |
|---|
| 1391 | if( !pPsiInfra ) |
|---|
| 1392 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1393 | |
|---|
| 1394 | if( iPidCtlIndex > MAX_PID_FILTER_CNT ) |
|---|
| 1395 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1396 | |
|---|
| 1397 | |
|---|
| 1398 | pPidCtl = &(pPsiInfra->aPidCtl[iPidCtlIndex]); |
|---|
| 1399 | |
|---|
| 1400 | |
|---|
| 1401 | #if DEBUG |
|---|
| 1402 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ClosePidCtl : iPidCtlIndex = %i, refCount = %d , state = %d\r\n" ,iPidCtlIndex , pPidCtl->nRefCount , pPidCtl->eState); |
|---|
| 1403 | #endif |
|---|
| 1404 | |
|---|
| 1405 | |
|---|
| 1406 | if ( pPidCtl->nRefCount == 0 && pPidCtl->eState == PCS_INIT ) { |
|---|
| 1407 | pPidCtl->eState = PCS_RAW; |
|---|
| 1408 | } |
|---|
| 1409 | |
|---|
| 1410 | return DHL_OK; |
|---|
| 1411 | |
|---|
| 1412 | } |
|---|
| 1413 | |
|---|
| 1414 | |
|---|
| 1415 | /*state change to PCS_INIT : pidCtl LockÀ» ¹Ì¸® °É°í È£Ãâ.*/ |
|---|
| 1416 | DHL_RESULT DD_PSI_OpenPidCtl( PSI_INFRA_CTL_t *pPsiInfra , int iPidCtlIndex ) |
|---|
| 1417 | { |
|---|
| 1418 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1419 | PSI_PID_CTL_t *pPidCtl = NULL; |
|---|
| 1420 | |
|---|
| 1421 | if( !pPsiInfra ) |
|---|
| 1422 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1423 | |
|---|
| 1424 | if( iPidCtlIndex > MAX_PID_FILTER_CNT ) |
|---|
| 1425 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1426 | |
|---|
| 1427 | #if DEBUG |
|---|
| 1428 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_OpenPidCtl : iPidCtlIndex = %i\r\n" ,iPidCtlIndex ); |
|---|
| 1429 | #endif |
|---|
| 1430 | |
|---|
| 1431 | pPidCtl = &(pPsiInfra->aPidCtl[iPidCtlIndex]); |
|---|
| 1432 | |
|---|
| 1433 | if ( pPidCtl->nRefCount == 0 ) { |
|---|
| 1434 | pPidCtl->eState = PCS_INIT; |
|---|
| 1435 | } |
|---|
| 1436 | |
|---|
| 1437 | return (DHL_RESULT)dhlResult; |
|---|
| 1438 | } |
|---|
| 1439 | |
|---|
| 1440 | /*refCount decrease.*/ |
|---|
| 1441 | DHL_RESULT DD_PSI_ReleasePidCtl ( PSI_INFRA_CTL_t *pPsiInfra , int iPidCtlIndex ) |
|---|
| 1442 | { |
|---|
| 1443 | int i=0; |
|---|
| 1444 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1445 | |
|---|
| 1446 | if(!pPsiInfra) |
|---|
| 1447 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1448 | |
|---|
| 1449 | if( iPidCtlIndex > MAX_PID_FILTER_CNT) |
|---|
| 1450 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1451 | |
|---|
| 1452 | #if DEBUG |
|---|
| 1453 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_ReleasePidCtl\r\n"); |
|---|
| 1454 | #endif |
|---|
| 1455 | |
|---|
| 1456 | |
|---|
| 1457 | dhlResult = DD_PSI_LockPidCtlArray( pPsiInfra , OS_WAIT_FOREVER ); |
|---|
| 1458 | if( dhlResult != DHL_OK ) |
|---|
| 1459 | { |
|---|
| 1460 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ReleasePidCtl : timeout.\r\n"); |
|---|
| 1461 | return dhlResult; |
|---|
| 1462 | } |
|---|
| 1463 | |
|---|
| 1464 | |
|---|
| 1465 | |
|---|
| 1466 | if( pPsiInfra->aPidCtl[iPidCtlIndex].nRefCount <= 0) |
|---|
| 1467 | { |
|---|
| 1468 | #if DEBUG |
|---|
| 1469 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "eState = PCS_RAW set.\r\n"); |
|---|
| 1470 | #endif |
|---|
| 1471 | |
|---|
| 1472 | |
|---|
| 1473 | pPsiInfra->aPidCtl[iPidCtlIndex].nRefCount = 0; |
|---|
| 1474 | pPsiInfra->aPidCtl[i].eState = PCS_RAW; |
|---|
| 1475 | dhlResult = DHL_FAIL_INVALID_PARAM; |
|---|
| 1476 | goto GOOUT; |
|---|
| 1477 | } |
|---|
| 1478 | |
|---|
| 1479 | --(pPsiInfra->aPidCtl[iPidCtlIndex].nRefCount); |
|---|
| 1480 | #if DEBUG |
|---|
| 1481 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ReleasePidCtl, pid = 0x%x, -nRefCount = %d , nRunn = %d , state = %d\r\n" , |
|---|
| 1482 | pPsiInfra->aPidCtl[iPidCtlIndex].uiPid , |
|---|
| 1483 | pPsiInfra->aPidCtl[iPidCtlIndex].nRefCount, |
|---|
| 1484 | pPsiInfra->aPidCtl[iPidCtlIndex].nRefCountRunning, |
|---|
| 1485 | pPsiInfra->aPidCtl[iPidCtlIndex].eState ); |
|---|
| 1486 | #endif |
|---|
| 1487 | |
|---|
| 1488 | |
|---|
| 1489 | if(pPsiInfra->aPidCtl[iPidCtlIndex].nRefCount == 0 ) |
|---|
| 1490 | { |
|---|
| 1491 | int i = 0; |
|---|
| 1492 | /*exception case : why this happend?*/ |
|---|
| 1493 | for( i = 0 ; i < pPsiInfra->aPidCtl[iPidCtlIndex].nRefCountRunning ; i++ ) |
|---|
| 1494 | { |
|---|
| 1495 | DD_PSI_StopPidCtl( pPsiInfra , iPidCtlIndex ); |
|---|
| 1496 | } |
|---|
| 1497 | |
|---|
| 1498 | DD_PSI_ClosePidCtl( pPsiInfra , iPidCtlIndex ); |
|---|
| 1499 | |
|---|
| 1500 | } |
|---|
| 1501 | |
|---|
| 1502 | GOOUT : |
|---|
| 1503 | |
|---|
| 1504 | |
|---|
| 1505 | DD_PSI_UnlockPidCtlArray( pPsiInfra ); |
|---|
| 1506 | |
|---|
| 1507 | |
|---|
| 1508 | return dhlResult; |
|---|
| 1509 | } |
|---|
| 1510 | |
|---|
| 1511 | /*refCount increase.*/ |
|---|
| 1512 | DHL_RESULT DD_PSI_GetPidCtl( PSI_INFRA_CTL_t *pPsiInfra , unsigned int pid, int *iPidCtlIndex ) |
|---|
| 1513 | { |
|---|
| 1514 | int i = 0; |
|---|
| 1515 | unsigned int iFirstRawPidCtlIndex = 0xffffffff; |
|---|
| 1516 | DHL_RESULT dhlResult = DHL_FAIL_NOT_FOUND; |
|---|
| 1517 | DS_BOOL bFound = _FALSE_; |
|---|
| 1518 | |
|---|
| 1519 | if(!pPsiInfra) |
|---|
| 1520 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1521 | |
|---|
| 1522 | #if DEBUG |
|---|
| 1523 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_GetPidCtl\r\n"); |
|---|
| 1524 | #endif |
|---|
| 1525 | |
|---|
| 1526 | |
|---|
| 1527 | dhlResult = DD_PSI_LockPidCtlArray( pPsiInfra , OS_WAIT_FOREVER ); |
|---|
| 1528 | if( dhlResult != DHL_OK ) |
|---|
| 1529 | { |
|---|
| 1530 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : timeout.\r\n"); |
|---|
| 1531 | return dhlResult; |
|---|
| 1532 | } |
|---|
| 1533 | |
|---|
| 1534 | |
|---|
| 1535 | for( i = 0 ; i < MAX_PID_FILTER_CNT ; i++ ) |
|---|
| 1536 | { |
|---|
| 1537 | /*try to find the same pid among already allcoated pid-Ctls*/ |
|---|
| 1538 | if( pPsiInfra->aPidCtl[i].eState != PCS_RAW ) |
|---|
| 1539 | { |
|---|
| 1540 | if( pPsiInfra->aPidCtl[i].uiPid == pid ) |
|---|
| 1541 | { |
|---|
| 1542 | ++(pPsiInfra->aPidCtl[i].nRefCount); |
|---|
| 1543 | dhlResult = DHL_OK; |
|---|
| 1544 | *iPidCtlIndex = i; |
|---|
| 1545 | |
|---|
| 1546 | #if DEBUG |
|---|
| 1547 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : already exist pid-ctl. refn = %d , state = %d , index =%d \r\n", \ |
|---|
| 1548 | pPsiInfra->aPidCtl[i].nRefCount , pPsiInfra->aPidCtl[i].eState , i ); |
|---|
| 1549 | #endif |
|---|
| 1550 | |
|---|
| 1551 | bFound = _TRUE_; |
|---|
| 1552 | break; |
|---|
| 1553 | } |
|---|
| 1554 | } |
|---|
| 1555 | else |
|---|
| 1556 | { |
|---|
| 1557 | if( iFirstRawPidCtlIndex == 0xffffffff ) |
|---|
| 1558 | iFirstRawPidCtlIndex = i; |
|---|
| 1559 | } |
|---|
| 1560 | } |
|---|
| 1561 | |
|---|
| 1562 | /*if not found it among already allocated pid-Ctls.*/ |
|---|
| 1563 | if( bFound == _FALSE_) |
|---|
| 1564 | { |
|---|
| 1565 | if( iFirstRawPidCtlIndex == 0xffffffff ) |
|---|
| 1566 | { |
|---|
| 1567 | #if DEBUG |
|---|
| 1568 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : no more pidFilter\r\n"); |
|---|
| 1569 | #endif |
|---|
| 1570 | |
|---|
| 1571 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 1572 | goto GOOUT; |
|---|
| 1573 | } |
|---|
| 1574 | |
|---|
| 1575 | *iPidCtlIndex = iFirstRawPidCtlIndex; |
|---|
| 1576 | |
|---|
| 1577 | dhlResult = DD_PSI_OpenPidCtl( pPsiInfra , iFirstRawPidCtlIndex ); |
|---|
| 1578 | if( dhlResult == DHL_OK ) |
|---|
| 1579 | { |
|---|
| 1580 | ++(pPsiInfra->aPidCtl[iFirstRawPidCtlIndex].nRefCount); |
|---|
| 1581 | pPsiInfra->aPidCtl[iFirstRawPidCtlIndex].uiPid = pid; |
|---|
| 1582 | |
|---|
| 1583 | } |
|---|
| 1584 | else |
|---|
| 1585 | { |
|---|
| 1586 | pPsiInfra->aPidCtl[iFirstRawPidCtlIndex].eState = PCS_RAW; |
|---|
| 1587 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : DD_PSI_OpenPidCtl returned error(0x%x)\r\n", dhlResult ); |
|---|
| 1588 | } |
|---|
| 1589 | } |
|---|
| 1590 | |
|---|
| 1591 | GOOUT: |
|---|
| 1592 | |
|---|
| 1593 | |
|---|
| 1594 | DD_PSI_UnlockPidCtlArray( pPsiInfra ); |
|---|
| 1595 | |
|---|
| 1596 | |
|---|
| 1597 | return dhlResult; |
|---|
| 1598 | } |
|---|
| 1599 | |
|---|
| 1600 | static void DD_PSI_ReleaseAllPidCtls( PSI_INFRA_CTL_t *pPsiInfra ) |
|---|
| 1601 | { |
|---|
| 1602 | int i; |
|---|
| 1603 | int j; |
|---|
| 1604 | int count; |
|---|
| 1605 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1606 | |
|---|
| 1607 | if( !pPsiInfra ) |
|---|
| 1608 | return; |
|---|
| 1609 | |
|---|
| 1610 | DD_PSI_LockPidCtlArray( pPsiInfra , OS_WAIT_FOREVER ); |
|---|
| 1611 | if( dhlResult != DHL_OK ) |
|---|
| 1612 | { |
|---|
| 1613 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_GetPidCtl : timeout.\r\n"); |
|---|
| 1614 | } |
|---|
| 1615 | |
|---|
| 1616 | for( i = 0 ; i < MAX_PID_FILTER_CNT ; i++ ) |
|---|
| 1617 | { |
|---|
| 1618 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1619 | |
|---|
| 1620 | /*exception case 1:*/ |
|---|
| 1621 | count = pPsiInfra->aPidCtl[i].nRefCountRunning ; |
|---|
| 1622 | for( j = 0 ; j < count ; j++) |
|---|
| 1623 | { |
|---|
| 1624 | dhlResult = DD_PSI_StopPidCtl(pPsiInfra , i ); |
|---|
| 1625 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ReleaseAllPidCtls: DD_PSI_StopPidCtl call(%d).\r\n" , i); |
|---|
| 1626 | } |
|---|
| 1627 | |
|---|
| 1628 | /*exception case 2:*/ |
|---|
| 1629 | count = pPsiInfra->aPidCtl[i].nRefCount; |
|---|
| 1630 | for( j = 0 ; j < count ; j++) |
|---|
| 1631 | { |
|---|
| 1632 | dhlResult = DD_PSI_ReleasePidCtl(pPsiInfra , i ); |
|---|
| 1633 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ReleaseAllPidCtls: DD_PSI_ClosePidCtl call(%d).\r\n" , i); |
|---|
| 1634 | } |
|---|
| 1635 | } |
|---|
| 1636 | |
|---|
| 1637 | DD_PSI_UnlockPidCtlArray( pPsiInfra ); |
|---|
| 1638 | } |
|---|
| 1639 | |
|---|
| 1640 | DHL_RESULT DD_PSI_LockPidCtlArray ( PSI_INFRA_CTL_t *pPsiInfra , int timeOut ) |
|---|
| 1641 | { |
|---|
| 1642 | DS_U32 res; |
|---|
| 1643 | |
|---|
| 1644 | if( !pPsiInfra) |
|---|
| 1645 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1646 | |
|---|
| 1647 | if( !(pPsiInfra->hPidCtlAccessSema4) ) |
|---|
| 1648 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1649 | |
|---|
| 1650 | #if DEBUG |
|---|
| 1651 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockPidCtlArray. before sema lock\r\n"); |
|---|
| 1652 | #endif |
|---|
| 1653 | |
|---|
| 1654 | res = OS_TakeSemaphore_Wait(pPsiInfra->hPidCtlAccessSema4 , timeOut ); |
|---|
| 1655 | if ( res ) { |
|---|
| 1656 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockPidCtlArray : OS_TakeSemaphore_Wait timeout.\n"); |
|---|
| 1657 | return DHL_FAIL_TIMEOUT; |
|---|
| 1658 | } |
|---|
| 1659 | |
|---|
| 1660 | #if DEBUG |
|---|
| 1661 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockPidCtlArray. after sema lock\r\n"); |
|---|
| 1662 | #endif |
|---|
| 1663 | |
|---|
| 1664 | return DHL_OK; |
|---|
| 1665 | } |
|---|
| 1666 | |
|---|
| 1667 | |
|---|
| 1668 | DHL_RESULT DD_PSI_UnlockPidCtlArray ( PSI_INFRA_CTL_t *pPsiInfra ) |
|---|
| 1669 | { |
|---|
| 1670 | DS_U32 res; |
|---|
| 1671 | |
|---|
| 1672 | if( !pPsiInfra ) |
|---|
| 1673 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1674 | |
|---|
| 1675 | if( !pPsiInfra->hPidCtlAccessSema4 ) |
|---|
| 1676 | return DHL_FAIL_INVALID_PARAM; |
|---|
| 1677 | |
|---|
| 1678 | res = OS_GiveSemaphore(pPsiInfra->hPidCtlAccessSema4); |
|---|
| 1679 | if ( res ) |
|---|
| 1680 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "ERROR, LINE=%d\n", __LINE__); |
|---|
| 1681 | |
|---|
| 1682 | return DHL_OK; |
|---|
| 1683 | } |
|---|
| 1684 | |
|---|
| 1685 | void DD_PSI_PrintListElem( PSI_LIST_HEADER_t *pListHeader ) |
|---|
| 1686 | { |
|---|
| 1687 | int i = 0; |
|---|
| 1688 | PSI_LIST_ELEM_t *pElem = NULL; |
|---|
| 1689 | |
|---|
| 1690 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_PrintListElem : nCount = %d \r\n", pListHeader->nCount ); |
|---|
| 1691 | |
|---|
| 1692 | pElem = pListHeader->pElem; |
|---|
| 1693 | while(pElem) { |
|---|
| 1694 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, " %d elem : next = 0x%lx , 0x%lx , prev = 0x%lx\r\n", |
|---|
| 1695 | i, (DS_U32)pElem->pNext, (DS_U32)pElem, (DS_U32)pElem->pPrev ); |
|---|
| 1696 | pElem = pElem->pPrev; |
|---|
| 1697 | i++; |
|---|
| 1698 | } |
|---|
| 1699 | } |
|---|
| 1700 | |
|---|
| 1701 | /*header ÀÇ pElemÀÌ ³ªÁß¿¡ addµÈ element°¡ µÇµµ·Ï ÇÏÀÚ.*/ |
|---|
| 1702 | DHL_RESULT DD_PSI_AddElemIntoList(PSI_LIST_HEADER_t *pListHeader , void * pElemToInsert ) |
|---|
| 1703 | { |
|---|
| 1704 | PSI_LIST_ELEM_t *pAddElem = pElemToInsert; |
|---|
| 1705 | |
|---|
| 1706 | if(!pAddElem || !pListHeader) |
|---|
| 1707 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1708 | |
|---|
| 1709 | #if DEBUG |
|---|
| 1710 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_AddElemIntoList. new elem = 0x%x \r\n" , pAddElem ); |
|---|
| 1711 | #endif |
|---|
| 1712 | |
|---|
| 1713 | pAddElem->pPrev = NULL; |
|---|
| 1714 | pAddElem->pNext = NULL; |
|---|
| 1715 | |
|---|
| 1716 | if(pListHeader->pElem) { |
|---|
| 1717 | pListHeader->pElem->pNext = pAddElem; |
|---|
| 1718 | pAddElem->pPrev = pListHeader->pElem; |
|---|
| 1719 | } |
|---|
| 1720 | |
|---|
| 1721 | pListHeader->pElem = pAddElem; |
|---|
| 1722 | ++(pListHeader->nCount); |
|---|
| 1723 | |
|---|
| 1724 | #if DEBUG |
|---|
| 1725 | DD_PSI_PrintListElem(pListHeader); |
|---|
| 1726 | #endif |
|---|
| 1727 | |
|---|
| 1728 | return DHL_OK; |
|---|
| 1729 | } |
|---|
| 1730 | |
|---|
| 1731 | /*header ÀÇ pElemÀÌ °¡Àå ÃÖ±Ù¿¡ addµÈ element°¡ µÇµµ·Ï ÇÏÀÚ.*/ |
|---|
| 1732 | DHL_RESULT DD_PSI_DelElemFromList(PSI_LIST_HEADER_t *pListHeader , void * pElemToDelete ) |
|---|
| 1733 | { |
|---|
| 1734 | PSI_LIST_ELEM_t *pDelElem = NULL; |
|---|
| 1735 | DHL_RESULT dhlResult = DHL_FAIL_NOT_FOUND; |
|---|
| 1736 | |
|---|
| 1737 | if(!pElemToDelete || !pListHeader) |
|---|
| 1738 | return DHL_FAIL_NULL_POINTER; |
|---|
| 1739 | |
|---|
| 1740 | pDelElem = pListHeader->pElem; |
|---|
| 1741 | |
|---|
| 1742 | #if DEBUG |
|---|
| 1743 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_DelElemFromList. count = %d , old elem = 0x%x \r\n" , pListHeader->nCount ,pElemToDelete ); |
|---|
| 1744 | #endif |
|---|
| 1745 | |
|---|
| 1746 | while(pDelElem) |
|---|
| 1747 | { |
|---|
| 1748 | if( pDelElem == (PSI_LIST_ELEM_t *)pElemToDelete ) |
|---|
| 1749 | { |
|---|
| 1750 | if( pDelElem->pNext ) |
|---|
| 1751 | { |
|---|
| 1752 | pDelElem->pNext->pPrev = pDelElem->pPrev; |
|---|
| 1753 | } |
|---|
| 1754 | else /*header¶ó´Â ¼Ò¸®³×.*/ |
|---|
| 1755 | { |
|---|
| 1756 | if( pDelElem->pPrev ) |
|---|
| 1757 | { |
|---|
| 1758 | pDelElem->pPrev->pNext = NULL; |
|---|
| 1759 | |
|---|
| 1760 | } |
|---|
| 1761 | pListHeader->pElem = pDelElem->pPrev; |
|---|
| 1762 | } |
|---|
| 1763 | |
|---|
| 1764 | if( pDelElem->pPrev ) |
|---|
| 1765 | { |
|---|
| 1766 | pDelElem->pPrev->pNext = pDelElem->pNext; |
|---|
| 1767 | } |
|---|
| 1768 | else /*tailÀ̶õ ¼Ò¸®.*/ |
|---|
| 1769 | { |
|---|
| 1770 | if( pDelElem->pNext ) |
|---|
| 1771 | { |
|---|
| 1772 | pDelElem->pNext->pPrev = NULL; |
|---|
| 1773 | } |
|---|
| 1774 | } |
|---|
| 1775 | |
|---|
| 1776 | --(pListHeader->nCount); |
|---|
| 1777 | |
|---|
| 1778 | |
|---|
| 1779 | if(pListHeader->nCount == 0) |
|---|
| 1780 | pListHeader->pElem = NULL; |
|---|
| 1781 | |
|---|
| 1782 | #if DEBUG |
|---|
| 1783 | DD_PSI_PrintListElem(pListHeader); |
|---|
| 1784 | #endif |
|---|
| 1785 | |
|---|
| 1786 | dhlResult = DHL_OK; |
|---|
| 1787 | break; |
|---|
| 1788 | } |
|---|
| 1789 | |
|---|
| 1790 | pDelElem = pDelElem->pPrev; |
|---|
| 1791 | } |
|---|
| 1792 | |
|---|
| 1793 | return dhlResult; |
|---|
| 1794 | } |
|---|
| 1795 | |
|---|
| 1796 | |
|---|
| 1797 | |
|---|
| 1798 | DHL_RESULT DD_PSI_MonitorPSIPid( void *pPsiInfo, |
|---|
| 1799 | DS_U16 pid, |
|---|
| 1800 | PSIMode psiMode, |
|---|
| 1801 | PSIUpdateMode updateMode, |
|---|
| 1802 | PSIMask_t *prefList, |
|---|
| 1803 | DS_U16 maxData, |
|---|
| 1804 | DS_U16 maxSections, |
|---|
| 1805 | PSIEventProc_f eventProc, |
|---|
| 1806 | DS_U32 userParam, |
|---|
| 1807 | void **returnPSIControl ) |
|---|
| 1808 | |
|---|
| 1809 | { |
|---|
| 1810 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1811 | |
|---|
| 1812 | PSI_INFRA_CTL_t *pPsiInfra = NULL; |
|---|
| 1813 | PSI_SECTION_CTL_t * pSectionCtl = NULL; |
|---|
| 1814 | PSIContext_t *pPsiContext = NULL; |
|---|
| 1815 | // DS_BOOL bExist = _FALSE_; |
|---|
| 1816 | |
|---|
| 1817 | #if DEBUG |
|---|
| 1818 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the MonitorPSIPid.\r\n"); |
|---|
| 1819 | #endif |
|---|
| 1820 | |
|---|
| 1821 | *returnPSIControl = NULL; |
|---|
| 1822 | |
|---|
| 1823 | pPsiInfra = (PSI_INFRA_CTL_t *)pPsiInfo; |
|---|
| 1824 | |
|---|
| 1825 | #if DEBUG |
|---|
| 1826 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "pPsiInfra = 0x%x. pid = %d , entries.value = 0x%x \r\n" , pPsiInfra ,pid , prefList->entries[0].value); |
|---|
| 1827 | #endif |
|---|
| 1828 | |
|---|
| 1829 | #if DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 1830 | dhlResult = DD_PSI_LockSectCtlArray( pPsiInfra , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 1831 | if( dhlResult != DHL_OK ) |
|---|
| 1832 | { |
|---|
| 1833 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray... : timeout.\r\n"); |
|---|
| 1834 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 1835 | } |
|---|
| 1836 | #endif |
|---|
| 1837 | |
|---|
| 1838 | /*ATI section control unitÀ» ÇÒ´ç ¹Þ´Â´Ù.*/ |
|---|
| 1839 | dhlResult = DD_PSI_GetSectionCtl( pPsiInfra , pid , prefList , &pSectionCtl ); |
|---|
| 1840 | if( dhlResult != DHL_OK || pSectionCtl == NULL ) |
|---|
| 1841 | { |
|---|
| 1842 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPid : PSI_GetSectionCtl has returned NULL.\r\n"); |
|---|
| 1843 | goto GOOUT2; |
|---|
| 1844 | } |
|---|
| 1845 | |
|---|
| 1846 | |
|---|
| 1847 | dhlResult = DD_PSI_LockSectionCtl( pSectionCtl , OS_WAIT_FOREVER ); |
|---|
| 1848 | if( dhlResult != DHL_OK ) |
|---|
| 1849 | { |
|---|
| 1850 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPid : error. DD_PSI_LockSectionCtl timeout.\r\n"); |
|---|
| 1851 | goto GOOUT2; |
|---|
| 1852 | } |
|---|
| 1853 | |
|---|
| 1854 | /*second, allocate current psi context for gathering mpeg sections.*/ |
|---|
| 1855 | /*±âÁ¸¿¡ registerÇϰí releaseÇÏÁö ¾ÊÀº context°¡ ÀÖÀ¸¸é ¸ÕÀú releaseÇÑ´Ù.*/ |
|---|
| 1856 | if( pSectionCtl->pContext ) |
|---|
| 1857 | { |
|---|
| 1858 | DD_PSI_ReleasePSICtx( pSectionCtl->pContext); |
|---|
| 1859 | pSectionCtl->pContext = NULL; |
|---|
| 1860 | } |
|---|
| 1861 | |
|---|
| 1862 | |
|---|
| 1863 | /*»õ·Î ¹Þ±â¸¦ ½Ãµµ ÇÑ´Ù.*/ |
|---|
| 1864 | dhlResult = DD_PSI_RegisterPSICtx( (void *)pSectionCtl, |
|---|
| 1865 | pid, |
|---|
| 1866 | psiMode, |
|---|
| 1867 | updateMode, |
|---|
| 1868 | prefList, |
|---|
| 1869 | maxData, |
|---|
| 1870 | maxSections, |
|---|
| 1871 | eventProc, |
|---|
| 1872 | userParam , |
|---|
| 1873 | cbStopSectionCtl, |
|---|
| 1874 | (DS_U32)(void *)(pSectionCtl->pParent), |
|---|
| 1875 | _FALSE_, |
|---|
| 1876 | (void **)&pPsiContext ); |
|---|
| 1877 | if( dhlResult != DHL_OK || pPsiContext == NULL ) |
|---|
| 1878 | { |
|---|
| 1879 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_MonitorPSIPid : DD_PSI_RegisterPSICtx return erorr(0x%x)\r\n" , dhlResult ); |
|---|
| 1880 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 1881 | //DD_PSI_ReleaseSectionCtl(pSectionCtl); |
|---|
| 1882 | goto GOOUT1; |
|---|
| 1883 | } |
|---|
| 1884 | |
|---|
| 1885 | |
|---|
| 1886 | pSectionCtl->pContext = pPsiContext; |
|---|
| 1887 | dhlResult = DD_PSI_StartSectionCtl (pSectionCtl, prefList); |
|---|
| 1888 | if ( dhlResult == DHL_OK ) { |
|---|
| 1889 | *returnPSIControl = (void *)pSectionCtl; |
|---|
| 1890 | } else { |
|---|
| 1891 | DD_PSI_StopSectionCtl( pSectionCtl ); |
|---|
| 1892 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPid : PSI_StartSectionCtl has returned error(0x%x)\r\n" , dhlResult); |
|---|
| 1893 | dhlResult = DHL_FAIL_CORE_DRIVER; |
|---|
| 1894 | } |
|---|
| 1895 | |
|---|
| 1896 | GOOUT1: |
|---|
| 1897 | DD_PSI_UnlockSectionCtl( pSectionCtl ); |
|---|
| 1898 | |
|---|
| 1899 | GOOUT2: |
|---|
| 1900 | if( dhlResult != DHL_OK ) |
|---|
| 1901 | DD_PSI_ReleaseSectionCtl( pSectionCtl ); |
|---|
| 1902 | |
|---|
| 1903 | #if DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 1904 | DD_PSI_UnlockSectCtlArray( pPsiInfra ); |
|---|
| 1905 | #endif |
|---|
| 1906 | |
|---|
| 1907 | return dhlResult; |
|---|
| 1908 | } |
|---|
| 1909 | |
|---|
| 1910 | /*it is added to support Big Size SI.*/ |
|---|
| 1911 | DHL_RESULT DD_PSI_MonitorPSIPidBig( void *pPsiInfo, |
|---|
| 1912 | DS_U16 pid, |
|---|
| 1913 | PSIMode psiMode, |
|---|
| 1914 | PSIUpdateMode updateMode, |
|---|
| 1915 | PSIMask_t *prefList, |
|---|
| 1916 | DS_U16 maxData, |
|---|
| 1917 | DS_U16 maxSections, |
|---|
| 1918 | PSIEventProc_f eventProc, |
|---|
| 1919 | DS_U32 userParam, |
|---|
| 1920 | void **returnPSIControl ) |
|---|
| 1921 | |
|---|
| 1922 | { |
|---|
| 1923 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 1924 | |
|---|
| 1925 | PSI_INFRA_CTL_t *pPsiInfra = NULL; |
|---|
| 1926 | PSI_SECTION_CTL_t * pSectionCtl = NULL; |
|---|
| 1927 | PSIContext_t *pPsiContext = NULL; |
|---|
| 1928 | |
|---|
| 1929 | #if DEBUG |
|---|
| 1930 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the MonitorPSIPidBig.\r\n"); |
|---|
| 1931 | #endif |
|---|
| 1932 | |
|---|
| 1933 | *returnPSIControl = NULL; |
|---|
| 1934 | |
|---|
| 1935 | |
|---|
| 1936 | pPsiInfra = (PSI_INFRA_CTL_t *)pPsiInfo; |
|---|
| 1937 | |
|---|
| 1938 | #if DEBUG |
|---|
| 1939 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "pPsiInfra = 0x%x. pid = %d , entries.value = 0x%x \r\n" , pPsiInfra ,pid , prefList->entries[0].value); |
|---|
| 1940 | #endif |
|---|
| 1941 | |
|---|
| 1942 | #if 0 |
|---|
| 1943 | bExist = DD_PSI_ExistSectionCtl( pPsiInfra, pid, prefList ); |
|---|
| 1944 | |
|---|
| 1945 | if( bExist == _TRUE_ ) |
|---|
| 1946 | { |
|---|
| 1947 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPid : it's already exist filter. so, reject your request. \r\n"); |
|---|
| 1948 | dhlResult = DHL_FAIL_NOT_AVAILABLE; |
|---|
| 1949 | goto GOOUT; |
|---|
| 1950 | } |
|---|
| 1951 | #endif |
|---|
| 1952 | |
|---|
| 1953 | #if DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 1954 | dhlResult = DD_PSI_LockSectCtlArray( pPsiInfra , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 1955 | if( dhlResult != DHL_OK ) |
|---|
| 1956 | { |
|---|
| 1957 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray... : timeout.\r\n"); |
|---|
| 1958 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 1959 | } |
|---|
| 1960 | #endif |
|---|
| 1961 | |
|---|
| 1962 | /*ATI section control unitÀ» ÇÒ´ç ¹Þ´Â´Ù.*/ |
|---|
| 1963 | dhlResult = DD_PSI_GetSectionCtlBig( pPsiInfra , pid , prefList , &pSectionCtl ); |
|---|
| 1964 | if( dhlResult != DHL_OK || pSectionCtl == NULL ) |
|---|
| 1965 | { |
|---|
| 1966 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPidBig : PSI_GetSectionCtlBig has returned NULL.\r\n"); |
|---|
| 1967 | goto GOOUT2; |
|---|
| 1968 | } |
|---|
| 1969 | |
|---|
| 1970 | |
|---|
| 1971 | dhlResult = DD_PSI_LockSectionCtl( pSectionCtl , OS_WAIT_FOREVER ); |
|---|
| 1972 | if( dhlResult != DHL_OK ) |
|---|
| 1973 | { |
|---|
| 1974 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "PSI_MonitorPSIPidBig : error. DD_PSI_LockSectionCtl timeout.\r\n"); |
|---|
| 1975 | goto GOOUT1; |
|---|
| 1976 | } |
|---|
| 1977 | |
|---|
| 1978 | /*second, allocate current psi context for gathering mpeg sections.*/ |
|---|
| 1979 | /*±âÁ¸¿¡ registerÇϰí releaseÇÏÁö ¾ÊÀº context°¡ ÀÖÀ¸¸é ¸ÕÀú releaseÇÑ´Ù.*/ |
|---|
| 1980 | if( pSectionCtl->pContext ) |
|---|
| 1981 | { |
|---|
| 1982 | DD_PSI_ReleasePSICtx( pSectionCtl->pContext); |
|---|
| 1983 | pSectionCtl->pContext = NULL; |
|---|
| 1984 | } |
|---|
| 1985 | |
|---|
| 1986 | |
|---|
| 1987 | /*»õ·Î ¹Þ±â¸¦ ½Ãµµ ÇÑ´Ù.*/ |
|---|
| 1988 | dhlResult = DD_PSI_RegisterPSICtx( (void *)pSectionCtl, |
|---|
| 1989 | pid, |
|---|
| 1990 | psiMode, |
|---|
| 1991 | updateMode, |
|---|
| 1992 | prefList, |
|---|
| 1993 | maxData, |
|---|
| 1994 | maxSections, |
|---|
| 1995 | eventProc, |
|---|
| 1996 | userParam , |
|---|
| 1997 | cbStopSectionCtl, |
|---|
| 1998 | (DS_U32)(void *)(pSectionCtl->pParent), |
|---|
| 1999 | _FALSE_, |
|---|
| 2000 | (void **)&pPsiContext ); |
|---|
| 2001 | |
|---|
| 2002 | |
|---|
| 2003 | if( dhlResult != DHL_OK || pPsiContext == NULL ) |
|---|
| 2004 | { |
|---|
| 2005 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_MonitorPSIPidBig : DD_PSI_RegisterPSICtx return erorr(0x%x)\r\n" , dhlResult ); |
|---|
| 2006 | dhlResult = DHL_FAIL_OUT_OF_RESOURCE; |
|---|
| 2007 | DD_PSI_ReleaseSectionCtl(pSectionCtl); |
|---|
| 2008 | goto GOOUT1; |
|---|
| 2009 | } |
|---|
| 2010 | |
|---|
| 2011 | |
|---|
| 2012 | pSectionCtl->pContext = pPsiContext; |
|---|
| 2013 | dhlResult = DD_PSI_StartSectionCtl (pSectionCtl, prefList); |
|---|
| 2014 | if ( dhlResult == DHL_OK ) { |
|---|
| 2015 | *returnPSIControl = (void *)pSectionCtl; |
|---|
| 2016 | } else { |
|---|
| 2017 | DD_PSI_StopSectionCtl( pSectionCtl ); |
|---|
| 2018 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_MonitorPSIPidBig : PSI_StartSectionCtl has returned error(0x%x)\r\n" , dhlResult); |
|---|
| 2019 | dhlResult = DHL_FAIL_CORE_DRIVER; |
|---|
| 2020 | } |
|---|
| 2021 | |
|---|
| 2022 | GOOUT1: |
|---|
| 2023 | DD_PSI_UnlockSectionCtl( pSectionCtl ); |
|---|
| 2024 | |
|---|
| 2025 | GOOUT2: |
|---|
| 2026 | if ( dhlResult != DHL_OK ) { |
|---|
| 2027 | DD_PSI_ReleaseSectionCtl( pSectionCtl ); |
|---|
| 2028 | } |
|---|
| 2029 | |
|---|
| 2030 | #if DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 2031 | DD_PSI_UnlockSectCtlArray( pPsiInfra ); |
|---|
| 2032 | #endif |
|---|
| 2033 | |
|---|
| 2034 | return dhlResult; |
|---|
| 2035 | } |
|---|
| 2036 | |
|---|
| 2037 | DHL_RESULT DD_PSI_CancelPSIPid( DHL_PSI_HANDLE hPsiHandle, /*PSI_SECTION_CTL_t **/ void * pSectionCtl ) |
|---|
| 2038 | { |
|---|
| 2039 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 2040 | PSI_INFRA_CTL_t *pPsiInfra = NULL; |
|---|
| 2041 | PSI_SECTION_CTL_t *pSectCtl = NULL; |
|---|
| 2042 | PSIContext_t *psiCtl; |
|---|
| 2043 | |
|---|
| 2044 | #if DEBUG |
|---|
| 2045 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_CancelPSIPid.\r\n"); |
|---|
| 2046 | #endif |
|---|
| 2047 | |
|---|
| 2048 | if(!hPsiHandle || !pSectionCtl) |
|---|
| 2049 | return DHL_FAIL_NULL_POINTER; |
|---|
| 2050 | |
|---|
| 2051 | pSectCtl = (PSI_SECTION_CTL_t *)pSectionCtl; |
|---|
| 2052 | pPsiInfra = (PSI_INFRA_CTL_t *)hPsiHandle; |
|---|
| 2053 | psiCtl = (PSIContext_t *)pSectCtl->pContext; |
|---|
| 2054 | |
|---|
| 2055 | #if DEBUG |
|---|
| 2056 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_CancelPSIPid : hPsiHandle = 0x%x , pSectionCtl = 0x%x\r\n" ,hPsiHandle , pSectCtl ); |
|---|
| 2057 | #endif |
|---|
| 2058 | |
|---|
| 2059 | #if DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 2060 | dhlResult = DD_PSI_LockSectCtlArray( pPsiInfra , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 2061 | if( dhlResult != DHL_OK ) |
|---|
| 2062 | { |
|---|
| 2063 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_LockSectCtlArray... : timeout.\r\n"); |
|---|
| 2064 | return DHL_FAIL_CORE_DRIVER; |
|---|
| 2065 | } |
|---|
| 2066 | #endif |
|---|
| 2067 | |
|---|
| 2068 | dhlResult = DD_PSI_LockSectionCtl(pSectCtl , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 2069 | if( dhlResult != DHL_OK ) |
|---|
| 2070 | { |
|---|
| 2071 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_CancelPSIPid : timeout.\r\n"); |
|---|
| 2072 | return dhlResult; |
|---|
| 2073 | } |
|---|
| 2074 | dhlResult = DD_PSI_StopSectionCtl( pSectCtl ); |
|---|
| 2075 | if ( dhlResult != DHL_OK ) { |
|---|
| 2076 | #if DEBUG |
|---|
| 2077 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_CancelPSIPid : DD_PSI_StopSectionCtl returned error(0x%x)\r\n" , dhlResult ); |
|---|
| 2078 | #endif |
|---|
| 2079 | |
|---|
| 2080 | dhlResult = DHL_FAIL_CORE_DRIVER; |
|---|
| 2081 | } |
|---|
| 2082 | |
|---|
| 2083 | #if 0 // ÀÏ´Ü »ç¿ëÇÏÁö ¸»°í, leakage°¡ °è¼ÓÇØ¼ »ý±â¸é »ç¿ëÇÏÀÚ. |
|---|
| 2084 | // |
|---|
| 2085 | // descriptor array°¡ ÇØÁ¦µÇÁö ¾Ê¾ÒÀ¸¸é, cancelÇÒ¶§ ÇØÁ¦ÇÏÀÚ. (hwatk/20060830) |
|---|
| 2086 | // |
|---|
| 2087 | if (psiCtl->curDataArray) { |
|---|
| 2088 | DD_PSI_FreePSIData(psiCtl->curDataArray); |
|---|
| 2089 | psiCtl->curDataArray = NULL; |
|---|
| 2090 | } |
|---|
| 2091 | if (psiCtl->nextDataArray) { |
|---|
| 2092 | DD_PSI_FreePSIData(psiCtl->nextDataArray); |
|---|
| 2093 | psiCtl->nextDataArray = NULL; |
|---|
| 2094 | } |
|---|
| 2095 | #endif |
|---|
| 2096 | |
|---|
| 2097 | DD_PSI_UnlockSectionCtl(pSectCtl); |
|---|
| 2098 | DD_PSI_ReleaseSectionCtl(pSectionCtl); |
|---|
| 2099 | |
|---|
| 2100 | #if DONOT_USE_LOCK_SECTCTRLARRAY |
|---|
| 2101 | DD_PSI_UnlockSectCtlArray( pPsiInfra ); |
|---|
| 2102 | #endif |
|---|
| 2103 | |
|---|
| 2104 | return dhlResult; |
|---|
| 2105 | |
|---|
| 2106 | } |
|---|
| 2107 | |
|---|
| 2108 | DHL_RESULT DD_PSI_ReadPSIData( DHL_TBL_HANDLE hTblHandle , PSIDataArray_t **returnPsi ) |
|---|
| 2109 | { |
|---|
| 2110 | |
|---|
| 2111 | PSIContext_t *psi = NULL; |
|---|
| 2112 | PSI_SECTION_CTL_t * pSectionCtl = (PSI_SECTION_CTL_t *)hTblHandle; |
|---|
| 2113 | DHL_RESULT dhlResult = DHL_OK; |
|---|
| 2114 | //DS_BOOL bExist = _FALSE_; |
|---|
| 2115 | |
|---|
| 2116 | #if DEBUG |
|---|
| 2117 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "in the DD_PSI_ReadPSIData. tblHandle = 0x%x \r\n" ,hTblHandle ); |
|---|
| 2118 | #endif |
|---|
| 2119 | |
|---|
| 2120 | if(!pSectionCtl) |
|---|
| 2121 | return DHL_FAIL_NULL_POINTER; |
|---|
| 2122 | |
|---|
| 2123 | |
|---|
| 2124 | dhlResult = DD_PSI_LockSectionCtl(pSectionCtl , OS_WAIT_FOREVER /*infinite*/ ); |
|---|
| 2125 | if( dhlResult != DHL_OK ) |
|---|
| 2126 | { |
|---|
| 2127 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "DD_PSI_ReadPSIData : timeout.\r\n"); |
|---|
| 2128 | return dhlResult; |
|---|
| 2129 | } |
|---|
| 2130 | |
|---|
| 2131 | |
|---|
| 2132 | |
|---|
| 2133 | |
|---|
| 2134 | psi = pSectionCtl->pContext; |
|---|
| 2135 | |
|---|
| 2136 | if(psi) |
|---|
| 2137 | dhlResult = DD_PSI_ReadPSIArray(psi , returnPsi); |
|---|
| 2138 | else |
|---|
| 2139 | dhlResult = DHL_FAIL_NULL_POINTER; |
|---|
| 2140 | |
|---|
| 2141 | //GOOUT: |
|---|
| 2142 | |
|---|
| 2143 | DD_PSI_UnlockSectionCtl( pSectionCtl ); |
|---|
| 2144 | return dhlResult; |
|---|
| 2145 | } |
|---|
| 2146 | |
|---|
| 2147 | |
|---|
| 2148 | void DD_PSI_FreePSIData(PSIDataArray_t *psiData ) |
|---|
| 2149 | { |
|---|
| 2150 | if(psiData) |
|---|
| 2151 | DD_PSI_FreePSIArray(psiData); |
|---|
| 2152 | } |
|---|
| 2153 | |
|---|
| 2154 | #if 0 |
|---|
| 2155 | ___Local_Functions____________() |
|---|
| 2156 | #endif |
|---|
| 2157 | |
|---|
| 2158 | void hdmx_dbg(int dbg) |
|---|
| 2159 | { |
|---|
| 2160 | g_Demux_Debug = dbg; |
|---|
| 2161 | } |
|---|
| 2162 | |
|---|
| 2163 | void hdmx_temp_dbg(int dbg) |
|---|
| 2164 | { |
|---|
| 2165 | g_Temp_Debug = dbg; |
|---|
| 2166 | } |
|---|
| 2167 | |
|---|
| 2168 | void dumpLeakSize(void) |
|---|
| 2169 | { |
|---|
| 2170 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "\n\n\nMemory leakage by PSI monitor\n\n\n"); |
|---|
| 2171 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "nCount = %d\n", g_TotalLeakCnt); |
|---|
| 2172 | DHL_DbgPrintf( gddPsiDbgLvl, DDDBG_PSI, "nSize = %d\n", g_TotalLeakSize); |
|---|
| 2173 | } |
|---|
| 2174 | |
|---|
| 2175 | void hdmx_stat(void) |
|---|
| 2176 | { |
|---|
| 2177 | printf("4k:%d, 1k:%d\n", g_FilterCount_4Kb, g_FilterCount_1Kb); |
|---|
| 2178 | } |
|---|