Class TimedDataBuffer<T>
A circular buffer of timed samples (data with an associated Timecode).
Inherited Members
Namespace: Unity.LiveCapture
Assembly: Unity.LiveCapture.dll
Syntax
public class TimedDataBuffer<T> : CircularBuffer<(FrameTime frameTime, T value)>
Type Parameters
| Name | Description |
|---|---|
| T | The datatype of the samples. |
Constructors
TimedDataBuffer(FrameRate, int)
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. |
| int | capacity | The capacity of the buffer. |
See Also
Properties
FrameRate
Gets the nominal frame rate of the buffered samples.
Declaration
public FrameRate FrameRate { get; }
Property Value
| Type | Description |
|---|---|
| FrameRate |
See Also
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.
See Also
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.
See Also
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 |
|---|---|
| FrameTime? | The frame time of the newest sample or null if there are no samples in the buffer. |
See Also
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 |
|---|---|
| FrameTime? | The frame time of the oldest sample or null if there are no samples in the buffer. |
See Also
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 default if there are no samples in the buffer. |
| FrameTime | newestSample | The frame time of the newest sample in the buffer, or default if there are no samples in the buffer. |
Returns
| Type | Description |
|---|---|
| bool | true if there are any samples in the buffer; otherwise, false. |
See Also
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 default.
See Also
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 default.