Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update AndroidHelper.cs for new Unity API #186

Closed
wants to merge 1 commit into from

Conversation

Hextaku
Copy link

@Hextaku Hextaku commented Jul 4, 2023

Set multicast lock without calling deprecated/removed Unity APIs

This should resolve #167

Set multicast lock without calling deprecated/removed Unity APIs
@keijiro keijiro self-assigned this Jul 5, 2023
@huyqle3
Copy link

huyqle3 commented Jul 17, 2023

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.

image

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?

@huyqle3
Copy link

huyqle3 commented Jul 17, 2023

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.

@huyqle3
Copy link

huyqle3 commented Jul 17, 2023

Screenshot on Android Phone with No Sources available to select:

screen-shot-ndi

Package Manager In Project:

image

@Hextaku
Copy link
Author

Hextaku commented Jul 17, 2023

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.

@huyqle3
Copy link

huyqle3 commented Jul 17, 2023

Thanks for the message update and help, Hextaku!

Yes, I also added the Custom Main Manifest in Unity's PublishingSettings.

image (2)

With the permission in my manifest with the "CHANGE_WIFI_MULTICAST_STATE" section.

multicast-state-permission

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.

@huyqle3
Copy link

huyqle3 commented Jul 18, 2023

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

image

image

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

image

image

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.

image

@huyqle3
Copy link

huyqle3 commented Jul 18, 2023

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:

  1. Turns on the NDIReceiver 5 seconds later in a coroutine
  2. Turns on the NDISender 5 seconds later (just sends the sample Alpha Texture)
  3. SourceSelector on the Canvas is constantly updating the Dropdown menu with any new NDISender Sources

image

@huyqle3
Copy link

huyqle3 commented Jul 18, 2023

Samsung S21 5G

Unity 2022.3.3f1

Screen_Recording_20230718_030316_KlakNDI.URP.mp4

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

Screen_Recording_20230718_030355_KlakNDI.URP.2.mp4

On Unity 2021 LTS, there is no freeze, and it can send the local Alpha texture.

@huyqle3
Copy link

huyqle3 commented Jul 18, 2023

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.

@huyqle3
Copy link

huyqle3 commented Jul 19, 2023

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.

image

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.

@huyqle3
Copy link

huyqle3 commented Jul 19, 2023

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.

@hybridherbst
Copy link

hybridherbst commented Aug 8, 2023

@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!

@bvk0
Copy link

bvk0 commented Nov 18, 2023

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)

@daangijzen
Copy link

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)

@bvk0
Copy link

bvk0 commented Dec 4, 2023

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).

@daangijzen
Copy link

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!

@FireDragonGameStudio
Copy link

@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

@daangijzen
Copy link

@FireDragonGameStudio I did, I made a silly mistake. I forgot to install the NDI SDK 😅 maybe you have the same problem.

@FireDragonGameStudio
Copy link

@daangijzen Ah ok, the docs stated, that there is no need to install the NDI SDK Oo
I'll try it again, after installing.
image

@daangijzen
Copy link

daangijzen commented Dec 15, 2023

@FireDragonGameStudio That may be true, but the Kejiro’s page for this plugin does state that it might be useful 😉

IMG_4640

@FireDragonGameStudio
Copy link

@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 :/

@FireDragonGameStudio
Copy link

I just realised that there is a PR for Android lvl >= 31. That may be the issue here!

@daangijzen
Copy link

@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?

@huyqle3
Copy link

huyqle3 commented Dec 31, 2023

@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.

@keijiro
Copy link
Owner

keijiro commented Jun 12, 2024

This issue was resolved in the latest version (2.1.1).

@keijiro keijiro closed this Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Android Building Error
7 participants