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

Commit 219de73d authored by Eric Laurent's avatar Eric Laurent
Browse files

Fix AudioTrack and AudioRecord documentation

Improve documentation for error codes returned by
AudioTrack.write() and AudioRecord.read() methods.
Fix native to JAVA error code conversion in JNI.

Bug: 28906466

Change-Id: I4d48b1d428834b7a39a14e2d81b6c164696817a8
parent a56e732c
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19778,6 +19778,7 @@ package android.media {
    method public void stop() throws java.lang.IllegalStateException;
    field public static final int ERROR = -1; // 0xffffffff
    field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe
    field public static final int ERROR_DEAD_OBJECT = -6; // 0xfffffffa
    field public static final int ERROR_INVALID_OPERATION = -3; // 0xfffffffd
    field public static final int READ_BLOCKING = 0; // 0x0
    field public static final int READ_NON_BLOCKING = 1; // 0x1
@@ -19900,6 +19901,7 @@ package android.media {
    method public int write(java.nio.ByteBuffer, int, int, long);
    field public static final int ERROR = -1; // 0xffffffff
    field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe
    field public static final int ERROR_DEAD_OBJECT = -6; // 0xfffffffa
    field public static final int ERROR_INVALID_OPERATION = -3; // 0xfffffffd
    field public static final int MODE_STATIC = 0; // 0x0
    field public static final int MODE_STREAM = 1; // 0x1
+2 −0
Original line number Diff line number Diff line
@@ -21294,6 +21294,7 @@ package android.media {
    method public void stop() throws java.lang.IllegalStateException;
    field public static final int ERROR = -1; // 0xffffffff
    field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe
    field public static final int ERROR_DEAD_OBJECT = -6; // 0xfffffffa
    field public static final int ERROR_INVALID_OPERATION = -3; // 0xfffffffd
    field public static final int READ_BLOCKING = 0; // 0x0
    field public static final int READ_NON_BLOCKING = 1; // 0x1
@@ -21418,6 +21419,7 @@ package android.media {
    method public int write(java.nio.ByteBuffer, int, int, long);
    field public static final int ERROR = -1; // 0xffffffff
    field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe
    field public static final int ERROR_DEAD_OBJECT = -6; // 0xfffffffa
    field public static final int ERROR_INVALID_OPERATION = -3; // 0xfffffffd
    field public static final int MODE_STATIC = 0; // 0x0
    field public static final int MODE_STREAM = 1; // 0x1
+2 −0
Original line number Diff line number Diff line
@@ -19847,6 +19847,7 @@ package android.media {
    method public void stop() throws java.lang.IllegalStateException;
    field public static final int ERROR = -1; // 0xffffffff
    field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe
    field public static final int ERROR_DEAD_OBJECT = -6; // 0xfffffffa
    field public static final int ERROR_INVALID_OPERATION = -3; // 0xfffffffd
    field public static final int READ_BLOCKING = 0; // 0x0
    field public static final int READ_NON_BLOCKING = 1; // 0x1
@@ -19969,6 +19970,7 @@ package android.media {
    method public int write(java.nio.ByteBuffer, int, int, long);
    field public static final int ERROR = -1; // 0xffffffff
    field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe
    field public static final int ERROR_DEAD_OBJECT = -6; // 0xfffffffa
    field public static final int ERROR_INVALID_OPERATION = -3; // 0xfffffffd
    field public static final int MODE_STATIC = 0; // 0x0
    field public static final int MODE_STREAM = 1; // 0x1
+6 −10
Original line number Diff line number Diff line
@@ -479,17 +479,13 @@ void envReleaseArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems, jint

static inline
jint interpretReadSizeError(ssize_t readSize) {
    ALOGE_IF(readSize != WOULD_BLOCK, "Error %zd during AudioRecord native read", readSize);
    switch (readSize) {
    case WOULD_BLOCK:
    if (readSize == WOULD_BLOCK) {
        return (jint)0;
    case BAD_VALUE:
        return (jint)AUDIO_JAVA_BAD_VALUE;
    default:
        // may be possible for other errors such as
        // NO_INIT to happen if restoreRecord_l fails.
    case INVALID_OPERATION:
        return (jint)AUDIO_JAVA_INVALID_OPERATION;
    } else if (readSize == NO_INIT) {
        return AUDIO_JAVA_DEAD_OBJECT;
    } else {
        ALOGE("Error %zd during AudioRecord native read", readSize);
        return nativeToJavaStatus(readSize);
    }
}

+14 −3
Original line number Diff line number Diff line
@@ -606,6 +606,18 @@ void envReleaseArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems, jint
    env->ReleaseFloatArrayElements(array, elems, mode);
}

static inline
jint interpretWriteSizeError(ssize_t writeSize) {
    if (writeSize == WOULD_BLOCK) {
        return (jint)0;
    } else if (writeSize == NO_INIT) {
        return AUDIO_JAVA_DEAD_OBJECT;
    } else {
        ALOGE("Error %zd during AudioTrack native read", writeSize);
        return nativeToJavaStatus(writeSize);
    }
}

// ----------------------------------------------------------------------------
template <typename T>
static jint writeToTrack(const sp<AudioTrack>& track, jint audioFormat, const T *data,
@@ -628,11 +640,10 @@ static jint writeToTrack(const sp<AudioTrack>& track, jint audioFormat, const T
        memcpy(track->sharedBuffer()->pointer(), data + offsetInSamples, sizeInBytes);
        written = sizeInBytes;
    }
    if (written > 0) {
    if (written >= 0) {
        return written / sizeof(T);
    }
    // for compatibility, error codes pass through unchanged
    return written;
    return interpretWriteSizeError(written);
}

// ----------------------------------------------------------------------------
Loading