Class PreEventRecordingBlock
- Namespace
- VisioForge.Core.MediaBlocks.Sinks
- Assembly
- VisioForge.Core.dll
Pre-event (circular buffer) recording block for Media Blocks SDK. Continuously buffers encoded video/audio in memory. On trigger, flushes buffered pre-event frames to a file, continues recording live frames for a configurable post-event duration, then returns to buffer-only mode.
public class PreEventRecordingBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternalsInheritance
Implements
Inherited Members
Extension Methods
Constructors
PreEventRecordingBlock(PreEventRecordingSettings, string)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock class.
public PreEventRecordingBlock(PreEventRecordingSettings settings, string muxFactoryName = "mp4mux")Parameters
settingsPreEventRecordingSettings-
Pre-event recording configuration.
muxFactoryNamestring-
GStreamer mux element factory name (e.g., "mp4mux", "matroskamux", "mpegtsmux"). Default: "mp4mux".
Properties
AudioEnabled
Gets or sets whether audio capture is enabled. Set to false before pipeline start when no audio source is connected. Default: true.
public bool AudioEnabled { get; set; }Property Value
AudioInput
Gets the audio input pad.
public MediaBlockPad AudioInput { get; }Property Value
BufferTotalBytes
Gets the total bytes currently stored in the ring buffer.
public long BufferTotalBytes { get; }Property Value
BufferedDuration
Gets the current buffered duration.
public TimeSpan BufferedDuration { get; }Property Value
CurrentFilename
Gets the current recording filename.
public string CurrentFilename { get; }Property Value
DebugLogPath
Gets or sets the debug log file path. When non-null, detailed timestamp debugging is written to this file.
public string DebugLogPath { get; set; }Property Value
Input
Gets the primary input pad (video).
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all input pads.
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the primary output pad (none - this is a sink).
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets all output pads (none - this is a sink).
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets the pre-event recording settings.
public PreEventRecordingSettings Settings { get; }Property Value
State
Gets the current state of the pre-event recording system.
public PreEventRecordingState State { get; }Property Value
Type
Gets the media block type.
public override MediaBlockType Type { get; }Property Value
VideoInput
Gets the video input pad.
public MediaBlockPad VideoInput { get; }Property Value
Methods
Build()
Builds and initializes the pre-event recording block. Creates internal appsink elements for capturing encoded video/audio.
public override bool Build()Returns
- bool
-
trueif built successfully; otherwise,false.
CleanUp()
Cleans up all resources associated with the pre-event recording block.
public void CleanUp()Dispose(bool)
Releases resources.
protected override void Dispose(bool disposing)Parameters
disposingbool
ExtendRecording()
Extends the current recording by resetting the post-event timer. Call this when the trigger condition is still active (e.g., motion continues).
public void ExtendRecording()GetCore()
Gets the core element.
public BaseElement GetCore()Returns
- BaseElement
GetElement()
Gets the GStreamer element.
public Element GetElement()Returns
- Element
StartBuffering()
Starts or resumes buffering after being stopped. Frames are buffered only while the pipeline runs. Called before the pipeline starts, it raises OnStateChanged(Buffering) at once and the start does not raise it again. Does nothing when the block is already buffering or is disposed.
public void StartBuffering()StopBuffering()
Stops everything including buffering. Clears the buffer. The block stays VisioForge.Core.Types.X.PreEventRecording.PreEventRecordingState.Stopped, across pipeline restarts, until VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.StartBuffering. A repeated call raises no event.
public void StopBuffering()StopRecording()
Manually stops the current recording and returns to buffering mode.
public void StopRecording()TriggerRecording(string)
Triggers recording: flushes the pre-event buffer to a file and continues recording live frames. If already recording, extends the current recording (resets the post-event timer). The call is refused until the first encoded video sample has arrived and, when audio is enabled, until the first encoded audio sample has arrived.
public void TriggerRecording(string filename)Parameters
filenamestring-
The output filename for the recording.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the pipeline context.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline
OnRecordingStarted
Occurs when recording starts (buffer flushed to file).
public event EventHandler<PreEventRecordingEventArgs> OnRecordingStartedEvent Type
Remarks
VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.OnRecordingStarted, VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.OnRecordingStopped and VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.OnStateChanged are raised one at a time, in the order the changes happened, never under the block's locks. While a handler is running, on another thread or on this one, a call that causes an event returns before that event is raised: the thread running the handler raises it once the handler returns. A handler can therefore run on a worker thread, and after the pipeline stopped or the block was disposed; marshal to the UI thread in a handler that touches controls. VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.StopRecording, VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.StopBuffering, VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.StartBuffering and VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.TriggerRecording(System.String) rethrow what the handlers they raised threw; on the post-event timer, a pipeline start or stop, or a format change it is logged as an error.
OnRecordingStopped
Occurs when recording stops (post-event timer expired, manual stop, or the pipeline stopped). The file is finalized when it is raised.
public event EventHandler<PreEventRecordingEventArgs> OnRecordingStoppedEvent Type
Remarks
Raised in order with the other events; see VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.OnRecordingStarted.
OnStateChanged
Occurs when the recording state changes.
public event EventHandler<PreEventRecordingEventArgs> OnStateChangedEvent Type
Remarks
Raised in order with the other events; see VisioForge.Core.MediaBlocks.Sinks.PreEventRecordingBlock.OnRecordingStarted.