Increase priority for audio thread to prevent warnings and errors about "CPU pegged"

This commit is contained in:
pelya
2010-06-10 18:47:50 +03:00
parent faa64c538c
commit dd853f111c
2 changed files with 15 additions and 0 deletions

View File

@@ -35,6 +35,7 @@
#include <jni.h>
#include <android/log.h>
#include <string.h> // for memset()
#include <pthread.h>
#define _THIS SDL_AudioDevice *this
@@ -190,12 +191,18 @@ static jmethodID JavaFillBuffer = NULL;
static void ANDROIDAUD_ThreadInit(_THIS)
{
jclass JavaAudioThreadClass = NULL;
jmethodID JavaInitThread = NULL;
struct sched_param param;
(*jniVM)->AttachCurrentThread(jniVM, &jniEnvPlaying, NULL);
JavaAudioThreadClass = (*jniEnvPlaying)->GetObjectClass(jniEnvPlaying, JavaAudioThread);
JavaFillBuffer = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "fillBuffer", "()I");
/* HACK: raise our own thread priority to max to get rid of "W/AudioFlinger: write blocked for 54 msecs" errors */
JavaInitThread = (*jniEnvPlaying)->GetMethodID(jniEnvPlaying, JavaAudioThreadClass, "initAudioThread", "()I");
(*jniEnvPlaying)->CallIntMethod( jniEnvPlaying, JavaAudioThread, JavaInitThread );
};
static void ANDROIDAUD_ThreadDeinit(_THIS)

View File

@@ -15,6 +15,7 @@ import android.media.AudioFormat;
import java.io.*;
import java.nio.ByteBuffer;
import android.util.Log;
import java.lang.Thread;
class AudioThread {
@@ -74,6 +75,13 @@ class AudioThread {
return 1;
}
public int initAudioThread()
{
// Make audio thread priority higher so audio thread won't get underrun
Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
return 1;
}
private native int nativeAudioInitJavaCallbacks();
}