From 8b07ab3b697ff1159d988db9a84e0501a7b331e6 Mon Sep 17 00:00:00 2001 From: techyian Date: Sat, 12 Sep 2020 14:03:58 +0100 Subject: [PATCH] #108 - Allow raw frames to be passed to Image Processors. Do not call Callback Handler if buffer is empty for still ports. --- src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs | 2 +- .../Processors/Effects/ConvolutionBase.cs | 6 +++--- src/MMALSharp/Components/MMALCameraComponent.cs | 2 +- src/MMALSharp/Ports/Outputs/OutputPort.cs | 5 +++-- 4 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs b/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs index 6d23a438..e10d5bcb 100644 --- a/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs +++ b/src/MMALSharp.Processing/Handlers/StreamCaptureHandler.cs @@ -74,7 +74,7 @@ public override void PostProcess() } catch(Exception e) { - MMALLog.Logger.LogWarning($"Something went wrong while processing stream: {e.InnerException?.Message}. {e.StackTrace}"); + MMALLog.Logger.LogWarning($"Something went wrong while processing stream: {e.Message}. {e.InnerException?.Message}. {e.StackTrace}"); } } diff --git a/src/MMALSharp.Processing/Processors/Effects/ConvolutionBase.cs b/src/MMALSharp.Processing/Processors/Effects/ConvolutionBase.cs index 7791966b..ae28e933 100644 --- a/src/MMALSharp.Processing/Processors/Effects/ConvolutionBase.cs +++ b/src/MMALSharp.Processing/Processors/Effects/ConvolutionBase.cs @@ -82,7 +82,7 @@ public void ApplyConvolution(double[,] kernel, int kernelWidth, int kernelHeight Task.WaitAll(t1, t2, t3, t4); - if (context.Raw) + if (context.Raw && context.StoreFormat == null) { store = new byte[bytes]; Marshal.Copy(pNative, store, 0, bytes); @@ -90,7 +90,7 @@ public void ApplyConvolution(double[,] kernel, int kernelWidth, int kernelHeight bmp.UnlockBits(bmpData); - if (!context.Raw) + if (!context.Raw || context.StoreFormat != null) { using (var ms2 = new MemoryStream()) { @@ -128,7 +128,7 @@ private Bitmap LoadBitmap(ImageContext imageContext, MemoryStream stream) if (format == default) { - throw new Exception("Unsupported pixel format for Bitmap"); + throw new Exception($"Unsupported pixel format for Bitmap: {imageContext.PixelFormat}."); } return new Bitmap(imageContext.Resolution.Width, imageContext.Resolution.Height, format); diff --git a/src/MMALSharp/Components/MMALCameraComponent.cs b/src/MMALSharp/Components/MMALCameraComponent.cs index cd421fcd..3542480d 100644 --- a/src/MMALSharp/Components/MMALCameraComponent.cs +++ b/src/MMALSharp/Components/MMALCameraComponent.cs @@ -337,7 +337,7 @@ private void InitialiseStill(IOutputCaptureHandler handler) portConfig = new MMALPortConfig( encoding, - null, + encoding, width: currentWidth, height: currentHeight, framerate: MMALCameraConfig.Framerate, diff --git a/src/MMALSharp/Ports/Outputs/OutputPort.cs b/src/MMALSharp/Ports/Outputs/OutputPort.cs index 428b5780..8fc01b7b 100644 --- a/src/MMALSharp/Ports/Outputs/OutputPort.cs +++ b/src/MMALSharp/Ports/Outputs/OutputPort.cs @@ -296,10 +296,11 @@ internal virtual void NativeOutputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_HE bufferImpl.PrintProperties(); var failed = bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED); - + var eos = bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_FRAME_END) || bufferImpl.AssertProperty(MMALBufferProperties.MMAL_BUFFER_HEADER_FLAG_EOS) || - this.ComponentReference.ForceStopProcessing; + this.ComponentReference.ForceStopProcessing || + bufferImpl.Length == 0; if ((bufferImpl.CheckState() && bufferImpl.Length > 0 && !eos && !failed && !this.Trigger.Task.IsCompleted) || (eos && !this.Trigger.Task.IsCompleted)) {