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

Commit 45ebf857 authored by Phil Burk's avatar Phil Burk
Browse files

aaudio test: fix looping multiple times using -l

Wait for stream to pause before flushing.
Remove scary -110 result message.

Bug: 68271891
Test: adb shell write_sine_callback -pl -m2 -n2 -s2 -c2 -l100
Change-Id: Ide7e7642cbe0b9d43023106a526e8f1e205aab77
parent 19ae3119
Loading
Loading
Loading
Loading
+16 −0
Original line number Diff line number Diff line
@@ -223,6 +223,22 @@ public:
        return result;
    }

    aaudio_result_t waitUntilPaused() {
        aaudio_result_t result = AAUDIO_OK;
        aaudio_stream_state_t currentState = AAudioStream_getState(mStream);
        aaudio_stream_state_t inputState = AAUDIO_STREAM_STATE_PAUSING;
        while (result == AAUDIO_OK && currentState == AAUDIO_STREAM_STATE_PAUSING) {
            result = AAudioStream_waitForStateChange(mStream, inputState,
                                                     &currentState, NANOS_PER_SECOND);
            inputState = currentState;
        }
        if (result != AAUDIO_OK) {
            return result;
        }
        return (currentState == AAUDIO_STREAM_STATE_PAUSED)
               ? AAUDIO_OK : AAUDIO_ERROR_INVALID_STATE;
    }

    // Flush the stream. AAudio will stop calling your callback function.
    aaudio_result_t flush() {
        aaudio_result_t result = AAudioStream_requestFlush(mStream);
+10 −4
Original line number Diff line number Diff line
@@ -30,6 +30,8 @@
#include "AAudioSimplePlayer.h"
#include "AAudioArgsParser.h"

#define APP_VERSION  "0.1.5"

/**
 * Open stream, play some sine waves, then close the stream.
 *
@@ -109,13 +111,13 @@ static aaudio_result_t testOpenPlayClose(AAudioArgsParser &argParser,
        startedAtNanos = getNanoseconds(CLOCK_MONOTONIC);
        for (int second = 0; second < durationSeconds; second++) {
            // Sleep a while. Wake up early if there is an error, for example a DISCONNECT.
            long ret = myData.waker.wait(AAUDIO_OK, NANOS_PER_SECOND);
            myData.waker.wait(AAUDIO_OK, NANOS_PER_SECOND);
            int64_t millis =
                    (getNanoseconds(CLOCK_MONOTONIC) - startedAtNanos) / NANOS_PER_MILLISECOND;
            result = myData.waker.get();
            printf("wait() returns %ld, aaudio_result = %d, at %6d millis"
            printf(" waker result = %d, at %6d millis"
                           ", second = %3d, framesWritten = %8d, underruns = %d\n",
                   ret, result, (int) millis,
                   result, (int) millis,
                   second,
                   (int) AAudioStream_getFramesWritten(player.getStream()),
                   (int) AAudioStream_getXRunCount(player.getStream()));
@@ -138,6 +140,10 @@ static aaudio_result_t testOpenPlayClose(AAudioArgsParser &argParser,
            if (result != AAUDIO_OK) {
                goto error;
            }
            result = player.waitUntilPaused();
            if (result != AAUDIO_OK) {
                goto error;
            }
            result = player.flush();
        }
        if (result != AAUDIO_OK) {
@@ -219,7 +225,7 @@ int main(int argc, const char **argv)
    // in a buffer if we hang or crash.
    setvbuf(stdout, nullptr, _IONBF, (size_t) 0);

    printf("%s - Play a sine sweep using an AAudio callback V0.1.4\n", argv[0]);
    printf("%s - Play a sine sweep using an AAudio callback V%s\n", argv[0], APP_VERSION);

    for (int i = 1; i < argc; i++) {
        const char *arg = argv[i];