Skip to content

Can't set SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS #2392

Description

@asapha

Hi, I want to migrate an app using a custom implementation of OpenSL ES to oboe. It provides an option to use SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS.

There's some implicit logic in oboe that should allow us to do that by setting PerformanceMode to LowLatency and setting a SessionId:

case PerformanceMode::LowLatency:
openslMode = (getSessionId() == SessionId::None) ? SL_ANDROID_PERFORMANCE_LATENCY : SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS;
break;
case PerformanceMode::PowerSaving:

But it doesn't work because the session id is always set back to None at:

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;

Oboe version: main
App name used for testing: OboeTester

Steps to reproduce

Add logs in convertPerformanceMode:

SLuint32 AudioStreamOpenSLES::convertPerformanceMode(PerformanceMode oboeMode) const {
    SLuint32 openslMode = SL_ANDROID_PERFORMANCE_NONE;
    switch(oboeMode) {
        case PerformanceMode::None:
            openslMode =  SL_ANDROID_PERFORMANCE_NONE;
            break;
        case PerformanceMode::LowLatency:
            openslMode =  (getSessionId() == SessionId::None) ?  SL_ANDROID_PERFORMANCE_LATENCY : SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS;
            break;
        case PerformanceMode::PowerSaving:
            openslMode =  SL_ANDROID_PERFORMANCE_POWER_SAVING;
            break;
        default:
            break;
    }

    // -----
    LOGW("openslMode: %d, oboeMode: %d, sessionId %d", openslMode, oboeMode, getSessionId());
    // -----

    return openslMode;
}
  • Run Test output in OboeTester
  • Set OpenSL as the API and check Session Id

Expected behavior

The logs should print openslMode: 2 […]

Actual behavior

The logs print openslMode: 1, oboeMode: 12, sessionId -1

For reference

/** Audio performance values */
/*      No specific performance requirement. Allows HW and SW pre/post processing. */
#define SL_ANDROID_PERFORMANCE_NONE ((SLuint32) 0x00000000)
/*      Priority given to latency. No HW or software pre/post processing.
 *      This is the default if no performance mode is specified. */
#define SL_ANDROID_PERFORMANCE_LATENCY ((SLuint32) 0x00000001)
/*      Priority given to latency while still allowing HW pre and post processing. */
#define SL_ANDROID_PERFORMANCE_LATENCY_EFFECTS ((SLuint32) 0x00000002)
/*      Priority given to power saving if latency is not a concern.
 *      Allows HW and SW pre/post processing. */
#define SL_ANDROID_PERFORMANCE_POWER_SAVING ((SLuint32) 0x00000003)

Suggestion
I guess these

mDeviceIds.clear();
mSessionId = SessionId::None;

could be moved to

SLresult AudioStreamOpenSLES::finishCommonOpen(SLAndroidConfigurationItf configItf) {
  // here? <----

  // Setting privacy sensitive mode and allowed capture policy are not supported for OpenSL ES.
  mPrivacySensitiveMode = PrivacySensitiveMode::Unspecified;
  mAllowedCapturePolicy = AllowedCapturePolicy::Unspecified;

  // Spatialization Behavior is not supported for OpenSL ES.
  mSpatializationBehavior = SpatializationBehavior::Never;
 
  […]
}

As a side effect, AudioStreamOpenSLES::logUnsupportedAttributes would now show warnings about these properties.

edit: fixed suggestion

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions