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

Commit 68d5ebd1 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Improve error handling for AudioTrack write with PTS

Pick up some of the error handling from AudioTrack write ByteBuffer

Change-Id: I62f233c2026759dbe57d7e1f48d62babaa49e5b8
parent 16224288
Loading
Loading
Loading
Loading
+16 −1
Original line number Diff line number Diff line
@@ -1990,9 +1990,24 @@ public class AudioTrack
     *     The dead object error code is not returned if some data was successfully transferred.
     *     In this case, the error is returned at the next write().
     */
    public int write(ByteBuffer audioData, int sizeInBytes,
    public int write(@NonNull ByteBuffer audioData, int sizeInBytes,
            @WriteMode int writeMode, long timestamp) {

        if (mState == STATE_UNINITIALIZED) {
            Log.e(TAG, "AudioTrack.write() called in invalid state STATE_UNINITIALIZED");
            return ERROR_INVALID_OPERATION;
        }

        if ((writeMode != WRITE_BLOCKING) && (writeMode != WRITE_NON_BLOCKING)) {
            Log.e(TAG, "AudioTrack.write() called with invalid blocking mode");
            return ERROR_BAD_VALUE;
        }

        if (mDataLoadMode != MODE_STREAM) {
            Log.e(TAG, "AudioTrack.write() with timestamp called for non-streaming mode track");
            return ERROR_INVALID_OPERATION;
        }

        if ((mAttributes.getFlags() & AudioAttributes.FLAG_HW_AV_SYNC) == 0) {
            Log.d(TAG, "AudioTrack.write() called on a regular AudioTrack. Ignoring pts...");
            return write(audioData, sizeInBytes, writeMode);