UINT WINAPI CBonCtrl::ChScanThread(LPVOID param) { CBonCtrl* sys = (CBonCtrl*)param; sys->chUtil.Clear(); wstring chSet4 = sys->bonUtil.GetChSet4Path(); wstring chSet5 = sys->bonUtil.GetChSet5Path(); vector<CHK_CH_INFO> chkList; map<DWORD, BON_SPACE_INFO> spaceMap; if( sys->bonUtil.GetOriginalChList(&spaceMap) != NO_ERR ){ sys->chSt_err = ST_COMPLETE; sys->chUtil.SaveChSet(chSet4, chSet5); return 0; } map<DWORD, BON_SPACE_INFO>::iterator itrSpace; for( itrSpace = spaceMap.begin(); itrSpace != spaceMap.end(); itrSpace++ ){ sys->chSt_totalNum += (DWORD)itrSpace->second.chMap.size(); map<DWORD, BON_CH_INFO>::iterator itrCh; for( itrCh = itrSpace->second.chMap.begin(); itrCh != itrSpace->second.chMap.end(); itrCh++ ){ CHK_CH_INFO item; item.space = itrSpace->second.space; item.spaceName = itrSpace->second.spaceName; item.ch = itrCh->second.ch; item.chName = itrCh->second.chName; chkList.push_back(item); } } if( sys->chSt_totalNum == 0 ){ sys->chSt_err = ST_COMPLETE; sys->chUtil.SaveChSet(chSet4, chSet5); return 0; } wstring folderPath; GetModuleFolderPath( folderPath ); wstring iniPath = folderPath; iniPath += L"\\BonCtrl.ini"; DWORD chChgTimeOut = GetPrivateProfileInt(L"CHSCAN", L"ChChgTimeOut", 9, iniPath.c_str()); DWORD serviceChkTimeOut = GetPrivateProfileInt(L"CHSCAN", L"ServiceChkTimeOut", 8, iniPath.c_str()); DWORD wait = 0; BOOL chkNext = TRUE; LONGLONG startTime = 0; DWORD chkWait = 0; DWORD chkCount = 0; BOOL firstChg = FALSE; while(1){ if( ::WaitForSingleObject(sys->chScanStopEvent, wait) != WAIT_TIMEOUT ){ //キャンセルされた sys->chSt_err = ST_CANCEL; break; } if( chkNext == TRUE ){ sys->chSt_space = chkList[chkCount].space; sys->chSt_ch = chkList[chkCount].ch; sys->chSt_chName = chkList[chkCount].chName; sys->_SetCh(chkList[chkCount].space, chkList[chkCount].ch, TRUE); if( firstChg == FALSE ){ firstChg = TRUE; sys->tsOut.ResetChChange(); } startTime = GetTimeCount(); chkNext = FALSE; wait = 1000; chkWait = chChgTimeOut; }else{ BOOL chChgErr = FALSE; if( sys->tsOut.IsChChanging(&chChgErr) == TRUE ){ if( startTime + chkWait < GetTimeCount() ){ //チャンネル切り替えに8秒以上かかってるので無信号と判断 OutputDebugString(L"★AutoScan Ch Change timeout\r\n"); chkNext = TRUE; } }else{ if( startTime + chkWait+serviceChkTimeOut < GetTimeCount() || chChgErr == TRUE){ //チャンネル切り替え成功したけどサービス一覧とれないので無信号と判断 OutputDebugString(L"★AutoScan GetService timeout\r\n"); chkNext = TRUE; }else{ //サービス一覧の取得を行う DWORD serviceListSize; SERVICE_INFO* serviceList; if( sys->tsOut.GetServiceListActual(&serviceListSize, &serviceList) == NO_ERR ){ if( serviceListSize > 0 ){ //一覧の取得ができた for( DWORD i=0 ;i<serviceListSize; i++ ){ if( serviceList[i].extInfo != NULL ){ if( serviceList[i].extInfo->service_name != NULL ){ if( wcslen(serviceList[i].extInfo->service_name) > 0 ){ sys->chUtil.AddServiceInfo(chkList[chkCount].space, chkList[chkCount].ch, chkList[chkCount].chName, &(serviceList[i])); } } } } chkNext = TRUE; } } } } if( chkNext == TRUE ){ //次のチャンネルへ chkCount++; sys->chSt_chkNum++; if( sys->chSt_totalNum <= chkCount ){ //全部チェック終わったので終了 sys->chSt_err = ST_COMPLETE; sys->chUtil.SaveChSet(chSet4, chSet5); break; } } } } sys->chUtil.LoadChSet(chSet4, chSet5); return 0; }
UINT WINAPI CBonCtrl::EpgCapThread(LPVOID param) { CBonCtrl* sys = (CBonCtrl*)param; BOOL chkNext = TRUE; BOOL startCap = FALSE; DWORD wait = 0; LONGLONG startTime = 0; DWORD chkCount = 0; DWORD chkWait = 8; BOOL chkBS = FALSE; BOOL chkCS1 = FALSE; BOOL chkCS2 = FALSE; wstring folderPath; GetModuleFolderPath( folderPath ); wstring iniPath = folderPath; iniPath += L"\\BonCtrl.ini"; DWORD timeOut = GetPrivateProfileInt(L"EPGCAP", L"EpgCapTimeOut", 15, iniPath.c_str()); BOOL saveTimeOut = GetPrivateProfileInt(L"EPGCAP", L"EpgCapSaveTimeOut", 0, iniPath.c_str()); while(1){ if( ::WaitForSingleObject(sys->epgCapStopEvent, wait) != WAIT_TIMEOUT ){ //キャンセルされた OutputDebugString(L"EpgCapThread::Canceled"); sys->epgSt_err = ST_CANCEL; sys->tsOut.StopSaveEPG(FALSE); break; } if( chkNext == TRUE ){ if( sys->tsOut.IsChChanging(NULL) == TRUE ){ Sleep(200); continue; } DWORD space = 0; DWORD ch = 0; sys->chUtil.GetCh(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, space, ch); sys->_SetCh(space, ch); startTime = GetTimeCount(); chkNext = FALSE; startCap = FALSE; wait = 1000; TCHAR debug[MAX_PATH]; wsprintf(debug, _T("EpgCapThread::Check SID = %d"), sys->epgCapChList[chkCount].SID); OutputDebugString(debug); if( sys->epgCapChList[chkCount].ONID == 4 ){ OutputDebugString(L"EpgCapThread::BS Channel"); chkBS = TRUE; }else if( sys->epgCapChList[chkCount].ONID == 6 ){ OutputDebugString(L"EpgCapThread::CS1 Channel"); chkCS1 = TRUE; }else if( sys->epgCapChList[chkCount].ONID == 7 ){ OutputDebugString(L"EpgCapThread::CS2 Channel"); chkCS2 = TRUE; } sys->epgSt_ch = sys->epgCapChList[chkCount]; }else{ BOOL chChgErr = FALSE; if( sys->tsOut.IsChChanging(&chChgErr) == TRUE ){ if( startTime + chkWait < GetTimeCount() ){ //チャンネル切り替えに10秒以上かかってるので無信号と判断 OutputDebugString(L"EpgCapThread::No signal"); chkNext = TRUE; } }else{ if( (startTime + chkWait + timeOut*60 < GetTimeCount()) || chChgErr == TRUE){ //15分以上かかっているなら停止 OutputDebugString(L"EpgCapThread::Time out"); sys->tsOut.StopSaveEPG(saveTimeOut); chkNext = TRUE; wait = 0; _OutputDebugString(L"++%d分でEPG取得完了せず or Ch変更でエラー", timeOut); }else if(startTime + chkWait < GetTimeCount() ){ //切り替えから15秒以上過ぎているので取得処理 if( startCap == FALSE ){ //取得開始 startCap = TRUE; wstring epgDataPath = L""; sys->GetEpgDataFilePath(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, epgDataPath); sys->tsOut.StartSaveEPG(epgDataPath); sys->tsOut.ClearSectionStatus(); wait = 60*1000; }else{ //蓄積状態チェック BOOL leitFlag = sys->chUtil.IsPartial(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, sys->epgCapChList[chkCount].SID); EPG_SECTION_STATUS status = sys->tsOut.GetSectionStatus(leitFlag); if( sys->epgCapChList[chkCount].ONID == 4 && sys->BSBasic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else if( sys->epgCapChList[chkCount].ONID == 6 && sys->CS1Basic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else if( sys->epgCapChList[chkCount].ONID == 7 && sys->CS2Basic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else{ if( leitFlag == FALSE && status == EpgHEITAll ){ chkNext = TRUE; }else if( leitFlag == TRUE && status == EpgLEITAll ){ chkNext = TRUE; } } if( chkNext == TRUE ){ sys->tsOut.StopSaveEPG(TRUE); wait = 0; }else{ wait = 10*1000; } } } } if( chkNext == TRUE ){ //次のチャンネルへ chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } //BS 1チャンネルのみ? if( sys->epgCapChList[chkCount].ONID == 4 && sys->BSBasic == TRUE && chkBS == TRUE){ while(chkCount<(DWORD)sys->epgCapChList.size()){ if( sys->epgCapChList[chkCount].ONID != 4 ){ OutputDebugString(L"EpgCapThread::BS yet checked Basic"); break; } chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } } } //CS1 1チャンネルのみ? if( sys->epgCapChList[chkCount].ONID == 6 && sys->CS1Basic == TRUE && chkCS1 == TRUE ){ while(chkCount<(DWORD)sys->epgCapChList.size()){ if( sys->epgCapChList[chkCount].ONID != 6 ){ OutputDebugString(L"EpgCapThread::CS1 yet checked Basic"); break; } chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } } } //CS2 1チャンネルのみ? if( sys->epgCapChList[chkCount].ONID == 7 && sys->CS2Basic == TRUE && chkCS2 == TRUE ){ while(chkCount<(DWORD)sys->epgCapChList.size()){ if( sys->epgCapChList[chkCount].ONID != 7 ){ OutputDebugString(L"EpgCapThread::CS2 yet checked Basic"); break; } chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } } } } } } return 0; }
UINT WINAPI CBonCtrl::EpgCapThread(LPVOID param) { CBonCtrl* sys = (CBonCtrl*)param; BOOL chkNext = TRUE; BOOL startCap = FALSE; DWORD wait = 0; DWORD startTime = 0; DWORD chkCount = 0; DWORD chkWait = 8; BOOL chkBS = FALSE; BOOL chkCS1 = FALSE; BOOL chkCS2 = FALSE; wstring folderPath; GetModuleFolderPath( folderPath ); wstring iniPath = folderPath; iniPath += L"\\BonCtrl.ini"; DWORD timeOut = GetPrivateProfileInt(L"EPGCAP", L"EpgCapTimeOut", 15, iniPath.c_str()); BOOL saveTimeOut = GetPrivateProfileInt(L"EPGCAP", L"EpgCapSaveTimeOut", 0, iniPath.c_str()); //Common.iniは一般に外部プロセスが変更する可能性のある(はずの)ものなので、利用の直前にチェックする wstring commonIniPath; GetCommonIniPath(commonIniPath); BOOL BSBasic = GetPrivateProfileInt(L"SET", L"BSBasicOnly", 1, commonIniPath.c_str()); BOOL CS1Basic = GetPrivateProfileInt(L"SET", L"CS1BasicOnly", 1, commonIniPath.c_str()); BOOL CS2Basic = GetPrivateProfileInt(L"SET", L"CS2BasicOnly", 1, commonIniPath.c_str()); while(1){ if( ::WaitForSingleObject(sys->epgCapStopEvent, wait) != WAIT_TIMEOUT ){ //キャンセルされた sys->epgSt_err = ST_CANCEL; sys->tsOut.StopSaveEPG(FALSE); break; } if( chkNext == TRUE ){ if( sys->tsOut.IsChChanging(NULL) == TRUE ){ Sleep(200); continue; } DWORD space = 0; DWORD ch = 0; sys->chUtil.GetCh(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, space, ch); sys->_SetCh(space, ch); startTime = GetTickCount(); chkNext = FALSE; startCap = FALSE; wait = 1000; if( sys->epgCapChList[chkCount].ONID == 4 ){ chkBS = TRUE; }else if( sys->epgCapChList[chkCount].ONID == 6 ){ chkCS1 = TRUE; }else if( sys->epgCapChList[chkCount].ONID == 7 ){ chkCS2 = TRUE; } sys->epgSt_ch = sys->epgCapChList[chkCount]; }else{ BOOL chChgErr = FALSE; if( sys->tsOut.IsChChanging(&chChgErr) == TRUE ){ if( GetTickCount() - startTime > chkWait * 1000 ){ //チャンネル切り替えに10秒以上かかってるので無信号と判断 chkNext = TRUE; } }else{ if( GetTickCount() - startTime > (chkWait + timeOut * 60) * 1000 || chChgErr == TRUE){ //15分以上かかっているなら停止 sys->tsOut.StopSaveEPG(saveTimeOut); chkNext = TRUE; wait = 0; _OutputDebugString(L"++%d分でEPG取得完了せず or Ch変更でエラー", timeOut); }else if( GetTickCount() - startTime > chkWait * 1000 ){ //切り替えから15秒以上過ぎているので取得処理 if( startCap == FALSE ){ //取得開始 startCap = TRUE; wstring epgDataPath = L""; sys->GetEpgDataFilePath(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, epgDataPath, BSBasic, CS1Basic, CS2Basic); sys->tsOut.StartSaveEPG(epgDataPath); sys->tsOut.ClearSectionStatus(); wait = 60*1000; }else{ //蓄積状態チェック BOOL leitFlag = sys->chUtil.IsPartial(sys->epgCapChList[chkCount].ONID, sys->epgCapChList[chkCount].TSID, sys->epgCapChList[chkCount].SID); EPG_SECTION_STATUS status = sys->tsOut.GetSectionStatus(leitFlag); if( sys->epgCapChList[chkCount].ONID == 4 && BSBasic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else if( sys->epgCapChList[chkCount].ONID == 6 && CS1Basic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else if( sys->epgCapChList[chkCount].ONID == 7 && CS2Basic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else{ if( leitFlag == FALSE && status == EpgHEITAll ){ chkNext = TRUE; }else if( leitFlag == TRUE && status == EpgLEITAll ){ chkNext = TRUE; } } if( chkNext == TRUE ){ sys->tsOut.StopSaveEPG(TRUE); wait = 0; }else{ wait = 10*1000; } } } } if( chkNext == TRUE ){ //次のチャンネルへ chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } //BS 1チャンネルのみ? if( sys->epgCapChList[chkCount].ONID == 4 && BSBasic == TRUE && chkBS == TRUE){ while(chkCount<(DWORD)sys->epgCapChList.size()){ if( sys->epgCapChList[chkCount].ONID != 4 ){ break; } chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } } } //CS1 1チャンネルのみ? if( sys->epgCapChList[chkCount].ONID == 6 && CS1Basic == TRUE && chkCS1 == TRUE ){ while(chkCount<(DWORD)sys->epgCapChList.size()){ if( sys->epgCapChList[chkCount].ONID != 6 ){ break; } chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } } } //CS2 1チャンネルのみ? if( sys->epgCapChList[chkCount].ONID == 7 && CS2Basic == TRUE && chkCS2 == TRUE ){ while(chkCount<(DWORD)sys->epgCapChList.size()){ if( sys->epgCapChList[chkCount].ONID != 7 ){ break; } chkCount++; if( sys->epgCapChList.size() <= chkCount ){ //全部チェック終わったので終了 sys->epgSt_err = ST_COMPLETE; return 0; } } } } } } return 0; }