AudioSystem: Inform AudioFlinger of total memory

To better allocate per-client memory blocks.

Test: Debug logging
Bug: 64161002
Change-Id: I389bdea250a74322fab616f1009f51c6c73aef07
This commit is contained in:
Andy Hung
2018-01-23 13:58:02 -08:00
parent 3a29ce00bd
commit 7958358ddb
3 changed files with 18 additions and 5 deletions

View File

@@ -608,9 +608,10 @@ android_media_AudioSystem_getOutputLatency(JNIEnv *env, jobject clazz, jint stre
}
static jint
android_media_AudioSystem_setLowRamDevice(JNIEnv *env, jobject clazz, jboolean isLowRamDevice)
android_media_AudioSystem_setLowRamDevice(
JNIEnv *env, jobject clazz, jboolean isLowRamDevice, jlong totalMemory)
{
return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice);
return (jint) AudioSystem::setLowRamDevice((bool) isLowRamDevice, (int64_t) totalMemory);
}
static jint
@@ -1801,7 +1802,7 @@ static const JNINativeMethod gMethods[] = {
{"getPrimaryOutputSamplingRate", "()I", (void *)android_media_AudioSystem_getPrimaryOutputSamplingRate},
{"getPrimaryOutputFrameCount", "()I", (void *)android_media_AudioSystem_getPrimaryOutputFrameCount},
{"getOutputLatency", "(I)I", (void *)android_media_AudioSystem_getOutputLatency},
{"setLowRamDevice", "(Z)I", (void *)android_media_AudioSystem_setLowRamDevice},
{"setLowRamDevice", "(ZJ)I", (void *)android_media_AudioSystem_setLowRamDevice},
{"checkAudioFlinger", "()I", (void *)android_media_AudioSystem_checkAudioFlinger},
{"listAudioPorts", "(Ljava/util/ArrayList;[I)I",
(void *)android_media_AudioSystem_listAudioPorts},

View File

@@ -792,7 +792,7 @@ public class AudioSystem
public static native int getPrimaryOutputFrameCount();
public static native int getOutputLatency(int stream);
public static native int setLowRamDevice(boolean isLowRamDevice);
public static native int setLowRamDevice(boolean isLowRamDevice, long totalMemory);
public static native int checkAudioFlinger();
public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation);

View File

@@ -6583,7 +6583,19 @@ public class AudioService extends IAudioService.Stub
// Inform AudioFlinger of our device's low RAM attribute
private static void readAndSetLowRamDevice()
{
int status = AudioSystem.setLowRamDevice(ActivityManager.isLowRamDeviceStatic());
boolean isLowRamDevice = ActivityManager.isLowRamDeviceStatic();
long totalMemory = 1024 * 1024 * 1024; // 1GB is the default if ActivityManager fails.
try {
final ActivityManager.MemoryInfo info = new ActivityManager.MemoryInfo();
ActivityManager.getService().getMemoryInfo(info);
totalMemory = info.totalMem;
} catch (RemoteException e) {
Log.w(TAG, "Cannot obtain MemoryInfo from ActivityManager, assume low memory device");
isLowRamDevice = true;
}
final int status = AudioSystem.setLowRamDevice(isLowRamDevice, totalMemory);
if (status != 0) {
Log.w(TAG, "AudioFlinger informed of device's low RAM attribute; status " + status);
}