0

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.

Community
  • 1
  • 1
Amelse Etomer
  • 1,253
  • 10
  • 28
  • I just wanted to report that I did not find a solution, just a workaround: I associate the VideoInfoHeader with the ComboBox and once I want to connect the IPins, I reiterate through all media types of the upstream pin and grab the one where the VideoInfoHeaders are equal. (This might be ambiguous as there may be different AMMediaTypes with the same VideoInfoHeader properties. – Amelse Etomer Nov 08 '12 at 06:09
  • Duplicating media type is nothing but duplicating bytes from `formatPtr` and copying the rest of members. – Roman R. Nov 09 '12 at 00:45
  • @Roman, this requires a lot of footwork and it is, what I was doing anyways. It seems there is no other way, so I would accept your answer if you put it as one. ;-) – Amelse Etomer Jan 16 '13 at 00:13

1 Answers1

1

The AMMediaType aka AM_MEDIA_TYPE structure consists of regular members and additionally allocated piece of memory pointed to by formatPtr. 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 includes pUnk member supposed to be COM interface, however it is typically null. 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.

Roman R.
  • 68,205
  • 6
  • 94
  • 158