IltmmTargetFormat::put_UseFilterCache Example for C

#include "ltmm.h" 
#include "Filters/ILMMpg2MxT.h" 
#include <time.h> 
 
HRESULT UseFilterCache_Example (IltmmCapture* pCapture) 
{ 
   HRESULT hr; 
   IltmmDevices* devices   = NULL; 
   IltmmCompressors* compressors = NULL; 
   IltmmTargetFormats* pformats = NULL; 
   IltmmTargetFormat*  pformat  = NULL; 
   IUnknown*           pUnknown = NULL; 
   ILMMpg2MxT*         pMpgMux = NULL; 
   long lIndex = 0; 
   BSTR bstr; 
 
   // mpeg2 compressor 
   static TCHAR SZ_MPEG2_Compressor[] = "@device:sw:{33D9A760-90C8-11D0-BD43-00A0C911CE86}\\LEAD MPEG2 Encoder (3.0)"; 
 
   // get the video devices collection 
   hr = IltmmCapture_get_VideoDevices(pCapture, &devices); 
   if(FAILED(hr)) 
      return hr; 
 
   // select the capture device 
   hr = IltmmDevices_put_Selection(devices, 1); // Use a different video device if you want 
 
   // release the video devices collection object 
   IltmmDevices_Release(devices); 
   if(FAILED(hr)) 
      return hr; 
 
   // get the video compressors collection 
   hr = IltmmCapture_get_VideoCompressors(pCapture, &compressors); 
   if(FAILED(hr)) 
      return hr; 
 
   // find mpeg2 compressor 
   hr = IltmmCompressors_Find(compressors, T2OLE(SZ_MPEG2_Compressor), &lIndex); 
   if(FAILED(hr) || lIndex == -1) 
   { 
      // release the compressors collection object 
      IltmmCompressors_Release(compressors); 
      return S_FALSE; 
   } 
 
   // set the video compressor (only if the capture device is not already capturing compressed video) 
   IltmmCompressors_put_Selection(compressors, lIndex); 
 
   // release the compressors collection object 
   IltmmCompressors_Release(compressors); 
 
   // set the target output file 
   bstr = SysAllocString(L"c:\\CaptureKLV.avi"); 
   IltmmCapture_put_TargetFile(pCapture, bstr); 
   SysFreeString(bstr); 
 
   // just 10 seconds of capture time 
   IltmmCapture_put_UseTimeLimit (pCapture, VARIANT_TRUE); 
   IltmmCapture_put_TimeLimit(pCapture, 10); 
 
   // get the target formats collection 
   hr = IltmmCapture_get_TargetFormats(pCapture, &pformats); 
   if(FAILED(hr)) 
      return hr; 
 
   // get the MPEG2Transport target format object 
   hr = IltmmTargetFormats_Item(pformats, ltmmCapture_TargetFormat_MPEG2_TRANSPORT, &pformat); 
   if(FAILED(hr)) 
   { 
      // release the formats collection object 
      IltmmTargetFormats_Release(pformats); 
      return hr; 
   } 
 
   // IN a capture situation 
   // in order to get the mux in a capture situation, set the UseFilterCache property for the target format to TRUE 
   // This tells the toolkit to create a Mux object and keep it around when building or rebuilding graphs 
   // enable filter cache 
   hr = IltmmTargetFormat_put_UseFilterCache(pformat, VARIANT_TRUE); 
   if(FAILED(hr)) 
   { 
      // release the format and collection objects 
      IltmmTargetFormat_Release(pformat); 
      IltmmTargetFormats_Release(pformats); 
      return hr; 
   } 
 
   // select MPEG2Transport target format 
   hr = IltmmCapture_put_TargetFormat (pCapture, ltmmCapture_TargetFormat_MPEG2_TRANSPORT); 
   if(FAILED(hr)) 
      return hr; 
 
   // get the multiplexer object for this format 
   hr = IltmmTargetFormat_GetCacheObject(pformat, ltmmTargetFormat_Object_Mux, &pUnknown); 
   if(FAILED(hr)) 
   { 
      // release the format and collection objects 
      IltmmTargetFormat_Release(pformat); 
      IltmmTargetFormats_Release(pformats); 
      return hr;  
   } 
 
   // release the format and collection objects 
   IltmmTargetFormat_Release(pformat); 
   IltmmTargetFormats_Release(pformats); 
   hr = IUnknown_QueryInterface(pUnknown, &IID_ILMMpg2MxT, (void **)&pMpgMux); 
   IUnknown_Release(pUnknown); 
   if(FAILED(hr))  
      return hr; 
 
   if(pMpgMux) 
   { 
      ILMMpg2MxT_put_PrivateDataPID(pMpgMux, 0x70); 
      ILMMpg2MxT_put_PrivateDataFormatID(pMpgMux, 0x41564c4b); 
      ILMMpg2MxT_put_EnablePrivateData(pMpgMux, VARIANT_TRUE); 
   } 
 
   // release the multiplexer object 
   ILMMpg2MxT_Release(pMpgMux); 
 
   // start capture 
   hr = IltmmCapture_StartCapture(pCapture, ltmmCapture_Mode_Video); 
   if(FAILED(hr)) 
      return hr; 
 
   hr = WriteKLVData(pMpgMux); 
   return hr; 
} 
 
HRESULT WriteKLVData (ILMMpg2MxT*   pMpgMux ) 
{ 
   HRESULT hr = S_OK; 
   time_t basetime; 
   unsigned __int64 timestamp ; 
   ILMKlvBuilder* builder = NULL; 
   VARIANT v; 
   BSTR bstr; 
 
   time(&basetime); 
   timestamp = ((unsigned __int64) basetime * 1000000); 
 
   // get the mux builder 
   hr = ILMMpg2MxT_get_KlvBuilder(pMpgMux, &builder); 
   if(FAILED(hr)) 
      goto abort; 
 
   // clear out any existing data 
   ILMKlvBuilder_Clear(builder); 
   bstr = SysAllocString(L"06 0E 2B 34 01 01 01 03 07 02 01 01 01 05 00 00"); 
 
   // write the UDS timestamp 
   hr = ILMKlvBuilder_InsertUInt64(builder, -1L, bstr, timestamp); 
   SysFreeString(bstr); 
   if(FAILED(hr)) 
   { 
      ILMKlvBuilder_Release(builder); 
      goto abort; 
   } 
 
   // get KLV data 
   VariantInit(&v); 
   hr = ILMKlvBuilder_GetData(builder, &v); 
   if(FAILED(hr)) 
   { 
      ILMKlvBuilder_Release(builder); 
      goto abort; 
   } 
 
   // write one KLV data at the beginning 
   hr = ILMMpg2MxT_WritePrivateData(pMpgMux, Mpg2MxT_WriteFlag_PTSValid | Mpg2MxT_WriteFlag_PTSInSeconds, 1.0, v, -1); 
   VariantClear(&v); 
   if(FAILED(hr)) 
   { 
      ILMKlvBuilder_Release(builder); 
      goto abort; 
   } 
 
   ILMKlvBuilder_Release(builder); 
 
abort: 
   // close the stream 
   ILMMpg2MxT_ClosePrivateData(pMpgMux); 
 
   return hr; 
} 
Help Version 21.0.2021.7.19
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS Multimedia C API Help
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.