• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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     void setPreemptedSessions(const SortedVector<audio_session_t>& sessions);
60     SortedVector<audio_session_t> getPreemptedSessions() const;
61     bool hasPreemptedSession(audio_session_t session) const;
62     void clearPreemptedSessions();
63 
64 private:
65     audio_port_handle_t           mId;
66     // Because a preemtible capture session can preempt another one, we end up in an endless loop
67     // situation were each session is allowed to restart after being preempted,
68     // thus preempting the other one which restarts and so on.
69     // To avoid this situation, we store which audio session was preempted when
70     // a particular input started and prevent preemption of this active input by this session.
71     // We also inherit sessions from the preempted input to avoid a 3 way preemption loop etc...
72     SortedVector<audio_session_t> mPreemptedSessions;
73 
74 };
75 
76 class AudioInputCollection :
77         public DefaultKeyedVector< audio_io_handle_t, sp<AudioInputDescriptor> >
78 {
79 public:
80     bool isSourceActive(audio_source_t source) const;
81 
82     sp<AudioInputDescriptor> getInputFromId(audio_port_handle_t id) const;
83 
84     uint32_t activeInputsCount() const;
85 
86     /**
87      * return io handle of active input or 0 if no input is active
88      * Only considers inputs from physical devices (e.g. main mic, headset mic) when
89      * ignoreVirtualInputs is true.
90      */
91     audio_io_handle_t getActiveInput(bool ignoreVirtualInputs = true);
92 
93     audio_devices_t getSupportedDevices(audio_io_handle_t handle) const;
94 
95     status_t dump(int fd) const;
96 };
97 
98 
99 }; // namespace android
100