-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Replace the current audio driver with Oboe on Android #86776
base: master
Are you sure you want to change the base?
Conversation
You will also need to add the library to the list in |
195df38
to
4c46c72
Compare
c1d2804
to
57434a1
Compare
platform/android/audio_driver_oboe.h
Outdated
std::shared_ptr<InputErrorCallback> input_error_callback; | ||
|
||
std::shared_ptr<oboe::AudioStreamDataCallback> audio_output_callback; | ||
std::shared_ptr<oboe::AudioStreamDataCallback> audio_input_callback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't use the standard library normally, see here, would need to be discussed here depending on the library using it, no other engine component uses this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I know. Oboe uses shared_ptr and regular pointers, but methods accepting regular pointers are marked as deprecated, when I think about it again, it probably will be fine to use regular pointers, it just might create problems when closing the app (Through is this important?)
This comment was marked as outdated.
This comment was marked as outdated.
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked when shred_ptr was added, it was in the google/oboe#821 to fix an issue with the data race, without shared_ptr the data race will still occur, so I think shared_ptr should stay
Seems to be a problem with my device. Opened an issue on oboe repository. |
7026dae
to
482d1ff
Compare
9c51ce1
to
a69115a
Compare
} | ||
|
||
jclass cCharSequence = env->GetObjectClass(source); | ||
jmethodID toString = env->GetMethodID(cCharSequence, "toString", "()Ljava/lang/String;"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Camel Case to be consistent with "jni_utils.cpp", e.g.
godot/platform/android/jni_utils.cpp
Lines 198 to 199 in 5d08c26
jmethodID getName = env->GetMethodID(cclass, "getName", "()Ljava/lang/String;"); | |
jstring clsName = (jstring)env->CallObjectMethod(cls, getName); |
But that code is pretty old, maybe that code should be more consistent and not the other way around.
@@ -336,12 +337,14 @@ class Godot(private val context: Context) : SensorEventListener { | |||
} | |||
|
|||
if (nativeLayerInitializeCompleted && !nativeLayerSetupCompleted) { | |||
nativeLayerSetupCompleted = GodotLib.setup(commandLine.toTypedArray(), tts) | |||
var audioManager: AudioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager | |||
nativeLayerSetupCompleted = GodotLib.setup(commandLine.toTypedArray(), tts, audioManager) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context.getSystemService(Context.AUDIO_SERVICE)
can be called on the C++ side, but the code would be harder to understand and longer, this is just here for readability. Will change if needed
82f0379
to
30de669
Compare
I think the PR is ready. There are just a few issues that are worth addressing:
Issues above should all be fine when not using set_device, I assume that the default device picked by Android always works, so maybe it would be better to disable it for now? And some theoretically possible feature, that I could do in a follow-up, is very limited set_device for OpenSL. Also, #88628 could be implemented for Android too. For the same reasons as the ones why it is implemented for macOS. EDIT: |
@@ -653,7 +653,7 @@ | |||
<param index="0" name="name" type="String" /> | |||
<description> | |||
Requests permission from the OS for the given [param name]. Returns [code]true[/code] if the permission has been successfully granted. | |||
[b]Note:[/b] This method is currently only implemented on Android, to specifically request permission for [code]"RECORD_AUDIO"[/code] by [code]AudioDriverOpenSL[/code]. | |||
[b]Note:[/b] This method is currently only implemented on Android and is used by [code]AudioDriverOboe[/code]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the specific permissions and what they are for should be put somewhere else? It would feel better if they were in AudioServer docs somewhere, where the user would be expected to look first for any audio specific questions and issues. This PR also adds one more permission "MODIFY_AUDIO_SETTINGS" for SCO support on older devices, but I'm out of ideas where to put it.
@@ -63,6 +63,7 @@ public final class PermissionsUtil { | |||
public static final int REQUEST_RECORD_AUDIO_PERMISSION = 1; | |||
public static final int REQUEST_CAMERA_PERMISSION = 2; | |||
public static final int REQUEST_VIBRATE_PERMISSION = 3; | |||
public static final int REQUEST_MODIFY_AUDIO_SETTINGS_PERMISSION = 4; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it's unused, but added for consistency
@@ -62,6 +62,7 @@ class AudioDriver { | |||
unsigned int input_size = 0; | |||
|
|||
void audio_server_process(int p_frames, int32_t *p_buffer, bool p_update_mix_time = true); | |||
void audio_server_init_channels_and_buffers(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exposed it, since Oboe doesn't recommend to allocate memory in callbacks, which would happen through audio_server_process if device changed
thirdparty/README.md
Outdated
## oboe | ||
|
||
- Upstream: https://github.com/google/oboe | ||
- Version: 1.8.2 (16d72c89be9eb8a7d617a7be531a31dba3db74f1, 2024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Put version 1.8.2, although it's not released yet, just to have this fix: google/oboe#1968. Without this fix, on some devices, the audio would be silent or with a lot of glitches since the code checking for it was never called
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed version from "1.8.2" to "git", but the point still stands
I would like to help testing, but I have no knowledge abou C++. |
Thanks for replying! Here are instructions on how to build this PR and how to export with it: |
I misinterpreted Android docs, now output and input streams do not depend on each other. This introduced more bugs when setting output device, while input stream uses SCO. Have no ideas what the issue is, but will work on it. Default device still changes, but I don't think that's a big issue.
Fixed it, but input stream that uses SCO is very unstable due to #86428. |
May I ask which version this is likely to be supported on? |
Can't really guarantee anything here, I'm not part of Godot's team, I just work on it when I can (right now I don't have time). There are still some issues and I want to refactor the code (I'll mark it as a draft, kinda forgot to do it before😅). I am also more focused on #90013 for now, which would simplify the code here and I think it should be merged first. Not many users request Oboe and there's a lot of code to go through when reviewing, so this PR is probably not a priority for members. As far as I'm aware there's no consensus on using Oboe in the first place (I plan to write a comment on Oboe's proposal page that would go through what are the advantages and disadvantages of using Oboe) (should probably mention that no one on the team seems to be against using Oboe though). I think there's currently only one member of the audio team and that's reduz, who also has other stuff to do, so the reviewing process for this PR may take a long time. Because of all of this, I don't think it should be expected to be part of Godot any time soon if it will be. |
Closes: godot-proposals#2358
Sample project 5
TODO:
Get the correct number of frames per callback and for output.Went with the different idea.Get the correct number of frames per callback for input.Went with the different idea.Properly update device list after connecting or disconnecting devices.Went with the different idea.Known Issues:
Couldn't reproduce it on my phone.(My phone supports int32_t format, I just didn't know). Tested on the virtual machine.Audio not working on the physical device.An issue with my phone.See the comment for new TODO/TODO after merge list.