Exemplo n.º 1
0
/******************************Public*Routine******************************\
* OpenMovie
*
\**************************************************************************/
HRESULT
CMovie::OpenMovie(
    TCHAR *lpFileName
    )
{
    IUnknown        *pUnk;
    HRESULT         hres;
    WCHAR           FileName[MAX_PATH];

    // Check input string
    if (lpFileName == NULL)
        return E_POINTER;

    hres = StringCchCopyW(FileName, NUMELMS(FileName), lpFileName);

    hres = CoInitializeEx(NULL, COINIT_APARTMENTTHREADED);
    if(hres == S_FALSE)
        CoUninitialize();

    hres = CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
                            IID_IUnknown, (LPVOID *)&pUnk);

    if(SUCCEEDED(hres))
    {
        m_Mode = MOVIE_OPENED;
        hres = pUnk->QueryInterface(IID_IFilterGraph, (LPVOID *)&m_Fg);
        if(FAILED(hres))
        {
            pUnk->Release();
            return hres;
        }

        hres = AddVideoMixingRendererToFG();
        if(FAILED(hres))
        {
            m_Fg->Release(); m_Fg = NULL;
            return hres;
        }

        hres = pUnk->QueryInterface(IID_IGraphBuilder, (LPVOID *)&m_Gb);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            return hres;
        }

        hres = RenderFileToVideoRenderer( m_Gb, FileName, TRUE);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            m_Gb->Release(); m_Gb = NULL;
            return hres;
        }

        hres = m_Wc->QueryInterface(IID_IVMRMixerControl9, (LPVOID *) &m_pMixControl);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            m_Gb->Release(); m_Gb = NULL;
            m_pMixControl = NULL;
            return hres;
        }

        hres = pUnk->QueryInterface(IID_IMediaControl, (LPVOID *)&m_Mc);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            m_Gb->Release(); m_Gb = NULL;
            return hres;
        }

        //
        // Not being able to get the IMediaEvent interface doesn't
        // necessarly mean that we can't play the graph.
        //
        pUnk->QueryInterface(IID_IMediaEvent, (LPVOID *)&m_Me);
        GetMovieEventHandle();

        pUnk->QueryInterface(IID_IMediaSeeking, (LPVOID *)&m_Ms);
        pUnk->Release();
        return S_OK;
    }
    else
    {
        m_Fg = NULL;
    }

    return hres;
}
Exemplo n.º 2
0
/******************************Public*Routine******************************\
* OpenMovie
*
\**************************************************************************/
HRESULT
CMpegMovie::OpenMovie(
    TCHAR *lpFileName, BOOL bWin9xCompatible
    )
{
    USES_CONVERSION;
    IUnknown        *pUnk;
    HRESULT         hres;
    WCHAR           FileName[MAX_PATH];

    wcscpy(FileName, T2W(lpFileName));

    hres = CoInitialize(NULL);
    if(hres == S_FALSE)
        CoUninitialize();

	if ( bWin9xCompatible || !VerifyVMR() ) {

		//----------------------------------------------------
		// If video must be compatible with Win9x or 
		//  VMR don't exist on the system use old style movie.
		//----------------------------------------------------


		// Get the interface for DirectShow's GraphBuilder
		hres = CoCreateInstance( CLSID_FilterGraph, 
								NULL, CLSCTX_INPROC_SERVER, 
                         IID_IGraphBuilder, (void **)&m_Gb );

		if( SUCCEEDED(hres) )
		{
			// Have the graph builder construct its the appropriate graph automatically
			hres = m_Gb->RenderFile(FileName, NULL);
			if ( FAILED(hres) ) {
				m_Gb->Release(); m_Gb = NULL;
				return hres;
			}

			// QueryInterface for DirectShow interfaces
			hres = m_Gb->QueryInterface(IID_IMediaControl, (void **)&m_Mc);
			if ( FAILED(hres) ) {
				m_Mc->Release(); m_Mc = NULL;
				m_Gb->Release(); m_Gb = NULL;
				return hres;
			}

			hres = m_Gb->QueryInterface(IID_IMediaEventEx, (void **)&m_Me);
			if (m_Me) m_Me->SetNotifyWindow(NULL, 0, 0);

			hres = m_Gb->QueryInterface(IID_IMediaSeeking, (void **)&m_Ms);
			if ( FAILED(hres) ) {
				m_Ms->Release(); m_Ms = NULL;
				m_Me->Release(); m_Me = NULL;
				m_Mc->Release(); m_Mc = NULL;
				m_Gb->Release(); m_Gb = NULL;
				return hres;
			}

			// Query for video interfaces, 
			//  which may not be relevant for audio files.
			hres = m_Gb->QueryInterface(IID_IVideoWindow, (void **)&m_Vw);
			if ( FAILED(hres) ) {
				m_Vw = NULL;
			}
			hres = m_Gb->QueryInterface(IID_IBasicVideo, (void **)&m_Bv);
			if ( FAILED(hres) ) {
				m_Bv = NULL;
			}
			
		
			// Query for audio interfaces, which may not be relevant for video-only files
			hres = m_Gb->QueryInterface(IID_IBasicAudio, (void **)&m_Ba);
			if ( FAILED(hres) ) {
				m_Ba = NULL;
			}


			if ( m_Vw )
			{
				m_Vw->put_Visible(OAFALSE);
				m_Vw->put_AutoShow(OAFALSE);
            m_Vw->put_Owner((OAHWND)m_hwndApp);
				m_Vw->put_MessageDrain((OAHWND)m_hwndApp);
            m_Vw->put_WindowStyle( WS_CHILD | WS_CLIPSIBLINGS 
					| WS_CLIPCHILDREN );

			}

			m_bWin9xCompatible = TRUE;			

		}

		return hres;


	} else {

		//------------------------------------------
		//We can play using new WinXp WMR technique.
		//------------------------------------------

    hres = CoCreateInstance(
        CLSID_FilterGraph,
        NULL,
		  CLSCTX_INPROC_SERVER,
        IID_IUnknown,
        (LPVOID *)&pUnk);

    if(SUCCEEDED(hres))
    {
        m_Mode = MOVIE_OPENED;
        hres = pUnk->QueryInterface(IID_IFilterGraph, (LPVOID *)&m_Fg);
        if(FAILED(hres))
        {
            pUnk->Release();
            return hres;
        }

        hres = AddVideoMixingRendererToFG();
        if(FAILED(hres))
        {
            m_Fg->Release(); m_Fg = NULL;
            return hres;
        }

        hres = pUnk->QueryInterface(IID_IGraphBuilder, (LPVOID *)&m_Gb);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            return hres;
        }

        hres = m_Gb->RenderFile(FileName, NULL);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            m_Gb->Release(); m_Gb = NULL;
            return hres;
        }

        hres = pUnk->QueryInterface(IID_IMediaControl, (LPVOID *)&m_Mc);
        if(FAILED(hres))
        {
            pUnk->Release();
            m_Fg->Release(); m_Fg = NULL;
            m_Wc->Release(); m_Wc = NULL;
            m_Gb->Release(); m_Gb = NULL;
            return hres;
        }

		  // Query audio control
		  hres = m_Gb->QueryInterface(IID_IBasicAudio, (LPVOID *)&m_Ba);
		  if (FAILED(hres))
		  {
			  m_Ba = NULL;
		  }

        //
        // Not being able to get the IMediaEvent interface doesn't
        // necessarly mean that we can't play the graph.
        //
        pUnk->QueryInterface(IID_IMediaEventEx, (LPVOID *)&m_Me);
			if (m_Me) m_Me->SetNotifyWindow(NULL, 0, 0);

        pUnk->QueryInterface(IID_IMediaSeeking, (LPVOID *)&m_Ms);
        pUnk->Release();

		  m_bWin9xCompatible = FALSE;

        return S_OK;
    }
    else
    {
        m_Fg = NULL;
    }

    return hres;

	}
}