Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
Andy Hung | 07434ef | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 18 | #pragma once |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 19 | |
Andy Hung | a7926fd | 2023-07-18 18:43:08 -0700 | [diff] [blame] | 20 | #include "IAfPatchPanel.h" |
| 21 | |
| 22 | #include <map> // avoid transitive dependency |
| 23 | #include <set> // avoid transitive dependency |
| 24 | |
Andy Hung | 07434ef | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | |
Andy Hung | d63e79d | 2023-07-13 16:52:46 -0700 | [diff] [blame] | 27 | class PatchPanel : public IAfPatchPanel { |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 28 | public: |
Andy Hung | 68631eb | 2023-07-17 14:36:08 -0700 | [diff] [blame] | 29 | explicit PatchPanel(const sp<IAfPatchPanelCallback>& afPatchPanelCallback) |
| 30 | : mAfPatchPanelCallback(afPatchPanelCallback) {} |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 31 | |
| 32 | /* List connected audio ports and their attributes */ |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 33 | status_t listAudioPorts_l(unsigned int *num_ports, |
| 34 | struct audio_port* ports) final REQUIRES(audio_utils::AudioFlinger_Mutex); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 35 | |
| 36 | /* Get supported attributes for a given audio port */ |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 37 | status_t getAudioPort_l(struct audio_port_v7* port) final |
| 38 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 39 | |
| 40 | /* Create a patch between several source and sink ports */ |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 41 | status_t createAudioPatch_l(const struct audio_patch *patch, |
Francois Gaffie | e0dc36d | 2021-04-01 16:01:00 +0200 | [diff] [blame] | 42 | audio_patch_handle_t *handle, |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 43 | bool endpointPatch = false) final |
| 44 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 45 | |
| 46 | /* Release a patch */ |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 47 | status_t releaseAudioPatch_l(audio_patch_handle_t handle) final |
| 48 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 49 | |
| 50 | /* List connected audio devices and they attributes */ |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 51 | status_t listAudioPatches_l(unsigned int *num_patches, |
| 52 | struct audio_patch* patches) final |
| 53 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 54 | |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 55 | // Retrieves all currently established software patches for a stream |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 56 | // opened on an intermediate module. |
| 57 | status_t getDownstreamSoftwarePatches(audio_io_handle_t stream, |
Andy Hung | d63e79d | 2023-07-13 16:52:46 -0700 | [diff] [blame] | 58 | std::vector<SoftwarePatch>* patches) const final; |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 59 | |
| 60 | // Notifies patch panel about all opened and closed streams. |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 61 | void notifyStreamOpened(AudioHwDevice *audioHwDevice, audio_io_handle_t stream, |
Andy Hung | d63e79d | 2023-07-13 16:52:46 -0700 | [diff] [blame] | 62 | struct audio_patch* patch) final; |
| 63 | void notifyStreamClosed(audio_io_handle_t stream) final; |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 64 | |
Andy Hung | d63e79d | 2023-07-13 16:52:46 -0700 | [diff] [blame] | 65 | void dump(int fd) const final; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 66 | |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 67 | const std::map<audio_patch_handle_t, Patch>& patches_l() const final |
| 68 | REQUIRES(audio_utils::AudioFlinger_Mutex) { return mPatches; } |
Andy Hung | d63e79d | 2023-07-13 16:52:46 -0700 | [diff] [blame] | 69 | |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 70 | status_t getLatencyMs_l(audio_patch_handle_t patchHandle, double* latencyMs) const final |
| 71 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Andy Hung | d63e79d | 2023-07-13 16:52:46 -0700 | [diff] [blame] | 72 | |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 73 | void closeThreadInternal_l(const sp<IAfThreadBase>& thread) const final |
| 74 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Eric Laurent | 9b2064c | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 75 | |
jiabin | 12537fc | 2023-10-12 17:56:08 +0000 | [diff] [blame^] | 76 | /** |
| 77 | * Get the attributes of the mix port when connecting to the given device port |
| 78 | */ |
| 79 | status_t getAudioMixPort_l(const audio_port_v7* devicePort, audio_port_v7* mixPort) final |
| 80 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
| 81 | |
Eric Laurent | 9b2064c | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 82 | private: |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 83 | AudioHwDevice* findAudioHwDeviceByModule_l(audio_module_handle_t module) |
| 84 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
| 85 | sp<DeviceHalInterface> findHwDeviceByModule_l(audio_module_handle_t module) |
| 86 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
| 87 | void addSoftwarePatchToInsertedModules_l( |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 88 | audio_module_handle_t module, audio_patch_handle_t handle, |
Andy Hung | 3634612 | 2023-08-31 15:24:24 -0700 | [diff] [blame] | 89 | const struct audio_patch *patch) |
| 90 | REQUIRES(audio_utils::AudioFlinger_Mutex); |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 91 | void removeSoftwarePatchFromInsertedModules(audio_patch_handle_t handle); |
Eric Laurent | 9b2064c | 2019-11-22 17:25:04 -0800 | [diff] [blame] | 92 | void erasePatch(audio_patch_handle_t handle); |
Mikhail Naganov | 444ecc3 | 2018-05-01 17:40:05 -0700 | [diff] [blame] | 93 | |
Andy Hung | 68631eb | 2023-07-17 14:36:08 -0700 | [diff] [blame] | 94 | const sp<IAfPatchPanelCallback> mAfPatchPanelCallback; |
Mikhail Naganov | dea5304 | 2018-04-26 13:10:21 -0700 | [diff] [blame] | 95 | std::map<audio_patch_handle_t, Patch> mPatches; |
Mikhail Naganov | adca70f | 2018-07-09 12:49:25 -0700 | [diff] [blame] | 96 | |
| 97 | // This map allows going from a thread to "downstream" software patches |
| 98 | // when a processing module inserted in between. Example: |
| 99 | // |
| 100 | // from map value.streams map key |
| 101 | // [Mixer thread] --> [Virtual output device] --> [Processing module] ---\ |
| 102 | // [Harware module] <-- [Physical output device] <-- [S/W Patch] <--/ |
| 103 | // from map value.sw_patches |
| 104 | // |
| 105 | // This allows the mixer thread to look up the threads of the software patch |
| 106 | // for propagating timing info, parameters, etc. |
| 107 | // |
| 108 | // The current assumptions are: |
| 109 | // 1) The processing module acts as a mixer with several outputs which |
| 110 | // represent differently downmixed and / or encoded versions of the same |
| 111 | // mixed stream. There is no 1:1 correspondence between the input streams |
| 112 | // and the software patches, but rather a N:N correspondence between |
| 113 | // a group of streams and a group of patches. |
| 114 | // 2) There are only a couple of inserted processing modules in the system, |
| 115 | // so when looking for a stream or patch handle we can iterate over |
| 116 | // all modules. |
| 117 | struct ModuleConnections { |
| 118 | std::set<audio_io_handle_t> streams; |
| 119 | std::set<audio_patch_handle_t> sw_patches; |
| 120 | }; |
| 121 | std::map<audio_module_handle_t, ModuleConnections> mInsertedModules; |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 122 | }; |
Andy Hung | bd72c54 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 123 | |
Andy Hung | 07434ef | 2023-07-13 18:11:33 -0700 | [diff] [blame] | 124 | } // namespace android |