diff --git a/src/MMALSharp/Ports/Outputs/FastStillPort.cs b/src/MMALSharp/Ports/Outputs/FastStillPort.cs index ee95687c..4795f838 100644 --- a/src/MMALSharp/Ports/Outputs/FastStillPort.cs +++ b/src/MMALSharp/Ports/Outputs/FastStillPort.cs @@ -92,7 +92,7 @@ internal override void NativeOutputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_H } // Ensure we release the buffer before any signalling or we will cause a memory leak due to there still being a reference count on the buffer. - this.ReleaseBuffer(bufferImpl); + this.ReleaseBuffer(bufferImpl, this.ComponentReference.ForceStopProcessing || failed); // If this buffer signals the end of data stream, allow waiting thread to continue. if (this.ComponentReference.ForceStopProcessing || failed) diff --git a/src/MMALSharp/Ports/Outputs/FileEncodeOutputPort.cs b/src/MMALSharp/Ports/Outputs/FileEncodeOutputPort.cs index 2c553b84..c7878729 100644 --- a/src/MMALSharp/Ports/Outputs/FileEncodeOutputPort.cs +++ b/src/MMALSharp/Ports/Outputs/FileEncodeOutputPort.cs @@ -72,7 +72,7 @@ private void ProcessBuffer(IBuffer bufferImpl) } else { - this.ReleaseBuffer(bufferImpl); + this.ReleaseBuffer(bufferImpl, eos); } } else @@ -87,7 +87,7 @@ private void ProcessBuffer(IBuffer bufferImpl) } // Ensure we release the buffer before any signalling or we will cause a memory leak due to there still being a reference count on the buffer. - this.ReleaseBuffer(bufferImpl); + this.ReleaseBuffer(bufferImpl, eos); } } else diff --git a/src/MMALSharp/Ports/Outputs/IOutputPort.cs b/src/MMALSharp/Ports/Outputs/IOutputPort.cs index 547e99d1..292f5580 100644 --- a/src/MMALSharp/Ports/Outputs/IOutputPort.cs +++ b/src/MMALSharp/Ports/Outputs/IOutputPort.cs @@ -40,7 +40,8 @@ public interface IOutputPort : IPort /// Release an output port buffer, get a new one from the queue and send it for processing. /// /// A managed buffer object. - void ReleaseBuffer(IBuffer bufferImpl); + /// Flag that this buffer is the end of stream. + void ReleaseBuffer(IBuffer bufferImpl, bool eos); /// /// Call to register a new callback handler with this port. diff --git a/src/MMALSharp/Ports/Outputs/OutputPort.cs b/src/MMALSharp/Ports/Outputs/OutputPort.cs index 6287799f..ac0f4b34 100644 --- a/src/MMALSharp/Ports/Outputs/OutputPort.cs +++ b/src/MMALSharp/Ports/Outputs/OutputPort.cs @@ -169,9 +169,16 @@ public virtual void ConnectTo(IDownstreamComponent destinationComponent, int inp /// Release an output port buffer, get a new one from the queue and send it for processing. /// /// A managed buffer object. - public virtual void ReleaseBuffer(IBuffer bufferImpl) + /// Flag that this buffer is the end of stream. + public virtual void ReleaseBuffer(IBuffer bufferImpl, bool eos) { bufferImpl.Release(); + + if (eos) + { + // If we have reached the end of stream, we don't want to send a buffer to the output port again. + return; + } IBuffer newBuffer = null; @@ -297,7 +304,7 @@ internal virtual void NativeOutputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_HE } // Ensure we release the buffer before any signalling or we will cause a memory leak due to there still being a reference count on the buffer. - this.ReleaseBuffer(bufferImpl); + this.ReleaseBuffer(bufferImpl, eos); // If this buffer signals the end of data stream, allow waiting thread to continue. if (eos || failed) diff --git a/src/MMALSharp/Ports/Outputs/VideoPort.cs b/src/MMALSharp/Ports/Outputs/VideoPort.cs index 1fc1b699..dce8da9c 100644 --- a/src/MMALSharp/Ports/Outputs/VideoPort.cs +++ b/src/MMALSharp/Ports/Outputs/VideoPort.cs @@ -91,7 +91,7 @@ internal override void NativeOutputPortCallback(MMAL_PORT_T* port, MMAL_BUFFER_H } // Ensure we release the buffer before any signalling or we will cause a memory leak due to there still being a reference count on the buffer. - this.ReleaseBuffer(bufferImpl); + this.ReleaseBuffer(bufferImpl, eos); if (eos) {