• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 && bac.mChannelConfig == mChannelConfig
46                     && bac.mAudioFormat == mAudioFormat);
47         }
48         return false;
49     }
50 
51     @Override
hashCode()52     public int hashCode() {
53         return mSampleRate | (mChannelConfig << 24) | (mAudioFormat << 28);
54     }
55 
56     @Override
toString()57     public String toString() {
58         return "{mSampleRate:" + mSampleRate + ",mChannelConfig:" + mChannelConfig
59                 + ",mAudioFormat:" + mAudioFormat + "}";
60     }
61 
62     @Override
describeContents()63     public int describeContents() {
64         return 0;
65     }
66 
67     public static final @android.annotation.NonNull 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 
76                 public BluetoothAudioConfig[] newArray(int size) {
77                     return new BluetoothAudioConfig[size];
78                 }
79             };
80 
81     @Override
writeToParcel(Parcel out, int flags)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
90      *
91      * @return sample rate
92      */
getSampleRate()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})
100      *
101      * @return channel configuration
102      */
getChannelConfig()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}
110      *
111      * @return audio format
112      */
getAudioFormat()113     public int getAudioFormat() {
114         return mAudioFormat;
115     }
116 }
117