AudioInputDescriptor.h revision 4b2fcd8abf90b1bd95539f9f4ef2ac39ce9e2df1
1/* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17#pragma once 18 19#include "AudioPort.h" 20#include "AudioSession.h" 21#include <utils/Errors.h> 22#include <system/audio.h> 23#include <utils/SortedVector.h> 24#include <utils/KeyedVector.h> 25 26namespace android { 27 28class IOProfile; 29class AudioMix; 30 31// descriptor for audio inputs. Used to maintain current configuration of each opened audio input 32// and keep track of the usage of this input. 33class AudioInputDescriptor: public AudioPortConfig 34{ 35public: 36 AudioInputDescriptor(const sp<IOProfile>& profile); 37 void setIoHandle(audio_io_handle_t ioHandle); 38 audio_port_handle_t getId() const; 39 audio_module_handle_t getModuleHandle() const; 40 uint32_t getOpenRefCount() const; 41 42 status_t dump(int fd); 43 44 audio_io_handle_t mIoHandle; // input handle 45 audio_devices_t mDevice; // current device this input is routed to 46 AudioMix *mPolicyMix; // non NULL when used by a dynamic policy 47 audio_patch_handle_t mPatchHandle; 48 const sp<IOProfile> mProfile; // I/O profile this output derives from 49 50 virtual void toAudioPortConfig(struct audio_port_config *dstConfig, 51 const struct audio_port_config *srcConfig = NULL) const; 52 virtual sp<AudioPort> getAudioPort() const { return mProfile; } 53 void toAudioPort(struct audio_port *port) const; 54 void setPreemptedSessions(const SortedVector<audio_session_t>& sessions); 55 SortedVector<audio_session_t> getPreemptedSessions() const; 56 bool hasPreemptedSession(audio_session_t session) const; 57 void clearPreemptedSessions(); 58 bool isActive() const; 59 bool isSourceActive(audio_source_t source) const; 60 audio_source_t inputSource() const; 61 bool isSoundTrigger() const; 62 status_t addAudioSession(audio_session_t session, 63 const sp<AudioSession>& audioSession); 64 status_t removeAudioSession(audio_session_t session); 65 sp<AudioSession> getAudioSession(audio_session_t session) const; 66 AudioSessionCollection getAudioSessions(bool activeOnly) const; 67 audio_source_t getHighestPrioritySource(bool activeOnly) const; 68 69private: 70 audio_port_handle_t mId; 71 // audio sessions attached to this input 72 AudioSessionCollection mSessions; 73 // Because a preemptible capture session can preempt another one, we end up in an endless loop 74 // situation were each session is allowed to restart after being preempted, 75 // thus preempting the other one which restarts and so on. 76 // To avoid this situation, we store which audio session was preempted when 77 // a particular input started and prevent preemption of this active input by this session. 78 // We also inherit sessions from the preempted input to avoid a 3 way preemption loop etc... 79 SortedVector<audio_session_t> mPreemptedSessions; 80}; 81 82class AudioInputCollection : 83 public DefaultKeyedVector< audio_io_handle_t, sp<AudioInputDescriptor> > 84{ 85public: 86 bool isSourceActive(audio_source_t source) const; 87 88 sp<AudioInputDescriptor> getInputFromId(audio_port_handle_t id) const; 89 90 uint32_t activeInputsCount() const; 91 92 /** 93 * return io handle of active input or 0 if no input is active 94 * Only considers inputs from physical devices (e.g. main mic, headset mic) when 95 * ignoreVirtualInputs is true. 96 */ 97 Vector<sp <AudioInputDescriptor> > getActiveInputs(bool ignoreVirtualInputs = true); 98 99 audio_devices_t getSupportedDevices(audio_io_handle_t handle) const; 100 101 status_t dump(int fd) const; 102}; 103 104 105}; // namespace android 106