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::EpgCapBackThread(LPVOID param) { 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()); CBonCtrl* sys = (CBonCtrl*)param; if( ::WaitForSingleObject(sys->epgCapBackStopEvent, sys->epgCapBackStartWaitSec*1000) != WAIT_TIMEOUT ){ //キャンセルされた return 0; } if( sys->tsOut.IsRec() == TRUE ){ if( sys->enableRecEpgCap == FALSE ){ return 0; } }else{ if( sys->enableLiveEpgCap == FALSE ){ return 0; } } LONGLONG startTime = GetTimeCount(); wstring epgDataPath = L""; WORD ONID; WORD TSID; sys->tsOut.GetStreamID(&ONID, &TSID); if( sys->chUtil.IsEpgCapService(ONID, TSID) == FALSE ){ return 0; } sys->GetEpgDataFilePath(ONID, TSID, epgDataPath); sys->tsOut.StartSaveEPG(epgDataPath); sys->tsOut.ClearSectionStatus(); if( ::WaitForSingleObject(sys->epgCapBackStopEvent, 60*1000) != WAIT_TIMEOUT ){ //キャンセルされた sys->tsOut.StopSaveEPG(FALSE); return 0; } while(1){ //蓄積状態チェック BOOL chkNext = FALSE; BOOL leitFlag = sys->chUtil.IsPartial(ONID, TSID, sys->lastSID); EPG_SECTION_STATUS status = sys->tsOut.GetSectionStatus(leitFlag); if( ONID == 4 && sys->BSBasic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else if( ONID == 6 && sys->CS1Basic == TRUE ){ if( status == EpgBasicAll || status == EpgHEITAll ){ chkNext = TRUE; } }else if( 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); CSendCtrlCmd cmd; cmd.SetConnectTimeOut(1000); cmd.SendReloadEpg(); break; }else{ if( (startTime + timeOut*60 < GetTimeCount()) ){ //15分以上かかっているなら停止 sys->tsOut.StopSaveEPG(saveTimeOut); CSendCtrlCmd cmd; cmd.SetConnectTimeOut(1000); cmd.SendReloadEpg(); _OutputDebugString(L"++%d分でEPG取得完了せず or Ch変更でエラー", timeOut); break; } } if( ::WaitForSingleObject(sys->epgCapBackStopEvent, 10*1000) != WAIT_TIMEOUT ){ //キャンセルされた sys->tsOut.StopSaveEPG(FALSE); break; } } 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; }