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 18 #ifndef INCLUDING_FROM_AUDIOFLINGER_H 19 #error This header file should only be included from AudioFlinger.h 20 #endif 21 22 class PatchPanel : public RefBase { 23 public: 24 25 class Patch; 26 27 PatchPanel(const sp<AudioFlinger>& audioFlinger); 28 virtual ~PatchPanel(); 29 30 /* List connected audio ports and their attributes */ 31 status_t listAudioPorts(unsigned int *num_ports, 32 struct audio_port *ports); 33 34 /* Get supported attributes for a given audio port */ 35 status_t getAudioPort(struct audio_port *port); 36 37 /* Create a patch between several source and sink ports */ 38 status_t createAudioPatch(const struct audio_patch *patch, 39 audio_patch_handle_t *handle); 40 41 /* Release a patch */ 42 status_t releaseAudioPatch(audio_patch_handle_t handle); 43 44 /* List connected audio devices and they attributes */ 45 status_t listAudioPatches(unsigned int *num_patches, 46 struct audio_patch *patches); 47 48 /* Set audio port configuration */ 49 status_t setAudioPortConfig(const struct audio_port_config *config); 50 51 status_t createPatchConnections(Patch *patch, 52 const struct audio_patch *audioPatch); 53 void clearPatchConnections(Patch *patch); 54 55 class Patch { 56 public: Patch(const struct audio_patch * patch)57 Patch(const struct audio_patch *patch) : 58 mAudioPatch(*patch), mHandle(AUDIO_PATCH_HANDLE_NONE), 59 mHalHandle(AUDIO_PATCH_HANDLE_NONE), mRecordPatchHandle(AUDIO_PATCH_HANDLE_NONE), 60 mPlaybackPatchHandle(AUDIO_PATCH_HANDLE_NONE) {} ~Patch()61 ~Patch() {} 62 63 struct audio_patch mAudioPatch; 64 audio_patch_handle_t mHandle; 65 // handle for audio HAL patch handle present only when the audio HAL version is >= 3.0 66 audio_patch_handle_t mHalHandle; 67 // below members are used by a software audio patch connecting a source device from a 68 // given audio HW module to a sink device on an other audio HW module. 69 // playback thread created by createAudioPatch() and released by clearPatchConnections() if 70 // no existing playback thread can be used by the software patch 71 sp<PlaybackThread> mPlaybackThread; 72 // audio track created by createPatchConnections() and released by clearPatchConnections() 73 sp<PlaybackThread::PatchTrack> mPatchTrack; 74 // record thread created by createAudioPatch() and released by clearPatchConnections() 75 sp<RecordThread> mRecordThread; 76 // audio record created by createPatchConnections() and released by clearPatchConnections() 77 sp<RecordThread::PatchRecord> mPatchRecord; 78 // handle for audio patch connecting source device to record thread input. 79 // created by createPatchConnections() and released by clearPatchConnections() 80 audio_patch_handle_t mRecordPatchHandle; 81 // handle for audio patch connecting playback thread output to sink device 82 // created by createPatchConnections() and released by clearPatchConnections() 83 audio_patch_handle_t mPlaybackPatchHandle; 84 85 }; 86 87 private: 88 const wp<AudioFlinger> mAudioFlinger; 89 SortedVector <Patch *> mPatches; 90 }; 91