From 8530c26227f51ff3e3fa793916afd5bd11560c39 Mon Sep 17 00:00:00 2001 From: rootkiller6788 Date: Fri, 21 Aug 2026 18:21:56 +0800 Subject: [PATCH] Fix SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS not usable on OpenSL ES streams 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. --- src/opensles/AudioStreamOpenSLES.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/opensles/AudioStreamOpenSLES.cpp b/src/opensles/AudioStreamOpenSLES.cpp index 70f78b664..0df867cd2 100644 --- a/src/opensles/AudioStreamOpenSLES.cpp +++ b/src/opensles/AudioStreamOpenSLES.cpp @@ -28,10 +28,9 @@ using namespace oboe; AudioStreamOpenSLES::AudioStreamOpenSLES(const AudioStreamBuilder &builder) : AudioStreamBuffered(builder) { - // OpenSL ES does not support device IDs. So overwrite value from builder. - mDeviceIds.clear(); - // OpenSL ES does not support session IDs. So overwrite value from builder. - mSessionId = SessionId::None; + // Device ID and session ID are deliberately not reset here. They are read from the + // builder during open() to configure the stream, e.g. to select the performance mode, + // and to log unsupported attributes. They are reset in finishCommonOpen(). } static constexpr int32_t kHighLatencyBufferSizeMillis = 20; // typical Android period @@ -114,6 +113,13 @@ SLresult AudioStreamOpenSLES::finishCommonOpen(SLAndroidConfigurationItf configI // Spatialization Behavior is not supported for OpenSL ES. mSpatializationBehavior = SpatializationBehavior::Never; + // Device ID and session ID are not supported for OpenSL ES. They are only used during + // open() to configure the stream and to log unsupported attributes, so they are reset + // here once the stream has been configured. This also keeps getDeviceId() and + // getSessionId() from reporting attributes that OpenSL ES does not actually provide. + mDeviceIds.clear(); + mSessionId = SessionId::None; + SLresult result = registerBufferQueueCallback(); if (SL_RESULT_SUCCESS != result) { return result;