Skip to content

Commit

Permalink
feat: Upgrade WebRTC package 2.4.0-exp.5 (Unity-Technologies#630)
Browse files Browse the repository at this point in the history
* fix flip streaming using ScreenStreamSender on Opengl

* fix compile error

* fix error

* update depend webrtc package version

* update manifest

* add package for ar sample

* add comment in screen stream sender

* add arfoundation

* update setting for testing with vulkan api

* exclude unit testing on andoid with Vulkan API for workaround

* fix test

* workaround: exclude standalone app testing with il2cpp on maoOS(Silicon)

Co-authored-by: kazuki <karasusan@gmail.com>
  • Loading branch information
kannan-xiao4 and karasusan committed Feb 7, 2022
1 parent 3729e8a commit e169e09
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 20 deletions.
13 changes: 5 additions & 8 deletions Runtime/Scripts/AudioStreamReceiver.cs
Expand Up @@ -39,20 +39,17 @@ protected virtual void Start()

private void StartedStream(string connectionId)
{
var audioTrack = Track as AudioStreamTrack;
audioTrack.OnAudioReceived += OnAudioReceived;
if (Track is AudioStreamTrack audioTrack)
{
m_renderer = audioTrack.Renderer.clip;
OnUpdateReceiveAudioClip?.Invoke(m_renderer);
}
}

private void StoppedStream(string connectionId)
{
m_renderer = null;
OnUpdateReceiveAudioClip?.Invoke(null);
}

private void OnAudioReceived(AudioClip clip)
{
m_renderer = clip;
OnUpdateReceiveAudioClip?.Invoke(clip);
}
}
}
9 changes: 8 additions & 1 deletion Runtime/Scripts/ScreenStreamSender.cs
Expand Up @@ -4,6 +4,7 @@
using Unity.WebRTC;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Rendering;

namespace Unity.RenderStreaming
{
Expand Down Expand Up @@ -90,7 +91,13 @@ protected override MediaStreamTrack CreateTrack()
m_sendTexture = rt;
}

return new VideoStreamTrack(rt.GetNativeTexturePtr(), rt.width, rt.height, rt.graphicsFormat);
// The texture obtained by ScreenCapture.CaptureScreenshotIntoRenderTexture is different between OpenGL and other Graphics APIs.
// In OpenGL, we got a texture that is not inverted, so need flip when sending.
var isOpenGl = SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLCore ||
SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES2 ||
SystemInfo.graphicsDeviceType == GraphicsDeviceType.OpenGLES3;

return new VideoStreamTrack(rt, isOpenGl);
}

IEnumerator RecordScreenFrame()
Expand Down
23 changes: 14 additions & 9 deletions Runtime/Scripts/VideoStreamReceiver.cs
Expand Up @@ -4,33 +4,33 @@
namespace Unity.RenderStreaming
{
/// <summary>
///
///
/// </summary>
public class VideoStreamReceiver : StreamReceiverBase
{
/// <summary>
///
///
/// </summary>
/// <param name="receiveTexture"></param>
public delegate void OnUpdateReceiveTextureHandler(Texture receiveTexture);

/// <summary>
///
///
/// </summary>
public OnUpdateReceiveTextureHandler OnUpdateReceiveTexture;

/// <summary>
///
///
/// </summary>
public override TrackKind Kind { get { return TrackKind.Video; } }

/// <summary>
///
///
/// </summary>
[SerializeField] private Vector2Int streamingSize = new Vector2Int(1280, 720);

/// <summary>
///
///
/// </summary>
public Texture ReceiveTexture => m_receiveTexture;

Expand All @@ -44,9 +44,14 @@ protected virtual void Start()

private void StartedStream(string connectionId)
{
var videoTrack = Track as VideoStreamTrack;
m_receiveTexture = videoTrack?.InitializeReceiver(streamingSize.x, streamingSize.y);
OnUpdateReceiveTexture?.Invoke(m_receiveTexture);
if (Track is VideoStreamTrack videoTrack)
{
videoTrack.OnVideoReceived += texture =>
{
m_receiveTexture = texture;
OnUpdateReceiveTexture?.Invoke(m_receiveTexture);
};
}
}

private void StoppedStream(string connectionId)
Expand Down
7 changes: 6 additions & 1 deletion Tests/Runtime/InputSystem/InputRemotingTest.cs
Expand Up @@ -117,6 +117,9 @@ public IEnumerator UnitySetUp()

// If target1 processes resent Offer from target2, target1 is not stable.
Assert.That(_target2.IsStable(connectionId), Is.True);

yield return new WaitUntil(() => _channel1 != null);
Assert.That(_channel1.ReadyState, Is.EqualTo(RTCDataChannelState.Open));
}

[UnityTearDown]
Expand All @@ -133,7 +136,8 @@ public IEnumerator UnityTearDown()

_channel1.Dispose();
_channel2.Dispose();

_channel1 = null;
_channel2 = null;
_test.component.StopAllCoroutines();
_target1.Dispose();
_target2.Dispose();
Expand All @@ -157,6 +161,7 @@ public void Sender()
senderInput.StartSending();
senderInput.StopSending();
senderDisposer.Dispose();
sender.Dispose();
}

[Test]
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"unity": "2019.4",
"description": "This is a package for using Unity Render Streaming technology. It contains two samples to use the technology.",
"dependencies": {
"com.unity.webrtc": "2.4.0-exp.4",
"com.unity.webrtc": "2.4.0-exp.5",
"com.unity.inputsystem": "1.0.2"
},
"samples": [
Expand Down

0 comments on commit e169e09

Please sign in to comment.