Class TimedDataSource
A base class that implements the default behaviour for a ITimed
Namespace: Unity.LiveCapture
Assembly: Unity.LiveCapture.dll
Syntax
[Serializable]
public class TimedDataSource : ITimedDataSource, IRegistrable
Properties
BufferSize
The current buffer size.
Declaration
public int BufferSize { get; set; }
Property Value
Type | Description |
---|---|
int |
Enabled
Is the data source ready to buffer samples.
Declaration
public bool Enabled { get; }
Property Value
Type | Description |
---|---|
bool |
FrameRate
The number of data samples per second.
Declaration
public FrameRate FrameRate { get; set; }
Property Value
Type | Description |
---|---|
Frame |
IsSynchronized
Signal to the data source whether it is being synchronized via Present
Declaration
public bool IsSynchronized { get; set; }
Property Value
Type | Description |
---|---|
bool |
Remarks
When true, the data source should disable its own update mechanism.
MaxBufferSize
The maximum size of the sample buffer, if limited.
Declaration
public int? MaxBufferSize { get; set; }
Property Value
Type | Description |
---|---|
int? |
MinBufferSize
The minimum size of the sample buffer, if limited.
Declaration
public int? MinBufferSize { get; set; }
Property Value
Type | Description |
---|---|
int? |
Offset
The time offset applied to sample timecodes, in frames.
Declaration
public FrameTime Offset { get; set; }
Property Value
Type | Description |
---|---|
Frame |
Remarks
The frame duration corresponds to the Frame
SourceObject
The object that owns this data source.
Declaration
public Object SourceObject { get; set; }
Property Value
Type | Description |
---|---|
Object |
Synchronizer
The ISynchronizer controlling this source.
Declaration
public ISynchronizer Synchronizer { get; set; }
Property Value
Type | Description |
---|---|
ISynchronizer |
Remarks
In most cases you can simply implement this as an auto-property. The default synchronizer implementation
automatically assigns this property when you call Add
Methods
AddSampleWithGeneratedTime<T>(in T)
Adds a new data sample to the buffer.
Declaration
public FrameTimeWithRate AddSampleWithGeneratedTime<T>(in T value)
Parameters
Type | Name | Description |
---|---|---|
T | value | The sample value to add. |
Returns
Type | Description |
---|---|
Frame |
The generated sample time. |
Type Parameters
Name | Description |
---|---|
T | The datatype of the sample. |
Remarks
Use this when a device does not provide timecode information with the samples, and instead relies on genlock to facilitate synchronization. When this data source is assigned to a synchronizer, a timecode will be generated using the synchronizer's presentation time. This should usually be called once per frame. When called multiple times in a single frame, the new value will overwrite any previous values submitted for the current frame.
See Also
AddSample<T>(in T, in FrameTimeWithRate)
Adds a new data sample to the buffer.
Declaration
public void AddSample<T>(in T value, in FrameTimeWithRate time)
Parameters
Type | Name | Description |
---|---|---|
T | value | The sample value to add. |
Frame |
time | The time of the sample. |
Type Parameters
Name | Description |
---|---|
T | The datatype of the sample. |
See Also
ClearBuffer()
Removes all frames from the data buffer.
Declaration
public void ClearBuffer()
Disable()
Deactivates the data source.
Declaration
public void Disable()
Enable(ITimedDataBuffer)
Activates the data source.
Declaration
public void Enable(ITimedDataBuffer buffer)
Parameters
Type | Name | Description |
---|---|---|
ITimed |
buffer | The buffer to use for storing frame samples. |
GenerateFrameTime(in FrameRate)
Gets a time based on the current engine time.
Declaration
public static FrameTimeWithRate GenerateFrameTime(in FrameRate frameRate)
Parameters
Type | Name | Description |
---|---|---|
Frame |
frameRate | The frame rate of the frame sequence. |
Returns
Type | Description |
---|---|
Frame |
The generated time. |
GetSamplesInRange<T>(FrameTime, FrameTime)
Declaration
public IEnumerable<(FrameTime time, T value)> GetSamplesInRange<T>(FrameTime from, FrameTime to)
Parameters
Returns
Type | Description |
---|---|
IEnumerable<(Frame |
Type Parameters
Name | Description |
---|---|
T |
TryGetBufferRange(out FrameTime, out FrameTime)
Gets the frame time of the newest and oldest samples buffered by the data source.
Declaration
public bool TryGetBufferRange(out FrameTime oldestSample, out FrameTime newestSample)
Parameters
Type | Name | Description |
---|---|---|
Frame |
oldestSample | The frame time of the oldest buffered sample, or default if there are no buffered samples. |
Frame |
newestSample | The frame time of the newest buffered sample, or default if there are no buffered samples. |
Returns
Remarks
The frame duration corresponds to the Frame
TryGetSample<T>(FrameTime, out T)
Retrieves a sample from the buffer at the specified time.
Declaration
public TimedSampleStatus TryGetSample<T>(FrameTime frame, out T value)
Parameters
Type | Name | Description |
---|---|---|
Frame |
frame | The time to retrieve the sample data for, expressed relative to the Frame |
T | value |
Returns
Type | Description |
---|---|
Timed |
The status of the retrieved sample. |
Type Parameters
Name | Description |
---|---|
T |
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 DatasampleValue
to default.
Events
FramePresented
An event invoked when this source presents a synchronized frame.
Declaration
public event Action<FrameTimeWithRate> FramePresented
Event Type
Type | Description |
---|---|
Action<Frame |
Remarks
This method is only invoked when Is
- The parameter is the sample time for the presented frame.