blob: b0fa26c025d9ea6d88cab5328cc7f5df102d31c7 [file] [log] [blame]
Patty5c05c2f2021-11-04 21:03:32 +08001/*
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
17package android.bluetooth;
18
Sagar Vermacda6dbf2024-01-19 11:32:47 +053019import android.annotation.FlaggedApi;
Patty5c05c2f2021-11-04 21:03:32 +080020import android.annotation.IntDef;
21import android.annotation.NonNull;
Anton Hanssonfa927a52023-11-09 09:08:19 +000022import android.annotation.Nullable;
Pattyd8c49272022-01-19 16:26:00 +080023import android.os.Parcel;
24import android.os.Parcelable;
Patty5c05c2f2021-11-04 21:03:32 +080025
Sagar Vermacda6dbf2024-01-19 11:32:47 +053026import com.android.bluetooth.flags.Flags;
27
Patty5c05c2f2021-11-04 21:03:32 +080028import java.lang.annotation.Retention;
29import java.lang.annotation.RetentionPolicy;
Patty5aa4bd22022-01-25 19:58:37 +080030import java.util.Objects;
Patty5c05c2f2021-11-04 21:03:32 +080031
32/**
33 * Represents the codec configuration for a Bluetooth LE Audio source device.
Patty5c05c2f2021-11-04 21:03:32 +080034 *
David Duarteee52b7e2023-12-02 01:32:11 +000035 * <p>Contains the source codec type.
36 *
37 * <p>The source codec type values are the same as those supported by the device hardware.
38 *
David Duarte5a02bb42023-12-04 23:07:42 +000039 * @see BluetoothLeAudioCodecConfig
Patty5c05c2f2021-11-04 21:03:32 +080040 */
Pattyd8c49272022-01-19 16:26:00 +080041public final class BluetoothLeAudioCodecConfig implements Parcelable {
Patty5c05c2f2021-11-04 21:03:32 +080042 // Add an entry for each source codec here.
43
44 /** @hide */
David Duarteee52b7e2023-12-02 01:32:11 +000045 @IntDef(
46 prefix = "SOURCE_CODEC_TYPE_",
47 value = {SOURCE_CODEC_TYPE_LC3, SOURCE_CODEC_TYPE_INVALID})
Patty5c05c2f2021-11-04 21:03:32 +080048 @Retention(RetentionPolicy.SOURCE)
49 public @interface SourceCodecType {};
50
51 public static final int SOURCE_CODEC_TYPE_LC3 = 0;
52 public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000;
53
Pattyd8c49272022-01-19 16:26:00 +080054 /** @hide */
David Duarteee52b7e2023-12-02 01:32:11 +000055 @IntDef(
56 prefix = "CODEC_PRIORITY_",
Pattyd8c49272022-01-19 16:26:00 +080057 value = {CODEC_PRIORITY_DISABLED, CODEC_PRIORITY_DEFAULT, CODEC_PRIORITY_HIGHEST})
58 @Retention(RetentionPolicy.SOURCE)
59 public @interface CodecPriority {}
60
61 /**
David Duarteee52b7e2023-12-02 01:32:11 +000062 * Codec priority disabled. Used to indicate that this codec is disabled and should not be used.
Pattyd8c49272022-01-19 16:26:00 +080063 */
64 public static final int CODEC_PRIORITY_DISABLED = -1;
65
David Duarteee52b7e2023-12-02 01:32:11 +000066 /** Codec priority default. Default value used for codec priority. */
Pattyd8c49272022-01-19 16:26:00 +080067 public static final int CODEC_PRIORITY_DEFAULT = 0;
68
David Duarteee52b7e2023-12-02 01:32:11 +000069 /** Codec priority highest. Used to indicate the highest priority a codec can have. */
Pattyd8c49272022-01-19 16:26:00 +080070 public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000;
71
72 /** @hide */
David Duarteee52b7e2023-12-02 01:32:11 +000073 @IntDef(
74 flag = true,
75 prefix = "SAMPLE_RATE_",
76 value = {
77 SAMPLE_RATE_NONE,
78 SAMPLE_RATE_8000,
Sagar Vermacda6dbf2024-01-19 11:32:47 +053079 SAMPLE_RATE_11025,
David Duarteee52b7e2023-12-02 01:32:11 +000080 SAMPLE_RATE_16000,
Sagar Vermacda6dbf2024-01-19 11:32:47 +053081 SAMPLE_RATE_22050,
David Duarteee52b7e2023-12-02 01:32:11 +000082 SAMPLE_RATE_24000,
83 SAMPLE_RATE_32000,
84 SAMPLE_RATE_44100,
Sagar Vermacda6dbf2024-01-19 11:32:47 +053085 SAMPLE_RATE_48000,
86 SAMPLE_RATE_88200,
87 SAMPLE_RATE_96000,
88 SAMPLE_RATE_176400,
89 SAMPLE_RATE_192000,
90 SAMPLE_RATE_384000
David Duarteee52b7e2023-12-02 01:32:11 +000091 })
Pattyd8c49272022-01-19 16:26:00 +080092 @Retention(RetentionPolicy.SOURCE)
93 public @interface SampleRate {}
94
95 /**
David Duarteee52b7e2023-12-02 01:32:11 +000096 * Codec sample rate 0 Hz. Default value used for codec sample rate. Values are the bit mask as
97 * defined in the Bluetooth Assigned Numbers, Generic Audio, Supported_Sampling_Frequencies
Sagar Vermacda6dbf2024-01-19 11:32:47 +053098 * table.
Pattyd8c49272022-01-19 16:26:00 +080099 */
100 public static final int SAMPLE_RATE_NONE = 0;
101
David Duarteee52b7e2023-12-02 01:32:11 +0000102 /** Codec sample rate 8000 Hz. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000103 public static final int SAMPLE_RATE_8000 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800104
Sagar Vermacda6dbf2024-01-19 11:32:47 +0530105 /** Codec sample rate 11025 Hz. */
106 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
107 public static final int SAMPLE_RATE_11025 = 0x01 << 1;
108
David Duarteee52b7e2023-12-02 01:32:11 +0000109 /** Codec sample rate 16000 Hz. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000110 public static final int SAMPLE_RATE_16000 = 0x01 << 2;
Pattyd8c49272022-01-19 16:26:00 +0800111
Sagar Vermacda6dbf2024-01-19 11:32:47 +0530112 /** Codec sample rate 22050 Hz. */
113 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
114 public static final int SAMPLE_RATE_22050 = 0x01 << 3;
115
David Duarteee52b7e2023-12-02 01:32:11 +0000116 /** Codec sample rate 24000 Hz. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000117 public static final int SAMPLE_RATE_24000 = 0x01 << 4;
Pattyd8c49272022-01-19 16:26:00 +0800118
David Duarteee52b7e2023-12-02 01:32:11 +0000119 /** Codec sample rate 32000 Hz. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000120 public static final int SAMPLE_RATE_32000 = 0x01 << 5;
Pattyd8c49272022-01-19 16:26:00 +0800121
David Duarteee52b7e2023-12-02 01:32:11 +0000122 /** Codec sample rate 44100 Hz. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000123 public static final int SAMPLE_RATE_44100 = 0x01 << 6;
Pattyd8c49272022-01-19 16:26:00 +0800124
David Duarteee52b7e2023-12-02 01:32:11 +0000125 /** Codec sample rate 48000 Hz. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000126 public static final int SAMPLE_RATE_48000 = 0x01 << 7;
Pattyd8c49272022-01-19 16:26:00 +0800127
Sagar Vermacda6dbf2024-01-19 11:32:47 +0530128 /** Codec sample rate 88200 Hz. */
129 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
130 public static final int SAMPLE_RATE_88200 = 0x01 << 8;
131
132 /** Codec sample rate 96000 Hz. */
133 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
134 public static final int SAMPLE_RATE_96000 = 0x01 << 9;
135
136 /** Codec sample rate 176400 Hz. */
137 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
138 public static final int SAMPLE_RATE_176400 = 0x01 << 10;
139
140 /** Codec sample rate 192000 Hz. */
141 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
142 public static final int SAMPLE_RATE_192000 = 0x01 << 11;
143
144 /** Codec sample rate 384000 Hz. */
145 @FlaggedApi(Flags.FLAG_LEAUDIO_ADD_SAMPLING_FREQUENCIES)
146 public static final int SAMPLE_RATE_384000 = 0x01 << 12;
147
Pattyd8c49272022-01-19 16:26:00 +0800148 /** @hide */
David Duarteee52b7e2023-12-02 01:32:11 +0000149 @IntDef(
150 flag = true,
151 prefix = "BITS_PER_SAMPLE_",
152 value = {
153 BITS_PER_SAMPLE_NONE,
154 BITS_PER_SAMPLE_16,
155 BITS_PER_SAMPLE_24,
156 BITS_PER_SAMPLE_32
157 })
Pattyd8c49272022-01-19 16:26:00 +0800158 @Retention(RetentionPolicy.SOURCE)
159 public @interface BitsPerSample {}
160
David Duarteee52b7e2023-12-02 01:32:11 +0000161 /** Codec bits per sample 0. Default value of the codec bits per sample. */
Pattyd8c49272022-01-19 16:26:00 +0800162 public static final int BITS_PER_SAMPLE_NONE = 0;
163
David Duarteee52b7e2023-12-02 01:32:11 +0000164 /** Codec bits per sample 16. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000165 public static final int BITS_PER_SAMPLE_16 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800166
David Duarteee52b7e2023-12-02 01:32:11 +0000167 /** Codec bits per sample 24. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000168 public static final int BITS_PER_SAMPLE_24 = 0x01 << 1;
Pattyd8c49272022-01-19 16:26:00 +0800169
David Duarteee52b7e2023-12-02 01:32:11 +0000170 /** Codec bits per sample 32. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000171 public static final int BITS_PER_SAMPLE_32 = 0x01 << 3;
Pattyd8c49272022-01-19 16:26:00 +0800172
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000173 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000174 * Values are the bit mask as defined in the Bluetooth Assigned Numbers, Generic Audio,
175 * Supported_Audio_Channel_Counts table Note: We use only part of it.
176 *
177 * @hide
178 */
179 @IntDef(
180 flag = true,
181 prefix = "CHANNEL_COUNT_",
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000182 value = {CHANNEL_COUNT_NONE, CHANNEL_COUNT_1, CHANNEL_COUNT_2})
Pattyd8c49272022-01-19 16:26:00 +0800183 @Retention(RetentionPolicy.SOURCE)
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000184 public @interface ChannelCount {}
Pattyd8c49272022-01-19 16:26:00 +0800185
David Duarteee52b7e2023-12-02 01:32:11 +0000186 /** Codec channel mode NONE. Default value of the codec channel mode. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000187 public static final int CHANNEL_COUNT_NONE = 0;
Pattyd8c49272022-01-19 16:26:00 +0800188
David Duarteee52b7e2023-12-02 01:32:11 +0000189 /** Codec channel mode MONO. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000190 public static final int CHANNEL_COUNT_1 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800191
David Duarteee52b7e2023-12-02 01:32:11 +0000192 /** Codec channel mode STEREO. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000193 public static final int CHANNEL_COUNT_2 = 0x01 << 1;
Pattyd8c49272022-01-19 16:26:00 +0800194
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000195 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000196 * Values are the bit mask as defined in the Bluetooth Assigned Numbers, Generic Audio,
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000197 * Supported_Frame_Durations table
198 *
David Duarteee52b7e2023-12-02 01:32:11 +0000199 * @hide
200 */
201 @IntDef(
202 flag = true,
203 prefix = "FRAME_DURATION_",
Pattyd8c49272022-01-19 16:26:00 +0800204 value = {FRAME_DURATION_NONE, FRAME_DURATION_7500, FRAME_DURATION_10000})
205 @Retention(RetentionPolicy.SOURCE)
206 public @interface FrameDuration {}
207
David Duarteee52b7e2023-12-02 01:32:11 +0000208 /** Frame duration 0. Default value of the frame duration. */
Pattyd8c49272022-01-19 16:26:00 +0800209 public static final int FRAME_DURATION_NONE = 0;
210
David Duarteee52b7e2023-12-02 01:32:11 +0000211 /** Frame duration 7500 us. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000212 public static final int FRAME_DURATION_7500 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800213
David Duarteee52b7e2023-12-02 01:32:11 +0000214 /** Frame duration 10000 us. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000215 public static final int FRAME_DURATION_10000 = 0x01 << 1;
Pattyd8c49272022-01-19 16:26:00 +0800216
Patty5c05c2f2021-11-04 21:03:32 +0800217 private final @SourceCodecType int mCodecType;
Pattyd8c49272022-01-19 16:26:00 +0800218 private final @CodecPriority int mCodecPriority;
219 private final @SampleRate int mSampleRate;
220 private final @BitsPerSample int mBitsPerSample;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000221 private final @ChannelCount int mChannelCount;
Pattyd8c49272022-01-19 16:26:00 +0800222 private final @FrameDuration int mFrameDuration;
223 private final int mOctetsPerFrame;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000224 private final int mMinOctetsPerFrame;
225 private final int mMaxOctetsPerFrame;
226
Patty5c05c2f2021-11-04 21:03:32 +0800227 /**
228 * Creates a new BluetoothLeAudioCodecConfig.
229 *
230 * @param codecType the source codec type
Pattyd8c49272022-01-19 16:26:00 +0800231 * @param codecPriority the priority of this codec
232 * @param sampleRate the codec sample rate
233 * @param bitsPerSample the bits per sample of this codec
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000234 * @param channelCount the channel count of this codec
Pattyd8c49272022-01-19 16:26:00 +0800235 * @param frameDuration the frame duration of this codec
236 * @param octetsPerFrame the octets per frame of this codec
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000237 * @param minOctetsPerFrame the minimum octets per frame of this codec
238 * @param maxOctetsPerFrame the maximum octets per frame of this codec
Patty5c05c2f2021-11-04 21:03:32 +0800239 */
David Duarteee52b7e2023-12-02 01:32:11 +0000240 private BluetoothLeAudioCodecConfig(
241 @SourceCodecType int codecType,
242 @CodecPriority int codecPriority,
243 @SampleRate int sampleRate,
244 @BitsPerSample int bitsPerSample,
245 @ChannelCount int channelCount,
246 @FrameDuration int frameDuration,
247 int octetsPerFrame,
248 int minOctetsPerFrame,
249 int maxOctetsPerFrame) {
Patty5c05c2f2021-11-04 21:03:32 +0800250 mCodecType = codecType;
Pattyd8c49272022-01-19 16:26:00 +0800251 mCodecPriority = codecPriority;
252 mSampleRate = sampleRate;
253 mBitsPerSample = bitsPerSample;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000254 mChannelCount = channelCount;
Pattyd8c49272022-01-19 16:26:00 +0800255 mFrameDuration = frameDuration;
256 mOctetsPerFrame = octetsPerFrame;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000257 mMinOctetsPerFrame = minOctetsPerFrame;
258 mMaxOctetsPerFrame = maxOctetsPerFrame;
Pattyd8c49272022-01-19 16:26:00 +0800259 }
260
261 @Override
262 public int describeContents() {
263 return 0;
264 }
265
David Duarteee52b7e2023-12-02 01:32:11 +0000266 /** {@link Parcelable.Creator} interface implementation. */
267 public static final @android.annotation.NonNull Parcelable.Creator<BluetoothLeAudioCodecConfig>
268 CREATOR =
269 new Parcelable.Creator<BluetoothLeAudioCodecConfig>() {
270 public BluetoothLeAudioCodecConfig createFromParcel(Parcel in) {
271 int codecType = in.readInt();
272 int codecPriority = in.readInt();
273 int sampleRate = in.readInt();
274 int bitsPerSample = in.readInt();
275 int channelCount = in.readInt();
276 int frameDuration = in.readInt();
277 int octetsPerFrame = in.readInt();
278 int minOctetsPerFrame = in.readInt();
279 int maxOctetsPerFrame = in.readInt();
280 return new BluetoothLeAudioCodecConfig(
281 codecType,
282 codecPriority,
283 sampleRate,
284 bitsPerSample,
285 channelCount,
286 frameDuration,
287 octetsPerFrame,
288 minOctetsPerFrame,
289 maxOctetsPerFrame);
290 }
Pattyd8c49272022-01-19 16:26:00 +0800291
David Duarteee52b7e2023-12-02 01:32:11 +0000292 public BluetoothLeAudioCodecConfig[] newArray(int size) {
293 return new BluetoothLeAudioCodecConfig[size];
294 }
295 };
Pattyd8c49272022-01-19 16:26:00 +0800296
297 @Override
298 public void writeToParcel(@NonNull Parcel out, int flags) {
299 out.writeInt(mCodecType);
300 out.writeInt(mCodecPriority);
301 out.writeInt(mSampleRate);
302 out.writeInt(mBitsPerSample);
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000303 out.writeInt(mChannelCount);
Pattyd8c49272022-01-19 16:26:00 +0800304 out.writeInt(mFrameDuration);
305 out.writeInt(mOctetsPerFrame);
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000306 out.writeInt(mMinOctetsPerFrame);
307 out.writeInt(mMaxOctetsPerFrame);
Patty5c05c2f2021-11-04 21:03:32 +0800308 }
309
Łukasz Rymanowski4b6c0d02024-04-22 15:02:02 +0000310 private String sampleRateToString(@SampleRate int sampleRateBit) {
311 switch (sampleRateBit) {
312 case SAMPLE_RATE_NONE:
313 return "None";
314 case SAMPLE_RATE_8000:
315 return "8 kHz";
316 case SAMPLE_RATE_11025:
317 return "11.025 kHz";
318 case SAMPLE_RATE_16000:
319 return "16 kHz";
320 case SAMPLE_RATE_22050:
321 return "22.05 kHz";
322 case SAMPLE_RATE_24000:
323 return "24 kHz";
324 case SAMPLE_RATE_32000:
325 return "32 kHz";
326 case SAMPLE_RATE_44100:
327 return "44.1 kHz";
328 case SAMPLE_RATE_48000:
329 return "48 kHz";
330 case SAMPLE_RATE_88200:
331 return "88.2 kHz";
332 case SAMPLE_RATE_96000:
333 return "96 kHz";
334 case SAMPLE_RATE_176400:
335 return "176.4 kHz";
336 case SAMPLE_RATE_192000:
337 return "192 kHz";
338 case SAMPLE_RATE_384000:
339 return "384 kHz";
340 default:
341 return "Unknown bit " + sampleRateBit;
342 }
343 }
344
345 private String frameDurationToString(@FrameDuration int frameDurationBit) {
346 switch (frameDurationBit) {
347 case FRAME_DURATION_NONE:
348 return "None";
349 case FRAME_DURATION_7500:
350 return "7.5 ms";
351 case FRAME_DURATION_10000:
352 return "10 ms";
353 default:
354 return "Unknown bit " + frameDurationBit;
355 }
356 }
357
Patty5c05c2f2021-11-04 21:03:32 +0800358 @Override
359 public String toString() {
David Duarteee52b7e2023-12-02 01:32:11 +0000360 return "{codecName:"
361 + getCodecName()
362 + ",mCodecType:"
363 + mCodecType
364 + ",mCodecPriority:"
365 + mCodecPriority
366 + ",mSampleRate:"
Łukasz Rymanowski4b6c0d02024-04-22 15:02:02 +0000367 + sampleRateToString(mSampleRate)
David Duarteee52b7e2023-12-02 01:32:11 +0000368 + ",mBitsPerSample:"
369 + mBitsPerSample
Łukasz Rymanowski4b6c0d02024-04-22 15:02:02 +0000370 + ",mChannelCountBitMask:"
David Duarteee52b7e2023-12-02 01:32:11 +0000371 + mChannelCount
372 + ",mFrameDuration:"
Łukasz Rymanowski4b6c0d02024-04-22 15:02:02 +0000373 + frameDurationToString(mFrameDuration)
David Duarteee52b7e2023-12-02 01:32:11 +0000374 + ",mOctetsPerFrame:"
375 + mOctetsPerFrame
376 + ",mMinOctetsPerFrame:"
377 + mMinOctetsPerFrame
378 + ",mMaxOctetsPerFrame:"
379 + mMaxOctetsPerFrame
380 + "}";
Patty5c05c2f2021-11-04 21:03:32 +0800381 }
382
383 /**
384 * Gets the codec type.
385 *
386 * @return the codec type
387 */
388 public @SourceCodecType int getCodecType() {
389 return mCodecType;
390 }
391
392 /**
Patty5c05c2f2021-11-04 21:03:32 +0800393 * Gets the codec name.
394 *
395 * @return the codec name
396 */
397 public @NonNull String getCodecName() {
398 switch (mCodecType) {
399 case SOURCE_CODEC_TYPE_LC3:
400 return "LC3";
401 case SOURCE_CODEC_TYPE_INVALID:
402 return "INVALID CODEC";
403 default:
404 break;
405 }
406 return "UNKNOWN CODEC(" + mCodecType + ")";
407 }
408
409 /**
Pattyd8c49272022-01-19 16:26:00 +0800410 * Returns the codec selection priority.
David Duarteee52b7e2023-12-02 01:32:11 +0000411 *
412 * <p>The codec selection priority is relative to other codecs: larger value means higher
413 * priority.
Pattyd8c49272022-01-19 16:26:00 +0800414 */
415 public @CodecPriority int getCodecPriority() {
416 return mCodecPriority;
417 }
418
David Duarteee52b7e2023-12-02 01:32:11 +0000419 /** Returns the codec sample rate. */
Pattyd8c49272022-01-19 16:26:00 +0800420 public @SampleRate int getSampleRate() {
421 return mSampleRate;
422 }
423
David Duarteee52b7e2023-12-02 01:32:11 +0000424 /** Returns the codec bits per sample. */
Pattyd8c49272022-01-19 16:26:00 +0800425 public @BitsPerSample int getBitsPerSample() {
426 return mBitsPerSample;
427 }
428
David Duarteee52b7e2023-12-02 01:32:11 +0000429 /** Returns the codec channel mode. */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000430 public @ChannelCount int getChannelCount() {
431 return mChannelCount;
Pattyd8c49272022-01-19 16:26:00 +0800432 }
433
David Duarteee52b7e2023-12-02 01:32:11 +0000434 /** Returns the frame duration. */
Patty3a61c472022-02-08 12:16:46 +0800435 public @FrameDuration int getFrameDuration() {
Pattyd8c49272022-01-19 16:26:00 +0800436 return mFrameDuration;
437 }
438
David Duarteee52b7e2023-12-02 01:32:11 +0000439 /** Returns the octets per frame */
Patty3a61c472022-02-08 12:16:46 +0800440 public int getOctetsPerFrame() {
Pattyd8c49272022-01-19 16:26:00 +0800441 return mOctetsPerFrame;
442 }
443
David Duarteee52b7e2023-12-02 01:32:11 +0000444 /** Returns the minimum octets per frame */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000445 public int getMinOctetsPerFrame() {
446 return mMinOctetsPerFrame;
447 }
448
David Duarteee52b7e2023-12-02 01:32:11 +0000449 /** Returns the maximum octets per frame */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000450 public int getMaxOctetsPerFrame() {
451 return mMaxOctetsPerFrame;
452 }
453
Patty5aa4bd22022-01-25 19:58:37 +0800454 @Override
Anton Hanssonfa927a52023-11-09 09:08:19 +0000455 public boolean equals(@Nullable Object o) {
Patty5aa4bd22022-01-25 19:58:37 +0800456 if (o instanceof BluetoothLeAudioCodecConfig) {
457 BluetoothLeAudioCodecConfig other = (BluetoothLeAudioCodecConfig) o;
458 return (other.getCodecType() == mCodecType
459 && other.getCodecPriority() == mCodecPriority
460 && other.getSampleRate() == mSampleRate
461 && other.getBitsPerSample() == mBitsPerSample
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000462 && other.getChannelCount() == mChannelCount
Patty5aa4bd22022-01-25 19:58:37 +0800463 && other.getFrameDuration() == mFrameDuration
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000464 && other.getOctetsPerFrame() == mOctetsPerFrame
465 && other.getMinOctetsPerFrame() == mMinOctetsPerFrame
466 && other.getMaxOctetsPerFrame() == mMaxOctetsPerFrame);
Patty5aa4bd22022-01-25 19:58:37 +0800467 }
468 return false;
469 }
470
471 /**
David Duarteee52b7e2023-12-02 01:32:11 +0000472 * Returns a hash representation of this BluetoothLeAudioCodecConfig based on all the config
473 * values.
Patty5aa4bd22022-01-25 19:58:37 +0800474 */
475 @Override
476 public int hashCode() {
David Duarteee52b7e2023-12-02 01:32:11 +0000477 return Objects.hash(
478 mCodecType,
479 mCodecPriority,
480 mSampleRate,
481 mBitsPerSample,
482 mChannelCount,
483 mFrameDuration,
484 mOctetsPerFrame,
485 mMinOctetsPerFrame,
486 mMaxOctetsPerFrame);
Patty5aa4bd22022-01-25 19:58:37 +0800487 }
488
Pattyd8c49272022-01-19 16:26:00 +0800489 /**
Patty5c05c2f2021-11-04 21:03:32 +0800490 * Builder for {@link BluetoothLeAudioCodecConfig}.
David Duarteee52b7e2023-12-02 01:32:11 +0000491 *
492 * <p>By default, the codec type will be set to {@link
493 * BluetoothLeAudioCodecConfig#SOURCE_CODEC_TYPE_INVALID}
Patty5c05c2f2021-11-04 21:03:32 +0800494 */
495 public static final class Builder {
496 private int mCodecType = BluetoothLeAudioCodecConfig.SOURCE_CODEC_TYPE_INVALID;
Pattyd8c49272022-01-19 16:26:00 +0800497 private int mCodecPriority = BluetoothLeAudioCodecConfig.CODEC_PRIORITY_DEFAULT;
498 private int mSampleRate = BluetoothLeAudioCodecConfig.SAMPLE_RATE_NONE;
499 private int mBitsPerSample = BluetoothLeAudioCodecConfig.BITS_PER_SAMPLE_NONE;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000500 private int mChannelCount = BluetoothLeAudioCodecConfig.CHANNEL_COUNT_NONE;
Pattyd8c49272022-01-19 16:26:00 +0800501 private int mFrameDuration = BluetoothLeAudioCodecConfig.FRAME_DURATION_NONE;
502 private int mOctetsPerFrame = 0;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000503 private int mMinOctetsPerFrame = 0;
504 private int mMaxOctetsPerFrame = 0;
Pattyd8c49272022-01-19 16:26:00 +0800505
506 public Builder() {}
507
508 public Builder(@NonNull BluetoothLeAudioCodecConfig config) {
509 mCodecType = config.getCodecType();
510 mCodecPriority = config.getCodecPriority();
511 mSampleRate = config.getSampleRate();
512 mBitsPerSample = config.getBitsPerSample();
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000513 mChannelCount = config.getChannelCount();
Pattyd8c49272022-01-19 16:26:00 +0800514 mFrameDuration = config.getFrameDuration();
515 mOctetsPerFrame = config.getOctetsPerFrame();
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000516 mMinOctetsPerFrame = config.getMinOctetsPerFrame();
517 mMaxOctetsPerFrame = config.getMaxOctetsPerFrame();
Pattyd8c49272022-01-19 16:26:00 +0800518 }
Patty5c05c2f2021-11-04 21:03:32 +0800519
520 /**
Pattyd8c49272022-01-19 16:26:00 +0800521 * Set codec type for Bluetooth LE audio codec config.
Patty5c05c2f2021-11-04 21:03:32 +0800522 *
523 * @param codecType of this codec
524 * @return the same Builder instance
525 */
526 public @NonNull Builder setCodecType(@SourceCodecType int codecType) {
527 mCodecType = codecType;
528 return this;
529 }
530
531 /**
Pattyd8c49272022-01-19 16:26:00 +0800532 * Set codec priority for Bluetooth LE audio codec config.
533 *
534 * @param codecPriority of this codec
535 * @return the same Builder instance
536 */
537 public @NonNull Builder setCodecPriority(@CodecPriority int codecPriority) {
538 mCodecPriority = codecPriority;
539 return this;
540 }
541
542 /**
543 * Set sample rate for Bluetooth LE audio codec config.
544 *
545 * @param sampleRate of this codec
546 * @return the same Builder instance
547 */
548 public @NonNull Builder setSampleRate(@SampleRate int sampleRate) {
549 mSampleRate = sampleRate;
550 return this;
551 }
552
553 /**
554 * Set the bits per sample for LE audio codec config.
555 *
556 * @param bitsPerSample of this codec
557 * @return the same Builder instance
558 */
559 public @NonNull Builder setBitsPerSample(@BitsPerSample int bitsPerSample) {
560 mBitsPerSample = bitsPerSample;
561 return this;
562 }
563
564 /**
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000565 * Set the channel count for Bluetooth LE audio codec config.
Pattyd8c49272022-01-19 16:26:00 +0800566 *
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000567 * @param channelCount of this codec
Pattyd8c49272022-01-19 16:26:00 +0800568 * @return the same Builder instance
569 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000570 public @NonNull Builder setChannelCount(@ChannelCount int channelCount) {
571 mChannelCount = channelCount;
Pattyd8c49272022-01-19 16:26:00 +0800572 return this;
573 }
574
575 /**
576 * Set the frame duration for Bluetooth LE audio codec config.
577 *
578 * @param frameDuration of this codec
579 * @return the same Builder instance
580 */
581 public @NonNull Builder setFrameDuration(@FrameDuration int frameDuration) {
582 mFrameDuration = frameDuration;
583 return this;
584 }
585
586 /**
587 * Set the octets per frame for Bluetooth LE audio codec config.
588 *
589 * @param octetsPerFrame of this codec
590 * @return the same Builder instance
591 */
592 public @NonNull Builder setOctetsPerFrame(int octetsPerFrame) {
593 mOctetsPerFrame = octetsPerFrame;
594 return this;
595 }
596
597 /**
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000598 * Set the minimum octets per frame for Bluetooth LE audio codec config.
599 *
600 * @param minOctetsPerFrame of this codec
601 * @return the same Builder instance
602 */
603 public @NonNull Builder setMinOctetsPerFrame(int minOctetsPerFrame) {
604 mMinOctetsPerFrame = minOctetsPerFrame;
605 return this;
606 }
607
608 /**
609 * Set the maximum octets per frame for Bluetooth LE audio codec config.
610 *
611 * @param maxOctetsPerFrame of this codec
612 * @return the same Builder instance
613 */
614 public @NonNull Builder setMaxOctetsPerFrame(int maxOctetsPerFrame) {
615 mMaxOctetsPerFrame = maxOctetsPerFrame;
616 return this;
617 }
618
619 /**
Patty5c05c2f2021-11-04 21:03:32 +0800620 * Build {@link BluetoothLeAudioCodecConfig}.
David Duarteee52b7e2023-12-02 01:32:11 +0000621 *
Patty5c05c2f2021-11-04 21:03:32 +0800622 * @return new BluetoothLeAudioCodecConfig built
623 */
624 public @NonNull BluetoothLeAudioCodecConfig build() {
David Duarteee52b7e2023-12-02 01:32:11 +0000625 return new BluetoothLeAudioCodecConfig(
626 mCodecType,
627 mCodecPriority,
628 mSampleRate,
629 mBitsPerSample,
630 mChannelCount,
631 mFrameDuration,
632 mOctetsPerFrame,
633 mMinOctetsPerFrame,
634 mMaxOctetsPerFrame);
Patty5c05c2f2021-11-04 21:03:32 +0800635 }
636 }
637}