Custom frame sources

Implement IVisionFrameSource to publish a custom video pipeline to Convai, including the Y-flip requirement, lifecycle state pattern, and auto-discovery rules.

Implement IVisionFrameSource to publish any custom video pipeline — a video file, a custom render texture, or a screen capture utility — without modifying the publishing layer. Once your component is on the scene, ConvaiVisionPublisher discovers and streams it automatically.

Interface contract

IVisionFrameSource is the minimal contract required for video streaming via ConvaiVisionPublisher and live feed display via VisionDebugPreview.

public interface IVisionFrameSource
{
    bool IsCapturing { get; }
    long FrameCount { get; }
    (int Width, int Height) FrameDimensions { get; }
    float TargetFrameRate { get; }
    string SourceId { get; }
    RenderTexture CurrentRenderTexture { get; }
    bool IsFrameReady { get; }
    event Action FrameReady;
    void StartCapture();
    void StopCapture();
}

Your implementation must be a MonoBehaviour. ConvaiVisionPublisher discovers frame sources using GetComponent and GetComponentsInChildren, which only work on Unity components.

Y-flip requirement

CurrentRenderTexture must be in top-down orientation (Y-axis flipped from Unity's default bottom-up). LiveKit and standard video formats expect Y=0 at the top of the image. Skipping this step produces an upside-down feed at the receiving end.

Apply the flip with a Graphics.Blit call when writing from your source texture into the output RenderTexture:

The scale.y = -1 and offset.y = 1 arguments together flip the vertical axis. Assign _outputRt to CurrentRenderTexture.

Minimal implementation

The following skeleton implements every required member and handles FrameReady correctly. Fill in the CaptureFrame method with your actual capture logic.

FrameReady must be raised on the Unity main thread. ConvaiVisionPublisher and VisionDebugPreview both assume all IVisionFrameSource callbacks execute on the main thread. If your capture logic runs on a background thread, marshal the event raise back using a flag checked in Update, as shown in the skeleton above.

Expose lifecycle state

Implement IVisionFrameSourceStatusProvider alongside IVisionFrameSource to expose richer lifecycle state — permission flow, delayed initialization, or structured error information. The publisher can then react to readiness changes without polling.

Auto-discovery

Once your component is on the scene, ConvaiVisionPublisher discovers it automatically in this order:

  1. The Source field in the Inspector (explicit assignment).

  2. GetComponent<CameraVisionFrameSource>() on the same GameObject (built-in preference).

  3. GetComponentsInChildren<MonoBehaviour>(true) — first IVisionFrameSource found on the same GameObject or children.

If more than one frame source is found under step 3, the publisher logs a warning and selects the first. Assign the Source field explicitly to avoid ambiguity.

Next steps

Vision debug previewVision scripting API

Last updated

Was this helpful?