blob: 6caf527aba131c257a75835c24458896976a48c9 [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
Andy Hungbd72c542023-06-20 18:56:17 -070022public: // TODO(b/288339104) extract out of AudioFlinger class
Mikhail Naganovdea53042018-04-26 13:10:21 -070023// PatchPanel is concealed within AudioFlinger, their lifetimes are the same.
Andy Hungd63e79d2023-07-13 16:52:46 -070024class PatchPanel : public IAfPatchPanel {
Eric Laurent1c333e22014-05-20 10:48:17 -070025public:
Mikhail Naganovdea53042018-04-26 13:10:21 -070026 explicit PatchPanel(AudioFlinger* audioFlinger) : mAudioFlinger(*audioFlinger) {}
Eric Laurent1c333e22014-05-20 10:48:17 -070027
28 /* List connected audio ports and their attributes */
29 status_t listAudioPorts(unsigned int *num_ports,
Andy Hungd63e79d2023-07-13 16:52:46 -070030 struct audio_port* ports) final;
Eric Laurent1c333e22014-05-20 10:48:17 -070031
32 /* Get supported attributes for a given audio port */
Andy Hungd63e79d2023-07-13 16:52:46 -070033 status_t getAudioPort(struct audio_port_v7* port) final;
Eric Laurent1c333e22014-05-20 10:48:17 -070034
35 /* Create a patch between several source and sink ports */
36 status_t createAudioPatch(const struct audio_patch *patch,
Francois Gaffiee0dc36d2021-04-01 16:01:00 +020037 audio_patch_handle_t *handle,
Andy Hungd63e79d2023-07-13 16:52:46 -070038 bool endpointPatch = false) final;
Eric Laurent1c333e22014-05-20 10:48:17 -070039
40 /* Release a patch */
Andy Hungd63e79d2023-07-13 16:52:46 -070041 status_t releaseAudioPatch(audio_patch_handle_t handle) final;
Eric Laurent1c333e22014-05-20 10:48:17 -070042
43 /* List connected audio devices and they attributes */
44 status_t listAudioPatches(unsigned int *num_patches,
Andy Hungd63e79d2023-07-13 16:52:46 -070045 struct audio_patch* patches) final;
Eric Laurent1c333e22014-05-20 10:48:17 -070046
Mikhail Naganovadca70f2018-07-09 12:49:25 -070047 // Retrieves all currently estrablished software patches for a stream
48 // opened on an intermediate module.
49 status_t getDownstreamSoftwarePatches(audio_io_handle_t stream,
Andy Hungd63e79d2023-07-13 16:52:46 -070050 std::vector<SoftwarePatch>* patches) const final;
Mikhail Naganovadca70f2018-07-09 12:49:25 -070051
52 // Notifies patch panel about all opened and closed streams.
Eric Laurent74c38dc2020-12-23 18:19:44 +010053 void notifyStreamOpened(AudioHwDevice *audioHwDevice, audio_io_handle_t stream,
Andy Hungd63e79d2023-07-13 16:52:46 -070054 struct audio_patch* patch) final;
55 void notifyStreamClosed(audio_io_handle_t stream) final;
Mikhail Naganovadca70f2018-07-09 12:49:25 -070056
Andy Hungd63e79d2023-07-13 16:52:46 -070057 void dump(int fd) const final;
Eric Laurent83b88082014-06-20 18:31:16 -070058
Eric Laurent9b2064c2019-11-22 17:25:04 -080059 // Call with AudioFlinger mLock held
Andy Hungd63e79d2023-07-13 16:52:46 -070060 const std::map<audio_patch_handle_t, Patch>& patches_l() const final { return mPatches; }
61
62 // Must be called under AudioFlinger::mLock
63 status_t getLatencyMs_l(audio_patch_handle_t patchHandle, double* latencyMs) const final;
64
65 void closeThreadInternal_l(const sp<IAfThreadBase>& thread) const final;
Eric Laurent9b2064c2019-11-22 17:25:04 -080066
67private:
Mikhail Naganovadca70f2018-07-09 12:49:25 -070068 AudioHwDevice* findAudioHwDeviceByModule(audio_module_handle_t module);
Mikhail Naganov444ecc32018-05-01 17:40:05 -070069 sp<DeviceHalInterface> findHwDeviceByModule(audio_module_handle_t module);
Mikhail Naganovadca70f2018-07-09 12:49:25 -070070 void addSoftwarePatchToInsertedModules(
Eric Laurent74c38dc2020-12-23 18:19:44 +010071 audio_module_handle_t module, audio_patch_handle_t handle,
72 const struct audio_patch *patch);
Mikhail Naganovadca70f2018-07-09 12:49:25 -070073 void removeSoftwarePatchFromInsertedModules(audio_patch_handle_t handle);
Eric Laurent9b2064c2019-11-22 17:25:04 -080074 void erasePatch(audio_patch_handle_t handle);
Mikhail Naganov444ecc32018-05-01 17:40:05 -070075
Mikhail Naganovdea53042018-04-26 13:10:21 -070076 AudioFlinger &mAudioFlinger;
77 std::map<audio_patch_handle_t, Patch> mPatches;
Mikhail Naganovadca70f2018-07-09 12:49:25 -070078
79 // This map allows going from a thread to "downstream" software patches
80 // when a processing module inserted in between. Example:
81 //
82 // from map value.streams map key
83 // [Mixer thread] --> [Virtual output device] --> [Processing module] ---\
84 // [Harware module] <-- [Physical output device] <-- [S/W Patch] <--/
85 // from map value.sw_patches
86 //
87 // This allows the mixer thread to look up the threads of the software patch
88 // for propagating timing info, parameters, etc.
89 //
90 // The current assumptions are:
91 // 1) The processing module acts as a mixer with several outputs which
92 // represent differently downmixed and / or encoded versions of the same
93 // mixed stream. There is no 1:1 correspondence between the input streams
94 // and the software patches, but rather a N:N correspondence between
95 // a group of streams and a group of patches.
96 // 2) There are only a couple of inserted processing modules in the system,
97 // so when looking for a stream or patch handle we can iterate over
98 // all modules.
99 struct ModuleConnections {
100 std::set<audio_io_handle_t> streams;
101 std::set<audio_patch_handle_t> sw_patches;
102 };
103 std::map<audio_module_handle_t, ModuleConnections> mInsertedModules;
Eric Laurent1c333e22014-05-20 10:48:17 -0700104};
Andy Hungbd72c542023-06-20 18:56:17 -0700105
106private: