2
我使用FFMPEG在C#,並具有以下功能prototpe:的IntPtr到回調函數
public static extern AVIOContext* avio_alloc_context(byte* buffer, int buffer_size, int write_flag, void* opaque, IntPtr read_packet, IntPtr write_packet, IntPtr seek);
在C/C++此函數被聲明如下:
avio_alloc_context (unsigned char *buffer, int buffer_size, int write_flag, void *opaque, int(*read_packet)(void *opaque, uint8_t *buf, int buf_size), int(*write_packet)(void *opaque, uint8_t *buf, int buf_size), int64_t(*seek)(void *opaque, int64_t offset, int whence))
在C/C++我可以執行以下操作來調用這個函數:
int readFunction(void* opaque, uint8_t* buf, int buf_size)
{
// Do something here
int numBytes = CalcBytes();
return numBytes;
}
int64_t seekFunction(void* opaque, int64_t offset, int whence)
{
// Do seeking here
return pos;
}
AVIOContext * avioContext = avio_alloc_context(ioBuffer, ioBufferSize, 0, (void*)(&fileStream), &readFunction, NULL, &seekFunction);
凡readFunction
和seekFunction
是CAL用於讀取/搜索等的lback函數。
我不確定如何在C#版本的代碼中複製此行爲,當它期望IntPtr
。我如何創建回調函數並將它們傳遞給C#版本?