views:

190

answers:

1

I'm currently working on a C# wrapper to work with Dallmeier Common API light.
See previous posting: http://stackoverflow.com/questions/2430089/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.

A: 

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.

logicnp
Thanks logicnp. Just a followup on this, i have created a struct with the parameters as above but what should 'Int64_t' be in c# and do I use the same MashalAs for the 'pitch' which is also an array of integers e.g. [MarshalAs(UnmanagedType.ByValArray,SizeConst=1)] IntPtr[] pitch
int64_t should be defined as long (which is also 64-bits in c#).For the pitch, your definition is correct if 'pitch' is a one-dimensional array.
logicnp
How and Were do I use the Marshal.Read or Marshal.Copy
@logicnp: I think you meant UnmanagedType.LPArray. ByValArray is only valid on structure fields.
Mattias S