Skip to content

Fix SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS not usable on OpenSL ES streams - #2411

Draft
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-opensles-latency-effects-session-id
Draft

Fix SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS not usable on OpenSL ES streams#2411
rootkiller6788 wants to merge 1 commit into
google:mainfrom
rootkiller6788:fix-opensles-latency-effects-session-id

Conversation

@rootkiller6788

Copy link
Copy Markdown

Fixes #2392.

Problem

OpenSL ES streams force mSessionId = SessionId::None and mDeviceIds.clear() in the constructor, before open() runs. This makes two code paths in AudioStreamOpenSLES unreachable:

  1. SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS can never be selected. convertPerformanceMode() maps PerformanceMode::LowLatency to SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS when getSessionId() != SessionId::None, but since the session ID was always reset to None in the constructor, the condition was always false and only SL_ANDROID_PERFORMANCE_LATENCY was ever used.

  2. logUnsupportedAttributes() never warns about device IDs or session IDs on OpenSL ES, because both had already been cleared before it ran.

Fix

Keep the builder's device ID and session ID during open(), then reset them in finishCommonOpen(), which runs after configurePerformanceMode() on both the output (AudioOutputStreamOpenSLES::open()) and input (AudioInputStreamOpenSLES::open()) paths. This:

  • lets convertPerformanceMode() reach the SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS branch, so apps can opt into HW pre/post processing on a low-latency OpenSL ES stream,
  • makes the unsupported-attribute warnings in logUnsupportedAttributes() functional,
  • preserves the existing post-open behavior where getDeviceId()/getSessionId() report no device/session (OpenSL ES does not actually provide them).

…reams

The OpenSL ES stream constructor cleared the device ID and session ID
requested by the app before AudioStreamOpenSLES::open() could use them.

Because mSessionId was always reset to SessionId::None in the constructor,
convertPerformanceMode() could never select
SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS for a LowLatency stream that also
requested a session ID, leaving that branch unreachable.

Similarly, logUnsupportedAttributes() never reported that device IDs and
session IDs are not supported on OpenSL ES, because both were cleared
before it ran.

Keep the builder's values during open() so the performance mode and the
unsupported-attribute warnings are computed correctly, then reset them in
finishCommonOpen(), which runs after the stream has been configured. This
also keeps getDeviceId() and getSessionId() from reporting attributes that
OpenSL ES does not actually provide.
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.

Can't set SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS

1 participant