PatchPanel.h revision b997d3a3d61a86dc9525860e863c7b690356d405
11c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent/* 21c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** 31c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** Copyright 2014, The Android Open Source Project 41c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** 51c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** Licensed under the Apache License, Version 2.0 (the "License"); 61c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** you may not use this file except in compliance with the License. 71c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** You may obtain a copy of the License at 81c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** 91c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** http://www.apache.org/licenses/LICENSE-2.0 101c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** 111c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** Unless required by applicable law or agreed to in writing, software 121c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** distributed under the License is distributed on an "AS IS" BASIS, 131c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 141c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** See the License for the specific language governing permissions and 151c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent** limitations under the License. 161c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent*/ 171c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 181c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent#ifndef INCLUDING_FROM_AUDIOFLINGER_H 191c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent #error This header file should only be included from AudioFlinger.h 201c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent#endif 211c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 221c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurentclass PatchPanel : public RefBase { 231c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurentpublic: 2483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 2583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent class Patch; 2683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 271c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent PatchPanel(const sp<AudioFlinger>& audioFlinger); 281c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent virtual ~PatchPanel(); 291c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 301c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent /* List connected audio ports and their attributes */ 311c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent status_t listAudioPorts(unsigned int *num_ports, 321c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent struct audio_port *ports); 331c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 341c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent /* Get supported attributes for a given audio port */ 351c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent status_t getAudioPort(struct audio_port *port); 361c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 371c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent /* Create a patch between several source and sink ports */ 381c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent status_t createAudioPatch(const struct audio_patch *patch, 391c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent audio_patch_handle_t *handle); 401c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 411c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent /* Release a patch */ 421c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent status_t releaseAudioPatch(audio_patch_handle_t handle); 431c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 441c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent /* List connected audio devices and they attributes */ 451c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent status_t listAudioPatches(unsigned int *num_patches, 461c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent struct audio_patch *patches); 471c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 481c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent /* Set audio port configuration */ 491c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent status_t setAudioPortConfig(const struct audio_port_config *config); 501c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 5183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent status_t createPatchConnections(Patch *patch, 5283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent const struct audio_patch *audioPatch); 5383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent void clearPatchConnections(Patch *patch); 5483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 551c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent class Patch { 561c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent public: 571c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent Patch(const struct audio_patch *patch) : 5883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mAudioPatch(*patch), mHandle(AUDIO_PATCH_HANDLE_NONE), 5983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mHalHandle(AUDIO_PATCH_HANDLE_NONE), mRecordPatchHandle(AUDIO_PATCH_HANDLE_NONE), 6083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent mPlaybackPatchHandle(AUDIO_PATCH_HANDLE_NONE) {} 6183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent ~Patch() {} 6283b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 6383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent struct audio_patch mAudioPatch; 6483b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent audio_patch_handle_t mHandle; 65b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // handle for audio HAL patch handle present only when the audio HAL version is >= 3.0 6683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent audio_patch_handle_t mHalHandle; 67b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // below members are used by a software audio patch connecting a source device from a 68b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // given audio HW module to a sink device on an other audio HW module. 69b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // playback thread created by createAudioPatch() and released by clearPatchConnections() if 70b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // no existing playback thread can be used by the software patch 7183b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent sp<PlaybackThread> mPlaybackThread; 72b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // audio track created by createPatchConnections() and released by clearPatchConnections() 7383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent sp<PlaybackThread::PatchTrack> mPatchTrack; 74b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // record thread created by createAudioPatch() and released by clearPatchConnections() 7583b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent sp<RecordThread> mRecordThread; 76b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // audio record created by createPatchConnections() and released by clearPatchConnections() 7783b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent sp<RecordThread::PatchRecord> mPatchRecord; 78b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // handle for audio patch connecting source device to record thread input. 79b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // created by createPatchConnections() and released by clearPatchConnections() 8083b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent audio_patch_handle_t mRecordPatchHandle; 81b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // handle for audio patch connecting playback thread output to sink device 82b997d3a3d61a86dc9525860e863c7b690356d405Eric Laurent // created by createPatchConnections() and released by clearPatchConnections() 8383b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent audio_patch_handle_t mPlaybackPatchHandle; 841c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent 851c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent }; 8683b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent 871c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurentprivate: 8883b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent const wp<AudioFlinger> mAudioFlinger; 8983b8808faad1e91690c64d7007348be8d9ebde73Eric Laurent SortedVector <Patch *> mPatches; 901c333e252cbca3337c1bedbc57a005f3b7d23fdbEric Laurent}; 91