Example #1
0
// Calling this function with bEnable equals to true when
// shuffle is already enabled will re-shuffle the tracks.
void CPlaylist::SetShuffle(bool bEnable)
{
    m_bShuffle = bEnable;

    if (bEnable && !IsEmpty()) {
        m_nShuffledListSize = GetCount();
        CAtlArray<plsort_t> positions;
        positions.SetCount(m_nShuffledListSize + 1);
        srand((unsigned int)time(nullptr));
        POSITION pos = GetHeadPosition();
        for (size_t i = 0; pos; i++, GetNext(pos)) {
            positions[i].n = rand();
            positions[i].pos = pos;
        }
        qsort(positions.GetData(), m_nShuffledListSize, sizeof(plsort_t), compare);
        positions[m_nShuffledListSize].pos = nullptr; // Termination

        m_posHeadShuffle = positions[0].pos;
        m_posTailShuffle = nullptr;
        for (size_t i = 0; i < m_nShuffledListSize; i++) {
            pos = positions[i].pos;
            CPlaylistItem& pli = GetAt(pos);
            pli.m_posPrevShuffle = m_posTailShuffle;
            pli.m_posNextShuffle = positions[i + 1].pos;
            m_posTailShuffle = pos;
        }
    } else {
        m_posHeadShuffle = m_posTailShuffle = nullptr;
        m_nShuffledListSize = 0;
    }
}
Example #2
0
bool TrackEntry::Expand(CBinary& data, UINT64 Scope)
{
    if (ces.ce.IsEmpty()) {
        return true;
    }

    CAtlArray<ContentEncoding*> cearray;
    POSITION pos = ces.ce.GetHeadPosition();
    while (pos) {
        cearray.Add(ces.ce.GetNext(pos));
    }
    qsort(cearray.GetData(), cearray.GetCount(), sizeof(ContentEncoding*), cesort);

    for (int i = (int)cearray.GetCount() - 1; i >= 0; i--) {
        ContentEncoding* ce = cearray[i];

        if (!(ce->ContentEncodingScope & Scope)) {
            continue;
        }

        if (ce->ContentEncodingType == ContentEncoding::Compression) {
            if (!data.Decompress(ce->cc)) {
                return false;
            }
        } else if (ce->ContentEncodingType == ContentEncoding::Encryption) {
            // TODO
            return false;
        }
    }

    return true;
}
Example #3
0
bool CJpegEncoderMem::PutBytes(const void* pData, int len)
{
	CAtlArray<BYTE> moredata;
	moredata.SetCount(len);
	memcpy(moredata.GetData(), pData, len);
	m_pdata->Append(moredata);
	return true;
}
Example #4
0
HRESULT CAC3Encoder::Encode(CAtlArray<float>& BuffIn, CAtlArray<BYTE>& BuffOut)
{
	int buffsamples = BuffIn.GetCount() / m_pAVCtx->channels;
	if (buffsamples < m_pAVCtx->frame_size) {
		return E_ABORT;
	}

	float* pEnc  = m_pSamples;
	float* pIn   = BuffIn.GetData();
	int channels = m_pAVCtx->channels;
	int samples  = m_pAVCtx->frame_size;

	for (int ch = 0; ch < channels; ++ch) {
		for (int i = 0; i < samples; ++i) {
			*pEnc++ = pIn[channels * i + ch];
		}
	}

	int ret;
	AVPacket avpkt;
	int got_packet;

	av_init_packet(&avpkt);
	avpkt.data = NULL; // packet data will be allocated by the encoder
	avpkt.size = 0;

	ret = avcodec_encode_audio2(m_pAVCtx, &avpkt, m_pFrame, &got_packet);
	if (ret < 0) {
		av_free_packet(&avpkt);
		return E_FAIL;
	}
	if (got_packet) {
		BuffOut.SetCount(avpkt.size);
		memcpy(BuffOut.GetData(), avpkt.data, avpkt.size);
	}
	av_free_packet(&avpkt);

	size_t old_size  = BuffIn.GetCount() * sizeof(float);
	size_t new_size  = BuffIn.GetCount() * sizeof(float) - m_framesize;
	size_t new_count = new_size / sizeof(float);

	memmove(pIn, (BYTE*)pIn + m_framesize, new_size);
	BuffIn.SetCount(new_count);

	return S_OK;
}
Example #5
0
void CPlaylist::SortByPath()
{
    CAtlArray<plsort2_t> a;
    a.SetCount(GetCount());
    POSITION pos = GetHeadPosition();
    for (int i = 0; pos; i++, GetNext(pos)) {
        a[i].str = GetAt(pos).m_fns.GetHead(), a[i].pos = pos;
    }
    qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
    for (size_t i = 0; i < a.GetCount(); i++) {
        MoveToTail(a[i].pos);
    }
}
Example #6
0
	// 指定したcodepageのテキストとしてファイルを読み込みます
