void CPlayerPlaylistBar::AddItem(CAtlList<CString>& fns, CAtlList<CString>* subs) { CPlaylistItem pli; POSITION pos = fns.GetHeadPosition(); while (pos) { CString fn = fns.GetNext(pos); if (!fn.Trim().IsEmpty()) { pli.m_fns.AddTail(fn); } } if (subs) { POSITION posSub = subs->GetHeadPosition(); while (posSub) { CString fn = subs->GetNext(posSub); if (!fn.Trim().IsEmpty()) { pli.m_subs.AddTail(fn); } } } pli.AutoLoadFiles(); m_pl.AddTail(pli); }
bool SubtitleFile::Lookup(float at, CAutoPtrList<Subtitle>& subs) { if(!subs.IsEmpty()) {ASSERT(0); return false;} CAtlList<SegmentItem> sis; m_segments.Lookup(at, sis); POSITION pos = sis.GetHeadPosition(); while(pos) { SegmentItem& si = sis.GetNext(pos); CAutoPtr<Subtitle> s(DNew Subtitle(this)); if(s->Parse(si.pDef, si.start, si.stop, at)) { for(POSITION pos = subs.GetHeadPosition(); pos; subs.GetNext(pos)) { if(s->m_layer < subs.GetAt(pos)->m_layer) { subs.InsertBefore(pos, s); break; } } if(s) { subs.AddTail(s); } } } return !subs.IsEmpty(); }
void CFileAssoc::SetNoRecentDocs(bool bNoRecentDocs, bool bUpdateAssocs /*= false*/) { if (bNoRecentDocs == m_bNoRecentDocs) { bUpdateAssocs = false; } else { m_bNoRecentDocs = bNoRecentDocs; } CAtlList<CString> exts; if (bUpdateAssocs && GetAssociatedExtensionsFromRegistry(exts)) { CRegKey key; POSITION pos = exts.GetHeadPosition(); while (pos) { const CString& ext = exts.GetNext(pos); if (ERROR_SUCCESS == key.Open(HKEY_CLASSES_ROOT, PROGID + ext)) { if (m_bNoRecentDocs) { key.SetStringValue(_T("NoRecentDocs"), _T("")); } else { key.DeleteValue(_T("NoRecentDocs")); } } } } }
BOOL CShaderCombineDlg::OnInitDialog() { __super::OnInitDialog(); AddAnchor(IDC_LIST1, TOP_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_COMBO1, BOTTOM_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_STATIC1, BOTTOM_LEFT, BOTTOM_RIGHT); AddAnchor(IDC_BUTTON2, BOTTOM_RIGHT); AddAnchor(IDC_BUTTON3, BOTTOM_RIGHT); AddAnchor(IDC_BUTTON1, TOP_RIGHT); AddAnchor(IDC_BUTTON4, TOP_RIGHT); AddAnchor(IDOK, TOP_RIGHT); AddAnchor(IDCANCEL, TOP_RIGHT); AppSettings& s = AfxGetCurrentSettings(); CString str = s.m_shadercombine.Trim(); CAtlList<CString> sl; if(!str.IsEmpty()) Explode(str, sl, '|'); POSITION pos = sl.GetHeadPosition(); while(pos) m_list.AddString(sl.GetNext(pos)); pos = s.m_shaders.GetHeadPosition(); while(pos) m_combo.AddString(s.m_shaders.GetNext(pos).label); if(m_combo.GetCount()) m_combo.SetCurSel(0); return TRUE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
void CPPageExternalFilters::OnDropFiles(CAtlList<CString>& slFiles, DROPEFFECT) { SetActiveWindow(); POSITION pos = slFiles.GetHeadPosition(); while (pos) { CString fn = slFiles.GetNext(pos); CFilterMapper2 fm2(false); fm2.Register(fn); while (!fm2.m_filters.IsEmpty()) { if (FilterOverride* f = fm2.m_filters.RemoveHead()) { CAutoPtr<FilterOverride> p(f); int i = m_filters.InsertItem(m_filters.GetItemCount(), f->name); m_filters.SetItemData(i, reinterpret_cast<DWORD_PTR>(m_pFilters.AddTail(p))); m_filters.SetCheck(i, 1); if (fm2.m_filters.IsEmpty()) { m_filters.SetItemState(i, LVIS_SELECTED, LVIS_SELECTED); m_filters.SetSelectionMark(i); OnFilterSelectionChange(); } m_filters.SetColumnWidth(0, LVSCW_AUTOSIZE); SetModified(); } } } }
void CPPageExternalFilters::OnDropFiles(CAtlList<CString>& slFiles, DROPEFFECT) { SetActiveWindow(); POSITION pos = slFiles.GetHeadPosition(); while (pos) { CString fn = slFiles.GetNext(pos); CFilterMapper2 fm2(false); fm2.Register(fn); while (!fm2.m_filters.IsEmpty()) { if (FilterOverride* f = fm2.m_filters.RemoveHead()) { CAutoPtr<FilterOverride> p(f); int i = m_filters.AddString(f->name); m_filters.SetItemDataPtr(i, m_pFilters.AddTail(p)); m_filters.SetCheck(i, 1); if (fm2.m_filters.IsEmpty()) { m_filters.SetCurSel(i); OnFilterSelectionChange(); } SetModified(); } } } }
HRESULT CDSFilters::ReplaceCodecsPath(CAtlList<DSFilterInfo*>& InfoList, CString& strNewPath) { DSFilterInfo* pInfo = NULL; POSITION pos = InfoList.GetHeadPosition(); while (pos) { pInfo = InfoList.GetNext(pos); if (pInfo != NULL) { pInfo->path.Replace(m_strCodecsPath, strNewPath); POSITION pos2 = pInfo->depends.GetHeadPosition(); while (pos2) { CString& depend = pInfo->depends.GetNext(pos2); depend.Replace(m_strCodecsPath, strNewPath); } pos2 = pInfo->preloads.GetHeadPosition(); while (pos2) { CString& preload = pInfo->preloads.GetNext(pos2); preload.Replace(m_strCodecsPath, strNewPath); } } } return S_OK; }
void SubtitleFile::Parse(InputStream& s) { m_segments.RemoveAll(); __super::Parse(s, s_predef); // TODO: check file.format == "ssf" and file.version == 1 CAtlList<Definition*> defs; GetRootRef()->GetChildDefs(defs, L"subtitle"); StringMapW<float> offset; POSITION pos = defs.GetHeadPosition(); while(pos) { Definition* pDef = defs.GetNext(pos); try { Definition::Time time; if(pDef->GetAsTime(time, offset) && (*pDef)[L"@"].IsValue()) { m_segments.Insert(time.start.value, time.stop.value, pDef); } } catch(Exception&) { } } }
void CDSFilters::SortInfoByExtension(CAtlList<DSFilterInfo*>& InfoList, const TCHAR* pcszExtension) { DSFilterInfo* pInfo = NULL; POSITION pos = InfoList.GetHeadPosition(); while (pos) { BOOL bMatched = FALSE; pInfo = InfoList.GetAt(pos); if (pInfo != NULL) { POSITION pos2 = pInfo->extensions.GetHeadPosition(); while (pos2) { CString& extension = pInfo->extensions.GetNext(pos2); if (extension.CompareNoCase(pcszExtension+1)) { bMatched = TRUE; break; } } if (bMatched) { InfoList.MoveToHead(pos); } } InfoList.GetNext(pos); } }
BOOL CMultiFiles::OpenFiles(CAtlList<CHdmvClipInfo::PlaylistItem>& files, UINT nOpenFlags) { POSITION pos = files.GetHeadPosition(); LARGE_INTEGER llSize; int nPos = 0; REFERENCE_TIME rtDur = 0; Reset(); while(pos) { CHdmvClipInfo::PlaylistItem& s = files.GetNext(pos); m_strFiles.Add(s.m_strFileName); if (!OpenPart(nPos)) return false; llSize.QuadPart = 0; GetFileSizeEx (m_hFile, &llSize); m_llTotalLength += llSize.QuadPart; m_FilesSize.Add (llSize.QuadPart); m_rtPtsOffsets.Add (rtDur); rtDur += s.Duration(); nPos++; } if (files.GetCount() > 1) ClosePart(); return TRUE; }
CFileAssoc::reg_state_t CFileAssoc::AreRegisteredFileContextMenuEntries(const CMediaFormatCategory& mfc) { CAtlList<CString> exts; ExplodeMin(mfc.GetExtsWithPeriod(), exts, ' '); size_t cnt = 0; POSITION pos = exts.GetHeadPosition(); while (pos) { if (CFileAssoc::AreRegisteredFileContextMenuEntries(exts.GetNext(pos))) { cnt++; } } reg_state_t res; if (cnt == 0) { res = NOT_REGISTERED; } else if (cnt == exts.GetCount()) { res = ALL_REGISTERED; } else { res = SOME_REGISTERED; } return res; }
void CPlayerPlaylistBar::ParsePlayList(CAtlList<CString>& fns, CAtlList<CString>* subs) { if (fns.IsEmpty()) { return; } const CAppSettings& s = AfxGetAppSettings(); ResolveLinkFiles(fns); CAtlList<CString> sl; if (SearchFiles(fns.GetHead(), sl)) { if (sl.GetCount() > 1) { subs = NULL; } POSITION pos = sl.GetHeadPosition(); while (pos) { ParsePlayList(sl.GetNext(pos), subs); } return; } CAtlList<CString> redir; CStringA ct = GetContentType(fns.GetHead(), &redir); if (!redir.IsEmpty()) { POSITION pos = redir.GetHeadPosition(); while (pos) { ParsePlayList(sl.GetNext(pos), subs); } return; } if (ct == "application/x-mpc-playlist") { ParseMPCPlayList(fns.GetHead()); return; } else { #if INTERNAL_SOURCEFILTER_MPEG if (ct == "application/x-bdmv-playlist" && s.SrcFilters[SRC_MPEG]) { ParseBDMVPlayList(fns.GetHead()); return; } #endif } AddItem(fns, subs); }
bool FindFileInList(const CAtlList<CString>& sl, CString fn) { bool fFound = false; POSITION pos = sl.GetHeadPosition(); while (pos && !fFound) { if (!sl.GetNext(pos).CompareNoCase(fn)) { fFound = true; } } return fFound; }
void CPlayerPlaylistBar::Append(CAtlList<CString>& fns, bool fMulti, CAtlList<CString>* subs) { if (fMulti) { ASSERT(subs == NULL || subs->GetCount() == 0); POSITION pos = fns.GetHeadPosition(); while (pos) { ParsePlayList(fns.GetNext(pos), NULL); } } else { ParsePlayList(fns, subs); } Refresh(); SavePlaylist(); }
bool CFileAssoc::Register(CMediaFormatCategory& mfc, bool bRegister, bool bRegisterContextMenuEntries, bool bAssociatedWithIcon) { CAtlList<CString> exts; ExplodeMin(mfc.GetExtsWithPeriod(), exts, ' '); CString strLabel = mfc.GetDescription(); bool res = true; POSITION pos = exts.GetHeadPosition(); while (pos) { res &= Register(exts.GetNext(pos), strLabel, bRegister, bRegisterContextMenuEntries, bAssociatedWithIcon); } return res; }
CString ISOLang::LanguageToISO6392(LPCTSTR lang) { CString str = lang; str.MakeLower(); for (size_t i = 0, cnt = _countof(s_isolangs); i < cnt; i++) { CAtlList<CString> sl; Explode(CString(s_isolangs[i].name), sl, _T(';')); POSITION pos = sl.GetHeadPosition(); while (pos) { if (!str.CompareNoCase(sl.GetNext(pos))) { return CString(s_isolangs[i].iso6392); } } } return _T(""); }
HRESULT CHdmvClipInfo::FindMainMovie(LPCTSTR strFolder, CString& strPlaylistFile, CAtlList<PlaylistItem>& MainPlaylist) { HRESULT hr = E_FAIL; CString strPath (strFolder); CString strFilter; CAtlList<PlaylistItem> Playlist; WIN32_FIND_DATA fd = {0}; strPath.Replace(_T("\\PLAYLIST\\"), _T("\\")); //strPath.Replace(_T("\\BDMV\\"), _T("\\")); strPath.Replace(_T("\\STREAM\\"), _T("\\")); strPath += _T("\\BDMV\\"); strFilter.Format (_T("%sPLAYLIST\\*.mpls"), strPath); HANDLE hFind = FindFirstFile(strFilter, &fd); if(hFind != INVALID_HANDLE_VALUE) { REFERENCE_TIME rtMax = 0; REFERENCE_TIME rtCurrent; CString strCurrentPlaylist; do { strCurrentPlaylist.Format(_T("%sPLAYLIST\\%s"), strPath, fd.cFileName); Playlist.RemoveAll(); // Main movie shouldn't have duplicate M2TS filename... if (ReadPlaylist(strCurrentPlaylist, rtCurrent, Playlist) == S_OK && rtCurrent > rtMax) { rtMax = rtCurrent; strPlaylistFile = strCurrentPlaylist; MainPlaylist.RemoveAll(); POSITION pos = Playlist.GetHeadPosition(); while(pos) { MainPlaylist.AddTail(Playlist.GetNext(pos)); } hr = S_OK; } } while(FindNextFile(hFind, &fd)); FindClose(hFind); } return hr; }
void CPPageFormats::SetListItemState(int nItem) { if(nItem < 0) return; CString str = AfxGetAppSettings().Formats[(int)m_list.GetItemData(nItem)].GetExtsWithPeriod(); CAtlList<CString> exts; ExplodeMin(str, exts, ' '); int cnt = 0; POSITION pos = exts.GetHeadPosition(); while(pos) if(IsRegistered(exts.GetNext(pos))) cnt++; if (cnt != 0) cnt = (cnt == (int)exts.GetCount() ? 1 : 2); SetChecked(nItem, cnt); }
void CDSMMuxerFilter::MuxFooter(IBitStream* pBS) { // syncpoints int len = 0; CAtlList<IndexedSyncPoint> isps; REFERENCE_TIME rtPrev = 0, rt; UINT64 fpPrev = 0, fp; POSITION pos = m_isps.GetHeadPosition(); while (pos) { IndexedSyncPoint& isp = m_isps.GetNext(pos); TRACE(_T("sp[%d]: %I64d %I64x\n"), isp.id, isp.rt, isp.fp); rt = isp.rt - rtPrev; rtPrev = isp.rt; fp = isp.fp - fpPrev; fpPrev = isp.fp; IndexedSyncPoint isp2; isp2.fp = fp; isp2.rt = rt; isps.AddTail(isp2); len += 1 + GetByteLength(myabs(rt)) + GetByteLength(fp); // flags + rt + fp } MuxPacketHeader(pBS, DSMP_SYNCPOINTS, len); pos = isps.GetHeadPosition(); while (pos) { IndexedSyncPoint& isp = isps.GetNext(pos); int irt = GetByteLength(myabs(isp.rt)); int ifp = GetByteLength(isp.fp); pBS->BitWrite(isp.rt < 0, 1); pBS->BitWrite(irt, 3); pBS->BitWrite(ifp, 3); pBS->BitWrite(0, 1); // reserved pBS->BitWrite(myabs(isp.rt), irt << 3); pBS->BitWrite(isp.fp, ifp << 3); } }
bool CFileAssoc::GetAssociatedExtensions(const CMediaFormats& mf, CAtlList<CString>& exts) { exts.RemoveAll(); CAtlList<CString> mfcExts; for (size_t i = 0, cnt = mf.GetCount(); i < cnt; i++) { ExplodeMin(mf[i].GetExtsWithPeriod(), mfcExts, _T(' ')); POSITION pos = mfcExts.GetHeadPosition(); while (pos) { const CString ext = mfcExts.GetNext(pos); if (CFileAssoc::IsRegistered(ext)) { exts.AddTail(ext); } } } return !exts.IsEmpty(); }
void SubtitleFile::Append(InputStream& s, float start, float stop, bool fSetTime) { Reference* pRootRef = GetRootRef(); ParseDefs(s, pRootRef); CAtlList<Definition*> defs; GetNewDefs(defs); POSITION pos = defs.GetHeadPosition(); while(pos) { Definition* pDef = defs.GetNext(pos); if(pDef->m_parent == pRootRef && pDef->m_type == L"subtitle" && (*pDef)[L"@"].IsValue()) { m_segments.Insert(start, stop, pDef); if(fSetTime) { try { Definition::Time time; StringMapW<float> offset; pDef->GetAsTime(time, offset); if(time.start.value == start && time.stop.value == stop) continue; } catch(Exception&) { } CStringW str; str.Format(L"%.3f", start); pDef->SetChildAsNumber(L"time.start", str, L"s"); str.Format(L"%.3f", stop); pDef->SetChildAsNumber(L"time.stop", str, L"s"); } } } Commit(); }
STDMETHODIMP CBaseSplitterFilter::Load(LPCOLESTR pszFileName, const AM_MEDIA_TYPE* pmt) { CheckPointer(pszFileName, E_POINTER); m_fn = pszFileName; HRESULT hr = E_FAIL; CComPtr<IAsyncReader> pAsyncReader; CAtlList<CHdmvClipInfo::PlaylistItem> Items; CAtlList<CHdmvClipInfo::PlaylistChapter> Chapters; if (BuildPlaylist(pszFileName, Items)) { pAsyncReader = (IAsyncReader*)DEBUG_NEW CAsyncFileReader(Items, hr); } else { pAsyncReader = (IAsyncReader*)DEBUG_NEW CAsyncFileReader(CString(pszFileName), hr); } if (FAILED(hr) || FAILED(hr = DeleteOutputs()) || FAILED(hr = CreateOutputs(pAsyncReader))) { m_fn = ""; return hr; } if (BuildChapters(pszFileName, Items, Chapters)) { POSITION pos = Chapters.GetHeadPosition(); int i = 1; while (pos) { CString str; CHdmvClipInfo::PlaylistChapter& chap = Chapters.GetNext(pos); if (chap.m_nMarkType == CHdmvClipInfo::EntryMark) { str.Format(_T("Chapter %d"), i); ChapAppend(chap.m_rtTimestamp, str); i++; } } } ChapSort(); m_pSyncReader = pAsyncReader; return S_OK; }
bool CWebServer::ToLocalPath(CString& path, CString& redir) { if(!path.IsEmpty() && m_webroot.IsDirectory()) { CString str = path; str.Replace('/', '\\'); str.TrimLeft('\\'); CPath p; p.Combine(m_webroot, str); p.Canonicalize(); if(p.IsDirectory()) { CAtlList<CString> sl; Explode(AfxGetAppSettings().WebDefIndex, sl, ';'); POSITION pos = sl.GetHeadPosition(); while(pos) { str = sl.GetNext(pos); CPath p2 = p; p2.Append(str); if(p2.FileExists()) { p = p2; redir = path; if(redir.GetAt(redir.GetLength()-1) != '/') redir += '/'; redir += str; break; } } } if(_tcslen(p) > _tcslen(m_webroot) && p.FileExists()) { path = (LPCTSTR)p; return true; } } return false; }
bool CFileAssoc::ReAssocIcons(const CAtlList<CString>& exts) { if (!LoadIconLib()) { return false; } SaveIconLibVersion(); const CString progPath = GetProgramPath(true); CRegKey key; POSITION pos = exts.GetHeadPosition(); while (pos) { const CString ext = exts.GetNext(pos); const CString strProgID = PROGID + ext; CString appIcon; int iconIndex = GetIconIndex(ext); /* icon_index value -1 means no icon was found in the iconlib for the file extension */ if (iconIndex >= 0 && ExtractIcon(AfxGetApp()->m_hInstance, m_iconLibPath, iconIndex)) { appIcon.Format(_T("\"%s\",%d"), m_iconLibPath, iconIndex); } /* no icon was found for the file extension, so use MPC's icon */ if (appIcon.IsEmpty()) { appIcon = "\"" + progPath + "\",0"; } if (ERROR_SUCCESS != key.Create(HKEY_CLASSES_ROOT, strProgID + _T("\\DefaultIcon")) || ERROR_SUCCESS != key.SetStringValue(NULL, appIcon)) { return false; } key.Close(); } FreeIconLib(); return true; }
BOOL CDSFilters::CheckTypes(DSFilterInfo* pInfo, const CAtlList<MediaTypeItem>& mts) { CheckPointer(pInfo, FALSE); POSITION pos = mts.GetHeadPosition(); while (pos) { MediaTypeItem& mt_from_pin = mts.GetNext(pos); POSITION pos2 = pInfo->mediatypes.GetHeadPosition(); while (pos2) { MediaTypeItem& mt_from_info = pInfo->mediatypes.GetNext(pos2); if( (mt_from_info.majortype == mt_from_pin.majortype || mt_from_info.majortype == GUID_NULL) && (mt_from_info.subtype == mt_from_pin.subtype || mt_from_info.subtype == GUID_NULL) ) { return TRUE; } } } return FALSE; }
void ParseDirs(CAtlList<CString>& paths) { POSITION pos = paths.GetHeadPosition(); while (pos) { POSITION prevPos = pos; CString fn = paths.GetNext(pos); // Try to follow link files that point to a directory if (IsLinkFile(fn)) { fn = ResolveLinkFile(fn); } if (IsDir(fn)) { CAtlList<CString> subDirs; RecurseAddDir(fn, subDirs); // Add the subdirectories just after their parent // so that the tree is not parsed multiple times while (!subDirs.IsEmpty()) { paths.InsertAfter(prevPos, subDirs.RemoveTail()); } } } }
void CPlayerPlaylistBar::ResolveLinkFiles(CAtlList<CString>& fns) { // resolve .lnk files CComPtr<IShellLink> pSL; pSL.CoCreateInstance(CLSID_ShellLink); CComQIPtr<IPersistFile> pPF = pSL; POSITION pos = fns.GetHeadPosition(); while (pSL && pPF && pos) { CString& fn = fns.GetNext(pos); TCHAR buff[_MAX_PATH]; if (CPath(fn).GetExtension().MakeLower() != _T(".lnk") || FAILED(pPF->Load(CStringW(fn), STGM_READ)) || FAILED(pSL->Resolve(NULL, SLR_ANY_MATCH | SLR_NO_UI)) || FAILED(pSL->GetPath(buff, _countof(buff), NULL, 0))) { continue; } fn = buff; } }
CWebServer::CWebServer(CMainFrame* pMainFrame, int nPort) : m_pMainFrame(pMainFrame) , m_nPort(nPort) { m_webroot = CPath(GetProgramPath()); const CAppSettings& s = AfxGetAppSettings(); CString WebRoot = s.strWebRoot; WebRoot.Replace('/', '\\'); WebRoot.Trim(); CPath p(WebRoot); if (WebRoot.Find(_T(":\\")) < 0 && WebRoot.Find(_T("\\\\")) < 0) { m_webroot.Append(WebRoot); } else { m_webroot = p; } m_webroot.Canonicalize(); m_webroot.MakePretty(); if (!m_webroot.IsDirectory()) { m_webroot = CPath(); } CAtlList<CString> sl; Explode(s.strWebServerCGI, sl, ';'); POSITION pos = sl.GetHeadPosition(); while (pos) { CAtlList<CString> sl2; CString ext = Explode(sl.GetNext(pos), sl2, '=', 2); if (sl2.GetCount() < 2) { continue; } m_cgi[ext] = sl2.GetTail(); } m_ThreadId = 0; m_hThread = ::CreateThread(nullptr, 0, StaticThreadProc, (LPVOID)this, 0, &m_ThreadId); }
HRESULT CHdmvClipInfo::FindMainMovie(LPCTSTR strFolder, CString& strPlaylistFile, CAtlList<PlaylistItem>& MainPlaylist, CAtlList<PlaylistItem>& MPLSPlaylists) { HRESULT hr = E_FAIL; CString strPath(strFolder); CString strFilter; MPLSPlaylists.RemoveAll(); CAtlList<PlaylistItem> Playlist; WIN32_FIND_DATA fd = {0}; strPath.Replace(_T("\\PLAYLIST\\"), _T("\\")); strPath.Replace(_T("\\STREAM\\"), _T("\\")); strPath += _T("\\BDMV\\"); strFilter.Format(_T("%sPLAYLIST\\*.mpls"), strPath); HANDLE hFind = FindFirstFile(strFilter, &fd); if (hFind != INVALID_HANDLE_VALUE) { REFERENCE_TIME rtMax = 0; REFERENCE_TIME rtCurrent; CString strCurrentPlaylist; do { strCurrentPlaylist.Format(_T("%sPLAYLIST\\%s"), strPath, fd.cFileName); Playlist.RemoveAll(); // Main movie shouldn't have duplicate M2TS filename... if (ReadPlaylist(strCurrentPlaylist, rtCurrent, Playlist) == S_OK) { if (rtCurrent > rtMax) { rtMax = rtCurrent; strPlaylistFile = strCurrentPlaylist; MainPlaylist.RemoveAll(); POSITION pos = Playlist.GetHeadPosition(); while (pos) { MainPlaylist.AddTail(Playlist.GetNext(pos)); } hr = S_OK; } if (rtCurrent >= (REFERENCE_TIME)MIN_LIMIT * 600000000) { PlaylistItem Item; Item.m_strFileName = strCurrentPlaylist; Item.m_rtIn = 0; Item.m_rtOut = rtCurrent; MPLSPlaylists.AddTail(Item); } } } while (FindNextFile(hFind, &fd)); FindClose(hFind); } if (MPLSPlaylists.GetCount() > 1) { // bubble sort for (size_t j = 0; j < MPLSPlaylists.GetCount(); j++) { for (size_t i = 0; i < MPLSPlaylists.GetCount() - 1; i++) { if (MPLSPlaylists.GetAt(MPLSPlaylists.FindIndex(i)).Duration() < MPLSPlaylists.GetAt(MPLSPlaylists.FindIndex(i + 1)).Duration()) { MPLSPlaylists.SwapElements(MPLSPlaylists.FindIndex(i), MPLSPlaylists.FindIndex(i + 1)); } } } } return hr; }
HRESULT CHdmvClipInfo::ReadChapters(CString strPlaylistFile, CAtlList<CHdmvClipInfo::PlaylistItem>& PlaylistItems, CAtlList<PlaylistChapter>& Chapters) { CPath Path(strPlaylistFile); // Get BDMV folder Path.RemoveFileSpec(); Path.RemoveFileSpec(); m_hFile = CreateFile(strPlaylistFile, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_READONLY | FILE_FLAG_SEQUENTIAL_SCAN, NULL); if (m_hFile != INVALID_HANDLE_VALUE) { REFERENCE_TIME* rtOffset = DEBUG_NEW REFERENCE_TIME[PlaylistItems.GetCount()]; REFERENCE_TIME rtSum = 0; int nIndex = 0; BYTE Buff[100]; bool bDuplicate = false; POSITION pos = PlaylistItems.GetHeadPosition(); while (pos) { CHdmvClipInfo::PlaylistItem& PI = PlaylistItems.GetNext(pos); rtOffset[nIndex] = rtSum - PI.m_rtIn; rtSum = rtSum + PI.Duration(); nIndex++; } ReadBuffer(Buff, 4); if (memcmp(Buff, "MPLS", 4)) { SAFE_DELETE_ARRAY(rtOffset); return CloseFile(VFW_E_INVALID_FILE_FORMAT); } ReadBuffer(Buff, 4); if ((memcmp(Buff, "0200", 4) != 0) && (memcmp(Buff, "0100", 4) != 0)) { SAFE_DELETE_ARRAY(rtOffset); return CloseFile(VFW_E_INVALID_FILE_FORMAT); } LARGE_INTEGER Pos; unsigned short nMarkCount; ReadDword(); // PlayList_start_address Pos.QuadPart = ReadDword(); // PlayListMark_start_address // PlayListMark() SetFilePointerEx(m_hFile, Pos, NULL, FILE_BEGIN); ReadDword(); // length nMarkCount = ReadShort(); // number_of_PlayList_marks for (size_t i = 0; i < nMarkCount; i++) { PlaylistChapter Chapter; ReadByte(); // reserved_for_future_use Chapter.m_nMarkType = (PlaylistMarkType)ReadByte(); // mark_type Chapter.m_nPlayItemId = ReadShort(); // ref_to_PlayItem_id Chapter.m_rtTimestamp = 20000i64 * ReadDword() / 90 + rtOffset[Chapter.m_nPlayItemId]; // mark_time_stamp Chapter.m_nEntryPID = ReadShort(); // entry_ES_PID Chapter.m_rtDuration = 20000i64 * ReadDword() / 90; // duration Chapters.AddTail(Chapter); //TRACE(_T("Chapter %d : %s\n"), i, ReftimeToString(Chapter.m_rtTimestamp)); } CloseFile(S_OK); SAFE_DELETE_ARRAY(rtOffset); return bDuplicate ? S_FALSE : S_OK; } return AmHresultFromWin32(GetLastError()); }