Table of Contents

Class ClosedCaptionsBufferEventArgs

Namespace
VisioForge.Core.Types.Events
Assembly
VisioForge.Core.dll

Provides data for closed captions buffer events, containing raw closed caption data and timing information.

public class ClosedCaptionsBufferEventArgs : EventArgs

Inheritance

Inherited Members

Examples

// Event handler for processing raw closed caption data
void OnClosedCaptionsBuffer(object sender, ClosedCaptionsBufferEventArgs e)
{
    // Copy the buffer data for processing
    byte[] captionData = new byte[e.BufferSize];
    Marshal.Copy(e.Buffer, captionData, 0, e.BufferSize);

    Console.WriteLine($"Received {e.BufferSize} bytes of caption data");
    Console.WriteLine($"Time range: {e.StartTime} - {e.StopTime}");

    // Process the raw caption data (format-specific)
    ProcessCaptionData(captionData, e.StartTime, e.StopTime);
}

Remarks

This event args class is used when raw closed caption data is extracted from video streams. Closed captions are textual representations of audio content, including dialogue, sound effects, and other audio information, designed for viewers who are deaf or hard of hearing.

The buffer contains raw closed caption data in various formats such as: - CEA-608 (Line 21) captions for analog and digital TV - CEA-708 captions for digital TV - WebVTT for web-based video - Other proprietary closed caption formats

This event provides low-level access to caption data before it is decoded into text. For decoded text captions, use VisioForge.Core.Types.Events.ClosedCaptionsTextEventArgs instead.

Constructors

ClosedCaptionsBufferEventArgs(nint, int, TimeSpan, TimeSpan)

Initializes a new instance of the VisioForge.Core.Types.Events.ClosedCaptionsBufferEventArgs class with raw caption data and timing information.

public ClosedCaptionsBufferEventArgs(nint buffer, int bufferSize, TimeSpan startTime, TimeSpan stopTime)

Parameters

buffer nint

A pointer to the unmanaged buffer containing raw closed caption data. Must not be Zero.

bufferSize int

The size of the buffer in bytes. Must be greater than 0.

startTime TimeSpan

The media timeline position when this caption should start displaying.

stopTime TimeSpan

The media timeline position when this caption should stop displaying. Must be greater than or equal to startTime.

Examples

// Extract closed caption data from a video frame
IntPtr ccBuffer = ExtractClosedCaptionData(videoFrame);
int ccSize = GetClosedCaptionDataSize(videoFrame);
TimeSpan frameTime = GetFrameTimestamp(videoFrame);
TimeSpan frameDuration = GetFrameDuration(videoFrame);

var args = new ClosedCaptionsBufferEventArgs(
    ccBuffer, 
    ccSize, 
    frameTime, 
    frameTime + frameDuration);

ClosedCaptionsBuffer?.Invoke(this, args);

Remarks

This constructor is typically called by media processing components when extracting closed caption data from video streams. The caller is responsible for ensuring the buffer remains valid for the duration of the event handler execution.

Exceptions

ArgumentException

Thrown when buffer is Zero, bufferSize is less than or equal to 0, or stopTime is less than startTime.

Properties

Buffer

Gets the pointer to the buffer containing raw closed caption data.

public nint Buffer { get; }

Property Value

nint

Remarks

This buffer contains raw, undecoded closed caption data. The format of the data depends on the source video stream and may require specific decoders to interpret.

Important: The buffer is only valid during the event handler execution. If you need to process the data asynchronously, copy it to a managed array first using Copy(IntPtr, Byte[], Int32, Int32).

BufferSize

Gets the size of the closed caption data buffer in bytes.

public int BufferSize { get; }

Property Value

int

Remarks

Use this value when copying data from the unmanaged buffer to ensure you don't read beyond the allocated memory. The actual caption data may be smaller than the buffer size if padding is present.

StartTime

Gets the start time for when this caption data should be displayed.

public TimeSpan StartTime { get; }

Property Value

TimeSpan

Remarks

This timestamp is relative to the beginning of the media stream. It indicates when the closed caption text should first appear on screen.

For continuous captions (like live broadcasts), the start time may be very close to the stop time. For pre-recorded content, there may be a longer duration between start and stop times.

StopTime

Gets the stop time for when this caption data should no longer be displayed.

public TimeSpan StopTime { get; }

Property Value

TimeSpan

Remarks

This timestamp indicates when the closed caption text should be removed from the display. The duration between VisioForge.Core.Types.Events.ClosedCaptionsBufferEventArgs.StartTime and VisioForge.Core.Types.Events.ClosedCaptionsBufferEventArgs.StopTime represents how long the caption should remain visible.

For scrolling or paint-on captions, multiple buffer events may be received with overlapping time ranges.