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.annotation.Nullable; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Represents the audio configuration for a Bluetooth A2DP source device. 25 * 26 * {@see BluetoothA2dpSink} 27 * 28 * {@hide} 29 */ 30 public final class BluetoothAudioConfig implements Parcelable { 31 32 private final int mSampleRate; 33 private final int mChannelConfig; 34 private final int mAudioFormat; 35 BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat)36 public BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat) { 37 mSampleRate = sampleRate; 38 mChannelConfig = channelConfig; 39 mAudioFormat = audioFormat; 40 } 41 42 @Override equals(@ullable Object o)43 public boolean equals(@Nullable Object o) { 44 if (o instanceof BluetoothAudioConfig) { 45 BluetoothAudioConfig bac = (BluetoothAudioConfig) o; 46 return (bac.mSampleRate == mSampleRate && bac.mChannelConfig == mChannelConfig 47 && bac.mAudioFormat == mAudioFormat); 48 } 49 return false; 50 } 51 52 @Override hashCode()53 public int hashCode() { 54 return mSampleRate | (mChannelConfig << 24) | (mAudioFormat << 28); 55 } 56 57 @Override toString()58 public String toString() { 59 return "{mSampleRate:" + mSampleRate + ",mChannelConfig:" + mChannelConfig 60 + ",mAudioFormat:" + mAudioFormat + "}"; 61 } 62 63 @Override describeContents()64 public int describeContents() { 65 return 0; 66 } 67 68 public static final @android.annotation.NonNull Parcelable.Creator<BluetoothAudioConfig> CREATOR = 69 new Parcelable.Creator<BluetoothAudioConfig>() { 70 public BluetoothAudioConfig createFromParcel(Parcel in) { 71 int sampleRate = in.readInt(); 72 int channelConfig = in.readInt(); 73 int audioFormat = in.readInt(); 74 return new BluetoothAudioConfig(sampleRate, channelConfig, audioFormat); 75 } 76 77 public BluetoothAudioConfig[] newArray(int size) { 78 return new BluetoothAudioConfig[size]; 79 } 80 }; 81 82 @Override writeToParcel(Parcel out, int flags)83 public void writeToParcel(Parcel out, int flags) { 84 out.writeInt(mSampleRate); 85 out.writeInt(mChannelConfig); 86 out.writeInt(mAudioFormat); 87 } 88 89 /** 90 * Returns the sample rate in samples per second 91 * 92 * @return sample rate 93 */ getSampleRate()94 public int getSampleRate() { 95 return mSampleRate; 96 } 97 98 /** 99 * Returns the channel configuration (either {@link android.media.AudioFormat#CHANNEL_IN_MONO} 100 * or {@link android.media.AudioFormat#CHANNEL_IN_STEREO}) 101 * 102 * @return channel configuration 103 */ getChannelConfig()104 public int getChannelConfig() { 105 return mChannelConfig; 106 } 107 108 /** 109 * Returns the channel audio format (either {@link android.media.AudioFormat#ENCODING_PCM_16BIT} 110 * or {@link android.media.AudioFormat#ENCODING_PCM_8BIT} 111 * 112 * @return audio format 113 */ getAudioFormat()114 public int getAudioFormat() { 115 return mAudioFormat; 116 } 117 } 118