Update sample code and documentation to use new data and error callback interfaces #1091
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR refactors the sample code away from using a single callback (
AudioStreamCallback
) for both data and error events to using the newAudioStreamDataCallback
andAudioStreamErrorCallback
classes.The only issue I faced was that the original
DefaultAudioStreamCallback
(used by hello-oboe and megadrone) would attempt to set thread affinity inside the data callback and would reset it inside the error callback through a single field:mIsThreadAffinitySet
.By separating the two callbacks the error callback no longer has access to this field. To solve this I added a
reset
method toDefaultDataCallback
which can be called to reset the data callback to its initial configuration (in this case, only the thread affinity).The responsibility for calling
reset
moves away from the error callback, which just callsrestart
on itsIRestartable
parent. It's up to the parent to callreset
on the data callback. Example here: https://github.com/google/oboe/compare/master...dturner:split_callbacks?expand=1#diff-300176f2b98467e0664a62ca6d40aa3f5c2401121741bcdea15a787557a6071bR133.