CString Util::File::ReadAllText(const CString& path, const UINT codePage)
{
	CString rc;
	CAtlFile file;
	if(file.Create(path, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING) != S_OK){
		rc.Format(_T("ERROR: File Not Found[path=%s]\n"), (LPCTSTR)path);
		return rc;
	}
	ULONGLONG size;
	if(file.GetSize(size) != S_OK){
		rc.Format(_T("ERROR: File GetSize[%s]\n"), (LPCTSTR)path);
		return rc;
	}
	CAtlArray<char> buf;
	buf.SetCount((size_t)size+1);
	if(file.Read(buf.GetData(), (DWORD)size) != S_OK){
		rc.Format(_T("ERROR: File Read[%s]\n"), (LPCTSTR)path);
		return rc;
	}
	buf[(size_t)size] = 0;
	rc = CA2CT(buf.GetData(), codePage);
	return rc;
}
Example #7
0
void CPlaylist::Randomize()
{
    CAtlArray<plsort_t> a;
    a.SetCount(GetCount());
    srand((unsigned int)time(nullptr));
    POSITION pos = GetHeadPosition();
    for (int i = 0; pos; i++, GetNext(pos)) {
        a[i].n = rand(), a[i].pos = pos;
    }
    qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
    for (size_t i = 0; i < a.GetCount(); i++) {
        MoveToTail(a[i].pos);
    }
}
BOOL CPPageAccelTbl::OnApply()
{
	AfxGetMyApp()->UnregisterHotkeys();
	UpdateData();

	AppSettings& s = AfxGetAppSettings();

	s.wmcmds.RemoveAll();
	s.wmcmds.AddTail(&m_wmcmds);

	CAtlArray<ACCEL> pAccel;
	pAccel.SetCount(m_wmcmds.GetCount());
	POSITION pos = m_wmcmds.GetHeadPosition();
	for (int i = 0; pos; i++) {
		pAccel[i] = m_wmcmds.GetNext(pos);
	}
	if (s.hAccel) {
		DestroyAcceleratorTable(s.hAccel);
	}
	s.hAccel = CreateAcceleratorTable(pAccel.GetData(), pAccel.GetCount());

	GetParentFrame()->m_hAccelTable = s.hAccel;

	s.fWinLirc = !!m_fWinLirc;
	s.strWinLircAddr = m_WinLircAddr;
	if (s.fWinLirc) {
		s.WinLircClient.Connect(m_WinLircAddr);
	}
	s.fUIce = !!m_fUIce;
	s.strUIceAddr = m_UIceAddr;
	if (s.fUIce) {
		s.UIceClient.Connect(m_UIceAddr);
	}
	s.fGlobalMedia = !!m_fGlobalMedia;

	AfxGetMyApp()->RegisterHotkeys();

	s.AccelTblColWidth.bEnable = true;
	s.AccelTblColWidth.cmd		= m_list.GetColumnWidth(COL_CMD);
	s.AccelTblColWidth.key		= m_list.GetColumnWidth(COL_KEY);
	s.AccelTblColWidth.id		= m_list.GetColumnWidth(COL_ID);
	s.AccelTblColWidth.mwnd		= m_list.GetColumnWidth(COL_MOUSE);
	s.AccelTblColWidth.mfs		= m_list.GetColumnWidth(COL_MOUSE_FS);
	s.AccelTblColWidth.appcmd	= m_list.GetColumnWidth(COL_APPCMD);
	s.AccelTblColWidth.remcmd	= m_list.GetColumnWidth(COL_RMCMD);
	s.AccelTblColWidth.repcnt	= m_list.GetColumnWidth(COL_RMREPCNT);

	return __super::OnApply();
}
Example #9
0
void CPlaylist::SortByPath()
{
	CAtlArray<plsort2_t> a;
	a.SetCount(GetCount());
	POSITION pos = GetHeadPosition();
	for(int i = 0; pos; i++, GetNext(pos))
		a[i].str = GetAt(pos).m_fns.GetHead(), a[i].pos = pos;
	qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
	for(int i = 0; i < a.GetCount(); i++)
	{
		AddTail(GetAt(a[i].pos));
		__super::RemoveAt(a[i].pos);
		if(m_pos == a[i].pos) m_pos = GetTailPosition(); 
	}
}
STDMETHODIMP CDriveItemPropertyStoreFactory::GetPropertyStore(GETPROPERTYSTOREFLAGS flags, __in_opt IUnknown * /*punkFactory*/, REFIID riid, __deref_out void **ppv)
{
  Log::WriteOutput(LogType::Debug, L"CDriveItemPropertyStoreFactory::GetPropertyStore()");

  CAtlArray<PROPERTYKEY> rgKeys;

  HRESULT hr = _CreatePropertyKeyArray(flags, rgKeys);

  if (SUCCEEDED(hr))
  {
    hr = GetPropertyStoreForKeys(rgKeys.GetData(), (UINT)rgKeys.GetCount(), flags, riid, ppv);
  }

  return hr;
}
Example #11
0
void CPlaylist::SortByName()
{
    CAtlArray<plsort2_t> a;
    a.SetCount(GetCount());
    POSITION pos = GetHeadPosition();
    for (int i = 0; pos; i++, GetNext(pos)) {
        CString& fn = GetAt(pos).m_fns.GetHead();
        a[i].str = (LPCTSTR)fn + std::max(fn.ReverseFind('/'), fn.ReverseFind('\\')) + 1;
        a[i].pos = pos;
    }
    qsort(a.GetData(), a.GetCount(), sizeof(plsort2_t), compare2);
    for (size_t i = 0; i < a.GetCount(); i++) {
        MoveToTail(a[i].pos);
    }
}
Example #12
0
void CPlaylist::SortById()
{
    CAtlArray<plsort_t> a;
    a.SetCount(GetCount());
    POSITION pos = GetHeadPosition();
    for (int i = 0; pos; i++, GetNext(pos)) {
        a[i].n = GetAt(pos).m_id, a[i].pos = pos;
    }
    qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
    for (size_t i = 0; i < a.GetCount(); i++) {
        AddTail(GetAt(a[i].pos));
        __super::RemoveAt(a[i].pos);
        if (m_pos == a[i].pos) {
            m_pos = GetTailPosition();
        }
    }
}
Example #13
0
void CPlaylist::Randomize()
{
	CAtlArray<plsort_t> a;
	a.SetCount(GetCount());
	srand((unsigned int)time(NULL));
	POSITION pos = GetHeadPosition();
	for(int i = 0; pos; i++, GetNext(pos))
		a[i].n = rand(), a[i].pos = pos;
	qsort(a.GetData(), a.GetCount(), sizeof(plsort_t), compare);
	CList<CPlaylistItem> pl;
	for(int i = 0; i < a.GetCount(); i++)
	{
		AddTail(GetAt(a[i].pos));
		__super::RemoveAt(a[i].pos);
		if(m_pos == a[i].pos)
			m_pos = GetTailPosition(); 
	}
}
Example #14
0
HRESULT CDll_RS232::ReadBuffer( CAtlArray<BYTE> &buffer ) 
{
	HRESULT hr = S_OK ;
	
	if ( !m_bIsConnection ) return E_FAIL ;

	OVERLAPPED ov ;
	memset( &ov , 0 , sizeof( ov ) ) ;
	ov.hEvent = CreateEvent( NULL , TRUE , NULL , NULL ) ;
	DWORD dwRead , dwError ;
	COMSTAT cs ;
	memset( &cs , 0 , sizeof( cs ) ) ;
	
	if ( !ClearCommError( m_hCommPort , &dwError , &cs ) ){
		ATLASSERT( 0 ) ;
		ATLTRACE( "Get count available bytes failed\r\n" ) ;
		return E_FAIL ;
	}

	if ( cs.cbInQue == 0 ) {
		CloseHandle( ov.hEvent ) ;
		return S_OK ;
	}
	bool ok = buffer.SetCount( cs.cbInQue ) ;
	ATLASSERT ( ok ) ;
	
	BOOL bRet = ReadFile( m_hCommPort , buffer.GetData() , ( DWORD )buffer.GetCount() , &dwRead , &ov ) ;
	if ( !bRet ){
		if ( GetLastError() == ERROR_IO_PENDING ){
			DWORD dwWait = WaitForSingleObject( ov.hEvent , INFINITE ) ;
			ATLASSERT( dwWait == WAIT_OBJECT_0 ) ;
		}else{
			ATLASSERT( 0 ) ;
			hr = E_FAIL ;
		}
	}
	CloseHandle( ov.hEvent ) ;
	return hr ;
}
Example #15
0
HRESULT CDll_RS232::WriteBuffer( CAtlArray<BYTE> &buffer ) 
{
	HRESULT hr = S_OK ;
	
	if ( !m_bIsConnection ) return E_FAIL ;

	OVERLAPPED ov ;
	memset( &ov , 0 , sizeof( ov ) ) ;
	ov.hEvent = CreateEvent( NULL , TRUE , NULL , NULL ) ;
	DWORD dwWrite ;
	BOOL bRet = WriteFile( m_hCommPort , buffer.GetData() , ( DWORD )buffer.GetCount() , &dwWrite , &ov ) ;
	if ( !bRet ){
		if ( GetLastError() == ERROR_IO_PENDING ){
			DWORD dwWait = WaitForSingleObject( ov.hEvent , INFINITE ) ;
			ATLASSERT( dwWait == WAIT_OBJECT_0 ) ;
		}else{
			ATLASSERT( 0 ) ;
			hr = E_FAIL ;
		}
	}
	CloseHandle( ov.hEvent ) ;
	return hr ;
}
Example #16
0
bool CPlayerPlaylistBar::ParseMPCPlayList(CString fn)
{
    CString str;
    CAtlMap<int, CPlaylistItem> pli;
    CAtlArray<int> idx;

    CWebTextFile f;
    if (!f.Open(fn) || !f.ReadString(str) || str != _T("MPCPLAYLIST")) {
        return false;
    }

    if (f.GetEncoding() == CTextFile::ASCII) {
        f.SetEncoding(CTextFile::ANSI);
    }

    CPath base(fn);
    base.RemoveFileSpec();

    while (f.ReadString(str)) {
        CAtlList<CString> sl;
        Explode(str, sl, ',', 3);
        if (sl.GetCount() != 3) {
            continue;
        }

        if (int i = _ttoi(sl.RemoveHead())) {
            CString key = sl.RemoveHead();
            CString value = sl.RemoveHead();

            if (key == _T("type")) {
                pli[i].m_type = (CPlaylistItem::type_t)_ttol(value);
                idx.Add(i);
            } else if (key == _T("label")) {
                pli[i].m_label = value;
            } else if (key == _T("filename")) {
                value = CombinePath(base, value);
                pli[i].m_fns.AddTail(value);
            } else if (key == _T("subtitle")) {
                value = CombinePath(base, value);
                pli[i].m_subs.AddTail(value);
            } else if (key == _T("video")) {
                while (pli[i].m_fns.GetCount() < 2) {
                    pli[i].m_fns.AddTail(_T(""));
                }
                pli[i].m_fns.GetHead() = value;
            } else if (key == _T("audio")) {
                while (pli[i].m_fns.GetCount() < 2) {
                    pli[i].m_fns.AddTail(_T(""));
                }
                pli[i].m_fns.GetTail() = value;
            } else if (key == _T("vinput")) {
                pli[i].m_vinput = _ttol(value);
            } else if (key == _T("vchannel")) {
                pli[i].m_vchannel = _ttol(value);
            } else if (key == _T("ainput")) {
                pli[i].m_ainput = _ttol(value);
            } else if (key == _T("country")) {
                pli[i].m_country = _ttol(value);
            }
        }
    }

    qsort(idx.GetData(), idx.GetCount(), sizeof(int), s_int_comp);
    for (size_t i = 0; i < idx.GetCount(); i++) {
        m_pl.AddTail(pli[idx[i]]);
    }

    return pli.GetCount() > 0;
}
Example #17
0
unsigned CDll_RS232::ThreadFunction( ) 
{
	DWORD dwEventMask = 0 , dwWait ;
	BOOL	bContinue = TRUE ;
	OVERLAPPED ov ;
	memset( &ov , 0 , sizeof( ov ) ) ;
	ov.hEvent = CreateEvent( NULL , TRUE , NULL , NULL ) ;

	HANDLE arHandles[ 2 ] = { m_hTerminate , ov.hEvent } ;
	
	SetEvent( m_hThreadStarted ) ;
	while( bContinue ) 
	{
		BOOL bRet = WaitCommEvent( m_hCommPort , &dwEventMask , &ov ) ;

		if ( !bRet ){
			ATLASSERT( GetLastError() == ERROR_IO_PENDING ) ;
		}

		dwWait = WaitForMultipleObjects ( 2 , arHandles , FALSE , INFINITE ) ;
		switch( dwWait ){
		case WAIT_OBJECT_0 :
			ATLTRACE( "RS232 thread terminate\r\n" ) ;
			_endthreadex( 1 ) ;
			break ;
		case WAIT_OBJECT_0 + 1 :
			{
				try{
					OVERLAPPED ovRead ;
					memset( &ovRead , 0 , sizeof( ovRead ) ) ;
					ovRead.hEvent = CreateEvent( NULL , TRUE , NULL , NULL ) ;
					COMSTAT cs ; 
					memset( &cs , 0 , sizeof( cs ) ) ;
					DWORD dwError ; 
					if ( !ClearCommError( m_hCommPort , &dwError , &cs ) ){
						throw ;
					}
					DWORD dwReadAvailable = cs.cbInQue , dwRead ;
					if ( !dwReadAvailable ) {
						CloseHandle( ovRead.hEvent ) ;
						continue ;
					}
					CAtlArray<BYTE> buf ;
					buf.SetCount( dwReadAvailable ) ;
					BOOL bOk = ReadFile( m_hCommPort , buf.GetData() , dwReadAvailable , &dwRead , &ovRead ) ;
					if ( !bOk ){
						if ( GetLastError() == ERROR_IO_PENDING ){
							dwWait = WaitForSingleObject( ovRead.hEvent , INFINITE ) ;
							ATLASSERT( dwWait == WAIT_OBJECT_0 ) ;
						}else{
							CloseHandle( ovRead.hEvent ) ;
							continue ;
						}
					}
					LockBuffer() ;
					m_arBuffer.Append( buf ) ;
//#ifdef _DEBUG
					char _dbg[ 1024 ] ;
					sprintf( _dbg , "Receive bytes : " ) ;
					for ( int i = 0 ; i < buf.GetCount() ; i++ ) 
						sprintf( _dbg , "%s %02X" , _dbg , buf[ i ] ) ;
					sprintf( _dbg , "%s Tick = %d\r\n" , _dbg , GetTickCount( ) ) ;
					ATLTRACE( _dbg ) ;
					fprintf( stream , _dbg ) ;
					fflush( stream ) ;
//#endif
					UnLockBuffer ( ) ;
					
					m_SignalDataReceive ( ) ;
					
					CloseHandle( ovRead.hEvent ) ;
					ResetEvent( ov.hEvent ) ;
				}catch(...){
					ATLASSERT( 0 ) ;
				}
			break ;
			}
		}
	}
	return 1 ;
}
Example #18
0
BOOL bigfilehelper::GetAutoDestDirFromSize(CString& strDir)
{
    BOOL retval = FALSE;
    CAtlArray<TCHAR> buffer;
    TCHAR* pBuffer = NULL;
    DWORD dwSize;
    CAtlList<CString> logicalDrvs;
    CString strDrv;
    POSITION pos = NULL;
    POSITION max_size_pos = NULL;
    ULONGLONG uMaxSize = 0;
    DWORD dwSectorsPerCluster;
    DWORD dwBytesPerSector;
    DWORD dwNumberOfFreeClusters;
    DWORD dwTotalNumberOfClusters;
    CString strSysDrv;
    TCHAR szVolName[MAX_PATH+1] = { 0 };
    TCHAR szFileSystem[MAX_PATH+1] = { 0 };
    BOOL fRetCode;

    SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);

    if (!GetSystemDrive(strSysDrv))
        goto clean0;

    buffer.SetCount(512);
    pBuffer = buffer.GetData();
    dwSize = (DWORD)buffer.GetCount();
    memset(pBuffer, 0, dwSize * sizeof(TCHAR));
    dwSize = GetLogicalDriveStrings(dwSize, buffer.GetData());

    if (dwSize > 2) 
    {
        strDrv = pBuffer;
        logicalDrvs.AddTail(strDrv);

        for (DWORD i = 3; i < dwSize; ++i) 
        {
            if (pBuffer[i] != 0 && pBuffer[i - 1] == 0) 
            {
                strDrv = pBuffer + i;
                logicalDrvs.AddTail(strDrv);
            }
        }
    }

    pos = logicalDrvs.GetHeadPosition();
    while (pos)
    {
        POSITION current = pos;
        CString _drv = logicalDrvs.GetNext(pos);
        _drv.MakeLower();
        if (_drv == _T("a:\\") || _drv == _T("b:\\"))
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }

        UINT uType = GetDriveType(_drv);
        if (uType != DRIVE_FIXED &&
            uType != DRIVE_REMOVABLE)
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }

        if (strSysDrv.CompareNoCase(_drv)==0)
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }

        RtlZeroMemory(szVolName, sizeof(szVolName));
        RtlZeroMemory(szFileSystem, sizeof(szFileSystem));
        fRetCode = GetVolumeInformation(
            _drv,
            szVolName,
            MAX_PATH+1,
            NULL,
            NULL,
            NULL,
            szFileSystem,
            MAX_PATH+1
            );
        if (!fRetCode)
        {
            logicalDrvs.RemoveAt(current);
            continue;
        }
    }

    pos = logicalDrvs.GetHeadPosition();
    while (pos)
    {
        POSITION current = pos;
        const CString& _drv = logicalDrvs.GetNext(pos);
        BOOL fRetCode = GetDiskFreeSpace(
            _drv,
            &dwSectorsPerCluster,
            &dwBytesPerSector,
            &dwNumberOfFreeClusters,
            &dwTotalNumberOfClusters
            );
        if (!fRetCode)
            continue;

        ULONGLONG uCurrentFreeSize = (ULONGLONG)dwNumberOfFreeClusters * dwSectorsPerCluster * dwBytesPerSector;
        if (uCurrentFreeSize > uMaxSize)
        {
            max_size_pos = current;
            uMaxSize = uCurrentFreeSize;
        }
    }
    if (max_size_pos==NULL)
        goto clean0;
    strDir = logicalDrvs.GetAt(max_size_pos);
    strDir += _T("系统盘大文件");

    retval = TRUE;

