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 <utils/Errors.h>
21 #include <system/audio.h>
22 #include <utils/SortedVector.h>
23 #include <utils/KeyedVector.h>
24 
25 namespace android {
26 
27 class IOProfile;
28 class AudioMix;
29 
30 // descriptor for audio inputs. Used to maintain current configuration of each opened audio input
31 // and keep track of the usage of this input.
32 class AudioInputDescriptor: public AudioPortConfig
33 {
34 public:
35     AudioInputDescriptor(const sp<IOProfile>& profile);
36     void setIoHandle(audio_io_handle_t ioHandle);
37     audio_port_handle_t getId() const;
38     audio_module_handle_t getModuleHandle() const;
39 
40     status_t    dump(int fd);
41 
42     audio_io_handle_t             mIoHandle;       // input handle
43     audio_devices_t               mDevice;         // current device this input is routed to
44     AudioMix                      *mPolicyMix;     // non NULL when used by a dynamic policy
45     audio_patch_handle_t          mPatchHandle;
46     uint32_t                      mRefCount;       // number of AudioRecord clients using
47     // this input
48     uint32_t                      mOpenRefCount;
49     audio_source_t                mInputSource;    // input source selected by application
50     //(mediarecorder.h)
51     const sp<IOProfile>           mProfile;        // I/O profile this output derives from
52     SortedVector<audio_session_t> mSessions;       // audio sessions attached to this input
53     bool                          mIsSoundTrigger; // used by a soundtrigger capture
54 
55     virtual void toAudioPortConfig(struct audio_port_config *dstConfig,
56             const struct audio_port_config *srcConfig = NULL) const;
getAudioPort()57     virtual sp<AudioPort> getAudioPort() const { return mProfile; }
58     void toAudioPort(struct audio_port *port) const;
59 
60 private:
61     audio_port_handle_t           mId;
62 };
63 
64 class AudioInputCollection :
65         public DefaultKeyedVector< audio_io_handle_t, sp<AudioInputDescriptor> >
66 {
67 public:
68     bool isSourceActive(audio_source_t source) const;
69 
70     sp<AudioInputDescriptor> getInputFromId(audio_port_handle_t id) const;
71 
72     uint32_t activeInputsCount() const;
73 
74     /**
75      * return io handle of active input or 0 if no input is active
76      * Only considers inputs from physical devices (e.g. main mic, headset mic) when
77      * ignoreVirtualInputs is true.
78      */
79     audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true);
80 
81     audio_devices_t getSupportedDevices(audio_io_handle_t handle) const;
82 
83     status_t dump(int fd) const;
84 };
85 
86 
87 }; // namespace android
88