| 1 | /* |
|---|
| 2 | DMW_PsiAPI.c |
|---|
| 3 | |
|---|
| 4 | DST TV MW PSI Scan Module |
|---|
| 5 | |
|---|
| 6 | PSI Scan API implementation |
|---|
| 7 | |
|---|
| 8 | Copyright 2006~2009 Digital STREAM Technology, Inc. |
|---|
| 9 | All Rights Reserved |
|---|
| 10 | |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | #include "DMW_Platform.h" |
|---|
| 16 | |
|---|
| 17 | #define __DEFINE_PSIM_STRING__ |
|---|
| 18 | #include "DMW_PsiAPI.h" |
|---|
| 19 | #undef __DEFINE_PSIM_STRING__ |
|---|
| 20 | |
|---|
| 21 | #include "DMW_PsiEngine.h" |
|---|
| 22 | #include "DMW_PsiDatabase.h" |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | |
|---|
| 27 | |
|---|
| 28 | |
|---|
| 29 | #if COMMENT |
|---|
| 30 | ____API____(){} |
|---|
| 31 | #endif |
|---|
| 32 | |
|---|
| 33 | |
|---|
| 34 | /* |
|---|
| 35 | PSI moduleÀ» ÃʱâÈ ÇÑ´Ù. |
|---|
| 36 | */ |
|---|
| 37 | STATUS DMW_PSI_Init(void) |
|---|
| 38 | { |
|---|
| 39 | STATUS status = statusOK; |
|---|
| 40 | S_PSIM_CONTEXT *module; |
|---|
| 41 | |
|---|
| 42 | module = PSIE_InitEngine(); |
|---|
| 43 | DHL_ASSERT(module != NULL, "psiengine_init err"); |
|---|
| 44 | |
|---|
| 45 | status = PSITASK_Init(module); |
|---|
| 46 | DHL_ASSERT(status == statusOK, "psitask_init err"); |
|---|
| 47 | |
|---|
| 48 | return status; |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | /* |
|---|
| 52 | ƯÁ¤ ts portÀÇ PSI/PSIP µ¥ÀÌÅÍ scanÀ» ½ÃÀÛÇÑ´Ù. |
|---|
| 53 | ¿©±â¼ ÁöÁ¤ÇÏ´Â @rf´Â ´Ü¼øÈ÷ id ¿ëµµ·Î¸¸ »ç¿ëÀÌ µÇ¸ç, ½ÇÁ¦ FrontEnd ¼³Á¤Àº caller°¡ ´ã´ç. |
|---|
| 54 | |
|---|
| 55 | @tsd Çϳª´ç ÇϳªÀÇ scan ÀÛ¾÷ÀÌ °¡´ÉÇÏ´Ù. N°³ÀÇ tsd°¡ µ¿½Ã¿¡ scan µÉ ¼ö ÀÖ´Ù. |
|---|
| 56 | ÃÖ´ë tsd °¹¼ö´Â hardware ¸¶´Ù ´Ù¸¥µ¥, SW ³»ºÎÀûÀ¸·Î´Â MAX_TS_INPUT À¸·Î Á¦ÇѵǾî ÀÖ´Ù. |
|---|
| 57 | |
|---|
| 58 | flags: PSI_FLAGS_XXX °ªÀÇ Á¶ÇÕ. |
|---|
| 59 | |
|---|
| 60 | @program_number, @source_id ´Â PSI_FLAGS_AUTOSCAN °ú °°Àº ƯÁ¤ ¸ðµå¿¡¼´Â »ç¿ëµÇÁö ¾Ê´Â´Ù. |
|---|
| 61 | ±× ¿Ü¿¡´Â Á¤È®ÇÑ °ªÀ» ÁöÁ¤ÇØ Áà¾ß ÇÑ´Ù. |
|---|
| 62 | |
|---|
| 63 | */ |
|---|
| 64 | STATUS DMW_PSI_StartUpdate(tDHL_TSD tsd, int rf, int program_number, int source_id, |
|---|
| 65 | UINT32 flags, F_PSIM_EVENT_PROC userproc, UINT32 userparam) |
|---|
| 66 | { |
|---|
| 67 | |
|---|
| 68 | S_PSIM_USER_INPUT input; |
|---|
| 69 | |
|---|
| 70 | input.rf = rf; |
|---|
| 71 | input.program_number = program_number; |
|---|
| 72 | input.source_id = source_id; |
|---|
| 73 | input.flags = flags; |
|---|
| 74 | input.userproc = userproc; |
|---|
| 75 | input.userparam = userparam; |
|---|
| 76 | |
|---|
| 77 | // we can use local variable because we use sync'ed call. |
|---|
| 78 | // bWait should be "TRUE". |
|---|
| 79 | |
|---|
| 80 | return PSITASK_SendCommand(ePSIM_CMD_ScanStart, (UINT32)tsd, (UINT32)&input, TRUE); |
|---|
| 81 | // jump to PsiMsgHandler_ScanStart |
|---|
| 82 | } |
|---|
| 83 | |
|---|
| 84 | /* |
|---|
| 85 | ÁöÁ¤ÇÑ @tsd Æ÷Æ®ÀÇ µ¿ÀÛ ÁßÀÎ psi scan ÀÛ¾÷À» Áß´ÜÇÑ´Ù. |
|---|
| 86 | |
|---|
| 87 | ±× ¿ÜÀÇ tsd Æ÷Æ® scan ÀÛ¾÷Àº ¿µÇâ ¹ÞÁö ¾Ê°í °è¼Ó µÈ´Ù. |
|---|
| 88 | |
|---|
| 89 | */ |
|---|
| 90 | void DMW_PSI_CancelUpdate(tDHL_TSD tsd) |
|---|
| 91 | { |
|---|
| 92 | PSITASK_SendCommand(ePSIM_CMD_ScanStop, (UINT32)tsd, 0, TRUE); |
|---|
| 93 | // jump to PsiMsgHandler_ScanStop |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | |
|---|
| 97 | /* |
|---|
| 98 | PSI DBÀÇ °¢Á¾ Å×À̺íÀ» Á¦°Å. |
|---|
| 99 | |
|---|
| 100 | @rf ¸¦ ÁöÁ¤Çϸé ÇØ´ç rfÀÇ Tables ¸¸ »èÁ¦Çϰí, |
|---|
| 101 | @rf ·Î 0À» ÁöÁ¤ÇÏ¸é ¸ðµç TableµéÀ» »èÁ¦ÇÑ´Ù. |
|---|
| 102 | |
|---|
| 103 | */ |
|---|
| 104 | void DMW_PSI_DeleteTables(int rf) |
|---|
| 105 | { |
|---|
| 106 | PSITASK_SendCommand(ePSIM_CMD_DeleteTables, rf, 0, TRUE); |
|---|
| 107 | // jump to PsiMsgHandler_DeleteTables |
|---|
| 108 | } |
|---|
| 109 | |
|---|
| 110 | /* |
|---|
| 111 | PSI DB¿¡ Á¢±ÙÇϱâ À§Çؼ »ç¿ëÇÏ´Â mutex lock API. |
|---|
| 112 | |
|---|
| 113 | Rule: |
|---|
| 114 | PsiTask ¿¡¼ DB´Â ÀÚÀ¯·Ó°Ô ÀÐÀ» ¼ö ÀÖÀ½. |
|---|
| 115 | PsiTask ¿¡¼´Â Lock ÈÄ DB ¼öÁ¤ °¡´É. |
|---|
| 116 | |
|---|
| 117 | ÀÓÀÇ task¿¡¼´Â Lock ÈÄ DB Àб⠰¡´É. |
|---|
| 118 | ÀÓÀÇ task¿¡¼ DBÀÇ º¯°æÀº Àý´ë ±ÝÁö. |
|---|
| 119 | |
|---|
| 120 | */ |
|---|
| 121 | void DMW_PSI_LockDB(BOOL bLock) |
|---|
| 122 | { |
|---|
| 123 | PSIDB_LockDB(bLock); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | S_PSIM_CHINFO *DMW_PSI_GetChInfo(int rf) |
|---|
| 127 | { |
|---|
| 128 | return PSIDB_GetPsiChInfo(rf); |
|---|
| 129 | } |
|---|
| 130 | |
|---|
| 131 | S_PSIM_SUBCHINFO *DMW_PSI_GetSubChInfo(int rf, int source_id) |
|---|
| 132 | { |
|---|
| 133 | return PSIDB_GetPsiSubChInfo(rf, source_id); |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | #if 0 |
|---|
| 138 | STATUS DMW_PSI_GetCurrentProgramInfo (TSD *tsd, DPG_ProgramInfo *info) |
|---|
| 139 | { |
|---|
| 140 | |
|---|
| 141 | |
|---|
| 142 | } |
|---|
| 143 | |
|---|
| 144 | |
|---|
| 145 | STATUS DMW_PSI_FreeProgramInfo (DPG_ProgramInfo *info) |
|---|
| 146 | { |
|---|
| 147 | |
|---|
| 148 | |
|---|
| 149 | } |
|---|
| 150 | #endif |
|---|
| 151 | |
|---|
| 152 | |
|---|
| 153 | const char *DMW_PSI_ScanStatusString(E_PSIM_SCAN_STATUS e) |
|---|
| 154 | { |
|---|
| 155 | return PSIM_SCAN_STATUS_STRING(e); |
|---|
| 156 | } |
|---|
| 157 | |
|---|
| 158 | const char *DMW_PSI_EventString(E_PSIM_EVENT e) |
|---|
| 159 | { |
|---|
| 160 | return PSIM_EVENT_STRING(e); |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | |
|---|
| 164 | |
|---|
| 165 | #if COMMENT |
|---|
| 166 | ____Test____(){} |
|---|
| 167 | #endif |
|---|
| 168 | |
|---|
| 169 | #define OS_DbgPrintf DHL_OS_Printf |
|---|
| 170 | |
|---|
| 171 | void TEST_PSI_TryTune(int rf, int pn, int sid) |
|---|
| 172 | { |
|---|
| 173 | S_PSIM_CHINFO *chInfo; |
|---|
| 174 | int i; |
|---|
| 175 | MPEG_PMT *pmt = NULL; |
|---|
| 176 | |
|---|
| 177 | DMW_PSI_LockDB(TRUE); |
|---|
| 178 | |
|---|
| 179 | chInfo = DMW_PSI_GetChInfo(rf); |
|---|
| 180 | if (chInfo) { |
|---|
| 181 | OS_DbgPrintf("### pat %x, vct %x\n", chInfo->pat, chInfo->vct); |
|---|
| 182 | if (chInfo->pat && chInfo->pmts) { |
|---|
| 183 | for (i=0; i<chInfo->pat->numPrograms; i++) { |
|---|
| 184 | if (chInfo->pmts[i]->program_number == pn) { |
|---|
| 185 | pmt = chInfo->pmts[i]; |
|---|
| 186 | OS_DbgPrintf("### pmt[%d] %x\n", i, pmt); |
|---|
| 187 | break; |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | |
|---|
| 191 | if (pmt && chInfo->vct) { |
|---|
| 192 | // get pid info using chInfo->vct and pmt.. |
|---|
| 193 | // |
|---|
| 194 | // vpid = xx, apid = xx.. |
|---|
| 195 | OS_DbgPrintf("### ready for AV start..\n"); |
|---|
| 196 | } |
|---|
| 197 | } |
|---|
| 198 | } |
|---|
| 199 | DMW_PSI_LockDB(FALSE); |
|---|
| 200 | |
|---|
| 201 | // tune! |
|---|
| 202 | |
|---|
| 203 | } |
|---|
| 204 | |
|---|
| 205 | |
|---|
| 206 | void TEST_PSI_EventProc(tDHL_TSD tsd, E_PSIM_EVENT evt, UINT32 param) |
|---|
| 207 | { |
|---|
| 208 | if (0); |
|---|
| 209 | else if (evt == ePSIM_EVENT_PatReceived) { |
|---|
| 210 | //MPEG_PAT *pat = (MPEG_PAT *)status; |
|---|
| 211 | //OS_DbgPrintf("\n\n ######## event, pat %x received, user %x\n\n\n", |
|---|
| 212 | // pat, param->userparam); |
|---|
| 213 | } |
|---|
| 214 | |
|---|
| 215 | //-------------------------------------- |
|---|
| 216 | // belows are for viewing & recording |
|---|
| 217 | |
|---|
| 218 | else if (evt == ePSIM_EVENT_PmtReceived) { |
|---|
| 219 | MPEG_PMT *pmt = (MPEG_PMT *)param; |
|---|
| 220 | OS_DbgPrintf("\n\n ######## event, pmt %x received, user %x\n", pmt); |
|---|
| 221 | |
|---|
| 222 | //TEST_PSI_TryTune(param->rf, param->program_number, param->source_id); |
|---|
| 223 | |
|---|
| 224 | OS_DbgPrintf("\n\n"); |
|---|
| 225 | } |
|---|
| 226 | else if (evt == ePSIM_EVENT_VctReceived) { |
|---|
| 227 | xvctPtr_t vct = (xvctPtr_t)param; |
|---|
| 228 | OS_DbgPrintf("\n\n ######## event, vct %x received\n", vct); |
|---|
| 229 | |
|---|
| 230 | //TEST_PSI_TryTune(param->rf, param->program_number, param->source_id); |
|---|
| 231 | |
|---|
| 232 | OS_DbgPrintf("\n\n"); |
|---|
| 233 | } |
|---|
| 234 | |
|---|
| 235 | //-------------------------------------- |
|---|
| 236 | // belows are for autoscan.. |
|---|
| 237 | |
|---|
| 238 | else if (evt == ePSIM_EVENT_BasePsipReceived) { |
|---|
| 239 | OS_DbgPrintf("\n\n ######## event, base psip received\n"); |
|---|
| 240 | |
|---|
| 241 | OS_DbgPrintf("\n\n"); |
|---|
| 242 | } |
|---|
| 243 | else if (evt == ePSIM_EVENT_AllPmtsReceived) { |
|---|
| 244 | OS_DbgPrintf("\n\n ######## event, all pmts received\n"); |
|---|
| 245 | |
|---|
| 246 | OS_DbgPrintf("\n\n"); |
|---|
| 247 | } |
|---|
| 248 | } |
|---|
| 249 | |
|---|
| 250 | |
|---|
| 251 | |
|---|
| 252 | void TEST_PSI_Init(void) |
|---|
| 253 | { |
|---|
| 254 | //extern STATUS Dmc_PausePsiMonitor(UINT32 bPause); |
|---|
| 255 | //extern UINT8 g_Trace_PsiFilter, g_Trace_PsiFilterTidCount; |
|---|
| 256 | |
|---|
| 257 | Dmc_PausePsiMonitor(TRUE); // compiler warning will be removed later.. |
|---|
| 258 | |
|---|
| 259 | //g_Trace_PsiFilter = 4; |
|---|
| 260 | //g_Trace_PsiFilterTidCount = 20; |
|---|
| 261 | |
|---|
| 262 | DHL_DBG_SetModuleLevel("psieng", 3); |
|---|
| 263 | DHL_DBG_SetModuleLevel("psitsk", 3); |
|---|
| 264 | |
|---|
| 265 | DMW_PSI_Init(); |
|---|
| 266 | } |
|---|
| 267 | |
|---|
| 268 | void TEST_PSI_Scan(int rf) |
|---|
| 269 | { |
|---|
| 270 | tDHL_TSD *tsd = DHL_DMX_GetTsd(); |
|---|
| 271 | |
|---|
| 272 | DMW_PSI_StartUpdate(tsd, rf, 0, 0, PSI_FLAGS_AUTOSCAN, TEST_PSI_EventProc, 0x11); |
|---|
| 273 | } |
|---|
| 274 | |
|---|
| 275 | void TEST_PSI_Start(int rf, int pn, int si) |
|---|
| 276 | { |
|---|
| 277 | tDHL_TSD *tsd = DHL_DMX_GetTsd(); |
|---|
| 278 | |
|---|
| 279 | DMW_PSI_StartUpdate(tsd, rf, pn, si, PSI_FLAGS_NORMAL, TEST_PSI_EventProc, ((pn & 0xffff)<<16) | (si & 0xffff)); |
|---|
| 280 | } |
|---|
| 281 | |
|---|
| 282 | void TEST_PSI_Stop(int rf) |
|---|
| 283 | { |
|---|
| 284 | tDHL_TSD *tsd = DHL_DMX_GetTsd(); |
|---|
| 285 | |
|---|
| 286 | DMW_PSI_CancelUpdate(tsd); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | #if 0 |
|---|
| 290 | // Dmc_GetMainChannelTables(TSD * tsd, DmcMainTables * tbls, int timeOut, BOOL(* ckfn)(UINT32)) |
|---|
| 291 | |
|---|
| 292 | STATUS DMW_XXX_GetTablesForAutoScan (tsd, rf, timeout, cancelchk, tbls [out]) |
|---|
| 293 | { |
|---|
| 294 | |
|---|
| 295 | } |
|---|
| 296 | #endif |
|---|
| 297 | |
|---|