HRESULT CWavPackDSSplitter::TryToLoadCorrectionFile()
{
    // Here is the nasty hacky stuff :>

    HRESULT hr = S_FALSE;
    IPin *pPinOutSrc = NULL;
    IFileSourceFilter *pFSF = NULL;
    LPOLESTR pszFileName = NULL;
    IBaseFilter* pSrcFilterCorr = NULL;
    IFileSourceFilter*	pFSFCorr = NULL;
    IEnumPins *pEnum = NULL;
    IPin *pPinNew = NULL;
    BOOL bCorrectionFileLoaded = FALSE;
    IEnumFilters* pEnumFilers = NULL;
    BOOL bSrcFileAlreadyLoaded = FALSE;

    DebugLog("===> Entering CWavPackDSSplitter::TryToLoadCorrectionFile... 0x%08X", GetCurrentThreadId());

    if((m_bDontTryToLoadCorrectionFileAgain == TRUE) ||
       (m_pInputPinCorr == NULL) ||
       (m_pInputPinCorr->IsConnected() == TRUE))
    {
        DebugLog("<=== Leaving CWavPackDSSplitter::TryToLoadCorrectionFile already loaded ?... 0x%08X", GetCurrentThreadId());
        return hr;
    }

    if((m_pInputPin->m_pWavPackParser->first_wphdr.flags & HYBRID_FLAG) != HYBRID_FLAG)
    {
        // Not an hybrid file, don't even try
        m_bDontTryToLoadCorrectionFileAgain = TRUE;
        DebugLog("<=== Leaving CWavPackDSSplitter::TryToLoadCorrectionFile not hybrid... 0x%08X", GetCurrentThreadId());
        return hr;
    }
    
#define IF_FAIL_BREAK(x) if(FAILED(x)) { break; }
    
    do {
        hr = m_pInputPin->ConnectedTo(&pPinOutSrc);
        IF_FAIL_BREAK(hr);

        // Get a pointer on the source filter
        PIN_INFO pi;
        pi.pFilter = NULL;
        hr = pPinOutSrc->QueryPinInfo(&pi);
        IF_FAIL_BREAK(hr);
        
        // Get source filter IFileSourceFilter interface    
        hr = pi.pFilter->QueryInterface(IID_IFileSourceFilter, (void **)&pFSF);
        IF_FAIL_BREAK(hr);
        
        // Get filename
        hr = pFSF->GetCurFile(&pszFileName, NULL);
        IF_FAIL_BREAK(hr);

        // Create correction file filename
        WCHAR pszFileNameC[MAX_PATH];
        ZeroMemory(pszFileNameC, sizeof(WCHAR)*MAX_PATH);
        int cch = lstrlenW(pszFileName);
        CopyMemory(pszFileNameC, pszFileName, cch*sizeof(WCHAR));
        pszFileNameC[cch] = 'c';
        
        IFilterGraph* pFG = GetFilterGraph();

        // Search in the graph in case the source filter with correction file already exist
        hr = pFG->EnumFilters(&pEnumFilers);
        IF_FAIL_BREAK(hr);
        while(pEnumFilers->Next(1, &pSrcFilterCorr, 0) == S_OK)
        {
            HRESULT lhr;
            lhr = pSrcFilterCorr->QueryInterface(IID_IFileSourceFilter, (void**)&pFSFCorr);
            if(SUCCEEDED(lhr))
            {
                LPOLESTR pszFileNameCandidate = NULL;
                pFSFCorr->GetCurFile(&pszFileNameCandidate, NULL);
                if(memcmp(pszFileNameCandidate,pszFileNameC,(cch+1)*sizeof(WCHAR)) == 0)
                {
                    // This is the good file
                    bSrcFileAlreadyLoaded = TRUE;
                    if(pszFileNameCandidate != NULL)
                    {
                        CoTaskMemFree(pszFileNameCandidate);
                    }
                    break;
                }
                if(pszFileNameCandidate != NULL)
                {
                    CoTaskMemFree(pszFileNameCandidate);
                }
            }
            pSrcFilterCorr->Release();
            pSrcFilterCorr = NULL;
        }

        if(bSrcFileAlreadyLoaded == FALSE)
        {        
            // Create new file source filter
            hr = CoCreateInstance(CLSID_AsyncReader,
                NULL, CLSCTX_INPROC_SERVER, IID_IBaseFilter,
                (void**)&pSrcFilterCorr);
            IF_FAIL_BREAK(hr);
        
            hr = pFG->AddFilter(pSrcFilterCorr, pszFileNameC);
            IF_FAIL_BREAK(hr);
        
            hr = pSrcFilterCorr->QueryInterface(IID_IFileSourceFilter, (void**)&pFSFCorr);
            IF_FAIL_BREAK(hr);

            hr = pFSFCorr->Load(pszFileNameC, NULL);
            IF_FAIL_BREAK(hr);
        }
        
        // Get first pin and connect it
        hr = pSrcFilterCorr->EnumPins(&pEnum);
        IF_FAIL_BREAK(hr);
        if(pEnum->Next(1, &pPinNew, 0) == S_OK)
        {            
            hr = pFG->ConnectDirect(pPinNew, m_pInputPinCorr, NULL);
            bCorrectionFileLoaded = SUCCEEDED(hr);
        }
        
    } while(0);
    
    if((bCorrectionFileLoaded == FALSE) && (pSrcFilterCorr != NULL))
    {
        IFilterGraph* pFG = GetFilterGraph();
        pFG->RemoveFilter(pSrcFilterCorr);
    }

    // Cleanup
    SAFE_RELEASE(pPinNew);
    SAFE_RELEASE(pEnum);
    SAFE_RELEASE(pEnumFilers);
    SAFE_RELEASE(pFSFCorr);
    SAFE_RELEASE(pSrcFilterCorr);
    if(pszFileName != NULL)
    {
        CoTaskMemFree(pszFileName);
    }
    SAFE_RELEASE(pFSF);
    SAFE_RELEASE(pPinOutSrc);
    
#undef IF_FAIL_BREAK
    
    m_bDontTryToLoadCorrectionFileAgain = bCorrectionFileLoaded;

    if(bCorrectionFileLoaded)
    {
        DebugLog("<=== Leaving TryToLoadCorrectionFile successfull 0x%08X", GetCurrentThreadId());
    }
    else
    {
        DebugLog("<=== Leaving TryToLoadCorrectionFile FAILED 0x%08X", GetCurrentThreadId());
    }

    return hr;
}
Exemple #2
0
HRESULT fsPartMediaPlayer::Open(HANDLE hFile, UINT64 uMaxAvail)
{
	HRESULT hr;

	Close ();

	
	m_stream.Attach (hFile, uMaxAvail);

	
	if (m_stream.Get_MediaType () == NULL)
		return E_FAIL;

	m_reader.Set_MediaType (m_stream.Get_MediaType ());

	

	RIF (CoCreateInstance (CLSID_FilterGraph, NULL, CLSCTX_INPROC,
		IID_IGraphBuilder, (void**) &m_pGB));

	IFilterGraph* pFG = NULL;
	RIF (m_pGB->QueryInterface (IID_IFilterGraph, (void**)&pFG));

	RIF (pFG->AddFilter (&m_reader, NULL));
	pFG->Release ();

	RIF (m_pGB->Render (m_reader.GetPin (0)));

	RIF (m_pGB->QueryInterface (IID_IMediaControl, (void**)&m_pMC));
	RIF (m_pGB->QueryInterface (IID_IMediaEventEx, (void**)&m_pME));
	RIF (m_pGB->QueryInterface (IID_IMediaSeeking, (void**)&m_pMS));
	
	m_pGB->QueryInterface (IID_IVideoWindow, (void**)&m_pVW);
	m_pGB->QueryInterface (IID_IBasicAudio, (void**)&m_pBA);

	IBasicVideo* pBV = NULL;
	m_pGB->QueryInterface (IID_IBasicVideo, (void**) &pBV);
	if (pBV != NULL)
	{
		long nW, nH;
		pBV->get_VideoWidth (&nW);
		pBV->get_VideoHeight (&nH);
		m_fVideoRatio = (double)nW / nH;
		pBV->Release ();
	}
	else
	{
		m_fVideoRatio = 1;
	}

	if (m_pVW)
	{
		if (FAILED (m_pVW->put_MessageDrain ((OAHWND)m_hOutWnd)))
		{
			SAFE_RELEASE (m_pVW);
		}
	}

	RIF (m_pME->SetNotifyWindow ((OAHWND)m_hOutWnd, WM_VIDEONOTIFY, LONG(this)));

	if (m_pVW)
	{
		m_pVW->put_Visible (OAFALSE);
		m_pVW->put_WindowStyle (WS_CHILD);
		m_pVW->put_Owner ((OAHWND)m_hOutWnd);

		AutoSize ();

		m_pVW->put_Visible (OATRUE);

		m_pVW->SetWindowForeground (-1);
	}

	m_state = VFPS_STOPPED;

	return S_OK;
}