blob: c2cb7ac5a441b1d1a1f01902563c29ad9da6a466 [file] [log] [blame]
Eric Laurent1c333e22014-05-20 10:48:17 -07001/*
2**
3** Copyright 2014, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18#ifndef INCLUDING_FROM_AUDIOFLINGER_H
19 #error This header file should only be included from AudioFlinger.h
20#endif
21
Mikhail Naganovdea53042018-04-26 13:10:21 -070022// PatchPanel is concealed within AudioFlinger, their lifetimes are the same.
23class PatchPanel {
Eric Laurent1c333e22014-05-20 10:48:17 -070024public:
Mikhail Naganovdea53042018-04-26 13:10:21 -070025 explicit PatchPanel(AudioFlinger* audioFlinger) : mAudioFlinger(*audioFlinger) {}
Eric Laurent1c333e22014-05-20 10:48:17 -070026
27 /* List connected audio ports and their attributes */
28 status_t listAudioPorts(unsigned int *num_ports,
29 struct audio_port *ports);
30
31 /* Get supported attributes for a given audio port */
32 status_t getAudioPort(struct audio_port *port);
33
34 /* Create a patch between several source and sink ports */
35 status_t createAudioPatch(const struct audio_patch *patch,
36 audio_patch_handle_t *handle);
37
38 /* Release a patch */
39 status_t releaseAudioPatch(audio_patch_handle_t handle);
40
41 /* List connected audio devices and they attributes */
42 status_t listAudioPatches(unsigned int *num_patches,
43 struct audio_patch *patches);
44
Mikhail Naganovdea53042018-04-26 13:10:21 -070045private:
Eric Laurent1c333e22014-05-20 10:48:17 -070046 class Patch {
47 public:
Mikhail Naganovdea53042018-04-26 13:10:21 -070048 explicit Patch(const struct audio_patch &patch) : mAudioPatch(patch) {}
Eric Laurent1c333e22014-05-20 10:48:17 -070049
Mikhail Naganovdea53042018-04-26 13:10:21 -070050 status_t createConnections(PatchPanel *panel);
51 void clearConnections(PatchPanel *panel);
52
53 // Note that audio_patch::id is only unique within a HAL module
Eric Laurent83b88082014-06-20 18:31:16 -070054 struct audio_patch mAudioPatch;
Eric Laurentb997d3a2016-06-07 18:23:45 -070055 // handle for audio HAL patch handle present only when the audio HAL version is >= 3.0
Mikhail Naganovdea53042018-04-26 13:10:21 -070056 audio_patch_handle_t mHalHandle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurentb997d3a2016-06-07 18:23:45 -070057 // below members are used by a software audio patch connecting a source device from a
58 // given audio HW module to a sink device on an other audio HW module.
Mikhail Naganovdea53042018-04-26 13:10:21 -070059 // the objects are created by createConnections() and released by clearConnections()
60 // playback thread is created if no existing playback thread can be used
Eric Laurent83b88082014-06-20 18:31:16 -070061 sp<PlaybackThread> mPlaybackThread;
62 sp<PlaybackThread::PatchTrack> mPatchTrack;
63 sp<RecordThread> mRecordThread;
64 sp<RecordThread::PatchRecord> mPatchRecord;
Eric Laurentb997d3a2016-06-07 18:23:45 -070065 // handle for audio patch connecting source device to record thread input.
Mikhail Naganovdea53042018-04-26 13:10:21 -070066 audio_patch_handle_t mRecordPatchHandle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurentb997d3a2016-06-07 18:23:45 -070067 // handle for audio patch connecting playback thread output to sink device
Mikhail Naganovdea53042018-04-26 13:10:21 -070068 audio_patch_handle_t mPlaybackPatchHandle = AUDIO_PATCH_HANDLE_NONE;
Eric Laurent83b88082014-06-20 18:31:16 -070069
Eric Laurent1c333e22014-05-20 10:48:17 -070070 };
Eric Laurent83b88082014-06-20 18:31:16 -070071
Mikhail Naganovdea53042018-04-26 13:10:21 -070072 AudioFlinger &mAudioFlinger;
73 std::map<audio_patch_handle_t, Patch> mPatches;
Eric Laurent1c333e22014-05-20 10:48:17 -070074};