| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 | |
| 19 | import android.annotation.IntDef; |
| 20 | import android.annotation.NonNull; |
| Anton Hansson | fa927a5 | 2023-11-09 09:08:19 +0000 | [diff] [blame^] | 21 | import android.annotation.Nullable; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 22 | import android.os.Parcel; |
| 23 | import android.os.Parcelable; |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 24 | |
| 25 | import java.lang.annotation.Retention; |
| 26 | import java.lang.annotation.RetentionPolicy; |
| Patty | 5aa4bd2 | 2022-01-25 19:58:37 +0800 | [diff] [blame] | 27 | import java.util.Objects; |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Represents the codec configuration for a Bluetooth LE Audio source device. |
| 31 | * <p>Contains the source codec type. |
| 32 | * <p>The source codec type values are the same as those supported by the |
| 33 | * device hardware. |
| 34 | * |
| 35 | * {@see BluetoothLeAudioCodecConfig} |
| 36 | */ |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 37 | public final class BluetoothLeAudioCodecConfig implements Parcelable { |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 38 | // Add an entry for each source codec here. |
| 39 | |
| 40 | /** @hide */ |
| 41 | @IntDef(prefix = "SOURCE_CODEC_TYPE_", value = { |
| 42 | SOURCE_CODEC_TYPE_LC3, |
| 43 | SOURCE_CODEC_TYPE_INVALID |
| 44 | }) |
| 45 | @Retention(RetentionPolicy.SOURCE) |
| 46 | public @interface SourceCodecType {}; |
| 47 | |
| 48 | public static final int SOURCE_CODEC_TYPE_LC3 = 0; |
| 49 | public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000; |
| 50 | |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 51 | /** @hide */ |
| 52 | @IntDef(prefix = "CODEC_PRIORITY_", |
| 53 | value = {CODEC_PRIORITY_DISABLED, CODEC_PRIORITY_DEFAULT, CODEC_PRIORITY_HIGHEST}) |
| 54 | @Retention(RetentionPolicy.SOURCE) |
| 55 | public @interface CodecPriority {} |
| 56 | |
| 57 | /** |
| 58 | * Codec priority disabled. |
| 59 | * Used to indicate that this codec is disabled and should not be used. |
| 60 | */ |
| 61 | public static final int CODEC_PRIORITY_DISABLED = -1; |
| 62 | |
| 63 | /** |
| 64 | * Codec priority default. |
| 65 | * Default value used for codec priority. |
| 66 | */ |
| 67 | public static final int CODEC_PRIORITY_DEFAULT = 0; |
| 68 | |
| 69 | /** |
| 70 | * Codec priority highest. |
| 71 | * Used to indicate the highest priority a codec can have. |
| 72 | */ |
| 73 | public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000; |
| 74 | |
| 75 | /** @hide */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 76 | @IntDef(flag = true, prefix = "SAMPLE_RATE_", |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 77 | value = {SAMPLE_RATE_NONE, SAMPLE_RATE_8000, SAMPLE_RATE_16000, SAMPLE_RATE_24000, |
| 78 | SAMPLE_RATE_32000, SAMPLE_RATE_44100, SAMPLE_RATE_48000}) |
| 79 | @Retention(RetentionPolicy.SOURCE) |
| 80 | public @interface SampleRate {} |
| 81 | |
| 82 | /** |
| 83 | * Codec sample rate 0 Hz. Default value used for |
| 84 | * codec sample rate. |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 85 | * Values are the bit mask as defined in the |
| 86 | * Bluetooth Assigned Numbers, Generic Audio, |
| 87 | * Supported_Sampling_Frequencies table |
| 88 | * Note: We use only part of it. |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 89 | */ |
| 90 | public static final int SAMPLE_RATE_NONE = 0; |
| 91 | |
| 92 | /** |
| 93 | * Codec sample rate 8000 Hz. |
| 94 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 95 | public static final int SAMPLE_RATE_8000 = 0x01 << 0; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Codec sample rate 16000 Hz. |
| 99 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 100 | public static final int SAMPLE_RATE_16000 = 0x01 << 2; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 101 | |
| 102 | /** |
| 103 | * Codec sample rate 24000 Hz. |
| 104 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 105 | public static final int SAMPLE_RATE_24000 = 0x01 << 4; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 106 | |
| 107 | /** |
| 108 | * Codec sample rate 32000 Hz. |
| 109 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 110 | public static final int SAMPLE_RATE_32000 = 0x01 << 5; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 111 | |
| 112 | /** |
| 113 | * Codec sample rate 44100 Hz. |
| 114 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 115 | public static final int SAMPLE_RATE_44100 = 0x01 << 6; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 116 | |
| 117 | /** |
| 118 | * Codec sample rate 48000 Hz. |
| 119 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 120 | public static final int SAMPLE_RATE_48000 = 0x01 << 7; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 121 | |
| 122 | /** @hide */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 123 | @IntDef(flag = true, prefix = "BITS_PER_SAMPLE_", |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 124 | value = {BITS_PER_SAMPLE_NONE, BITS_PER_SAMPLE_16, BITS_PER_SAMPLE_24, |
| 125 | BITS_PER_SAMPLE_32}) |
| 126 | @Retention(RetentionPolicy.SOURCE) |
| 127 | public @interface BitsPerSample {} |
| 128 | |
| 129 | /** |
| 130 | * Codec bits per sample 0. Default value of the codec |
| 131 | * bits per sample. |
| 132 | */ |
| 133 | public static final int BITS_PER_SAMPLE_NONE = 0; |
| 134 | |
| 135 | /** |
| 136 | * Codec bits per sample 16. |
| 137 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 138 | public static final int BITS_PER_SAMPLE_16 = 0x01 << 0; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 139 | |
| 140 | /** |
| 141 | * Codec bits per sample 24. |
| 142 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 143 | public static final int BITS_PER_SAMPLE_24 = 0x01 << 1; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 144 | |
| 145 | /** |
| 146 | * Codec bits per sample 32. |
| 147 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 148 | public static final int BITS_PER_SAMPLE_32 = 0x01 << 3; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 149 | |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 150 | /** |
| 151 | * Values are the bit mask as defined in the |
| 152 | * Bluetooth Assigned Numbers, Generic Audio, |
| 153 | * Supported_Audio_Channel_Counts table |
| 154 | * Note: We use only part of it. |
| 155 | * @hide */ |
| 156 | @IntDef(flag = true, prefix = "CHANNEL_COUNT_", |
| 157 | value = {CHANNEL_COUNT_NONE, CHANNEL_COUNT_1, CHANNEL_COUNT_2}) |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 158 | @Retention(RetentionPolicy.SOURCE) |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 159 | public @interface ChannelCount {} |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 160 | |
| 161 | /** |
| 162 | * Codec channel mode NONE. Default value of the |
| 163 | * codec channel mode. |
| 164 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 165 | public static final int CHANNEL_COUNT_NONE = 0; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 166 | |
| 167 | /** |
| 168 | * Codec channel mode MONO. |
| 169 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 170 | public static final int CHANNEL_COUNT_1 = 0x01 << 0; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 171 | |
| 172 | /** |
| 173 | * Codec channel mode STEREO. |
| 174 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 175 | public static final int CHANNEL_COUNT_2 = 0x01 << 1; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 176 | |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 177 | /** |
| 178 | * Values are the bit mask as defined in the |
| 179 | * Bluetooth Assigned Numbers, Generic Audio, |
| 180 | * Supported_Frame_Durations table |
| 181 | * |
| 182 | * @hide */ |
| 183 | @IntDef(flag = true, prefix = "FRAME_DURATION_", |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 184 | value = {FRAME_DURATION_NONE, FRAME_DURATION_7500, FRAME_DURATION_10000}) |
| 185 | @Retention(RetentionPolicy.SOURCE) |
| 186 | public @interface FrameDuration {} |
| 187 | |
| 188 | /** |
| 189 | * Frame duration 0. Default value of the frame duration. |
| 190 | */ |
| 191 | public static final int FRAME_DURATION_NONE = 0; |
| 192 | |
| 193 | /** |
| 194 | * Frame duration 7500 us. |
| 195 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 196 | public static final int FRAME_DURATION_7500 = 0x01 << 0; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 197 | |
| 198 | /** |
| 199 | * Frame duration 10000 us. |
| 200 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 201 | public static final int FRAME_DURATION_10000 = 0x01 << 1; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 202 | |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 203 | private final @SourceCodecType int mCodecType; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 204 | private final @CodecPriority int mCodecPriority; |
| 205 | private final @SampleRate int mSampleRate; |
| 206 | private final @BitsPerSample int mBitsPerSample; |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 207 | private final @ChannelCount int mChannelCount; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 208 | private final @FrameDuration int mFrameDuration; |
| 209 | private final int mOctetsPerFrame; |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 210 | private final int mMinOctetsPerFrame; |
| 211 | private final int mMaxOctetsPerFrame; |
| 212 | |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 213 | |
| 214 | /** |
| 215 | * Creates a new BluetoothLeAudioCodecConfig. |
| 216 | * |
| 217 | * @param codecType the source codec type |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 218 | * @param codecPriority the priority of this codec |
| 219 | * @param sampleRate the codec sample rate |
| 220 | * @param bitsPerSample the bits per sample of this codec |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 221 | * @param channelCount the channel count of this codec |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 222 | * @param frameDuration the frame duration of this codec |
| 223 | * @param octetsPerFrame the octets per frame of this codec |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 224 | * @param minOctetsPerFrame the minimum octets per frame of this codec |
| 225 | * @param maxOctetsPerFrame the maximum octets per frame of this codec |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 226 | */ |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 227 | private BluetoothLeAudioCodecConfig(@SourceCodecType int codecType, |
| 228 | @CodecPriority int codecPriority, @SampleRate int sampleRate, |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 229 | @BitsPerSample int bitsPerSample, @ChannelCount int channelCount, |
| 230 | @FrameDuration int frameDuration, int octetsPerFrame, |
| 231 | int minOctetsPerFrame, int maxOctetsPerFrame) { |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 232 | mCodecType = codecType; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 233 | mCodecPriority = codecPriority; |
| 234 | mSampleRate = sampleRate; |
| 235 | mBitsPerSample = bitsPerSample; |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 236 | mChannelCount = channelCount; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 237 | mFrameDuration = frameDuration; |
| 238 | mOctetsPerFrame = octetsPerFrame; |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 239 | mMinOctetsPerFrame = minOctetsPerFrame; |
| 240 | mMaxOctetsPerFrame = maxOctetsPerFrame; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | @Override |
| 244 | public int describeContents() { |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | /** |
| 249 | * {@link Parcelable.Creator} interface implementation. |
| 250 | */ |
| 251 | public static final |
| 252 | @android.annotation.NonNull Parcelable.Creator<BluetoothLeAudioCodecConfig> CREATOR = |
| 253 | new Parcelable.Creator<BluetoothLeAudioCodecConfig>() { |
| 254 | public BluetoothLeAudioCodecConfig createFromParcel(Parcel in) { |
| 255 | int codecType = in.readInt(); |
| 256 | int codecPriority = in.readInt(); |
| 257 | int sampleRate = in.readInt(); |
| 258 | int bitsPerSample = in.readInt(); |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 259 | int channelCount = in.readInt(); |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 260 | int frameDuration = in.readInt(); |
| 261 | int octetsPerFrame = in.readInt(); |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 262 | int minOctetsPerFrame = in.readInt(); |
| 263 | int maxOctetsPerFrame = in.readInt(); |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 264 | return new BluetoothLeAudioCodecConfig(codecType, codecPriority, sampleRate, |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 265 | bitsPerSample, channelCount, frameDuration, octetsPerFrame, |
| 266 | minOctetsPerFrame, maxOctetsPerFrame); |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | public BluetoothLeAudioCodecConfig[] newArray(int size) { |
| 270 | return new BluetoothLeAudioCodecConfig[size]; |
| 271 | } |
| 272 | }; |
| 273 | |
| 274 | @Override |
| 275 | public void writeToParcel(@NonNull Parcel out, int flags) { |
| 276 | out.writeInt(mCodecType); |
| 277 | out.writeInt(mCodecPriority); |
| 278 | out.writeInt(mSampleRate); |
| 279 | out.writeInt(mBitsPerSample); |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 280 | out.writeInt(mChannelCount); |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 281 | out.writeInt(mFrameDuration); |
| 282 | out.writeInt(mOctetsPerFrame); |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 283 | out.writeInt(mMinOctetsPerFrame); |
| 284 | out.writeInt(mMaxOctetsPerFrame); |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | @Override |
| 288 | public String toString() { |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 289 | return "{codecName:" + getCodecName() + ",mCodecType:" + mCodecType |
| 290 | + ",mCodecPriority:" + mCodecPriority + ",mSampleRate:" + mSampleRate |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 291 | + ",mBitsPerSample:" + mBitsPerSample + ",mChannelCount:" + mChannelCount |
| 292 | + ",mFrameDuration:" + mFrameDuration + ",mOctetsPerFrame:" + mOctetsPerFrame |
| 293 | + ",mMinOctetsPerFrame:" + mMinOctetsPerFrame |
| 294 | + ",mMaxOctetsPerFrame:" + mMaxOctetsPerFrame + "}"; |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | /** |
| 298 | * Gets the codec type. |
| 299 | * |
| 300 | * @return the codec type |
| 301 | */ |
| 302 | public @SourceCodecType int getCodecType() { |
| 303 | return mCodecType; |
| 304 | } |
| 305 | |
| 306 | /** |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 307 | * Gets the codec name. |
| 308 | * |
| 309 | * @return the codec name |
| 310 | */ |
| 311 | public @NonNull String getCodecName() { |
| 312 | switch (mCodecType) { |
| 313 | case SOURCE_CODEC_TYPE_LC3: |
| 314 | return "LC3"; |
| 315 | case SOURCE_CODEC_TYPE_INVALID: |
| 316 | return "INVALID CODEC"; |
| 317 | default: |
| 318 | break; |
| 319 | } |
| 320 | return "UNKNOWN CODEC(" + mCodecType + ")"; |
| 321 | } |
| 322 | |
| 323 | /** |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 324 | * Returns the codec selection priority. |
| 325 | * <p>The codec selection priority is relative to other codecs: larger value |
| 326 | * means higher priority. |
| 327 | */ |
| 328 | public @CodecPriority int getCodecPriority() { |
| 329 | return mCodecPriority; |
| 330 | } |
| 331 | |
| 332 | /** |
| 333 | * Returns the codec sample rate. |
| 334 | */ |
| 335 | public @SampleRate int getSampleRate() { |
| 336 | return mSampleRate; |
| 337 | } |
| 338 | |
| 339 | /** |
| 340 | * Returns the codec bits per sample. |
| 341 | */ |
| 342 | public @BitsPerSample int getBitsPerSample() { |
| 343 | return mBitsPerSample; |
| 344 | } |
| 345 | |
| 346 | /** |
| 347 | * Returns the codec channel mode. |
| 348 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 349 | public @ChannelCount int getChannelCount() { |
| 350 | return mChannelCount; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | /** |
| 354 | * Returns the frame duration. |
| 355 | */ |
| Patty | 3a61c47 | 2022-02-08 12:16:46 +0800 | [diff] [blame] | 356 | public @FrameDuration int getFrameDuration() { |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 357 | return mFrameDuration; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * Returns the octets per frame |
| 362 | */ |
| Patty | 3a61c47 | 2022-02-08 12:16:46 +0800 | [diff] [blame] | 363 | public int getOctetsPerFrame() { |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 364 | return mOctetsPerFrame; |
| 365 | } |
| 366 | |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 367 | /** |
| 368 | * Returns the minimum octets per frame |
| 369 | */ |
| 370 | public int getMinOctetsPerFrame() { |
| 371 | return mMinOctetsPerFrame; |
| 372 | } |
| 373 | |
| 374 | /** |
| 375 | * Returns the maximum octets per frame |
| 376 | */ |
| 377 | public int getMaxOctetsPerFrame() { |
| 378 | return mMaxOctetsPerFrame; |
| 379 | } |
| 380 | |
| Patty | 5aa4bd2 | 2022-01-25 19:58:37 +0800 | [diff] [blame] | 381 | @Override |
| Anton Hansson | fa927a5 | 2023-11-09 09:08:19 +0000 | [diff] [blame^] | 382 | public boolean equals(@Nullable Object o) { |
| Patty | 5aa4bd2 | 2022-01-25 19:58:37 +0800 | [diff] [blame] | 383 | if (o instanceof BluetoothLeAudioCodecConfig) { |
| 384 | BluetoothLeAudioCodecConfig other = (BluetoothLeAudioCodecConfig) o; |
| 385 | return (other.getCodecType() == mCodecType |
| 386 | && other.getCodecPriority() == mCodecPriority |
| 387 | && other.getSampleRate() == mSampleRate |
| 388 | && other.getBitsPerSample() == mBitsPerSample |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 389 | && other.getChannelCount() == mChannelCount |
| Patty | 5aa4bd2 | 2022-01-25 19:58:37 +0800 | [diff] [blame] | 390 | && other.getFrameDuration() == mFrameDuration |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 391 | && other.getOctetsPerFrame() == mOctetsPerFrame |
| 392 | && other.getMinOctetsPerFrame() == mMinOctetsPerFrame |
| 393 | && other.getMaxOctetsPerFrame() == mMaxOctetsPerFrame); |
| Patty | 5aa4bd2 | 2022-01-25 19:58:37 +0800 | [diff] [blame] | 394 | } |
| 395 | return false; |
| 396 | } |
| 397 | |
| 398 | /** |
| 399 | * Returns a hash representation of this BluetoothLeAudioCodecConfig |
| 400 | * based on all the config values. |
| 401 | */ |
| 402 | @Override |
| 403 | public int hashCode() { |
| 404 | return Objects.hash(mCodecType, mCodecPriority, mSampleRate, |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 405 | mBitsPerSample, mChannelCount, mFrameDuration, mOctetsPerFrame, |
| 406 | mMinOctetsPerFrame, mMaxOctetsPerFrame); |
| Patty | 5aa4bd2 | 2022-01-25 19:58:37 +0800 | [diff] [blame] | 407 | } |
| 408 | |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 409 | /** |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 410 | * Builder for {@link BluetoothLeAudioCodecConfig}. |
| 411 | * <p> By default, the codec type will be set to |
| 412 | * {@link BluetoothLeAudioCodecConfig#SOURCE_CODEC_TYPE_INVALID} |
| 413 | */ |
| 414 | public static final class Builder { |
| 415 | private int mCodecType = BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 416 | private int mCodecPriority = BluetoothLeAudioCodecConfig.CODEC_PRIORITY_DEFAULT; |
| 417 | private int mSampleRate = BluetoothLeAudioCodecConfig.SAMPLE_RATE_NONE; |
| 418 | private int mBitsPerSample = BluetoothLeAudioCodecConfig.BITS_PER_SAMPLE_NONE; |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 419 | private int mChannelCount = BluetoothLeAudioCodecConfig.CHANNEL_COUNT_NONE; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 420 | private int mFrameDuration = BluetoothLeAudioCodecConfig.FRAME_DURATION_NONE; |
| 421 | private int mOctetsPerFrame = 0; |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 422 | private int mMinOctetsPerFrame = 0; |
| 423 | private int mMaxOctetsPerFrame = 0; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 424 | |
| 425 | public Builder() {} |
| 426 | |
| 427 | public Builder(@NonNull BluetoothLeAudioCodecConfig config) { |
| 428 | mCodecType = config.getCodecType(); |
| 429 | mCodecPriority = config.getCodecPriority(); |
| 430 | mSampleRate = config.getSampleRate(); |
| 431 | mBitsPerSample = config.getBitsPerSample(); |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 432 | mChannelCount = config.getChannelCount(); |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 433 | mFrameDuration = config.getFrameDuration(); |
| 434 | mOctetsPerFrame = config.getOctetsPerFrame(); |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 435 | mMinOctetsPerFrame = config.getMinOctetsPerFrame(); |
| 436 | mMaxOctetsPerFrame = config.getMaxOctetsPerFrame(); |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 437 | } |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 438 | |
| 439 | /** |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 440 | * Set codec type for Bluetooth LE audio codec config. |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 441 | * |
| 442 | * @param codecType of this codec |
| 443 | * @return the same Builder instance |
| 444 | */ |
| 445 | public @NonNull Builder setCodecType(@SourceCodecType int codecType) { |
| 446 | mCodecType = codecType; |
| 447 | return this; |
| 448 | } |
| 449 | |
| 450 | /** |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 451 | * Set codec priority for Bluetooth LE audio codec config. |
| 452 | * |
| 453 | * @param codecPriority of this codec |
| 454 | * @return the same Builder instance |
| 455 | */ |
| 456 | public @NonNull Builder setCodecPriority(@CodecPriority int codecPriority) { |
| 457 | mCodecPriority = codecPriority; |
| 458 | return this; |
| 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Set sample rate for Bluetooth LE audio codec config. |
| 463 | * |
| 464 | * @param sampleRate of this codec |
| 465 | * @return the same Builder instance |
| 466 | */ |
| 467 | public @NonNull Builder setSampleRate(@SampleRate int sampleRate) { |
| 468 | mSampleRate = sampleRate; |
| 469 | return this; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Set the bits per sample for LE audio codec config. |
| 474 | * |
| 475 | * @param bitsPerSample of this codec |
| 476 | * @return the same Builder instance |
| 477 | */ |
| 478 | public @NonNull Builder setBitsPerSample(@BitsPerSample int bitsPerSample) { |
| 479 | mBitsPerSample = bitsPerSample; |
| 480 | return this; |
| 481 | } |
| 482 | |
| 483 | /** |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 484 | * Set the channel count for Bluetooth LE audio codec config. |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 485 | * |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 486 | * @param channelCount of this codec |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 487 | * @return the same Builder instance |
| 488 | */ |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 489 | public @NonNull Builder setChannelCount(@ChannelCount int channelCount) { |
| 490 | mChannelCount = channelCount; |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 491 | return this; |
| 492 | } |
| 493 | |
| 494 | /** |
| 495 | * Set the frame duration for Bluetooth LE audio codec config. |
| 496 | * |
| 497 | * @param frameDuration of this codec |
| 498 | * @return the same Builder instance |
| 499 | */ |
| 500 | public @NonNull Builder setFrameDuration(@FrameDuration int frameDuration) { |
| 501 | mFrameDuration = frameDuration; |
| 502 | return this; |
| 503 | } |
| 504 | |
| 505 | /** |
| 506 | * Set the octets per frame for Bluetooth LE audio codec config. |
| 507 | * |
| 508 | * @param octetsPerFrame of this codec |
| 509 | * @return the same Builder instance |
| 510 | */ |
| 511 | public @NonNull Builder setOctetsPerFrame(int octetsPerFrame) { |
| 512 | mOctetsPerFrame = octetsPerFrame; |
| 513 | return this; |
| 514 | } |
| 515 | |
| 516 | /** |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 517 | * Set the minimum octets per frame for Bluetooth LE audio codec config. |
| 518 | * |
| 519 | * @param minOctetsPerFrame of this codec |
| 520 | * @return the same Builder instance |
| 521 | */ |
| 522 | public @NonNull Builder setMinOctetsPerFrame(int minOctetsPerFrame) { |
| 523 | mMinOctetsPerFrame = minOctetsPerFrame; |
| 524 | return this; |
| 525 | } |
| 526 | |
| 527 | /** |
| 528 | * Set the maximum octets per frame for Bluetooth LE audio codec config. |
| 529 | * |
| 530 | * @param maxOctetsPerFrame of this codec |
| 531 | * @return the same Builder instance |
| 532 | */ |
| 533 | public @NonNull Builder setMaxOctetsPerFrame(int maxOctetsPerFrame) { |
| 534 | mMaxOctetsPerFrame = maxOctetsPerFrame; |
| 535 | return this; |
| 536 | } |
| 537 | |
| 538 | /** |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 539 | * Build {@link BluetoothLeAudioCodecConfig}. |
| 540 | * @return new BluetoothLeAudioCodecConfig built |
| 541 | */ |
| 542 | public @NonNull BluetoothLeAudioCodecConfig build() { |
| Patty | d8c4927 | 2022-01-19 16:26:00 +0800 | [diff] [blame] | 543 | return new BluetoothLeAudioCodecConfig(mCodecType, mCodecPriority, mSampleRate, |
| Łukasz Rymanowski | 3c97945 | 2022-03-10 10:28:12 +0000 | [diff] [blame] | 544 | mBitsPerSample, mChannelCount, mFrameDuration, mOctetsPerFrame, |
| 545 | mMinOctetsPerFrame, mMaxOctetsPerFrame); |
| Patty | 5c05c2f | 2021-11-04 21:03:32 +0800 | [diff] [blame] | 546 | } |
| 547 | } |
| 548 | } |