Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | package android.bluetooth; |
| 18 | |
| 19 | import android.os.Parcel; |
| 20 | import android.os.Parcelable; |
| 21 | |
| 22 | /** |
| 23 | * Represents the audio configuration for a Bluetooth A2DP source device. |
| 24 | * |
| 25 | * {@see BluetoothA2dpSink} |
| 26 | * |
| 27 | * {@hide} |
| 28 | */ |
| 29 | public 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 He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 44 | BluetoothAudioConfig bac = (BluetoothAudioConfig) o; |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 45 | return (bac.mSampleRate == mSampleRate && bac.mChannelConfig == mChannelConfig |
| 46 | && bac.mAudioFormat == mAudioFormat); |
Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 47 | } |
| 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 He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 62 | @Override |
Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 63 | public int describeContents() { |
| 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | public static final Parcelable.Creator<BluetoothAudioConfig> CREATOR = |
| 68 | new Parcelable.Creator<BluetoothAudioConfig>() { |
Jack He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 69 | 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 Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 80 | |
Jack He | 2992cd0 | 2017-08-22 21:21:23 -0700 | [diff] [blame] | 81 | @Override |
Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 82 | 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 He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 90 | * |
Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 91 | * @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 He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 100 | * |
Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 101 | * @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 He | a355e5e | 2017-08-22 16:06:54 -0700 | [diff] [blame] | 110 | * |
Mike Lockwood | 2263dd1 | 2014-05-14 09:51:30 -0700 | [diff] [blame] | 111 | * @return audio format |
| 112 | */ |
| 113 | public int getAudioFormat() { |
| 114 | return mAudioFormat; |
| 115 | } |
| 116 | } |