Skip to content

feat: add oboe host API#1084

Open
acolombier wants to merge 4 commits intoPortAudio:masterfrom
acolombier:feat/add-oboe-host-api
Open

feat: add oboe host API#1084
acolombier wants to merge 4 commits intoPortAudio:masterfrom
acolombier:feat/add-oboe-host-api

Conversation

@acolombier
Copy link
Copy Markdown

This superseded #840

Note that this patch was previously on top of b0cc303 (ref) but will need to be re-tested on top of on master, once we have finish upgraded our vcpkg to the latest versions.

Comment on lines +1492 to +1506
// FIXME this is leading to a segfault - is the stream still active shortly after closing?
// Try to wait for state change in vain
// for (int i = 0; i < paOboe_numberOfBuffers; ++i) {
// if (paOboeStream->hasOutput)
// PaUtil_FreeMemory(paOboeStream->outputBuffers[i]);
// if (paOboeStream->hasInput)
// PaUtil_FreeMemory(paOboeStream->inputBuffers[i]);
// }

// if (paOboeStream->hasOutput)
// PaUtil_FreeMemory(paOboeStream->outputBuffers);
// if (paOboeStream->hasInput)
// PaUtil_FreeMemory(paOboeStream->inputBuffers);

// PaUtil_FreeMemory(paOboeStream);
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This remains a blocking issue - Perhaps @philburk you would have an idea of why this approach doesn't currently work and leads to a segfault?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@acolombier wrote:

is the stream still active shortly after closing?

Ideally no. But these were some system bugs that could cause this.
These have been fixed in the newer versions of Android. But if you are running on older versions of Android then
you may hit these problems. Luckily you can avoid the problems with some careful coding.

This Oboe page has lots of information on this issue:
https://github.com/google/oboe/wiki/TechNote_HowToAvoidCrashes

There is also this related issue:
https://github.com/google/oboe/wiki/CrashUAF_ObtainReleaseBuffer

@philburk
Copy link
Copy Markdown
Collaborator

@hopefulGiupplo and @acolombier - thank you both for working on this.

We are getting close to finishing 19.8. So I can start looking at this PR in more detail.
Hopefully we can get it merged in 19.9

@philburk
Copy link
Copy Markdown
Collaborator

@acolombier - Were any changes made to the code between the end of #840 and the squashing into the 1st commit of this PR?

@acolombier
Copy link
Copy Markdown
Author

Hi @philburk , yes, here is the summary

  • Refactored the CMake rule to allow more flexibility with existing oboe library (instead of expecting a local clone)
  • Refactor oboe-specific port audio methods to allow native device detection and request specific modes (performance, media type, exclusivity, ...) for each open request (instead of global value to drive those
  • Remove any code style change (space to tab conversion mainly)
    Let me know if you would prefer me to keep the initial commit history.

Copy link
Copy Markdown
Collaborator

@philburk philburk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some general thoughts...

Oboe will support almost any configuration that you request. So you may not need to probe for them. Just advertise, for example, mono, stereo, {8000, 16000, 32000, 44100, 48000}, {float, int16, int24}

You can decide whether to use PerformanceMode=LowLatency if the suggested latency from PortAudio is < 80(?) msec.

To avoid crashes, do not delete anything right after close.
Just hang onto the memory in a unique_ptr and only free it if you allocate a new one later.

If the app specifies a sample rate, use the Oboe sample rate converter.
You will get much better latency.
builder->setSampleRateConversionQuality(oboe::SampleRateConversionQuality::Medium)


4) Build PaOboe (you can use "build_all_PaOboe.sh").
5) Don't forget to add liboboe.so and libportaudio.so in your jniLibs folder.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have instructions for adding this to an Android Studio project.
I think most Android developers are using that.

It might help to add some build.gradle files, which might get imported into Android Studio automatically.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, I don't use Android Studio and don't have any experience with it - I use PortAudio+oboe in Qt, using a CMake setup.
WOuld you be able to share some basic build.gradle?

* @param direction The device direction
* @param channelCounts The device channel count
* @param sampleRate The device default sampleRate
*/
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like we would also need a deviceId so that we can select the device using builder.setDeviceId(id). Maybe I am missing something.

@philburk
Copy link
Copy Markdown
Collaborator

Remove any code style change (space to tab conversion mainly)

Did you convert spaces to tabs OR tabs to spaces?! I hope the latter.

Let me know if you would prefer me to keep the initial commit history.

That is up to you. I don't know how hard it would be. And we would lose this partial review if we started a new PR.
I am OK to continue with the PR as is. But you will not get credit for your changes.

I am fine either way. I can just focus on the current state of the code and move forward.

@acolombier acolombier force-pushed the feat/add-oboe-host-api branch from 3002310 to 2e3aad8 Compare November 26, 2025 15:52
@acolombier
Copy link
Copy Markdown
Author

Thanks for all this input and the initial review. I have pushed a new head as #, with 3 commits:

Let me know if this is better to review, I can revert otherwise.

Did you convert spaces to tabs OR tabs to spaces?! I hope the latter.

I just reverted to what was used, in order to limit the diff - initial version add 310 line changes, including many that were unrelated to oboe and seem to be random style updates (capitalisation number of spaces/tabs, ..). Regarding the used style, I try to imitate as much what I could see in other places of PortAudio, but feel free to point inconsistency and I will update.

I will start addressing your feedback asap!

@acolombier
Copy link
Copy Markdown
Author

I have pushed the first batch of changes, including some DRY cleanup and better concurrency/allocation handling.
I have changed the stream close free to happen in the destructor and leveraging a shared_ptr to delay the freeing of resources.

I still need to test that!

@acolombier acolombier force-pushed the feat/add-oboe-host-api branch from 3671f42 to 8508b45 Compare December 10, 2025 17:45
@acolombier
Copy link
Copy Markdown
Author

Tested and could not reproduce any crash!
Though I couldn't confirm if it also gets deallocated correctly.

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.

3 participants