The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* //device/include/server/AudioFlinger/AudioFlinger.h |
| 2 | ** |
| 3 | ** Copyright 2007, 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 ANDROID_AUDIO_FLINGER_H |
| 19 | #define ANDROID_AUDIO_FLINGER_H |
| 20 | |
| 21 | #include <stdint.h> |
| 22 | #include <sys/types.h> |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 23 | #include <limits.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | #include <media/IAudioFlinger.h> |
| 26 | #include <media/IAudioFlingerClient.h> |
| 27 | #include <media/IAudioTrack.h> |
| 28 | #include <media/IAudioRecord.h> |
Glenn Kasten | 34f9f8b | 2012-01-20 17:00:00 -0800 | [diff] [blame] | 29 | #include <media/AudioSystem.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | |
| 31 | #include <utils/Atomic.h> |
| 32 | #include <utils/Errors.h> |
| 33 | #include <utils/threads.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <utils/SortedVector.h> |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 35 | #include <utils/TypeHelpers.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include <utils/Vector.h> |
| 37 | |
Mathias Agopian | 2465168 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 38 | #include <binder/BinderService.h> |
| 39 | #include <binder/MemoryDealer.h> |
| 40 | |
Dima Zavin | 34bb419 | 2011-05-11 14:15:23 -0700 | [diff] [blame] | 41 | #include <system/audio.h> |
Dima Zavin | 290029d | 2011-06-13 18:16:26 -0700 | [diff] [blame] | 42 | #include <hardware/audio.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
| 44 | #include "AudioBufferProvider.h" |
| 45 | |
Eric Laurent | 6dbdc40 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 46 | #include <powermanager/IPowerManager.h> |
| 47 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 48 | namespace android { |
| 49 | |
| 50 | class audio_track_cblk_t; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 51 | class effect_param_cblk_t; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | class AudioMixer; |
| 53 | class AudioBuffer; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 54 | class AudioResampler; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 55 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 56 | // ---------------------------------------------------------------------------- |
| 57 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | static const nsecs_t kStandbyTimeInNsecs = seconds(3); |
| 59 | |
Mathias Agopian | 2465168 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 60 | class AudioFlinger : |
| 61 | public BinderService<AudioFlinger>, |
| 62 | public BnAudioFlinger |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | { |
Mathias Agopian | 2465168 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 64 | friend class BinderService<AudioFlinger>; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | public: |
Glenn Kasten | 99c2fd3 | 2012-01-06 07:46:30 -0800 | [diff] [blame] | 66 | static const char* getServiceName() { return "media.audio_flinger"; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
| 68 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 69 | |
| 70 | // IAudioFlinger interface |
| 71 | virtual sp<IAudioTrack> createTrack( |
| 72 | pid_t pid, |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 73 | audio_stream_type_t streamType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 75 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 76 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | int frameCount, |
| 78 | uint32_t flags, |
| 79 | const sp<IMemory>& sharedBuffer, |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 80 | audio_io_handle_t output, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 81 | int *sessionId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | status_t *status); |
| 83 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 84 | virtual uint32_t sampleRate(audio_io_handle_t output) const; |
| 85 | virtual int channelCount(audio_io_handle_t output) const; |
| 86 | virtual audio_format_t format(audio_io_handle_t output) const; |
| 87 | virtual size_t frameCount(audio_io_handle_t output) const; |
| 88 | virtual uint32_t latency(audio_io_handle_t output) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
| 90 | virtual status_t setMasterVolume(float value); |
| 91 | virtual status_t setMasterMute(bool muted); |
| 92 | |
| 93 | virtual float masterVolume() const; |
| 94 | virtual bool masterMute() const; |
| 95 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 96 | virtual status_t setStreamVolume(audio_stream_type_t stream, float value, |
| 97 | audio_io_handle_t output); |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 98 | virtual status_t setStreamMute(audio_stream_type_t stream, bool muted); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 100 | virtual float streamVolume(audio_stream_type_t stream, |
| 101 | audio_io_handle_t output) const; |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 102 | virtual bool streamMute(audio_stream_type_t stream) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | |
Glenn Kasten | accb114 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 104 | virtual status_t setMode(audio_mode_t mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | |
| 106 | virtual status_t setMicMute(bool state); |
| 107 | virtual bool getMicMute() const; |
| 108 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 109 | virtual status_t setParameters(audio_io_handle_t ioHandle, const String8& keyValuePairs); |
| 110 | virtual String8 getParameters(audio_io_handle_t ioHandle, const String8& keys) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | |
| 112 | virtual void registerClient(const sp<IAudioFlingerClient>& client); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 113 | |
Glenn Kasten | 3f6d83a | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 114 | virtual size_t getInputBufferSize(uint32_t sampleRate, audio_format_t format, int channelCount) const; |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 115 | virtual unsigned int getInputFramesLost(audio_io_handle_t ioHandle) const; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 116 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 117 | virtual audio_io_handle_t openOutput(uint32_t *pDevices, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 118 | uint32_t *pSamplingRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 119 | audio_format_t *pFormat, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 120 | uint32_t *pChannels, |
| 121 | uint32_t *pLatencyMs, |
| 122 | uint32_t flags); |
| 123 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 124 | virtual audio_io_handle_t openDuplicateOutput(audio_io_handle_t output1, |
| 125 | audio_io_handle_t output2); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 126 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 127 | virtual status_t closeOutput(audio_io_handle_t output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 128 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 129 | virtual status_t suspendOutput(audio_io_handle_t output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 130 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 131 | virtual status_t restoreOutput(audio_io_handle_t output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 132 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 133 | virtual audio_io_handle_t openInput(uint32_t *pDevices, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 134 | uint32_t *pSamplingRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 135 | audio_format_t *pFormat, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 136 | uint32_t *pChannels, |
Glenn Kasten | 882c0a2 | 2012-01-27 12:32:34 -0800 | [diff] [blame] | 137 | audio_in_acoustics_t acoustics); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 138 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 139 | virtual status_t closeInput(audio_io_handle_t input); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 140 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 141 | virtual status_t setStreamOutput(audio_stream_type_t stream, audio_io_handle_t output); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 142 | |
Eric Laurent | 415f3e2 | 2009-10-21 08:14:22 -0700 | [diff] [blame] | 143 | virtual status_t setVoiceVolume(float volume); |
| 144 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 145 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames, |
| 146 | audio_io_handle_t output) const; |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 147 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 148 | virtual int newAudioSessionId(); |
| 149 | |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 150 | virtual void acquireAudioSessionId(int audioSession); |
| 151 | |
| 152 | virtual void releaseAudioSessionId(int audioSession); |
| 153 | |
Glenn Kasten | 3f6d83a | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 154 | virtual status_t queryNumberEffects(uint32_t *numEffects) const; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 155 | |
Glenn Kasten | 3f6d83a | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 156 | virtual status_t queryEffect(uint32_t index, effect_descriptor_t *descriptor) const; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 157 | |
Glenn Kasten | 6731333 | 2012-01-30 07:40:52 -0800 | [diff] [blame] | 158 | virtual status_t getEffectDescriptor(const effect_uuid_t *pUuid, |
Glenn Kasten | 3f6d83a | 2012-01-26 16:25:10 -0800 | [diff] [blame] | 159 | effect_descriptor_t *descriptor) const; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 160 | |
| 161 | virtual sp<IEffect> createEffect(pid_t pid, |
| 162 | effect_descriptor_t *pDesc, |
| 163 | const sp<IEffectClient>& effectClient, |
| 164 | int32_t priority, |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 165 | audio_io_handle_t io, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 166 | int sessionId, |
| 167 | status_t *status, |
| 168 | int *id, |
| 169 | int *enabled); |
| 170 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 171 | virtual status_t moveEffects(int sessionId, audio_io_handle_t srcOutput, |
| 172 | audio_io_handle_t dstOutput); |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 173 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | enum hardware_call_state { |
| 175 | AUDIO_HW_IDLE = 0, |
| 176 | AUDIO_HW_INIT, |
| 177 | AUDIO_HW_OUTPUT_OPEN, |
| 178 | AUDIO_HW_OUTPUT_CLOSE, |
| 179 | AUDIO_HW_INPUT_OPEN, |
| 180 | AUDIO_HW_INPUT_CLOSE, |
| 181 | AUDIO_HW_STANDBY, |
| 182 | AUDIO_HW_SET_MASTER_VOLUME, |
| 183 | AUDIO_HW_GET_ROUTING, |
| 184 | AUDIO_HW_SET_ROUTING, |
| 185 | AUDIO_HW_GET_MODE, |
| 186 | AUDIO_HW_SET_MODE, |
| 187 | AUDIO_HW_GET_MIC_MUTE, |
| 188 | AUDIO_HW_SET_MIC_MUTE, |
| 189 | AUDIO_SET_VOICE_VOLUME, |
| 190 | AUDIO_SET_PARAMETER, |
| 191 | }; |
| 192 | |
| 193 | // record interface |
| 194 | virtual sp<IAudioRecord> openRecord( |
| 195 | pid_t pid, |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 196 | audio_io_handle_t input, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 197 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 198 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 199 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 200 | int frameCount, |
| 201 | uint32_t flags, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 202 | int *sessionId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | status_t *status); |
| 204 | |
| 205 | virtual status_t onTransact( |
| 206 | uint32_t code, |
| 207 | const Parcel& data, |
| 208 | Parcel* reply, |
| 209 | uint32_t flags); |
| 210 | |
Glenn Kasten | accb114 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 211 | audio_mode_t getMode() const { return mMode; } |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 212 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 213 | bool btNrecIsOff() const { return mBtNrecIsOff; } |
Eric Laurent | 6639b55 | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 214 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | private: |
Glenn Kasten | 34f9f8b | 2012-01-20 17:00:00 -0800 | [diff] [blame] | 216 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | AudioFlinger(); |
| 218 | virtual ~AudioFlinger(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 219 | |
Dima Zavin | 2986f5b | 2011-04-19 19:04:32 -0700 | [diff] [blame] | 220 | status_t initCheck() const; |
| 221 | virtual void onFirstRef(); |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 222 | audio_hw_device_t* findSuitableHwDev_l(uint32_t devices); |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 223 | void purgeStaleEffects_l(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 224 | |
| 225 | // Internal dump utilites. |
| 226 | status_t dumpPermissionDenial(int fd, const Vector<String16>& args); |
| 227 | status_t dumpClients(int fd, const Vector<String16>& args); |
| 228 | status_t dumpInternals(int fd, const Vector<String16>& args); |
| 229 | |
| 230 | // --- Client --- |
| 231 | class Client : public RefBase { |
| 232 | public: |
| 233 | Client(const sp<AudioFlinger>& audioFlinger, pid_t pid); |
| 234 | virtual ~Client(); |
Glenn Kasten | 1f812f7 | 2012-01-30 10:15:48 -0800 | [diff] [blame] | 235 | sp<MemoryDealer> heap() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | pid_t pid() const { return mPid; } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 237 | sp<AudioFlinger> audioFlinger() const { return mAudioFlinger; } |
Eric Laurent | b9481d8 | 2009-09-17 05:12:56 -0700 | [diff] [blame] | 238 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | private: |
| 240 | Client(const Client&); |
| 241 | Client& operator = (const Client&); |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 242 | const sp<AudioFlinger> mAudioFlinger; |
| 243 | const sp<MemoryDealer> mMemoryDealer; |
| 244 | const pid_t mPid; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 245 | }; |
| 246 | |
Eric Laurent | 4f0f17d | 2010-05-12 02:05:53 -0700 | [diff] [blame] | 247 | // --- Notification Client --- |
| 248 | class NotificationClient : public IBinder::DeathRecipient { |
| 249 | public: |
| 250 | NotificationClient(const sp<AudioFlinger>& audioFlinger, |
| 251 | const sp<IAudioFlingerClient>& client, |
| 252 | pid_t pid); |
| 253 | virtual ~NotificationClient(); |
| 254 | |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 255 | sp<IAudioFlingerClient> audioFlingerClient() const { return mAudioFlingerClient; } |
Eric Laurent | 4f0f17d | 2010-05-12 02:05:53 -0700 | [diff] [blame] | 256 | |
| 257 | // IBinder::DeathRecipient |
| 258 | virtual void binderDied(const wp<IBinder>& who); |
| 259 | |
| 260 | private: |
| 261 | NotificationClient(const NotificationClient&); |
| 262 | NotificationClient& operator = (const NotificationClient&); |
| 263 | |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 264 | const sp<AudioFlinger> mAudioFlinger; |
| 265 | const pid_t mPid; |
| 266 | const sp<IAudioFlingerClient> mAudioFlingerClient; |
Eric Laurent | 4f0f17d | 2010-05-12 02:05:53 -0700 | [diff] [blame] | 267 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 268 | |
| 269 | class TrackHandle; |
| 270 | class RecordHandle; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 271 | class RecordThread; |
| 272 | class PlaybackThread; |
| 273 | class MixerThread; |
| 274 | class DirectOutputThread; |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 275 | class DuplicatingThread; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 276 | class Track; |
| 277 | class RecordTrack; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 278 | class EffectModule; |
| 279 | class EffectHandle; |
| 280 | class EffectChain; |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 281 | struct AudioStreamOut; |
| 282 | struct AudioStreamIn; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 284 | class ThreadBase : public Thread { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 285 | public: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | |
Glenn Kasten | efd511a | 2012-01-26 10:38:26 -0800 | [diff] [blame] | 287 | enum type_t { |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 288 | MIXER, // Thread class is MixerThread |
| 289 | DIRECT, // Thread class is DirectOutputThread |
| 290 | DUPLICATING, // Thread class is DuplicatingThread |
| 291 | RECORD // Thread class is RecordThread |
| 292 | }; |
| 293 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 294 | ThreadBase (const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id, uint32_t device, type_t type); |
Glenn Kasten | efd511a | 2012-01-26 10:38:26 -0800 | [diff] [blame] | 295 | virtual ~ThreadBase(); |
| 296 | |
Eric Laurent | 3fdb126 | 2009-11-07 00:01:32 -0800 | [diff] [blame] | 297 | status_t dumpBase(int fd, const Vector<String16>& args); |
Eric Laurent | 1345d33 | 2011-07-24 17:49:51 -0700 | [diff] [blame] | 298 | status_t dumpEffectChains(int fd, const Vector<String16>& args); |
Eric Laurent | 3fdb126 | 2009-11-07 00:01:32 -0800 | [diff] [blame] | 299 | |
Eric Laurent | 6dbdc40 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 300 | void clearPowerManager(); |
| 301 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 302 | // base for record and playback |
| 303 | class TrackBase : public AudioBufferProvider, public RefBase { |
| 304 | |
| 305 | public: |
| 306 | enum track_state { |
| 307 | IDLE, |
| 308 | TERMINATED, |
| 309 | STOPPED, |
| 310 | RESUMING, |
| 311 | ACTIVE, |
| 312 | PAUSING, |
| 313 | PAUSED |
| 314 | }; |
| 315 | |
| 316 | enum track_flags { |
| 317 | STEPSERVER_FAILED = 0x01, // StepServer could not acquire cblk->lock mutex |
| 318 | SYSTEM_FLAGS_MASK = 0x0000ffffUL, |
| 319 | // The upper 16 bits are used for track-specific flags. |
| 320 | }; |
| 321 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 322 | TrackBase(const wp<ThreadBase>& thread, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | const sp<Client>& client, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 324 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 325 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 326 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | int frameCount, |
| 328 | uint32_t flags, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 329 | const sp<IMemory>& sharedBuffer, |
| 330 | int sessionId); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 331 | virtual ~TrackBase(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | |
| 333 | virtual status_t start() = 0; |
| 334 | virtual void stop() = 0; |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 335 | sp<IMemory> getCblk() const { return mCblkMemory; } |
Eric Laurent | 6c30a71 | 2009-08-10 23:22:32 -0700 | [diff] [blame] | 336 | audio_track_cblk_t* cblk() const { return mCblk; } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 337 | int sessionId() const { return mSessionId; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 338 | |
| 339 | protected: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 340 | friend class ThreadBase; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | friend class RecordHandle; |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 342 | friend class PlaybackThread; |
| 343 | friend class RecordThread; |
| 344 | friend class MixerThread; |
| 345 | friend class DirectOutputThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 346 | |
| 347 | TrackBase(const TrackBase&); |
| 348 | TrackBase& operator = (const TrackBase&); |
| 349 | |
| 350 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) = 0; |
| 351 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 352 | |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 353 | audio_format_t format() const { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 354 | return mFormat; |
| 355 | } |
| 356 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 357 | int channelCount() const { return mChannelCount; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 358 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 359 | uint32_t channelMask() const { return mChannelMask; } |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 360 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 361 | int sampleRate() const; // FIXME inline after cblk sr moved |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 362 | |
| 363 | void* getBuffer(uint32_t offset, uint32_t frames) const; |
| 364 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 365 | bool isStopped() const { |
| 366 | return mState == STOPPED; |
| 367 | } |
| 368 | |
| 369 | bool isTerminated() const { |
| 370 | return mState == TERMINATED; |
| 371 | } |
| 372 | |
| 373 | bool step(); |
| 374 | void reset(); |
| 375 | |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 376 | const wp<ThreadBase> mThread; |
| 377 | /*const*/ sp<Client> mClient; // see explanation at ~TrackBase() why not const |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 378 | sp<IMemory> mCblkMemory; |
| 379 | audio_track_cblk_t* mCblk; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 380 | void* mBuffer; |
| 381 | void* mBufferEnd; |
| 382 | uint32_t mFrameCount; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 383 | // we don't really need a lock for these |
Glenn Kasten | 5635620 | 2012-01-26 13:39:18 -0800 | [diff] [blame] | 384 | track_state mState; |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 385 | const audio_format_t mFormat; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | uint32_t mFlags; |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 387 | const int mSessionId; |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 388 | uint8_t mChannelCount; |
| 389 | uint32_t mChannelMask; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | }; |
| 391 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 392 | class ConfigEvent { |
| 393 | public: |
| 394 | ConfigEvent() : mEvent(0), mParam(0) {} |
| 395 | |
| 396 | int mEvent; |
| 397 | int mParam; |
| 398 | }; |
| 399 | |
Eric Laurent | 6dbdc40 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 400 | class PMDeathRecipient : public IBinder::DeathRecipient { |
| 401 | public: |
| 402 | PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {} |
| 403 | virtual ~PMDeathRecipient() {} |
| 404 | |
| 405 | // IBinder::DeathRecipient |
| 406 | virtual void binderDied(const wp<IBinder>& who); |
| 407 | |
| 408 | private: |
| 409 | PMDeathRecipient(const PMDeathRecipient&); |
| 410 | PMDeathRecipient& operator = (const PMDeathRecipient&); |
| 411 | |
| 412 | wp<ThreadBase> mThread; |
| 413 | }; |
| 414 | |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 415 | virtual status_t initCheck() const = 0; |
Glenn Kasten | efd511a | 2012-01-26 10:38:26 -0800 | [diff] [blame] | 416 | type_t type() const { return mType; } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 417 | uint32_t sampleRate() const { return mSampleRate; } |
| 418 | int channelCount() const { return mChannelCount; } |
| 419 | audio_format_t format() const { return mFormat; } |
| 420 | size_t frameCount() const { return mFrameCount; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 421 | void wakeUp() { mWaitWorkCV.broadcast(); } |
| 422 | void exit(); |
| 423 | virtual bool checkForNewParameters_l() = 0; |
| 424 | virtual status_t setParameters(const String8& keyValuePairs); |
| 425 | virtual String8 getParameters(const String8& keys) = 0; |
Eric Laurent | eb8f850d | 2010-05-14 03:26:45 -0700 | [diff] [blame] | 426 | virtual void audioConfigChanged_l(int event, int param = 0) = 0; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 427 | void sendConfigEvent(int event, int param = 0); |
Eric Laurent | 8fce46a | 2009-08-04 09:45:33 -0700 | [diff] [blame] | 428 | void sendConfigEvent_l(int event, int param = 0); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 429 | void processConfigEvents(); |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 430 | audio_io_handle_t id() const { return mId;} |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 431 | bool standby() { return mStandby; } |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 432 | uint32_t device() { return mDevice; } |
| 433 | virtual audio_stream_t* stream() = 0; |
| 434 | |
| 435 | sp<EffectHandle> createEffect_l( |
| 436 | const sp<AudioFlinger::Client>& client, |
| 437 | const sp<IEffectClient>& effectClient, |
| 438 | int32_t priority, |
| 439 | int sessionId, |
| 440 | effect_descriptor_t *desc, |
| 441 | int *enabled, |
| 442 | status_t *status); |
| 443 | void disconnectEffect(const sp< EffectModule>& effect, |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 444 | const wp<EffectHandle>& handle, |
| 445 | bool unpiniflast); |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 446 | |
| 447 | // return values for hasAudioSession (bit field) |
| 448 | enum effect_state { |
| 449 | EFFECT_SESSION = 0x1, // the audio session corresponds to at least one |
| 450 | // effect |
| 451 | TRACK_SESSION = 0x2 // the audio session corresponds to at least one |
| 452 | // track |
| 453 | }; |
| 454 | |
| 455 | // get effect chain corresponding to session Id. |
| 456 | sp<EffectChain> getEffectChain(int sessionId); |
| 457 | // same as getEffectChain() but must be called with ThreadBase mutex locked |
| 458 | sp<EffectChain> getEffectChain_l(int sessionId); |
| 459 | // add an effect chain to the chain list (mEffectChains) |
| 460 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain) = 0; |
| 461 | // remove an effect chain from the chain list (mEffectChains) |
| 462 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain) = 0; |
| 463 | // lock mall effect chains Mutexes. Must be called before releasing the |
| 464 | // ThreadBase mutex before processing the mixer and effects. This guarantees the |
| 465 | // integrity of the chains during the process. |
| 466 | void lockEffectChains_l(Vector<sp <EffectChain> >& effectChains); |
| 467 | // unlock effect chains after process |
| 468 | void unlockEffectChains(Vector<sp <EffectChain> >& effectChains); |
| 469 | // set audio mode to all effect chains |
Glenn Kasten | accb114 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 470 | void setMode(audio_mode_t mode); |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 471 | // get effect module with corresponding ID on specified audio session |
| 472 | sp<AudioFlinger::EffectModule> getEffect_l(int sessionId, int effectId); |
| 473 | // add and effect module. Also creates the effect chain is none exists for |
| 474 | // the effects audio session |
| 475 | status_t addEffect_l(const sp< EffectModule>& effect); |
| 476 | // remove and effect module. Also removes the effect chain is this was the last |
| 477 | // effect |
| 478 | void removeEffect_l(const sp< EffectModule>& effect); |
| 479 | // detach all tracks connected to an auxiliary effect |
| 480 | virtual void detachAuxEffect_l(int effectId) {} |
| 481 | // returns either EFFECT_SESSION if effects on this audio session exist in one |
| 482 | // chain, or TRACK_SESSION if tracks on this audio session exist, or both |
| 483 | virtual uint32_t hasAudioSession(int sessionId) = 0; |
| 484 | // the value returned by default implementation is not important as the |
| 485 | // strategy is only meaningful for PlaybackThread which implements this method |
| 486 | virtual uint32_t getStrategyForSession_l(int sessionId) { return 0; } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 487 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 488 | // suspend or restore effect according to the type of effect passed. a NULL |
| 489 | // type pointer means suspend all effects in the session |
| 490 | void setEffectSuspended(const effect_uuid_t *type, |
| 491 | bool suspend, |
| 492 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
| 493 | // check if some effects must be suspended/restored when an effect is enabled |
| 494 | // or disabled |
Eric Laurent | 7fa1cee | 2011-10-19 11:44:54 -0700 | [diff] [blame] | 495 | void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect, |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 496 | bool enabled, |
| 497 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
Eric Laurent | 7fa1cee | 2011-10-19 11:44:54 -0700 | [diff] [blame] | 498 | void checkSuspendOnEffectEnabled_l(const sp<EffectModule>& effect, |
| 499 | bool enabled, |
| 500 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 501 | mutable Mutex mLock; |
| 502 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 503 | protected: |
| 504 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 505 | // entry describing an effect being suspended in mSuspendedSessions keyed vector |
| 506 | class SuspendedSessionDesc : public RefBase { |
| 507 | public: |
| 508 | SuspendedSessionDesc() : mRefCount(0) {} |
| 509 | |
| 510 | int mRefCount; // number of active suspend requests |
| 511 | effect_uuid_t mType; // effect type UUID |
| 512 | }; |
| 513 | |
Eric Laurent | 6dbdc40 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 514 | void acquireWakeLock(); |
| 515 | void acquireWakeLock_l(); |
| 516 | void releaseWakeLock(); |
| 517 | void releaseWakeLock_l(); |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 518 | void setEffectSuspended_l(const effect_uuid_t *type, |
| 519 | bool suspend, |
| 520 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
| 521 | // updated mSuspendedSessions when an effect suspended or restored |
| 522 | void updateSuspendedSessions_l(const effect_uuid_t *type, |
| 523 | bool suspend, |
| 524 | int sessionId); |
| 525 | // check if some effects must be suspended when an effect chain is added |
| 526 | void checkSuspendOnAddEffectChain_l(const sp<EffectChain>& chain); |
Eric Laurent | 6dbdc40 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 527 | |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 528 | friend class AudioFlinger; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 529 | friend class Track; |
| 530 | friend class TrackBase; |
| 531 | friend class PlaybackThread; |
| 532 | friend class MixerThread; |
| 533 | friend class DirectOutputThread; |
| 534 | friend class DuplicatingThread; |
| 535 | friend class RecordThread; |
| 536 | friend class RecordTrack; |
| 537 | |
Glenn Kasten | efd511a | 2012-01-26 10:38:26 -0800 | [diff] [blame] | 538 | const type_t mType; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 539 | Condition mWaitWorkCV; |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 540 | const sp<AudioFlinger> mAudioFlinger; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 541 | uint32_t mSampleRate; |
| 542 | size_t mFrameCount; |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 543 | uint32_t mChannelMask; |
Eric Laurent | b0a0147 | 2010-05-14 05:45:46 -0700 | [diff] [blame] | 544 | uint16_t mChannelCount; |
Glenn Kasten | faf354d | 2012-01-11 09:48:27 -0800 | [diff] [blame] | 545 | size_t mFrameSize; |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 546 | audio_format_t mFormat; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 547 | Condition mParamCond; |
Eric Laurent | 8fce46a | 2009-08-04 09:45:33 -0700 | [diff] [blame] | 548 | Vector<String8> mNewParameters; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 549 | status_t mParamStatus; |
Glenn Kasten | 4b220f0 | 2011-12-13 11:50:00 -0800 | [diff] [blame] | 550 | Vector<ConfigEvent> mConfigEvents; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 551 | bool mStandby; |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 552 | const audio_io_handle_t mId; |
Eric Laurent | 49f02be | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 553 | bool mExiting; |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 554 | Vector< sp<EffectChain> > mEffectChains; |
| 555 | uint32_t mDevice; // output device for PlaybackThread |
| 556 | // input + output devices for RecordThread |
Eric Laurent | 6dbdc40 | 2011-07-22 09:04:31 -0700 | [diff] [blame] | 557 | static const int kNameLength = 32; |
| 558 | char mName[kNameLength]; |
| 559 | sp<IPowerManager> mPowerManager; |
| 560 | sp<IBinder> mWakeLockToken; |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 561 | const sp<PMDeathRecipient> mDeathRecipient; |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 562 | // list of suspended effects per session and per type. The first vector is |
| 563 | // keyed by session ID, the second by type UUID timeLow field |
| 564 | KeyedVector< int, KeyedVector< int, sp<SuspendedSessionDesc> > > mSuspendedSessions; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 565 | }; |
| 566 | |
Glenn Kasten | 3773334 | 2012-02-08 12:36:25 -0800 | [diff] [blame^] | 567 | struct stream_type_t { |
| 568 | stream_type_t() |
| 569 | : volume(1.0f), |
| 570 | mute(false), |
| 571 | valid(true) |
| 572 | { |
| 573 | } |
| 574 | float volume; |
| 575 | bool mute; |
| 576 | bool valid; |
| 577 | }; |
| 578 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 579 | // --- PlaybackThread --- |
| 580 | class PlaybackThread : public ThreadBase { |
| 581 | public: |
| 582 | |
Eric Laurent | 059b4be | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 583 | enum mixer_state { |
| 584 | MIXER_IDLE, |
| 585 | MIXER_TRACKS_ENABLED, |
| 586 | MIXER_TRACKS_READY |
| 587 | }; |
| 588 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 589 | // playback track |
| 590 | class Track : public TrackBase { |
| 591 | public: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 592 | Track( const wp<ThreadBase>& thread, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | const sp<Client>& client, |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 594 | audio_stream_type_t streamType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 596 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 597 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 598 | int frameCount, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 599 | const sp<IMemory>& sharedBuffer, |
| 600 | int sessionId); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 601 | virtual ~Track(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | |
| 603 | void dump(char* buffer, size_t size); |
| 604 | virtual status_t start(); |
| 605 | virtual void stop(); |
| 606 | void pause(); |
| 607 | |
| 608 | void flush(); |
| 609 | void destroy(); |
| 610 | void mute(bool); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 611 | int name() const { |
| 612 | return mName; |
| 613 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 614 | |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 615 | audio_stream_type_t type() const { |
Eric Laurent | 4bc035a | 2009-05-22 09:18:15 -0700 | [diff] [blame] | 616 | return mStreamType; |
| 617 | } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 618 | status_t attachAuxEffect(int EffectId); |
| 619 | void setAuxBuffer(int EffectId, int32_t *buffer); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 620 | int32_t *auxBuffer() const { return mAuxBuffer; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 621 | void setMainBuffer(int16_t *buffer) { mMainBuffer = buffer; } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 622 | int16_t *mainBuffer() const { return mMainBuffer; } |
| 623 | int auxEffectId() const { return mAuxEffectId; } |
Eric Laurent | 4bc035a | 2009-05-22 09:18:15 -0700 | [diff] [blame] | 624 | |
| 625 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 626 | protected: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 627 | friend class ThreadBase; |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 628 | friend class TrackHandle; |
| 629 | friend class PlaybackThread; |
| 630 | friend class MixerThread; |
| 631 | friend class DirectOutputThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | |
| 633 | Track(const Track&); |
| 634 | Track& operator = (const Track&); |
| 635 | |
| 636 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 637 | bool isMuted() const { return mMute; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 638 | bool isPausing() const { |
| 639 | return mState == PAUSING; |
| 640 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 641 | bool isPaused() const { |
| 642 | return mState == PAUSED; |
| 643 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 644 | bool isReady() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 645 | void setPaused() { mState = PAUSED; } |
| 646 | void reset(); |
| 647 | |
Eric Laurent | 49f02be | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 648 | bool isOutputTrack() const { |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 649 | return (mStreamType == AUDIO_STREAM_CNT); |
Eric Laurent | 49f02be | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 650 | } |
| 651 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | // we don't really need a lock for these |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 653 | volatile bool mMute; |
| 654 | // FILLED state is used for suppressing volume ramp at begin of playing |
| 655 | enum {FS_FILLING, FS_FILLED, FS_ACTIVE}; |
| 656 | mutable uint8_t mFillingUpStatus; |
| 657 | int8_t mRetryCount; |
| 658 | sp<IMemory> mSharedBuffer; |
| 659 | bool mResetDone; |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 660 | audio_stream_type_t mStreamType; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 661 | int mName; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 662 | int16_t *mMainBuffer; |
| 663 | int32_t *mAuxBuffer; |
| 664 | int mAuxEffectId; |
Eric Laurent | a92ebfa | 2010-08-31 13:50:07 -0700 | [diff] [blame] | 665 | bool mHasVolumeController; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 666 | }; // end of Track |
| 667 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 668 | |
| 669 | // playback track |
| 670 | class OutputTrack : public Track { |
| 671 | public: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 672 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 673 | class Buffer: public AudioBufferProvider::Buffer { |
| 674 | public: |
| 675 | int16_t *mBuffer; |
| 676 | }; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 677 | |
| 678 | OutputTrack( const wp<ThreadBase>& thread, |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 679 | DuplicatingThread *sourceThread, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 681 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 682 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 683 | int frameCount); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 684 | virtual ~OutputTrack(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 685 | |
| 686 | virtual status_t start(); |
| 687 | virtual void stop(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 688 | bool write(int16_t* data, uint32_t frames); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 689 | bool bufferQueueEmpty() const { return (mBufferQueue.size() == 0) ? true : false; } |
| 690 | bool isActive() const { return mActive; } |
| 691 | const wp<ThreadBase>& thread() const { return mThread; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 692 | |
| 693 | private: |
| 694 | |
Glenn Kasten | 34f9f8b | 2012-01-20 17:00:00 -0800 | [diff] [blame] | 695 | enum { |
| 696 | NO_MORE_BUFFERS = 0x80000001, // same in AudioTrack.h, ok to be different value |
| 697 | }; |
| 698 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 699 | status_t obtainBuffer(AudioBufferProvider::Buffer* buffer, uint32_t waitTimeMs); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 700 | void clearBufferQueue(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 701 | |
| 702 | // Maximum number of pending buffers allocated by OutputTrack::write() |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 703 | static const uint8_t kMaxOverFlowBuffers = 10; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 704 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 705 | Vector < Buffer* > mBufferQueue; |
| 706 | AudioBufferProvider::Buffer mOutBuffer; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 707 | bool mActive; |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 708 | DuplicatingThread* const mSourceThread; // for waitTimeMs() in write() |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 709 | }; // end of OutputTrack |
| 710 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 711 | PlaybackThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, |
| 712 | audio_io_handle_t id, uint32_t device, type_t type); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 713 | virtual ~PlaybackThread(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 714 | |
| 715 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 716 | |
| 717 | // Thread virtuals |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 718 | virtual status_t readyToRun(); |
| 719 | virtual void onFirstRef(); |
| 720 | |
Glenn Kasten | c434c90 | 2011-12-13 11:53:26 -0800 | [diff] [blame] | 721 | virtual status_t initCheck() const { return (mOutput == NULL) ? NO_INIT : NO_ERROR; } |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 722 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 723 | virtual uint32_t latency() const; |
| 724 | |
| 725 | virtual status_t setMasterVolume(float value); |
| 726 | virtual status_t setMasterMute(bool muted); |
| 727 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 728 | virtual float masterVolume() const { return mMasterVolume; } |
| 729 | virtual bool masterMute() const { return mMasterMute; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 730 | |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 731 | virtual status_t setStreamVolume(audio_stream_type_t stream, float value); |
| 732 | virtual status_t setStreamMute(audio_stream_type_t stream, bool muted); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 733 | |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 734 | virtual float streamVolume(audio_stream_type_t stream) const; |
| 735 | virtual bool streamMute(audio_stream_type_t stream) const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 737 | sp<Track> createTrack_l( |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 738 | const sp<AudioFlinger::Client>& client, |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 739 | audio_stream_type_t streamType, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 740 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 741 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 742 | uint32_t channelMask, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 743 | int frameCount, |
| 744 | const sp<IMemory>& sharedBuffer, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 745 | int sessionId, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | status_t *status); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 747 | |
Glenn Kasten | 5b0135e | 2012-01-26 09:46:34 -0800 | [diff] [blame] | 748 | AudioStreamOut* getOutput() const; |
Eric Laurent | 828b977 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 749 | AudioStreamOut* clearOutput(); |
| 750 | virtual audio_stream_t* stream(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 751 | |
Eric Laurent | d5603c1 | 2009-08-06 08:49:39 -0700 | [diff] [blame] | 752 | void suspend() { mSuspended++; } |
| 753 | void restore() { if (mSuspended) mSuspended--; } |
Glenn Kasten | 1dce841 | 2012-01-04 11:01:11 -0800 | [diff] [blame] | 754 | bool isSuspended() const { return (mSuspended != 0); } |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 755 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | eb8f850d | 2010-05-14 03:26:45 -0700 | [diff] [blame] | 756 | virtual void audioConfigChanged_l(int event, int param = 0); |
Eric Laurent | 0986e79 | 2010-01-19 17:37:09 -0800 | [diff] [blame] | 757 | virtual status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 758 | int16_t *mixBuffer() const { return mMixBuffer; }; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 759 | |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 760 | virtual void detachAuxEffect_l(int effectId); |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 761 | status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track, |
| 762 | int EffectId); |
| 763 | status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track, |
| 764 | int EffectId); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 765 | |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 766 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain); |
| 767 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); |
| 768 | virtual uint32_t hasAudioSession(int sessionId); |
| 769 | virtual uint32_t getStrategyForSession_l(int sessionId); |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 770 | |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 771 | void setStreamValid(audio_stream_type_t streamType, bool valid); |
Eric Laurent | 05ce094 | 2011-08-30 10:18:54 -0700 | [diff] [blame] | 772 | |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 773 | protected: |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 774 | int16_t* mMixBuffer; |
Eric Laurent | d5603c1 | 2009-08-06 08:49:39 -0700 | [diff] [blame] | 775 | int mSuspended; |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 776 | int mBytesWritten; |
Glenn Kasten | e6f8a42 | 2011-12-13 11:47:54 -0800 | [diff] [blame] | 777 | private: |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 778 | bool mMasterMute; |
Glenn Kasten | e6f8a42 | 2011-12-13 11:47:54 -0800 | [diff] [blame] | 779 | protected: |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 780 | SortedVector< wp<Track> > mActiveTracks; |
| 781 | |
Eric Laurent | 62443f5 | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 782 | virtual int getTrackName_l() = 0; |
| 783 | virtual void deleteTrackName_l(int name) = 0; |
Eric Laurent | 4433169 | 2011-12-05 09:47:19 -0800 | [diff] [blame] | 784 | virtual uint32_t activeSleepTimeUs(); |
Eric Laurent | 059b4be | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 785 | virtual uint32_t idleSleepTimeUs() = 0; |
Eric Laurent | 8448a79 | 2010-08-18 18:13:17 -0700 | [diff] [blame] | 786 | virtual uint32_t suspendSleepTimeUs() = 0; |
Eric Laurent | 62443f5 | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 787 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 788 | private: |
| 789 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 790 | friend class AudioFlinger; |
Eric Laurent | 6c30a71 | 2009-08-10 23:22:32 -0700 | [diff] [blame] | 791 | friend class OutputTrack; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 792 | friend class Track; |
| 793 | friend class TrackBase; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 794 | friend class MixerThread; |
| 795 | friend class DirectOutputThread; |
| 796 | friend class DuplicatingThread; |
| 797 | |
| 798 | PlaybackThread(const Client&); |
| 799 | PlaybackThread& operator = (const PlaybackThread&); |
| 800 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 801 | status_t addTrack_l(const sp<Track>& track); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 802 | void destroyTrack_l(const sp<Track>& track); |
Eric Laurent | 90681d6 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 803 | void removeTrack_l(const sp<Track>& track); |
Eric Laurent | 62443f5 | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 804 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 805 | void readOutputParameters(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 807 | virtual status_t dumpInternals(int fd, const Vector<String16>& args); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | status_t dumpTracks(int fd, const Vector<String16>& args); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 809 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | SortedVector< sp<Track> > mTracks; |
Glenn Kasten | 6e987a4 | 2012-01-06 08:40:01 -0800 | [diff] [blame] | 811 | // mStreamTypes[] uses 1 additional stream type internally for the OutputTrack used by DuplicatingThread |
Dima Zavin | 24fc2fb | 2011-04-19 22:30:36 -0700 | [diff] [blame] | 812 | stream_type_t mStreamTypes[AUDIO_STREAM_CNT + 1]; |
Glenn Kasten | 5b0135e | 2012-01-26 09:46:34 -0800 | [diff] [blame] | 813 | AudioStreamOut *mOutput; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | float mMasterVolume; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | nsecs_t mLastWriteTime; |
| 816 | int mNumWrites; |
| 817 | int mNumDelayedWrites; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 818 | bool mInWrite; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | }; |
| 820 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 821 | class MixerThread : public PlaybackThread { |
| 822 | public: |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 823 | MixerThread (const sp<AudioFlinger>& audioFlinger, |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 824 | AudioStreamOut* output, |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 825 | audio_io_handle_t id, |
Glenn Kasten | efd511a | 2012-01-26 10:38:26 -0800 | [diff] [blame] | 826 | uint32_t device, |
| 827 | type_t type = MIXER); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 828 | virtual ~MixerThread(); |
| 829 | |
| 830 | // Thread virtuals |
| 831 | virtual bool threadLoop(); |
| 832 | |
Glenn Kasten | bc1d77b | 2012-01-12 16:38:12 -0800 | [diff] [blame] | 833 | void invalidateTracks(audio_stream_type_t streamType); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 834 | virtual bool checkForNewParameters_l(); |
| 835 | virtual status_t dumpInternals(int fd, const Vector<String16>& args); |
| 836 | |
| 837 | protected: |
Glenn Kasten | 789fef1 | 2012-01-26 13:37:52 -0800 | [diff] [blame] | 838 | mixer_state prepareTracks_l(const SortedVector< wp<Track> >& activeTracks, |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 839 | Vector< sp<Track> > *tracksToRemove); |
Eric Laurent | 62443f5 | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 840 | virtual int getTrackName_l(); |
| 841 | virtual void deleteTrackName_l(int name); |
Eric Laurent | 059b4be | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 842 | virtual uint32_t idleSleepTimeUs(); |
Eric Laurent | 8448a79 | 2010-08-18 18:13:17 -0700 | [diff] [blame] | 843 | virtual uint32_t suspendSleepTimeUs(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 844 | |
Eric Laurent | 71c4496 | 2012-01-17 19:20:12 -0800 | [diff] [blame] | 845 | AudioMixer* mAudioMixer; |
Glenn Kasten | 789fef1 | 2012-01-26 13:37:52 -0800 | [diff] [blame] | 846 | mixer_state mPrevMixerStatus; // previous status returned by prepareTracks_l() |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 847 | }; |
| 848 | |
| 849 | class DirectOutputThread : public PlaybackThread { |
| 850 | public: |
| 851 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 852 | DirectOutputThread (const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, |
| 853 | audio_io_handle_t id, uint32_t device); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 854 | virtual ~DirectOutputThread(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 855 | |
| 856 | // Thread virtuals |
| 857 | virtual bool threadLoop(); |
| 858 | |
Eric Laurent | 62443f5 | 2009-10-05 20:29:18 -0700 | [diff] [blame] | 859 | virtual bool checkForNewParameters_l(); |
| 860 | |
| 861 | protected: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 862 | virtual int getTrackName_l(); |
| 863 | virtual void deleteTrackName_l(int name); |
Eric Laurent | 059b4be | 2009-11-09 23:32:22 -0800 | [diff] [blame] | 864 | virtual uint32_t activeSleepTimeUs(); |
| 865 | virtual uint32_t idleSleepTimeUs(); |
Eric Laurent | 8448a79 | 2010-08-18 18:13:17 -0700 | [diff] [blame] | 866 | virtual uint32_t suspendSleepTimeUs(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 867 | |
| 868 | private: |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 869 | void applyVolume(uint16_t leftVol, uint16_t rightVol, bool ramp); |
| 870 | |
| 871 | float mLeftVolFloat; |
| 872 | float mRightVolFloat; |
| 873 | uint16_t mLeftVolShort; |
| 874 | uint16_t mRightVolShort; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 875 | }; |
| 876 | |
| 877 | class DuplicatingThread : public MixerThread { |
| 878 | public: |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 879 | DuplicatingThread (const sp<AudioFlinger>& audioFlinger, MixerThread* mainThread, |
| 880 | audio_io_handle_t id); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 881 | virtual ~DuplicatingThread(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 882 | |
| 883 | // Thread virtuals |
| 884 | virtual bool threadLoop(); |
| 885 | void addOutputTrack(MixerThread* thread); |
| 886 | void removeOutputTrack(MixerThread* thread); |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 887 | uint32_t waitTimeMs() { return mWaitTimeMs; } |
| 888 | protected: |
| 889 | virtual uint32_t activeSleepTimeUs(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 890 | |
| 891 | private: |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 892 | bool outputsReady(SortedVector< sp<OutputTrack> > &outputTracks); |
| 893 | void updateWaitTime(); |
| 894 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 895 | SortedVector < sp<OutputTrack> > mOutputTracks; |
Eric Laurent | 8ac9f8d | 2009-12-18 05:47:48 -0800 | [diff] [blame] | 896 | uint32_t mWaitTimeMs; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 897 | }; |
| 898 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 899 | PlaybackThread *checkPlaybackThread_l(audio_io_handle_t output) const; |
| 900 | MixerThread *checkMixerThread_l(audio_io_handle_t output) const; |
| 901 | RecordThread *checkRecordThread_l(audio_io_handle_t input) const; |
| 902 | float streamVolumeInternal(audio_stream_type_t stream) const |
| 903 | { return mStreamTypes[stream].volume; } |
| 904 | void audioConfigChanged_l(int event, audio_io_handle_t ioHandle, void *param2); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 905 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 906 | // allocate an audio_io_handle_t, session ID, or effect ID |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 907 | uint32_t nextUniqueId(); |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 908 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 909 | status_t moveEffectChain_l(int sessionId, |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 910 | AudioFlinger::PlaybackThread *srcThread, |
Eric Laurent | 493941b | 2010-07-28 01:32:47 -0700 | [diff] [blame] | 911 | AudioFlinger::PlaybackThread *dstThread, |
| 912 | bool reRegister); |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 913 | PlaybackThread *primaryPlaybackThread_l(); |
| 914 | uint32_t primaryOutputDevice_l(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 915 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 916 | friend class AudioBuffer; |
| 917 | |
| 918 | class TrackHandle : public android::BnAudioTrack { |
| 919 | public: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 920 | TrackHandle(const sp<PlaybackThread::Track>& track); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | virtual ~TrackHandle(); |
Glenn Kasten | 0ae4d97 | 2012-01-26 13:40:12 -0800 | [diff] [blame] | 922 | virtual sp<IMemory> getCblk() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 923 | virtual status_t start(); |
| 924 | virtual void stop(); |
| 925 | virtual void flush(); |
| 926 | virtual void mute(bool); |
| 927 | virtual void pause(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 928 | virtual status_t attachAuxEffect(int effectId); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | virtual status_t onTransact( |
| 930 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 931 | private: |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 932 | const sp<PlaybackThread::Track> mTrack; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 933 | }; |
| 934 | |
| 935 | friend class Client; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 936 | friend class PlaybackThread::Track; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 937 | |
| 938 | |
Eric Laurent | b9481d8 | 2009-09-17 05:12:56 -0700 | [diff] [blame] | 939 | void removeClient_l(pid_t pid); |
Eric Laurent | 4f0f17d | 2010-05-12 02:05:53 -0700 | [diff] [blame] | 940 | void removeNotificationClient(pid_t pid); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 941 | |
| 942 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 943 | // record thread |
| 944 | class RecordThread : public ThreadBase, public AudioBufferProvider |
| 945 | { |
| 946 | public: |
| 947 | |
| 948 | // record track |
| 949 | class RecordTrack : public TrackBase { |
| 950 | public: |
| 951 | RecordTrack(const wp<ThreadBase>& thread, |
| 952 | const sp<Client>& client, |
| 953 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 954 | audio_format_t format, |
Jean-Michel Trivi | 5439223 | 2011-05-24 15:53:33 -0700 | [diff] [blame] | 955 | uint32_t channelMask, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 956 | int frameCount, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 957 | uint32_t flags, |
| 958 | int sessionId); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 959 | virtual ~RecordTrack(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 960 | |
| 961 | virtual status_t start(); |
| 962 | virtual void stop(); |
| 963 | |
| 964 | bool overflow() { bool tmp = mOverflow; mOverflow = false; return tmp; } |
| 965 | bool setOverflow() { bool tmp = mOverflow; mOverflow = true; return tmp; } |
| 966 | |
Eric Laurent | 3fdb126 | 2009-11-07 00:01:32 -0800 | [diff] [blame] | 967 | void dump(char* buffer, size_t size); |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 968 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 969 | private: |
| 970 | friend class AudioFlinger; |
Eric Laurent | 2c817f5 | 2009-07-23 13:17:39 -0700 | [diff] [blame] | 971 | friend class RecordThread; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 972 | |
| 973 | RecordTrack(const RecordTrack&); |
| 974 | RecordTrack& operator = (const RecordTrack&); |
| 975 | |
| 976 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 977 | |
| 978 | bool mOverflow; |
| 979 | }; |
| 980 | |
| 981 | |
| 982 | RecordThread(const sp<AudioFlinger>& audioFlinger, |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 983 | AudioStreamIn *input, |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 984 | uint32_t sampleRate, |
Eric Laurent | 49f02be | 2009-11-19 09:00:56 -0800 | [diff] [blame] | 985 | uint32_t channels, |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 986 | audio_io_handle_t id, |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 987 | uint32_t device); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 988 | virtual ~RecordThread(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 989 | |
| 990 | virtual bool threadLoop(); |
Eric Laurent | 828b977 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 991 | virtual status_t readyToRun(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 992 | virtual void onFirstRef(); |
| 993 | |
Glenn Kasten | c434c90 | 2011-12-13 11:53:26 -0800 | [diff] [blame] | 994 | virtual status_t initCheck() const { return (mInput == NULL) ? NO_INIT : NO_ERROR; } |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 995 | sp<AudioFlinger::RecordThread::RecordTrack> createRecordTrack_l( |
| 996 | const sp<AudioFlinger::Client>& client, |
| 997 | uint32_t sampleRate, |
Glenn Kasten | 0a204ed | 2012-01-12 12:27:51 -0800 | [diff] [blame] | 998 | audio_format_t format, |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 999 | int channelMask, |
| 1000 | int frameCount, |
| 1001 | uint32_t flags, |
| 1002 | int sessionId, |
| 1003 | status_t *status); |
| 1004 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1005 | status_t start(RecordTrack* recordTrack); |
| 1006 | void stop(RecordTrack* recordTrack); |
| 1007 | status_t dump(int fd, const Vector<String16>& args); |
Glenn Kasten | 5b0135e | 2012-01-26 09:46:34 -0800 | [diff] [blame] | 1008 | AudioStreamIn* getInput() const; |
Eric Laurent | 828b977 | 2011-08-07 16:32:26 -0700 | [diff] [blame] | 1009 | AudioStreamIn* clearInput(); |
| 1010 | virtual audio_stream_t* stream(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1011 | |
| 1012 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 1013 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 1014 | virtual bool checkForNewParameters_l(); |
| 1015 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | eb8f850d | 2010-05-14 03:26:45 -0700 | [diff] [blame] | 1016 | virtual void audioConfigChanged_l(int event, int param = 0); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1017 | void readInputParameters(); |
Eric Laurent | 47d0a92 | 2010-02-26 02:47:27 -0800 | [diff] [blame] | 1018 | virtual unsigned int getInputFramesLost(); |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1019 | |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1020 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain); |
| 1021 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); |
| 1022 | virtual uint32_t hasAudioSession(int sessionId); |
Eric Laurent | 6639b55 | 2011-08-01 09:52:20 -0700 | [diff] [blame] | 1023 | RecordTrack* track(); |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1024 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1025 | private: |
| 1026 | RecordThread(); |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1027 | AudioStreamIn *mInput; |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1028 | RecordTrack* mTrack; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1029 | sp<RecordTrack> mActiveTrack; |
| 1030 | Condition mStartStopCond; |
| 1031 | AudioResampler *mResampler; |
| 1032 | int32_t *mRsmpOutBuffer; |
| 1033 | int16_t *mRsmpInBuffer; |
| 1034 | size_t mRsmpInIndex; |
| 1035 | size_t mInputBytes; |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 1036 | const int mReqChannelCount; |
| 1037 | const uint32_t mReqSampleRate; |
Eric Laurent | 9cc489a | 2009-12-05 05:20:01 -0800 | [diff] [blame] | 1038 | ssize_t mBytesRead; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1039 | }; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1040 | |
| 1041 | class RecordHandle : public android::BnAudioRecord { |
| 1042 | public: |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1043 | RecordHandle(const sp<RecordThread::RecordTrack>& recordTrack); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1044 | virtual ~RecordHandle(); |
Glenn Kasten | 0ae4d97 | 2012-01-26 13:40:12 -0800 | [diff] [blame] | 1045 | virtual sp<IMemory> getCblk() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1046 | virtual status_t start(); |
| 1047 | virtual void stop(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1048 | virtual status_t onTransact( |
| 1049 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 1050 | private: |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 1051 | const sp<RecordThread::RecordTrack> mRecordTrack; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1052 | }; |
| 1053 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1054 | //--- Audio Effect Management |
| 1055 | |
| 1056 | // EffectModule and EffectChain classes both have their own mutex to protect |
| 1057 | // state changes or resource modifications. Always respect the following order |
| 1058 | // if multiple mutexes must be acquired to avoid cross deadlock: |
| 1059 | // AudioFlinger -> ThreadBase -> EffectChain -> EffectModule |
| 1060 | |
| 1061 | // The EffectModule class is a wrapper object controlling the effect engine implementation |
| 1062 | // in the effect library. It prevents concurrent calls to process() and command() functions |
| 1063 | // from different client threads. It keeps a list of EffectHandle objects corresponding |
| 1064 | // to all client applications using this effect and notifies applications of effect state, |
| 1065 | // control or parameter changes. It manages the activation state machine to send appropriate |
| 1066 | // reset, enable, disable commands to effect engine and provide volume |
| 1067 | // ramping when effects are activated/deactivated. |
| 1068 | // When controlling an auxiliary effect, the EffectModule also provides an input buffer used by |
| 1069 | // the attached track(s) to accumulate their auxiliary channel. |
| 1070 | class EffectModule: public RefBase { |
| 1071 | public: |
| 1072 | EffectModule(const wp<ThreadBase>& wThread, |
| 1073 | const wp<AudioFlinger::EffectChain>& chain, |
| 1074 | effect_descriptor_t *desc, |
| 1075 | int id, |
| 1076 | int sessionId); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 1077 | virtual ~EffectModule(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1078 | |
| 1079 | enum effect_state { |
| 1080 | IDLE, |
Eric Laurent | 7d850f2 | 2010-07-09 13:34:17 -0700 | [diff] [blame] | 1081 | RESTART, |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1082 | STARTING, |
| 1083 | ACTIVE, |
| 1084 | STOPPING, |
Eric Laurent | 21b5c47 | 2011-07-26 20:54:46 -0700 | [diff] [blame] | 1085 | STOPPED, |
| 1086 | DESTROYED |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1087 | }; |
| 1088 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1089 | int id() const { return mId; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1090 | void process(); |
Eric Laurent | 7d850f2 | 2010-07-09 13:34:17 -0700 | [diff] [blame] | 1091 | void updateState(); |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 1092 | status_t command(uint32_t cmdCode, |
| 1093 | uint32_t cmdSize, |
| 1094 | void *pCmdData, |
| 1095 | uint32_t *replySize, |
| 1096 | void *pReplyData); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1097 | |
Eric Laurent | df9b81c | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 1098 | void reset_l(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1099 | status_t configure(); |
| 1100 | status_t init(); |
Glenn Kasten | 452d6d6 | 2012-01-26 13:43:46 -0800 | [diff] [blame] | 1101 | effect_state state() const { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1102 | return mState; |
| 1103 | } |
| 1104 | uint32_t status() { |
| 1105 | return mStatus; |
| 1106 | } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1107 | int sessionId() const { |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1108 | return mSessionId; |
| 1109 | } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1110 | status_t setEnabled(bool enabled); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1111 | bool isEnabled() const; |
| 1112 | bool isProcessEnabled() const; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1113 | |
| 1114 | void setInBuffer(int16_t *buffer) { mConfig.inputCfg.buffer.s16 = buffer; } |
| 1115 | int16_t *inBuffer() { return mConfig.inputCfg.buffer.s16; } |
| 1116 | void setOutBuffer(int16_t *buffer) { mConfig.outputCfg.buffer.s16 = buffer; } |
| 1117 | int16_t *outBuffer() { return mConfig.outputCfg.buffer.s16; } |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1118 | void setChain(const wp<EffectChain>& chain) { mChain = chain; } |
| 1119 | void setThread(const wp<ThreadBase>& thread) { mThread = thread; } |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 1120 | const wp<ThreadBase>& thread() { return mThread; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1121 | |
Glenn Kasten | 1f812f7 | 2012-01-30 10:15:48 -0800 | [diff] [blame] | 1122 | status_t addHandle(const sp<EffectHandle>& handle); |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1123 | void disconnect(const wp<EffectHandle>& handle, bool unpiniflast); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1124 | size_t removeHandle (const wp<EffectHandle>& handle); |
| 1125 | |
| 1126 | effect_descriptor_t& desc() { return mDescriptor; } |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 1127 | wp<EffectChain>& chain() { return mChain; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1128 | |
| 1129 | status_t setDevice(uint32_t device); |
| 1130 | status_t setVolume(uint32_t *left, uint32_t *right, bool controller); |
Glenn Kasten | accb114 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 1131 | status_t setMode(audio_mode_t mode); |
Eric Laurent | 6fccbd0 | 2011-10-05 17:42:25 -0700 | [diff] [blame] | 1132 | status_t start(); |
Eric Laurent | 21b5c47 | 2011-07-26 20:54:46 -0700 | [diff] [blame] | 1133 | status_t stop(); |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1134 | void setSuspended(bool suspended); |
Glenn Kasten | 1dce841 | 2012-01-04 11:01:11 -0800 | [diff] [blame] | 1135 | bool suspended() const; |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1136 | |
| 1137 | sp<EffectHandle> controlHandle(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1138 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1139 | bool isPinned() const { return mPinned; } |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1140 | void unPin() { mPinned = false; } |
| 1141 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1142 | status_t dump(int fd, const Vector<String16>& args); |
| 1143 | |
| 1144 | protected: |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1145 | friend class EffectHandle; |
| 1146 | friend class AudioFlinger; |
| 1147 | bool mPinned; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1148 | |
Eric Laurent | 7d850f2 | 2010-07-09 13:34:17 -0700 | [diff] [blame] | 1149 | // Maximum time allocated to effect engines to complete the turn off sequence |
| 1150 | static const uint32_t MAX_DISABLE_TIME_MS = 10000; |
| 1151 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1152 | EffectModule(const EffectModule&); |
| 1153 | EffectModule& operator = (const EffectModule&); |
| 1154 | |
Eric Laurent | df9b81c | 2010-07-02 08:12:41 -0700 | [diff] [blame] | 1155 | status_t start_l(); |
| 1156 | status_t stop_l(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1157 | |
Glenn Kasten | 1dce841 | 2012-01-04 11:01:11 -0800 | [diff] [blame] | 1158 | mutable Mutex mLock; // mutex for process, commands and handles list protection |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1159 | wp<ThreadBase> mThread; // parent thread |
| 1160 | wp<EffectChain> mChain; // parent effect chain |
| 1161 | int mId; // this instance unique ID |
| 1162 | int mSessionId; // audio session ID |
| 1163 | effect_descriptor_t mDescriptor;// effect descriptor received from effect engine |
| 1164 | effect_config_t mConfig; // input and output audio configuration |
Eric Laurent | 0fb66c2 | 2011-05-17 19:16:02 -0700 | [diff] [blame] | 1165 | effect_handle_t mEffectInterface; // Effect module C API |
Glenn Kasten | 452d6d6 | 2012-01-26 13:43:46 -0800 | [diff] [blame] | 1166 | status_t mStatus; // initialization status |
| 1167 | effect_state mState; // current activation state |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1168 | Vector< wp<EffectHandle> > mHandles; // list of client handles |
Eric Laurent | 7d850f2 | 2010-07-09 13:34:17 -0700 | [diff] [blame] | 1169 | uint32_t mMaxDisableWaitCnt; // maximum grace period before forcing an effect off after |
| 1170 | // sending disable command. |
| 1171 | uint32_t mDisableWaitCnt; // current process() calls count during disable period. |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1172 | bool mSuspended; // effect is suspended: temporarily disabled by framework |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1173 | }; |
| 1174 | |
| 1175 | // The EffectHandle class implements the IEffect interface. It provides resources |
| 1176 | // to receive parameter updates, keeps track of effect control |
| 1177 | // ownership and state and has a pointer to the EffectModule object it is controlling. |
| 1178 | // There is one EffectHandle object for each application controlling (or using) |
| 1179 | // an effect module. |
| 1180 | // The EffectHandle is obtained by calling AudioFlinger::createEffect(). |
| 1181 | class EffectHandle: public android::BnEffect { |
| 1182 | public: |
| 1183 | |
| 1184 | EffectHandle(const sp<EffectModule>& effect, |
| 1185 | const sp<AudioFlinger::Client>& client, |
| 1186 | const sp<IEffectClient>& effectClient, |
| 1187 | int32_t priority); |
| 1188 | virtual ~EffectHandle(); |
| 1189 | |
| 1190 | // IEffect |
| 1191 | virtual status_t enable(); |
| 1192 | virtual status_t disable(); |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 1193 | virtual status_t command(uint32_t cmdCode, |
| 1194 | uint32_t cmdSize, |
| 1195 | void *pCmdData, |
| 1196 | uint32_t *replySize, |
| 1197 | void *pReplyData); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1198 | virtual void disconnect(); |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1199 | virtual void disconnect(bool unpiniflast); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1200 | virtual sp<IMemory> getCblk() const { return mCblkMemory; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1201 | virtual status_t onTransact(uint32_t code, const Parcel& data, |
| 1202 | Parcel* reply, uint32_t flags); |
| 1203 | |
| 1204 | |
| 1205 | // Give or take control of effect module |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1206 | // - hasControl: true if control is given, false if removed |
| 1207 | // - signal: true client app should be signaled of change, false otherwise |
| 1208 | // - enabled: state of the effect when control is passed |
| 1209 | void setControl(bool hasControl, bool signal, bool enabled); |
Eric Laurent | a4c72ac | 2010-07-28 05:40:18 -0700 | [diff] [blame] | 1210 | void commandExecuted(uint32_t cmdCode, |
| 1211 | uint32_t cmdSize, |
| 1212 | void *pCmdData, |
| 1213 | uint32_t replySize, |
| 1214 | void *pReplyData); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1215 | void setEnabled(bool enabled); |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1216 | bool enabled() const { return mEnabled; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1217 | |
| 1218 | // Getters |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1219 | int id() const { return mEffect->id(); } |
| 1220 | int priority() const { return mPriority; } |
| 1221 | bool hasControl() const { return mHasControl; } |
| 1222 | sp<EffectModule> effect() const { return mEffect; } |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1223 | |
| 1224 | void dump(char* buffer, size_t size); |
| 1225 | |
| 1226 | protected: |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1227 | friend class AudioFlinger; |
| 1228 | friend class EffectModule; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1229 | EffectHandle(const EffectHandle&); |
| 1230 | EffectHandle& operator =(const EffectHandle&); |
| 1231 | |
| 1232 | sp<EffectModule> mEffect; // pointer to controlled EffectModule |
| 1233 | sp<IEffectClient> mEffectClient; // callback interface for client notifications |
Glenn Kasten | 803a86a | 2012-01-25 14:28:29 -0800 | [diff] [blame] | 1234 | /*const*/ sp<Client> mClient; // client for shared memory allocation, see disconnect() |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1235 | sp<IMemory> mCblkMemory; // shared memory for control block |
| 1236 | effect_param_cblk_t* mCblk; // control block for deferred parameter setting via shared memory |
| 1237 | uint8_t* mBuffer; // pointer to parameter area in shared memory |
| 1238 | int mPriority; // client application priority to control the effect |
| 1239 | bool mHasControl; // true if this handle is controlling the effect |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1240 | bool mEnabled; // cached enable state: needed when the effect is |
| 1241 | // restored after being suspended |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1242 | }; |
| 1243 | |
| 1244 | // the EffectChain class represents a group of effects associated to one audio session. |
| 1245 | // There can be any number of EffectChain objects per output mixer thread (PlaybackThread). |
| 1246 | // The EffecChain with session ID 0 contains global effects applied to the output mix. |
| 1247 | // Effects in this chain can be insert or auxiliary. Effects in other chains (attached to tracks) |
| 1248 | // are insert only. The EffectChain maintains an ordered list of effect module, the order corresponding |
| 1249 | // in the effect process order. When attached to a track (session ID != 0), it also provide it's own |
| 1250 | // input buffer used by the track as accumulation buffer. |
| 1251 | class EffectChain: public RefBase { |
| 1252 | public: |
| 1253 | EffectChain(const wp<ThreadBase>& wThread, int sessionId); |
Glenn Kasten | b163138 | 2012-01-30 14:54:39 -0800 | [diff] [blame] | 1254 | virtual ~EffectChain(); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1255 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1256 | // special key used for an entry in mSuspendedEffects keyed vector |
| 1257 | // corresponding to a suspend all request. |
| 1258 | static const int kKeyForSuspendAll = 0; |
| 1259 | |
Eric Laurent | f9c361d | 2011-11-11 15:42:52 -0800 | [diff] [blame] | 1260 | // minimum duration during which we force calling effect process when last track on |
| 1261 | // a session is stopped or removed to allow effect tail to be rendered |
| 1262 | static const int kProcessTailDurationMs = 1000; |
| 1263 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1264 | void process_l(); |
| 1265 | |
| 1266 | void lock() { |
| 1267 | mLock.lock(); |
| 1268 | } |
| 1269 | void unlock() { |
| 1270 | mLock.unlock(); |
| 1271 | } |
| 1272 | |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1273 | status_t addEffect_l(const sp<EffectModule>& handle); |
Eric Laurent | 76c40f7 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1274 | size_t removeEffect_l(const sp<EffectModule>& handle); |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1275 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1276 | int sessionId() const { return mSessionId; } |
Eric Laurent | 464d5b3 | 2011-06-17 21:29:58 -0700 | [diff] [blame] | 1277 | void setSessionId(int sessionId) { mSessionId = sessionId; } |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1278 | |
Eric Laurent | 76c40f7 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1279 | sp<EffectModule> getEffectFromDesc_l(effect_descriptor_t *descriptor); |
| 1280 | sp<EffectModule> getEffectFromId_l(int id); |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1281 | sp<EffectModule> getEffectFromType_l(const effect_uuid_t *type); |
Eric Laurent | 76c40f7 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1282 | bool setVolume_l(uint32_t *left, uint32_t *right); |
| 1283 | void setDevice_l(uint32_t device); |
Glenn Kasten | accb114 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 1284 | void setMode_l(audio_mode_t mode); |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 1285 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1286 | void setInBuffer(int16_t *buffer, bool ownsBuffer = false) { |
| 1287 | mInBuffer = buffer; |
| 1288 | mOwnInBuffer = ownsBuffer; |
| 1289 | } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1290 | int16_t *inBuffer() const { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1291 | return mInBuffer; |
| 1292 | } |
| 1293 | void setOutBuffer(int16_t *buffer) { |
| 1294 | mOutBuffer = buffer; |
| 1295 | } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1296 | int16_t *outBuffer() const { |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1297 | return mOutBuffer; |
| 1298 | } |
| 1299 | |
Eric Laurent | 90681d6 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 1300 | void incTrackCnt() { android_atomic_inc(&mTrackCnt); } |
| 1301 | void decTrackCnt() { android_atomic_dec(&mTrackCnt); } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1302 | int32_t trackCnt() const { return mTrackCnt;} |
Eric Laurent | 90681d6 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 1303 | |
Eric Laurent | f9c361d | 2011-11-11 15:42:52 -0800 | [diff] [blame] | 1304 | void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt); |
| 1305 | mTailBufferCount = mMaxTailBuffers; } |
Eric Laurent | 90681d6 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 1306 | void decActiveTrackCnt() { android_atomic_dec(&mActiveTrackCnt); } |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1307 | int32_t activeTrackCnt() const { return mActiveTrackCnt;} |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1308 | |
Glenn Kasten | eabd94a | 2012-02-02 14:06:11 -0800 | [diff] [blame] | 1309 | uint32_t strategy() const { return mStrategy; } |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1310 | void setStrategy(uint32_t strategy) |
| 1311 | { mStrategy = strategy; } |
| 1312 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1313 | // suspend effect of the given type |
| 1314 | void setEffectSuspended_l(const effect_uuid_t *type, |
| 1315 | bool suspend); |
| 1316 | // suspend all eligible effects |
| 1317 | void setEffectSuspendedAll_l(bool suspend); |
| 1318 | // check if effects should be suspend or restored when a given effect is enable or disabled |
Eric Laurent | 7fa1cee | 2011-10-19 11:44:54 -0700 | [diff] [blame] | 1319 | void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect, |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1320 | bool enabled); |
| 1321 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1322 | status_t dump(int fd, const Vector<String16>& args); |
| 1323 | |
| 1324 | protected: |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1325 | friend class AudioFlinger; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1326 | EffectChain(const EffectChain&); |
| 1327 | EffectChain& operator =(const EffectChain&); |
| 1328 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1329 | class SuspendedEffectDesc : public RefBase { |
| 1330 | public: |
| 1331 | SuspendedEffectDesc() : mRefCount(0) {} |
| 1332 | |
| 1333 | int mRefCount; |
| 1334 | effect_uuid_t mType; |
| 1335 | wp<EffectModule> mEffect; |
| 1336 | }; |
| 1337 | |
| 1338 | // get a list of effect modules to suspend when an effect of the type |
| 1339 | // passed is enabled. |
Glenn Kasten | 9704026 | 2012-01-30 12:56:03 -0800 | [diff] [blame] | 1340 | void getSuspendEligibleEffects(Vector< sp<EffectModule> > &effects); |
| 1341 | |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1342 | // get an effect module if it is currently enable |
| 1343 | sp<EffectModule> getEffectIfEnabled(const effect_uuid_t *type); |
Eric Laurent | 6752ec8 | 2011-08-10 10:37:50 -0700 | [diff] [blame] | 1344 | // true if the effect whose descriptor is passed can be suspended |
| 1345 | // OEMs can modify the rules implemented in this method to exclude specific effect |
| 1346 | // types or implementations from the suspend/restore mechanism. |
| 1347 | bool isEffectEligibleForSuspend(const effect_descriptor_t& desc); |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1348 | |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1349 | wp<ThreadBase> mThread; // parent mixer thread |
| 1350 | Mutex mLock; // mutex protecting effect list |
| 1351 | Vector<sp<EffectModule> > mEffects; // list of effect modules |
| 1352 | int mSessionId; // audio session ID |
| 1353 | int16_t *mInBuffer; // chain input buffer |
| 1354 | int16_t *mOutBuffer; // chain output buffer |
Eric Laurent | 90681d6 | 2011-05-09 12:09:06 -0700 | [diff] [blame] | 1355 | volatile int32_t mActiveTrackCnt; // number of active tracks connected |
| 1356 | volatile int32_t mTrackCnt; // number of tracks connected |
Eric Laurent | f9c361d | 2011-11-11 15:42:52 -0800 | [diff] [blame] | 1357 | int32_t mTailBufferCount; // current effect tail buffer count |
| 1358 | int32_t mMaxTailBuffers; // maximum effect tail buffers |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1359 | bool mOwnInBuffer; // true if the chain owns its input buffer |
Eric Laurent | 76c40f7 | 2010-07-15 12:50:15 -0700 | [diff] [blame] | 1360 | int mVolumeCtrlIdx; // index of insert effect having control over volume |
| 1361 | uint32_t mLeftVolume; // previous volume on left channel |
| 1362 | uint32_t mRightVolume; // previous volume on right channel |
Eric Laurent | 0d7e048 | 2010-07-19 06:24:46 -0700 | [diff] [blame] | 1363 | uint32_t mNewLeftVolume; // new volume on left channel |
| 1364 | uint32_t mNewRightVolume; // new volume on right channel |
Eric Laurent | 8ed6ed0 | 2010-07-13 04:45:46 -0700 | [diff] [blame] | 1365 | uint32_t mStrategy; // strategy for this effect chain |
Eric Laurent | f82fccd | 2011-07-27 19:49:51 -0700 | [diff] [blame] | 1366 | // mSuspendedEffects lists all effect currently suspended in the chain |
| 1367 | // use effect type UUID timelow field as key. There is no real risk of identical |
| 1368 | // timeLow fields among effect type UUIDs. |
| 1369 | KeyedVector< int, sp<SuspendedEffectDesc> > mSuspendedEffects; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1370 | }; |
| 1371 | |
Glenn Kasten | 5b0135e | 2012-01-26 09:46:34 -0800 | [diff] [blame] | 1372 | // AudioStreamOut and AudioStreamIn are immutable, so their fields are const. |
| 1373 | // For emphasis, we could also make all pointers to them be "const *", |
| 1374 | // but that would clutter the code unnecessarily. |
| 1375 | |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1376 | struct AudioStreamOut { |
Glenn Kasten | 5b0135e | 2012-01-26 09:46:34 -0800 | [diff] [blame] | 1377 | audio_hw_device_t* const hwDev; |
| 1378 | audio_stream_out_t* const stream; |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1379 | |
| 1380 | AudioStreamOut(audio_hw_device_t *dev, audio_stream_out_t *out) : |
| 1381 | hwDev(dev), stream(out) {} |
| 1382 | }; |
| 1383 | |
| 1384 | struct AudioStreamIn { |
Glenn Kasten | 5b0135e | 2012-01-26 09:46:34 -0800 | [diff] [blame] | 1385 | audio_hw_device_t* const hwDev; |
| 1386 | audio_stream_in_t* const stream; |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1387 | |
| 1388 | AudioStreamIn(audio_hw_device_t *dev, audio_stream_in_t *in) : |
| 1389 | hwDev(dev), stream(in) {} |
| 1390 | }; |
| 1391 | |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1392 | struct AudioSessionRef { |
Glenn Kasten | dc3ac85 | 2012-01-25 15:28:08 -0800 | [diff] [blame] | 1393 | // FIXME rename parameter names when fields get "m" prefix |
| 1394 | AudioSessionRef(int sessionid_, pid_t pid_) : |
| 1395 | sessionid(sessionid_), pid(pid_), cnt(1) {} |
| 1396 | const int sessionid; |
| 1397 | const pid_t pid; |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1398 | int cnt; |
| 1399 | }; |
| 1400 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1401 | friend class RecordThread; |
| 1402 | friend class PlaybackThread; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1403 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1404 | mutable Mutex mLock; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1405 | |
Glenn Kasten | 803a86a | 2012-01-25 14:28:29 -0800 | [diff] [blame] | 1406 | DefaultKeyedVector< pid_t, wp<Client> > mClients; // see ~Client() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1407 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1408 | mutable Mutex mHardwareLock; |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1409 | audio_hw_device_t* mPrimaryHardwareDev; |
| 1410 | Vector<audio_hw_device_t*> mAudioHwDevs; |
Glenn Kasten | a934c2c | 2012-01-04 11:02:33 -0800 | [diff] [blame] | 1411 | mutable hardware_call_state mHardwareStatus; // for dump only |
The Android Open Source Project | c39a6e0 | 2009-03-11 12:11:56 -0700 | [diff] [blame] | 1412 | |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1413 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1414 | DefaultKeyedVector< audio_io_handle_t, sp<PlaybackThread> > mPlaybackThreads; |
Glenn Kasten | 3773334 | 2012-02-08 12:36:25 -0800 | [diff] [blame^] | 1415 | stream_type_t mStreamTypes[AUDIO_STREAM_CNT]; |
Glenn Kasten | e6f8a42 | 2011-12-13 11:47:54 -0800 | [diff] [blame] | 1416 | |
| 1417 | // both are protected by mLock |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1418 | float mMasterVolume; |
| 1419 | bool mMasterMute; |
| 1420 | |
Glenn Kasten | 39d00cb | 2012-01-17 11:09:42 -0800 | [diff] [blame] | 1421 | DefaultKeyedVector< audio_io_handle_t, sp<RecordThread> > mRecordThreads; |
Eric Laurent | a553c25 | 2009-07-17 12:17:14 -0700 | [diff] [blame] | 1422 | |
Eric Laurent | 4f0f17d | 2010-05-12 02:05:53 -0700 | [diff] [blame] | 1423 | DefaultKeyedVector< pid_t, sp<NotificationClient> > mNotificationClients; |
Eric Laurent | 65b6545 | 2010-06-01 23:49:17 -0700 | [diff] [blame] | 1424 | volatile int32_t mNextUniqueId; |
Glenn Kasten | accb114 | 2012-01-04 11:00:47 -0800 | [diff] [blame] | 1425 | audio_mode_t mMode; |
Eric Laurent | 2d95dfb | 2011-08-29 12:42:48 -0700 | [diff] [blame] | 1426 | bool mBtNrecIsOff; |
Eric Laurent | 53334cd | 2010-06-23 17:38:20 -0700 | [diff] [blame] | 1427 | |
Marco Nelissen | c74b93f | 2011-08-02 13:33:41 -0700 | [diff] [blame] | 1428 | Vector<AudioSessionRef*> mAudioSessionRefs; |
Glenn Kasten | e6f8a42 | 2011-12-13 11:47:54 -0800 | [diff] [blame] | 1429 | |
| 1430 | float masterVolume_l() const { return mMasterVolume; } |
| 1431 | bool masterMute_l() const { return mMasterMute; } |
Glenn Kasten | 803a86a | 2012-01-25 14:28:29 -0800 | [diff] [blame] | 1432 | |
| 1433 | private: |
| 1434 | sp<Client> registerPid_l(pid_t pid); // always returns non-0 |
| 1435 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1436 | }; |
| 1437 | |
Dima Zavin | 31f18889 | 2011-04-18 16:57:27 -0700 | [diff] [blame] | 1438 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1439 | // ---------------------------------------------------------------------------- |
| 1440 | |
| 1441 | }; // namespace android |
| 1442 | |
| 1443 | #endif // ANDROID_AUDIO_FLINGER_H |