From f6d543a7d0e6919a7d9055f4911d57e209e3e9db Mon Sep 17 00:00:00 2001 From: Pavlin Radoslavov Date: Wed, 25 Jan 2017 16:54:07 -0800 Subject: Update the A2DP Codec Config API Previously, the JNI upcall would contain only the current codec config. In the new API, the upcall contains: 1. The current codec config 2. The list of codecs containing the local codecs capabilities 3. The list of codecs containing the selectable codecs capabilities. This list is the intersection of the local codecs capabilities and the capabilities of the paired device. Also, refactored the Java internals to accomodate the extra information: * Added new class BluetoothCodecStatus that contains the extra info: current codec config, local codecs capabilities and selectable codecs capabilities * Renamed method getCodecConfig() to getCodecStatus() and return the corresponding BluetoothCodecStatus object. * Updates to class BluetoothCodecConfig: new methods isValid(), getCodecName(), and updated toString() so it is more user friendly * Removed BluetoothCodecConfig.EXTRA_CODEC_CONFIG and EXTRA_PREVIOUS_CODEC_CONFIG. The former is superseded by BluetoothCodecStatus.EXTRA_CODEC_STATUS; the latter is not really used. Test: A2DP streaming with headsets and switching the codecs Change-Id: Ia1af2c22e521e863e28a360610aca49f7e62d31b --- .../android/bluetooth/BluetoothCodecConfig.java | 143 +++++++++++++++++---- 1 file changed, 115 insertions(+), 28 deletions(-) (limited to 'framework/java/android/bluetooth/BluetoothCodecConfig.java') diff --git a/framework/java/android/bluetooth/BluetoothCodecConfig.java b/framework/java/android/bluetooth/BluetoothCodecConfig.java index a37a0b38aa..a48210340e 100644 --- a/framework/java/android/bluetooth/BluetoothCodecConfig.java +++ b/framework/java/android/bluetooth/BluetoothCodecConfig.java @@ -29,24 +29,6 @@ import java.util.Objects; * {@hide} */ public final class BluetoothCodecConfig implements Parcelable { - - /** - * Extra for the codec configuration intents of the individual profiles. - * - * This extra represents the current codec configuration of the A2DP - * profile. - */ - public static final String EXTRA_CODEC_CONFIG = "android.bluetooth.codec.extra.CODEC_CONFIG"; - - /** - * Extra for the codec configuration intents of the individual profiles. - * - * This extra represents the previous codec configuration of the A2DP - * profile. - */ - public static final String EXTRA_PREVIOUS_CODEC_CONFIG = - "android.bluetooth.codec.extra.PREVIOUS_CODEC_CONFIG"; - // Add an entry for each source codec here. // NOTE: The values should be same as those listed in the following file: // hardware/libhardware/include/hardware/bt_av.h @@ -128,13 +110,93 @@ public final class BluetoothCodecConfig implements Parcelable { mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); } + /** + * Checks whether the object contains valid codec configuration. + * + * @return true if the object contains valid codec configuration, + * otherwise false. + */ + public boolean isValid() { + return (mSampleRate != SAMPLE_RATE_NONE) && + (mBitsPerSample != BITS_PER_SAMPLE_NONE) && + (mChannelMode != CHANNEL_MODE_NONE); + } + + /** + * Adds capability string to an existing string. + * + * @param prevStr the previous string with the capabilities. Can be + * a null pointer. + * @param capStr the capability string to append to prevStr argument. + * @return the result string in the form "prevStr|capStr". + */ + private static String appendCapabilityToString(String prevStr, + String capStr) { + if (prevStr == null) { + return capStr; + } + return prevStr + "|" + capStr; + } + @Override public String toString() { - return "{mCodecType:" + mCodecType + + String sampleRateStr = null; + if (mSampleRate == SAMPLE_RATE_NONE) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "NONE"); + } + if ((mSampleRate & SAMPLE_RATE_44100) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "44100"); + } + if ((mSampleRate & SAMPLE_RATE_48000) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "48000"); + } + if ((mSampleRate & SAMPLE_RATE_88200) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "88200"); + } + if ((mSampleRate & SAMPLE_RATE_96000) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "96000"); + } + if ((mSampleRate & SAMPLE_RATE_176400) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "176400"); + } + if ((mSampleRate & SAMPLE_RATE_192000) != 0) { + sampleRateStr = appendCapabilityToString(sampleRateStr, "192000"); + } + + String bitsPerSampleStr = null; + if (mBitsPerSample == BITS_PER_SAMPLE_NONE) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "NONE"); + } + if ((mBitsPerSample & BITS_PER_SAMPLE_16) != 0) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "16"); + } + if ((mBitsPerSample & BITS_PER_SAMPLE_24) != 0) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "24"); + } + if ((mBitsPerSample & BITS_PER_SAMPLE_32) != 0) { + bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "32"); + } + + String channelModeStr = null; + if (mChannelMode == CHANNEL_MODE_NONE) { + channelModeStr = appendCapabilityToString(channelModeStr, "NONE"); + } + if ((mChannelMode & CHANNEL_MODE_MONO) != 0) { + channelModeStr = appendCapabilityToString(channelModeStr, "MONO"); + } + if ((mChannelMode & CHANNEL_MODE_STEREO) != 0) { + channelModeStr = appendCapabilityToString(channelModeStr, "STEREO"); + } + + return "{codecName:" + getCodecName() + + ",mCodecType:" + mCodecType + ",mCodecPriority:" + mCodecPriority + ",mSampleRate:" + String.format("0x%x", mSampleRate) + + "(" + sampleRateStr + ")" + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) + + "(" + bitsPerSampleStr + ")" + ",mChannelMode:" + String.format("0x%x", mChannelMode) + + "(" + channelModeStr + ")" + ",mCodecSpecific1:" + mCodecSpecific1 + ",mCodecSpecific2:" + mCodecSpecific2 + ",mCodecSpecific3:" + mCodecSpecific3 + @@ -181,7 +243,32 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec type. + * Gets the codec name. + * + * @return the codec name + */ + public String getCodecName() { + switch (mCodecType) { + case SOURCE_CODEC_TYPE_SBC: + return "SBC"; + case SOURCE_CODEC_TYPE_AAC: + return "AAC"; + case SOURCE_CODEC_TYPE_APTX: + return "aptX"; + case SOURCE_CODEC_TYPE_APTX_HD: + return "aptX HD"; + case SOURCE_CODEC_TYPE_LDAC: + return "LDAC"; + case SOURCE_CODEC_TYPE_INVALID: + return "INVALID CODEC"; + default: + break; + } + return "UNKNOWN CODEC(" + mCodecType + ")"; + } + + /** + * Gets the codec type. * See {@link android.bluetooth.BluetoothCodecConfig#SOURCE_CODEC_TYPE_SBC}. * * @return the codec type @@ -191,7 +278,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec selection priority. + * Gets the codec selection priority. * The codec selection priority is relative to other codecs: larger value * means higher priority. If 0, reset to default. * @@ -202,7 +289,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec sample rate. The value can be a bitmask with all + * Gets the codec sample rate. The value can be a bitmask with all * supported sample rates: * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_NONE} or * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_44100} or @@ -219,7 +306,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec bits per sample. The value can be a bitmask with all + * Gets the codec bits per sample. The value can be a bitmask with all * bits per sample supported: * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_NONE} or * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_16} or @@ -233,7 +320,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns the codec channel mode. The value can be a bitmask with all + * Gets the codec channel mode. The value can be a bitmask with all * supported channel modes: * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_NONE} or * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_MONO} or @@ -246,7 +333,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value1. + * Gets a codec specific value1. * * @return a codec specific value1. */ @@ -255,7 +342,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value2. + * Gets a codec specific value2. * * @return a codec specific value2 */ @@ -264,7 +351,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value3. + * Gets a codec specific value3. * * @return a codec specific value3 */ @@ -273,7 +360,7 @@ public final class BluetoothCodecConfig implements Parcelable { } /** - * Returns a codec specific value4. + * Gets a codec specific value4. * * @return a codec specific value4 */ -- cgit v1.2.3