blob: 0fcaf1677ef9ffea4260abaa20729bcae90d1090 [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
19import android.annotation.IntDef;
20import android.annotation.NonNull;
Anton Hanssonfa927a52023-11-09 09:08:19 +000021import android.annotation.Nullable;
Pattyd8c49272022-01-19 16:26:00 +080022import android.os.Parcel;
23import android.os.Parcelable;
Patty5c05c2f2021-11-04 21:03:32 +080024
25import java.lang.annotation.Retention;
26import java.lang.annotation.RetentionPolicy;
Patty5aa4bd22022-01-25 19:58:37 +080027import java.util.Objects;
Patty5c05c2f2021-11-04 21:03:32 +080028
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 */
Pattyd8c49272022-01-19 16:26:00 +080037public final class BluetoothLeAudioCodecConfig implements Parcelable {
Patty5c05c2f2021-11-04 21:03:32 +080038 // 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
Pattyd8c49272022-01-19 16:26:00 +080051 /** @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 Rymanowski3c979452022-03-10 10:28:12 +000076 @IntDef(flag = true, prefix = "SAMPLE_RATE_",
Pattyd8c49272022-01-19 16:26:00 +080077 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 Rymanowski3c979452022-03-10 10:28:12 +000085 * 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.
Pattyd8c49272022-01-19 16:26:00 +080089 */
90 public static final int SAMPLE_RATE_NONE = 0;
91
92 /**
93 * Codec sample rate 8000 Hz.
94 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +000095 public static final int SAMPLE_RATE_8000 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +080096
97 /**
98 * Codec sample rate 16000 Hz.
99 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000100 public static final int SAMPLE_RATE_16000 = 0x01 << 2;
Pattyd8c49272022-01-19 16:26:00 +0800101
102 /**
103 * Codec sample rate 24000 Hz.
104 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000105 public static final int SAMPLE_RATE_24000 = 0x01 << 4;
Pattyd8c49272022-01-19 16:26:00 +0800106
107 /**
108 * Codec sample rate 32000 Hz.
109 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000110 public static final int SAMPLE_RATE_32000 = 0x01 << 5;
Pattyd8c49272022-01-19 16:26:00 +0800111
112 /**
113 * Codec sample rate 44100 Hz.
114 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000115 public static final int SAMPLE_RATE_44100 = 0x01 << 6;
Pattyd8c49272022-01-19 16:26:00 +0800116
117 /**
118 * Codec sample rate 48000 Hz.
119 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000120 public static final int SAMPLE_RATE_48000 = 0x01 << 7;
Pattyd8c49272022-01-19 16:26:00 +0800121
122 /** @hide */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000123 @IntDef(flag = true, prefix = "BITS_PER_SAMPLE_",
Pattyd8c49272022-01-19 16:26:00 +0800124 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 Rymanowski3c979452022-03-10 10:28:12 +0000138 public static final int BITS_PER_SAMPLE_16 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800139
140 /**
141 * Codec bits per sample 24.
142 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000143 public static final int BITS_PER_SAMPLE_24 = 0x01 << 1;
Pattyd8c49272022-01-19 16:26:00 +0800144
145 /**
146 * Codec bits per sample 32.
147 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000148 public static final int BITS_PER_SAMPLE_32 = 0x01 << 3;
Pattyd8c49272022-01-19 16:26:00 +0800149
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000150 /**
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})
Pattyd8c49272022-01-19 16:26:00 +0800158 @Retention(RetentionPolicy.SOURCE)
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000159 public @interface ChannelCount {}
Pattyd8c49272022-01-19 16:26:00 +0800160
161 /**
162 * Codec channel mode NONE. Default value of the
163 * codec channel mode.
164 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000165 public static final int CHANNEL_COUNT_NONE = 0;
Pattyd8c49272022-01-19 16:26:00 +0800166
167 /**
168 * Codec channel mode MONO.
169 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000170 public static final int CHANNEL_COUNT_1 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800171
172 /**
173 * Codec channel mode STEREO.
174 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000175 public static final int CHANNEL_COUNT_2 = 0x01 << 1;
Pattyd8c49272022-01-19 16:26:00 +0800176
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000177 /**
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_",
Pattyd8c49272022-01-19 16:26:00 +0800184 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 Rymanowski3c979452022-03-10 10:28:12 +0000196 public static final int FRAME_DURATION_7500 = 0x01 << 0;
Pattyd8c49272022-01-19 16:26:00 +0800197
198 /**
199 * Frame duration 10000 us.
200 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000201 public static final int FRAME_DURATION_10000 = 0x01 << 1;
Pattyd8c49272022-01-19 16:26:00 +0800202
Patty5c05c2f2021-11-04 21:03:32 +0800203 private final @SourceCodecType int mCodecType;
Pattyd8c49272022-01-19 16:26:00 +0800204 private final @CodecPriority int mCodecPriority;
205 private final @SampleRate int mSampleRate;
206 private final @BitsPerSample int mBitsPerSample;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000207 private final @ChannelCount int mChannelCount;
Pattyd8c49272022-01-19 16:26:00 +0800208 private final @FrameDuration int mFrameDuration;
209 private final int mOctetsPerFrame;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000210 private final int mMinOctetsPerFrame;
211 private final int mMaxOctetsPerFrame;
212
Patty5c05c2f2021-11-04 21:03:32 +0800213
214 /**
215 * Creates a new BluetoothLeAudioCodecConfig.
216 *
217 * @param codecType the source codec type
Pattyd8c49272022-01-19 16:26:00 +0800218 * @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 Rymanowski3c979452022-03-10 10:28:12 +0000221 * @param channelCount the channel count of this codec
Pattyd8c49272022-01-19 16:26:00 +0800222 * @param frameDuration the frame duration of this codec
223 * @param octetsPerFrame the octets per frame of this codec
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000224 * @param minOctetsPerFrame the minimum octets per frame of this codec
225 * @param maxOctetsPerFrame the maximum octets per frame of this codec
Patty5c05c2f2021-11-04 21:03:32 +0800226 */
Pattyd8c49272022-01-19 16:26:00 +0800227 private BluetoothLeAudioCodecConfig(@SourceCodecType int codecType,
228 @CodecPriority int codecPriority, @SampleRate int sampleRate,
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000229 @BitsPerSample int bitsPerSample, @ChannelCount int channelCount,
230 @FrameDuration int frameDuration, int octetsPerFrame,
231 int minOctetsPerFrame, int maxOctetsPerFrame) {
Patty5c05c2f2021-11-04 21:03:32 +0800232 mCodecType = codecType;
Pattyd8c49272022-01-19 16:26:00 +0800233 mCodecPriority = codecPriority;
234 mSampleRate = sampleRate;
235 mBitsPerSample = bitsPerSample;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000236 mChannelCount = channelCount;
Pattyd8c49272022-01-19 16:26:00 +0800237 mFrameDuration = frameDuration;
238 mOctetsPerFrame = octetsPerFrame;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000239 mMinOctetsPerFrame = minOctetsPerFrame;
240 mMaxOctetsPerFrame = maxOctetsPerFrame;
Pattyd8c49272022-01-19 16:26:00 +0800241 }
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 Rymanowski3c979452022-03-10 10:28:12 +0000259 int channelCount = in.readInt();
Pattyd8c49272022-01-19 16:26:00 +0800260 int frameDuration = in.readInt();
261 int octetsPerFrame = in.readInt();
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000262 int minOctetsPerFrame = in.readInt();
263 int maxOctetsPerFrame = in.readInt();
Pattyd8c49272022-01-19 16:26:00 +0800264 return new BluetoothLeAudioCodecConfig(codecType, codecPriority, sampleRate,
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000265 bitsPerSample, channelCount, frameDuration, octetsPerFrame,
266 minOctetsPerFrame, maxOctetsPerFrame);
Pattyd8c49272022-01-19 16:26:00 +0800267 }
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 Rymanowski3c979452022-03-10 10:28:12 +0000280 out.writeInt(mChannelCount);
Pattyd8c49272022-01-19 16:26:00 +0800281 out.writeInt(mFrameDuration);
282 out.writeInt(mOctetsPerFrame);
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000283 out.writeInt(mMinOctetsPerFrame);
284 out.writeInt(mMaxOctetsPerFrame);
Patty5c05c2f2021-11-04 21:03:32 +0800285 }
286
287 @Override
288 public String toString() {
Pattyd8c49272022-01-19 16:26:00 +0800289 return "{codecName:" + getCodecName() + ",mCodecType:" + mCodecType
290 + ",mCodecPriority:" + mCodecPriority + ",mSampleRate:" + mSampleRate
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000291 + ",mBitsPerSample:" + mBitsPerSample + ",mChannelCount:" + mChannelCount
292 + ",mFrameDuration:" + mFrameDuration + ",mOctetsPerFrame:" + mOctetsPerFrame
293 + ",mMinOctetsPerFrame:" + mMinOctetsPerFrame
294 + ",mMaxOctetsPerFrame:" + mMaxOctetsPerFrame + "}";
Patty5c05c2f2021-11-04 21:03:32 +0800295 }
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 /**
Patty5c05c2f2021-11-04 21:03:32 +0800307 * 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 /**
Pattyd8c49272022-01-19 16:26:00 +0800324 * 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 Rymanowski3c979452022-03-10 10:28:12 +0000349 public @ChannelCount int getChannelCount() {
350 return mChannelCount;
Pattyd8c49272022-01-19 16:26:00 +0800351 }
352
353 /**
354 * Returns the frame duration.
355 */
Patty3a61c472022-02-08 12:16:46 +0800356 public @FrameDuration int getFrameDuration() {
Pattyd8c49272022-01-19 16:26:00 +0800357 return mFrameDuration;
358 }
359
360 /**
361 * Returns the octets per frame
362 */
Patty3a61c472022-02-08 12:16:46 +0800363 public int getOctetsPerFrame() {
Pattyd8c49272022-01-19 16:26:00 +0800364 return mOctetsPerFrame;
365 }
366
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000367 /**
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
Patty5aa4bd22022-01-25 19:58:37 +0800381 @Override
Anton Hanssonfa927a52023-11-09 09:08:19 +0000382 public boolean equals(@Nullable Object o) {
Patty5aa4bd22022-01-25 19:58:37 +0800383 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 Rymanowski3c979452022-03-10 10:28:12 +0000389 && other.getChannelCount() == mChannelCount
Patty5aa4bd22022-01-25 19:58:37 +0800390 && other.getFrameDuration() == mFrameDuration
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000391 && other.getOctetsPerFrame() == mOctetsPerFrame
392 && other.getMinOctetsPerFrame() == mMinOctetsPerFrame
393 && other.getMaxOctetsPerFrame() == mMaxOctetsPerFrame);
Patty5aa4bd22022-01-25 19:58:37 +0800394 }
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 Rymanowski3c979452022-03-10 10:28:12 +0000405 mBitsPerSample, mChannelCount, mFrameDuration, mOctetsPerFrame,
406 mMinOctetsPerFrame, mMaxOctetsPerFrame);
Patty5aa4bd22022-01-25 19:58:37 +0800407 }
408
Pattyd8c49272022-01-19 16:26:00 +0800409 /**
Patty5c05c2f2021-11-04 21:03:32 +0800410 * 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;
Pattyd8c49272022-01-19 16:26:00 +0800416 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 Rymanowski3c979452022-03-10 10:28:12 +0000419 private int mChannelCount = BluetoothLeAudioCodecConfig.CHANNEL_COUNT_NONE;
Pattyd8c49272022-01-19 16:26:00 +0800420 private int mFrameDuration = BluetoothLeAudioCodecConfig.FRAME_DURATION_NONE;
421 private int mOctetsPerFrame = 0;
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000422 private int mMinOctetsPerFrame = 0;
423 private int mMaxOctetsPerFrame = 0;
Pattyd8c49272022-01-19 16:26:00 +0800424
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 Rymanowski3c979452022-03-10 10:28:12 +0000432 mChannelCount = config.getChannelCount();
Pattyd8c49272022-01-19 16:26:00 +0800433 mFrameDuration = config.getFrameDuration();
434 mOctetsPerFrame = config.getOctetsPerFrame();
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000435 mMinOctetsPerFrame = config.getMinOctetsPerFrame();
436 mMaxOctetsPerFrame = config.getMaxOctetsPerFrame();
Pattyd8c49272022-01-19 16:26:00 +0800437 }
Patty5c05c2f2021-11-04 21:03:32 +0800438
439 /**
Pattyd8c49272022-01-19 16:26:00 +0800440 * Set codec type for Bluetooth LE audio codec config.
Patty5c05c2f2021-11-04 21:03:32 +0800441 *
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 /**
Pattyd8c49272022-01-19 16:26:00 +0800451 * 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 Rymanowski3c979452022-03-10 10:28:12 +0000484 * Set the channel count for Bluetooth LE audio codec config.
Pattyd8c49272022-01-19 16:26:00 +0800485 *
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000486 * @param channelCount of this codec
Pattyd8c49272022-01-19 16:26:00 +0800487 * @return the same Builder instance
488 */
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000489 public @NonNull Builder setChannelCount(@ChannelCount int channelCount) {
490 mChannelCount = channelCount;
Pattyd8c49272022-01-19 16:26:00 +0800491 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 Rymanowski3c979452022-03-10 10:28:12 +0000517 * 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 /**
Patty5c05c2f2021-11-04 21:03:32 +0800539 * Build {@link BluetoothLeAudioCodecConfig}.
540 * @return new BluetoothLeAudioCodecConfig built
541 */
542 public @NonNull BluetoothLeAudioCodecConfig build() {
Pattyd8c49272022-01-19 16:26:00 +0800543 return new BluetoothLeAudioCodecConfig(mCodecType, mCodecPriority, mSampleRate,
Łukasz Rymanowski3c979452022-03-10 10:28:12 +0000544 mBitsPerSample, mChannelCount, mFrameDuration, mOctetsPerFrame,
545 mMinOctetsPerFrame, mMaxOctetsPerFrame);
Patty5c05c2f2021-11-04 21:03:32 +0800546 }
547 }
548}