Merge "Fix AudioTrack and AudioRecord documentation" into nyc-dev

am: b143e3de34

* commit 'b143e3de34ab98463a641fd6d67165fce878f1ff':
  Fix AudioTrack and AudioRecord documentation

Change-Id: I861c0047b33730465c3ceeae1c4072f17b29d804
This commit is contained in:
Eric Laurent
2016-05-24 17:43:34 +00:00
committed by android-build-merger
7 changed files with 179 additions and 103 deletions

View File

@@ -19877,6 +19877,7 @@ package android.media {
method public void stop() throws java.lang.IllegalStateException; method public void stop() throws java.lang.IllegalStateException;
field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR = -1; // 0xffffffff
field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe 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 ERROR_INVALID_OPERATION = -3; // 0xfffffffd
field public static final int READ_BLOCKING = 0; // 0x0 field public static final int READ_BLOCKING = 0; // 0x0
field public static final int READ_NON_BLOCKING = 1; // 0x1 field public static final int READ_NON_BLOCKING = 1; // 0x1
@@ -19999,6 +20000,7 @@ package android.media {
method public int write(java.nio.ByteBuffer, int, int, long); method public int write(java.nio.ByteBuffer, int, int, long);
field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR = -1; // 0xffffffff
field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe 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 ERROR_INVALID_OPERATION = -3; // 0xfffffffd
field public static final int MODE_STATIC = 0; // 0x0 field public static final int MODE_STATIC = 0; // 0x0
field public static final int MODE_STREAM = 1; // 0x1 field public static final int MODE_STREAM = 1; // 0x1

View File

@@ -21393,6 +21393,7 @@ package android.media {
method public void stop() throws java.lang.IllegalStateException; method public void stop() throws java.lang.IllegalStateException;
field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR = -1; // 0xffffffff
field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe 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 ERROR_INVALID_OPERATION = -3; // 0xfffffffd
field public static final int READ_BLOCKING = 0; // 0x0 field public static final int READ_BLOCKING = 0; // 0x0
field public static final int READ_NON_BLOCKING = 1; // 0x1 field public static final int READ_NON_BLOCKING = 1; // 0x1
@@ -21517,6 +21518,7 @@ package android.media {
method public int write(java.nio.ByteBuffer, int, int, long); method public int write(java.nio.ByteBuffer, int, int, long);
field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR = -1; // 0xffffffff
field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe 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 ERROR_INVALID_OPERATION = -3; // 0xfffffffd
field public static final int MODE_STATIC = 0; // 0x0 field public static final int MODE_STATIC = 0; // 0x0
field public static final int MODE_STREAM = 1; // 0x1 field public static final int MODE_STREAM = 1; // 0x1

View File

@@ -19947,6 +19947,7 @@ package android.media {
method public void stop() throws java.lang.IllegalStateException; method public void stop() throws java.lang.IllegalStateException;
field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR = -1; // 0xffffffff
field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe 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 ERROR_INVALID_OPERATION = -3; // 0xfffffffd
field public static final int READ_BLOCKING = 0; // 0x0 field public static final int READ_BLOCKING = 0; // 0x0
field public static final int READ_NON_BLOCKING = 1; // 0x1 field public static final int READ_NON_BLOCKING = 1; // 0x1
@@ -20069,6 +20070,7 @@ package android.media {
method public int write(java.nio.ByteBuffer, int, int, long); method public int write(java.nio.ByteBuffer, int, int, long);
field public static final int ERROR = -1; // 0xffffffff field public static final int ERROR = -1; // 0xffffffff
field public static final int ERROR_BAD_VALUE = -2; // 0xfffffffe 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 ERROR_INVALID_OPERATION = -3; // 0xfffffffd
field public static final int MODE_STATIC = 0; // 0x0 field public static final int MODE_STATIC = 0; // 0x0
field public static final int MODE_STREAM = 1; // 0x1 field public static final int MODE_STREAM = 1; // 0x1

View File

@@ -479,17 +479,13 @@ void envReleaseArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems, jint
static inline static inline
jint interpretReadSizeError(ssize_t readSize) { jint interpretReadSizeError(ssize_t readSize) {
ALOGE_IF(readSize != WOULD_BLOCK, "Error %zd during AudioRecord native read", readSize); if (readSize == WOULD_BLOCK) {
switch (readSize) {
case WOULD_BLOCK:
return (jint)0; return (jint)0;
case BAD_VALUE: } else if (readSize == NO_INIT) {
return (jint)AUDIO_JAVA_BAD_VALUE; return AUDIO_JAVA_DEAD_OBJECT;
default: } else {
// may be possible for other errors such as ALOGE("Error %zd during AudioRecord native read", readSize);
// NO_INIT to happen if restoreRecord_l fails. return nativeToJavaStatus(readSize);
case INVALID_OPERATION:
return (jint)AUDIO_JAVA_INVALID_OPERATION;
} }
} }

View File

@@ -606,6 +606,18 @@ void envReleaseArrayElements(JNIEnv *env, jfloatArray array, jfloat *elems, jint
env->ReleaseFloatArrayElements(array, elems, mode); 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> template <typename T>
static jint writeToTrack(const sp<AudioTrack>& track, jint audioFormat, const T *data, 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); memcpy(track->sharedBuffer()->pointer(), data + offsetInSamples, sizeInBytes);
written = sizeInBytes; written = sizeInBytes;
} }
if (written > 0) { if (written >= 0) {
return written / sizeof(T); return written / sizeof(T);
} }
// for compatibility, error codes pass through unchanged return interpretWriteSizeError(written);
return written;
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@@ -94,6 +94,11 @@ public class AudioRecord implements AudioRouting
* Denotes a failure due to the improper use of a method. * Denotes a failure due to the improper use of a method.
*/ */
public static final int ERROR_INVALID_OPERATION = AudioSystem.INVALID_OPERATION; public static final int ERROR_INVALID_OPERATION = AudioSystem.INVALID_OPERATION;
/**
* An error code indicating that the object reporting it is no longer valid and needs to
* be recreated.
*/
public static final int ERROR_DEAD_OBJECT = AudioSystem.DEAD_OBJECT;
// Error codes: // Error codes:
// to keep in sync with frameworks/base/core/jni/android_media_AudioRecord.cpp // to keep in sync with frameworks/base/core/jni/android_media_AudioRecord.cpp
@@ -1046,10 +1051,16 @@ public class AudioRecord implements AudioRouting
* @param audioData the array to which the recorded audio data is written. * @param audioData the array to which the recorded audio data is written.
* @param offsetInBytes index in audioData from which the data is written expressed in bytes. * @param offsetInBytes index in audioData from which the data is written expressed in bytes.
* @param sizeInBytes the number of requested bytes. * @param sizeInBytes the number of requested bytes.
* @return the number of bytes that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of bytes that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of bytes will not exceed sizeInBytes.
* the parameters don't resolve to valid data and indexes. * <ul>
* The number of bytes will not exceed sizeInBytes. * <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes) { public int read(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes) {
return read(audioData, offsetInBytes, sizeInBytes, READ_BLOCKING); return read(audioData, offsetInBytes, sizeInBytes, READ_BLOCKING);
@@ -1070,11 +1081,17 @@ public class AudioRecord implements AudioRouting
* is read. * is read.
* <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after * <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after
* reading as much audio data as possible without blocking. * reading as much audio data as possible without blocking.
* @return the number of bytes that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of bytes that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of bytes will be a multiple of the frame size in bytes
* the parameters don't resolve to valid data and indexes.
* The number of bytes will be a multiple of the frame size in bytes
* not to exceed sizeInBytes. * not to exceed sizeInBytes.
* <ul>
* <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes, public int read(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes,
@ReadMode int readMode) { @ReadMode int readMode) {
@@ -1106,10 +1123,17 @@ public class AudioRecord implements AudioRouting
* Must not be negative, or cause the data access to go out of bounds of the array. * Must not be negative, or cause the data access to go out of bounds of the array.
* @param sizeInShorts the number of requested shorts. * @param sizeInShorts the number of requested shorts.
* Must not be negative, or cause the data access to go out of bounds of the array. * Must not be negative, or cause the data access to go out of bounds of the array.
* @return the number of shorts that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of shorts that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of shorts will be a multiple of the channel count not to exceed
* the parameters don't resolve to valid data and indexes. * sizeInShorts.
* The number of shorts will be a multiple of the channel count not to exceed sizeInShorts. * <ul>
* <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull short[] audioData, int offsetInShorts, int sizeInShorts) { public int read(@NonNull short[] audioData, int offsetInShorts, int sizeInShorts) {
return read(audioData, offsetInShorts, sizeInShorts, READ_BLOCKING); return read(audioData, offsetInShorts, sizeInShorts, READ_BLOCKING);
@@ -1129,10 +1153,17 @@ public class AudioRecord implements AudioRouting
* is read. * is read.
* <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after * <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after
* reading as much audio data as possible without blocking. * reading as much audio data as possible without blocking.
* @return the number of shorts that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of shorts that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of shorts will be a multiple of the channel count not to exceed
* the parameters don't resolve to valid data and indexes. * sizeInShorts.
* The number of shorts will be a multiple of the channel count not to exceed sizeInShorts. * <ul>
* <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull short[] audioData, int offsetInShorts, int sizeInShorts, public int read(@NonNull short[] audioData, int offsetInShorts, int sizeInShorts,
@ReadMode int readMode) { @ReadMode int readMode) {
@@ -1169,10 +1200,17 @@ public class AudioRecord implements AudioRouting
* is read. * is read.
* <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after * <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after
* reading as much audio data as possible without blocking. * reading as much audio data as possible without blocking.
* @return the number of floats that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of floats that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of floats will be a multiple of the channel count not to exceed
* the parameters don't resolve to valid data and indexes. * sizeInFloats.
* The number of floats will be a multiple of the channel count not to exceed sizeInFloats. * <ul>
* <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull float[] audioData, int offsetInFloats, int sizeInFloats, public int read(@NonNull float[] audioData, int offsetInFloats, int sizeInFloats,
@ReadMode int readMode) { @ReadMode int readMode) {
@@ -1213,11 +1251,17 @@ public class AudioRecord implements AudioRouting
* @param sizeInBytes the number of requested bytes. It is recommended but not enforced * @param sizeInBytes the number of requested bytes. It is recommended but not enforced
* that the number of bytes requested be a multiple of the frame size (sample size in * that the number of bytes requested be a multiple of the frame size (sample size in
* bytes multiplied by the channel count). * bytes multiplied by the channel count).
* @return the number of bytes that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of bytes that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of bytes will not exceed sizeInBytes and will be truncated to be
* the parameters don't resolve to valid data and indexes. * a multiple of the frame size.
* The number of bytes will not exceed sizeInBytes. * <ul>
* The number of bytes read will be truncated to be a multiple of the frame size. * <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull ByteBuffer audioBuffer, int sizeInBytes) { public int read(@NonNull ByteBuffer audioBuffer, int sizeInBytes) {
return read(audioBuffer, sizeInBytes, READ_BLOCKING); return read(audioBuffer, sizeInBytes, READ_BLOCKING);
@@ -1240,11 +1284,17 @@ public class AudioRecord implements AudioRouting
* is read. * is read.
* <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after * <br>With {@link #READ_NON_BLOCKING}, the read will return immediately after
* reading as much audio data as possible without blocking. * reading as much audio data as possible without blocking.
* @return the number of bytes that were read or {@link #ERROR_INVALID_OPERATION} * @return zero or the positive number of bytes that were read, or one of the following
* if the object wasn't properly initialized, or {@link #ERROR_BAD_VALUE} if * error codes. The number of bytes will not exceed sizeInBytes and will be truncated to be
* the parameters don't resolve to valid data and indexes. * a multiple of the frame size.
* The number of bytes will not exceed sizeInBytes. * <ul>
* The number of bytes read will be truncated to be a multiple of the frame size. * <li>{@link #ERROR_INVALID_OPERATION} if the object isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the object is not valid anymore and
* needs to be recreated. The dead object error code is not returned if some data was
* successfully transferred. In this case, the error is returned at the next read()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int read(@NonNull ByteBuffer audioBuffer, int sizeInBytes, @ReadMode int readMode) { public int read(@NonNull ByteBuffer audioBuffer, int sizeInBytes, @ReadMode int readMode) {
if (mState != STATE_INITIALIZED) { if (mState != STATE_INITIALIZED) {

View File

@@ -156,7 +156,6 @@ public class AudioTrack extends PlayerBase
/** /**
* An error code indicating that the object reporting it is no longer valid and needs to * An error code indicating that the object reporting it is no longer valid and needs to
* be recreated. * be recreated.
* @hide
*/ */
public static final int ERROR_DEAD_OBJECT = AudioSystem.DEAD_OBJECT; public static final int ERROR_DEAD_OBJECT = AudioSystem.DEAD_OBJECT;
/** /**
@@ -1840,17 +1839,17 @@ public class AudioTrack extends PlayerBase
* Must not be negative, or cause the data access to go out of bounds of the array. * Must not be negative, or cause the data access to go out of bounds of the array.
* @param sizeInBytes the number of bytes to write in audioData after the offset. * @param sizeInBytes the number of bytes to write in audioData after the offset.
* Must not be negative, or cause the data access to go out of bounds of the array. * Must not be negative, or cause the data access to go out of bounds of the array.
* @return zero or the positive number of bytes that were written, or * @return zero or the positive number of bytes that were written, or one of the following
* {@link #ERROR_INVALID_OPERATION} * error codes. The number of bytes will be a multiple of the frame size in bytes
* if the track isn't properly initialized, or {@link #ERROR_BAD_VALUE} if
* the parameters don't resolve to valid data and indexes, or
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* needs to be recreated.
* 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().
* The number of bytes will be a multiple of the frame size in bytes
* not to exceed sizeInBytes. * not to exceed sizeInBytes.
* * <ul>
* <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* needs to be recreated. 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()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
* This is equivalent to {@link #write(byte[], int, int, int)} with <code>writeMode</code> * This is equivalent to {@link #write(byte[], int, int, int)} with <code>writeMode</code>
* set to {@link #WRITE_BLOCKING}. * set to {@link #WRITE_BLOCKING}.
*/ */
@@ -1888,16 +1887,17 @@ public class AudioTrack extends PlayerBase
* to the audio sink. * to the audio sink.
* <br>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after * <br>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after
* queuing as much audio data for playback as possible without blocking. * queuing as much audio data for playback as possible without blocking.
* @return zero or the positive number of bytes that were written, or * @return zero or the positive number of bytes that were written, or one of the following
* {@link #ERROR_INVALID_OPERATION} * error codes. The number of bytes will be a multiple of the frame size in bytes
* if the track isn't properly initialized, or {@link #ERROR_BAD_VALUE} if
* the parameters don't resolve to valid data and indexes, or
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* needs to be recreated.
* 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().
* The number of bytes will be a multiple of the frame size in bytes
* not to exceed sizeInBytes. * not to exceed sizeInBytes.
* <ul>
* <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* needs to be recreated. 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()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int write(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes, public int write(@NonNull byte[] audioData, int offsetInBytes, int sizeInBytes,
@WriteMode int writeMode) { @WriteMode int writeMode) {
@@ -1950,16 +1950,17 @@ public class AudioTrack extends PlayerBase
* Must not be negative, or cause the data access to go out of bounds of the array. * Must not be negative, or cause the data access to go out of bounds of the array.
* @param sizeInShorts the number of shorts to read in audioData after the offset. * @param sizeInShorts the number of shorts to read in audioData after the offset.
* Must not be negative, or cause the data access to go out of bounds of the array. * Must not be negative, or cause the data access to go out of bounds of the array.
* @return zero or the positive number of shorts that were written, or * @return zero or the positive number of shorts that were written, or one of the following
* {@link #ERROR_INVALID_OPERATION} * error codes. The number of shorts will be a multiple of the channel count not to
* if the track isn't properly initialized, or {@link #ERROR_BAD_VALUE} if * exceed sizeInShorts.
* the parameters don't resolve to valid data and indexes, or * <ul>
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and * <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* needs to be recreated. * <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* The dead object error code is not returned if some data was successfully transferred. * <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* In this case, the error is returned at the next write(). * needs to be recreated. The dead object error code is not returned if some data was
* The number of shorts will be a multiple of the channel count not to exceed sizeInShorts. * successfully transferred. In this case, the error is returned at the next write()</li>
* * <li>{@link #ERROR} in case of other error</li>
* </ul>
* This is equivalent to {@link #write(short[], int, int, int)} with <code>writeMode</code> * This is equivalent to {@link #write(short[], int, int, int)} with <code>writeMode</code>
* set to {@link #WRITE_BLOCKING}. * set to {@link #WRITE_BLOCKING}.
*/ */
@@ -1995,15 +1996,17 @@ public class AudioTrack extends PlayerBase
* to the audio sink. * to the audio sink.
* <br>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after * <br>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after
* queuing as much audio data for playback as possible without blocking. * queuing as much audio data for playback as possible without blocking.
* @return zero or the positive number of shorts that were written, or * @return zero or the positive number of shorts that were written, or one of the following
* {@link #ERROR_INVALID_OPERATION} * error codes. The number of shorts will be a multiple of the channel count not to
* if the track isn't properly initialized, or {@link #ERROR_BAD_VALUE} if * exceed sizeInShorts.
* the parameters don't resolve to valid data and indexes, or * <ul>
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and * <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* needs to be recreated. * <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* The dead object error code is not returned if some data was successfully transferred. * <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* In this case, the error is returned at the next write(). * needs to be recreated. The dead object error code is not returned if some data was
* The number of shorts will be a multiple of the channel count not to exceed sizeInShorts. * successfully transferred. In this case, the error is returned at the next write()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int write(@NonNull short[] audioData, int offsetInShorts, int sizeInShorts, public int write(@NonNull short[] audioData, int offsetInShorts, int sizeInShorts,
@WriteMode int writeMode) { @WriteMode int writeMode) {
@@ -2074,15 +2077,17 @@ public class AudioTrack extends PlayerBase
* to the audio sink. * to the audio sink.
* <br>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after * <br>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after
* queuing as much audio data for playback as possible without blocking. * queuing as much audio data for playback as possible without blocking.
* @return zero or the positive number of floats that were written, or * @return zero or the positive number of floats that were written, or one of the following
* {@link #ERROR_INVALID_OPERATION} * error codes. The number of floats will be a multiple of the channel count not to
* if the track isn't properly initialized, or {@link #ERROR_BAD_VALUE} if * exceed sizeInFloats.
* the parameters don't resolve to valid data and indexes, or * <ul>
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and * <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* needs to be recreated. * <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* The dead object error code is not returned if some data was successfully transferred. * <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* In this case, the error is returned at the next write(). * needs to be recreated. The dead object error code is not returned if some data was
* The number of floats will be a multiple of the channel count not to exceed sizeInFloats. * successfully transferred. In this case, the error is returned at the next write()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int write(@NonNull float[] audioData, int offsetInFloats, int sizeInFloats, public int write(@NonNull float[] audioData, int offsetInFloats, int sizeInFloats,
@WriteMode int writeMode) { @WriteMode int writeMode) {
@@ -2154,12 +2159,16 @@ public class AudioTrack extends PlayerBase
* to the audio sink. * to the audio sink.
* <BR>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after * <BR>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after
* queuing as much audio data for playback as possible without blocking. * queuing as much audio data for playback as possible without blocking.
* @return zero or the positive number of bytes that were written, or * @return zero or the positive number of bytes that were written, or one of the following
* {@link #ERROR_BAD_VALUE}, {@link #ERROR_INVALID_OPERATION}, or * error codes.
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and * <ul>
* needs to be recreated. * <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* The dead object error code is not returned if some data was successfully transferred. * <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* In this case, the error is returned at the next write(). * <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* needs to be recreated. 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()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int write(@NonNull ByteBuffer audioData, int sizeInBytes, public int write(@NonNull ByteBuffer audioData, int sizeInBytes,
@WriteMode int writeMode) { @WriteMode int writeMode) {
@@ -2223,12 +2232,16 @@ public class AudioTrack extends PlayerBase
* <BR>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after * <BR>With {@link #WRITE_NON_BLOCKING}, the write will return immediately after
* queuing as much audio data for playback as possible without blocking. * queuing as much audio data for playback as possible without blocking.
* @param timestamp The timestamp of the first decodable audio frame in the provided audioData. * @param timestamp The timestamp of the first decodable audio frame in the provided audioData.
* @return zero or a positive number of bytes that were written, or * @return zero or the positive number of bytes that were written, or one of the following
* {@link #ERROR_BAD_VALUE}, {@link #ERROR_INVALID_OPERATION}, or * error codes.
* {@link AudioManager#ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and * <ul>
* needs to be recreated. * <li>{@link #ERROR_INVALID_OPERATION} if the track isn't properly initialized</li>
* The dead object error code is not returned if some data was successfully transferred. * <li>{@link #ERROR_BAD_VALUE} if the parameters don't resolve to valid data and indexes</li>
* In this case, the error is returned at the next write(). * <li>{@link #ERROR_DEAD_OBJECT} if the AudioTrack is not valid anymore and
* needs to be recreated. 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()</li>
* <li>{@link #ERROR} in case of other error</li>
* </ul>
*/ */
public int write(@NonNull ByteBuffer audioData, int sizeInBytes, public int write(@NonNull ByteBuffer audioData, int sizeInBytes,
@WriteMode int writeMode, long timestamp) { @WriteMode int writeMode, long timestamp) {