Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

- Declaration

public static IDisposable BindUserVideoFrames(this CavrnusUser user, Action<TextureWithUVs> userFrameArrived)

- Description

Triggers an event for every new frame of a user’s video stream. Note that this frame will sometimes be null if there is no stream.

The provided type is TextureWithUVs. This is important because different stream sources sometimes provide odd UVRects. For performance reasons we don’t attempt to flip/correct the Textures themselves but , instead we provide you with the UVs to flip the top-level UI when necessary. See the sample below for more details.

- Sample

Code Block
languagec#
public class UsersPanelEntry : MonoBehaviour
{
    [SerializeField] private RawImage videoStreamImage;
    [SerializeField] private AspectRatioFitter aspectRatioFitter;
    
    public void Setup(CavrnusUser user) => user.BindUserVideoFrames(AssignVidTexture);
    
    private void AssignVidTexture(TextureWithUVs tex)
    {
        float aspectRatio = 1.5f; // default value
        
        if (tex.Texture.width > 0 && tex.Texture.height > 0)
            aspectRatio = (float) tex.Texture.width / tex.Texture.height;

        aspectRatioFitter.aspectRatio = aspectRatio;
        videoStreamImage.texture = tex.Texture;
        videoStreamImage.uvRect = tex.UVRect;
    }
}