Example #1
0
POSITION CPlaylist::Shuffle()
{
    static INT_PTR idx = 0;
    static INT_PTR count = 0;
    static CAtlArray<plsort_t> a;

    ASSERT(GetCount() > 2);
    // insert or remove items in playlist, or index out of bounds then recalculate
    if ((count != GetCount()) || (idx >= GetCount())) {
        a.RemoveAll();
        idx = 0;
        a.SetCount(count = GetCount());

        POSITION pos = GetHeadPosition();
        for (INT_PTR i = 0; pos; i++, GetNext(pos)) {
            a[i].pos = pos;    // initialize position array
        }

        //Use Fisher-Yates shuffle algorithm
        srand((unsigned)time(nullptr));
        for (INT_PTR i = 0; i < (count - 1); i++) {
            INT_PTR r = i + (rand() % (count - i));
            POSITION temp = a[i].pos;
            a[i].pos = a[r].pos;
            a[r].pos = temp;
        }
    }

    return a[idx++].pos;
}
Example #2
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 #3
0
static void LoadInternalExceptionList()
{
	g_aException.SetCount( 0, 32 );

	LPCTSTR rs = NULL;
	size_t len = AtlLoadString(
		IDS_INTERNAL_EXCEPTIONS,
		reinterpret_cast<LPTSTR>(&rs),
		0
		);

	LPTSTR buf = reinterpret_cast<LPTSTR>( malloc((len + 1) * sizeof(TCHAR)) );
	_tcsncpy( buf, rs, len );
	buf[len] = 0;

	LPCTSTR p = _tcstok( buf, _T("|") );
	while( p != NULL )
	{
		CExceptionInfo ei;
		ei.bUser = false;
		ei.bFiltered = false;
		ei.dwCode = _tcstoul( p, NULL, 0 );
		p = _tcstok( NULL, _T("|") );
		_tcsncpy( ei.szName, p, _countof(ei.szName) );
		ei.szName[_countof(ei.szName) - 1] = 0;
		g_aException.Add( ei );
		p = _tcstok( NULL, _T("|") );
	}

	free( buf );
}
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
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 #6
0
void Glyph::CreateSplineCoeffs(const CRect& spdrc)
{
    spline.RemoveAll();

    if (style.placement.path.IsEmpty()) {
        return;
    }

    size_t i = 0, j = style.placement.path.GetCount();

    CAtlArray<Point> pts;
    pts.SetCount(j + 2);

    Point p;

    while (i < j) {
        p.x = style.placement.path[i].x * scale.cx + spdrc.left * 64;
        p.y = style.placement.path[i].y * scale.cy + spdrc.top * 64;
        pts[++i] = p;
    }

    if (pts.GetCount() >= 4) {
        if (pts[1].x == pts[j].x && pts[1].y == pts[j].y) {
            pts.SetAt(0, pts[j - 1]);
            pts.SetAt(j + 1, pts[2]);
        } else {
            p.x = pts[1].x * 2 - pts[2].x;
            p.y = pts[1].y * 2 - pts[2].y;
            pts.SetAt(0, p);

            p.x = pts[j].x * 2 - pts[j - 1].x;
            p.y = pts[j].y * 2 - pts[j - 1].y;
            pts.SetAt(j + 1, p);
        }

        spline.SetCount(pts.GetCount() - 3);

        for (size_t i = 0, j = pts.GetCount() - 4; i <= j; i++) {
            static const float _1div6 = 1.0f / 6;

            SplineCoeffs sc;

            sc.cx[3] = _1div6 * (-  pts[i + 0].x + 3 * pts[i + 1].x - 3 * pts[i + 2].x + pts[i + 3].x);
            sc.cx[2] = _1div6 * (3 * pts[i + 0].x - 6 * pts[i + 1].x + 3 * pts[i + 2].x);
            sc.cx[1] = _1div6 * (-3 * pts[i + 0].x                + 3 * pts[i + 2].x);
            sc.cx[0] = _1div6 * (pts[i + 0].x + 4 * pts[i + 1].x + 1 * pts[i + 2].x);

            sc.cy[3] = _1div6 * (-  pts[i + 0].y + 3 * pts[i + 1].y - 3 * pts[i + 2].y + pts[i + 3].y);
            sc.cy[2] = _1div6 * (3 * pts[i + 0].y - 6 * pts[i + 1].y + 3 * pts[i + 2].y);
            sc.cy[1] = _1div6 * (-3 * pts[i + 0].y                + 3 * pts[i + 2].y);
            sc.cy[0] = _1div6 * (pts[i + 0].y + 4 * pts[i + 1].y + 1 * pts[i + 2].y);

            spline.SetAt(i, sc);
        }
    }
}
Example #7
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 #8
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 #10
0
POSITION CPlaylist::Shuffle()
{
	CAtlArray<plsort2_t> a;
	a.SetCount(GetCount());
	srand((unsigned)time(NULL));
	POSITION pos = GetHeadPosition();
	for(int i = 0; pos; i++, GetNext(pos))
		a[i].pos = pos;
	
	pos = GetPos();
	int rnd = Rand(0, a.GetCount()-1);
	while(pos == a[rnd].pos) rnd = Rand(0, a.GetCount()-1);

	return a[rnd].pos;
}
Example #11
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(); 
	}
}
Example #12
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 #13
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 #14
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 #15
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 #16
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 #17
0
void MergeRects(const XyRectExList& input, XyRectExList* output)
{
    int input_count = input.GetCount();
    if(output==NULL || input_count==0)
        return;

    typedef CAtlList<XyRectEx> Segment;

    struct BreakPoint
    {
        int x;
        const XyRectEx* rect;

        inline bool operator<(const BreakPoint& breakpoint ) const
        {
            return (x < breakpoint.x);
        }
    };

    std::vector<int> vertical_breakpoints(2*input_count);
    std::vector<BreakPoint> herizon_breakpoints(input_count);

    POSITION pos = input.GetHeadPosition();
    for(int i=0; i<input_count; i++)
    {
        const XyRectEx& rect = input.GetNext(pos);
        vertical_breakpoints[2*i]=rect.top;
        vertical_breakpoints[2*i+1]=rect.bottom;

        herizon_breakpoints[i].x = rect.left;
        herizon_breakpoints[i].rect = &rect;
    }

    std::sort(vertical_breakpoints.begin(), vertical_breakpoints.end());
    std::sort(herizon_breakpoints.begin(), herizon_breakpoints.end());

    CAtlArray<Segment> tempSegments;
    tempSegments.SetCount(vertical_breakpoints.size()-1);
    int prev = vertical_breakpoints[0], count = 0;
    for(unsigned ptr = 1; ptr<vertical_breakpoints.size(); ptr++)
    {
        if(vertical_breakpoints[ptr] != prev)
        {
            Segment& seg = tempSegments[count];
            seg.AddTail();
            seg.GetTail().SetRect(INT_MIN, prev, INT_MIN, vertical_breakpoints[ptr]);
            seg.GetTail().item_ex_list.reset(new PCompositeDrawItemExList());

            prev = vertical_breakpoints[ptr];
            count++;
        }
    }

    for(int i=0; i<input_count; i++)
    {
        const XyRectEx& rect = *herizon_breakpoints[i].rect;

        int start = 0, mid, end = count;

        while(start<end)
        {
            mid = (start+end)>>1;
            if(tempSegments[mid].GetTail().top < rect.top)
            {
                start = mid+1;
            }
            else
            {
                end = mid;
            }
        }
        for(; start < count; start++)
        {
            CAtlList<XyRectEx>& cur_line = tempSegments[start];
            XyRectEx & item = cur_line.GetTail();
            if (item.top >= rect.bottom)
            {
                break;
            }
            if (item.right<rect.left)
            {
                cur_line.AddTail();
                XyRectEx & new_item = cur_line.GetTail();
                new_item.SetRect( rect.left, item.top, rect.right, item.bottom );
                new_item.item_ex_list.reset(new PCompositeDrawItemExList());
                new_item.item_ex_list->AddTailList( rect.item_ex_list.get() );
            }
            else
            {
                if (item.right<rect.right)
                {
                    item.right = rect.right;
                }
                item.item_ex_list->AddTailList( rect.item_ex_list.get() );
            }
        }
    }

    for (int i=count-1;i>0;i--)
    {
        CAtlList<XyRectEx>& cur_line = tempSegments[i];
        CAtlList<XyRectEx>& upper_line = tempSegments[i-1];

        POSITION pos_cur_line = cur_line.GetTailPosition();
        XyRectEx *cur_rect = &cur_line.GetPrev(pos_cur_line);
        if(cur_rect->top == upper_line.GetTail().bottom)
        {
            POSITION pos = upper_line.GetTailPosition();                          
            while(pos)
            {
                XyRectEx& upper_rect = upper_line.GetPrev(pos);
                while( upper_rect.right<cur_rect->right || upper_rect.left<cur_rect->left )
                {
                    output->AddHead(*cur_rect);
                    //if(!cur_line.IsEmpty())
                    cur_rect = &cur_line.GetPrev(pos_cur_line);
                }
                if(!pos_cur_line)
                    break;

                if(upper_rect.right==cur_rect->right && upper_rect.left==cur_rect->left)
                {
                    upper_rect.bottom = cur_rect->bottom;
                    upper_rect.item_ex_list->AddTailList( cur_rect->item_ex_list.get() );
                    //if(!cur_line.IsEmpty())
                    cur_rect = &cur_line.GetPrev(pos_cur_line);
                }
                //else if ( upper_rect.right>cur_rect.right || upper_rect.left>cur_rect.left )             
            }
        }
        while(pos_cur_line)
        {
            output->AddHead(*cur_rect);
            cur_rect = &cur_line.GetPrev(pos_cur_line);
        }
    }
    if(count>0)
    {
        CAtlList<XyRectEx>& cur_line = tempSegments[0];
        POSITION pos_cur_line = cur_line.GetTailPosition();
        XyRectEx *cur_rect = &cur_line.GetPrev(pos_cur_line);
        while(pos_cur_line)
        {
            output->AddHead(*cur_rect);
            cur_rect = &cur_line.GetPrev(pos_cur_line);
        }
    }
}
Example #18
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 #19
0
void CBinRes::BufferResource( CAtlArray<BYTE>& buff )
{
	buff.SetCount( m_size );
	memcpy( buff.GetData(), m_resAdrr, m_size );
}
Example #20
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 #21
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 #22
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 #23
0
bool CAviPlotterWnd::Create(CAviFile* pAF, CRect r, CWnd* pParentWnd)
{
	if(!CreateEx(WS_EX_CLIENTEDGE, _T("STATIC"), _T(""), WS_CHILD|WS_VISIBLE, r, pParentWnd, 0))
		return(false);

	GetClientRect(r);
	int w = r.Width();
	int h = r.Height() - GRAPHFOOTER;

	CDC* pDC = GetDC();
	m_dc.CreateCompatibleDC(pDC);
	m_bm.CreateCompatibleBitmap(pDC, r.Width(), r.Height());
	ReleaseDC(pDC);

	CBitmap* pOldBitmap = m_dc.SelectObject(&m_bm);
	
	m_dc.FillSolidRect(r, 0);

	{
		CPen pen(PS_DOT, 1, 0x008000);
		CPen* pOldPen = m_dc.SelectObject(&pen);
		for(int y = 0, dy = max(h/10,1); y < h; y += dy) {if(y == 0) continue; m_dc.MoveTo(0, y); m_dc.LineTo(w, y);}
		for(int x = 0, dx = max(w/10,1); x < w; x += dx) {if(x == 0) continue; m_dc.MoveTo(x, 0); m_dc.LineTo(x, w);}
		m_dc.SelectObject(pOldPen);
	}

	{
		CPen pen(PS_SOLID, 1, 0x00ff00);
		CPen* pOldPen = m_dc.SelectObject(&pen);
		m_dc.MoveTo(15, 30);
		m_dc.LineTo(15, 2);
		m_dc.LineTo(19, 10);
		m_dc.LineTo(11, 10);
		m_dc.LineTo(15, 2);
		m_dc.MoveTo(w-30-10, h-15); 
		m_dc.LineTo(w-2-10, h-15);
		m_dc.LineTo(w-10-10, h-19);
		m_dc.LineTo(w-10-10, h-11);
		m_dc.LineTo(w-2-10, h-15);
		m_dc.SelectObject(pOldPen);

		m_dc.SetTextColor(0x008000);
		m_dc.TextOut(20, 10, _T("Chunk"));

		CSize size = m_dc.GetTextExtent(_T("Time"));
		m_dc.TextOut(w - size.cx - 10, h - size.cy - 20, _T("Time"));
	}

	COLORREF clr[] = {0x0000ff,0xff0000,0x40ffff,0xff40ff,0xffff40,0xffffff};

	for(int i = 0, y = 40, dy = m_dc.GetTextExtent(_T("Stream N")).cy + 1; i < (int)pAF->m_avih.dwStreams; i++, y += dy)
	{
		m_dc.SetTextColor(clr[i%pAF->m_avih.dwStreams]);
		m_dc.SetBkMode(TRANSPARENT);
		CString str;
		str.Format(_T("Stream %d"), i);
		m_dc.TextOut(10, y, str);
	}

	DWORD nmax = 0, tmax = 0;

	for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++)
	{
		int cnt = pAF->m_strms[i]->cs2.GetCount();
		if(cnt <= 0) continue;
		CAviFile::strm_t::chunk2& c2 = pAF->m_strms[i]->cs2[cnt-1];
		nmax = max(nmax, c2.n);
		tmax = max(tmax, c2.t);
	}

	if(nmax > 0 && tmax > 0)
	{
		CAtlArray<CPen> pen;
		pen.SetCount(pAF->m_avih.dwStreams);
		for(int i = 0; i < pen.GetCount(); i++)
			pen[i].CreatePen(PS_SOLID, 2, clr[i]);

		CAtlArray<CPoint> pp;
		pp.SetCount(pAF->m_avih.dwStreams);
		for(int i = 0; i < pen.GetCount(); i++)
			pp[i].SetPoint(-1, -1);

		m_chunkdist.SetCount(w);
		memset(m_chunkdist.GetData(), 0, sizeof(int)*w);

		DWORD* curchunks = DNew DWORD[pAF->m_avih.dwStreams];
		memset(curchunks, 0, sizeof(DWORD)*pAF->m_avih.dwStreams);

		CAviFile::strm_t::chunk2 cs2last = {(DWORD)-1, 0};

		while(1)
		{
			CAviFile::strm_t::chunk2 cs2min = {LONG_MAX, LONG_MAX};

			int n = -1;
			for(int i = 0; i < (int)pAF->m_avih.dwStreams; i++)
			{
				int curchunk = curchunks[i];
				if(curchunk >= pAF->m_strms[i]->cs2.GetCount()) continue;
				CAviFile::strm_t::chunk2& cs2 = pAF->m_strms[i]->cs2[curchunk];
				if(cs2.t < cs2min.t) {cs2min = cs2; n = i;}
			}
			if(n == -1) break;


			CPoint p;
			p.x = (int)(1.0 * w * cs2min.t / tmax);
			p.y = (int)(h - 1.0 * h * cs2min.n / nmax);
			if(pp[n] != p)
			{
				CPen* pOldPen = m_dc.SelectObject(&pen[n]);
				if(pp[n] == CPoint(-1, -1)) m_dc.MoveTo(p);
				else {m_dc.MoveTo(pp[n]); m_dc.LineTo(p);}
				m_dc.SelectObject(pOldPen);
				pp[n] = p;
			}

			int dist = abs((int)cs2min.n - (int)cs2last.n);

			if(cs2last.t >= 0 /*&& dist >= 1000*/)
			{
				if(p.x >= 0 && p.x < w)
				{
					m_chunkdist[p.x] = max(m_chunkdist[p.x], dist);
				}
			}

			curchunks[n]++;
			cs2last = cs2min;
		}

		CPen red(PS_SOLID, 1, 0x0000ff);
		CPen green(PS_SOLID, 1, 0x00ff00);

		for(int x = 0; x < w; x++)
		{
			CPen* pOldPen = m_dc.SelectObject(m_chunkdist[x] >= 1000 ? &red : &green);
			m_dc.MoveTo(x, h);
			m_dc.LineTo(x, h + GRAPHFOOTER);
			m_dc.SelectObject(pOldPen);
		}

		delete [] curchunks;
	}

	m_dc.SelectObject(pOldBitmap);

	return(true);
}
Example #24
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;
						}
					}
				}
			}