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.NonNull; 20 import android.annotation.Nullable; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * Represents the audio configuration for a Bluetooth A2DP source device. 26 * 27 * {@see BluetoothA2dpSink} 28 * 29 * {@hide} 30 */ 31 public final class BluetoothAudioConfig implements Parcelable { 32 33 private final int mSampleRate; 34 private final int mChannelConfig; 35 private final int mAudioFormat; 36 BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat)37 public BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat) { 38 mSampleRate = sampleRate; 39 mChannelConfig = channelConfig; 40 mAudioFormat = audioFormat; 41 } 42 43 @Override equals(@ullable Object o)44 public boolean equals(@Nullable Object o) { 45 if (o instanceof BluetoothAudioConfig) { 46 BluetoothAudioConfig bac = (BluetoothAudioConfig) o; 47 return (bac.mSampleRate == mSampleRate && bac.mChannelConfig == mChannelConfig 48 && bac.mAudioFormat == mAudioFormat); 49 } 50 return false; 51 } 52 53 @Override hashCode()54 public int hashCode() { 55 return mSampleRate | (mChannelConfig << 24) | (mAudioFormat << 28); 56 } 57 58 @Override toString()59 public String toString() { 60 return "{mSampleRate:" + mSampleRate + ",mChannelConfig:" + mChannelConfig 61 + ",mAudioFormat:" + mAudioFormat + "}"; 62 } 63 64 @Override describeContents()65 public int describeContents() { 66 return 0; 67 } 68 69 public static final @NonNull Creator<BluetoothAudioConfig> CREATOR = new Creator<>() { 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