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

Support getDeviceIds API #2162

Open
flamme opened this issue Feb 14, 2025 · 3 comments
Open

Support getDeviceIds API #2162

flamme opened this issue Feb 14, 2025 · 3 comments
Assignees

Comments

@flamme
Copy link
Collaborator

flamme commented Feb 14, 2025

From API 36, aaudio added AAudioStream_getDeviceIds API, which can return multiple device IDs when there are multiple devices used. For instance, for ringtone and alarm on phone with peripheral devices connected. In that case, it should be also added to oboe.

@robertwu1
Copy link
Collaborator

There are a couple ways we can write the oboe API for OboeStream.getDevices(). Copying the AAudio API below for reference.

/**
 * Call this function after AAudioStreamBuilder_openStream().
 * An array of size 16 should generally be large enough to fit all device identifiers.
 *
 * Available since API level 36.
 *
 * @param stream reference provided by AAudioStreamBuilder_openStream().
 * @param ids reference to an array of ids.
 * @params numIds size allocated to the array of ids.
 *         The input should be the size of the ids array.
 *         The output will be the actual number of device ids.
 * @return {@link #AAUDIO_OK} or an error code.
 *         If numIds is null, return {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT}.
 *         If numIds is smaller than the number of device ids, return
 *         {@link #AAUDIO_ERROR_OUT_OF_RANGE}. The value of numIds will still be updated.
 *         Otherwise, if ids is null, return {@link #AAUDIO_ERROR_ILLEGAL_ARGUMENT}.
 */
AAUDIO_API aaudio_result_t AAudioStream_getDeviceIds(AAudioStream* _Nonnull stream,
        int32_t* _Nullable ids, int32_t* _Nullable numIds) __INTRODUCED_IN(36);
  1. We can use the exact same API in oboe with ids and numIds being the two parameters for an Oboe. It's look like oboe::Result getDeviceIds(int32_t* ids, int32_t* numIds)
  2. By querying AAudioStream_getDeviceIds with an empty ids array, we can get numIds. This way, we can call AAudioStream_getDeviceIds again with the arrays with a fixed size and it should just work. We can pack this into an std::vector. The function can look like vector<int32_t> getDeviceIds().
  3. We can do something similar like option 2 but pass by parameter. The function can be void getDeviceIds(vector<int32_t>& deviceIds).

I prefer option 2. @flamme @philburk what do you guys think?

@flamme
Copy link
Collaborator Author

flamme commented Feb 22, 2025

Option 2 looks good to me. One thing to be noted is that the device ids may be changed after querying getDeviceIds for the first time even though at this case the stream is connected.

@robertwu1
Copy link
Collaborator

Yea, if the size changes after querying it again, we can keep trying until the size is consistent

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants