New AudioTrack implementation now works on pre-Lollipop devices.
The previous version used an AudioTrack.write() implementation that required API Level 21. This is now fixed. BUG=4339 R=magjed@webrtc.org, perkj@webrtc.org Review URL: https://webrtc-codereview.appspot.com/42459004 Cr-Commit-Position: refs/heads/master@{#8494} git-svn-id: http://webrtc.googlecode.com/svn/trunk@8494 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
parent
112f127170
commit
0a3ff7976b
@ -96,9 +96,16 @@ class WebRtcAudioTrack {
|
||||
// Upon return, the buffer position will have been advanced to reflect
|
||||
// the amount of data that was successfully written to the AudioTrack.
|
||||
assertTrue(sizeInBytes <= byteBuffer.remaining());
|
||||
int bytesWritten = audioTrack.write(byteBuffer,
|
||||
sizeInBytes,
|
||||
AudioTrack.WRITE_BLOCKING);
|
||||
int bytesWritten = 0;
|
||||
if (WebRtcAudioUtils.runningOnLollipopOrHigher()) {
|
||||
bytesWritten = audioTrack.write(byteBuffer,
|
||||
sizeInBytes,
|
||||
AudioTrack.WRITE_BLOCKING);
|
||||
} else {
|
||||
bytesWritten = audioTrack.write(byteBuffer.array(),
|
||||
0,
|
||||
sizeInBytes);
|
||||
}
|
||||
if (bytesWritten != sizeInBytes) {
|
||||
Loge("AudioTrack.write failed: " + bytesWritten);
|
||||
if (bytesWritten == AudioTrack.ERROR_INVALID_OPERATION) {
|
||||
@ -146,7 +153,6 @@ class WebRtcAudioTrack {
|
||||
byteBuffer = byteBuffer.allocateDirect(
|
||||
BYTES_PER_FRAME * (sampleRate / BUFFERS_PER_SECOND));
|
||||
Logd("byteBuffer.capacity: " + byteBuffer.capacity());
|
||||
|
||||
// Rather than passing the ByteBuffer with every callback (requiring
|
||||
// the potentially expensive GetDirectBufferAddress) we simply have the
|
||||
// the native class cache the address to the memory once.
|
||||
|
@ -28,6 +28,10 @@ public final class WebRtcAudioUtils {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1;
|
||||
}
|
||||
|
||||
public static boolean runningOnLollipopOrHigher() {
|
||||
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
|
||||
}
|
||||
|
||||
/** Helper method for building a string of thread information.*/
|
||||
public static String getThreadInfo() {
|
||||
return "@[name=" + Thread.currentThread().getName()
|
||||
|
Loading…
x
Reference in New Issue
Block a user