Add checks and offset when using byteBuffer in WebRtcAudioRecord.
See bug for more info. In this case, the offset of the byteBuffer was observed to be 4 bytes when testing, meaning that the first 4 bytes sent to the AudioSamples callback were empty, and the last 4 bytes that should have been sent were not sent. This CL adjusts the range copied from the backing array to match the offset. Bug: webrtc:9175 Change-Id: I40ac6e10c6d7058ead7eff1c9fa2f342920cf2a4 Reviewed-on: https://webrtc-review.googlesource.com/75123 Reviewed-by: Henrik Andreassson <henrika@webrtc.org> Reviewed-by: Magnus Jedvert <magjed@webrtc.org> Commit-Queue: Paulina Hensman <phensman@webrtc.org> Cr-Commit-Position: refs/heads/master@{#23172}
This commit is contained in:
committed by
Commit Bot
parent
0520b0eb7b
commit
24bebb86bd
@ -88,8 +88,6 @@ class WebRtcAudioRecord {
|
||||
super(name);
|
||||
}
|
||||
|
||||
// TODO(titovartem) make correct fix during webrtc:9175
|
||||
@SuppressWarnings("ByteBufferBackingArray")
|
||||
@Override
|
||||
public void run() {
|
||||
Process.setThreadPriority(Process.THREAD_PRIORITY_URGENT_AUDIO);
|
||||
@ -111,9 +109,10 @@ class WebRtcAudioRecord {
|
||||
nativeDataIsRecorded(nativeAudioRecord, bytesRead);
|
||||
}
|
||||
if (audioSamplesReadyCallback != null) {
|
||||
// Copy the entire byte buffer array. Assume that the start of the byteBuffer is
|
||||
// Copy the entire byte buffer array. The start of the byteBuffer is not necessarily
|
||||
// at index 0.
|
||||
byte[] data = Arrays.copyOf(byteBuffer.array(), byteBuffer.capacity());
|
||||
byte[] data = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.arrayOffset(),
|
||||
byteBuffer.capacity() + byteBuffer.arrayOffset());
|
||||
audioSamplesReadyCallback.onWebRtcAudioRecordSamplesReady(
|
||||
new JavaAudioDeviceModule.AudioSamples(audioRecord.getAudioFormat(),
|
||||
audioRecord.getChannelCount(), audioRecord.getSampleRate(), data));
|
||||
@ -208,6 +207,10 @@ class WebRtcAudioRecord {
|
||||
final int bytesPerFrame = channels * (BITS_PER_SAMPLE / 8);
|
||||
final int framesPerBuffer = sampleRate / BUFFERS_PER_SECOND;
|
||||
byteBuffer = ByteBuffer.allocateDirect(bytesPerFrame * framesPerBuffer);
|
||||
if (!(byteBuffer.hasArray())) {
|
||||
reportWebRtcAudioRecordInitError("ByteBuffer does not have backing array.");
|
||||
return -1;
|
||||
}
|
||||
Logging.d(TAG, "byteBuffer.capacity: " + byteBuffer.capacity());
|
||||
emptyBytes = new byte[byteBuffer.capacity()];
|
||||
// Rather than passing the ByteBuffer with every callback (requiring
|
||||
|
||||
Reference in New Issue
Block a user