Class TimedDataBuffer<T>
A circular buffer of data samples ordered by the FrameTime of each sample.
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, Action<T>)
Creates a new TimedDataBuffer<T> instance.
Declaration
public TimedDataBuffer(FrameRate frameRate, int capacity = 5, Action<T> sampleDiscard = null)
Parameters
Type | Name | Description |
---|---|---|
FrameRate | frameRate | The frame rate of the samples. |
Int32 | capacity | The capacity of the buffer. |
Action<T> | sampleDiscard | A callback invoked for each sample that is discarded from the buffer. This may be used to dispose samples if needed. |
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |
Properties
Interpolator
The interpolator used when TryGetSample(FrameTime, out T) is called for a time which lies between two samples.
Declaration
public IInterpolator<T> Interpolator { get; set; }
Property Value
Type | Description |
---|---|
IInterpolator<T> |
Methods
Add(in T, Double)
Adds a new sample to the buffer.
Declaration
public void Add(in T value, double time)
Parameters
Type | Name | Description |
---|---|---|
T | value | The sample value. |
Double | time | The time of the sample in seconds. |
Remarks
When the buffer is full, the oldest sample in the buffer is discarded. The sample is inserted into the buffer so that the samples are ordered by increasing time. If a sample with the specified time already exists in the buffer, its value is updated with the new value.
Add(in T, in FrameTimeWithRate)
Adds a new sample to the buffer.
Declaration
public void Add(in T value, in FrameTimeWithRate time)
Parameters
Type | Name | Description |
---|---|---|
T | value | The sample value. |
FrameTimeWithRate | time | The time of the sample in frames. |
Remarks
When the buffer is full, the oldest sample in the buffer is discarded. The sample is inserted into the buffer so that the samples are ordered by increasing time. If a sample with the specified time already exists in the buffer, its value is updated with the new value.
GetFrameRate()
Gets the frame rate of the buffered samples.
Declaration
public FrameRate GetFrameRate()
Returns
Type | Description |
---|---|
FrameRate | The frame rate of the buffered samples. |
GetSamplesInRange(FrameTime, FrameTime)
Retrieves the buffered samples that lie in a time range.
Declaration
public IEnumerable<(FrameTime time, T value)> GetSamplesInRange(FrameTime from, FrameTime to)
Parameters
Type | Name | Description |
---|---|---|
FrameTime | from | The start time of the range, expressed relative to the FrameRate. |
FrameTime | to | The end time of the range, expressed relative to the FrameRate. |
Returns
Type | Description |
---|---|
IEnumerable<(T1, T2)<FrameTime, T>> | An iterator that returns all samples in the specified range. |
Remarks
The range bounds are inclusive.
SetFrameRate(FrameRate)
Sets the frame rate of the buffered samples.
Declaration
public void SetFrameRate(FrameRate frameRate)
Parameters
Type | Name | Description |
---|---|---|
FrameRate | frameRate | The new frame rate. |
Remarks
This will remap the frame time of all samples in the buffer to match the new frame rate.
Exceptions
Type | Condition |
---|---|
ArgumentException | Thrown if |
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.
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. |
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.