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 BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat)35 public BluetoothAudioConfig(int sampleRate, int channelConfig, int audioFormat) { 36 mSampleRate = sampleRate; 37 mChannelConfig = channelConfig; 38 mAudioFormat = audioFormat; 39 } 40 41 @Override equals(Object o)42 public boolean equals(Object o) { 43 if (o instanceof BluetoothAudioConfig) { 44 BluetoothAudioConfig bac = (BluetoothAudioConfig)o; 45 return (bac.mSampleRate == mSampleRate && 46 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 describeContents()63 public int describeContents() { 64 return 0; 65 } 66 67 public static final Parcelable.Creator<BluetoothAudioConfig> CREATOR = 68 new Parcelable.Creator<BluetoothAudioConfig>() { 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 public BluetoothAudioConfig[] newArray(int size) { 76 return new BluetoothAudioConfig[size]; 77 } 78 }; 79 writeToParcel(Parcel out, int flags)80 public void writeToParcel(Parcel out, int flags) { 81 out.writeInt(mSampleRate); 82 out.writeInt(mChannelConfig); 83 out.writeInt(mAudioFormat); 84 } 85 86 /** 87 * Returns the sample rate in samples per second 88 * @return sample rate 89 */ getSampleRate()90 public int getSampleRate() { 91 return mSampleRate; 92 } 93 94 /** 95 * Returns the channel configuration (either {@link android.media.AudioFormat#CHANNEL_IN_MONO} 96 * or {@link android.media.AudioFormat#CHANNEL_IN_STEREO}) 97 * @return channel configuration 98 */ getChannelConfig()99 public int getChannelConfig() { 100 return mChannelConfig; 101 } 102 103 /** 104 * Returns the channel audio format (either {@link android.media.AudioFormat#ENCODING_PCM_16BIT} 105 * or {@link android.media.AudioFormat#ENCODING_PCM_8BIT} 106 * @return audio format 107 */ getAudioFormat()108 public int getAudioFormat() { 109 return mAudioFormat; 110 } 111 } 112