Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
#136 - Do not send buffer to port if we have reached end of stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
techyian committed Apr 8, 2020
1 parent 2898be9 commit 0ec4bcb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/MMALSharp/Ports/Outputs/FastStillPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/MMALSharp/Ports/Outputs/FileEncodeOutputPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private void ProcessBuffer(IBuffer bufferImpl)
}
else
{
this.ReleaseBuffer(bufferImpl);
this.ReleaseBuffer(bufferImpl, eos);
}
}
else
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/MMALSharp/Ports/Outputs/IOutputPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
/// <param name="bufferImpl">A managed buffer object.</param>
void ReleaseBuffer(IBuffer bufferImpl);
/// <param name="eos">Flag that this buffer is the end of stream.</param>
void ReleaseBuffer(IBuffer bufferImpl, bool eos);

/// <summary>
/// Call to register a new callback handler with this port.
Expand Down
11 changes: 9 additions & 2 deletions src/MMALSharp/Ports/Outputs/OutputPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
/// </summary>
/// <param name="bufferImpl">A managed buffer object.</param>
public virtual void ReleaseBuffer(IBuffer bufferImpl)
/// <param name="eos">Flag that this buffer is the end of stream.</param>
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;

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/MMALSharp/Ports/Outputs/VideoPort.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 0ec4bcb

Please sign in to comment.