I am able to copy a VideoInfoHeader which is part AMMediaType with the following lines:
AMMediaType mediaType = new AMMediaType();
VideoInfoHeader videoInfo = new VideoInfoHeader();
(pSampleGrabber as ISampleGrabber).GetConnectedMediaType(mediaType);
videoInfo = (VideoInfoHeader)Marshal.PtrToStructure(mediaType.formatPtr, typeof(VideoInfoHeader));
that I got from SampleGrabber Parameter is Incorrect and other ressources on the internet. However I am not able to copy the whole AMMediaType-Structure. The pointer to the VideoInfoHeader is lost.
So I was wondering if there exists a helper function that
copies an AMMediaType to a different location in memory, looks for pointers like VideoInfoHeader and copies the content of the VideoInfoHeader and other referenced data to a new location (including pointing formatPtr to the right location).
I am using this in the following scenario:
I retrieve all possible IPin mediatypes of a video input device and show the AMMediaTypes in a Windows.Forms – Combobox. When I read the SelectedObject from the Combobox, the pointer to the VideoInfoHeader is zero. This is where it fails to connect using my selected pin configuration when constructing the filtergraph.
The
AMMediaTypeakaAM_MEDIA_TYPEstructure consists of regular members and additionally allocated piece of memory pointed to byformatPtr. The latter is a byte array with a meaning dependent on format type. Both structure and slave memory block are typically using specific COM allocator.Duplicating the structure is copying its members and duplicating the byte array behind
formatPtr. The structure also includespUnkmember supposed to be COM interface, however it is typicallynull. It is valid for it to be non-null, but I cannot remember a single case over years when it was actually used, in particular with video and audio media types.