Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 659a9712 authored by Glenn Kasten's avatar Glenn Kasten
Browse files

Improve error reporting in AudioTrack JNI

for android_media_AudioTrack_get_min_buff_size when it
calls AudioTrack::getMinFrameCount.  That AudioTrack API
has been changed recently to guarantee that it will always
return a valid frameCount if the return value == NO_ERROR.

Change-Id: I8f7f850f1c30229ce77a02bdc963634cdbaf3aac
parent 8a1b1e6f
Loading
Loading
Loading
Loading
+6 −3
Original line number Original line Diff line number Diff line
@@ -829,9 +829,12 @@ static jint android_media_AudioTrack_get_output_sample_rate(JNIEnv *env, jobjec
static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env,  jobject thiz,
static jint android_media_AudioTrack_get_min_buff_size(JNIEnv *env,  jobject thiz,
    jint sampleRateInHertz, jint nbChannels, jint audioFormat) {
    jint sampleRateInHertz, jint nbChannels, jint audioFormat) {


    size_t frameCount = 0;
    size_t frameCount;
    if (AudioTrack::getMinFrameCount(&frameCount, AUDIO_STREAM_DEFAULT,
    const status_t status = AudioTrack::getMinFrameCount(&frameCount, AUDIO_STREAM_DEFAULT,
            sampleRateInHertz) != NO_ERROR) {
            sampleRateInHertz);
    if (status != NO_ERROR) {
        ALOGE("AudioTrack::getMinFrameCount() for sample rate %d failed with status %d",
                sampleRateInHertz, status);
        return -1;
        return -1;
    }
    }
    return frameCount * nbChannels * (audioFormat == ENCODING_PCM_16BIT ? 2 : 1);
    return frameCount * nbChannels * (audioFormat == ENCODING_PCM_16BIT ? 2 : 1);