docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    Class TimedDataSource

    A base class that implements the default behaviour for a ITimedDataSource.

    Inheritance
    object
    TimedDataSource
    Implements
    ITimedDataSource
    IRegistrable
    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
    FrameRate

    IsSynchronized

    Signal to the data source whether it is being synchronized via PresentAt(FrameTimeWithRate).

    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
    FrameTime
    Remarks

    The frame duration corresponds to the FrameRate of this source. This value should typically match the time delay between timecode generation and data sampling.

    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 AddDataSource(ITimedDataSource).

    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
    FrameTimeWithRate

    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)

    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.

    FrameTimeWithRate time

    The time of the sample.

    Type Parameters
    Name Description
    T

    The datatype of the sample.

    See Also
    AddSampleWithGeneratedTime<T>(in T)

    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
    ITimedDataBuffer 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
    FrameRate frameRate

    The frame rate of the frame sequence.

    Returns
    Type Description
    FrameTimeWithRate

    The generated time.

    GetSamplesInRange<T>(FrameTime, FrameTime)

    Declaration
    public IEnumerable<(FrameTime time, T value)> GetSamplesInRange<T>(FrameTime from, FrameTime to)
    Parameters
    Type Name Description
    FrameTime from
    FrameTime to
    Returns
    Type Description
    IEnumerable<(FrameTime time, T value)>
    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
    FrameTime oldestSample

    The frame time of the oldest buffered sample, or default if there are no buffered samples.

    FrameTime newestSample

    The frame time of the newest buffered sample, or default if there are no buffered samples.

    Returns
    Type Description
    bool

    true if there are any buffered samples; otherwise, false.

    Remarks

    The frame duration corresponds to the FrameRate of this source.

    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
    FrameTime frame

    The time to retrieve the sample data for, expressed relative to the FrameRate.

    T value
    Returns
    Type Description
    TimedSampleStatus

    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 DataMissing and sets sampleValue 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<FrameTimeWithRate>
    Remarks

    This method is only invoked when IsSynchronized is true.

    • The parameter is the sample time for the presented frame.

    Implements

    ITimedDataSource
    IRegistrable
    In This Article
    Back to top
    Copyright © 2025 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)