Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2012, 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 INCLUDING_FROM_AUDIOFLINGER_H |
| 19 | #error This header file should only be included from AudioFlinger.h |
| 20 | #endif |
| 21 | |
| 22 | class ThreadBase : public Thread { |
| 23 | public: |
| 24 | |
| 25 | #include "TrackBase.h" |
| 26 | |
| 27 | enum type_t { |
| 28 | MIXER, // Thread class is MixerThread |
| 29 | DIRECT, // Thread class is DirectOutputThread |
| 30 | DUPLICATING, // Thread class is DuplicatingThread |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 31 | RECORD, // Thread class is RecordThread |
| 32 | OFFLOAD // Thread class is OffloadThread |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 33 | }; |
| 34 | |
| 35 | ThreadBase(const sp<AudioFlinger>& audioFlinger, audio_io_handle_t id, |
| 36 | audio_devices_t outDevice, audio_devices_t inDevice, type_t type); |
| 37 | virtual ~ThreadBase(); |
| 38 | |
Glenn Kasten | cf04c2c | 2013-08-06 07:41:16 -0700 | [diff] [blame] | 39 | virtual status_t readyToRun(); |
| 40 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 41 | void dumpBase(int fd, const Vector<String16>& args); |
| 42 | void dumpEffectChains(int fd, const Vector<String16>& args); |
| 43 | |
| 44 | void clearPowerManager(); |
| 45 | |
| 46 | // base for record and playback |
| 47 | enum { |
| 48 | CFG_EVENT_IO, |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 49 | CFG_EVENT_PRIO, |
| 50 | CFG_EVENT_SET_PARAMETER, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 51 | }; |
| 52 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 53 | class ConfigEventData: public RefBase { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 54 | public: |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 55 | virtual ~ConfigEventData() {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 56 | |
| 57 | virtual void dump(char *buffer, size_t size) = 0; |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 58 | protected: |
| 59 | ConfigEventData() {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 60 | }; |
| 61 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 62 | // Config event sequence by client if status needed (e.g binder thread calling setParameters()): |
| 63 | // 1. create SetParameterConfigEvent. This sets mWaitStatus in config event |
| 64 | // 2. Lock mLock |
| 65 | // 3. Call sendConfigEvent_l(): Append to mConfigEvents and mWaitWorkCV.signal |
| 66 | // 4. sendConfigEvent_l() reads status from event->mStatus; |
| 67 | // 5. sendConfigEvent_l() returns status |
| 68 | // 6. Unlock |
| 69 | // |
| 70 | // Parameter sequence by server: threadLoop calling processConfigEvents_l(): |
| 71 | // 1. Lock mLock |
| 72 | // 2. If there is an entry in mConfigEvents proceed ... |
| 73 | // 3. Read first entry in mConfigEvents |
| 74 | // 4. Remove first entry from mConfigEvents |
| 75 | // 5. Process |
| 76 | // 6. Set event->mStatus |
| 77 | // 7. event->mCond.signal |
| 78 | // 8. Unlock |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 79 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 80 | class ConfigEvent: public RefBase { |
| 81 | public: |
| 82 | virtual ~ConfigEvent() {} |
| 83 | |
| 84 | void dump(char *buffer, size_t size) { mData->dump(buffer, size); } |
| 85 | |
| 86 | const int mType; // event type e.g. CFG_EVENT_IO |
| 87 | Mutex mLock; // mutex associated with mCond |
| 88 | Condition mCond; // condition for status return |
| 89 | status_t mStatus; // status communicated to sender |
| 90 | bool mWaitStatus; // true if sender is waiting for status |
| 91 | sp<ConfigEventData> mData; // event specific parameter data |
| 92 | |
| 93 | protected: |
| 94 | ConfigEvent(int type) : mType(type), mStatus(NO_ERROR), mWaitStatus(false), mData(NULL) {} |
| 95 | }; |
| 96 | |
| 97 | class IoConfigEventData : public ConfigEventData { |
| 98 | public: |
| 99 | IoConfigEventData(int event, int param) : |
| 100 | mEvent(event), mParam(param) {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 101 | |
| 102 | virtual void dump(char *buffer, size_t size) { |
| 103 | snprintf(buffer, size, "IO event: event %d, param %d\n", mEvent, mParam); |
| 104 | } |
| 105 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 106 | const int mEvent; |
| 107 | const int mParam; |
| 108 | }; |
| 109 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 110 | class IoConfigEvent : public ConfigEvent { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 111 | public: |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 112 | IoConfigEvent(int event, int param) : |
| 113 | ConfigEvent(CFG_EVENT_IO) { |
| 114 | mData = new IoConfigEventData(event, param); |
| 115 | } |
| 116 | virtual ~IoConfigEvent() {} |
| 117 | }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 118 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 119 | class PrioConfigEventData : public ConfigEventData { |
| 120 | public: |
| 121 | PrioConfigEventData(pid_t pid, pid_t tid, int32_t prio) : |
| 122 | mPid(pid), mTid(tid), mPrio(prio) {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 123 | |
| 124 | virtual void dump(char *buffer, size_t size) { |
| 125 | snprintf(buffer, size, "Prio event: pid %d, tid %d, prio %d\n", mPid, mTid, mPrio); |
| 126 | } |
| 127 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 128 | const pid_t mPid; |
| 129 | const pid_t mTid; |
| 130 | const int32_t mPrio; |
| 131 | }; |
| 132 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 133 | class PrioConfigEvent : public ConfigEvent { |
| 134 | public: |
| 135 | PrioConfigEvent(pid_t pid, pid_t tid, int32_t prio) : |
| 136 | ConfigEvent(CFG_EVENT_PRIO) { |
| 137 | mData = new PrioConfigEventData(pid, tid, prio); |
| 138 | } |
| 139 | virtual ~PrioConfigEvent() {} |
| 140 | }; |
| 141 | |
| 142 | class SetParameterConfigEventData : public ConfigEventData { |
| 143 | public: |
| 144 | SetParameterConfigEventData(String8 keyValuePairs) : |
| 145 | mKeyValuePairs(keyValuePairs) {} |
| 146 | |
| 147 | virtual void dump(char *buffer, size_t size) { |
| 148 | snprintf(buffer, size, "KeyValue: %s\n", mKeyValuePairs.string()); |
| 149 | } |
| 150 | |
| 151 | const String8 mKeyValuePairs; |
| 152 | }; |
| 153 | |
| 154 | class SetParameterConfigEvent : public ConfigEvent { |
| 155 | public: |
| 156 | SetParameterConfigEvent(String8 keyValuePairs) : |
| 157 | ConfigEvent(CFG_EVENT_SET_PARAMETER) { |
| 158 | mData = new SetParameterConfigEventData(keyValuePairs); |
| 159 | mWaitStatus = true; |
| 160 | } |
| 161 | virtual ~SetParameterConfigEvent() {} |
| 162 | }; |
| 163 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 164 | |
| 165 | class PMDeathRecipient : public IBinder::DeathRecipient { |
| 166 | public: |
| 167 | PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {} |
| 168 | virtual ~PMDeathRecipient() {} |
| 169 | |
| 170 | // IBinder::DeathRecipient |
| 171 | virtual void binderDied(const wp<IBinder>& who); |
| 172 | |
| 173 | private: |
| 174 | PMDeathRecipient(const PMDeathRecipient&); |
| 175 | PMDeathRecipient& operator = (const PMDeathRecipient&); |
| 176 | |
| 177 | wp<ThreadBase> mThread; |
| 178 | }; |
| 179 | |
| 180 | virtual status_t initCheck() const = 0; |
| 181 | |
| 182 | // static externally-visible |
| 183 | type_t type() const { return mType; } |
| 184 | audio_io_handle_t id() const { return mId;} |
| 185 | |
| 186 | // dynamic externally-visible |
| 187 | uint32_t sampleRate() const { return mSampleRate; } |
| 188 | uint32_t channelCount() const { return mChannelCount; } |
| 189 | audio_channel_mask_t channelMask() const { return mChannelMask; } |
| 190 | audio_format_t format() const { return mFormat; } |
| 191 | // Called by AudioFlinger::frameCount(audio_io_handle_t output) and effects, |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 192 | // and returns the [normal mix] buffer's frame count. |
| 193 | virtual size_t frameCount() const = 0; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 194 | size_t frameSize() const { return mFrameSize; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 195 | |
| 196 | // Should be "virtual status_t requestExitAndWait()" and override same |
| 197 | // method in Thread, but Thread::requestExitAndWait() is not yet virtual. |
| 198 | void exit(); |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 199 | virtual bool checkForNewParameter_l(const String8& keyValuePair, |
| 200 | status_t& status) = 0; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 201 | virtual status_t setParameters(const String8& keyValuePairs); |
| 202 | virtual String8 getParameters(const String8& keys) = 0; |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame^] | 203 | virtual void audioConfigChanged(int event, int param = 0) = 0; |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 204 | // sendConfigEvent_l() must be called with ThreadBase::mLock held |
| 205 | // Can temporarily release the lock if waiting for a reply from |
| 206 | // processConfigEvents_l(). |
| 207 | status_t sendConfigEvent_l(sp<ConfigEvent>& event); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 208 | void sendIoConfigEvent(int event, int param = 0); |
| 209 | void sendIoConfigEvent_l(int event, int param = 0); |
| 210 | void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio); |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 211 | status_t sendSetParameterConfigEvent_l(const String8& keyValuePair); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame^] | 212 | void processConfigEvents_l(); |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 213 | virtual void cacheParameters_l() = 0; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 214 | |
| 215 | // see note at declaration of mStandby, mOutDevice and mInDevice |
| 216 | bool standby() const { return mStandby; } |
| 217 | audio_devices_t outDevice() const { return mOutDevice; } |
| 218 | audio_devices_t inDevice() const { return mInDevice; } |
| 219 | |
| 220 | virtual audio_stream_t* stream() const = 0; |
| 221 | |
| 222 | sp<EffectHandle> createEffect_l( |
| 223 | const sp<AudioFlinger::Client>& client, |
| 224 | const sp<IEffectClient>& effectClient, |
| 225 | int32_t priority, |
| 226 | int sessionId, |
| 227 | effect_descriptor_t *desc, |
| 228 | int *enabled, |
Glenn Kasten | 9156ef3 | 2013-08-06 15:39:08 -0700 | [diff] [blame] | 229 | status_t *status /*non-NULL*/); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 230 | void disconnectEffect(const sp< EffectModule>& effect, |
| 231 | EffectHandle *handle, |
| 232 | bool unpinIfLast); |
| 233 | |
| 234 | // return values for hasAudioSession (bit field) |
| 235 | enum effect_state { |
| 236 | EFFECT_SESSION = 0x1, // the audio session corresponds to at least one |
| 237 | // effect |
| 238 | TRACK_SESSION = 0x2 // the audio session corresponds to at least one |
| 239 | // track |
| 240 | }; |
| 241 | |
| 242 | // get effect chain corresponding to session Id. |
| 243 | sp<EffectChain> getEffectChain(int sessionId); |
| 244 | // same as getEffectChain() but must be called with ThreadBase mutex locked |
| 245 | sp<EffectChain> getEffectChain_l(int sessionId) const; |
| 246 | // add an effect chain to the chain list (mEffectChains) |
| 247 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain) = 0; |
| 248 | // remove an effect chain from the chain list (mEffectChains) |
| 249 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain) = 0; |
| 250 | // lock all effect chains Mutexes. Must be called before releasing the |
| 251 | // ThreadBase mutex before processing the mixer and effects. This guarantees the |
| 252 | // integrity of the chains during the process. |
| 253 | // Also sets the parameter 'effectChains' to current value of mEffectChains. |
| 254 | void lockEffectChains_l(Vector< sp<EffectChain> >& effectChains); |
| 255 | // unlock effect chains after process |
| 256 | void unlockEffectChains(const Vector< sp<EffectChain> >& effectChains); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 257 | // get a copy of mEffectChains vector |
| 258 | Vector< sp<EffectChain> > getEffectChains_l() const { return mEffectChains; }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 259 | // set audio mode to all effect chains |
| 260 | void setMode(audio_mode_t mode); |
| 261 | // get effect module with corresponding ID on specified audio session |
| 262 | sp<AudioFlinger::EffectModule> getEffect(int sessionId, int effectId); |
| 263 | sp<AudioFlinger::EffectModule> getEffect_l(int sessionId, int effectId); |
| 264 | // add and effect module. Also creates the effect chain is none exists for |
| 265 | // the effects audio session |
| 266 | status_t addEffect_l(const sp< EffectModule>& effect); |
| 267 | // remove and effect module. Also removes the effect chain is this was the last |
| 268 | // effect |
| 269 | void removeEffect_l(const sp< EffectModule>& effect); |
| 270 | // detach all tracks connected to an auxiliary effect |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 271 | virtual void detachAuxEffect_l(int effectId __unused) {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 272 | // returns either EFFECT_SESSION if effects on this audio session exist in one |
| 273 | // chain, or TRACK_SESSION if tracks on this audio session exist, or both |
| 274 | virtual uint32_t hasAudioSession(int sessionId) const = 0; |
| 275 | // the value returned by default implementation is not important as the |
| 276 | // strategy is only meaningful for PlaybackThread which implements this method |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 277 | virtual uint32_t getStrategyForSession_l(int sessionId __unused) { return 0; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 278 | |
| 279 | // suspend or restore effect according to the type of effect passed. a NULL |
| 280 | // type pointer means suspend all effects in the session |
| 281 | void setEffectSuspended(const effect_uuid_t *type, |
| 282 | bool suspend, |
| 283 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
| 284 | // check if some effects must be suspended/restored when an effect is enabled |
| 285 | // or disabled |
| 286 | void checkSuspendOnEffectEnabled(const sp<EffectModule>& effect, |
| 287 | bool enabled, |
| 288 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
| 289 | void checkSuspendOnEffectEnabled_l(const sp<EffectModule>& effect, |
| 290 | bool enabled, |
| 291 | int sessionId = AUDIO_SESSION_OUTPUT_MIX); |
| 292 | |
| 293 | virtual status_t setSyncEvent(const sp<SyncEvent>& event) = 0; |
| 294 | virtual bool isValidSyncEvent(const sp<SyncEvent>& event) const = 0; |
| 295 | |
Glenn Kasten | b880f5e | 2014-05-07 08:43:45 -0700 | [diff] [blame] | 296 | // Return a reference to a per-thread heap which can be used to allocate IMemory |
| 297 | // objects that will be read-only to client processes, read/write to mediaserver, |
| 298 | // and shared by all client processes of the thread. |
| 299 | // The heap is per-thread rather than common across all threads, because |
| 300 | // clients can't be trusted not to modify the offset of the IMemory they receive. |
| 301 | // If a thread does not have such a heap, this method returns 0. |
| 302 | virtual sp<MemoryDealer> readOnlyHeap() const { return 0; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 303 | |
| 304 | mutable Mutex mLock; |
| 305 | |
| 306 | protected: |
| 307 | |
| 308 | // entry describing an effect being suspended in mSuspendedSessions keyed vector |
| 309 | class SuspendedSessionDesc : public RefBase { |
| 310 | public: |
| 311 | SuspendedSessionDesc() : mRefCount(0) {} |
| 312 | |
| 313 | int mRefCount; // number of active suspend requests |
| 314 | effect_uuid_t mType; // effect type UUID |
| 315 | }; |
| 316 | |
Marco Nelissen | e14a5d6 | 2013-10-03 08:51:24 -0700 | [diff] [blame] | 317 | void acquireWakeLock(int uid = -1); |
| 318 | void acquireWakeLock_l(int uid = -1); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 319 | void releaseWakeLock(); |
| 320 | void releaseWakeLock_l(); |
Marco Nelissen | 462fd2f | 2013-01-14 14:12:05 -0800 | [diff] [blame] | 321 | void updateWakeLockUids(const SortedVector<int> &uids); |
| 322 | void updateWakeLockUids_l(const SortedVector<int> &uids); |
| 323 | void getPowerManager_l(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 324 | void setEffectSuspended_l(const effect_uuid_t *type, |
| 325 | bool suspend, |
| 326 | int sessionId); |
| 327 | // updated mSuspendedSessions when an effect suspended or restored |
| 328 | void updateSuspendedSessions_l(const effect_uuid_t *type, |
| 329 | bool suspend, |
| 330 | int sessionId); |
| 331 | // check if some effects must be suspended when an effect chain is added |
| 332 | void checkSuspendOnAddEffectChain_l(const sp<EffectChain>& chain); |
| 333 | |
Narayan Kamath | 014e7fa | 2013-10-14 15:03:38 +0100 | [diff] [blame] | 334 | String16 getWakeLockTag(); |
| 335 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 336 | virtual void preExit() { } |
| 337 | |
| 338 | friend class AudioFlinger; // for mEffectChains |
| 339 | |
| 340 | const type_t mType; |
| 341 | |
| 342 | // Used by parameters, config events, addTrack_l, exit |
| 343 | Condition mWaitWorkCV; |
| 344 | |
| 345 | const sp<AudioFlinger> mAudioFlinger; |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 346 | |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 347 | // updated by PlaybackThread::readOutputParameters_l() or |
| 348 | // RecordThread::readInputParameters_l() |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 349 | uint32_t mSampleRate; |
| 350 | size_t mFrameCount; // output HAL, direct output, record |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 351 | audio_channel_mask_t mChannelMask; |
Glenn Kasten | f6ed423 | 2013-07-16 11:16:27 -0700 | [diff] [blame] | 352 | uint32_t mChannelCount; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 353 | size_t mFrameSize; |
| 354 | audio_format_t mFormat; |
Glenn Kasten | 70949c4 | 2013-08-06 07:40:12 -0700 | [diff] [blame] | 355 | size_t mBufferSize; // HAL buffer size for read() or write() |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 356 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 357 | Vector< sp<ConfigEvent> > mConfigEvents; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 358 | |
| 359 | // These fields are written and read by thread itself without lock or barrier, |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 360 | // and read by other threads without lock or barrier via standby(), outDevice() |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 361 | // and inDevice(). |
| 362 | // Because of the absence of a lock or barrier, any other thread that reads |
| 363 | // these fields must use the information in isolation, or be prepared to deal |
| 364 | // with possibility that it might be inconsistent with other information. |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 365 | bool mStandby; // Whether thread is currently in standby. |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 366 | audio_devices_t mOutDevice; // output device |
| 367 | audio_devices_t mInDevice; // input device |
| 368 | audio_source_t mAudioSource; // (see audio.h, audio_source_t) |
| 369 | |
| 370 | const audio_io_handle_t mId; |
| 371 | Vector< sp<EffectChain> > mEffectChains; |
| 372 | |
| 373 | static const int kNameLength = 16; // prctl(PR_SET_NAME) limit |
| 374 | char mName[kNameLength]; |
| 375 | sp<IPowerManager> mPowerManager; |
| 376 | sp<IBinder> mWakeLockToken; |
| 377 | const sp<PMDeathRecipient> mDeathRecipient; |
| 378 | // list of suspended effects per session and per type. The first vector is |
| 379 | // keyed by session ID, the second by type UUID timeLow field |
| 380 | KeyedVector< int, KeyedVector< int, sp<SuspendedSessionDesc> > > |
| 381 | mSuspendedSessions; |
Glenn Kasten | ab7d72f | 2013-02-27 09:05:28 -0800 | [diff] [blame] | 382 | static const size_t kLogSize = 4 * 1024; |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 383 | sp<NBLog::Writer> mNBLogWriter; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 384 | }; |
| 385 | |
| 386 | // --- PlaybackThread --- |
| 387 | class PlaybackThread : public ThreadBase { |
| 388 | public: |
| 389 | |
| 390 | #include "PlaybackTracks.h" |
| 391 | |
| 392 | enum mixer_state { |
| 393 | MIXER_IDLE, // no active tracks |
| 394 | MIXER_TRACKS_ENABLED, // at least one active track, but no track has any data ready |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 395 | MIXER_TRACKS_READY, // at least one active track, and at least one track has data |
| 396 | MIXER_DRAIN_TRACK, // drain currently playing track |
| 397 | MIXER_DRAIN_ALL, // fully drain the hardware |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 398 | // standby mode does not have an enum value |
| 399 | // suspend by audio policy manager is orthogonal to mixer state |
| 400 | }; |
| 401 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 402 | // retry count before removing active track in case of underrun on offloaded thread: |
| 403 | // we need to make sure that AudioTrack client has enough time to send large buffers |
| 404 | //FIXME may be more appropriate if expressed in time units. Need to revise how underrun is handled |
| 405 | // for offloaded tracks |
| 406 | static const int8_t kMaxTrackRetriesOffload = 20; |
| 407 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 408 | PlaybackThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, |
| 409 | audio_io_handle_t id, audio_devices_t device, type_t type); |
| 410 | virtual ~PlaybackThread(); |
| 411 | |
| 412 | void dump(int fd, const Vector<String16>& args); |
| 413 | |
| 414 | // Thread virtuals |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 415 | virtual bool threadLoop(); |
| 416 | |
| 417 | // RefBase |
| 418 | virtual void onFirstRef(); |
| 419 | |
| 420 | protected: |
| 421 | // Code snippets that were lifted up out of threadLoop() |
| 422 | virtual void threadLoop_mix() = 0; |
| 423 | virtual void threadLoop_sleepTime() = 0; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 424 | virtual ssize_t threadLoop_write(); |
| 425 | virtual void threadLoop_drain(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 426 | virtual void threadLoop_standby(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 427 | virtual void threadLoop_exit(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 428 | virtual void threadLoop_removeTracks(const Vector< sp<Track> >& tracksToRemove); |
| 429 | |
| 430 | // prepareTracks_l reads and writes mActiveTracks, and returns |
| 431 | // the pending set of tracks to remove via Vector 'tracksToRemove'. The caller |
| 432 | // is responsible for clearing or destroying this Vector later on, when it |
| 433 | // is safe to do so. That will drop the final ref count and destroy the tracks. |
| 434 | virtual mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove) = 0; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 435 | void removeTracks_l(const Vector< sp<Track> >& tracksToRemove); |
| 436 | |
| 437 | void writeCallback(); |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 438 | void resetWriteBlocked(uint32_t sequence); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 439 | void drainCallback(); |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 440 | void resetDraining(uint32_t sequence); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 441 | |
| 442 | static int asyncCallback(stream_callback_event_t event, void *param, void *cookie); |
| 443 | |
| 444 | virtual bool waitingAsyncCallback(); |
| 445 | virtual bool waitingAsyncCallback_l(); |
| 446 | virtual bool shouldStandby_l(); |
Haynes Mathew George | 4c6a433 | 2014-01-15 12:31:39 -0800 | [diff] [blame] | 447 | virtual void onAddNewTrack_l(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 448 | |
| 449 | // ThreadBase virtuals |
| 450 | virtual void preExit(); |
| 451 | |
| 452 | public: |
| 453 | |
| 454 | virtual status_t initCheck() const { return (mOutput == NULL) ? NO_INIT : NO_ERROR; } |
| 455 | |
| 456 | // return estimated latency in milliseconds, as reported by HAL |
| 457 | uint32_t latency() const; |
| 458 | // same, but lock must already be held |
| 459 | uint32_t latency_l() const; |
| 460 | |
| 461 | void setMasterVolume(float value); |
| 462 | void setMasterMute(bool muted); |
| 463 | |
| 464 | void setStreamVolume(audio_stream_type_t stream, float value); |
| 465 | void setStreamMute(audio_stream_type_t stream, bool muted); |
| 466 | |
| 467 | float streamVolume(audio_stream_type_t stream) const; |
| 468 | |
| 469 | sp<Track> createTrack_l( |
| 470 | const sp<AudioFlinger::Client>& client, |
| 471 | audio_stream_type_t streamType, |
| 472 | uint32_t sampleRate, |
| 473 | audio_format_t format, |
| 474 | audio_channel_mask_t channelMask, |
Glenn Kasten | 74935e4 | 2013-12-19 08:56:45 -0800 | [diff] [blame] | 475 | size_t *pFrameCount, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 476 | const sp<IMemory>& sharedBuffer, |
| 477 | int sessionId, |
| 478 | IAudioFlinger::track_flags_t *flags, |
| 479 | pid_t tid, |
Marco Nelissen | 462fd2f | 2013-01-14 14:12:05 -0800 | [diff] [blame] | 480 | int uid, |
Glenn Kasten | 9156ef3 | 2013-08-06 15:39:08 -0700 | [diff] [blame] | 481 | status_t *status /*non-NULL*/); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 482 | |
| 483 | AudioStreamOut* getOutput() const; |
| 484 | AudioStreamOut* clearOutput(); |
| 485 | virtual audio_stream_t* stream() const; |
| 486 | |
| 487 | // a very large number of suspend() will eventually wraparound, but unlikely |
| 488 | void suspend() { (void) android_atomic_inc(&mSuspended); } |
| 489 | void restore() |
| 490 | { |
| 491 | // if restore() is done without suspend(), get back into |
| 492 | // range so that the next suspend() will operate correctly |
| 493 | if (android_atomic_dec(&mSuspended) <= 0) { |
| 494 | android_atomic_release_store(0, &mSuspended); |
| 495 | } |
| 496 | } |
| 497 | bool isSuspended() const |
| 498 | { return android_atomic_acquire_load(&mSuspended) > 0; } |
| 499 | |
| 500 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame^] | 501 | virtual void audioConfigChanged(int event, int param = 0); |
Kévin PETIT | 377b2ec | 2014-02-03 12:35:36 +0000 | [diff] [blame] | 502 | status_t getRenderPosition(uint32_t *halFrames, uint32_t *dspFrames); |
Andy Hung | 010a1a1 | 2014-03-13 13:57:33 -0700 | [diff] [blame] | 503 | // FIXME rename mixBuffer() to sinkBuffer() and remove int16_t* dependency. |
| 504 | // Consider also removing and passing an explicit mMainBuffer initialization |
| 505 | // parameter to AF::PlaybackThread::Track::Track(). |
| 506 | int16_t *mixBuffer() const { |
| 507 | return reinterpret_cast<int16_t *>(mSinkBuffer); }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 508 | |
| 509 | virtual void detachAuxEffect_l(int effectId); |
| 510 | status_t attachAuxEffect(const sp<AudioFlinger::PlaybackThread::Track> track, |
| 511 | int EffectId); |
| 512 | status_t attachAuxEffect_l(const sp<AudioFlinger::PlaybackThread::Track> track, |
| 513 | int EffectId); |
| 514 | |
| 515 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain); |
| 516 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); |
| 517 | virtual uint32_t hasAudioSession(int sessionId) const; |
| 518 | virtual uint32_t getStrategyForSession_l(int sessionId); |
| 519 | |
| 520 | |
| 521 | virtual status_t setSyncEvent(const sp<SyncEvent>& event); |
| 522 | virtual bool isValidSyncEvent(const sp<SyncEvent>& event) const; |
Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 523 | |
| 524 | // called with AudioFlinger lock held |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 525 | void invalidateTracks(audio_stream_type_t streamType); |
| 526 | |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 527 | virtual size_t frameCount() const { return mNormalFrameCount; } |
| 528 | |
| 529 | // Return's the HAL's frame count i.e. fast mixer buffer size. |
| 530 | size_t frameCountHAL() const { return mFrameCount; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 531 | |
Eric Laurent | accc147 | 2013-09-20 09:36:34 -0700 | [diff] [blame] | 532 | status_t getTimestamp_l(AudioTimestamp& timestamp); |
| 533 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 534 | protected: |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 535 | // updated by readOutputParameters_l() |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 536 | size_t mNormalFrameCount; // normal mixer and effects |
| 537 | |
Andy Hung | 010a1a1 | 2014-03-13 13:57:33 -0700 | [diff] [blame] | 538 | void* mSinkBuffer; // frame size aligned sink buffer |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 539 | |
Andy Hung | 98ef978 | 2014-03-04 14:46:50 -0800 | [diff] [blame] | 540 | // TODO: |
| 541 | // Rearrange the buffer info into a struct/class with |
| 542 | // clear, copy, construction, destruction methods. |
| 543 | // |
| 544 | // mSinkBuffer also has associated with it: |
| 545 | // |
| 546 | // mSinkBufferSize: Sink Buffer Size |
| 547 | // mFormat: Sink Buffer Format |
| 548 | |
Andy Hung | 69aed5f | 2014-02-25 17:24:40 -0800 | [diff] [blame] | 549 | // Mixer Buffer (mMixerBuffer*) |
| 550 | // |
| 551 | // In the case of floating point or multichannel data, which is not in the |
| 552 | // sink format, it is required to accumulate in a higher precision or greater channel count |
| 553 | // buffer before downmixing or data conversion to the sink buffer. |
| 554 | |
| 555 | // Set to "true" to enable the Mixer Buffer otherwise mixer output goes to sink buffer. |
| 556 | bool mMixerBufferEnabled; |
| 557 | |
| 558 | // Storage, 32 byte aligned (may make this alignment a requirement later). |
| 559 | // Due to constraints on mNormalFrameCount, the buffer size is a multiple of 16 frames. |
| 560 | void* mMixerBuffer; |
| 561 | |
| 562 | // Size of mMixerBuffer in bytes: mNormalFrameCount * #channels * sampsize. |
| 563 | size_t mMixerBufferSize; |
| 564 | |
| 565 | // The audio format of mMixerBuffer. Set to AUDIO_FORMAT_PCM_(FLOAT|16_BIT) only. |
| 566 | audio_format_t mMixerBufferFormat; |
| 567 | |
| 568 | // An internal flag set to true by MixerThread::prepareTracks_l() |
| 569 | // when mMixerBuffer contains valid data after mixing. |
| 570 | bool mMixerBufferValid; |
| 571 | |
Andy Hung | 98ef978 | 2014-03-04 14:46:50 -0800 | [diff] [blame] | 572 | // Effects Buffer (mEffectsBuffer*) |
| 573 | // |
| 574 | // In the case of effects data, which is not in the sink format, |
| 575 | // it is required to accumulate in a different buffer before data conversion |
| 576 | // to the sink buffer. |
| 577 | |
| 578 | // Set to "true" to enable the Effects Buffer otherwise effects output goes to sink buffer. |
| 579 | bool mEffectBufferEnabled; |
| 580 | |
| 581 | // Storage, 32 byte aligned (may make this alignment a requirement later). |
| 582 | // Due to constraints on mNormalFrameCount, the buffer size is a multiple of 16 frames. |
| 583 | void* mEffectBuffer; |
| 584 | |
| 585 | // Size of mEffectsBuffer in bytes: mNormalFrameCount * #channels * sampsize. |
| 586 | size_t mEffectBufferSize; |
| 587 | |
| 588 | // The audio format of mEffectsBuffer. Set to AUDIO_FORMAT_PCM_16_BIT only. |
| 589 | audio_format_t mEffectBufferFormat; |
| 590 | |
| 591 | // An internal flag set to true by MixerThread::prepareTracks_l() |
| 592 | // when mEffectsBuffer contains valid data after mixing. |
| 593 | // |
| 594 | // When this is set, all mixer data is routed into the effects buffer |
| 595 | // for any processing (including output processing). |
| 596 | bool mEffectBufferValid; |
| 597 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 598 | // suspend count, > 0 means suspended. While suspended, the thread continues to pull from |
| 599 | // tracks and mix, but doesn't write to HAL. A2DP and SCO HAL implementations can't handle |
| 600 | // concurrent use of both of them, so Audio Policy Service suspends one of the threads to |
| 601 | // workaround that restriction. |
| 602 | // 'volatile' means accessed via atomic operations and no lock. |
| 603 | volatile int32_t mSuspended; |
| 604 | |
| 605 | // FIXME overflows every 6+ hours at 44.1 kHz stereo 16-bit samples |
| 606 | // mFramesWritten would be better, or 64-bit even better |
| 607 | size_t mBytesWritten; |
| 608 | private: |
| 609 | // mMasterMute is in both PlaybackThread and in AudioFlinger. When a |
| 610 | // PlaybackThread needs to find out if master-muted, it checks it's local |
| 611 | // copy rather than the one in AudioFlinger. This optimization saves a lock. |
| 612 | bool mMasterMute; |
| 613 | void setMasterMute_l(bool muted) { mMasterMute = muted; } |
| 614 | protected: |
| 615 | SortedVector< wp<Track> > mActiveTracks; // FIXME check if this could be sp<> |
Marco Nelissen | 462fd2f | 2013-01-14 14:12:05 -0800 | [diff] [blame] | 616 | SortedVector<int> mWakeLockUids; |
| 617 | int mActiveTracksGeneration; |
Eric Laurent | fd47797 | 2013-10-25 18:10:40 -0700 | [diff] [blame] | 618 | wp<Track> mLatestActiveTrack; // latest track added to mActiveTracks |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 619 | |
| 620 | // Allocate a track name for a given channel mask. |
| 621 | // Returns name >= 0 if successful, -1 on failure. |
| 622 | virtual int getTrackName_l(audio_channel_mask_t channelMask, int sessionId) = 0; |
| 623 | virtual void deleteTrackName_l(int name) = 0; |
| 624 | |
| 625 | // Time to sleep between cycles when: |
| 626 | virtual uint32_t activeSleepTimeUs() const; // mixer state MIXER_TRACKS_ENABLED |
| 627 | virtual uint32_t idleSleepTimeUs() const = 0; // mixer state MIXER_IDLE |
| 628 | virtual uint32_t suspendSleepTimeUs() const = 0; // audio policy manager suspended us |
| 629 | // No sleep when mixer state == MIXER_TRACKS_READY; relies on audio HAL stream->write() |
| 630 | // No sleep in standby mode; waits on a condition |
| 631 | |
| 632 | // Code snippets that are temporarily lifted up out of threadLoop() until the merge |
| 633 | void checkSilentMode_l(); |
| 634 | |
| 635 | // Non-trivial for DUPLICATING only |
| 636 | virtual void saveOutputTracks() { } |
| 637 | virtual void clearOutputTracks() { } |
| 638 | |
| 639 | // Cache various calculated values, at threadLoop() entry and after a parameter change |
| 640 | virtual void cacheParameters_l(); |
| 641 | |
| 642 | virtual uint32_t correctLatency_l(uint32_t latency) const; |
| 643 | |
| 644 | private: |
| 645 | |
| 646 | friend class AudioFlinger; // for numerous |
| 647 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 648 | PlaybackThread& operator = (const PlaybackThread&); |
| 649 | |
| 650 | status_t addTrack_l(const sp<Track>& track); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 651 | bool destroyTrack_l(const sp<Track>& track); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 652 | void removeTrack_l(const sp<Track>& track); |
Eric Laurent | ede6c3b | 2013-09-19 14:37:46 -0700 | [diff] [blame] | 653 | void broadcast_l(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 654 | |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 655 | void readOutputParameters_l(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 656 | |
| 657 | virtual void dumpInternals(int fd, const Vector<String16>& args); |
| 658 | void dumpTracks(int fd, const Vector<String16>& args); |
| 659 | |
| 660 | SortedVector< sp<Track> > mTracks; |
| 661 | // mStreamTypes[] uses 1 additional stream type internally for the OutputTrack used by |
| 662 | // DuplicatingThread |
| 663 | stream_type_t mStreamTypes[AUDIO_STREAM_CNT + 1]; |
| 664 | AudioStreamOut *mOutput; |
| 665 | |
| 666 | float mMasterVolume; |
| 667 | nsecs_t mLastWriteTime; |
| 668 | int mNumWrites; |
| 669 | int mNumDelayedWrites; |
| 670 | bool mInWrite; |
| 671 | |
| 672 | // FIXME rename these former local variables of threadLoop to standard "m" names |
| 673 | nsecs_t standbyTime; |
Andy Hung | 25c2dac | 2014-02-27 14:56:00 -0800 | [diff] [blame] | 674 | size_t mSinkBufferSize; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 675 | |
| 676 | // cached copies of activeSleepTimeUs() and idleSleepTimeUs() made by cacheParameters_l() |
| 677 | uint32_t activeSleepTime; |
| 678 | uint32_t idleSleepTime; |
| 679 | |
| 680 | uint32_t sleepTime; |
| 681 | |
| 682 | // mixer status returned by prepareTracks_l() |
| 683 | mixer_state mMixerStatus; // current cycle |
| 684 | // previous cycle when in prepareTracks_l() |
| 685 | mixer_state mMixerStatusIgnoringFastTracks; |
| 686 | // FIXME or a separate ready state per track |
| 687 | |
| 688 | // FIXME move these declarations into the specific sub-class that needs them |
| 689 | // MIXER only |
| 690 | uint32_t sleepTimeShift; |
| 691 | |
| 692 | // same as AudioFlinger::mStandbyTimeInNsecs except for DIRECT which uses a shorter value |
| 693 | nsecs_t standbyDelay; |
| 694 | |
| 695 | // MIXER only |
| 696 | nsecs_t maxPeriod; |
| 697 | |
| 698 | // DUPLICATING only |
| 699 | uint32_t writeFrames; |
| 700 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 701 | size_t mBytesRemaining; |
| 702 | size_t mCurrentWriteLength; |
| 703 | bool mUseAsyncWrite; |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 704 | // mWriteAckSequence contains current write sequence on bits 31-1. The write sequence is |
| 705 | // incremented each time a write(), a flush() or a standby() occurs. |
| 706 | // Bit 0 is set when a write blocks and indicates a callback is expected. |
| 707 | // Bit 0 is reset by the async callback thread calling resetWriteBlocked(). Out of sequence |
| 708 | // callbacks are ignored. |
| 709 | uint32_t mWriteAckSequence; |
| 710 | // mDrainSequence contains current drain sequence on bits 31-1. The drain sequence is |
| 711 | // incremented each time a drain is requested or a flush() or standby() occurs. |
| 712 | // Bit 0 is set when the drain() command is called at the HAL and indicates a callback is |
| 713 | // expected. |
| 714 | // Bit 0 is reset by the async callback thread calling resetDraining(). Out of sequence |
| 715 | // callbacks are ignored. |
| 716 | uint32_t mDrainSequence; |
Eric Laurent | ede6c3b | 2013-09-19 14:37:46 -0700 | [diff] [blame] | 717 | // A condition that must be evaluated by prepareTrack_l() has changed and we must not wait |
| 718 | // for async write callback in the thread loop before evaluating it |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 719 | bool mSignalPending; |
| 720 | sp<AsyncCallbackThread> mCallbackThread; |
| 721 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 722 | private: |
| 723 | // The HAL output sink is treated as non-blocking, but current implementation is blocking |
| 724 | sp<NBAIO_Sink> mOutputSink; |
| 725 | // If a fast mixer is present, the blocking pipe sink, otherwise clear |
| 726 | sp<NBAIO_Sink> mPipeSink; |
| 727 | // The current sink for the normal mixer to write it's (sub)mix, mOutputSink or mPipeSink |
| 728 | sp<NBAIO_Sink> mNormalSink; |
Glenn Kasten | 46909e7 | 2013-02-26 09:20:22 -0800 | [diff] [blame] | 729 | #ifdef TEE_SINK |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 730 | // For dumpsys |
| 731 | sp<NBAIO_Sink> mTeeSink; |
| 732 | sp<NBAIO_Source> mTeeSource; |
Glenn Kasten | 46909e7 | 2013-02-26 09:20:22 -0800 | [diff] [blame] | 733 | #endif |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 734 | uint32_t mScreenState; // cached copy of gScreenState |
Glenn Kasten | ab7d72f | 2013-02-27 09:05:28 -0800 | [diff] [blame] | 735 | static const size_t kFastMixerLogSize = 4 * 1024; |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 736 | sp<NBLog::Writer> mFastMixerNBLogWriter; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 737 | public: |
| 738 | virtual bool hasFastMixer() const = 0; |
Glenn Kasten | 0f11b51 | 2014-01-31 16:18:54 -0800 | [diff] [blame] | 739 | virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex __unused) const |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 740 | { FastTrackUnderruns dummy; return dummy; } |
| 741 | |
| 742 | protected: |
| 743 | // accessed by both binder threads and within threadLoop(), lock on mutex needed |
| 744 | unsigned mFastTrackAvailMask; // bit i set if fast track [i] is available |
Glenn Kasten | bd096fd | 2013-08-23 13:53:56 -0700 | [diff] [blame] | 745 | |
| 746 | private: |
| 747 | // timestamp latch: |
| 748 | // D input is written by threadLoop_write while mutex is unlocked, and read while locked |
| 749 | // Q output is written while locked, and read while locked |
| 750 | struct { |
| 751 | AudioTimestamp mTimestamp; |
| 752 | uint32_t mUnpresentedFrames; |
| 753 | } mLatchD, mLatchQ; |
| 754 | bool mLatchDValid; // true means mLatchD is valid, and clock it into latch at next opportunity |
| 755 | bool mLatchQValid; // true means mLatchQ is valid |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 756 | }; |
| 757 | |
| 758 | class MixerThread : public PlaybackThread { |
| 759 | public: |
| 760 | MixerThread(const sp<AudioFlinger>& audioFlinger, |
| 761 | AudioStreamOut* output, |
| 762 | audio_io_handle_t id, |
| 763 | audio_devices_t device, |
| 764 | type_t type = MIXER); |
| 765 | virtual ~MixerThread(); |
| 766 | |
| 767 | // Thread virtuals |
| 768 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 769 | virtual bool checkForNewParameter_l(const String8& keyValuePair, |
| 770 | status_t& status); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 771 | virtual void dumpInternals(int fd, const Vector<String16>& args); |
| 772 | |
| 773 | protected: |
| 774 | virtual mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove); |
| 775 | virtual int getTrackName_l(audio_channel_mask_t channelMask, int sessionId); |
| 776 | virtual void deleteTrackName_l(int name); |
| 777 | virtual uint32_t idleSleepTimeUs() const; |
| 778 | virtual uint32_t suspendSleepTimeUs() const; |
| 779 | virtual void cacheParameters_l(); |
| 780 | |
| 781 | // threadLoop snippets |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 782 | virtual ssize_t threadLoop_write(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 783 | virtual void threadLoop_standby(); |
| 784 | virtual void threadLoop_mix(); |
| 785 | virtual void threadLoop_sleepTime(); |
| 786 | virtual void threadLoop_removeTracks(const Vector< sp<Track> >& tracksToRemove); |
| 787 | virtual uint32_t correctLatency_l(uint32_t latency) const; |
| 788 | |
| 789 | AudioMixer* mAudioMixer; // normal mixer |
| 790 | private: |
| 791 | // one-time initialization, no locks required |
| 792 | FastMixer* mFastMixer; // non-NULL if there is also a fast mixer |
| 793 | sp<AudioWatchdog> mAudioWatchdog; // non-0 if there is an audio watchdog thread |
| 794 | |
| 795 | // contents are not guaranteed to be consistent, no locks required |
| 796 | FastMixerDumpState mFastMixerDumpState; |
| 797 | #ifdef STATE_QUEUE_DUMP |
| 798 | StateQueueObserverDump mStateQueueObserverDump; |
| 799 | StateQueueMutatorDump mStateQueueMutatorDump; |
| 800 | #endif |
| 801 | AudioWatchdogDump mAudioWatchdogDump; |
| 802 | |
| 803 | // accessible only within the threadLoop(), no locks required |
| 804 | // mFastMixer->sq() // for mutating and pushing state |
| 805 | int32_t mFastMixerFutex; // for cold idle |
| 806 | |
| 807 | public: |
| 808 | virtual bool hasFastMixer() const { return mFastMixer != NULL; } |
| 809 | virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const { |
| 810 | ALOG_ASSERT(fastIndex < FastMixerState::kMaxFastTracks); |
| 811 | return mFastMixerDumpState.mTracks[fastIndex].mUnderruns; |
| 812 | } |
| 813 | }; |
| 814 | |
| 815 | class DirectOutputThread : public PlaybackThread { |
| 816 | public: |
| 817 | |
| 818 | DirectOutputThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, |
| 819 | audio_io_handle_t id, audio_devices_t device); |
| 820 | virtual ~DirectOutputThread(); |
| 821 | |
| 822 | // Thread virtuals |
| 823 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 824 | virtual bool checkForNewParameter_l(const String8& keyValuePair, |
| 825 | status_t& status); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 826 | |
| 827 | protected: |
| 828 | virtual int getTrackName_l(audio_channel_mask_t channelMask, int sessionId); |
| 829 | virtual void deleteTrackName_l(int name); |
| 830 | virtual uint32_t activeSleepTimeUs() const; |
| 831 | virtual uint32_t idleSleepTimeUs() const; |
| 832 | virtual uint32_t suspendSleepTimeUs() const; |
| 833 | virtual void cacheParameters_l(); |
| 834 | |
| 835 | // threadLoop snippets |
| 836 | virtual mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove); |
| 837 | virtual void threadLoop_mix(); |
| 838 | virtual void threadLoop_sleepTime(); |
| 839 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 840 | // volumes last sent to audio HAL with stream->set_volume() |
| 841 | float mLeftVolFloat; |
| 842 | float mRightVolFloat; |
| 843 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 844 | DirectOutputThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, |
| 845 | audio_io_handle_t id, uint32_t device, ThreadBase::type_t type); |
| 846 | void processVolume_l(Track *track, bool lastTrack); |
| 847 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 848 | // prepareTracks_l() tells threadLoop_mix() the name of the single active track |
| 849 | sp<Track> mActiveTrack; |
| 850 | public: |
| 851 | virtual bool hasFastMixer() const { return false; } |
| 852 | }; |
| 853 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 854 | class OffloadThread : public DirectOutputThread { |
| 855 | public: |
| 856 | |
| 857 | OffloadThread(const sp<AudioFlinger>& audioFlinger, AudioStreamOut* output, |
| 858 | audio_io_handle_t id, uint32_t device); |
Eric Laurent | 6a51d7e | 2013-10-17 18:59:26 -0700 | [diff] [blame] | 859 | virtual ~OffloadThread() {}; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 860 | |
| 861 | protected: |
| 862 | // threadLoop snippets |
| 863 | virtual mixer_state prepareTracks_l(Vector< sp<Track> > *tracksToRemove); |
| 864 | virtual void threadLoop_exit(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 865 | |
| 866 | virtual bool waitingAsyncCallback(); |
| 867 | virtual bool waitingAsyncCallback_l(); |
| 868 | virtual bool shouldStandby_l(); |
Haynes Mathew George | 4c6a433 | 2014-01-15 12:31:39 -0800 | [diff] [blame] | 869 | virtual void onAddNewTrack_l(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 870 | |
| 871 | private: |
| 872 | void flushHw_l(); |
| 873 | |
| 874 | private: |
| 875 | bool mHwPaused; |
| 876 | bool mFlushPending; |
| 877 | size_t mPausedWriteLength; // length in bytes of write interrupted by pause |
| 878 | size_t mPausedBytesRemaining; // bytes still waiting in mixbuffer after resume |
Eric Laurent | d7e5922 | 2013-11-15 12:02:28 -0800 | [diff] [blame] | 879 | wp<Track> mPreviousTrack; // used to detect track switch |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 880 | }; |
| 881 | |
| 882 | class AsyncCallbackThread : public Thread { |
| 883 | public: |
| 884 | |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 885 | AsyncCallbackThread(const wp<PlaybackThread>& playbackThread); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 886 | |
| 887 | virtual ~AsyncCallbackThread(); |
| 888 | |
| 889 | // Thread virtuals |
| 890 | virtual bool threadLoop(); |
| 891 | |
| 892 | // RefBase |
| 893 | virtual void onFirstRef(); |
| 894 | |
| 895 | void exit(); |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 896 | void setWriteBlocked(uint32_t sequence); |
| 897 | void resetWriteBlocked(); |
| 898 | void setDraining(uint32_t sequence); |
| 899 | void resetDraining(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 900 | |
| 901 | private: |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 902 | const wp<PlaybackThread> mPlaybackThread; |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 903 | // mWriteAckSequence corresponds to the last write sequence passed by the offload thread via |
| 904 | // setWriteBlocked(). The sequence is shifted one bit to the left and the lsb is used |
| 905 | // to indicate that the callback has been received via resetWriteBlocked() |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 906 | uint32_t mWriteAckSequence; |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 907 | // mDrainSequence corresponds to the last drain sequence passed by the offload thread via |
| 908 | // setDraining(). The sequence is shifted one bit to the left and the lsb is used |
| 909 | // to indicate that the callback has been received via resetDraining() |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 910 | uint32_t mDrainSequence; |
| 911 | Condition mWaitWorkCV; |
| 912 | Mutex mLock; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 913 | }; |
| 914 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 915 | class DuplicatingThread : public MixerThread { |
| 916 | public: |
| 917 | DuplicatingThread(const sp<AudioFlinger>& audioFlinger, MixerThread* mainThread, |
| 918 | audio_io_handle_t id); |
| 919 | virtual ~DuplicatingThread(); |
| 920 | |
| 921 | // Thread virtuals |
| 922 | void addOutputTrack(MixerThread* thread); |
| 923 | void removeOutputTrack(MixerThread* thread); |
| 924 | uint32_t waitTimeMs() const { return mWaitTimeMs; } |
| 925 | protected: |
| 926 | virtual uint32_t activeSleepTimeUs() const; |
| 927 | |
| 928 | private: |
| 929 | bool outputsReady(const SortedVector< sp<OutputTrack> > &outputTracks); |
| 930 | protected: |
| 931 | // threadLoop snippets |
| 932 | virtual void threadLoop_mix(); |
| 933 | virtual void threadLoop_sleepTime(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 934 | virtual ssize_t threadLoop_write(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 935 | virtual void threadLoop_standby(); |
| 936 | virtual void cacheParameters_l(); |
| 937 | |
| 938 | private: |
| 939 | // called from threadLoop, addOutputTrack, removeOutputTrack |
| 940 | virtual void updateWaitTime_l(); |
| 941 | protected: |
| 942 | virtual void saveOutputTracks(); |
| 943 | virtual void clearOutputTracks(); |
| 944 | private: |
| 945 | |
| 946 | uint32_t mWaitTimeMs; |
| 947 | SortedVector < sp<OutputTrack> > outputTracks; |
| 948 | SortedVector < sp<OutputTrack> > mOutputTracks; |
| 949 | public: |
| 950 | virtual bool hasFastMixer() const { return false; } |
| 951 | }; |
| 952 | |
| 953 | |
| 954 | // record thread |
Glenn Kasten | 6dd62fb | 2013-12-05 16:35:58 -0800 | [diff] [blame] | 955 | class RecordThread : public ThreadBase |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 956 | { |
| 957 | public: |
| 958 | |
Glenn Kasten | 6dd62fb | 2013-12-05 16:35:58 -0800 | [diff] [blame] | 959 | class RecordTrack; |
| 960 | class ResamplerBufferProvider : public AudioBufferProvider |
| 961 | // derives from AudioBufferProvider interface for use by resampler |
| 962 | { |
| 963 | public: |
| 964 | ResamplerBufferProvider(RecordTrack* recordTrack) : mRecordTrack(recordTrack) { } |
| 965 | virtual ~ResamplerBufferProvider() { } |
| 966 | // AudioBufferProvider interface |
| 967 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer, int64_t pts); |
| 968 | virtual void releaseBuffer(AudioBufferProvider::Buffer* buffer); |
| 969 | private: |
| 970 | RecordTrack * const mRecordTrack; |
| 971 | }; |
| 972 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 973 | #include "RecordTracks.h" |
| 974 | |
| 975 | RecordThread(const sp<AudioFlinger>& audioFlinger, |
| 976 | AudioStreamIn *input, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 977 | audio_io_handle_t id, |
Eric Laurent | d3922f7 | 2013-02-01 17:57:04 -0800 | [diff] [blame] | 978 | audio_devices_t outDevice, |
Glenn Kasten | 46909e7 | 2013-02-26 09:20:22 -0800 | [diff] [blame] | 979 | audio_devices_t inDevice |
| 980 | #ifdef TEE_SINK |
| 981 | , const sp<NBAIO_Sink>& teeSink |
| 982 | #endif |
| 983 | ); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 984 | virtual ~RecordThread(); |
| 985 | |
| 986 | // no addTrack_l ? |
| 987 | void destroyTrack_l(const sp<RecordTrack>& track); |
| 988 | void removeTrack_l(const sp<RecordTrack>& track); |
| 989 | |
| 990 | void dumpInternals(int fd, const Vector<String16>& args); |
| 991 | void dumpTracks(int fd, const Vector<String16>& args); |
| 992 | |
| 993 | // Thread virtuals |
| 994 | virtual bool threadLoop(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 995 | |
| 996 | // RefBase |
| 997 | virtual void onFirstRef(); |
| 998 | |
| 999 | virtual status_t initCheck() const { return (mInput == NULL) ? NO_INIT : NO_ERROR; } |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 1000 | |
Glenn Kasten | b880f5e | 2014-05-07 08:43:45 -0700 | [diff] [blame] | 1001 | virtual sp<MemoryDealer> readOnlyHeap() const { return mReadOnlyHeap; } |
| 1002 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1003 | sp<AudioFlinger::RecordThread::RecordTrack> createRecordTrack_l( |
| 1004 | const sp<AudioFlinger::Client>& client, |
| 1005 | uint32_t sampleRate, |
| 1006 | audio_format_t format, |
| 1007 | audio_channel_mask_t channelMask, |
Glenn Kasten | 74935e4 | 2013-12-19 08:56:45 -0800 | [diff] [blame] | 1008 | size_t *pFrameCount, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1009 | int sessionId, |
Marco Nelissen | 462fd2f | 2013-01-14 14:12:05 -0800 | [diff] [blame] | 1010 | int uid, |
Glenn Kasten | ddb0ccf | 2013-07-31 16:14:50 -0700 | [diff] [blame] | 1011 | IAudioFlinger::track_flags_t *flags, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1012 | pid_t tid, |
Glenn Kasten | 9156ef3 | 2013-08-06 15:39:08 -0700 | [diff] [blame] | 1013 | status_t *status /*non-NULL*/); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1014 | |
| 1015 | status_t start(RecordTrack* recordTrack, |
| 1016 | AudioSystem::sync_event_t event, |
| 1017 | int triggerSession); |
| 1018 | |
| 1019 | // ask the thread to stop the specified track, and |
| 1020 | // return true if the caller should then do it's part of the stopping process |
Glenn Kasten | a8356f6 | 2013-07-25 14:37:52 -0700 | [diff] [blame] | 1021 | bool stop(RecordTrack* recordTrack); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1022 | |
| 1023 | void dump(int fd, const Vector<String16>& args); |
| 1024 | AudioStreamIn* clearInput(); |
| 1025 | virtual audio_stream_t* stream() const; |
| 1026 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1027 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 1028 | virtual bool checkForNewParameter_l(const String8& keyValuePair, |
| 1029 | status_t& status); |
| 1030 | virtual void cacheParameters_l() {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1031 | virtual String8 getParameters(const String8& keys); |
Eric Laurent | 021cf96 | 2014-05-13 10:18:14 -0700 | [diff] [blame^] | 1032 | virtual void audioConfigChanged(int event, int param = 0); |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 1033 | void readInputParameters_l(); |
Glenn Kasten | 5f972c0 | 2014-01-13 09:59:31 -0800 | [diff] [blame] | 1034 | virtual uint32_t getInputFramesLost(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1035 | |
| 1036 | virtual status_t addEffectChain_l(const sp<EffectChain>& chain); |
| 1037 | virtual size_t removeEffectChain_l(const sp<EffectChain>& chain); |
| 1038 | virtual uint32_t hasAudioSession(int sessionId) const; |
| 1039 | |
| 1040 | // Return the set of unique session IDs across all tracks. |
| 1041 | // The keys are the session IDs, and the associated values are meaningless. |
| 1042 | // FIXME replace by Set [and implement Bag/Multiset for other uses]. |
| 1043 | KeyedVector<int, bool> sessionIds() const; |
| 1044 | |
| 1045 | virtual status_t setSyncEvent(const sp<SyncEvent>& event); |
| 1046 | virtual bool isValidSyncEvent(const sp<SyncEvent>& event) const; |
| 1047 | |
| 1048 | static void syncStartEventCallback(const wp<SyncEvent>& event); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1049 | |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1050 | virtual size_t frameCount() const { return mFrameCount; } |
Glenn Kasten | 3a6c90a | 2014-03-13 15:07:51 -0700 | [diff] [blame] | 1051 | bool hasFastCapture() const { return false; } |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1052 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1053 | private: |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1054 | // Enter standby if not already in standby, and set mStandby flag |
Glenn Kasten | 93e471f | 2013-08-19 08:40:07 -0700 | [diff] [blame] | 1055 | void standbyIfNotAlreadyInStandby(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1056 | |
| 1057 | // Call the HAL standby method unconditionally, and don't change mStandby flag |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 1058 | void inputStandBy(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1059 | |
| 1060 | AudioStreamIn *mInput; |
| 1061 | SortedVector < sp<RecordTrack> > mTracks; |
Glenn Kasten | 2b80640 | 2013-11-20 16:37:38 -0800 | [diff] [blame] | 1062 | // mActiveTracks has dual roles: it indicates the current active track(s), and |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1063 | // is used together with mStartStopCond to indicate start()/stop() progress |
Glenn Kasten | 2b80640 | 2013-11-20 16:37:38 -0800 | [diff] [blame] | 1064 | SortedVector< sp<RecordTrack> > mActiveTracks; |
| 1065 | // generation counter for mActiveTracks |
| 1066 | int mActiveTracksGen; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1067 | Condition mStartStopCond; |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1068 | |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1069 | // resampler converts input at HAL Hz to output at AudioRecord client Hz |
| 1070 | int16_t *mRsmpInBuffer; // see new[] for details on the size |
| 1071 | size_t mRsmpInFrames; // size of resampler input in frames |
| 1072 | size_t mRsmpInFramesP2;// size rounded up to a power-of-2 |
Glenn Kasten | 6dd62fb | 2013-12-05 16:35:58 -0800 | [diff] [blame] | 1073 | |
| 1074 | // rolling index that is never cleared |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1075 | int32_t mRsmpInRear; // last filled frame + 1 |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1076 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1077 | // For dumpsys |
| 1078 | const sp<NBAIO_Sink> mTeeSink; |
Glenn Kasten | b880f5e | 2014-05-07 08:43:45 -0700 | [diff] [blame] | 1079 | |
| 1080 | const sp<MemoryDealer> mReadOnlyHeap; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1081 | }; |