diff options
author | Eric Laurent <elaurent@google.com> | 2014-05-31 00:49:26 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-31 00:49:27 +0000 |
commit | a89eb2d8e550b511285ab3b4fb7dec1ed4ca5028 (patch) | |
tree | 2d48237cd68700a09a2084e971eef1daa697202b /media | |
parent | ba23f6da6e40892202199a4b7c5672b92827828d (diff) | |
parent | b69681c894c663e84f2826d9b0c832ceb9b45047 (diff) | |
download | frameworks_base-a89eb2d8e550b511285ab3b4fb7dec1ed4ca5028.zip frameworks_base-a89eb2d8e550b511285ab3b4fb7dec1ed4ca5028.tar.gz frameworks_base-a89eb2d8e550b511285ab3b4fb7dec1ed4ca5028.tar.bz2 |
Merge "AudioSystem: added JNI for routing extensions" into lmp-preview-dev
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioManager.java | 130 | ||||
-rw-r--r-- | media/java/android/media/AudioSystem.java | 8 |
2 files changed, 133 insertions, 5 deletions
diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index f4affa0..bbe5331 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -3003,7 +3003,7 @@ public class AudioManager { * @hide */ public int listAudioPorts(ArrayList<AudioPort> ports) { - return ERROR_INVALID_OPERATION; + return updateAudioPortCache(ports, null); } /** @@ -3012,7 +3012,17 @@ public class AudioManager { * @hide */ public int listAudioDevicePorts(ArrayList<AudioPort> devices) { - return ERROR_INVALID_OPERATION; + ArrayList<AudioPort> ports = new ArrayList<AudioPort>(); + int status = updateAudioPortCache(ports, null); + if (status == SUCCESS) { + devices.clear(); + for (int i = 0; i < ports.size(); i++) { + if (ports.get(i) instanceof AudioDevicePort) { + devices.add(ports.get(i)); + } + } + } + return status; } /** @@ -3041,7 +3051,7 @@ public class AudioManager { public int createAudioPatch(AudioPatch[] patch, AudioPortConfig[] sources, AudioPortConfig[] sinks) { - return ERROR_INVALID_OPERATION; + return AudioSystem.createAudioPatch(patch, sources, sinks); } /** @@ -3056,7 +3066,7 @@ public class AudioManager { * @hide */ public int releaseAudioPatch(AudioPatch patch) { - return ERROR_INVALID_OPERATION; + return AudioSystem.releaseAudioPatch(patch); } /** @@ -3065,7 +3075,7 @@ public class AudioManager { * @hide */ public int listAudioPatches(ArrayList<AudioPatch> patches) { - return ERROR_INVALID_OPERATION; + return updateAudioPortCache(null, patches); } /** @@ -3114,4 +3124,114 @@ public class AudioManager { */ public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) { } + + // + // AudioPort implementation + // + + static final int AUDIOPORT_GENERATION_INIT = 0; + Integer mAudioPortGeneration = new Integer(AUDIOPORT_GENERATION_INIT); + ArrayList<AudioPort> mAudioPortsCached = new ArrayList<AudioPort>(); + ArrayList<AudioPatch> mAudioPatchesCached = new ArrayList<AudioPatch>(); + + int resetAudioPortGeneration() { + int generation; + synchronized (mAudioPortGeneration) { + generation = mAudioPortGeneration; + mAudioPortGeneration = AUDIOPORT_GENERATION_INIT; + } + return generation; + } + + int updateAudioPortCache(ArrayList<AudioPort> ports, ArrayList<AudioPatch> patches) { + synchronized (mAudioPortGeneration) { + + if (mAudioPortGeneration == AUDIOPORT_GENERATION_INIT) { + int[] patchGeneration = new int[1]; + int[] portGeneration = new int[1]; + int status; + ArrayList<AudioPort> newPorts = new ArrayList<AudioPort>(); + ArrayList<AudioPatch> newPatches = new ArrayList<AudioPatch>(); + + do { + newPorts.clear(); + status = AudioSystem.listAudioPorts(newPorts, portGeneration); + Log.i(TAG, "updateAudioPortCache AudioSystem.listAudioPorts() status: "+ + status+" num ports: "+ newPorts.size() +" portGeneration: "+portGeneration[0]); + if (status != SUCCESS) { + return status; + } + newPatches.clear(); + status = AudioSystem.listAudioPatches(newPatches, patchGeneration); + Log.i(TAG, "updateAudioPortCache AudioSystem.listAudioPatches() status: "+ + status+" num patches: "+ newPatches.size() +" patchGeneration: "+patchGeneration[0]); + if (status != SUCCESS) { + return status; + } + } while (patchGeneration[0] != portGeneration[0]); + + for (int i = 0; i < newPatches.size(); i++) { + for (int j = 0; j < newPatches.get(i).sources().length; j++) { + AudioPortConfig portCfg = updatePortConfig(newPatches.get(i).sources()[j], newPorts); + if (portCfg == null) { + return ERROR; + } + newPatches.get(i).sources()[j] = portCfg; + } + for (int j = 0; j < newPatches.get(i).sinks().length; j++) { + AudioPortConfig portCfg = updatePortConfig(newPatches.get(i).sinks()[j], newPorts); + if (portCfg == null) { + return ERROR; + } + newPatches.get(i).sinks()[j] = portCfg; + } + } + + mAudioPortsCached = newPorts; + mAudioPatchesCached = newPatches; + mAudioPortGeneration = portGeneration[0]; + } + if (ports != null) { + ports.clear(); + ports.addAll(mAudioPortsCached); + } + if (patches != null) { + patches.clear(); + patches.addAll(mAudioPatchesCached); + } + } + return SUCCESS; + } + + AudioPortConfig updatePortConfig(AudioPortConfig portCfg, ArrayList<AudioPort> ports) { + AudioPort port = portCfg.port(); + int k; + for (k = 0; k < ports.size(); k++) { + // compare handles because the port returned by JNI is not of the correct + // subclass + if (ports.get(k).handle().equals(port.handle())) { + Log.i(TAG, "updatePortConfig match found for port handle: "+ + port.handle().id()+" port: "+ k); + port = ports.get(k); + break; + } + } + if (k == ports.size()) { + // this hould never happen + Log.e(TAG, "updatePortConfig port not found for handle: "+port.handle().id()); + return null; + } + AudioGainConfig gainCfg = portCfg.gain(); + if (gainCfg != null) { + AudioGain gain = port.gain(gainCfg.index()); + gainCfg = gain.buildConfig(gainCfg.mode(), + gainCfg.channelMask(), + gainCfg.values(), + gainCfg.rampDurationMs()); + } + return port.buildConfig(portCfg.samplingRate(), + portCfg.channelMask(), + portCfg.format(), + gainCfg); + } } diff --git a/media/java/android/media/AudioSystem.java b/media/java/android/media/AudioSystem.java index 0c45443..47a884b 100644 --- a/media/java/android/media/AudioSystem.java +++ b/media/java/android/media/AudioSystem.java @@ -16,6 +16,7 @@ package android.media; +import java.util.ArrayList; /* IF YOU CHANGE ANY OF THE CONSTANTS IN THIS FILE, DO NOT FORGET * TO UPDATE THE CORRESPONDING NATIVE GLUE AND AudioManager.java. @@ -458,4 +459,11 @@ public class AudioSystem public static native int setLowRamDevice(boolean isLowRamDevice); public static native int checkAudioFlinger(); + + public static native int listAudioPorts(ArrayList<AudioPort> ports, int[] generation); + public static native int createAudioPatch(AudioPatch[] patch, + AudioPortConfig[] sources, AudioPortConfig[] sinks); + public static native int releaseAudioPatch(AudioPatch patch); + public static native int listAudioPatches(ArrayList<AudioPatch> patches, int[] generation); } + |