From c18ece59e21b9ced6fc2120f95a5541c6a4835e9 Mon Sep 17 00:00:00 2001 From: Jon McGuire Date: Sat, 10 Oct 2020 11:19:50 -0400 Subject: [PATCH] suppress callback if buffer length is zero --- src/MMALSharp.Processing/Handlers/InMemoryCaptureHandler.cs | 6 +----- src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs | 6 +----- src/MMALSharp/Ports/Outputs/OutputPort.cs | 2 +- 3 files changed, 3 insertions(+), 11 deletions(-) diff --git a/src/MMALSharp.Processing/Handlers/InMemoryCaptureHandler.cs b/src/MMALSharp.Processing/Handlers/InMemoryCaptureHandler.cs index 907ca24d..246b9be7 100644 --- a/src/MMALSharp.Processing/Handlers/InMemoryCaptureHandler.cs +++ b/src/MMALSharp.Processing/Handlers/InMemoryCaptureHandler.cs @@ -51,11 +51,7 @@ public override void Process(ImageContext context) /// public override void PostProcess() { - // When the context data length is zero, the data in the stream is a partial frame due to a race condition - // where the hardware has started the next frame before the library has begun the shutdown process. The buffer - // which triggered the call to PostProcess (from PortCallbackHandler) has a zero length which is what we're - // checking for here. - if (this.OnManipulate != null && this.ImageContext != null && this.ImageContext.Data.Length > 0) + if (this.OnManipulate != null && this.ImageContext != null) { this.ImageContext.Data = this.WorkingData.ToArray(); this.OnManipulate(new FrameProcessingContext(this.ImageContext)); diff --git a/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs b/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs index 56524077..986adbe8 100644 --- a/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs +++ b/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs @@ -44,11 +44,7 @@ public override void PostProcess() { if (this.CurrentStream != null && this.CurrentStream.CanRead && this.CurrentStream.Length > 0) { - // When the context data length is zero, the data in the stream is a partial frame due to a race condition - // where the hardware has started the next frame before the library has begun the shutdown process. The buffer - // which triggered the call to PostProcess (from PortCallbackHandler) has a zero length which is what we're - // checking for here. - if (this.OnManipulate != null && this.ImageContext != null && this.ImageContext.Data.Length > 0) + if (this.OnManipulate != null && this.ImageContext != null) { byte[] arr = null; diff --git a/src/MMALSharp/Ports/Outputs/OutputPort.cs b/src/MMALSharp/Ports/Outputs/OutputPort.cs index bb962be6..3f16b6f2 100644 --- a/src/MMALSharp/Ports/Outputs/OutputPort.cs +++ b/src/MMALSharp/Ports/Outputs/OutputPort.cs @@ -302,7 +302,7 @@ internal virtual void NativeOutputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_HE this.ComponentReference.ForceStopProcessing || bufferImpl.Length == 0; - if ((bufferImpl.CheckState() && bufferImpl.Length > 0 && !eos && !failed && !this.Trigger.Task.IsCompleted) || (eos && !this.Trigger.Task.IsCompleted)) + if ((bufferImpl.CheckState() && bufferImpl.Length > 0 && !eos && !failed && !this.Trigger.Task.IsCompleted) || (eos && !this.Trigger.Task.IsCompleted && bufferImpl.Length > 0)) { this.CallbackHandler.Callback(bufferImpl); }