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