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)>, IReadOnlyList<(FrameTime frameTime, T value)>, IReadOnlyCollection<(FrameTime frameTime, T value)>, IEnumerable<(FrameTime frameTime, T value)>, IEnumerable
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
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.
GetNewestSampleTime(FrameRate)
Gets the frame time of the newest sample in the buffer.
Declaration
public FrameTime? GetNewestSampleTime(FrameRate frameRate)
Parameters
Type | Name | Description |
---|---|---|
FrameRate | frameRate | The frame rate to use for the returned frame time. |
Returns
Type | Description |
---|---|
Nullable<FrameTime> | The frame time of the newest sample or null if there are no samples in the buffer. |
GetOldestSampleTime(FrameRate)
Gets the frame time of the oldest sample in the buffer.
Declaration
public FrameTime? GetOldestSampleTime(FrameRate frameRate)
Parameters
Type | Name | Description |
---|---|---|
FrameRate | frameRate | The frame rate to use for the returned frame time. |
Returns
Type | Description |
---|---|
Nullable<FrameTime> | The frame time of the oldest sample or null if there are no samples in the buffer. |
TryGetBufferRange(out FrameTime, out FrameTime)
Gets the frame time of the newest and oldest samples in the buffer.
Declaration
public bool TryGetBufferRange(out FrameTime oldestSample, out FrameTime newestSample)
Parameters
Type | Name | Description |
---|---|---|
FrameTime | oldestSample | The frame time of the oldest sample in the buffer, or langword_csharp_default if there are no samples in the buffer. |
FrameTime | newestSample | The frame time of the newest sample in the buffer, or langword_csharp_default if there are no samples in the buffer. |
Returns
Type | Description |
---|---|
Boolean | true if there are any samples in the buffer; otherwise, false. |
TryGetSample(FrameTime, out T)
Retrieves a sample from the buffer at the specified 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 FrameRate. |
T | sampleValue | The retrieved sample, if successful. |
Returns
Type | Description |
---|---|
TimedSampleStatus | The status of the retrieved sample. See remarks. |
Remarks
If there isn't a sample at the specified time, the following occurs:
a) if the time is bounded by the oldest and newest samples contained in the buffer,
sampleValue
is set to the nearest sample and returns Ok.
b) if the time is outside of the buffer but there is at least one buffered sample,
sampleValue
is set to the newest or oldest buffered sample (whichever is closer)
and returns Behind or Ahead respectively.
c) otherwise, returns DataMissing and sets sampleValue
to langword_csharp_default.
TryGetSample(Timecode, FrameRate, out T)
Retrieves a sample from the buffer at the specified 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. It might 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 there isn't a sample at the specified time, the following occurs:
a) if the time is bounded by the oldest and newest samples contained in the buffer,
sampleValue
is set to the nearest sample and returns Ok.
b) if the time is outside of the buffer but there is at least one buffered sample,
sampleValue
is set to the newest or oldest buffered sample (whichever is closer)
and returns Behind or Ahead respectively.
c) otherwise, returns DataMissing and sets sampleValue
to langword_csharp_default.