summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorJean-Michel Trivi <jmtrivi@google.com>2014-03-20 17:02:31 -0700
committerJean-Michel Trivi <jmtrivi@google.com>2014-03-21 09:24:26 -0700
commit5d21f679c58dbb13c8c931ffec6e06b6b8cd454f (patch)
treef2ea3cdda36f5da80fc31d8551897723eb1fbbdf /media
parent31dc8f701fb14e185bf1c1b35d68bd7d1a42a54a (diff)
downloadframeworks_base-5d21f679c58dbb13c8c931ffec6e06b6b8cd454f.zip
frameworks_base-5d21f679c58dbb13c8c931ffec6e06b6b8cd454f.tar.gz
frameworks_base-5d21f679c58dbb13c8c931ffec6e06b6b8cd454f.tar.bz2
AudioTrack write from ByteBuffer updates position
Remove offset parameter. Update buffer position when data is successfully written. Bug 7919023 Change-Id: I1701532ef0a91e2ccecfc38b24de29bc4f64d035
Diffstat (limited to 'media')
-rw-r--r--media/java/android/media/AudioTrack.java32
1 files changed, 15 insertions, 17 deletions
diff --git a/media/java/android/media/AudioTrack.java b/media/java/android/media/AudioTrack.java
index 5611efb..fdcba07 100644
--- a/media/java/android/media/AudioTrack.java
+++ b/media/java/android/media/AudioTrack.java
@@ -1177,14 +1177,11 @@ public class AudioTrack
* In streaming mode, the blocking behavior will depend on the write mode.
* @param audioData the buffer that holds the data to play, starting at the position reported
* by <code>audioData.position()</code>.
- * <BR>Note that this method will not update the position in this buffer, therefore when
- * writing a loop to write all the data in the buffer, you should increment the
- * <code>offsetInBytes</code> parameter at each pass by the amount that was previously
- * written for this buffer.
- * @param offsetInBytes offset to read from in bytes (note this differs from
- * <code>audioData.position()</code>).
- * @param sizeInBytes number of bytes to read (note this differs from
- * <code>audioData.remaining()</code>).
+ * <BR>Note that upon return, the buffer position (<code>audioData.position()</code>) will
+ * have been advanced to reflect the amount of data that was successfully written to
+ * the AudioTrack.
+ * @param sizeInBytes number of bytes to write.
+ * <BR>Note this may differ from <code>audioData.remaining()</code>, but cannot exceed it.
* @param writeMode one of {@link #WRITE_BLOCKING}, {@link #WRITE_NON_BLOCKING}. It has no
* effect in static mode.
* <BR>With {@link #WRITE_BLOCKING}, the write will block until all data has been written
@@ -1194,7 +1191,7 @@ public class AudioTrack
* @return 0 or a positive number of bytes that were written, or
* {@link #ERROR_BAD_VALUE}, {@link #ERROR_INVALID_OPERATION}
*/
- public int write(ByteBuffer audioData, int offsetInBytes, int sizeInBytes,
+ public int write(ByteBuffer audioData, int sizeInBytes,
@WriteMode int writeMode) {
if (mState == STATE_UNINITIALIZED) {
@@ -1207,22 +1204,19 @@ public class AudioTrack
return ERROR_BAD_VALUE;
}
- if ( (audioData == null) || (offsetInBytes < 0 ) || (sizeInBytes < 0)
- || (offsetInBytes + sizeInBytes < 0) // detect integer overflow
- || (offsetInBytes + sizeInBytes > audioData.remaining())) {
- Log.e(TAG, "AudioTrack.write() called with invalid size/offset values");
+ if ( (audioData == null) || (sizeInBytes < 0) || (sizeInBytes > audioData.remaining())) {
+ Log.e(TAG, "AudioTrack.write() called with invalid size (" + sizeInBytes + ") value");
return ERROR_BAD_VALUE;
}
int ret = 0;
if (audioData.isDirect()) {
ret = native_write_native_bytes(audioData,
- audioData.position(),
- offsetInBytes, sizeInBytes, mAudioFormat,
+ audioData.position(), sizeInBytes, mAudioFormat,
writeMode == WRITE_BLOCKING);
} else {
ret = native_write_byte(NioUtils.unsafeArray(audioData),
- NioUtils.unsafeArrayOffset(audioData) + audioData.position() + offsetInBytes,
+ NioUtils.unsafeArrayOffset(audioData) + audioData.position(),
sizeInBytes, mAudioFormat,
writeMode == WRITE_BLOCKING);
}
@@ -1234,6 +1228,10 @@ public class AudioTrack
mState = STATE_INITIALIZED;
}
+ if (ret > 0) {
+ audioData.position(audioData.position() + ret);
+ }
+
return ret;
}
@@ -1443,7 +1441,7 @@ public class AudioTrack
int offsetInShorts, int sizeInShorts, int format);
private native final int native_write_native_bytes(Object audioData,
- int positionInBytes, int offsetInBytes, int sizeInBytes, int format, boolean blocking);
+ int positionInBytes, int sizeInBytes, int format, boolean blocking);
private native final int native_reload_static();