blob: a4410563c99153f9de2dedc261ea6d9523e3883d [file] [log] [blame]
Mike Lockwood2263dd12014-05-14 09:51:30 -07001/*
2 * Copyright (C) 2009 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
22/**
23 * Represents the audio configuration for a Bluetooth A2DP source device.
24 *
25 * {@see BluetoothA2dpSink}
26 *
27 * {@hide}
28 */
29public final class BluetoothAudioConfig implements Parcelable {
30
31 private final int mSampleRate;
32 private final int mChannelConfig;
33 private final int mAudioFormat;
34
35 public BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat) {
36 mSampleRate = sampleRate;
37 mChannelConfig = channelConfig;
38 mAudioFormat = audioFormat;
39 }
40
41 @Override
42 public boolean equals(Object o) {
43 if (o instanceof BluetoothAudioConfig) {
Jack Hea355e5e2017-08-22 16:06:54 -070044 BluetoothAudioConfig bac = (BluetoothAudioConfig) o;
Jack He2992cd02017-08-22 21:21:23 -070045 return (bac.mSampleRate == mSampleRate && bac.mChannelConfig == mChannelConfig
46 && bac.mAudioFormat == mAudioFormat);
Mike Lockwood2263dd12014-05-14 09:51:30 -070047 }
48 return false;
49 }
50
51 @Override
52 public int hashCode() {
53 return mSampleRate | (mChannelConfig << 24) | (mAudioFormat << 28);
54 }
55
56 @Override
57 public String toString() {
58 return "{mSampleRate:" + mSampleRate + ",mChannelConfig:" + mChannelConfig
59 + ",mAudioFormat:" + mAudioFormat + "}";
60 }
61
Jack He2992cd02017-08-22 21:21:23 -070062 @Override
Mike Lockwood2263dd12014-05-14 09:51:30 -070063 public int describeContents() {
64 return 0;
65 }
66
67 public static final Parcelable.Creator<BluetoothAudioConfig> CREATOR =
68 new Parcelable.Creator<BluetoothAudioConfig>() {
Jack Hea355e5e2017-08-22 16:06:54 -070069 public BluetoothAudioConfig createFromParcel(Parcel in) {
70 int sampleRate = in.readInt();
71 int channelConfig = in.readInt();
72 int audioFormat = in.readInt();
73 return new BluetoothAudioConfig(sampleRate, channelConfig, audioFormat);
74 }
75
76 public BluetoothAudioConfig[] newArray(int size) {
77 return new BluetoothAudioConfig[size];
78 }
79 };
Mike Lockwood2263dd12014-05-14 09:51:30 -070080
Jack He2992cd02017-08-22 21:21:23 -070081 @Override
Mike Lockwood2263dd12014-05-14 09:51:30 -070082 public void writeToParcel(Parcel out, int flags) {
83 out.writeInt(mSampleRate);
84 out.writeInt(mChannelConfig);
85 out.writeInt(mAudioFormat);
86 }
87
88 /**
89 * Returns the sample rate in samples per second
Jack Hea355e5e2017-08-22 16:06:54 -070090 *
Mike Lockwood2263dd12014-05-14 09:51:30 -070091 * @return sample rate
92 */
93 public int getSampleRate() {
94 return mSampleRate;
95 }
96
97 /**
98 * Returns the channel configuration (either {@link android.media.AudioFormat#CHANNEL_IN_MONO}
99 * or {@link android.media.AudioFormat#CHANNEL_IN_STEREO})
Jack Hea355e5e2017-08-22 16:06:54 -0700100 *
Mike Lockwood2263dd12014-05-14 09:51:30 -0700101 * @return channel configuration
102 */
103 public int getChannelConfig() {
104 return mChannelConfig;
105 }
106
107 /**
108 * Returns the channel audio format (either {@link android.media.AudioFormat#ENCODING_PCM_16BIT}
109 * or {@link android.media.AudioFormat#ENCODING_PCM_8BIT}
Jack Hea355e5e2017-08-22 16:06:54 -0700110 *
Mike Lockwood2263dd12014-05-14 09:51:30 -0700111 * @return audio format
112 */
113 public int getAudioFormat() {
114 return mAudioFormat;
115 }
116}