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

Commit 187dcd4e authored by Phil Burk's avatar Phil Burk
Browse files

aaudio example: print timestamps during callbacks.

Bug: 63918065
Test: this is a test
Change-Id: Id25dd36764761583986d3ce29f7d82032ec4539f
parent cda5c070
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -36,6 +36,13 @@
// How long to sleep in a callback to cause an intentional glitch. For testing.
#define FORCED_UNDERRUN_SLEEP_MICROS     (10 * 1000)

#define MAX_TIMESTAMPS   16

typedef struct Timestamp {
    int64_t position;
    int64_t nanoseconds;
} Timestamp;

/**
 * Simple wrapper for AAudio that opens an output stream either in callback or blocking write mode.
 */
@@ -227,10 +234,12 @@ typedef struct SineThreadedData_s {

    SineGenerator  sineOsc1;
    SineGenerator  sineOsc2;
    Timestamp      timestamps[MAX_TIMESTAMPS];
    int64_t        framesTotal = 0;
    int64_t        nextFrameToGlitch = FORCED_UNDERRUN_PERIOD_FRAMES;
    int32_t        minNumFrames = INT32_MAX;
    int32_t        maxNumFrames = 0;
    int32_t        timestampCount = 0; // in timestamps

    int            scheduler = 0;
    bool           schedulerChecked = false;
@@ -273,6 +282,17 @@ aaudio_data_callback_result_t SimplePlayerDataCallbackProc(
        sineData->schedulerChecked = true;
    }

    if (sineData->timestampCount < MAX_TIMESTAMPS) {
        Timestamp *timestamp = &sineData->timestamps[sineData->timestampCount];
        aaudio_result_t result = AAudioStream_getTimestamp(stream,
            CLOCK_MONOTONIC, &timestamp->position, &timestamp->nanoseconds);
        if (result == AAUDIO_OK && // valid?
                (sineData->timestampCount == 0 || // first one?
                (timestamp->position != (timestamp - 1)->position))) { // advanced position?
            sineData->timestampCount++; // keep this one
        }
    }

    if (numFrames > sineData->maxNumFrames) {
        sineData->maxNumFrames = numFrames;
    }
+12 −0
Original line number Diff line number Diff line
@@ -120,6 +120,18 @@ static aaudio_result_t testOpenPlayClose(AAudioArgsParser &argParser)
        goto error;
    }

    for (int i = 0; i < myData.timestampCount; i++) {
        Timestamp *timestamp = &myData.timestamps[i];
        bool retro = (i > 0 &&
                      ((timestamp->position < (timestamp - 1)->position)
                       || ((timestamp->nanoseconds < (timestamp - 1)->nanoseconds))));
        const char *message = retro ? "  <= RETROGRADE!" : "";
        printf("Timestamp %3d : %8lld, %8lld %s\n", i,
               (long long) timestamp->position,
               (long long) timestamp->nanoseconds,
               message);
    }

    if (myData.schedulerChecked) {
        printf("scheduler = 0x%08x, SCHED_FIFO = 0x%08X\n",
               myData.scheduler,