/// <summary> /// Pushes a frame into the defined video source. /// </summary> /// <param name="frame">The frame to push to the video source.</param> /// <returns> /// MLResult.Result will be <c>MLResult.Code.Ok</c> if destroying all handles was successful. /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInstanceNotCreated</c> if MLWebRTC instance was not created. /// MLResult.Result will be <c>MLResult.Code.InvalidParam</c> if an invalid parameter was passed. /// MLResult.Result will be <c>MLResult.Code.WebRTCResultMismatchingHandle</c> if an incorrect handle was sent. /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInvalidFrameFormat</c> if an invalid frame format was specified. /// MLResult.Result will be <c>MLResult.Code.WebRTCResultInvalidFramePlaneCount</c> if an invalid plane count was specified for the given frame format. /// </returns> protected async Task <MLResult> PushFrameAsync(MLWebRTC.VideoSink.Frame frame) { if (!MagicLeapNativeBindings.MLHandleIsValid(this.Handle)) { return(await Task.FromResult(MLResult.Create(MLResult.Code.InvalidParam, "Handle is invalid."))); } pushFrameEvent.Reset(); MLWebRTC.VideoSink.Frame.NativeBindings.MLWebRTCFrame frameNative = MLWebRTC.VideoSink.Frame.NativeBindings.MLWebRTCFrame.Create(frame); MLResult.Code resultCode = NativeBindings.MLWebRTCSourceAppDefinedVideoSourcePushFrame(this.Handle, in frameNative); DidNativeCallSucceed(resultCode, "MLWebRTCSourceAppDefinedVideoSourcePushFrame()"); pushFrameEvent.Set(); return(await Task.FromResult(MLResult.Create(resultCode))); }
/// <summary> /// Frees any allocated memory made from building a WebRTC frame. /// Only used when building your own frame objects, such as in an app defined video source. /// </summary> /// <param name="frame">Frame object with the allocated memory.</param> /// <param name="frameNative">Timestamp of the frame.</param> internal static void FreeAllocatedImageMemory(MLWebRTC.VideoSink.Frame frame, MLWebRTC.VideoSink.Frame.NativeBindings.MLWebRTCFrame frameNative) { for (int i = 0; i < frame.ImagePlanes.Length; ++i) { MLWebRTC.VideoSink.Frame.ImagePlane imagePlane = frame.ImagePlanes[i]; MLWebRTC.VideoSink.Frame.NativeBindings.ImagePlaneInfoNative imagePlaneNative = frameNative.ImagePlanes[i]; } }