clean0:
    return retval;
}
Example #19
0
BOOL bigfilehelper::GetAllVols(std::vector<VolInfo>& vVols)
{
    BOOL retval = FALSE;
    CAtlArray<TCHAR> buffer;
    TCHAR* pBuffer = NULL;
    DWORD dwSize;
    std::vector<CString> logicalDrvs;
    CString strDrv;
    POSITION pos = NULL;
    POSITION max_size_pos = NULL;
    ULONGLONG uMaxSize = 0;
    DWORD dwSectorsPerCluster;
    DWORD dwBytesPerSector;
    DWORD dwNumberOfFreeClusters;
    DWORD dwTotalNumberOfClusters;
    TCHAR szVolName[MAX_PATH+1] = { 0 };
    TCHAR szFileSystem[MAX_PATH+1] = { 0 };
    BOOL fRetCode;
    VolInfo volInfo;
    size_t idx;

    SetErrorMode(SEM_NOOPENFILEERRORBOX | SEM_FAILCRITICALERRORS);

    buffer.SetCount(512);
    pBuffer = buffer.GetData();
    dwSize = (DWORD)buffer.GetCount();
    memset(pBuffer, 0, dwSize * sizeof(TCHAR));
    dwSize = GetLogicalDriveStrings(dwSize, buffer.GetData());

    if (dwSize > 2)
    {
        strDrv = pBuffer;
        logicalDrvs.push_back(strDrv);

        for (DWORD i = 3; i < dwSize; ++i) 
        {
            if (pBuffer[i] != 0 && pBuffer[i - 1] == 0) 
            {
                strDrv = pBuffer + i;
                logicalDrvs.push_back(strDrv);
            }
        }
    }

    for (idx = 0; idx < logicalDrvs.size(); ++idx)
    {
        CString _drv = logicalDrvs[idx];
        BOOL bRemovable = FALSE;

        if (_drv.CompareNoCase(_T("a:\\")) == 0 || 
            _drv.CompareNoCase(_T("b:\\")) == 0)
        {
            continue;
        }

        UINT uType = GetDriveType(_drv);
        if (uType != DRIVE_FIXED &&
            uType != DRIVE_REMOVABLE)
        {
            continue;
        }

        if (DRIVE_REMOVABLE == uType)
            bRemovable = TRUE;

        RtlZeroMemory(szVolName, sizeof(szVolName));
        RtlZeroMemory(szFileSystem, sizeof(szFileSystem));
        fRetCode = GetVolumeInformation(
            _drv,
            szVolName,
            MAX_PATH+1,
            NULL,
            NULL,
            NULL,
            szFileSystem,
            MAX_PATH+1
            );
        if (!fRetCode)
        {
            continue;
        }

        fRetCode = GetDiskFreeSpace(
            _drv,
            &dwSectorsPerCluster,
            &dwBytesPerSector,
            &dwNumberOfFreeClusters,
            &dwTotalNumberOfClusters
            );
        if (!fRetCode)
        {
            continue;
        }

        volInfo.cVol = (char)_drv[0];
        volInfo.strVolName = szVolName;
        if (volInfo.strVolName.IsEmpty())
            volInfo.strVolName = _T("本地磁盘");
        volInfo.qwTotalSize = (ULONGLONG)dwTotalNumberOfClusters * dwBytesPerSector * dwSectorsPerCluster;
        volInfo.qwFreeSize = (ULONGLONG)dwNumberOfFreeClusters * dwBytesPerSector * dwSectorsPerCluster;
        volInfo.bRemovable = bRemovable;
        vVols.push_back(volInfo);
    }

    retval = TRUE;

//clean0:
    return retval;
}
Example #20
0
HRESULT CZlib::EncodeFile( LPCWSTR lpwszSrcFile, LPCWSTR lpwszDstFile, int level )
{
    if ( zlib_compress )
    {
        CAtlFile hInFile;
        HRESULT hr = hInFile.Create(
            lpwszSrcFile,
            GENERIC_READ,
            FILE_SHARE_READ | FILE_SHARE_DELETE,
            OPEN_EXISTING);
        if (FAILED(hr))
            return hr;

        CAtlFile hOutFile;
        hr = hOutFile.Create(
            lpwszDstFile,
            GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_DELETE,
            CREATE_ALWAYS);
        if (FAILED(hr))
            return hr;

        ULONGLONG uInFileSize = 0;
        hr = hInFile.GetSize(uInFileSize);
        if (FAILED(hr))
            return hr;

        // 0长度文件不需要压缩
        if (0 == uInFileSize)
            return S_OK;

        // 太大的文件不压缩
        if (uInFileSize >  ZLIB_SINGLE_FILE_MAX_SIZE ) //假定压缩比为4:1
            return E_FAIL;

        // 读取输入
        CAtlArray<BYTE> bufRead;
        bufRead.SetCount((size_t)uInFileSize);
        if (uInFileSize != bufRead.GetCount())
            return E_OUTOFMEMORY;

        hr = hInFile.Read(bufRead.GetData(), (DWORD)bufRead.GetCount());
        if (FAILED(hr))
            return hr;

        // 准备压缩
        ULONGLONG uOutFileSize = max(uInFileSize, ZLIB_DECOMPRESS_INIT_BUFF_SIZE);
        CAtlArray<BYTE> bufWrite;
        try
        {
            while (uOutFileSize <= ZLIB_SINGLE_FILE_MAX_SIZE )
            {
                bufWrite.SetCount(0);
                bufWrite.SetCount((DWORD)uOutFileSize);
                if (uOutFileSize != bufWrite.GetCount())
                    return E_OUTOFMEMORY;

                DWORD dwcompressSize = DWORD(uOutFileSize);
                int nRet = zlib_compress2(
                    bufWrite.GetData(),
                    &dwcompressSize,
                    bufRead.GetData(),
                    (int)bufRead.GetCount(),
                    level
                    );
                if (nRet == Z_OK && dwcompressSize <= uOutFileSize)
                {
                    bufWrite.SetCount(dwcompressSize);
                    break;
                }

                if (nRet != Z_BUF_ERROR)
                    return E_FAIL;

                uOutFileSize *= 2;
            }	
        }
        catch (...)
        {
            return E_FAIL;
        }

        hr = hOutFile.Write(bufWrite.GetData(), (DWORD)bufWrite.GetCount());
        if (FAILED(hr))
            return hr;

        return S_OK;
    }
    else
    {
        return E_NOINTERFACE;
    }
}
Example #21
0
void GetSubFileNames(CString fn, CAtlArray<CString>& paths, CAtlArray<SubFile>& ret)
{
	ret.RemoveAll();

	int extlistnum = _countof(ext);
	int extsubnum = _countof(ext[0]);

	fn.Replace('\\', '/');

	bool fWeb = false;
	{
		//		int i = fn.Find(_T("://"));
		int i = fn.Find(_T("http://"));
		if (i > 0) {
			fn = _T("http") + fn.Mid(i);
			fWeb = true;
		}
	}

	int	l = fn.GetLength(), l2 = l;
	l2 = fn.ReverseFind('.');
	l = fn.ReverseFind('/') + 1;
	if (l2 < l) {
		l2 = l;
	}

	CString orgpath = fn.Left(l);
	CString title = fn.Mid(l, l2-l);
	CString filename = title + _T(".nooneexpectsthespanishinquisition");

	if (!fWeb) {
		// struct _tfinddata_t file, file2;
		// long hFile, hFile2 = 0;

		WIN32_FIND_DATA wfd, wfd2;
		HANDLE hFile, hFile2;

		for (size_t k = 0; k < paths.GetCount(); k++) {
			CString path = paths[k];
			path.Replace('\\', '/');

			l = path.GetLength();
			if (l > 0 && path[l-1] != '/') {
				path += '/';
			}

			if (path.Find(':') == -1 && path.Find(_T("\\\\")) != 0) {
				path = orgpath + path;
			}

			path.Replace(_T("/./"), _T("/"));
			path.Replace('/', '\\');

			// CAtlList<CString> sl;

			bool fEmpty = true;

			if ((hFile = FindFirstFile(path + title + _T("*"), &wfd)) != INVALID_HANDLE_VALUE) {
				do {
					if (filename.CompareNoCase(wfd.cFileName) != 0) {
						fEmpty = false;
						// sl.AddTail(path + file.name);
					}
				} while (FindNextFile(hFile, &wfd));

				FindClose(hFile);
			}

			// TODO: use 'sl' in the next step to find files (already a nice speedup as it is now...)
			if (fEmpty) {
				continue;
			}

			for (ptrdiff_t j = 0; j < extlistnum; j++) {
				for (ptrdiff_t i = 0; i < extsubnum; i++) {
					if ((hFile = FindFirstFile(path + title + ext[j][i], &wfd)) != INVALID_HANDLE_VALUE) {
						do {
							CString fn = path + wfd.cFileName;

							hFile2 = INVALID_HANDLE_VALUE;

							if (j == 0 || (hFile2 = FindFirstFile(fn.Left(fn.ReverseFind('.')) + _T(".avi"), &wfd2)) == INVALID_HANDLE_VALUE) {
								SubFile f;
								f.fn = fn;
								ret.Add(f);
							}

							if (hFile2 != INVALID_HANDLE_VALUE) {
								FindClose(hFile2);
							}
						} while (FindNextFile(hFile, &wfd));

						FindClose(hFile);
					}
				}
			}
		}
	} else if (l > 7) {
		CWebTextFile wtf; // :)
		if (wtf.Open(orgpath + title + WEBSUBEXT)) {
			CString fn;
			while (wtf.ReadString(fn) && fn.Find(_T("://")) >= 0) {
				SubFile f;
				f.fn = fn;
				ret.Add(f);
			}
		}
	}

	// sort files, this way the user can define the order (movie.00.English.srt, movie.01.Hungarian.srt, etc)

	qsort(ret.GetData(), ret.GetCount(), sizeof(SubFile), SubFileCompare);
}
Example #22
0
void CBBrowserCaps::Init(void)
{
	if(s_bInited)return;

	s_csBrowserCaps.Enter();
	if(s_bInited)
	{
		s_csBrowserCaps.Leave();
		return;
	}

	CBComPtr<_Data> pData;
	int n;
	BOOL bFind = FALSE;

	pData.CreateInstance();

	CBComPtr<CBFile> pFile;
	CBStringA strLine;

	pFile.CreateInstance();
	if(SUCCEEDED(pFile->Open(L"\\browscap.ini")))
	{
		while(SUCCEEDED(pFile->ReadLine(strLine)))
		{
			strLine.Trim();
			if(!strLine.IsEmpty())
				if(strLine[0] == '[' && strLine[strLine.GetLength() - 1] == ']')
				{
					pData.CreateInstance();
					pData->UserAgent = strLine.Mid(1, strLine.GetLength() - 2);

					if(pData->UserAgent.Find('*') == -1 && pData->UserAgent.Find('?') == -1)
						s_bcDatas.SetAt(pData->UserAgent, pData);
					else s_bcDatasExt.Add(pData);

					if(!pData->UserAgent.Compare("*"))
						bFind = TRUE;
				}else if(strLine[0] != ';')
				{
					n = strLine.Find('=');
					if(n != -1)
					{
						CBStringA strName, strValue;

						strName = strLine.Left(n).Trim();
						if(!strName.IsEmpty())
						{
							strValue = strLine.Mid(n + 1).Trim();
							if(!strName.CompareNoCase("parent"))
							{
								CBComPtr<_Data> pParentData;
								
								if(s_bcDatas.Lookup(strValue, pParentData))
								{
									pData->Name = pParentData->Name;
									pData->Type = pParentData->Type;
									pData->Version = pParentData->Version;
									pData->MajorVersion = pParentData->MajorVersion;
									pData->MinorVersion = pParentData->MinorVersion;
									pData->Platform = pParentData->Platform;
									pData->CSSVersion = pParentData->CSSVersion;
									pData->Frames = pParentData->Frames;
									pData->IFrames = pParentData->IFrames;
									pData->Tables = pParentData->Tables;
									pData->Cookies = pParentData->Cookies;
									pData->BackgroundSounds = pParentData->BackgroundSounds;
									pData->VBScript = pParentData->VBScript;
									pData->JavaScript = pParentData->JavaScript;
									pData->JavaApplets = pParentData->JavaApplets;
									pData->ActiveXControls = pParentData->ActiveXControls;
									pData->CDF = pParentData->CDF;
									pData->AOL = pParentData->AOL;
									pData->Beta = pParentData->Beta;
									pData->Win16 = pParentData->Win16;
									pData->Crawler = pParentData->Crawler;
									pData->WAP = pParentData->WAP;
									pData->NetCLR = pParentData->NetCLR;
								}
							}
							else if(!strName.CompareNoCase("browser"))
							{
								pData->Name = strValue;

								pData->Type = pData->Name;
								if(!pData->MajorVersion.IsEmpty() && pData->MajorVersion.Compare(L"0"))
								{
									pData->Type += ' ';
									pData->Type += pData->MajorVersion;
								}
							}
							else if(!strName.CompareNoCase("Version"))
								pData->Version = strValue;
							else if(!strName.CompareNoCase("MajorVer"))
							{
								pData->MajorVersion = strValue;

								pData->Type = pData->Name;
								if(!pData->MajorVersion.IsEmpty() && pData->MajorVersion.Compare(L"0"))
								{
									pData->Type += ' ';
									pData->Type += pData->MajorVersion;
								}
							}
							else if(!strName.CompareNoCase("MinorVer"))
								pData->MinorVersion = strValue;
							else if(!strName.CompareNoCase("Platform"))
								pData->Platform = strValue;
							else if(!strName.CompareNoCase("CSS"))
								pData->CSSVersion = atoi(strValue);
							else if(!strName.CompareNoCase("Frames"))
								pData->Frames = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("IFrames"))
								pData->IFrames = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("Tables"))
								pData->Tables = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("Cookies"))
								pData->Cookies = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("BackgroundSounds"))
								pData->BackgroundSounds = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("VBScript"))
								pData->VBScript = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("JavaScript"))
								pData->JavaScript = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("JavaApplets"))
								pData->JavaApplets = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("ActiveXControls"))
								pData->ActiveXControls = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("CDF"))
								pData->CDF = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("AOL"))
								pData->AOL = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("Beta"))
								pData->Beta = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("Win16"))
								pData->Win16 = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("Crawler"))
								pData->Crawler = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("WAP"))
								pData->WAP = !strValue.CompareNoCase("true");
							else if(!strName.CompareNoCase("NetCLR"))
								pData->NetCLR = !strValue.CompareNoCase("true");
						}
					}
				}
		}
	}

	if(!bFind)
	{
		pData.CreateInstance();
		pData->UserAgent = "*";
		s_bcDatasExt.Add(pData);
	}

	qsort(s_bcDatasExt.GetData(), s_bcDatasExt.GetCount(), sizeof(CBComPtr<_Data>),
		(int (__cdecl *)(const void *,const void *))staticCompare);

	s_bInited = TRUE;
	s_csBrowserCaps.Leave();
}
Example #23
0
bool CFontInstaller::InstallFont(const CAtlArray<BYTE>& data)
{
	return InstallFont(data.GetData(), (UINT)data.GetCount());
}
Example #24
0
void GetSubFileNames(CString fn, CAtlArray<CString>& paths, CString load_ext_list, CAtlArray<SubFile>& ret)
{
    XY_LOG_INFO(XY_LOG_VAR_2_STR(fn.GetString())<<XY_LOG_VAR_2_STR(paths.GetCount())<<XY_LOG_VAR_2_STR(load_ext_list.GetString()));

    ret.RemoveAll();

    fn.Replace('\\', '/');

    bool fWeb = false;
    {
        //int i = fn.Find(_T("://"));
        int i = fn.Find(_T("http://"));
        if(i > 0) {fn = _T("http") + fn.Mid(i); fWeb = true;}
    }

    int	l = fn.GetLength(), l2 = l;
    l2 = fn.ReverseFind('.');
    l = fn.ReverseFind('/') + 1;
    if(l2 < l) l2 = l;

    CString orgpath = fn.Left(l);
    CString title = fn.Mid(l, l2-l);
    CString filename = title + _T(".nooneexpectsthespanishinquisition");
    
    ExtSupport ext_support;
    if (!ext_support.init(load_ext_list))
    {
        XY_LOG_INFO(_T("unexpected error"));
        return;
    }

    if(!fWeb)
    {
        WIN32_FIND_DATA wfd;
        for(size_t k = 0; k < paths.GetCount(); k++)
        {
            CString path = paths[k];
            path.Replace('\\', '/');

            l = path.GetLength();
            if(l > 0 && path[l-1] != '/') path += '/';

            if(path.Find(':') == -1 && path.Find(_T("\\\\")) != 0) path = orgpath + path;

            path.Replace(_T("/./"), _T("/"));
            path.Replace('/', '\\');

            CAtlList<CString> sl;

            bool fEmpty = true;

            HANDLE hFile = FindFirstFile(path + title + _T(".*"), &wfd);
            if(hFile != INVALID_HANDLE_VALUE)
            {
                do
                {
                    if(filename.CompareNoCase(wfd.cFileName) != 0) 
                    {
                        fEmpty = false;
                        sl.AddTail(wfd.cFileName);
                    }
                }
                while(FindNextFile(hFile, &wfd));

                FindClose(hFile);
            }

            if(fEmpty) continue;

            POSITION pos = sl.GetHeadPosition();
            while(pos)
            {
                const CString& fn = sl.GetNext(pos);
                int l = fn.ReverseFind('.');
                CString ext = fn.Mid(l+1).MakeLower();
                int ext_order = ext_support.ext_support_order(ext);
                if (ext_order>-1)
                {
                    SubFile f;
                    f.full_file_name = path + fn;

                    int l2 = fn.Find('.');
                    if (l2==l)
                    {
                        f.extra_name = "";
                    }
                    else
                    {
                        f.extra_name = fn.Mid(l2+1, l-l2-1);
                    }

                    f.ext_order = ext_order;
                    f.path_order = k;
                    ret.Add(f);
                }
            }
        }
    }
    else if(l > 7)
    {
        CWebTextFile wtf; // :)
        if(wtf.Open(orgpath + title + WEBSUBEXT))
        {
            CString fn;
            while(wtf.ReadString(fn) && fn.Find(_T("://")) >= 0)
            {
                SubFile f;
                f.full_file_name = fn;
                f.extra_name = fn.Mid(fn.ReverseFind('/')+1);
                f.ext_order = MAXINT32;
                f.path_order = MAXINT32;
                ret.Add(f);
            }
        }
    }

    // sort files, this way the user can define the order (movie.00.English.srt, movie.01.Hungarian.srt, etc)

    qsort(ret.GetData(), ret.GetCount(), sizeof(SubFile), SubFileCompare);
}
Example #25
0
void CBinRes::BufferResource( CAtlArray<BYTE>& buff )
{
	buff.SetCount( m_size );
	memcpy( buff.GetData(), m_resAdrr, m_size );
}
Example #26
0
HRESULT CMatroskaSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
{
	CheckPointer(pAsyncReader, E_POINTER);

	HRESULT hr = E_FAIL;

	m_pFile.Free();
	m_pTrackEntryMap.RemoveAll();
	m_pOrderedTrackArray.RemoveAll();

	CAtlArray<CMatroskaSplitterOutputPin*> pinOut;
	CAtlArray<TrackEntry*> pinOutTE;

	m_pFile.Attach(DNew CMatroskaFile(pAsyncReader, hr));
	if(!m_pFile) return E_OUTOFMEMORY;
	if(FAILED(hr)) {m_pFile.Free(); return hr;}

	m_rtNewStart = m_rtCurrent = 0;
	m_rtNewStop = m_rtStop = m_rtDuration = 0;

	int iVideo = 1, iAudio = 1, iSubtitle = 1;

	POSITION pos = m_pFile->m_segment.Tracks.GetHeadPosition();
	while(pos)
	{
		Track* pT = m_pFile->m_segment.Tracks.GetNext(pos);

		POSITION pos2 = pT->TrackEntries.GetHeadPosition();
		while(pos2)
		{
			TrackEntry* pTE = pT->TrackEntries.GetNext(pos2);

			bool isSub = false;

			if(!pTE->Expand(pTE->CodecPrivate, ContentEncoding::TracksPrivateData))
				continue;

			CStringA CodecID = pTE->CodecID.ToString();

			CStringW Name;
			Name.Format(L"Output %I64d", (UINT64)pTE->TrackNumber);

			CMediaType mt;
			CAtlArray<CMediaType> mts;

			mt.SetSampleSize(1);

			if(pTE->TrackType == TrackEntry::TypeVideo)
			{
				Name.Format(L"Video %d", iVideo++);

				mt.majortype = MEDIATYPE_Video;

				if(CodecID == "V_MS/VFW/FOURCC")
				{
					mt.formattype = FORMAT_VideoInfo;
					VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount() - sizeof(BITMAPINFOHEADER));
					memset(mt.Format(), 0, mt.FormatLength());
					memcpy(&pvih->bmiHeader, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
					mt.subtype = FOURCCMap(pvih->bmiHeader.biCompression);
					switch(pvih->bmiHeader.biCompression)
					{
					case BI_RGB: case BI_BITFIELDS: mt.subtype = 
						pvih->bmiHeader.biBitCount == 1 ? MEDIASUBTYPE_RGB1 :
						pvih->bmiHeader.biBitCount == 4 ? MEDIASUBTYPE_RGB4 :
						pvih->bmiHeader.biBitCount == 8 ? MEDIASUBTYPE_RGB8 :
						pvih->bmiHeader.biBitCount == 16 ? MEDIASUBTYPE_RGB565 :
						pvih->bmiHeader.biBitCount == 24 ? MEDIASUBTYPE_RGB24 :
						pvih->bmiHeader.biBitCount == 32 ? MEDIASUBTYPE_ARGB32 :
						MEDIASUBTYPE_NULL;
						break;
//					case BI_RLE8: mt.subtype = MEDIASUBTYPE_RGB8; break;
//					case BI_RLE4: mt.subtype = MEDIASUBTYPE_RGB4; break;
					}
					mts.Add(mt);
				}
				else if(CodecID == "V_UNCOMPRESSED")
				{
				}
				else if(CodecID.Find("V_MPEG4/ISO/AVC") == 0 && pTE->CodecPrivate.GetCount() >= 6)
				{
					BYTE sps = pTE->CodecPrivate[5] & 0x1f;

	std::vector<BYTE> avcC;
	for(int i = 0, j = pTE->CodecPrivate.GetCount(); i < j; i++)
		avcC.push_back(pTE->CodecPrivate[i]);

	std::vector<BYTE> sh;

	unsigned jj = 6;

	while (sps--) {
	  if (jj + 2 > avcC.size())
	    goto avcfail;
	  unsigned spslen = ((unsigned)avcC[jj] << 8) | avcC[jj+1];
	  if (jj + 2 + spslen > avcC.size())
	    goto avcfail;
	  unsigned cur = sh.size();
	  sh.resize(cur + spslen + 2, 0);
	  std::copy(avcC.begin() + jj, avcC.begin() + jj + 2 + spslen,sh.begin() + cur);
	  jj += 2 + spslen;
	}

	if (jj + 1 > avcC.size())
	  continue;

	unsigned pps = avcC[jj++];

	while (pps--) {
	  if (jj + 2 > avcC.size())
	    goto avcfail;
	  unsigned ppslen = ((unsigned)avcC[jj] << 8) | avcC[jj+1];
	  if (jj + 2 + ppslen > avcC.size())
	    goto avcfail;
	  unsigned cur = sh.size();
	  sh.resize(cur + ppslen + 2, 0);
	  std::copy(avcC.begin() + jj, avcC.begin() + jj + 2 + ppslen, sh.begin() + cur);
	  jj += 2 + ppslen;
	}

	goto avcsuccess;
avcfail:
	continue;
avcsuccess:

					CAtlArray<BYTE> data;
					data.SetCount(sh.size());
					std::copy(sh.begin(), sh.end(), data.GetData());

					mt.subtype = FOURCCMap('1CVA');
					mt.formattype = FORMAT_MPEG2Video;
					MPEG2VIDEOINFO* pm2vi = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + data.GetCount());
					memset(mt.Format(), 0, mt.FormatLength());
					pm2vi->hdr.bmiHeader.biSize = sizeof(pm2vi->hdr.bmiHeader);
					pm2vi->hdr.bmiHeader.biWidth = (LONG)pTE->v.PixelWidth;
					pm2vi->hdr.bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
					pm2vi->hdr.bmiHeader.biCompression = '1CVA';
					pm2vi->hdr.bmiHeader.biPlanes = 1;
					pm2vi->hdr.bmiHeader.biBitCount = 24;
					pm2vi->dwProfile = pTE->CodecPrivate[1];
					pm2vi->dwLevel = pTE->CodecPrivate[3];
					pm2vi->dwFlags = (pTE->CodecPrivate[4] & 3) + 1;
					BYTE* pSequenceHeader = (BYTE*)pm2vi->dwSequenceHeader;
					memcpy(pSequenceHeader, data.GetData(), data.GetCount());
					pm2vi->cbSequenceHeader = data.GetCount();
					mts.Add(mt);
				}
				else if(CodecID.Find("V_MPEG4/") == 0)
				{
					mt.subtype = FOURCCMap('V4PM');
					mt.formattype = FORMAT_MPEG2Video;
					MPEG2VIDEOINFO* pm2vi = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(FIELD_OFFSET(MPEG2VIDEOINFO, dwSequenceHeader) + pTE->CodecPrivate.GetCount());
					memset(mt.Format(), 0, mt.FormatLength());
					pm2vi->hdr.bmiHeader.biSize = sizeof(pm2vi->hdr.bmiHeader);
					pm2vi->hdr.bmiHeader.biWidth = (LONG)pTE->v.PixelWidth;
					pm2vi->hdr.bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
					pm2vi->hdr.bmiHeader.biCompression = 'V4PM';
					pm2vi->hdr.bmiHeader.biPlanes = 1;
					pm2vi->hdr.bmiHeader.biBitCount = 24;
					BYTE* pSequenceHeader = (BYTE*)pm2vi->dwSequenceHeader;
					memcpy(pSequenceHeader, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
					pm2vi->cbSequenceHeader = pTE->CodecPrivate.GetCount();
					mts.Add(mt);
				}
				else if(CodecID.Find("V_REAL/RV") == 0)
				{
					mt.subtype = FOURCCMap('00VR' + ((CodecID[9]-0x30)<<16));
					mt.formattype = FORMAT_VideoInfo;
					VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount());
					memset(mt.Format(), 0, mt.FormatLength());
					memcpy(mt.Format() + sizeof(VIDEOINFOHEADER), pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
					pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader);
					pvih->bmiHeader.biWidth = (LONG)pTE->v.PixelWidth;
					pvih->bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
					pvih->bmiHeader.biCompression = mt.subtype.Data1;
					mts.Add(mt);
				}
				else if(CodecID == "V_DIRAC")
				{
					mt.subtype = MEDIASUBTYPE_DiracVideo;
					mt.formattype = FORMAT_DiracVideoInfo;
					DIRACINFOHEADER* dvih = (DIRACINFOHEADER*)mt.AllocFormatBuffer(FIELD_OFFSET(DIRACINFOHEADER, dwSequenceHeader) + pTE->CodecPrivate.GetCount());
					memset(mt.Format(), 0, mt.FormatLength());
					dvih->hdr.bmiHeader.biSize = sizeof(dvih->hdr.bmiHeader);
					dvih->hdr.bmiHeader.biWidth = (LONG)pTE->v.PixelWidth;
					dvih->hdr.bmiHeader.biHeight = (LONG)pTE->v.PixelHeight;
					dvih->hdr.dwPictAspectRatioX = dvih->hdr.bmiHeader.biWidth;
					dvih->hdr.dwPictAspectRatioY = dvih->hdr.bmiHeader.biHeight;

					BYTE* pSequenceHeader = (BYTE*)dvih->dwSequenceHeader;
					memcpy(pSequenceHeader, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
					dvih->cbSequenceHeader = pTE->CodecPrivate.GetCount();

					mts.Add(mt);
				}
				else if(CodecID == "V_MPEG2")
				{
					BYTE* seqhdr = pTE->CodecPrivate.GetData();
					DWORD len = pTE->CodecPrivate.GetCount();
					int w = pTE->v.PixelWidth;
					int h = pTE->v.PixelHeight;

					if(MakeMPEG2MediaType(mt, seqhdr, len, w, h))
						mts.Add(mt);
				}
				else if(CodecID == "V_THEORA")
				{
					BYTE* thdr = pTE->CodecPrivate.GetData() + 3;

					mt.majortype		= MEDIATYPE_Video;
					mt.subtype			= FOURCCMap('OEHT');
					mt.formattype		= FORMAT_MPEG2_VIDEO;
					MPEG2VIDEOINFO* vih = (MPEG2VIDEOINFO*)mt.AllocFormatBuffer(sizeof(MPEG2VIDEOINFO) + pTE->CodecPrivate.GetCount());
					memset(mt.Format(), 0, mt.FormatLength());
					vih->hdr.bmiHeader.biSize		 = sizeof(vih->hdr.bmiHeader);
					vih->hdr.bmiHeader.biWidth		 = *(WORD*)&thdr[10] >> 4;
					vih->hdr.bmiHeader.biHeight		 = *(WORD*)&thdr[12] >> 4;
					vih->hdr.bmiHeader.biCompression = 'OEHT';
					vih->hdr.bmiHeader.biPlanes		 = 1;
					vih->hdr.bmiHeader.biBitCount	 = 24;
					int nFpsNum	= (thdr[22]<<24)|(thdr[23]<<16)|(thdr[24]<<8)|thdr[25];
					int nFpsDenum	= (thdr[26]<<24)|(thdr[27]<<16)|(thdr[28]<<8)|thdr[29];
					if(nFpsNum) vih->hdr.AvgTimePerFrame = (REFERENCE_TIME)(10000000.0 * nFpsDenum / nFpsNum);
					vih->hdr.dwPictAspectRatioX = (thdr[14]<<16)|(thdr[15]<<8)|thdr[16];
					vih->hdr.dwPictAspectRatioY = (thdr[17]<<16)|(thdr[18]<<8)|thdr[19];
					mt.bFixedSizeSamples = 0;

					vih->cbSequenceHeader = pTE->CodecPrivate.GetCount();
					memcpy (&vih->dwSequenceHeader, pTE->CodecPrivate.GetData(), vih->cbSequenceHeader);

					mts.Add(mt);
				}
				else if(CodecID.Find("V_VP8") == 0) 
				{ 
					mt.subtype = FOURCCMap('08PV'); 
					mt.formattype = FORMAT_VideoInfo; 
					VIDEOINFOHEADER* pvih = (VIDEOINFOHEADER*)mt.AllocFormatBuffer(sizeof(VIDEOINFOHEADER) + pTE->CodecPrivate.GetCount()); 
					memset(mt.Format(), 0, mt.FormatLength()); 
					memcpy(mt.Format() + sizeof(VIDEOINFOHEADER), pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount()); 
					pvih->bmiHeader.biSize = sizeof(pvih->bmiHeader); 
					pvih->bmiHeader.biWidth = (LONG)pTE->v.PixelWidth; 
					pvih->bmiHeader.biHeight = (LONG)pTE->v.PixelHeight; 
					pvih->bmiHeader.biCompression = mt.subtype.Data1; 
					mts.Add(mt); 
				} 
/*
				else if(CodecID == "V_DSHOW/MPEG1VIDEO") // V_MPEG1
				{
					mt.majortype = MEDIATYPE_Video;
					mt.subtype = MEDIASUBTYPE_MPEG1Payload;
					mt.formattype = FORMAT_MPEGVideo;
					MPEG1VIDEOINFO* pm1vi = (MPEG1VIDEOINFO*)mt.AllocFormatBuffer(pTE->CodecPrivate.GetCount());
					memcpy(pm1vi, pTE->CodecPrivate.GetData(), pTE->CodecPrivate.GetCount());
					mt.SetSampleSize(pm1vi->hdr.bmiHeader.biWidth*pm1vi->hdr.bmiHeader.biHeight*4);
					mts.Add(mt);
				}
*/
				REFERENCE_TIME AvgTimePerFrame = 0;

                if(pTE->v.FramePerSec > 0)
					AvgTimePerFrame = (REFERENCE_TIME)(10000000i64 / pTE->v.FramePerSec);
				else if(pTE->DefaultDuration > 0)
					AvgTimePerFrame = (REFERENCE_TIME)pTE->DefaultDuration / 100;

				if(AvgTimePerFrame)
				{
					for(int i = 0; i < mts.GetCount(); i++)
					{
						if(mts[i].formattype == FORMAT_VideoInfo
						|| mts[i].formattype == FORMAT_VideoInfo2
						|| mts[i].formattype == FORMAT_MPEG2Video)
						{
							((VIDEOINFOHEADER*)mts[i].Format())->AvgTimePerFrame = AvgTimePerFrame;
						}
					}
				}

				if(pTE->v.DisplayWidth != 0 && pTE->v.DisplayHeight != 0)
				{
					for(int i = 0; i < mts.GetCount(); i++)
					{
						if(mts[i].formattype == FORMAT_VideoInfo)
						{
							DWORD vih1 = FIELD_OFFSET(VIDEOINFOHEADER, bmiHeader);
							DWORD vih2 = FIELD_OFFSET(VIDEOINFOHEADER2, bmiHeader);
							DWORD bmi = mts[i].FormatLength() - FIELD_OFFSET(VIDEOINFOHEADER, bmiHeader);
							mt.formattype = FORMAT_VideoInfo2;
							mt.AllocFormatBuffer(vih2 + bmi);
							memcpy(mt.Format(), mts[i].Format(), vih1);
							memset(mt.Format() + vih1, 0, vih2 - vih1);
							memcpy(mt.Format() + vih2, mts[i].Format() + vih1, bmi);
							((VIDEOINFOHEADER2*)mt.Format())->dwPictAspectRatioX = (DWORD)pTE->v.DisplayWidth;
							((VIDEOINFOHEADER2*)mt.Format())->dwPictAspectRatioY = (DWORD)pTE->v.DisplayHeight;
							mts.InsertAt(i++, mt);
						}
						else if(mts[i].formattype == FORMAT_MPEG2Video)
						{
							((MPEG2VIDEOINFO*)mts[i].Format())->hdr.dwPictAspectRatioX = (DWORD)pTE->v.DisplayWidth;
							((MPEG2VIDEOINFO*)mts[i].Format())->hdr.dwPictAspectRatioY = (DWORD)pTE->v.DisplayHeight;
						}
					}
				}
			}
Example #27
0
HRESULT CDSMSplitterFilter::CreateOutputs(IAsyncReader* pAsyncReader)
{
    CheckPointer(pAsyncReader, E_POINTER);

    HRESULT hr = E_FAIL;

    m_pFile.Free();
    m_pFile.Attach(DEBUG_NEW CDSMSplitterFile(pAsyncReader, hr, *this, *this));
    if (!m_pFile) {
        return E_OUTOFMEMORY;
    }
    if (FAILED(hr)) {
        m_pFile.Free();
        return hr;
    }

    m_rtNewStart = m_rtCurrent = 0;
    m_rtNewStop = m_rtStop = m_rtDuration = m_pFile->m_rtDuration;

    CAtlArray<BYTE> ids;

    POSITION pos = m_pFile->m_mts.GetStartPosition();
    while (pos) {
        BYTE id;
        CMediaType mt;
        m_pFile->m_mts.GetNextAssoc(pos, id, mt);
        ids.Add(id);
    }

    qsort(ids.GetData(), ids.GetCount(), sizeof(BYTE), compare_id);

    for (size_t i = 0; i < ids.GetCount(); i++) {
        BYTE id = ids[i];
        CMediaType& mt = m_pFile->m_mts[id];

        CStringW name, lang;
        name.Format(L"Output %02u", id);

        CAtlArray<CMediaType> mts;
        mts.Add(mt);

        CAutoPtr<CBaseSplitterOutputPin> pPinOut(DEBUG_NEW CBaseSplitterOutputPin(mts, name, this, this, &hr));

        name.Empty();

        pos = m_pFile->m_sim[id].GetStartPosition();
        while (pos) {
            CStringA key;
            CStringW value;
            m_pFile->m_sim[id].GetNextAssoc(pos, key, value);
            pPinOut->SetProperty(CStringW(key), value);

            if (key == "NAME") {
                name = value;
            }
            if (key == "LANG") {
                lang = ISOLang::ISO6392ToLanguage(CStringA(value));
                if (lang.IsEmpty()) {
                    lang = value;
                }
            }
        }

        if (!name.IsEmpty() || !lang.IsEmpty()) {
            if (!name.IsEmpty()) {
                if (!lang.IsEmpty()) {
                    name += L" (" + lang + L")";
                }
            } else if (!lang.IsEmpty()) {
                name = lang;
            }
            pPinOut->SetName(name);
        }

        EXECUTE_ASSERT(SUCCEEDED(AddOutputPin(id, pPinOut)));
    }

    pos = m_pFile->m_fim.GetStartPosition();
    while (pos) {
        CStringA key;
        CStringW value;
        m_pFile->m_fim.GetNextAssoc(pos, key, value);
        SetProperty(CStringW(key), value);
    }

    for (size_t i = 0; i < m_resources.GetCount(); i++) {
        const CDSMResource& r = m_resources[i];
        if (r.mime == L"application/x-truetype-font" ||
                r.mime == L"application/x-font-ttf" ||
                r.mime == L"application/vnd.ms-opentype") {
            //m_fontinst.InstallFont(r.data);
            m_fontinst.InstallFontMemory(r.data.GetData(), (UINT)r.data.GetCount());
        }
    }

    return !m_pOutputs.IsEmpty() ? S_OK : E_FAIL;
}