Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.bluetooth; |
| 18 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 20 | import android.os.Parcel; |
| 21 | import android.os.Parcelable; |
| 22 | |
| 23 | import java.util.Objects; |
| 24 | |
| 25 | /** |
| 26 | * Represents the codec configuration for a Bluetooth A2DP source device. |
| 27 | * |
| 28 | * {@see BluetoothA2dp} |
| 29 | * |
| 30 | * {@hide} |
| 31 | */ |
| 32 | public final class BluetoothCodecConfig implements Parcelable { |
Pavlin Radoslavov | feeb9b2 | 2017-01-04 16:10:09 -0800 | [diff] [blame] | 33 | // Add an entry for each source codec here. |
| 34 | // NOTE: The values should be same as those listed in the following file: |
| 35 | // hardware/libhardware/include/hardware/bt_av.h |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 36 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 37 | public static final int SOURCE_CODEC_TYPE_SBC = 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 38 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 39 | public static final int SOURCE_CODEC_TYPE_AAC = 1; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 40 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 41 | public static final int SOURCE_CODEC_TYPE_APTX = 2; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 42 | @UnsupportedAppUsage |
Pavlin Radoslavov | b33bd5b | 2017-01-14 00:41:05 -0800 | [diff] [blame] | 43 | public static final int SOURCE_CODEC_TYPE_APTX_HD = 3; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 44 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 45 | public static final int SOURCE_CODEC_TYPE_LDAC = 4; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 46 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 47 | public static final int SOURCE_CODEC_TYPE_MAX = 5; |
Pavlin Radoslavov | feeb9b2 | 2017-01-04 16:10:09 -0800 | [diff] [blame] | 48 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 49 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 50 | public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; |
| 51 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 52 | @UnsupportedAppUsage |
Pavlin Radoslavov | 2199339 | 2017-02-05 15:45:06 -0800 | [diff] [blame] | 53 | public static final int CODEC_PRIORITY_DISABLED = -1; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 54 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 55 | public static final int CODEC_PRIORITY_DEFAULT = 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 56 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 57 | public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; |
| 58 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 59 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 60 | public static final int SAMPLE_RATE_NONE = 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 61 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 62 | public static final int SAMPLE_RATE_44100 = 0x1 << 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 63 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 64 | public static final int SAMPLE_RATE_48000 = 0x1 << 1; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 65 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 66 | public static final int SAMPLE_RATE_88200 = 0x1 << 2; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 67 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 68 | public static final int SAMPLE_RATE_96000 = 0x1 << 3; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 69 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 70 | public static final int SAMPLE_RATE_176400 = 0x1 << 4; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 71 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 72 | public static final int SAMPLE_RATE_192000 = 0x1 << 5; |
| 73 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 74 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 75 | public static final int BITS_PER_SAMPLE_NONE = 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 76 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 77 | public static final int BITS_PER_SAMPLE_16 = 0x1 << 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 78 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 79 | public static final int BITS_PER_SAMPLE_24 = 0x1 << 1; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 80 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 81 | public static final int BITS_PER_SAMPLE_32 = 0x1 << 2; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 82 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 83 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 84 | public static final int CHANNEL_MODE_NONE = 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 85 | @UnsupportedAppUsage |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 86 | public static final int CHANNEL_MODE_MONO = 0x1 << 0; |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 87 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 88 | public static final int CHANNEL_MODE_STEREO = 0x1 << 1; |
| 89 | |
| 90 | private final int mCodecType; |
Pavlin Radoslavov | 6107510 | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 91 | private int mCodecPriority; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 92 | private final int mSampleRate; |
| 93 | private final int mBitsPerSample; |
| 94 | private final int mChannelMode; |
| 95 | private final long mCodecSpecific1; |
| 96 | private final long mCodecSpecific2; |
| 97 | private final long mCodecSpecific3; |
| 98 | private final long mCodecSpecific4; |
| 99 | |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 100 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 101 | public BluetoothCodecConfig(int codecType, int codecPriority, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 102 | int sampleRate, int bitsPerSample, |
| 103 | int channelMode, long codecSpecific1, |
| 104 | long codecSpecific2, long codecSpecific3, |
| 105 | long codecSpecific4) { |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 106 | mCodecType = codecType; |
| 107 | mCodecPriority = codecPriority; |
| 108 | mSampleRate = sampleRate; |
| 109 | mBitsPerSample = bitsPerSample; |
| 110 | mChannelMode = channelMode; |
| 111 | mCodecSpecific1 = codecSpecific1; |
| 112 | mCodecSpecific2 = codecSpecific2; |
| 113 | mCodecSpecific3 = codecSpecific3; |
| 114 | mCodecSpecific4 = codecSpecific4; |
| 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public boolean equals(Object o) { |
| 119 | if (o instanceof BluetoothCodecConfig) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 120 | BluetoothCodecConfig other = (BluetoothCodecConfig) o; |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 121 | return (other.mCodecType == mCodecType |
| 122 | && other.mCodecPriority == mCodecPriority |
| 123 | && other.mSampleRate == mSampleRate |
| 124 | && other.mBitsPerSample == mBitsPerSample |
| 125 | && other.mChannelMode == mChannelMode |
| 126 | && other.mCodecSpecific1 == mCodecSpecific1 |
| 127 | && other.mCodecSpecific2 == mCodecSpecific2 |
| 128 | && other.mCodecSpecific3 == mCodecSpecific3 |
| 129 | && other.mCodecSpecific4 == mCodecSpecific4); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 130 | } |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | @Override |
| 135 | public int hashCode() { |
| 136 | return Objects.hash(mCodecType, mCodecPriority, mSampleRate, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 137 | mBitsPerSample, mChannelMode, mCodecSpecific1, |
| 138 | mCodecSpecific2, mCodecSpecific3, mCodecSpecific4); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 139 | } |
| 140 | |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 141 | /** |
| 142 | * Checks whether the object contains valid codec configuration. |
| 143 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 144 | * @return true if the object contains valid codec configuration, otherwise false. |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 145 | */ |
| 146 | public boolean isValid() { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 147 | return (mSampleRate != SAMPLE_RATE_NONE) |
| 148 | && (mBitsPerSample != BITS_PER_SAMPLE_NONE) |
| 149 | && (mChannelMode != CHANNEL_MODE_NONE); |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Adds capability string to an existing string. |
| 154 | * |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 155 | * @param prevStr the previous string with the capabilities. Can be a null pointer. |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 156 | * @param capStr the capability string to append to prevStr argument. |
| 157 | * @return the result string in the form "prevStr|capStr". |
| 158 | */ |
| 159 | private static String appendCapabilityToString(String prevStr, |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 160 | String capStr) { |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 161 | if (prevStr == null) { |
| 162 | return capStr; |
| 163 | } |
| 164 | return prevStr + "|" + capStr; |
| 165 | } |
| 166 | |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 167 | @Override |
| 168 | public String toString() { |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 169 | String sampleRateStr = null; |
| 170 | if (mSampleRate == SAMPLE_RATE_NONE) { |
| 171 | sampleRateStr = appendCapabilityToString(sampleRateStr, "NONE"); |
| 172 | } |
| 173 | if ((mSampleRate & SAMPLE_RATE_44100) != 0) { |
| 174 | sampleRateStr = appendCapabilityToString(sampleRateStr, "44100"); |
| 175 | } |
| 176 | if ((mSampleRate & SAMPLE_RATE_48000) != 0) { |
| 177 | sampleRateStr = appendCapabilityToString(sampleRateStr, "48000"); |
| 178 | } |
| 179 | if ((mSampleRate & SAMPLE_RATE_88200) != 0) { |
| 180 | sampleRateStr = appendCapabilityToString(sampleRateStr, "88200"); |
| 181 | } |
| 182 | if ((mSampleRate & SAMPLE_RATE_96000) != 0) { |
| 183 | sampleRateStr = appendCapabilityToString(sampleRateStr, "96000"); |
| 184 | } |
| 185 | if ((mSampleRate & SAMPLE_RATE_176400) != 0) { |
| 186 | sampleRateStr = appendCapabilityToString(sampleRateStr, "176400"); |
| 187 | } |
| 188 | if ((mSampleRate & SAMPLE_RATE_192000) != 0) { |
| 189 | sampleRateStr = appendCapabilityToString(sampleRateStr, "192000"); |
| 190 | } |
| 191 | |
| 192 | String bitsPerSampleStr = null; |
| 193 | if (mBitsPerSample == BITS_PER_SAMPLE_NONE) { |
| 194 | bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "NONE"); |
| 195 | } |
| 196 | if ((mBitsPerSample & BITS_PER_SAMPLE_16) != 0) { |
| 197 | bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "16"); |
| 198 | } |
| 199 | if ((mBitsPerSample & BITS_PER_SAMPLE_24) != 0) { |
| 200 | bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "24"); |
| 201 | } |
| 202 | if ((mBitsPerSample & BITS_PER_SAMPLE_32) != 0) { |
| 203 | bitsPerSampleStr = appendCapabilityToString(bitsPerSampleStr, "32"); |
| 204 | } |
| 205 | |
| 206 | String channelModeStr = null; |
| 207 | if (mChannelMode == CHANNEL_MODE_NONE) { |
| 208 | channelModeStr = appendCapabilityToString(channelModeStr, "NONE"); |
| 209 | } |
| 210 | if ((mChannelMode & CHANNEL_MODE_MONO) != 0) { |
| 211 | channelModeStr = appendCapabilityToString(channelModeStr, "MONO"); |
| 212 | } |
| 213 | if ((mChannelMode & CHANNEL_MODE_STEREO) != 0) { |
| 214 | channelModeStr = appendCapabilityToString(channelModeStr, "STEREO"); |
| 215 | } |
| 216 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 217 | return "{codecName:" + getCodecName() |
| 218 | + ",mCodecType:" + mCodecType |
| 219 | + ",mCodecPriority:" + mCodecPriority |
| 220 | + ",mSampleRate:" + String.format("0x%x", mSampleRate) |
| 221 | + "(" + sampleRateStr + ")" |
| 222 | + ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) |
| 223 | + "(" + bitsPerSampleStr + ")" |
| 224 | + ",mChannelMode:" + String.format("0x%x", mChannelMode) |
| 225 | + "(" + channelModeStr + ")" |
| 226 | + ",mCodecSpecific1:" + mCodecSpecific1 |
| 227 | + ",mCodecSpecific2:" + mCodecSpecific2 |
| 228 | + ",mCodecSpecific3:" + mCodecSpecific3 |
| 229 | + ",mCodecSpecific4:" + mCodecSpecific4 + "}"; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 230 | } |
| 231 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 232 | @Override |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 233 | public int describeContents() { |
| 234 | return 0; |
| 235 | } |
| 236 | |
| 237 | public static final Parcelable.Creator<BluetoothCodecConfig> CREATOR = |
| 238 | new Parcelable.Creator<BluetoothCodecConfig>() { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 239 | public BluetoothCodecConfig createFromParcel(Parcel in) { |
| 240 | final int codecType = in.readInt(); |
| 241 | final int codecPriority = in.readInt(); |
| 242 | final int sampleRate = in.readInt(); |
| 243 | final int bitsPerSample = in.readInt(); |
| 244 | final int channelMode = in.readInt(); |
| 245 | final long codecSpecific1 = in.readLong(); |
| 246 | final long codecSpecific2 = in.readLong(); |
| 247 | final long codecSpecific3 = in.readLong(); |
| 248 | final long codecSpecific4 = in.readLong(); |
| 249 | return new BluetoothCodecConfig(codecType, codecPriority, |
| 250 | sampleRate, bitsPerSample, |
| 251 | channelMode, codecSpecific1, |
| 252 | codecSpecific2, codecSpecific3, |
| 253 | codecSpecific4); |
| 254 | } |
| 255 | |
| 256 | public BluetoothCodecConfig[] newArray(int size) { |
| 257 | return new BluetoothCodecConfig[size]; |
| 258 | } |
| 259 | }; |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 260 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 261 | @Override |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 262 | public void writeToParcel(Parcel out, int flags) { |
| 263 | out.writeInt(mCodecType); |
| 264 | out.writeInt(mCodecPriority); |
| 265 | out.writeInt(mSampleRate); |
| 266 | out.writeInt(mBitsPerSample); |
| 267 | out.writeInt(mChannelMode); |
| 268 | out.writeLong(mCodecSpecific1); |
| 269 | out.writeLong(mCodecSpecific2); |
| 270 | out.writeLong(mCodecSpecific3); |
| 271 | out.writeLong(mCodecSpecific4); |
| 272 | } |
| 273 | |
| 274 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 275 | * Gets the codec name. |
| 276 | * |
| 277 | * @return the codec name |
| 278 | */ |
| 279 | public String getCodecName() { |
| 280 | switch (mCodecType) { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 281 | case SOURCE_CODEC_TYPE_SBC: |
| 282 | return "SBC"; |
| 283 | case SOURCE_CODEC_TYPE_AAC: |
| 284 | return "AAC"; |
| 285 | case SOURCE_CODEC_TYPE_APTX: |
| 286 | return "aptX"; |
| 287 | case SOURCE_CODEC_TYPE_APTX_HD: |
| 288 | return "aptX HD"; |
| 289 | case SOURCE_CODEC_TYPE_LDAC: |
| 290 | return "LDAC"; |
| 291 | case SOURCE_CODEC_TYPE_INVALID: |
| 292 | return "INVALID CODEC"; |
| 293 | default: |
| 294 | break; |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 295 | } |
| 296 | return "UNKNOWN CODEC(" + mCodecType + ")"; |
| 297 | } |
| 298 | |
| 299 | /** |
| 300 | * Gets the codec type. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 301 | * See {@link android.bluetooth.BluetoothCodecConfig#SOURCE_CODEC_TYPE_SBC}. |
| 302 | * |
| 303 | * @return the codec type |
| 304 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 305 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 306 | public int getCodecType() { |
| 307 | return mCodecType; |
| 308 | } |
| 309 | |
| 310 | /** |
Pavlin Radoslavov | 6107510 | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 311 | * Checks whether the codec is mandatory. |
| 312 | * |
| 313 | * @return true if the codec is mandatory, otherwise false. |
| 314 | */ |
| 315 | public boolean isMandatoryCodec() { |
| 316 | return mCodecType == SOURCE_CODEC_TYPE_SBC; |
| 317 | } |
| 318 | |
| 319 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 320 | * Gets the codec selection priority. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 321 | * The codec selection priority is relative to other codecs: larger value |
| 322 | * means higher priority. If 0, reset to default. |
| 323 | * |
| 324 | * @return the codec priority |
| 325 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 326 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 327 | public int getCodecPriority() { |
| 328 | return mCodecPriority; |
| 329 | } |
| 330 | |
| 331 | /** |
Pavlin Radoslavov | 6107510 | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 332 | * Sets the codec selection priority. |
| 333 | * The codec selection priority is relative to other codecs: larger value |
| 334 | * means higher priority. If 0, reset to default. |
| 335 | * |
| 336 | * @param codecPriority the codec priority |
| 337 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 338 | @UnsupportedAppUsage |
Pavlin Radoslavov | 6107510 | 2017-02-24 10:19:14 -0800 | [diff] [blame] | 339 | public void setCodecPriority(int codecPriority) { |
| 340 | mCodecPriority = codecPriority; |
| 341 | } |
| 342 | |
| 343 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 344 | * Gets the codec sample rate. The value can be a bitmask with all |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 345 | * supported sample rates: |
| 346 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_NONE} or |
| 347 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_44100} or |
| 348 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_48000} or |
| 349 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_88200} or |
| 350 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_96000} or |
| 351 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_176400} or |
| 352 | * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_192000} |
| 353 | * |
| 354 | * @return the codec sample rate |
| 355 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 356 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 357 | public int getSampleRate() { |
| 358 | return mSampleRate; |
| 359 | } |
| 360 | |
| 361 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 362 | * Gets the codec bits per sample. The value can be a bitmask with all |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 363 | * bits per sample supported: |
| 364 | * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_NONE} or |
| 365 | * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_16} or |
| 366 | * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_24} or |
| 367 | * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_32} |
| 368 | * |
| 369 | * @return the codec bits per sample |
| 370 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 371 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 372 | public int getBitsPerSample() { |
| 373 | return mBitsPerSample; |
| 374 | } |
| 375 | |
| 376 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 377 | * Gets the codec channel mode. The value can be a bitmask with all |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 378 | * supported channel modes: |
| 379 | * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_NONE} or |
| 380 | * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_MONO} or |
| 381 | * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO} |
| 382 | * |
| 383 | * @return the codec channel mode |
| 384 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 385 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 386 | public int getChannelMode() { |
| 387 | return mChannelMode; |
| 388 | } |
| 389 | |
| 390 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 391 | * Gets a codec specific value1. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 392 | * |
| 393 | * @return a codec specific value1. |
| 394 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 395 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 396 | public long getCodecSpecific1() { |
| 397 | return mCodecSpecific1; |
| 398 | } |
| 399 | |
| 400 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 401 | * Gets a codec specific value2. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 402 | * |
| 403 | * @return a codec specific value2 |
| 404 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 405 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 406 | public long getCodecSpecific2() { |
| 407 | return mCodecSpecific2; |
| 408 | } |
| 409 | |
| 410 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 411 | * Gets a codec specific value3. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 412 | * |
| 413 | * @return a codec specific value3 |
| 414 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 415 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 416 | public long getCodecSpecific3() { |
| 417 | return mCodecSpecific3; |
| 418 | } |
| 419 | |
| 420 | /** |
Pavlin Radoslavov | b37f181 | 2017-01-25 16:54:07 -0800 | [diff] [blame] | 421 | * Gets a codec specific value4. |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 422 | * |
| 423 | * @return a codec specific value4 |
| 424 | */ |
Mathew Inwood | 4dc66d3 | 2018-08-01 15:07:20 +0100 | [diff] [blame] | 425 | @UnsupportedAppUsage |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 426 | public long getCodecSpecific4() { |
| 427 | return mCodecSpecific4; |
| 428 | } |
| 429 | |
| 430 | /** |
| 431 | * Checks whether the audio feeding parameters are same. |
| 432 | * |
| 433 | * @param other the codec config to compare against |
| 434 | * @return true if the audio feeding parameters are same, otherwise false |
| 435 | */ |
| 436 | public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) { |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 437 | return (other != null && other.mSampleRate == mSampleRate |
| 438 | && other.mBitsPerSample == mBitsPerSample |
| 439 | && other.mChannelMode == mChannelMode); |
Pavlin Radoslavov | 44a4ef0 | 2016-12-21 12:05:51 -0800 | [diff] [blame] | 440 | } |
| 441 | } |