1 /*
2  * Copyright (C) 2014 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.media;
18 
19 /**
20  * An AudioPortConfig contains a possible configuration of an audio port chosen
21  * among all possible attributes described by an AudioPort.
22  * An AudioPortConfig is created by AudioPort.buildConfiguration().
23  * AudioPorts are used to specify the sources and sinks of a patch created
24  * with AudioManager.connectAudioPatch().
25  * Several specialized versions of AudioPortConfig exist to handle different categories of
26  * audio ports and their specific attributes:
27  * - AudioDevicePortConfig for input (e.g micropohone) and output devices (e.g speaker)
28  * - AudioMixPortConfig for input or output streams of the audio framework.
29  * @hide
30  */
31 
32 public class AudioPortConfig {
33     final AudioPort mPort;
34     private final int mSamplingRate;
35     private final int mChannelMask;
36     private final int mFormat;
37     private final AudioGainConfig mGain;
38 
39     // mConfigMask indicates which fields in this configuration should be
40     // taken into account. Used with AudioSystem.setAudioPortConfig()
41     // framework use only.
42     static final int SAMPLE_RATE  = 0x1;
43     static final int CHANNEL_MASK = 0x2;
44     static final int FORMAT       = 0x4;
45     static final int GAIN         = 0x8;
46     int mConfigMask;
47 
AudioPortConfig(AudioPort port, int samplingRate, int channelMask, int format, AudioGainConfig gain)48     AudioPortConfig(AudioPort port, int samplingRate, int channelMask, int format,
49             AudioGainConfig gain) {
50         mPort = port;
51         mSamplingRate = samplingRate;
52         mChannelMask = channelMask;
53         mFormat = format;
54         mGain = gain;
55         mConfigMask = 0;
56     }
57 
58     /**
59      * Returns the audio port this AudioPortConfig is issued from.
60      */
port()61     public AudioPort port() {
62         return mPort;
63     }
64 
65     /**
66      * Sampling rate configured for this AudioPortConfig.
67      */
samplingRate()68     public int samplingRate() {
69         return mSamplingRate;
70     }
71 
72     /**
73      * Channel mask configuration (e.g AudioFormat.CHANNEL_CONFIGURATION_STEREO).
74      */
channelMask()75     public int channelMask() {
76         return mChannelMask;
77     }
78 
79     /**
80      * Audio format configuration (e.g AudioFormat.ENCODING_PCM_16BIT).
81      */
format()82     public int format() {
83         return mFormat;
84     }
85 
86     /**
87      * The gain configuration if this port supports gain control, null otherwise
88      * @see AudioGainConfig.
89      */
gain()90     public AudioGainConfig gain() {
91         return mGain;
92     }
93 
94     @Override
toString()95     public String toString() {
96         return "{mPort:" + mPort
97                 + ", mSamplingRate:" + mSamplingRate
98                 + ", mChannelMask: " + mChannelMask
99                 + ", mFormat:" + mFormat
100                 + ", mGain:" + mGain
101                 + "}";
102     }
103 }
104