Class TimedDataBuffer<T>
A circular buffer of timed samples (data with an associated Timecode).
Inherited Members
Namespace: Unity.LiveCapture
Syntax
public class TimedDataBuffer<T> : CircularBuffer<(FrameTime frameTime, T value)>
Type Parameters
| Name | Description |
|---|---|
| T | The datatype of the samples. |
Constructors
TimedDataBuffer(FrameRate, Int32)
Creates a new TimedDataBuffer<T> instance.
Declaration
public TimedDataBuffer(FrameRate frameRate, int capacity = 5)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameRate | frameRate | The nominal frame rate of the samples. |
| Int32 | capacity | The capacity of the buffer. |
Properties
Boundary
Defines the size of a "valid" readable boundary around the beginning and end of the buffer, in frames.
Declaration
public int Boundary { get; set; }
Property Value
| Type | Description |
|---|---|
| Int32 |
Remarks
When attempting to retrieve a sample outside of this boundary, TryGetSample(Timecode, FrameRate, out T) will return DataMissing.
FrameRate
Gets the nominal frame rate of the buffered samples.
Declaration
public FrameRate FrameRate { get; }
Property Value
| Type | Description |
|---|---|
| FrameRate |
Methods
Add(Double, T)
Add a new sample to the back of the buffer.
Declaration
public void Add(double time, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| Double | time | The time of the sample in seconds. |
| T | value | The sample value. |
Remarks
If the back of the buffer (the newest sample) is older than or has the sample time value as the new sample, the new sample will not be added. That is, out-of-order additions will be dropped.
Add(Timecode, FrameRate, T)
Add a new sample to the back of the buffer.
Declaration
public void Add(Timecode timecode, FrameRate frameRate, T value)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | timecode | The timecode of the sample. |
| FrameRate | frameRate | The frame rate of the timecode. |
| T | value | The sample value. |
Remarks
If the back of the buffer (the newest sample) is older than or has the sample time value as the new sample, the new sample will not be added. That is, out-of-order additions will be dropped.
TryGetSample(FrameTime, out T)
Retrieve a sample from the buffer at the requested time, if available.
Declaration
public TimedSampleStatus TryGetSample(FrameTime frame, out T sampleValue)
Parameters
| Type | Name | Description |
|---|---|---|
| FrameTime | frame | The time to retrieve the sample data for, expressed relative to the nominal FrameRate. |
| T | sampleValue | The retrieved sample, if successful. |
Returns
| Type | Description |
|---|---|
| TimedSampleStatus | The status of the retrieved sample. See remarks. |
Remarks
If a sample with the requested time could not be found, this method will perform the following:
a) if the time is bounded by the oldest and newest samples contained in the buffer,
set sampleValue to the nearest sample and return Ok.
b) if the time is outside of the buffer and is within the valid region as defined by Boundary,
set sampleValue to the newest or oldest (whichever is closer) sample in the buffer,
and return Behind or Ahead respectively.
c) else the return DataMissing and sampleValue is set to its default.
TryGetSample(Timecode, FrameRate, out T)
Retrieve a sample from the buffer at the time, if available.
Declaration
public TimedSampleStatus TryGetSample(Timecode timecode, FrameRate frameRate, out T sampleValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Timecode | timecode | The time to retrieve the sample data for, expressed relative to the given |
| FrameRate | frameRate | The framerate of the timecode source. Could be different from the framerate of the data in the buffer. |
| T | sampleValue | The retrieved sample, if successful. |
Returns
| Type | Description |
|---|---|
| TimedSampleStatus | The status of the retrieved sample. See remarks. |
Remarks
If a sample with the requested time could not be found, this method will perform the following:
a) if the time is bounded by the oldest and newest samples contained in the buffer,
set sampleValue to the nearest sample and return Ok.
b) if the time is outside of the buffer and is within the valid region as defined by Boundary,
set sampleValue to the newest or oldest (whichever is closer) sample in the buffer,
and return Behind or Ahead respectively.
c) else the return DataMissing and sampleValue is set to its default.