public void EncodedVideoSampleReceived(byte[] sample, int length)
{
IntPtr encodedBufferPtr = Marshal.AllocHGlobal(length);
Marshal.Copy(sample, 0, encodedBufferPtr, length);
byte[] decodedBuffer = null;
uint decodedImgWidth = 0;
uint decodedImgHeight = 0;
unsafe
{
_vpxDecoder.Decode((byte*)encodedBufferPtr, length, ref decodedBuffer, ref decodedImgWidth, ref decodedImgHeight);
}
Marshal.FreeHGlobal(encodedBufferPtr);
if (decodedBuffer != null && decodedBuffer.Length > 0)
{
IntPtr decodedSamplePtr = Marshal.AllocHGlobal(decodedBuffer.Length);
Marshal.Copy(decodedBuffer, 0, decodedSamplePtr, decodedBuffer.Length);
byte[] bmp = null;
unsafe
{
_imageConverter.ConvertYUVToRGB((byte*)decodedSamplePtr, VideoSubTypesEnum.I420, Convert.ToInt32(decodedImgWidth), Convert.ToInt32(decodedImgHeight), VideoSubTypesEnum.RGB24, ref bmp);
}
Marshal.FreeHGlobal(decodedSamplePtr);
if (OnRemoteVideoSampleReady != null)
{
OnRemoteVideoSampleReady(bmp, Convert.ToInt32(decodedImgWidth), Convert.ToInt32(decodedImgHeight));
}
}
}