C# wrapper for array of three pointers

2020-04-21 06:34发布

问题:

I'm currently working on a C# wrapper to work with Dallmeier Common API light.
See previous posting: C# wrapper and Callbacks

I've got pretty much everything 'wrapped' but I'm stuck on wrapping a callback which contains an array of three pointers & an array integers:

dlm_setYUVDataCllback

int(int SessionHandle, void (*callback) (long IPlayerID, unsigned char** yuvData,  
    int* pitch, int width, int height, int64_t ts, char* extData))  

Function Set callback, to receive current YUV image.
Arguments SessionHandle: handle to current session.
Return PlayerID (see callback).
Callback - IPlayerId: id to the Player object
- yuvData: array of three pointers to Y, U and V part of image
The YUV format used is YUV420 planar (not packed).
char *y = yuvData[0];
char *u = yuvData[1];
char *v = yuvData[2];
- pitch: array of integers for pitches for Y, U and V part of image
- width: intrinsic width of image.
- height
- ts : timestamp of current frame
- extData: additional data to frame

How do I go about wrapping this in c#?

Any help is much appreciated.

回答1:

unsigned char** yuvData should be defined as [MarshalAs(UnmanagedType.ByValArray,SizeConst=3)] IntPtr[] yuvData

You will then get an array of 3 IntPtrs. You can the read the actual data using the Marshal.Read or Marshal.Copy.