PDA

View Full Version : How to play video inside control (frame, axwidget)? (dxshow)



Swat2k
3rd May 2013, 09:01
I want to play video using dxshow, but the method pVideoWindow->put_Owner() returns E_NOINTERFACE. I'm trying to solve this problem in two days, but have not found a solution. Anybody help me ?



void UltraVision::PlayVideo()
{
// DirectShow interfaces
IGraphBuilder *pGraphBuilder;
IMediaControl *pMediaControl;
IMediaEventEx *pMediaEvent;
IVideoWindow *pVideoWindow;
IBasicAudio *pBasicAudio;
IBasicVideo *pBasicVideo;
IMediaSeeking *pMediaSeeking;
IMediaPosition *pMediaPosition;
IVideoFrameStep *pFrameStep;
IBaseFilter *pBaseFilter;
IVMRWindowlessControl* pWindowlessControl;

HRESULT hr;

QAxWidget* mpVideoPlayer = new QAxWidget( ui.axWidget );

hr = CoInitialize( NULL );
hr = CoCreateInstance( CLSID_FilterGraph, NULL, CLSCTX_INPROC_SERVER,IID_IGraphBuilder, (void **) &pGraphBuilder );
hr = pGraphBuilder->QueryInterface( IID_IMediaControl, (void**) &pMediaControl );
hr = pGraphBuilder->QueryInterface( IID_IMediaEvent, (void **) &pMediaEvent);
hr = pGraphBuilder->QueryInterface( IID_IMediaSeeking, (void **) &pMediaSeeking );
hr = pGraphBuilder->QueryInterface( IID_IMediaPosition, (void **) &pMediaPosition);
hr = pGraphBuilder->QueryInterface( IID_IVideoWindow, (void **) &pVideoWindow );

if( pVideoWindow )
{
hr = pVideoWindow->put_Owner( (OAHWND) ui.axWidget->winId() ) );
hr = pVideoWindow->put_WindowStyle( WS_CHILD | WS_CLIPCHILDREN );
}

hr = InitWindowlessVMR( (HWND) mpVideoPlayer->winId( ), pGraphBuilder, &pWindowlessControl );

if( SUCCEEDED( hr ) )
{
// Build the graph. For example:
hr = pGraphBuilder->RenderFile( L"E:\\Video\\12\\Spartacus.S03E08.HDTVRip.avi", NULL );
}


// Find the native video size.
long lWidth, lHeight;
hr = pWindowlessControl->GetNativeVideoSize( &lWidth, &lHeight, NULL, NULL );

if ( SUCCEEDED( hr ) )
{
RECT rcSrc, rcDest;
// Set the source rectangle.
SetRect( &rcSrc, 0, 0, lWidth, lHeight );

// Get the window client area.
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcDest );
// Set the destination rectangle.
SetRect(&rcDest, 1, 1, 558, 349);

// Set the video position.
hr = pWindowlessControl->SetVideoPosition( &rcSrc, &rcDest );

// Add this code to make the video initially show up once opening the file
PAINTSTRUCT ps;
HDC hdc;
RECT rcClient;
GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcClient );
hdc = BeginPaint( (HWND) mpVideoPlayer->winId( ), &ps );
if( pWindowlessControl != NULL )
{
// Find the region where the application can paint by subtracting
// the video destination rectangle from the client area.
// (Assume that g_rcDest was calculated previously.)
HRGN rgnClient = CreateRectRgnIndirect( &rcClient );
HRGN rgnVideo = CreateRectRgnIndirect( &rcDest );
CombineRgn( rgnClient, rgnClient, rgnVideo, RGN_DIFF );

// Paint on window.
HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE );
FillRgn( hdc, rgnClient, hbr );

// Clean up.
DeleteObject( hbr );
DeleteObject( rgnClient );
DeleteObject( rgnVideo );

// Request the VMR to paint the video.
HRESULT hr = pWindowlessControl->RepaintVideo( (HWND) mpVideoPlayer->winId( ), hdc );
}
}

getFrameStepInterface(pGraphBuilder, pFrameStep);

pMediaControl->Run( );

}