Last active
January 21, 2021 13:42
-
-
Save icywind/c72b4236c1a27877d81ae1016b3f8ae3 to your computer and use it in GitHub Desktop.
Interface for Agora Video Chat clients
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Get Image from the AR Camera, extract the raw data from the image | |
private unsafe void CaptureARBuffer() | |
{ | |
// Get the image in the ARSubsystemManager.cameraFrameReceived callback | |
XRCameraImage image; | |
if (!cameraManager.TryGetLatestImage(out image)) | |
{ | |
Debug.LogWarning("Capture AR Buffer returns nothing!!!!!!"); | |
return; | |
} | |
var conversionParams = new XRCameraImageConversionParams | |
{ | |
// Get the full image | |
inputRect = new RectInt(0, 0, image.width, image.height), | |
// Downsample by 2 | |
outputDimensions = new Vector2Int(image.width, image.height), | |
// Color image format | |
outputFormat = ConvertFormat, | |
// Flip across the x axis | |
transformation = CameraImageTransformation.MirrorX | |
// Call ProcessImage when the async operation completes | |
}; | |
// See how many bytes we need to store the final image. | |
int size = image.GetConvertedDataSize(conversionParams); | |
Debug.Log("OnCameraFrameReceived, size == " + size + "w:" + image.width + " h:" + image.height + " planes=" + image.planeCount); | |
// Allocate a buffer to store the image | |
var buffer = new NativeArray<byte>(size, Allocator.Temp); | |
// Extract the image data | |
image.Convert(conversionParams, new System.IntPtr(buffer.GetUnsafePtr()), buffer.Length); | |
// The image was converted to RGBA32 format and written into the provided buffer | |
// so we can dispose of the CameraImage. We must do this or it will leak resources. | |
byte[] bytes = buffer.ToArray(); | |
monoProxy.StartCoroutine(PushFrame(bytes, image.width, image.height, | |
() => { image.Dispose(); buffer.Dispose(); })); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment