AudioInputDescriptor.h revision 2f4fe9f7df8f22c6bc8745407d19df73128810ec
1e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy/* 2e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Copyright (C) 2015 The Android Open Source Project 3e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 4e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Licensed under the Apache License, Version 2.0 (the "License"); 5e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * you may not use this file except in compliance with the License. 6e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * You may obtain a copy of the License at 7e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 8e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * http://www.apache.org/licenses/LICENSE-2.0 9e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * 10e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * Unless required by applicable law or agreed to in writing, software 11e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * distributed under the License is distributed on an "AS IS" BASIS, 12e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * See the License for the specific language governing permissions and 14e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy * limitations under the License. 15e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy */ 16e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 179d5316e3f56d138504565ff311145ac01621dff4Romain Guy#pragma once 189d5316e3f56d138504565ff311145ac01621dff4Romain Guy 199d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include "AudioPort.h" 209d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include "AudioSession.h" 219d5316e3f56d138504565ff311145ac01621dff4Romain Guy#include <utils/Errors.h> 2285bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy#include <system/audio.h> 23ce0537b80087a6225273040a987414b1dd081aa0Romain Guy#include <utils/SortedVector.h> 24f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy#include <utils/KeyedVector.h> 25ce0537b80087a6225273040a987414b1dd081aa0Romain Guy 26079ba2c85b15e882629b8d188f5fbdb42f7f8eeaRomain Guynamespace android { 27d27977d1a91d5a6b3cc9fa7664ac7e835e7bd895Romain Guy 2885bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guyclass IOProfile; 29e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guyclass AudioMix; 30bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 318694230ff25fa0a60e480d424843e56b718f0516Romain Guy// descriptor for audio inputs. Used to maintain current configuration of each opened audio input 32bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy// and keep track of the usage of this input. 3351769a68a5cb34e9564740c6a854fcb93018789dRomain Guyclass AudioInputDescriptor: public AudioPortConfig 34f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy{ 355cbbce535744b89df5ecea95de21ee3733298260Romain Guypublic: 36bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy AudioInputDescriptor(const sp<IOProfile>& profile); 375cbbce535744b89df5ecea95de21ee3733298260Romain Guy void setIoHandle(audio_io_handle_t ioHandle); 38f7f93556c8fcc640ab5adef79d021a80a72a645aRomain Guy audio_port_handle_t getId() const; 3906f96e2652e4855b6520ad9dd70583677605b79aRomain Guy audio_module_handle_t getModuleHandle() const; 40db1938e0e6ef816e228c815adccebd5cb05f2aa8Romain Guy uint32_t getOpenRefCount() const; 41fb8b763f762ae21923c58d64caa729b012f40e05Romain Guy 42bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy status_t dump(int fd); 43e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 449d5316e3f56d138504565ff311145ac01621dff4Romain Guy audio_io_handle_t mIoHandle; // input handle 45e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy audio_devices_t mDevice; // current device this input is routed to 46f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy AudioMix *mPolicyMix; // non NULL when used by a dynamic policy 47b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy audio_patch_handle_t mPatchHandle; 48b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy const sp<IOProfile> mProfile; // I/O profile this output derives from 49b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy 50b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 51b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy const struct audio_port_config *srcConfig = NULL) const; 52b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy virtual sp<AudioPort> getAudioPort() const { return mProfile; } 53b025b9c8b4efefadb01937db61a1f8ee7d2452bfRomain Guy void toAudioPort(struct audio_port *port) const; 54f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy void setPreemptedSessions(const SortedVector<audio_session_t>& sessions); 55f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy SortedVector<audio_session_t> getPreemptedSessions() const; 56f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy bool hasPreemptedSession(audio_session_t session) const; 57b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy void clearPreemptedSessions(); 58b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guy bool isActive() const; 595cbbce535744b89df5ecea95de21ee3733298260Romain Guy bool isSourceActive(audio_source_t source) const; 605cbbce535744b89df5ecea95de21ee3733298260Romain Guy audio_source_t inputSource() const; 615cbbce535744b89df5ecea95de21ee3733298260Romain Guy bool isSoundTrigger() const; 625cbbce535744b89df5ecea95de21ee3733298260Romain Guy status_t addAudioSession(audio_session_t session, 6385bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy const sp<AudioSession>& audioSession); 64e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy status_t removeAudioSession(audio_session_t session); 6585bf02fc16784d935fb9eebfa9cb20fe46ff7951Romain Guy sp<AudioSession> getAudioSession(audio_session_t session) const; 66e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy AudioSessionCollection getActiveAudioSessions() const; 67e4d011201cea40d46cb2b2eef401db8fddc5c9c6Romain Guy 68b051e895ccb696604349c6c5efe7c4747e1d1ab6Romain Guyprivate: 69e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy audio_port_handle_t mId; 706b7bd24659fb175fe1f0e97c86c18969918b496aRomain Guy // audio sessions attached to this input 71e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy AudioSessionCollection mSessions; 72e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy // Because a preemptible capture session can preempt another one, we end up in an endless loop 734aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy // situation were each session is allowed to restart after being preempted, 744aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy // thus preempting the other one which restarts and so on. 7508ae317c21ec3086b5017672bba87420cc38a407Romain Guy // To avoid this situation, we store which audio session was preempted when 76bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy // a particular input started and prevent preemption of this active input by this session. 774aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy // We also inherit sessions from the preempted input to avoid a 3 way preemption loop etc... 784aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy SortedVector<audio_session_t> mPreemptedSessions; 794aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy}; 80bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy 81e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guyclass AudioInputCollection : 82e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy public DefaultKeyedVector< audio_io_handle_t, sp<AudioInputDescriptor> > 83e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy{ 84e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guypublic: 85bd6b79b40247aea7bfe13d0831c6c0472df6c636Romain Guy bool isSourceActive(audio_source_t source) const; 864aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy 874aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy sp<AudioInputDescriptor> getInputFromId(audio_port_handle_t id) const; 884aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy 89f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy uint32_t activeInputsCount() const; 9041030da16856c8869e1e51d4a0405432fa96614eRomain Guy 91f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy /** 924aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * return io handle of active input or 0 if no input is active 934aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy * Only considers inputs from physical devices (e.g. main mic, headset mic) when 94f6a11b8a9e25ff9861bbba19251bea84d8a5daf2Romain Guy * ignoreVirtualInputs is true. 959d5316e3f56d138504565ff311145ac01621dff4Romain Guy */ 96c7d53494f1fbd9f9d74af89053ff9fdb1ccbac6cRomain Guy audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true); 974aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy 98bb9524b6bdddc7ac77d8628daa8b366b8a7be4a4Romain Guy audio_devices_t getSupportedDevices(audio_io_handle_t handle) const; 99e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy 100e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy status_t dump(int fd) const; 101e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy}; 102e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy 103e2d345ea67e2960b37bfdc0fc8626d1bfa747404Romain Guy 1044aa90573bbf86db0d33a3a790c5dbd0d93b95cfeRomain Guy}; // namespace android 1054bb942083a0d4db746adf95349108dd8ef842e32Romain Guy