KlakNDI
KlakNDI copied to clipboard
Update AndroidHelper.cs for new Unity API
Set multicast lock without calling deprecated/removed Unity APIs
This should resolve #167
I was trying this pull request with Unity Version 2022.3.2f1 with keijiro's example Test scene, but I was not able to send any sources from his Test scene. The dropdown menu from Test scene did not populate with any of his sender sources, so I was not able to receive any of those sources.
There were no errors on adb logcat -s Unity
However, the startup in Unity 2022.3.2f1 for the sample scene was a little slow for 5 seconds.
On Unity Version 2021 with the same files did work, so there's something that I'm missing for Unity 2022.3.2f1
Do you have any advice?
The Adb Logcat logs for the above were just:
07-17 04:39:53.824 18979 19013 I Unity : MemoryManager: Using 'Dynamic Heap' A
llocator.
07-17 04:39:53.890 18979 19013 I Unity : SystemInfo CPU = ARM64 FP ASIMD AES,
Cores = 8, Memory = 7361mb
07-17 04:39:53.890 18979 19013 I Unity : SystemInfo ARM big.LITTLE configurati
on: 4 big (mask: 0xf0), 4 little (mask: 0xf)
07-17 04:39:53.890 18979 19013 I Unity : ApplicationInfo com.DefaultCompany.Kl
akNDIURP version 0.1
07-17 04:39:53.890 18979 19013 I Unity : Built from '2022.3/staging' branch, V
ersion '2022.3.2f1 (d74737c6db50)', Build type 'Release', Scripting Backend 'il2
cpp', CPU 'arm64-v8a', Stripping 'Enabled'
07-17 04:39:54.114 18979 19013 I Unity : Company Name: DefaultCompany
07-17 04:39:54.114 18979 19013 I Unity : Product Name: KlakNDI URP
The Dropdown menu had no sources available when I clicked on the Dropdown.
Screenshot on Android Phone with No Sources available to select:
Package Manager In Project:
Have you added the multicast permission to your android manifest? This becomes necessary due to this no longer being part of the Unity API, so they don't automatically add it them self. If not, it should be "android.permission.CHANGE_WIFI_MULTICAST_STATE".
I can confirm this working for Unity 2022.3.3f1. But I have to admit, I did not test it with the example test scene due to the project I wrote this quick fix for being an VR Project targeted for the Vive XR Elite platform and I only tested it working there. But I see no reason why it shouldn't work on other Android platforms.
Thanks for the message update and help, Hextaku!
Yes, I also added the Custom Main Manifest in Unity's PublishingSettings.
With the permission in my manifest with the "CHANGE_WIFI_MULTICAST_STATE" section.
I'm going to see if maybe, I'll just try to add all the permissions available on the APK or something or more permissions. Maybe, I'm missing something.
I'm currently using a Samsung S21 5G to test kejiro's Test scene in Unity 2022.3.2f1.
I tried turning on every Internet permission and explicitly requesting them with Unity Runtime Permissions, and trying to create a minimalist custom scene and turning on the sender and receiver later in the scene runtime, but it looks like I'm stuck, trying to make NDI work for Unity 2022.3.3f1 on a Samsung S21 5G Android phone.
Unity 2021 LTS seems to always work.
Taking a look at the Unity versions in Development Build mode with a custom scene, just sending an Alpha Texture:
Unity 2021
Looking at the profiler for Unity 2021. In the app, I can select the source, and the NDI Receiver
here is receiving the local image, spending 1 ms.
Unity 2022.3.3f1
On Unity 2022.3.3f1, it seems like NDI Receiver
is not doing anything even if I explicitly use the source sender name that I know works for Unity 2021. It can't locally receive the NDI image for some reason.
Weird thing
I notice that once I enable any NDISender
on Unity 2022.3.3f1, there was a weird delay to turn on and freezes the app for like 3 seconds on Unity 2022.3.3f1.
On Unity 2021, no app freeze occurs when turning on or enabling a NDISender
gameObject.
Unity 2022.3.3f1 Test Failing
The Android Manifest permissions:
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.unity3d.player"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
<application>
<activity android:name="com.unity3d.player.UnityPlayerActivity"
android:theme="@style/UnityThemeSelector">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="unityplayer.UnityActivity" android:value="true" />
</activity>
</application>
</manifest>
Scene Test
A simple scene where it:
- Turns on the
NDIReceiver
5 seconds later in a coroutine - Turns on the
NDISender
5 seconds later (just sends the sample Alpha Texture) -
SourceSelector
on the Canvas is constantly updating the Dropdown menu with any newNDISender Sources
Samsung S21 5G
Unity 2022.3.3f1
https://github.com/keijiro/KlakNDI/assets/5465701/06dec636-d5cd-4c7c-833a-1bdb7b545522
When the coroutine turns on the NDISender
gameObject around 10-15 seconds in the app, there's this weird freeze that prevents interaction for like 3 seconds, so there's something weird happening with NDISender
on Unity 2022.3.3f1
No Unity errors though.
Unity 2021.3.10f1
https://github.com/keijiro/KlakNDI/assets/5465701/a1a7e54b-8e6f-4f1a-b688-4ff5d9dff372
On Unity 2021 LTS
, there is no freeze, and it can send the local Alpha texture.
Hey @Hextaku! I figured out a problem on my side!
You're right it does work! I tried on a different Samsung 21 Ultra 5G Android phone.
There's something weird going on with my personal Samsung S21 5G Phone.
For some reason, that personal phone doesn't work, but if I use a different phone, your change worked.
I thought that maybe, I have some weird network settings that is preventing the sender.
A note: After testing on Magic Leap 2, there is 1 more thing that Unity 2022 LTS users probably have to install, which is the Unity Transport Package
because it no longer comes by default in Unity.
I think that when I tried on Magic Leap 2 without this package, things did not work, but I am not 100% sure to be honest.
Also in this pull request, we might want to write down somewhere that the user probably also has to add this permission explicitly into their Android Manifest
file for Unity 2022 LTS
:
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
I think that this is the only must-have permission, but I am not 100% sure to be honest.
@keijiro would be cool if this could be merged + the readme updated with the new required Android permission. Currently KlakNDI doesn't build on 2022 LTS and 2023 on the Android build target. Thanks!
I can confirm this works on Unity 2022.3.11f1
streaming an NDI stream from Touchdesigner on Windows 11 to an app on the Quest 2. Thanks for the edit!
Steps:
- Edit
AndroidHelper.cs
with changes from this commit - Add multicast permission in
Android Manifest
file as listed two comments up
(For future users, building must be done through Unity's standard "Build Settings > Build" option, not through Oculus' OVR build tools. I got a "missing *.dll" exception for the latter)
I can confirm this works on
Unity 2022.3.11f1
streaming an NDI stream from Touchdesigner on Windows 11 to an app on the Quest 2. Thanks for the edit!Steps:
- Edit
AndroidHelper.cs
with changes from this commit- Add multicast permission in
Android Manifest
file as listed two comments up(For future users, building must be done through Unity's standard "Build Settings > Build" option, not through Oculus' OVR build tools. I got a "missing *.dll" exception for the latter)
@bvk0 Did you do anything else to send NDI?
Cause it does help with the build error I had, but it seems that I don't send any NDI from my Quest 3 now.
(Running 2022.3.10, changed AndroidHelper.cs, and added the line to the Mainifest)
No, I did nothing else.
However, you seem to stream NDI from quest outwards (I only streamed from PC to quest), and you seem to use a Quest 3 (I used a Quest 2).
Whelp. Then that wont work for me 😭
I'll give up for now, hopefully Android build support for receiving is fixed and issue #167 will no longer be a thing haha.
Thanks for your quick response tho!
@huyqle3 have you ever be able to track down, why your personal phone wasn't working? Applied all changes, but my Pixel 8 Pro refuses to receive the NDI data sent by my notebook, while being on the same 5G Wifi as my notebook. The quad where the stream should be shown remains blank... On my notebook and with a windows build, everything is working as expected. I'm using Unity 2022.3.15.
I'm on Android 14, maybe that is an issue?
br, Max
@FireDragonGameStudio I did, I made a silly mistake. I forgot to install the NDI SDK 😅 maybe you have the same problem.
@daangijzen Ah ok, the docs stated, that there is no need to install the NDI SDK Oo
I'll try it again, after installing.
@FireDragonGameStudio That may be true, but the Kejiro’s page for this plugin does state that it might be useful 😉
@daangijzen sry, I'm confused Oo even after the SDK install, my Android phone is neither found as sender nor can I receive smth on my lokal Wifi. Are there any extra steps, like linking to the SDK path or something?
sry for all those dumb questions :/
I just realised that there is a PR for Android lvl >= 31. That may be the issue here!
@daangijzen sry, I'm confused Oo even after the SDK install, my Android phone is neither found as sender nor can I receive smth on my lokal Wifi. Are there any extra steps, like linking to the SDK path or something?
sry for all those dumb questions :/
Hmmm… I do not know that. 🤔 maybe someone else knows?
@FireDragonGameStudio To respond to this thread very late, no, I never knew why KlakNDI would not work on my personal Android phone device. It's a Samsung S21 5G, so it's not that old. Maybe, I have specific wifi or network settings on that phone that made it not compatible with KlakNDI.
This issue was resolved in the latest version (2.1.1).