ao_audiotrack: set device_buffer based on underlying buffer size when available

Signed-off-by: Aman Karmani <aman@tmm1.net>
This commit is contained in:
Aman Karmani 2021-10-19 14:26:26 -07:00 committed by sfan5
parent 7356ee5339
commit 432c0255bc
1 changed files with 10 additions and 0 deletions

View File

@ -95,6 +95,7 @@ struct JNIAudioTrack {
jmethodID writeV23;
jmethodID writeShortV23;
jmethodID writeBufferV21;
jmethodID getBufferSizeInFramesV23;
jmethodID getPlaybackHeadPosition;
jmethodID getTimestamp;
jmethodID getLatency;
@ -128,6 +129,7 @@ struct JNIAudioTrack {
{"android/media/AudioTrack", "write", "([BIII)I", MP_JNI_METHOD, OFFSET(writeV23), 0},
{"android/media/AudioTrack", "write", "([SIII)I", MP_JNI_METHOD, OFFSET(writeShortV23), 0},
{"android/media/AudioTrack", "write", "(Ljava/nio/ByteBuffer;II)I", MP_JNI_METHOD, OFFSET(writeBufferV21), 1},
{"android/media/AudioTrack", "getBufferSizeInFrames", "()I", MP_JNI_METHOD, OFFSET(getBufferSizeInFramesV23), 0},
{"android/media/AudioTrack", "getTimestamp", "(Landroid/media/AudioTimestamp;)Z", MP_JNI_METHOD, OFFSET(getTimestamp), 1},
{"android/media/AudioTrack", "getPlaybackHeadPosition", "()I", MP_JNI_METHOD, OFFSET(getPlaybackHeadPosition), 1},
{"android/media/AudioTrack", "getLatency", "()I", MP_JNI_METHOD, OFFSET(getLatency), 1},
@ -345,6 +347,14 @@ static int AudioTrack_New(struct ao *ao)
return -1;
}
if (AudioTrack.getBufferSizeInFramesV23) {
int bufferSize = MP_JNI_CALL_INT(audiotrack, AudioTrack.getBufferSizeInFramesV23);
if (bufferSize > 0) {
MP_VERBOSE(ao, "AudioTrack.getBufferSizeInFrames = %d\n", bufferSize);
ao->device_buffer = bufferSize;
}
}
p->audiotrack = (*env)->NewGlobalRef(env, audiotrack);
(*env)->DeleteLocalRef(env, audiotrack);
if (!p->audiotrack)