Copying ltmmMediaType Attributes and Data for C

The following code demonstrates how to copy a media type's attributes and data to another media type.

// define helper macros for using interfaces under C 
#ifndef COBJMACROS 
#define COBJMACROS 
#endif 
// include the LEAD Multimedia TOOLKIT header 
#include "ltmm.h" 
///////////////////////////////////////////////////////////////// 
// CopyMediaTypeAttributes 
// copies data and attributes from one media type to another 
// pDest - destination media type interface 
// pSource - source media type interface 
// 
HRESULT CopyMediaTypeAttributesExample (IltmmMediaTypeDisp* pDest, IltmmMediaTypeDisp* pSource) 
{ 
   HRESULT hr; 
   VARIANT_BOOL f; 
   long l; 
   BSTR bstr; 
   long cbData; 
   VARIANT var; 
   // return an error if NULL 
   if(!pSource || !pDest) 
      return E_POINTER; 
   // get the format data size 
   hr = IltmmMediaTypeDisp_get_FormatSize (pSource, &cbData); 
   if(FAILED(hr)) 
      return hr; 
   // any format data? 
   if(cbData) 
   { 
      // yes, then copy away 
      hr = IltmmMediaTypeDisp_GetFormatData (pSource, cbData, &var); 
      if(FAILED(hr)) 
         return hr; 
      hr = IltmmMediaTypeDisp_SetFormatData (pDest, cbData, var); 
      VariantClear(&var); 
      if(FAILED(hr)) 
         return hr; 
   } 
   else 
   { 
      // no, just set the destdestination to zero 
      hr = IltmmMediaTypeDisp_put_FormatSize (pDest, 0); 
      if(FAILED(hr)) 
         return hr; 
   } 
   // copy type 
   bstr = NULL; 
   IltmmMediaTypeDisp_get_Type(pSource, &bstr); 
   IltmmMediaTypeDisp_put_Type (pDest, bstr); 
   SysFreeString(bstr); 
   // copy subtype 
   bstr = NULL; 
   IltmmMediaTypeDisp_get_Subtype (pSource, &bstr); 
   IltmmMediaTypeDisp_put_Subtype (pDest, bstr); 
   SysFreeString(bstr); 
   // copy formattype 
   bstr = NULL; 
   IltmmMediaTypeDisp_get_FormatType(pSource, &bstr); 
   IltmmMediaTypeDisp_put_FormatType (pDest, bstr); 
   SysFreeString(bstr); 
   // copy fixedsizesamples 
   f = VARIANT_FALSE; 
   IltmmMediaTypeDisp_get_FixedSizeSamples (pSource, &f); 
   IltmmMediaTypeDisp_put_FixedSizeSamples(pDest, f); 
   // copy temporalcompression 
   f = VARIANT_FALSE; 
   IltmmMediaTypeDisp_get_TemporalCompression (pSource, &f); 
   IltmmMediaTypeDisp_put_TemporalCompression (pDest, f); 
   // copy samplesize 
   l = 0; 
   IltmmMediaTypeDisp_get_SampleSize (pSource, &l); 
   IltmmMediaTypeDisp_put_SampleSize (pDest, l); 
   return S_OK; 
} 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
LEADTOOLS Multimedia C API Help