mirror of
https://github.com/encounter/SDL.git
synced 2025-12-08 21:17:45 +00:00
Fixed bug 3930 - Android, set thread priorities and names
SDLActivity thread priority is unchanged, by default -10 (THREAD_PRIORITY_VIDEO). SDLAudio thread priority was -4 (SDL_SetThreadPriority was ignored) and is now -16 (THREAD_PRIORITY_AUDIO). SDLThread thread priority was 0 (THREAD_PRIORITY_DEFAULT) and is -4 (THREAD_PRIORITY_DISPLAY).
This commit is contained in:
@@ -193,6 +193,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||
Log.v(TAG, "onCreate()");
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
try {
|
||||
Thread.currentThread().setName("SDLActivity");
|
||||
} catch (Exception e) {
|
||||
Log.v(TAG, "modify thread properties failed " + e.toString());
|
||||
}
|
||||
|
||||
// Load shared libraries
|
||||
String errorMsgBrokenLib = "";
|
||||
try {
|
||||
@@ -1494,7 +1500,14 @@ class SDLMain implements Runnable {
|
||||
String function = SDLActivity.mSingleton.getMainFunction();
|
||||
String[] arguments = SDLActivity.mSingleton.getArguments();
|
||||
|
||||
try {
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_DISPLAY);
|
||||
} catch (Exception e) {
|
||||
Log.v("SDL", "modify thread properties failed " + e.toString());
|
||||
}
|
||||
|
||||
Log.v("SDL", "Running main function " + function + " from library " + library);
|
||||
|
||||
SDLActivity.nativeRunMain(library, function, arguments);
|
||||
|
||||
Log.v("SDL", "Finished main function");
|
||||
|
||||
@@ -73,7 +73,7 @@ public class SDLAudioManager
|
||||
sampleSize = 2;
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
if (isCapture) {
|
||||
switch (desiredChannels) {
|
||||
case 1:
|
||||
@@ -298,7 +298,7 @@ public class SDLAudioManager
|
||||
Log.e(TAG, "Attempted to make audio call with uninitialized audio!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < buffer.length; ) {
|
||||
int result = mAudioTrack.write(buffer, i, buffer.length - i);
|
||||
if (result > 0) {
|
||||
@@ -364,5 +364,24 @@ public class SDLAudioManager
|
||||
}
|
||||
}
|
||||
|
||||
/** This method is called by SDL using JNI. */
|
||||
public static void audioSetThreadPriority(boolean iscapture, int device_id) {
|
||||
try {
|
||||
|
||||
/* Set thread name */
|
||||
if (iscapture) {
|
||||
Thread.currentThread().setName("SDLAudioC" + device_id);
|
||||
} else {
|
||||
Thread.currentThread().setName("SDLAudioP" + device_id);
|
||||
}
|
||||
|
||||
/* Set thread priority */
|
||||
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_AUDIO);
|
||||
|
||||
} catch (Exception e) {
|
||||
Log.v(TAG, "modify thread properties failed " + e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static native int nativeSetupJNI();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user