bool CEpgDataLoader::LoadFromFile(LPCTSTR pszFileName) { if (pszFileName==NULL) return false; static const DWORD MAX_READ_SIZE=0x1000000UL; // 16MiB static const DWORD BUFFER_SIZE=188*4096; HANDLE hFile; LARGE_INTEGER FileSize; DWORD ReadSize,RemainSize; BYTE *pBuffer; DWORD Size,Read; CTsPacket Packet; hFile=::CreateFile(pszFileName,GENERIC_READ,FILE_SHARE_READ,NULL, OPEN_EXISTING,FILE_FLAG_SEQUENTIAL_SCAN,NULL); if (hFile==INVALID_HANDLE_VALUE) return false; if (!::GetFileSizeEx(hFile,&FileSize) || FileSize.QuadPart<188*10) { ::CloseHandle(hFile); return false; } if (FileSize.QuadPart<=(LONGLONG)MAX_READ_SIZE) { ReadSize=FileSize.LowPart; } else { ReadSize=MAX_READ_SIZE; LARGE_INTEGER Offset; Offset.QuadPart=(FileSize.QuadPart-MAX_READ_SIZE)/188*188; ::SetFilePointerEx(hFile,Offset,NULL,FILE_BEGIN); } try { pBuffer=new BYTE[min(BUFFER_SIZE,ReadSize)]; } catch (...) { ::CloseHandle(hFile); return false; } m_EventManager.Reset(); for (RemainSize=ReadSize;RemainSize>=188;RemainSize-=Size) { Size=min(RemainSize,BUFFER_SIZE); if (!::ReadFile(hFile,pBuffer,Size,&Read,NULL)) break; BYTE *p=pBuffer,*pEnd=pBuffer+Read/188*188; while (p<pEnd) { const WORD PID=((WORD)(p[1]&0x1F)<<8) | (WORD)p[2]; // H-EIT / TOT / M-EIT / L-EIT if (PID==0x0012 || PID==0x0014 /*|| PID==0x0026*/ || PID==0x0027) { Packet.SetData(p,188); if (Packet.ParsePacket()==CTsPacket::EC_VALID) m_EventManager.InputMedia(&Packet); } p+=188; } if (Read<Size) break; } delete [] pBuffer; ::CloseHandle(hFile); TRACE(TEXT("EPG data loaded %s\n"),pszFileName); return true; }
const bool CTsPacketCounter::InputMedia(CMediaData *pMediaData, const DWORD dwInputIndex) { CBlockLock Lock(&m_DecoderLock); /* if (dwInputIndex >= GetInputNum()) return false; CTsPacket *pTsPacket = dynamic_cast<CTsPacket *>(pMediaData); // 入力メディアデータは互換性がない if(!pTsPacket)return false; */ CTsPacket *pTsPacket = static_cast<CTsPacket *>(pMediaData); m_InputPacketCount.Increment(); m_PidMapManager.StorePacket(pTsPacket); if (m_TargetServiceID == 0 && pTsPacket->IsScrambled()) m_ScrambledPacketCount.Increment(); OutputMedia(pTsPacket); return true; }
STDMETHODIMP CTSProcessor::OutputPacket(Interface::ITSPacket *pPacket) { if (pPacket == nullptr) return E_POINTER; ITsMediaData *pTsMediaData; if (SUCCEEDED(pPacket->QueryInterface(IID_PPV_ARGS(&pTsMediaData)))) { CMediaData *pMediaData = pTsMediaData->GetMediaData(); if (!m_fSourceProcessor && pPacket->GetModified() == S_OK) { #ifndef _DEBUG CTsPacket *pTsPacket = static_cast<CTsPacket*>(pMediaData); pTsPacket->ReparsePacket(); #else CTsPacket *pTsPacket = dynamic_cast<CTsPacket*>(pMediaData); _ASSERT(pTsPacket != nullptr); if (pTsPacket->ParsePacket() != CTsPacket::EC_VALID) { pTsMediaData->Release(); return E_FAIL; } #endif } OutputMedia(pMediaData); pTsMediaData->Release(); } else { HRESULT hr; ULONG Size = 0; hr = pPacket->GetSize(&Size); if (FAILED(hr)) return hr; BYTE *pData = nullptr; hr = pPacket->GetData(&pData); if (FAILED(hr)) return hr; if (Size == 0 || pData == nullptr) return E_FAIL; if (m_fSourceProcessor) { if (m_OutputPacket.SetData(pData, Size) != Size) return E_OUTOFMEMORY; } else { if (Size != TS_PACKETSIZE) return E_FAIL; if (m_OutputPacket.SetData(pData, TS_PACKETSIZE) != TS_PACKETSIZE) return E_OUTOFMEMORY; if (m_OutputPacket.ParsePacket() != CTsPacket::EC_VALID) return E_FAIL; } OutputMedia(&m_OutputPacket); } return S_OK; }
const bool CTsDemuxer::InputMedia(CMediaData *pMediaData, const DWORD dwInputIndex) { if(dwInputIndex >= GetInputNum())return false; CTsPacket *pTsPacket = dynamic_cast<CTsPacket *>(pMediaData); // 入力メディアデータは互換性がない if(!pTsPacket)return false; // 映像PESパケット抽出 if(pTsPacket->GetPID() == m_wVideoPID){ m_VideoPesParser.StorePacket(pTsPacket); return true; } // 音声PESパケット抽出 if(pTsPacket->GetPID() == m_wAudioPID){ m_AudioPesParser.StorePacket(pTsPacket); return true; } return true; }
const bool CMediaViewer::InputMedia(CMediaData *pMediaData, const DWORD dwInputIndex) { CBlockLock Lock(&m_DecoderLock); /* if(dwInputIndex >= GetInputNum())return false; CTsPacket *pTsPacket = dynamic_cast<CTsPacket *>(pMediaData); // 入力メディアデータは互換性がない if(!pTsPacket)return false; */ CTsPacket *pTsPacket = static_cast<CTsPacket *>(pMediaData); // フィルタグラフに入力 if (m_pSrcFilter && pTsPacket->GetPID() != 0x1FFF && !pTsPacket->IsScrambled()) { return m_pSrcFilter->InputMedia(pTsPacket); } return false; }