Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9237952c authored by Phil Burk's avatar Phil Burk Committed by android-build-merger
Browse files

aaudio: update stream performance mode after open

am: 30a70777

Change-Id: Ie3d88947ff8d13f962630baa7d7525e54597dd3e
parents 4abacfc2 30a70777
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -82,15 +82,17 @@ public:
        result = AAudio_createStreamBuilder(&mBuilder);
        if (result != AAUDIO_OK) return result;

        //AAudioStreamBuilder_setSampleRate(mBuilder, 44100);
        AAudioStreamBuilder_setSharingMode(mBuilder, mRequestedSharingMode);
        AAudioStreamBuilder_setDataCallback(mBuilder, dataProc, userContext);
        AAudioStreamBuilder_setFormat(mBuilder, AAUDIO_FORMAT_PCM_FLOAT);
        //AAudioStreamBuilder_setFramesPerDataCallback(mBuilder, CALLBACK_SIZE_FRAMES);
        // AAudioStreamBuilder_setBufferCapacityInFrames(mBuilder, 48 * 8);
        AAudioStreamBuilder_setBufferCapacityInFrames(mBuilder, 48 * 8);

        AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_NONE);
        //AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_LOW_LATENCY);
        //AAudioStreamBuilder_setPerformanceMode(mBuilder, AAUDIO_PERFORMANCE_MODE_POWER_SAVING);
        //aaudio_performance_mode_t perfMode = AAUDIO_PERFORMANCE_MODE_NONE;
        aaudio_performance_mode_t perfMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY;
        //aaudio_performance_mode_t perfMode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING;
        AAudioStreamBuilder_setPerformanceMode(mBuilder, perfMode);

        // Open an AAudioStream using the Builder.
        result = AAudioStreamBuilder_openStream(mBuilder, &mStream);
@@ -102,6 +104,8 @@ public:
               AAudioStream_getBufferSizeInFrames(mStream));
        printf("AAudioStream_getBufferCapacityInFrames() = %d\n",
               AAudioStream_getBufferCapacityInFrames(mStream));
        printf("AAudioStream_getPerformanceMode() = %d, requested %d\n",
               AAudioStream_getPerformanceMode(mStream), perfMode);

     finish1:
        AAudioStreamBuilder_delete(mBuilder);
+22 −1
Original line number Diff line number Diff line
@@ -69,7 +69,8 @@ aaudio_result_t AudioStreamTrack::open(const AudioStreamBuilder& builder)
            samplesPerFrame, channelMask);

    audio_output_flags_t flags = AUDIO_OUTPUT_FLAG_NONE;
    switch(getPerformanceMode()) {
    aaudio_performance_mode_t perfMode = getPerformanceMode();
    switch(perfMode) {
        case AAUDIO_PERFORMANCE_MODE_LOW_LATENCY:
            // Bypass the normal mixer and go straight to the FAST mixer.
            flags = (audio_output_flags_t)(AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_RAW);
@@ -160,6 +161,26 @@ aaudio_result_t AudioStreamTrack::open(const AudioStreamBuilder& builder)
    setState(AAUDIO_STREAM_STATE_OPEN);
    setDeviceId(mAudioTrack->getRoutedDeviceId());

    // Update performance mode based on the actual stream.
    // For example, if the sample rate is not allowed then you won't get a FAST track.
    audio_output_flags_t actualFlags = mAudioTrack->getFlags();
    aaudio_performance_mode_t actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_NONE;
    if ((actualFlags & (AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_RAW))
        == (AUDIO_OUTPUT_FLAG_FAST | AUDIO_OUTPUT_FLAG_RAW)) {
        actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_LOW_LATENCY;

    } else if ((actualFlags & AUDIO_OUTPUT_FLAG_DEEP_BUFFER) != 0) {
        actualPerformanceMode = AAUDIO_PERFORMANCE_MODE_POWER_SAVING;
    }
    setPerformanceMode(actualPerformanceMode);
    // Log warning if we did not get what we asked for.
    ALOGW_IF(actualFlags != flags,
             "AudioStreamTrack::open() flags changed from 0x%08X to 0x%08X",
             flags, actualFlags);
    ALOGW_IF(actualPerformanceMode != perfMode,
             "AudioStreamTrack::open() perfMode changed from %d to %d",
             perfMode, actualPerformanceMode);

    return AAUDIO_OK;
}