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 /**
23  * An AudioPatch describes a connection between audio sources and audio sinks.
24  * An audio source can be an output mix (playback AudioBus) or an input device (microphone).
25  * An audio sink can be an output device (speaker) or an input mix (capture AudioBus).
26  * An AudioPatch is created by AudioManager.createAudioPatch() and released by
27  * AudioManager.releaseAudioPatch()
28  * It contains the list of source and sink AudioPortConfig showing audio port configurations
29  * being connected.
30  * @hide
31  */
32 public class AudioPatch {
33 
34     @UnsupportedAppUsage
35     private final AudioHandle mHandle;
36     private final AudioPortConfig[] mSources;
37     private final AudioPortConfig[] mSinks;
38 
39     @UnsupportedAppUsage
AudioPatch(AudioHandle patchHandle, AudioPortConfig[] sources, AudioPortConfig[] sinks)40     AudioPatch(AudioHandle patchHandle, AudioPortConfig[] sources, AudioPortConfig[] sinks) {
41         mHandle = patchHandle;
42         mSources = sources;
43         mSinks = sinks;
44     }
45 
46     /**
47      * Retrieve the list of sources of this audio patch.
48      */
49     @UnsupportedAppUsage
sources()50     public AudioPortConfig[] sources() {
51         return mSources;
52     }
53 
54     /**
55      * Retreive the list of sinks of this audio patch.
56      */
57     @UnsupportedAppUsage
sinks()58     public AudioPortConfig[] sinks() {
59         return mSinks;
60     }
61 
62     /**
63      * Get the system unique patch ID.
64      */
id()65     public int id() {
66         return mHandle.id();
67     }
68 
69     @Override
toString()70     public String toString() {
71         StringBuilder s = new StringBuilder();
72         s.append("mHandle: ");
73         s.append(mHandle.toString());
74 
75         s.append(" mSources: {");
76         for (AudioPortConfig source : mSources) {
77             s.append(source.toString());
78             s.append(", ");
79         }
80         s.append("} mSinks: {");
81         for (AudioPortConfig sink : mSinks) {
82             s.append(sink.toString());
83             s.append(", ");
84         }
85         s.append("}");
86 
87         return s.toString();
88     }
89 }
90