PDA

View Full Version : Using DirectShow and COM objects



ToddAtWSU
24th February 2006, 14:55
I am trying to use Microsofts DirectShow objects inside a QAxWidget. I know there is a queryInterface() for QAxWidgets that I am supposed to use, but how do I add the COM object to that widget? Here is the code for adding the COM object that I have so far, neither works:

mpVideoPlayer = new QAxWidget( mpFrame );
//mpVideoPlayer->setControl( "{D1EB6D20-8923-11d0-9D97-00A0C90A43CB}" );
mpVideoPlayer->setGeometry( QRect( 15, 46, 551, 341 ) );
//mpVideoPlayer->queryInterface( IID_IVideoWindow, &pVW );

Here is the reference code for adding a DirectShow object in a MFC application:

USES_CONVERSION;
WCHAR wFile[MAX_PATH];
HRESULT hr;

if (!szFile)
return E_POINTER;

// Clear open dialog remnants before calling RenderFile()
UpdateWindow(ghApp);

// Convert filename to wide character string
wcsncpy(wFile, T2W(szFile), NUMELMS(wFile)-1);
wFile[MAX_PATH-1] = 0;

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

if(SUCCEEDED(hr))
{
// Have the graph builder construct its the appropriate graph automatically
JIF(pGB->RenderFile(wFile, NULL));

// QueryInterface for DirectShow interfaces
JIF(pGB->QueryInterface(IID_IMediaControl, (void **)&pMC));
JIF(pGB->QueryInterface(IID_IMediaEventEx, (void **)&pME));
JIF(pGB->QueryInterface(IID_IMediaSeeking, (void **)&pMS));
JIF(pGB->QueryInterface(IID_IMediaPosition, (void **)&pMP));

// Query for video interfaces, which may not be relevant for audio files
JIF(pGB->QueryInterface(IID_IVideoWindow, (void **)&pVW));
JIF(pGB->QueryInterface(IID_IBasicVideo, (void **)&pBV));

// Query for audio interfaces, which may not be relevant for video-only files
JIF(pGB->QueryInterface(IID_IBasicAudio, (void **)&pBA));

// Is this an audio-only file (no video component)?
CheckVisibility();

// Have the graph signal event via window callbacks for performance
JIF(pME->SetNotifyWindow((OAHWND)ghApp, WM_GRAPHNOTIFY, 0));

if (!g_bAudioOnly)
{
// Setup the video window
JIF(pVW->put_Owner((OAHWND)ghApp));
JIF(pVW->put_WindowStyle(WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN));

JIF(InitVideoWindow(1, 1));
GetFrameStepInterface();
}
else
{
// Initialize the default player size and enable playback menu items
JIF(InitPlayerWindow());
}

// Complete window initialization
ShowWindow(ghApp, SW_SHOWNORMAL);
UpdateWindow(ghApp);
SetForegroundWindow(ghApp);
g_bFullscreen = FALSE;
g_PlaybackRate = 1.0;
UpdateMainTitle();

#ifdef REGISTER_FILTERGRAPH
hr = AddGraphToRot(pGB, &g_dwGraphRegister);
if (FAILED(hr))
{
Msg(TEXT("Failed to register filter graph with ROT! hr=0x%x"), hr);
g_dwGraphRegister = 0;
}
#endif

// Run the graph to play the media file
JIF(pMC->Run());

g_psCurrent=Running;
SetFocus(ghApp);
}

return hr;

This is really bugging me why I cant figure this out. Please help!:confused:

jacek
24th February 2006, 15:21
To use queryInterface() you need to generate the definition of the interface from its IDL description.

ToddAtWSU
24th February 2006, 16:08
I am not sure what you mean by IDL description. I am new to using COM objects and relatively new to Qt. So a code example would be greatly appreciated.

jacek
24th February 2006, 16:58
I am not sure what you mean by IDL description. I am new to using COM objects and relatively new to Qt.
IDL is an Interface Description Language. If you don't have the .idl file for the COM object you want to use, you will have to use dynamicCall() method.

Rayven
27th February 2006, 15:15
I have been following the posts to the DirectShow since I am trying to use the same things in my application. I was looking up the dynamicCall() functionality, but it seems that it is used for controlling the video (such as play, stop, rewind etc) and not for inserting the video into the QAxWidget. How do I setup the QAxWidget to to use a COM object, more specifically, DirectShow. Example code would be very helpful!

Thanks:confused:

jacek
27th February 2006, 15:35
How do I setup the QAxWidget to to use a COM object, more specifically, DirectShow. Example code would be very helpful!
You must set the control property.

http://doc.trolltech.com/4.1/qaxbase.html#control-prop