#include #include #include #pragma comment(lib, "winscard.lib") #include "BonSrcDecoder.h" #include "TsPacketParser.h" #include "TsDescrambler.h" #include "FileWriter.h" #include "MediaGrabber.h" #include "SendTSTCP.h" sendtstcp::AddSendDataDLL pAddSend; bool CALLBACK sendToTCP (const CMediaData *pMediaData, const PVOID pParam) { static int cnt = 0; static BYTE buf[188*256]; if ( pAddSend == NULL ) { return false; } int id = *(int*)pParam; memcpy(buf+(188*cnt), pMediaData->GetData(), 188); cnt++; if ( cnt%256 == 0 ) { pAddSend(id, buf, 188*256); cnt = 0; } return true; } void _tmain(int argc, LPTSTR *argv) { int recsecs = 30; TCHAR *FileName = _T("temp3.m2ts"); int chs = 0; int channelnum = 10; BOOL noapo = FALSE; BOOL fastapo = FALSE; BOOL nodec = FALSE; for (int i = 0; i < argc; i++) { CString S0=argv[i]; if( S0.Compare(_T("-r"))==0){ recsecs = _tstoi(argv[++i]); } else if( S0.Compare(_T("-f"))==0){ FileName = argv[++i]; } else if( S0.Compare(_T("-c"))==0){ channelnum = _tstoi(argv[++i]); } else if( S0.Compare(_T("-chs"))==0){ chs = _tstoi(argv[++i]); } else if( S0.Compare(_T("-noapo"))==0){ noapo = TRUE; } else if( S0.Compare(_T("-fastapo"))==0){ fastapo = TRUE; } else if( S0.Compare(_T("-nodec"))==0){ nodec = TRUE; } } CBonSrcDecoder m_BonSrcDecoder;// = new CBonSrcDecoder(NULL); CTsPacketParser m_TsPacketParser;// = new CTsPacketParser(NULL); CTsDescrambler m_TsDescrambler;// = new CTsDescrambler(NULL); CMediaGrabber m_MediaGrabber; CFileWriter m_Mpeg2File;// = new CFileWriter(NULL); HMODULE hModule; //IBonDriver* (__stdcall *func) (void); TCHAR dllnamebuf[256]; int newchs; int tcpport; if ( 0 <= chs && chs <= 2 ) { //Ter _tcscpy( dllnamebuf, _T("BonDriver\\BonDriver_PT1-T\x1.dll") ); newchs = chs; tcpport = 2235; } else { //Sar _tcscpy( dllnamebuf, _T("BonDriver\\BonDriver_PT1-S\x1.dll") ); newchs = chs - 3; tcpport = 2237; } LPTSTR ctrpos = _tcschr(dllnamebuf, _T('\x1')); int retry_count = 0; BOOL tunerOpened = FALSE; retry_searchTuner: tcpport--; for( TCHAR dllnum = _T('0'); dllnum<=_T('9'); dllnum++ ) { tcpport++; *ctrpos = dllnum; hModule = LoadLibrary( dllnamebuf ); if ( hModule == NULL ) { continue; } /* func = (IBonDriver * (__stdcall *)())GetProcAddress( hModule, "CreateBonDriver" ); if ( func == NULL ) { FreeLibrary(hModule); continue; } IBonDriver *pBonDriv = func(); if ( pBonDriv == NULL ) { FreeLibrary(hModule); continue; } */ // チューナを開く if(!m_BonSrcDecoder.OpenTuner(hModule)){ m_BonSrcDecoder.CloseTuner(); FreeLibrary(hModule); continue; } tunerOpened = TRUE; break; } if ( tunerOpened == FALSE ) { //利用可能なチューナーがなかった if ( retry_count < 1 ) { ATOM apoatom = GlobalAddAtom(_T("FoltiaPT1_Apoptosis")); Sleep(2*1000); GlobalDeleteAtom(apoatom); retry_count++; goto retry_searchTuner; } else { _fputts(_T("No Available Tuner\n"), stderr); exit(-1); } } _fputts(dllnamebuf, stderr); _fputts(_T("\n"), stderr); m_BonSrcDecoder.SetOutputDecoder(&m_TsPacketParser,0); m_TsPacketParser.SetOutputDecoder(&m_TsDescrambler, 0); m_TsDescrambler.SetOutputDecoder(&m_MediaGrabber, 0); m_MediaGrabber.SetOutputDecoder(&m_Mpeg2File, 0); if( nodec == TRUE || ( ! m_TsDescrambler.OpenBcasCard(CCardReader::READER_BONCASCLIENT) ) ){ //::AfxMessageBox(TEXT("B-CASカードのオープンに失敗しました。")); //RecType=2; //解除せずに記録する _fputts( _T("nodec...\n") , stderr); m_TsPacketParser.SetOutputDecoder(&m_Mpeg2File, 0); nodec = TRUE; //return; } //チャンネル設定 m_BonSrcDecoder.SetChannel(newchs, channelnum); //TCHAR file_fullpath[MAX_PATH+1] = _T("F:\\m2ts\\"); //_tcscat(file_fullpath, FileName); m_Mpeg2File.OpenFile(FileName); // TSTCP HMODULE hTcp = LoadLibrary( _T("SendTSTCP.dll") ); int tstcp_id; if ( hTcp != NULL ) { sendtstcp::InitializeDLL pInit = (sendtstcp::InitializeDLL)GetProcAddress(hTcp, ("InitializeDLL")); tstcp_id = pInit(); pAddSend = (sendtstcp::AddSendDataDLL)GetProcAddress(hTcp, ("AddSendDataDLL")); sendtstcp::AddSendAddrDLL pSendAddr = (sendtstcp::AddSendAddrDLL)GetProcAddress(hTcp, ("AddSendAddrDLL")); pSendAddr(tstcp_id, L"192.168.0.3", tcpport); sendtstcp::StartSendDLL pStartSend = (sendtstcp::StartSendDLL)GetProcAddress(hTcp, ("StartSendDLL")); pStartSend(tstcp_id); m_MediaGrabber.SetMediaGrabCallback(::sendToTCP, &tstcp_id); } Sleep(500); if ( ! m_BonSrcDecoder.Play() ) { _fputts( _T("Play Failed.\n") , stderr); exit(-5); } unsigned __int64 size; for(int i=0;i