blob: 52cd2de4c2b6371b8de73486af2e40af58183678 [file] [log] [blame]
Pavlin Radoslavov44a4ef02016-12-21 12:05:51 -08001/*
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
17package android.bluetooth;
18
19import android.os.Parcel;
20import android.os.Parcelable;
21
22import java.util.Objects;
23
24/**
25 * Represents the codec configuration for a Bluetooth A2DP source device.
26 *
27 * {@see BluetoothA2dp}
28 *
29 * {@hide}
30 */
31public final class BluetoothCodecConfig implements Parcelable {
32
33 /**
34 * Extra for the codec configuration intents of the individual profiles.
35 *
36 * This extra represents the current codec configuration of the A2DP
37 * profile.
38 */
39 public static final String EXTRA_CODEC_CONFIG = "android.bluetooth.codec.extra.CODEC_CONFIG";
40
41 /**
42 * Extra for the codec configuration intents of the individual profiles.
43 *
44 * This extra represents the previous codec configuration of the A2DP
45 * profile.
46 */
47 public static final String EXTRA_PREVIOUS_CODEC_CONFIG =
48 "android.bluetooth.codec.extra.PREVIOUS_CODEC_CONFIG";
49
Pavlin Radoslavovfeeb9b22017-01-04 16:10:09 -080050 // Add an entry for each source codec here.
51 // NOTE: The values should be same as those listed in the following file:
52 // hardware/libhardware/include/hardware/bt_av.h
Pavlin Radoslavov44a4ef02016-12-21 12:05:51 -080053 public static final int SOURCE_CODEC_TYPE_SBC = 0;
Pavlin Radoslavovfeeb9b22017-01-04 16:10:09 -080054 public static final int SOURCE_CODEC_TYPE_APTX = 1;
55 public static final int SOURCE_CODEC_TYPE_APTX_HD = 2;
Pavlin Radoslavovfad8b732017-01-04 16:47:02 -080056 public static final int SOURCE_CODEC_TYPE_LDAC = 3;
Pavlin Radoslavovfeeb9b22017-01-04 16:10:09 -080057
Pavlin Radoslavov44a4ef02016-12-21 12:05:51 -080058 public static final int SOURCE_CODEC_TYPE_INVALID = 1000 * 1000;
59
60 public static final int CODEC_PRIORITY_DEFAULT = 0;
61 public static final int CODEC_PRIORITY_HIGHEST = 1000 * 1000;
62
63 public static final int SAMPLE_RATE_NONE = 0;
64 public static final int SAMPLE_RATE_44100 = 0x1 << 0;
65 public static final int SAMPLE_RATE_48000 = 0x1 << 1;
66 public static final int SAMPLE_RATE_88200 = 0x1 << 2;
67 public static final int SAMPLE_RATE_96000 = 0x1 << 3;
68 public static final int SAMPLE_RATE_176400 = 0x1 << 4;
69 public static final int SAMPLE_RATE_192000 = 0x1 << 5;
70
71 public static final int BITS_PER_SAMPLE_NONE = 0;
72 public static final int BITS_PER_SAMPLE_16 = 0x1 << 0;
73 public static final int BITS_PER_SAMPLE_24 = 0x1 << 1;
74 public static final int BITS_PER_SAMPLE_32 = 0x1 << 2;
75
76 public static final int CHANNEL_MODE_NONE = 0;
77 public static final int CHANNEL_MODE_MONO = 0x1 << 0;
78 public static final int CHANNEL_MODE_STEREO = 0x1 << 1;
79
80 private final int mCodecType;
81 private final int mCodecPriority;
82 private final int mSampleRate;
83 private final int mBitsPerSample;
84 private final int mChannelMode;
85 private final long mCodecSpecific1;
86 private final long mCodecSpecific2;
87 private final long mCodecSpecific3;
88 private final long mCodecSpecific4;
89
90 public BluetoothCodecConfig(int codecType, int codecPriority,
91 int sampleRate, int bitsPerSample,
92 int channelMode,long codecSpecific1,
93 long codecSpecific2, long codecSpecific3,
94 long codecSpecific4) {
95 mCodecType = codecType;
96 mCodecPriority = codecPriority;
97 mSampleRate = sampleRate;
98 mBitsPerSample = bitsPerSample;
99 mChannelMode = channelMode;
100 mCodecSpecific1 = codecSpecific1;
101 mCodecSpecific2 = codecSpecific2;
102 mCodecSpecific3 = codecSpecific3;
103 mCodecSpecific4 = codecSpecific4;
104 }
105
106 @Override
107 public boolean equals(Object o) {
108 if (o instanceof BluetoothCodecConfig) {
109 BluetoothCodecConfig other = (BluetoothCodecConfig)o;
110 return (other.mCodecType == mCodecType &&
111 other.mCodecPriority == mCodecPriority &&
112 other.mSampleRate == mSampleRate &&
113 other.mBitsPerSample == mBitsPerSample &&
114 other.mChannelMode == mChannelMode &&
115 other.mCodecSpecific1 == mCodecSpecific1 &&
116 other.mCodecSpecific2 == mCodecSpecific2 &&
117 other.mCodecSpecific3 == mCodecSpecific3 &&
118 other.mCodecSpecific4 == mCodecSpecific4);
119 }
120 return false;
121 }
122
123 @Override
124 public int hashCode() {
125 return Objects.hash(mCodecType, mCodecPriority, mSampleRate,
126 mBitsPerSample, mChannelMode, mCodecSpecific1,
127 mCodecSpecific2, mCodecSpecific3, mCodecSpecific4);
128 }
129
130 @Override
131 public String toString() {
132 return "{mCodecType:" + mCodecType +
133 ",mCodecPriority:" + mCodecPriority +
134 ",mSampleRate:" + String.format("0x%x", mSampleRate) +
135 ",mBitsPerSample:" + String.format("0x%x", mBitsPerSample) +
136 ",mChannelMode:" + String.format("0x%x", mChannelMode) +
137 ",mCodecSpecific1:" + mCodecSpecific1 +
138 ",mCodecSpecific2:" + mCodecSpecific2 +
139 ",mCodecSpecific3:" + mCodecSpecific3 +
140 ",mCodecSpecific4:" + mCodecSpecific4 + "}";
141 }
142
143 public int describeContents() {
144 return 0;
145 }
146
147 public static final Parcelable.Creator<BluetoothCodecConfig> CREATOR =
148 new Parcelable.Creator<BluetoothCodecConfig>() {
149 public BluetoothCodecConfig createFromParcel(Parcel in) {
150 final int codecType = in.readInt();
151 final int codecPriority = in.readInt();
152 final int sampleRate = in.readInt();
153 final int bitsPerSample = in.readInt();
154 final int channelMode = in.readInt();
155 final long codecSpecific1 = in.readLong();
156 final long codecSpecific2 = in.readLong();
157 final long codecSpecific3 = in.readLong();
158 final long codecSpecific4 = in.readLong();
159 return new BluetoothCodecConfig(codecType, codecPriority,
160 sampleRate, bitsPerSample,
161 channelMode, codecSpecific1,
162 codecSpecific2, codecSpecific3,
163 codecSpecific4);
164 }
165 public BluetoothCodecConfig[] newArray(int size) {
166 return new BluetoothCodecConfig[size];
167 }
168 };
169
170 public void writeToParcel(Parcel out, int flags) {
171 out.writeInt(mCodecType);
172 out.writeInt(mCodecPriority);
173 out.writeInt(mSampleRate);
174 out.writeInt(mBitsPerSample);
175 out.writeInt(mChannelMode);
176 out.writeLong(mCodecSpecific1);
177 out.writeLong(mCodecSpecific2);
178 out.writeLong(mCodecSpecific3);
179 out.writeLong(mCodecSpecific4);
180 }
181
182 /**
183 * Returns the codec type.
184 * See {@link android.bluetooth.BluetoothCodecConfig#SOURCE_CODEC_TYPE_SBC}.
185 *
186 * @return the codec type
187 */
188 public int getCodecType() {
189 return mCodecType;
190 }
191
192 /**
193 * Returns the codec selection priority.
194 * The codec selection priority is relative to other codecs: larger value
195 * means higher priority. If 0, reset to default.
196 *
197 * @return the codec priority
198 */
199 public int getCodecPriority() {
200 return mCodecPriority;
201 }
202
203 /**
204 * Returns the codec sample rate. The value can be a bitmask with all
205 * supported sample rates:
206 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_NONE} or
207 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_44100} or
208 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_48000} or
209 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_88200} or
210 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_96000} or
211 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_176400} or
212 * {@link android.bluetooth.BluetoothCodecConfig#SAMPLE_RATE_192000}
213 *
214 * @return the codec sample rate
215 */
216 public int getSampleRate() {
217 return mSampleRate;
218 }
219
220 /**
221 * Returns the codec bits per sample. The value can be a bitmask with all
222 * bits per sample supported:
223 * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_NONE} or
224 * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_16} or
225 * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_24} or
226 * {@link android.bluetooth.BluetoothCodecConfig#BITS_PER_SAMPLE_32}
227 *
228 * @return the codec bits per sample
229 */
230 public int getBitsPerSample() {
231 return mBitsPerSample;
232 }
233
234 /**
235 * Returns the codec channel mode. The value can be a bitmask with all
236 * supported channel modes:
237 * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_NONE} or
238 * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_MONO} or
239 * {@link android.bluetooth.BluetoothCodecConfig#CHANNEL_MODE_STEREO}
240 *
241 * @return the codec channel mode
242 */
243 public int getChannelMode() {
244 return mChannelMode;
245 }
246
247 /**
248 * Returns a codec specific value1.
249 *
250 * @return a codec specific value1.
251 */
252 public long getCodecSpecific1() {
253 return mCodecSpecific1;
254 }
255
256 /**
257 * Returns a codec specific value2.
258 *
259 * @return a codec specific value2
260 */
261 public long getCodecSpecific2() {
262 return mCodecSpecific2;
263 }
264
265 /**
266 * Returns a codec specific value3.
267 *
268 * @return a codec specific value3
269 */
270 public long getCodecSpecific3() {
271 return mCodecSpecific3;
272 }
273
274 /**
275 * Returns a codec specific value4.
276 *
277 * @return a codec specific value4
278 */
279 public long getCodecSpecific4() {
280 return mCodecSpecific4;
281 }
282
283 /**
284 * Checks whether the audio feeding parameters are same.
285 *
286 * @param other the codec config to compare against
287 * @return true if the audio feeding parameters are same, otherwise false
288 */
289 public boolean sameAudioFeedingParameters(BluetoothCodecConfig other) {
290 return (other != null && other.mSampleRate == mSampleRate &&
291 other.mBitsPerSample == mBitsPerSample &&
292 other.mChannelMode == mChannelMode);
293 }
294}