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