diff --git a/Packages/StreamVideo/DocsCodeSamples/01-basics/UiToolkitVideoCodeSamples.cs b/Packages/StreamVideo/DocsCodeSamples/01-basics/UiToolkitVideoCodeSamples.cs
new file mode 100644
index 00000000..73a37307
--- /dev/null
+++ b/Packages/StreamVideo/DocsCodeSamples/01-basics/UiToolkitVideoCodeSamples.cs
@@ -0,0 +1,47 @@
+using StreamVideo.Core.StatefulModels;
+using StreamVideo.Core.StatefulModels.Tracks;
+using UnityEngine;
+using UnityEngine.UIElements;
+
+namespace StreamVideoDocsCodeSamples._01_basics
+{
+ ///
+ /// Binds a participant video track to a UI Toolkit Image.
+ /// Size the element with USS (absolute fill or flex-grow). Otherwise it sizes itself to the texture
+ /// and the layout jumps when the incoming resolution changes.
+ ///
+ internal class UiToolkitVideoCodeSamples : MonoBehaviour
+ {
+ public void BindParticipant(IStreamVideoCallParticipant participant)
+ {
+ foreach (var track in participant.GetTracks())
+ {
+ OnParticipantTrackAdded(participant, track);
+ }
+
+ // A reconnect creates a new track. Bind again from TrackAdded.
+ participant.TrackAdded += OnParticipantTrackAdded;
+ }
+
+ private void OnEnable()
+ {
+ _video = _document.rootVisualElement.Q("video");
+ _video.scaleMode = ScaleMode.ScaleAndCrop;
+ }
+
+ private void OnParticipantTrackAdded(IStreamVideoCallParticipant participant, IStreamTrack track)
+ {
+ if (!(track is StreamVideoTrack videoTrack))
+ {
+ return;
+ }
+
+ videoTrack.SetRenderTarget(_video);
+ }
+
+ [SerializeField]
+ private UIDocument _document;
+
+ private Image _video;
+ }
+}
diff --git a/Packages/StreamVideo/DocsCodeSamples/01-basics/UiToolkitVideoCodeSamples.cs.meta b/Packages/StreamVideo/DocsCodeSamples/01-basics/UiToolkitVideoCodeSamples.cs.meta
new file mode 100644
index 00000000..61aaf3fc
--- /dev/null
+++ b/Packages/StreamVideo/DocsCodeSamples/01-basics/UiToolkitVideoCodeSamples.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: c9e5a3d16f4b508cad2e3f4a5b6c7d8e
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Packages/StreamVideo/Runtime/Core/DeviceManagers/IStreamVideoDeviceManager.cs b/Packages/StreamVideo/Runtime/Core/DeviceManagers/IStreamVideoDeviceManager.cs
index 135f9056..6fdfb5b7 100644
--- a/Packages/StreamVideo/Runtime/Core/DeviceManagers/IStreamVideoDeviceManager.cs
+++ b/Packages/StreamVideo/Runtime/Core/DeviceManagers/IStreamVideoDeviceManager.cs
@@ -41,7 +41,9 @@ public interface IStreamVideoDeviceManager : IDeviceManager, I
/// Assign it once (e.g. to a RawImage); the same instance is returned for the lifetime of the client, so no
/// rebinding is needed for camera switches, filter changes, joining, or leaving calls.
/// It is black until the camera delivers frames and is resized in place when the video size or orientation
- /// changes. Do not apply the camera's videoRotationAngle. Call from the main thread.
+ /// changes. A UI Toolkit does not regenerate its crop when that
+ /// same texture instance changes size; call
+ /// when the width or height changes. Do not apply the camera's videoRotationAngle. Call from the main thread.
///
Texture GetLocalPreviewTexture();
}
diff --git a/Packages/StreamVideo/Runtime/Core/StatefulModels/Tracks/StreamVideoTrack.cs b/Packages/StreamVideo/Runtime/Core/StatefulModels/Tracks/StreamVideoTrack.cs
index 329e2e97..4bdff32d 100644
--- a/Packages/StreamVideo/Runtime/Core/StatefulModels/Tracks/StreamVideoTrack.cs
+++ b/Packages/StreamVideo/Runtime/Core/StatefulModels/Tracks/StreamVideoTrack.cs
@@ -23,7 +23,18 @@ private void OnVideoReceived(Texture renderer)
_targetImage.texture = renderer;
}
- //StreamTodo: can we remove Unity dependency?
+ //StreamTodo: can we remove Unity dependency?
+ ///
+ /// Renders this track into a uGUI .
+ ///
+ ///
+ /// Only one render target is active. The last SetRenderTarget call wins and clears the other target.
+ /// Call from the main thread. The target is updated when the incoming resolution changes and the texture
+ /// instance is replaced. After a reconnect the participant receives a new track
+ /// (), so call SetRenderTarget again.
+ ///
+ /// Image that receives the video. Must not be null.
+ /// is null.
public void SetRenderTarget(RawImage targetImage)
{
if (targetImage == null)
@@ -32,18 +43,53 @@ public void SetRenderTarget(RawImage targetImage)
}
_targetImage = targetImage;
+ _targetUIToolkitImage = null;
+ }
+
+ ///
+ /// Renders this track into a UI Toolkit .
+ ///
+ ///
+ /// Only one render target is active. The last SetRenderTarget call wins and clears the other target.
+ /// Call from the main thread. stays null until the first
+ /// frame. The SDK assigns the new texture instance when the incoming resolution changes.
+ /// After a reconnect the participant receives a new track
+ /// (), so call SetRenderTarget again.
+ /// Set to and size
+ /// the element with USS (absolute fill or flex-grow). Without that, the element sizes itself to the texture
+ /// and the layout jumps when the resolution changes.
+ ///
+ /// Element that receives the video. Must not be null.
+ /// is null.
+ public void SetRenderTarget(UnityEngine.UIElements.Image targetImage)
+ {
+ if (targetImage == null)
+ {
+ throw new ArgumentNullException(nameof(targetImage));
+ }
+
+ _targetUIToolkitImage = targetImage;
+ _targetImage = null;
}
internal override void Update()
{
base.Update();
-
- if (_targetImage == null)
+
+ if (_targetImage != null)
{
+ _targetImage.texture = Track.Texture;
return;
}
-
- _targetImage.texture = Track.Texture;
+
+ if (_targetUIToolkitImage != null)
+ {
+ var texture = Track.Texture;
+ if (!ReferenceEquals(_targetUIToolkitImage.image, texture))
+ {
+ _targetUIToolkitImage.image = texture;
+ }
+ }
}
protected override void OnDisposing()
@@ -55,7 +101,14 @@ protected override void OnDisposing()
// {
// Track.OnVideoReceived -= OnVideoReceived;
// }
-
+
+ if (_targetUIToolkitImage != null && ReferenceEquals(_targetUIToolkitImage.image, Track.Texture))
+ {
+ _targetUIToolkitImage.image = null;
+ }
+
+ _targetUIToolkitImage = null;
+
base.OnDisposing();
}
@@ -63,5 +116,6 @@ protected override void OnDisposing()
internal RenderTexture TargetTexture => throw new NotSupportedException("This property is deprecated");
private RawImage _targetImage;
+ private UnityEngine.UIElements.Image _targetUIToolkitImage;
}
}
\ No newline at end of file
diff --git a/Packages/StreamVideo/Tests/Editor/StreamVideoTrackTests.cs b/Packages/StreamVideo/Tests/Editor/StreamVideoTrackTests.cs
new file mode 100644
index 00000000..3a87c395
--- /dev/null
+++ b/Packages/StreamVideo/Tests/Editor/StreamVideoTrackTests.cs
@@ -0,0 +1,209 @@
+#if STREAM_TESTS_ENABLED
+using System;
+using System.Reflection;
+using System.Threading;
+using NUnit.Framework;
+using StreamVideo.Core.StatefulModels.Tracks;
+using Unity.WebRTC;
+using UnityEngine;
+using UnityEngine.UI;
+using Object = UnityEngine.Object;
+using UiImage = UnityEngine.UIElements.Image;
+
+namespace StreamVideo.Tests.Editor
+{
+ ///
+ /// Tests for render targets.
+ /// A sending has a stable destination texture until its source size changes.
+ ///
+ internal sealed class StreamVideoTrackTests
+ {
+ [SetUp]
+ public void SetUp()
+ {
+ _uiImage = new UiImage();
+ _rawHost = new GameObject("StreamVideoTrackTests");
+ _rawImage = _rawHost.AddComponent();
+ EnsureWebRtcSyncContext();
+
+ try
+ {
+ _source = CreateTexture(160, 90);
+ _mediaTrack = new VideoStreamTrack(_source);
+ _track = new StreamVideoTrack(_mediaTrack);
+ }
+ catch (Exception exception)
+ {
+ Assert.Ignore(
+ "A sending VideoStreamTrack cannot be constructed in this Editor session (" +
+ exception.GetType().Name + ": " + exception.Message +
+ "). WebRTC.Context is created on assembly reload and is not publicly initializable.");
+ }
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ _track?.Dispose();
+ _mediaTrack?.Dispose();
+ DestroyTexture(_source);
+ DestroyTexture(_replacement);
+ if (_rawHost != null)
+ {
+ Object.DestroyImmediate(_rawHost);
+ }
+ }
+
+ [Test]
+ public void When_ui_toolkit_render_target_set_expect_image_receives_texture()
+ {
+ _track.SetRenderTarget(_uiImage);
+
+ _track.Update();
+
+ Assert.That(_uiImage.image, Is.SameAs(_mediaTrack.Texture),
+ "The UI Toolkit image should show the track texture after Update.");
+ Assert.That(_uiImage.image.width, Is.GreaterThan(0),
+ "The received texture should have a non-zero width.");
+ }
+
+ [Test]
+ public void When_retarget_to_raw_image_expect_ui_toolkit_updates_stop()
+ {
+ _track.SetRenderTarget(_uiImage);
+ _track.Update();
+ var firstTexture = _mediaTrack.Texture;
+
+ _track.SetRenderTarget(_rawImage);
+ _replacement = CreateTexture(320, 180);
+ _mediaTrack.ReplaceSourceTexture(_replacement);
+ _track.Update();
+
+ Assert.That(_mediaTrack.Texture, Is.Not.SameAs(firstTexture),
+ "A source size change should replace the sending texture instance.");
+ Assert.That(_rawImage.texture, Is.SameAs(_mediaTrack.Texture),
+ "The RawImage should receive the new texture after retargeting.");
+ Assert.That(_uiImage.image, Is.SameAs(firstTexture),
+ "The UI Toolkit image should stop updating after a RawImage target is set.");
+ }
+
+ [Test]
+ public void When_retarget_to_ui_toolkit_expect_raw_image_updates_stop()
+ {
+ _track.SetRenderTarget(_rawImage);
+ _track.Update();
+ var firstTexture = _mediaTrack.Texture;
+
+ _track.SetRenderTarget(_uiImage);
+ _replacement = CreateTexture(320, 180);
+ _mediaTrack.ReplaceSourceTexture(_replacement);
+ _track.Update();
+
+ Assert.That(_uiImage.image, Is.SameAs(_mediaTrack.Texture),
+ "The UI Toolkit image should receive the new texture after retargeting.");
+ Assert.That(_rawImage.texture, Is.SameAs(firstTexture),
+ "The RawImage should stop updating after a UI Toolkit target is set.");
+ }
+
+ [Test]
+ public void When_set_render_target_null_expect_argument_null_exception()
+ {
+ Assert.Throws(() => _track.SetRenderTarget((RawImage)null),
+ "A null RawImage should be rejected.");
+ Assert.Throws(() => _track.SetRenderTarget((UiImage)null),
+ "A null UI Toolkit image should be rejected.");
+ }
+
+ [Test]
+ public void When_track_disposed_expect_ui_toolkit_image_cleared()
+ {
+ _track.SetRenderTarget(_uiImage);
+ _track.Update();
+ Assert.That(_uiImage.image, Is.SameAs(_mediaTrack.Texture),
+ "Precondition: the image shows this track before dispose.");
+
+ _track.Dispose();
+ _track = null;
+
+ Assert.That(_uiImage.image, Is.Null,
+ "Dispose should clear the UI Toolkit image when it still shows this track's texture.");
+ }
+
+ [Test]
+ public void When_disposed_track_image_shows_another_track_expect_texture_kept()
+ {
+ var otherSource = CreateTexture(192, 108);
+ VideoStreamTrack otherMedia = null;
+ StreamVideoTrack otherTrack = null;
+ try
+ {
+ otherMedia = new VideoStreamTrack(otherSource);
+ otherTrack = new StreamVideoTrack(otherMedia);
+ _track.SetRenderTarget(_uiImage);
+ _track.Update();
+ otherTrack.SetRenderTarget(_uiImage);
+ otherTrack.Update();
+
+ _track.Dispose();
+ _track = null;
+
+ Assert.That(_uiImage.image, Is.SameAs(otherMedia.Texture),
+ "Dispose should not clear an image that another track has since taken over.");
+ }
+ finally
+ {
+ otherTrack?.Dispose();
+ otherMedia?.Dispose();
+ DestroyTexture(otherSource);
+ }
+ }
+
+ // Edit Mode does not run RuntimeInitializeOnLoadMethod, so WebRTC's sync context stays null
+ // and disposing a track throws. Play Mode installs the real context. This only fills the gap.
+ private static void EnsureWebRtcSyncContext()
+ {
+ var field = typeof(WebRTC).GetField("s_syncContext", BindingFlags.NonPublic | BindingFlags.Static);
+ if (field == null || field.GetValue(null) != null)
+ {
+ return;
+ }
+
+ field.SetValue(null, new InlineSynchronizationContext());
+ }
+
+ private sealed class InlineSynchronizationContext : SynchronizationContext
+ {
+ public override void Post(SendOrPostCallback callback, object state) => callback(state);
+
+ public override void Send(SendOrPostCallback callback, object state) => callback(state);
+ }
+
+ private static RenderTexture CreateTexture(int width, int height)
+ {
+ var format = WebRTC.GetSupportedGraphicsFormat(SystemInfo.graphicsDeviceType);
+ var texture = new RenderTexture(width, height, 0, format);
+ texture.Create();
+ return texture;
+ }
+
+ private static void DestroyTexture(RenderTexture texture)
+ {
+ if (texture == null)
+ {
+ return;
+ }
+
+ texture.Release();
+ Object.DestroyImmediate(texture);
+ }
+
+ private StreamVideoTrack _track;
+ private VideoStreamTrack _mediaTrack;
+ private RenderTexture _source;
+ private RenderTexture _replacement;
+ private GameObject _rawHost;
+ private RawImage _rawImage;
+ private UiImage _uiImage;
+ }
+}
+#endif
diff --git a/Packages/StreamVideo/Tests/Editor/StreamVideoTrackTests.cs.meta b/Packages/StreamVideo/Tests/Editor/StreamVideoTrackTests.cs.meta
new file mode 100644
index 00000000..16ba4016
--- /dev/null
+++ b/Packages/StreamVideo/Tests/Editor/StreamVideoTrackTests.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: a7c3e1b94d2f4e6a8b0c1d2e3f4a5b6c
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Packages/StreamVideo/Tests/Runtime/StreamVideoTrackTests.cs b/Packages/StreamVideo/Tests/Runtime/StreamVideoTrackTests.cs
new file mode 100644
index 00000000..aba714c3
--- /dev/null
+++ b/Packages/StreamVideo/Tests/Runtime/StreamVideoTrackTests.cs
@@ -0,0 +1,255 @@
+#if STREAM_TESTS_ENABLED
+using System.Collections;
+using System.Linq;
+using System.Reflection;
+using System.Threading.Tasks;
+using NUnit.Framework;
+using StreamVideo.Core;
+using StreamVideo.Core.StatefulModels;
+using StreamVideo.Core.StatefulModels.Tracks;
+using StreamVideo.Tests.Shared;
+using UnityEngine;
+using UnityEngine.TestTools;
+using UnityEngine.UI;
+using Object = UnityEngine.Object;
+using UiImage = UnityEngine.UIElements.Image;
+
+namespace StreamVideo.Tests.Runtime
+{
+ ///
+ /// Tests for UI Toolkit rendering against a live call.
+ ///
+ internal class StreamVideoTrackTests : TestsBase
+ {
+ [UnityTest, ConditionalIgnore(IgnoreConditionNoCameraKey, IgnoreConditionNoCameraReason)]
+ public IEnumerator When_ui_toolkit_render_target_set_expect_image_receives_texture()
+ => ConnectAndExecute(When_ui_toolkit_render_target_set_expect_image_receives_texture_Async,
+ ignoreFailingMessages: true);
+
+ [UnityTest, ConditionalIgnore(IgnoreConditionNoCameraKey, IgnoreConditionNoCameraReason)]
+ public IEnumerator When_retarget_to_raw_image_expect_ui_toolkit_updates_stop()
+ => ConnectAndExecute(When_retarget_to_raw_image_expect_ui_toolkit_updates_stop_Async,
+ ignoreFailingMessages: true);
+
+ [UnityTest, ConditionalIgnore(IgnoreConditionNoCameraKey, IgnoreConditionNoCameraReason)]
+ public IEnumerator When_render_target_null_or_disposed_expect_exception_and_cleared_image()
+ => ConnectAndExecute(When_render_target_null_or_disposed_expect_exception_and_cleared_image_Async,
+ ignoreFailingMessages: true);
+
+ private async Task When_ui_toolkit_render_target_set_expect_image_receives_texture_Async(
+ ITestClient clientA, ITestClient clientB)
+ {
+ var streamTrack = await ReceiveRemoteVideoTrackAsync(clientA, clientB);
+ var image = new UiImage();
+ streamTrack.SetRenderTarget(image);
+
+ var (received, elapsed) = await WaitForConditionAsync(
+ () => image.image != null && image.image.width > 0, timeoutMs: 15000);
+ AssertImageShowsTrackTexture(received, elapsed, streamTrack, image,
+ "UI Toolkit image should receive a remote video texture.");
+ }
+
+ private async Task When_retarget_to_raw_image_expect_ui_toolkit_updates_stop_Async(
+ ITestClient clientA, ITestClient clientB)
+ {
+ var participant = await ReceiveRemoteParticipantAsync(clientA, clientB);
+ var streamTrack = await WaitForVideoTrackAsync(participant);
+ var image = new UiImage();
+ streamTrack.SetRenderTarget(image);
+
+ var (received, elapsed) = await WaitForConditionAsync(
+ () => image.image != null && image.image.width > 0, timeoutMs: 15000);
+ AssertImageShowsTrackTexture(received, elapsed, streamTrack, image,
+ "Precondition: UI Toolkit image should receive video before retargeting.");
+
+ var rawHost = new GameObject("StreamVideoTrackTests.RawImage");
+ var rawImage = rawHost.AddComponent();
+ var sentinel = new Texture2D(8, 8);
+ try
+ {
+ streamTrack.SetRenderTarget(rawImage);
+ image.image = sentinel;
+ participant.UpdateRequestedVideoResolution(new VideoResolution(320, 240));
+
+ var (rawReceived, rawElapsed) = await WaitForConditionAsync(() => rawImage.texture != null,
+ timeoutMs: 5000);
+ Assert.That(rawReceived, Is.True,
+ "RawImage should receive the track texture after retargeting. Waited " +
+ rawElapsed.TotalSeconds + "s.");
+ Assert.That(image.image, Is.SameAs(sentinel),
+ "UI Toolkit updates should stop after SetRenderTarget(RawImage).");
+
+ streamTrack.SetRenderTarget(image);
+ rawImage.texture = sentinel;
+ var (uiReceived, uiElapsed) = await WaitForConditionAsync(
+ () => image.image != null && !ReferenceEquals(image.image, sentinel), timeoutMs: 5000);
+ Assert.That(uiReceived, Is.True,
+ "UI Toolkit image should receive the track texture again. Waited " + uiElapsed.TotalSeconds + "s.");
+ Assert.That(rawImage.texture, Is.SameAs(sentinel),
+ "RawImage updates should stop after SetRenderTarget(UI Toolkit image).");
+ }
+ finally
+ {
+ Object.Destroy(rawHost);
+ Object.Destroy(sentinel);
+ }
+ }
+
+ private async Task When_render_target_null_or_disposed_expect_exception_and_cleared_image_Async(
+ ITestClient clientA, ITestClient clientB)
+ {
+ var streamTrack = await ReceiveRemoteVideoTrackAsync(clientA, clientB);
+
+ Assert.Throws(() => streamTrack.SetRenderTarget((RawImage)null),
+ "A null RawImage should be rejected.");
+ Assert.Throws(() => streamTrack.SetRenderTarget((UiImage)null),
+ "A null UI Toolkit image should be rejected.");
+
+ var image = new UiImage();
+ streamTrack.SetRenderTarget(image);
+ var (received, elapsed) = await WaitForConditionAsync(
+ () => image.image != null && image.image.width > 0, timeoutMs: 15000);
+ AssertImageShowsTrackTexture(received, elapsed, streamTrack, image,
+ "Precondition: image should show the track before dispose.");
+
+ streamTrack.Dispose();
+
+ Assert.That(image.image, Is.Null,
+ "Dispose should clear the UI Toolkit image when it still shows this track's texture.");
+ }
+
+ private static async Task ReceiveRemoteVideoTrackAsync(ITestClient clientA, ITestClient clientB)
+ {
+ var participant = await ReceiveRemoteParticipantAsync(clientA, clientB);
+ return await WaitForVideoTrackAsync(participant);
+ }
+
+ private static async Task WaitForVideoTrackAsync(
+ IStreamVideoCallParticipant participant)
+ {
+ if (participant.VideoTrack is StreamVideoTrack existing)
+ {
+ return existing;
+ }
+
+ StreamVideoTrack streamTrack = null;
+ participant.TrackAdded += (_, track) =>
+ {
+ if (track is StreamVideoTrack videoTrack)
+ {
+ streamTrack = videoTrack;
+ }
+ };
+
+ if (participant.VideoTrack is StreamVideoTrack arrived)
+ {
+ return arrived;
+ }
+
+ var (received, elapsed) = await WaitForConditionAsync(() => streamTrack != null, timeoutMs: 15000);
+ Assert.That(received, Is.True,
+ "The watching client should receive a video track. Waited " + elapsed.TotalSeconds + "s.");
+ return streamTrack;
+ }
+
+ private static async Task ReceiveRemoteParticipantAsync(
+ ITestClient clientA, ITestClient clientB)
+ {
+ var clientACall = await clientA.JoinRandomCallAsync();
+ await SelectCameraThatDeliversFramesAsync(clientA.Client);
+
+ var clientBCall = await clientB.Client.JoinCallAsync(clientACall.Type, clientACall.Id, create: false,
+ ring: false, notify: false);
+
+ var localSessionId = clientACall.GetLocalParticipant().SessionId;
+ var (joined, elapsed) = await WaitForConditionAsync(
+ () => clientBCall.Participants.Any(participant => participant.SessionId == localSessionId),
+ timeoutMs: 15000);
+ Assert.That(joined, Is.True,
+ "The watching client should see the publishing participant. Waited " + elapsed.TotalSeconds + "s.");
+
+ var participant = clientBCall.Participants.First(p => p.SessionId == localSessionId);
+ participant.UpdateRequestedVideoResolution(VideoResolution.Res_720p);
+ return participant;
+ }
+
+ // The default SelectDevice request is 720p. Batch-mode players often reject that size
+ // ("could not find a supported resolution") even when a smaller mode works.
+ private static async Task SelectCameraThatDeliversFramesAsync(IStreamVideoClient client)
+ {
+ var manager = client.VideoDeviceManager;
+ foreach (var device in manager.EnumerateDevices())
+ {
+ foreach (var resolution in CandidateResolutions())
+ {
+ manager.SelectDevice(device, resolution, enable: true);
+ var texture = manager.GetSelectedDeviceWebCamTexture();
+ var (delivering, _) = await WaitForConditionAsync(
+ () => texture != null && texture.width > 16 && texture.height > 16,
+ timeoutMs: 2000);
+ if (!delivering)
+ {
+ continue;
+ }
+
+ Debug.Log("Publishing camera " + device.Name + " at " + texture.width + "x" + texture.height);
+ return;
+ }
+ }
+
+ Assert.Ignore("No camera delivered frames at a supported resolution in this player.");
+ }
+
+ // Batch-mode Play Mode connects and receives the track, but WebRTC.Update waits on
+ // WaitForEndOfFrame and no decoded texture is created. Ignore that environment limit.
+ // A texture that exists but is not assigned to the image is still a failure.
+ private static void AssertImageShowsTrackTexture(bool received, System.TimeSpan elapsed,
+ StreamVideoTrack streamTrack, UiImage image, string requirement)
+ {
+ if (received)
+ {
+ return;
+ }
+
+ var description = DescribeMediaTrack(streamTrack);
+ if (description.Contains("texture=null"))
+ {
+ Assert.Ignore("No decoded video texture arrived in this player, so the render target was not checked. " +
+ description + " Waited " + elapsed.TotalSeconds + "s.");
+ }
+
+ Assert.That(image.image, Is.Not.Null,
+ requirement + " Waited " + elapsed.TotalSeconds + "s. " + description);
+ }
+
+ private static string DescribeMediaTrack(StreamVideoTrack streamTrack)
+ {
+ var mediaTrack = typeof(StreamVideoTrack).BaseType
+ ?.GetProperty("Track", BindingFlags.Instance | BindingFlags.NonPublic)
+ ?.GetValue(streamTrack);
+ if (mediaTrack == null)
+ {
+ return "media track is null";
+ }
+
+ var mediaType = mediaTrack.GetType();
+ var texture = mediaType.GetProperty("Texture")?.GetValue(mediaTrack) as Texture;
+ var decoding = mediaType.GetProperty("Decoding")?.GetValue(mediaTrack);
+ var textureDescription = texture == null ? "null" : texture.width + "x" + texture.height;
+ return "decoding=" + decoding + ", texture=" + textureDescription;
+ }
+
+ private static VideoResolution[] CandidateResolutions()
+ {
+ return new[]
+ {
+ VideoResolution.Res_720p,
+ VideoResolution.Res_480p,
+ VideoResolution.Res_360p,
+ VideoResolution.Res_240p,
+ new VideoResolution(160, 120),
+ };
+ }
+ }
+}
+#endif
diff --git a/Packages/StreamVideo/Tests/Runtime/StreamVideoTrackTests.cs.meta b/Packages/StreamVideo/Tests/Runtime/StreamVideoTrackTests.cs.meta
new file mode 100644
index 00000000..96942c5f
--- /dev/null
+++ b/Packages/StreamVideo/Tests/Runtime/StreamVideoTrackTests.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: b8d4f2c05e3a4f7b9c1d2e3f4a5b6c7d
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant: