Esempio n. 1
0
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;
}