-
Notifications
You must be signed in to change notification settings - Fork 22
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
How to handle stream disconnect #32
Comments
@SupernaviX Course, this library still far from perfection. The stream builder takes ownership of callback but current API lacks any ways to get it back when stream drops. Have you any better ideas? |
@katyo I think that I found a way to accomplish this with the current interface in my project. Sample usage here. I wrote a I think that "turn a stream back into a builder" (or maybe just "clone a stream") could be helpful, but also hard to do. I'm realizing now that the stream really does need to own its callback, because otherwise you have to either deal with mutexes in a critical path or multiple streams possibly messing with the callback at once. And you need a thread-safe "global" reference to the "current" stream somewhere, which gets updated inside of |
@SupernaviX looks interesting as as compromise solution. |
I'd like to add that I'd love a way to get the callback back when closing the stream. At risk of giving too much detail: I'm writing a MIDI file player, so my callback calculates the next chunk of sound data, stepping through the MIDI file (stored in memory) as it does so. So, the callback needs a mutable reference (or ownership) to:
All this happens on the stream's callback thread. However, users can also pause playback at any time (closing the stream), and also skip ahead in the file while the stream is running. These actions come from a different thread. I'm fine with a small delay on these actions, so my plan was to just send messages to the callback thread which it can act on them when it gets a chance. This way there's only one thread mutating my sequencer/synthesizer, and I don't have to worry about locks or blocking. For pausing playback, it depends on whether the callback had a mutable reference to the sequencer/synthesizer or ownership: in the former case, this doesn't really work without hacking (e.g. Sorry if that wasn't particularly clear. Basically for performance reasons I want the callback thread to directly access some resources, but for usability reasons I want those resources to outlive the thread (e.g. in the case of pause/play) and be mutable (albeit with small delay) from outside the thread. |
Hi!
I've been using oboe-rs in my program, and for phones > 8.0 (i.e. anything that uses AAudio) it seems to be a frequent source of crashes. I finally tested the aaudio paths on my own phone (8.0, the first buggy version that can use AAudio) and it looks like
(If it makes a difference, my source code is here).
Reading the AAudio docs, it looks like I'm supposed to cope with this case by (opening a new thread and) creating a brand new audio stream. My audio callback owns a buffer which another thread writes to, so I can't easily construct a new callback; I think I need to create a new stream which reuses the callback from the disconnected one. My problem is, these rust bindings are getting in the way of this.
AudioStreamBuilder
, because the builder takes ownership of it.AudioStreamBuilder
to make a new stream, becauseAudioStreamBuilderAsync.open_stream
takesself
instead of&self
and consumes the builder.I think that both of these are issues with the rust typings.
The documentation for set_callback says that the API intentionally doesn't take a smart pointer, but is not meant to own the callback:
The AAudio docs say that
Do you have any guidance for how to handle this case? I can't find any sample usages of oboe-rs that deal with disconnected streams or non-trivial callbacks, and I can't follow the C++ examples because of these typings. I'm an amateur in programming audio, rust, and Android, so I suspect I'm doing something wrong, but can't find any good examples to copy from.
The text was updated successfully, but these errors were encountered: