Directly Accessing the DirectShow Objects

The ltmmCapture, ltmmConvert, and ltmmPlay objects implement the GetSubObject function to allow the user the ability to gain access to DirectShow specific objects.

For example, you can gain access to the ltmmCapture object’s underlying FilterGraph and setup log file output.

This is demonstrated, in C, with the following code:

IltmmCapture *pCapture;  // initialized elsewhere
HANDLE hLogFile;   // handle to logfile, set elsewhere
HRESULT hr;
IUnknown *pUnk;
IGraphBuilder *pFg;

// call the Capture object to retrieve the FilterGraph
hr = IltmmCapture_GetSubObject(pCapture, ltmmCapture_Object_FilterGraph, &pUnk);
if(SUCCEEDED(hr))
{
   // retrieve the IGraphBuilder interface
   hr = IUnknown_QueryInterface(pUnk, IID_IGraphBuilder, (void**) &pFg) ;
   IUnknown_Release(pUnk);
   if(SUCCEEDED(hr))
   {
      // assign the logfile
      IGraphBuilder _SetLogFile(pFg, (DWORD_PTR) hLogFile);
      IUnknown_Release(pFg);
   }
}

In C++, you would do the following:

IltmmCapture *pCapture;  // initialized elsewhere
HANDLE hLogFile;   // handle to logfile, set elsewhere
HRESULT hr;
IUnknown *pUnk;
IGraphBuilder *pFg;

// call the Capture object to retrieve the FilterGraph
hr = pCapture->GetSubObject(ltmmCapture_Object_FilterGraph, &pUnk);
if(SUCCEEDED(hr))
{
   // retrieve the IGraphBuilder interface
   hr = pUnk->QueryInterface(IID_IGraphBuilder, (void**) &pFg) ;
   pUnk->Release();
   if(SUCCEEDED(hr))
   {
      // assign the logfile
      pFg->SetLogFile((DWORD_PTR) hLogFile);
      pFg->Release();
   }
}

Another example, is to call the ltmmPlay object to retrieve the Video Renderer The DirectShow component responsible for playing the video. Some renderers might have useful settings you can adjust if you have problems playing the video. in order to enable RGB mode.

This is demonstrated, in C, as follows:

IltmmPlay *pPlay;  // initialized elsewhere
HRESULT hr;
IUnknown *pUnk;
IDirectDrawVideo *pDDV;

// call the Play object to retrieve the VideoRenderer
hr = IltmmPlay_GetSubObject(pPlay, ltmmPlay_Object_VideoRenderer, &pUnk);
if(SUCCEEDED(hr))
{
   // retrieve the IDirectDrawVideo interface
   hr = IUnknown_QueryInterface(pUnk, IID_IGraphBuilder, (void**) &pDDV) ;
   IUnknown_Release(pUnk);
   if(SUCCEEDED(hr))
   {
      // set rgb mode
      IDirectDrawVideo _SetSwitches(pDDV, AMDDS_RGB);
      IUnknown_Release(pDDV);
   }
}

In C++, you would do the following:

IltmmPlay *pPlay;  // initialized elsewhere
HRESULT hr;
IUnknown *pUnk;
IDirectDrawVideo *pDDV;

// call the Play object to retrieve the VideoRenderer
hr = pPlay->GetSubObject(ltmmPlay_Object_VideoRenderer, &pUnk);
if(SUCCEEDED(hr))
{
   // retrieve the IDirectDrawVideo interface
   hr = pUnk->QueryInterface(IID_IGraphBuilder, (void**) &pDDV) ;
   pUnk->Release(pUnk);
   if(SUCCEEDED(hr))
   {
      // set rgb mode
      pDDV->SetSwitches(AMDDS_RGB);
      pDDV->Release();
   }
}

Another example is to call the ltmmConvert object to retrieve the video compressor Also known as an encoder Also known as compressor, this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder., this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder Also known as a decompressor, this is a module or algorithm to decompress data.. and adjust the compression quality. This is demonstrated, in C, as follows:

IltmmConvert *pConvert;  // initialized elsewhere
HRESULT hr;
IUnknown *pUnk;
IAMVideoCompression *pVC;

// call the Convert object to retrieve the Video Compressor
hr = IltmmConvert_GetSubObject(pConvert, ltmmConvert_Object_VideoCompressor, &pUnk);
if(SUCCEEDED(hr))
{
   // retrieve the IAMVideoCompression interface
   hr = IUnknown_QueryInterface(pUnk, IID_IAMVideoCompression, (void**) &pVC) ;
   IUnknown_Release(pUnk);
   if(SUCCEEDED(hr))
   {
      // set the quality to the best available
      IAMVideoCompression__put_Quality(pVC, 1.0);
      IUnknown_Release(pVC);
   }
}

In C++, you would do the following:

IltmmConvert *pConvert;  // initialized elsewhere
HRESULT hr;
IUnknown *pUnk;
IAMVideoCompression *pVC;

// call the Convert object to retrieve the Video Compressor
hr = pConvert->GetSubObject(ltmmConvert_Object_VideoCompressor, &pUnk);
if(SUCCEEDED(hr))
{
   // retrieve the IAMVideoCompression interface
   hr = pUnk->QueryInterface(IID_IAMVideoCompression, (void**) &pVC) ;
   pUnk->Release(pUnk);
   if(SUCCEEDED(hr))
   {
      // set the quality to the best available
      pVC->put_Quality(1.0);
      pVC->Release();
   }
}