diff options
author | Eric Laurent <elaurent@google.com> | 2014-05-28 22:11:19 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-05-28 22:11:20 +0000 |
commit | 0aa1cbb0de71a0fa503eb62034b6390ec5c359e0 (patch) | |
tree | 8a6a08f75d09042aa308ad3e75ff65a290c03fc4 /media | |
parent | 751cd0cb1d19dcd5a01498cdd9eff28718d5358a (diff) | |
parent | 0abcc5a0bbf2ad6b70b461cec150b70cfe55d239 (diff) | |
download | frameworks_base-0aa1cbb0de71a0fa503eb62034b6390ec5c359e0.zip frameworks_base-0aa1cbb0de71a0fa503eb62034b6390ec5c359e0.tar.gz frameworks_base-0aa1cbb0de71a0fa503eb62034b6390ec5c359e0.tar.bz2 |
Merge "DO NOT MERGE - AudioManager: audio routing extensions" into lmp-preview-dev
Diffstat (limited to 'media')
-rw-r--r-- | media/java/android/media/AudioDevicePort.java | 85 | ||||
-rw-r--r-- | media/java/android/media/AudioDevicePortConfig.java | 41 | ||||
-rw-r--r-- | media/java/android/media/AudioGain.java | 159 | ||||
-rw-r--r-- | media/java/android/media/AudioGainConfig.java | 84 | ||||
-rw-r--r-- | media/java/android/media/AudioHandle.java | 49 | ||||
-rw-r--r-- | media/java/android/media/AudioManager.java | 148 | ||||
-rw-r--r-- | media/java/android/media/AudioMixPort.java | 51 | ||||
-rw-r--r-- | media/java/android/media/AudioMixPortConfig.java | 41 | ||||
-rw-r--r-- | media/java/android/media/AudioPatch.java | 55 | ||||
-rw-r--r-- | media/java/android/media/AudioPort.java | 174 | ||||
-rw-r--r-- | media/java/android/media/AudioPortConfig.java | 93 |
11 files changed, 980 insertions, 0 deletions
diff --git a/media/java/android/media/AudioDevicePort.java b/media/java/android/media/AudioDevicePort.java new file mode 100644 index 0000000..c088906 --- /dev/null +++ b/media/java/android/media/AudioDevicePort.java @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * The AudioDevicePort is a specialized type of AudioPort + * describing an input (e.g microphone) or output device (e.g speaker) + * of the system. + * An AudioDevicePort is an AudioPort controlled by the audio HAL, almost always a physical + * device at the boundary of the audio system. + * In addition to base audio port attributes, the device descriptor contains: + * - the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) + * - the device address (e.g MAC adddress for AD2P sink). + * @see AudioPort + * @hide + */ + +public class AudioDevicePort extends AudioPort { + + private final int mType; + private final String mAddress; + + AudioDevicePort(AudioHandle handle, int[] samplingRates, int[] channelMasks, + int[] formats, AudioGain[] gains, int type, String address) { + super(handle, + (AudioManager.isInputDevice(type) == true) ? + AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK, + samplingRates, channelMasks, formats, gains); + mType = type; + mAddress = address; + } + + /** + * Get the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) + */ + public int type() { + return mType; + } + + /** + * Get the device address. Address format varies with the device type. + * - USB devices ({@link AudioManager#DEVICE_OUT_USB_DEVICE}, + * {@link AudioManager#DEVICE_IN_USB_DEVICE}) use an address composed of the ALSA card number + * and device number: "card=2;device=1" + * - Bluetooth devices ({@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, + * {@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, {@link AudioManager#DEVICE_OUT_BLUETOOTH_A2DP}) + * use the MAC address of the bluetooth device in the form "00:11:22:AA:BB:CC" as reported by + * {@link BluetoothDevice#getAddress()}. + * - Deivces that do not have an address will indicate an empty string "". + */ + public String address() { + return mAddress; + } + + /** + * Build a specific configuration of this audio device port for use by methods + * like AudioManager.connectAudioPatch(). + */ + public AudioDevicePortConfig buildConfig(int samplingRate, int channelMask, int format, + AudioGainConfig gain) { + return new AudioDevicePortConfig(this, samplingRate, channelMask, format, gain); + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof AudioDevicePort)) { + return false; + } + return super.equals(o); + } +} diff --git a/media/java/android/media/AudioDevicePortConfig.java b/media/java/android/media/AudioDevicePortConfig.java new file mode 100644 index 0000000..a381e10 --- /dev/null +++ b/media/java/android/media/AudioDevicePortConfig.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * An AudioDevicePortConfig describes a possible configuration of an output or input device + * (speaker, headphone, microphone ...). + * It is used to specify a sink or source when creating a connection with + * AudioManager.connectAudioPatch(). + * An AudioDevicePortConfig is obtained from AudioDevicePort.buildConfig(). + * @hide + */ + +public class AudioDevicePortConfig extends AudioPortConfig { + AudioDevicePortConfig(AudioDevicePort devicePort, int samplingRate, int channelMask, + int format, AudioGainConfig gain) { + super((AudioPort)devicePort, samplingRate, channelMask, format, gain); + } + + /** + * Returns the audio device port this AudioDevicePortConfig is issued from. + */ + public AudioDevicePort port() { + return (AudioDevicePort)mPort; + } +} + diff --git a/media/java/android/media/AudioGain.java b/media/java/android/media/AudioGain.java new file mode 100644 index 0000000..57709d5 --- /dev/null +++ b/media/java/android/media/AudioGain.java @@ -0,0 +1,159 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * The AudioGain describes a gain controller. Gain controllers are exposed by + * audio ports when the gain is configurable at this port's input or output. + * Gain values are expressed in millibels. + * A gain controller has the following attributes: + * - mode: defines modes of operation or features + * MODE_JOINT: all channel gains are controlled simultaneously + * MODE_CHANNELS: each channel gain is controlled individually + * MODE_RAMP: ramps can be applied when gain changes + * - channel mask: indicates for which channels the gain can be controlled + * - min value: minimum gain value in millibel + * - max value: maximum gain value in millibel + * - default value: gain value after reset in millibel + * - step value: granularity of gain control in millibel + * - min ramp duration: minimum ramp duration in milliseconds + * - max ramp duration: maximum ramp duration in milliseconds + * + * This object is always created by the framework and read only by applications. + * Applications get a list of AudioGainDescriptors from AudioPortDescriptor.gains() and can build a + * valid gain configuration from AudioGain.buildConfig() + * @hide + */ +public class AudioGain { + + /** + * Bit of AudioGain.mode() field indicating that + * all channel gains are controlled simultaneously + */ + public static final int MODE_JOINT = 1; + /** + * Bit of AudioGain.mode() field indicating that + * each channel gain is controlled individually + */ + public static final int MODE_CHANNELS = 2; + /** + * Bit of AudioGain.mode() field indicating that + * ramps can be applied when gain changes. The type of ramp (linear, log etc...) is + * implementation specific. + */ + public static final int MODE_RAMP = 4; + + private final int mIndex; + private final int mMode; + private final int mChannelMask; + private final int mMinValue; + private final int mMaxValue; + private final int mDefaultValue; + private final int mStepValue; + private final int mRampDurationMinMs; + private final int mRampDurationMaxMs; + + // The channel mask passed to the constructor is as specified in AudioFormat + // (e.g. AudioFormat.CHANNEL_OUT_STEREO) + AudioGain(int index, int mode, int channelMask, + int minValue, int maxValue, int defaultValue, int stepValue, + int rampDurationMinMs, int rampDurationMaxMs) { + mIndex = index; + mMode = mode; + mChannelMask = channelMask; + mMinValue = minValue; + mMaxValue = maxValue; + mDefaultValue = defaultValue; + mStepValue = stepValue; + mRampDurationMinMs = rampDurationMinMs; + mRampDurationMaxMs = rampDurationMaxMs; + } + + /** + * Bit field indicating supported modes of operation + */ + public int mode() { + return mMode; + } + + /** + * Indicates for which channels the gain can be controlled + * (e.g. AudioFormat.CHANNEL_OUT_STEREO) + */ + public int channelMask() { + return mChannelMask; + } + + /** + * Minimum gain value in millibel + */ + public int minValue() { + return mMinValue; + } + + /** + * Maximum gain value in millibel + */ + public int maxValue() { + return mMaxValue; + } + + /** + * Default gain value in millibel + */ + public int defaultValue() { + return mDefaultValue; + } + + /** + * Granularity of gain control in millibel + */ + public int stepValue() { + return mStepValue; + } + + /** + * Minimum ramp duration in milliseconds + * 0 if MODE_RAMP not set + */ + public int rampDurationMinMs() { + return mRampDurationMinMs; + } + + /** + * Maximum ramp duration in milliseconds + * 0 if MODE_RAMP not set + */ + public int rampDurationMaxMs() { + return mRampDurationMaxMs; + } + + /** + * Build a valid gain configuration for this gain controller for use by + * AudioPortDescriptor.setGain() + * @param mode: desired mode of operation + * @param channelMask: channels of which the gain should be modified. + * @param values: gain values for each channels. + * @param rampDurationMs: ramp duration if mode MODE_RAMP is set. + * ignored if MODE_JOINT. + */ + public AudioGainConfig buildConfig(int mode, int channelMask, + int[] values, int rampDurationMs) { + //TODO: check params here + return new AudioGainConfig(mIndex, this, mode, channelMask, values, rampDurationMs); + } +} diff --git a/media/java/android/media/AudioGainConfig.java b/media/java/android/media/AudioGainConfig.java new file mode 100644 index 0000000..ea61679 --- /dev/null +++ b/media/java/android/media/AudioGainConfig.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * The AudioGainConfig is used by APIs setting or getting values on a given gain + * controller. It contains a valid configuration (value, channels...) for a gain controller + * exposed by an audio port. + * @see AudioGain + * @see AudioPort + * @hide + */ +public class AudioGainConfig { + AudioGain mGain; + private final int mIndex; + private final int mMode; + private final int mChannelMask; + private final int mValues[]; + private final int mRampDurationMs; + + AudioGainConfig(int index, AudioGain gain, int mode, int channelMask, + int[] values, int rampDurationMs) { + mIndex = index; + mGain = gain; + mMode = mode; + mChannelMask = channelMask; + mValues = values; + mRampDurationMs = rampDurationMs; + } + + /** + * get the index of the parent gain. + * frameworks use only. + */ + int index() { + return mIndex; + } + + /** + * Bit field indicating requested modes of operation. See {@link AudioGain#MODE_JOINT}, + * {@link AudioGain#MODE_CHANNELS}, {@link AudioGain#MODE_RAMP} + */ + public int mode() { + return mMode; + } + + /** + * Indicates for which channels the gain is set. + * See {@link AudioFormat#CHANNEL_OUT_STEREO}, {@link AudioFormat#CHANNEL_OUT_MONO} ... + */ + public int channelMask() { + return mChannelMask; + } + + /** + * Gain values for each channel in the order of bits set in + * channelMask() from LSB to MSB + */ + public int[] values() { + return mValues; + } + + /** + * Ramp duration in milliseconds. N/A if mode() does not + * specify MODE_RAMP. + */ + public int rampDurationMs() { + return mRampDurationMs; + } +} diff --git a/media/java/android/media/AudioHandle.java b/media/java/android/media/AudioHandle.java new file mode 100644 index 0000000..b58e7a3 --- /dev/null +++ b/media/java/android/media/AudioHandle.java @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * The AudioHandle is used by the audio framework implementation to + * uniquely identify a particular component of the routing topology + * (AudioPort or AudioPatch) + * It is not visible or used at the API. + */ +class AudioHandle { + private final int mId; + + AudioHandle(int id) { + mId = id; + } + + int id() { + return mId; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof AudioHandle)) { + return false; + } + AudioHandle ah = (AudioHandle)o; + return mId == ah.id(); + } + + @Override + public int hashCode() { + return mId; + } +} diff --git a/media/java/android/media/AudioManager.java b/media/java/android/media/AudioManager.java index 9803161..f4affa0 100644 --- a/media/java/android/media/AudioManager.java +++ b/media/java/android/media/AudioManager.java @@ -39,6 +39,7 @@ import android.util.Log; import android.view.KeyEvent; import java.util.HashMap; +import java.util.ArrayList; /** * AudioManager provides access to volume and ringer mode control. @@ -2966,4 +2967,151 @@ public class AudioManager { Log.w(TAG, "Error disabling safe media volume", e); } } + + /** + * Return codes for listAudioPorts(), createAudioPatch() ... + */ + + /** @hide + */ + public static final int SUCCESS = AudioSystem.SUCCESS; + /** @hide + */ + public static final int ERROR = AudioSystem.ERROR; + /** @hide + */ + public static final int ERROR_BAD_VALUE = AudioSystem.BAD_VALUE; + /** @hide + */ + public static final int ERROR_INVALID_OPERATION = AudioSystem.INVALID_OPERATION; + /** @hide + */ + public static final int ERROR_PERMISSION_DENIED = AudioSystem.PERMISSION_DENIED; + /** @hide + */ + public static final int ERROR_NO_INIT = AudioSystem.NO_INIT; + /** @hide + */ + public static final int ERROR_DEAD_OBJECT = AudioSystem.DEAD_OBJECT; + + /** + * Returns a list of descriptors for all audio ports managed by the audio framework. + * Audio ports are nodes in the audio framework or audio hardware that can be configured + * or connected and disconnected with createAudioPatch() or releaseAudioPatch(). + * See AudioPort for a list of attributes of each audio port. + * @param ports An AudioPort ArrayList where the list will be returned. + * @hide + */ + public int listAudioPorts(ArrayList<AudioPort> ports) { + return ERROR_INVALID_OPERATION; + } + + /** + * Specialized version of listAudioPorts() listing only audio devices (AudioDevicePort) + * @see listAudioPorts(ArrayList<AudioPort>) + * @hide + */ + public int listAudioDevicePorts(ArrayList<AudioPort> devices) { + return ERROR_INVALID_OPERATION; + } + + /** + * Create a connection between two or more devices. The framework will reject the request if + * device types are not compatible or the implementation does not support the requested + * configuration. + * NOTE: current implementation is limited to one source and one sink per patch. + * @param patch AudioPatch array where the newly created patch will be returned. + * As input, if patch[0] is not null, the specified patch will be replaced by the + * new patch created. This avoids calling releaseAudioPatch() when modifying a + * patch and allows the implementation to optimize transitions. + * @param sources List of source audio ports. All must be AudioPort.ROLE_SOURCE. + * @param sinks List of sink audio ports. All must be AudioPort.ROLE_SINK. + * + * @return - {@link #SUCCESS} if connection is successful. + * - {@link #ERROR_BAD_VALUE} if incompatible device types are passed. + * - {@link #ERROR_INVALID_OPERATION} if the requested connection is not supported. + * - {@link #ERROR_PERMISSION_DENIED} if the client does not have permission to create + * a patch. + * - {@link #ERROR_DEAD_OBJECT} if the server process is dead + * - {@link #ERROR} if patch cannot be connected for any other reason. + * + * patch[0] contains the newly created patch + * @hide + */ + public int createAudioPatch(AudioPatch[] patch, + AudioPortConfig[] sources, + AudioPortConfig[] sinks) { + return ERROR_INVALID_OPERATION; + } + + /** + * Releases an existing audio patch connection. + * @param patch The audio patch to disconnect. + * @return - {@link #SUCCESS} if disconnection is successful. + * - {@link #ERROR_BAD_VALUE} if the specified patch does not exist. + * - {@link #ERROR_PERMISSION_DENIED} if the client does not have permission to release + * a patch. + * - {@link #ERROR_DEAD_OBJECT} if the server process is dead + * - {@link #ERROR} if patch cannot be released for any other reason. + * @hide + */ + public int releaseAudioPatch(AudioPatch patch) { + return ERROR_INVALID_OPERATION; + } + + /** + * List all existing connections between audio ports. + * @param patches An AudioPatch array where the list will be returned. + * @hide + */ + public int listAudioPatches(ArrayList<AudioPatch> patches) { + return ERROR_INVALID_OPERATION; + } + + /** + * Set the gain on the specified AudioPort. The AudioGainConfig config is build by + * AudioGain.buildConfig() + * @hide + */ + public int setAudioPortGain(AudioPort port, AudioGainConfig gain) { + return ERROR_INVALID_OPERATION; + } + + /** + * Listener registered by client to be notified upon new audio port connections, + * disconnections or attributes update. + * @hide + */ + public interface OnAudioPortUpdateListener { + /** + * Callback method called upon audio port list update. + * @param portList the updated list of audio ports + */ + public void OnAudioPortListUpdate(AudioPort[] portList); + + /** + * Callback method called upon audio patch list update. + * @param patchList the updated list of audio patches + */ + public void OnAudioPatchListUpdate(AudioPatch[] patchList); + + /** + * Callback method called when the mediaserver dies + */ + public void OnServiceDied(); + } + + /** + * Register an audio port update listener. + * @hide + */ + public void registerAudioPortUpdateListener(OnAudioPortUpdateListener l) { + } + + /** + * Unregister an audio port update listener. + * @hide + */ + public void unregisterAudioPortUpdateListener(OnAudioPortUpdateListener l) { + } } diff --git a/media/java/android/media/AudioMixPort.java b/media/java/android/media/AudioMixPort.java new file mode 100644 index 0000000..1500a43 --- /dev/null +++ b/media/java/android/media/AudioMixPort.java @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * The AudioMixPort is a specialized type of AudioPort + * describing an audio mix or stream at an input or output stream of the audio + * framework. + * @see AudioPort + * @hide + */ + +public class AudioMixPort extends AudioPort { + + AudioMixPort(AudioHandle handle, int role, int[] samplingRates, int[] channelMasks, + int[] formats, AudioGain[] gains) { + super(handle, role, samplingRates, channelMasks, formats, gains); + } + + /** + * Build a specific configuration of this audio mix port for use by methods + * like AudioManager.connectAudioPatch(). + */ + public AudioMixPortConfig buildConfig(int samplingRate, int channelMask, int format, + AudioGainConfig gain) { + return new AudioMixPortConfig(this, samplingRate, channelMask, format, gain); + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof AudioMixPort)) { + return false; + } + return super.equals(o); + } + +} diff --git a/media/java/android/media/AudioMixPortConfig.java b/media/java/android/media/AudioMixPortConfig.java new file mode 100644 index 0000000..8eb9ef4 --- /dev/null +++ b/media/java/android/media/AudioMixPortConfig.java @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * An AudioMixPortConfig describes a possible configuration of an output or input mixer. + * It is used to specify a sink or source when creating a connection with + * AudioManager.connectAudioPatch(). + * An AudioMixPortConfig is obtained from AudioMixPort.buildConfig(). + * @hide + */ + +public class AudioMixPortConfig extends AudioPortConfig { + + AudioMixPortConfig(AudioMixPort mixPort, int samplingRate, int channelMask, int format, + AudioGainConfig gain) { + super((AudioPort)mixPort, samplingRate, channelMask, format, gain); + } + + /** + * Returns the audio mix port this AudioMixPortConfig is issued from. + */ + public AudioMixPort port() { + return (AudioMixPort)mPort; + } +} + diff --git a/media/java/android/media/AudioPatch.java b/media/java/android/media/AudioPatch.java new file mode 100644 index 0000000..72291f6 --- /dev/null +++ b/media/java/android/media/AudioPatch.java @@ -0,0 +1,55 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + + +/** + * An AudioPatch describes a connection between audio sources and audio sinks. + * An audio source can be an output mix (playback AudioBus) or an input device (microphone). + * An audio sink can be an output device (speaker) or an input mix (capture AudioBus). + * An AudioPatch is created by AudioManager.connectAudioPatch() and released by + * AudioManager.disconnectAudioPatch() + * It contains the list of source and sink AudioPortConfig showing audio port configurations + * being connected. + * @hide + */ +public class AudioPatch { + + private final AudioHandle mHandle; + private final AudioPortConfig[] mSources; + private final AudioPortConfig[] mSinks; + + AudioPatch(AudioHandle patchHandle, AudioPortConfig[] sources, AudioPortConfig[] sinks) { + mHandle = patchHandle; + mSources = sources; + mSinks = sinks; + } + + /** + * Retrieve the list of sources of this audio patch. + */ + public AudioPortConfig[] sources() { + return mSources; + } + + /** + * Retreive the list of sinks of this audio patch. + */ + public AudioPortConfig[] sinks() { + return mSinks; + } +} diff --git a/media/java/android/media/AudioPort.java b/media/java/android/media/AudioPort.java new file mode 100644 index 0000000..9aeddef --- /dev/null +++ b/media/java/android/media/AudioPort.java @@ -0,0 +1,174 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + + +/** + * An audio port is a node of the audio framework or hardware that can be connected to or + * disconnect from another audio node to create a specific audio routing configuration. + * Examples of audio ports are an output device (speaker) or an output mix (see AudioMixPort). + * All attributes that are relevant for applications to make routing selection are decribed + * in an AudioPort, in particular: + * - possible channel mask configurations. + * - audio format (PCM 16bit, PCM 24bit...) + * - gain: a port can be associated with one or more gain controllers (see AudioGain). + * + * This object is always created by the framework and read only by applications. + * A list of all audio port descriptors currently available for applications to control + * is obtained by AudioManager.listAudioPorts(). + * An application can obtain an AudioPortConfig for a valid configuration of this port + * by calling AudioPort.buildConfig() and use this configuration + * to create a connection between audio sinks and sources with AudioManager.connectAudioPatch() + * + * @hide + */ +public class AudioPort { + + /** + * For use by the audio framework. + */ + public static final int ROLE_NONE = 0; + /** + * The audio port is a source (produces audio) + */ + public static final int ROLE_SOURCE = 1; + /** + * The audio port is a sink (consumes audio) + */ + public static final int ROLE_SINK = 2; + + /** + * audio port type for use by audio framework implementation + */ + public static final int TYPE_NONE = 0; + /** + */ + public static final int TYPE_DEVICE = 1; + /** + */ + public static final int TYPE_SUBMIX = 2; + /** + */ + public static final int TYPE_SESSION = 3; + + + AudioHandle mHandle; + private final int mRole; + private final int[] mSamplingRates; + private final int[] mChannelMasks; + private final int[] mFormats; + private final AudioGain[] mGains; + private AudioPortConfig mActiveConfig; + + AudioPort(AudioHandle handle, int role, int[] samplingRates, int[] channelMasks, + int[] formats, AudioGain[] gains) { + mHandle = handle; + mRole = role; + mSamplingRates = samplingRates; + mChannelMasks = channelMasks; + mFormats = formats; + mGains = gains; + } + + AudioHandle handle() { + return mHandle; + } + + /** + * Get the audio port role + */ + public int role() { + return mRole; + } + + /** + * Get the list of supported sampling rates + * Empty array if sampling rate is not relevant for this audio port + */ + public int[] samplingRates() { + return mSamplingRates; + } + + /** + * Get the list of supported channel mask configurations + * (e.g AudioFormat.CHANNEL_OUT_STEREO) + * Empty array if channel mask is not relevant for this audio port + */ + public int[] channelMasks() { + return mChannelMasks; + } + + /** + * Get the list of supported audio format configurations + * (e.g AudioFormat.ENCODING_PCM_16BIT) + * Empty array if format is not relevant for this audio port + */ + public int[] formats() { + return mFormats; + } + + /** + * Get the list of gain descriptors + * Empty array if this port does not have gain control + */ + public AudioGain[] gains() { + return mGains; + } + + /** + * Get the gain descriptor at a given index + */ + AudioGain gain(int index) { + return mGains[index]; + } + + /** + * Build a specific configuration of this audio port for use by methods + * like AudioManager.connectAudioPatch(). + * @param channelMask The desired channel mask. AudioFormat.CHANNEL_OUT_DEFAULT if no change + * from active configuration requested. + * @param format The desired audio format. AudioFormat.ENCODING_DEFAULT if no change + * from active configuration requested. + * @param gain The desired gain. null if no gain changed requested. + */ + public AudioPortConfig buildConfig(int samplingRate, int channelMask, int format, + AudioGainConfig gain) { + return new AudioPortConfig(this, samplingRate, channelMask, format, gain); + } + + /** + * Get currently active configuration of this audio port. + */ + public AudioPortConfig activeConfig() { + return mActiveConfig; + } + + @Override + public boolean equals(Object o) { + if (o == null || !(o instanceof AudioPort)) { + return false; + } + AudioPort ap = (AudioPort)o; + return mHandle.equals(ap.handle()); + } + + @Override + public int hashCode() { + return mHandle.hashCode(); + } +} + diff --git a/media/java/android/media/AudioPortConfig.java b/media/java/android/media/AudioPortConfig.java new file mode 100644 index 0000000..5dc768d --- /dev/null +++ b/media/java/android/media/AudioPortConfig.java @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2014 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.media; + +/** + * An AudioPortConfig contains a possible configuration of an audio port chosen + * among all possible attributes described by an AudioPort. + * An AudioPortConfig is created by AudioPort.buildConfiguration(). + * AudioPorts are used to specify the sources and sinks of a patch created + * with AudioManager.connectAudioPatch(). + * Several specialized versions of AudioPortConfig exist to handle different categories of + * audio ports and their specific attributes: + * - AudioDevicePortConfig for input (e.g micropohone) and output devices (e.g speaker) + * - AudioMixPortConfig for input or output streams of the audio framework. + * @hide + */ + +public class AudioPortConfig { + final AudioPort mPort; + private final int mSamplingRate; + private final int mChannelMask; + private final int mFormat; + private final AudioGainConfig mGain; + + // mConfigMask indicates which fields in this configuration should be + // taken into account. Used with AudioSystem.setAudioPortConfig() + // framework use only. + static final int SAMPLE_RATE = 0x1; + static final int CHANNEL_MASK = 0x2; + static final int FORMAT = 0x4; + static final int GAIN = 0x8; + int mConfigMask; + + AudioPortConfig(AudioPort port, int samplingRate, int channelMask, int format, + AudioGainConfig gain) { + mPort = port; + mSamplingRate = samplingRate; + mChannelMask = channelMask; + mFormat = format; + mGain = gain; + mConfigMask = 0; + } + + /** + * Returns the audio port this AudioPortConfig is issued from. + */ + public AudioPort port() { + return mPort; + } + + /** + * Sampling rate configured for this AudioPortConfig. + */ + public int samplingRate() { + return mSamplingRate; + } + + /** + * Channel mask configuration (e.g AudioFormat.CHANNEL_CONFIGURATION_STEREO). + */ + public int channelMask() { + return mChannelMask; + } + + /** + * Audio format configuration (e.g AudioFormat.ENCODING_PCM_16BIT). + */ + public int format() { + return mFormat; + } + + /** + * The gain configuration if this port supports gain control, null otherwise + * @see AudioGainConfig. + */ + public AudioGainConfig gain() { + return mGain; + } +} |