The following code demonstrates how to copy a media sample's attributes and data to another media sample.
// include the LEAD Multimedia TOOLKIT header#include "ltmm.h"///////////////////////////////////////////////////////////////////CopyMediaSampleAttributes// copies data and attributes from one sample to another// pDest - destination sample interface// pSource - source sample interfaceHRESULT CopyMediaSampleAttributes(IltmmMediaSampleDisp* pDest, IltmmMediaSampleDisp* pSource){HRESULT hr;VARIANT_BOOL f;LARGE_INTEGER starttime;LARGE_INTEGER stoptime;VARIANT var;long cbData;long cbBuffer;IltmmMediaTypeDisp* pMediaType;// return error if NULLif(!pSource || !pDest)return E_POINTER;// get the source actual data lengthhr = pSource->get_ActualDataLength(&cbData);if(FAILED(hr))return hr;// now the dest maximum buffer sizehr = pDest->get_BufferSize(&cbBuffer);if(FAILED(hr))return hr;// if no room for the data, return an errorif(cbData > cbBuffer)return E_OUTOFMEMORY;// any data to copy?if(cbData){// yes, then copy awayhr = pSource->GetData(cbData, &var);if(FAILED(hr))return hr;hr = pDest->SetData(cbData, var);VariantClear(&var);if(FAILED(hr))return hr;}else{// no, just set the dest data length to 0pDest->put_ActualDataLength(0);}// copy the media type, if there is onepMediaType = NULL;pSource->GetMediaType(&pMediaType);if(pMediaType){pDest->SetMediaType(pMediaType);pMediaType->Release();}// copy discontinuityf = VARIANT_FALSE;pSource->get_Discontinuity(&f);pDest->put_Discontinuity(f);// copy prerollf = VARIANT_FALSE;pSource->get_Preroll(&f);pDest->put_Preroll(f);// copy syncpointf = VARIANT_FALSE;pSource->get_SyncPoint(&f);pDest->put_SyncPoint(f);// is the time available?hr = pSource->GetTime(&starttime.HighPart, (long*) &starttime.LowPart, &stoptime.HighPart, (long*) &stoptime.LowPart);if(FAILED(hr)){// no, then reset the dest timepDest->ResetTime();}else{// yes, copy to the destpDest->SetTime(starttime.HighPart, starttime.LowPart, stoptime.HighPart, stoptime.LowPart);}// is the media time available?hr = pSource->GetMediaTime(&starttime.HighPart, (long*) &starttime.LowPart, &stoptime.HighPart, (long*) &stoptime.LowPart);if(FAILED(hr)){// no, then reset the dest media timepDest->ResetMediaTime();}else{// yes, copy to the destpDest->SetMediaTime(starttime.HighPart, starttime.LowPart, stoptime.HighPart, stoptime.LowPart);}return S_OK;}
Help Collections
Raster .NET | C API | C++ Class Library | HTML5 JavaScript
Document .NET | C API | C++ Class Library | HTML5 JavaScript
Medical .NET | C API | C++ Class Library | HTML5 JavaScript
Medical Web Viewer .NET
Multimedia
Direct Show .NET | C API | Filters
Media Foundation .NET | C API | Transforms
Supported Platforms
.NET, Java, Android, and iOS/macOS Assemblies
Imaging, Medical, and Document
C API/C++ Class Libraries
Imaging, Medical, and Document
HTML5 JavaScript Libraries
Imaging, Medical, and Document
