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

Refactoring FrameDiffDriver.Apply to use early returns instead of nested ifs. #196

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 30 additions & 31 deletions src/MMALSharp.Processing/Processors/Motion/FrameDiffDriver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,48 +83,47 @@ public override void Apply(ImageContext context)
{
base.Apply(context);

if (context.Eos)
if (context.Eos == false)
{
// if zero bytes buffered, EOS is the end of a physical input video filestream
if (this.WorkingData.Count > 0)
{
if (!_fullTestFrame)
{
MMALLog.Logger.LogDebug("EOS reached for test frame.");
return;
}

this.PrepareTestFrame();
_fullTestFrame = true;
}
else
{
MMALLog.Logger.LogDebug("Have full frame, invoking motion algorithm.");
// if zero bytes buffered, EOS is the end of a physical input video filestream
if (this.WorkingData.Count == 0)
{
MMALLog.Logger.LogDebug("EOS reached, no working data buffered");
return;
}

// frameCounter++;
// frameTimer.Restart();
if (!_fullTestFrame)
{
MMALLog.Logger.LogDebug("EOS reached for test frame.");

var detected = _motionConfig.MotionAlgorithm.DetectMotion(this, Metadata);
this.PrepareTestFrame();
_fullTestFrame = true;
return;
}

// frameTimer.Stop();
// totalElapsed += frameTimer.ElapsedMilliseconds;
MMALLog.Logger.LogDebug("Have full frame, invoking motion algorithm.");

if (detected)
{
this.LastDetectionEvent.Restart();
// frameCounter++;
// frameTimer.Restart();

if(this.OnDetectEnabled)
{
_onDetect?.Invoke();
}
}
var detected = _motionConfig.MotionAlgorithm.DetectMotion(this, Metadata);

this.TryUpdateTestFrame();
}
}
else
// frameTimer.Stop();
// totalElapsed += frameTimer.ElapsedMilliseconds;

if (detected)
{
this.LastDetectionEvent.Restart();
if (this.OnDetectEnabled)
{
MMALLog.Logger.LogDebug("EOS reached, no working data buffered");
_onDetect?.Invoke();
}
}

this.TryUpdateTestFrame();
}

/// <summary>
Expand Down