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 | |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 18 | #pragma once |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 19 | |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 20 | namespace android { |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 21 | |
| 22 | class AsyncCallbackThread; |
| 23 | |
| 24 | class ThreadBase : public virtual IAfThreadBase, public Thread { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 25 | public: |
Glenn Kasten | 97b7b75 | 2014-09-28 13:04:24 -0700 | [diff] [blame] | 26 | static const char *threadTypeToString(type_t type); |
| 27 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 28 | IAfThreadCallback* afThreadCallback() const final { return mAfThreadCallback.get(); } |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 29 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 30 | ThreadBase(const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id, |
Andy Hung | cf10d74 | 2020-04-28 15:38:24 -0700 | [diff] [blame] | 31 | type_t type, bool systemReady, bool isOut); |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 32 | ~ThreadBase() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 33 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 34 | status_t readyToRun() final; |
| 35 | void clearPowerManager() final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 36 | |
| 37 | // base for record and playback |
| 38 | enum { |
| 39 | CFG_EVENT_IO, |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 40 | CFG_EVENT_PRIO, |
| 41 | CFG_EVENT_SET_PARAMETER, |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 42 | CFG_EVENT_CREATE_AUDIO_PATCH, |
| 43 | CFG_EVENT_RELEASE_AUDIO_PATCH, |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 44 | CFG_EVENT_UPDATE_OUT_DEVICE, |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 45 | CFG_EVENT_RESIZE_BUFFER, |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 46 | CFG_EVENT_CHECK_OUTPUT_STAGE_EFFECTS, |
| 47 | CFG_EVENT_HAL_LATENCY_MODES_CHANGED, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 48 | }; |
| 49 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 50 | class ConfigEventData: public RefBase { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 51 | public: |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 52 | virtual ~ConfigEventData() {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 53 | |
| 54 | virtual void dump(char *buffer, size_t size) = 0; |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 55 | protected: |
| 56 | ConfigEventData() {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 59 | // Config event sequence by client if status needed (e.g binder thread calling setParameters()): |
| 60 | // 1. create SetParameterConfigEvent. This sets mWaitStatus in config event |
| 61 | // 2. Lock mLock |
| 62 | // 3. Call sendConfigEvent_l(): Append to mConfigEvents and mWaitWorkCV.signal |
| 63 | // 4. sendConfigEvent_l() reads status from event->mStatus; |
| 64 | // 5. sendConfigEvent_l() returns status |
| 65 | // 6. Unlock |
| 66 | // |
| 67 | // Parameter sequence by server: threadLoop calling processConfigEvents_l(): |
| 68 | // 1. Lock mLock |
| 69 | // 2. If there is an entry in mConfigEvents proceed ... |
| 70 | // 3. Read first entry in mConfigEvents |
| 71 | // 4. Remove first entry from mConfigEvents |
| 72 | // 5. Process |
| 73 | // 6. Set event->mStatus |
| 74 | // 7. event->mCond.signal |
| 75 | // 8. Unlock |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 76 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 77 | class ConfigEvent: public RefBase { |
| 78 | public: |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 79 | void dump(char *buffer, size_t size) { |
| 80 | snprintf(buffer, size, "Event type: %d\n", mType); |
| 81 | if (mData != nullptr) { |
| 82 | snprintf(buffer, size, "Data:\n"); |
| 83 | mData->dump(buffer, size); |
| 84 | } |
| 85 | } |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 86 | |
| 87 | const int mType; // event type e.g. CFG_EVENT_IO |
| 88 | Mutex mLock; // mutex associated with mCond |
| 89 | Condition mCond; // condition for status return |
| 90 | status_t mStatus; // status communicated to sender |
| 91 | bool mWaitStatus; // true if sender is waiting for status |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 92 | bool mRequiresSystemReady; // true if must wait for system ready to enter event queue |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 93 | sp<ConfigEventData> mData; // event specific parameter data |
| 94 | |
| 95 | protected: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 96 | explicit ConfigEvent(int type, bool requiresSystemReady = false) : |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 97 | mType(type), mStatus(NO_ERROR), mWaitStatus(false), |
| 98 | mRequiresSystemReady(requiresSystemReady), mData(NULL) {} |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | class IoConfigEventData : public ConfigEventData { |
| 102 | public: |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 103 | IoConfigEventData(audio_io_config_event_t event, pid_t pid, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 104 | audio_port_handle_t portId) : |
| 105 | mEvent(event), mPid(pid), mPortId(portId) {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 106 | |
| 107 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 108 | snprintf(buffer, size, "- IO event: event %d\n", mEvent); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 111 | const audio_io_config_event_t mEvent; |
Eric Laurent | 7c1ec5f | 2015-07-09 14:52:47 -0700 | [diff] [blame] | 112 | const pid_t mPid; |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 113 | const audio_port_handle_t mPortId; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 114 | }; |
| 115 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 116 | class IoConfigEvent : public ConfigEvent { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 117 | public: |
Mikhail Naganov | 88536df | 2021-07-26 17:30:29 -0700 | [diff] [blame] | 118 | IoConfigEvent(audio_io_config_event_t event, pid_t pid, audio_port_handle_t portId) : |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 119 | ConfigEvent(CFG_EVENT_IO) { |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 120 | mData = new IoConfigEventData(event, pid, portId); |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 121 | } |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 122 | }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 123 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 124 | class PrioConfigEventData : public ConfigEventData { |
| 125 | public: |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 126 | PrioConfigEventData(pid_t pid, pid_t tid, int32_t prio, bool forApp) : |
| 127 | mPid(pid), mTid(tid), mPrio(prio), mForApp(forApp) {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 128 | |
| 129 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 130 | snprintf(buffer, size, "- Prio event: pid %d, tid %d, prio %d, for app? %d\n", |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 131 | mPid, mTid, mPrio, mForApp); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 132 | } |
| 133 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 134 | const pid_t mPid; |
| 135 | const pid_t mTid; |
| 136 | const int32_t mPrio; |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 137 | const bool mForApp; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 138 | }; |
| 139 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 140 | class PrioConfigEvent : public ConfigEvent { |
| 141 | public: |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 142 | PrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp) : |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 143 | ConfigEvent(CFG_EVENT_PRIO, true) { |
Mikhail Naganov | 83f0427 | 2017-02-07 10:45:09 -0800 | [diff] [blame] | 144 | mData = new PrioConfigEventData(pid, tid, prio, forApp); |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 145 | } |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 146 | }; |
| 147 | |
| 148 | class SetParameterConfigEventData : public ConfigEventData { |
| 149 | public: |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 150 | explicit SetParameterConfigEventData(const String8& keyValuePairs) : |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 151 | mKeyValuePairs(keyValuePairs) {} |
| 152 | |
| 153 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 154 | snprintf(buffer, size, "- KeyValue: %s\n", mKeyValuePairs.string()); |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | const String8 mKeyValuePairs; |
| 158 | }; |
| 159 | |
| 160 | class SetParameterConfigEvent : public ConfigEvent { |
| 161 | public: |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 162 | explicit SetParameterConfigEvent(const String8& keyValuePairs) : |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 163 | ConfigEvent(CFG_EVENT_SET_PARAMETER) { |
| 164 | mData = new SetParameterConfigEventData(keyValuePairs); |
| 165 | mWaitStatus = true; |
| 166 | } |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 169 | class CreateAudioPatchConfigEventData : public ConfigEventData { |
| 170 | public: |
| 171 | CreateAudioPatchConfigEventData(const struct audio_patch patch, |
| 172 | audio_patch_handle_t handle) : |
| 173 | mPatch(patch), mHandle(handle) {} |
| 174 | |
| 175 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 176 | snprintf(buffer, size, "- Patch handle: %u\n", mHandle); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | const struct audio_patch mPatch; |
| 180 | audio_patch_handle_t mHandle; |
| 181 | }; |
| 182 | |
| 183 | class CreateAudioPatchConfigEvent : public ConfigEvent { |
| 184 | public: |
| 185 | CreateAudioPatchConfigEvent(const struct audio_patch patch, |
| 186 | audio_patch_handle_t handle) : |
| 187 | ConfigEvent(CFG_EVENT_CREATE_AUDIO_PATCH) { |
| 188 | mData = new CreateAudioPatchConfigEventData(patch, handle); |
| 189 | mWaitStatus = true; |
| 190 | } |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 191 | }; |
| 192 | |
| 193 | class ReleaseAudioPatchConfigEventData : public ConfigEventData { |
| 194 | public: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 195 | explicit ReleaseAudioPatchConfigEventData(const audio_patch_handle_t handle) : |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 196 | mHandle(handle) {} |
| 197 | |
| 198 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 199 | snprintf(buffer, size, "- Patch handle: %u\n", mHandle); |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | audio_patch_handle_t mHandle; |
| 203 | }; |
| 204 | |
| 205 | class ReleaseAudioPatchConfigEvent : public ConfigEvent { |
| 206 | public: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 207 | explicit ReleaseAudioPatchConfigEvent(const audio_patch_handle_t handle) : |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 208 | ConfigEvent(CFG_EVENT_RELEASE_AUDIO_PATCH) { |
| 209 | mData = new ReleaseAudioPatchConfigEventData(handle); |
| 210 | mWaitStatus = true; |
| 211 | } |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 212 | }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 213 | |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 214 | class UpdateOutDevicesConfigEventData : public ConfigEventData { |
| 215 | public: |
| 216 | explicit UpdateOutDevicesConfigEventData(const DeviceDescriptorBaseVector& outDevices) : |
| 217 | mOutDevices(outDevices) {} |
| 218 | |
| 219 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 220 | snprintf(buffer, size, "- Devices: %s", android::toString(mOutDevices).c_str()); |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | DeviceDescriptorBaseVector mOutDevices; |
| 224 | }; |
| 225 | |
| 226 | class UpdateOutDevicesConfigEvent : public ConfigEvent { |
| 227 | public: |
| 228 | explicit UpdateOutDevicesConfigEvent(const DeviceDescriptorBaseVector& outDevices) : |
| 229 | ConfigEvent(CFG_EVENT_UPDATE_OUT_DEVICE) { |
| 230 | mData = new UpdateOutDevicesConfigEventData(outDevices); |
| 231 | } |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 232 | }; |
| 233 | |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 234 | class ResizeBufferConfigEventData : public ConfigEventData { |
| 235 | public: |
| 236 | explicit ResizeBufferConfigEventData(int32_t maxSharedAudioHistoryMs) : |
| 237 | mMaxSharedAudioHistoryMs(maxSharedAudioHistoryMs) {} |
| 238 | |
| 239 | virtual void dump(char *buffer, size_t size) { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 240 | snprintf(buffer, size, "- mMaxSharedAudioHistoryMs: %d", mMaxSharedAudioHistoryMs); |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | int32_t mMaxSharedAudioHistoryMs; |
| 244 | }; |
| 245 | |
| 246 | class ResizeBufferConfigEvent : public ConfigEvent { |
| 247 | public: |
| 248 | explicit ResizeBufferConfigEvent(int32_t maxSharedAudioHistoryMs) : |
| 249 | ConfigEvent(CFG_EVENT_RESIZE_BUFFER) { |
| 250 | mData = new ResizeBufferConfigEventData(maxSharedAudioHistoryMs); |
| 251 | } |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 252 | }; |
| 253 | |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 254 | class CheckOutputStageEffectsEvent : public ConfigEvent { |
| 255 | public: |
| 256 | CheckOutputStageEffectsEvent() : |
| 257 | ConfigEvent(CFG_EVENT_CHECK_OUTPUT_STAGE_EFFECTS) { |
| 258 | } |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 259 | }; |
| 260 | |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 261 | class HalLatencyModesChangedEvent : public ConfigEvent { |
| 262 | public: |
| 263 | HalLatencyModesChangedEvent() : |
| 264 | ConfigEvent(CFG_EVENT_HAL_LATENCY_MODES_CHANGED) { |
| 265 | } |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 266 | }; |
| 267 | |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 268 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 269 | class PMDeathRecipient : public IBinder::DeathRecipient { |
| 270 | public: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 271 | explicit PMDeathRecipient(const wp<ThreadBase>& thread) : mThread(thread) {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 272 | virtual ~PMDeathRecipient() {} |
| 273 | |
| 274 | // IBinder::DeathRecipient |
| 275 | virtual void binderDied(const wp<IBinder>& who); |
| 276 | |
| 277 | private: |
Mikhail Naganov | bf49308 | 2017-04-17 17:37:12 -0700 | [diff] [blame] | 278 | DISALLOW_COPY_AND_ASSIGN(PMDeathRecipient); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 279 | |
| 280 | wp<ThreadBase> mThread; |
| 281 | }; |
| 282 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 283 | type_t type() const final { return mType; } |
| 284 | bool isDuplicating() const final { return (mType == DUPLICATING); } |
| 285 | audio_io_handle_t id() const final { return mId;} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 286 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 287 | uint32_t sampleRate() const final { return mSampleRate; } |
| 288 | audio_channel_mask_t channelMask() const final { return mChannelMask; } |
| 289 | audio_channel_mask_t mixerChannelMask() const override { return mChannelMask; } |
| 290 | audio_format_t format() const final { return mHALFormat; } |
| 291 | uint32_t channelCount() const final { return mChannelCount; } |
| 292 | audio_channel_mask_t hapticChannelMask() const override { return AUDIO_CHANNEL_NONE; } |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 293 | uint32_t hapticChannelCount() const override { return 0; } |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 294 | uint32_t latency_l() const override { return 0; } |
| 295 | void setVolumeForOutput_l(float /* left */, float /* right */) const override {} |
Glenn Kasten | 4a8308b | 2016-04-18 14:10:01 -0700 | [diff] [blame] | 296 | |
| 297 | // Return's the HAL's frame count i.e. fast mixer buffer size. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 298 | size_t frameCountHAL() const final { return mFrameCount; } |
| 299 | size_t frameSize() const final { return mFrameSize; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 300 | |
| 301 | // Should be "virtual status_t requestExitAndWait()" and override same |
| 302 | // method in Thread, but Thread::requestExitAndWait() is not yet virtual. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 303 | void exit() final; |
| 304 | status_t setParameters(const String8& keyValuePairs) final; |
| 305 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 306 | // sendConfigEvent_l() must be called with ThreadBase::mLock held |
| 307 | // Can temporarily release the lock if waiting for a reply from |
| 308 | // processConfigEvents_l(). |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 309 | status_t sendConfigEvent_l(sp<ConfigEvent>& event); |
| 310 | void sendIoConfigEvent(audio_io_config_event_t event, pid_t pid = 0, |
| 311 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) final; |
| 312 | void sendIoConfigEvent_l(audio_io_config_event_t event, pid_t pid = 0, |
| 313 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) final; |
| 314 | void sendPrioConfigEvent(pid_t pid, pid_t tid, int32_t prio, bool forApp) final; |
| 315 | void sendPrioConfigEvent_l(pid_t pid, pid_t tid, int32_t prio, bool forApp) final; |
| 316 | status_t sendSetParameterConfigEvent_l(const String8& keyValuePair) final; |
| 317 | status_t sendCreateAudioPatchConfigEvent(const struct audio_patch* patch, |
| 318 | audio_patch_handle_t* handle) final; |
| 319 | status_t sendReleaseAudioPatchConfigEvent(audio_patch_handle_t handle) final; |
| 320 | status_t sendUpdateOutDeviceConfigEvent( |
| 321 | const DeviceDescriptorBaseVector& outDevices) final; |
| 322 | void sendResizeBufferConfigEvent_l(int32_t maxSharedAudioHistoryMs) final; |
| 323 | void sendCheckOutputStageEffectsEvent() final; |
| 324 | void sendCheckOutputStageEffectsEvent_l() final; |
| 325 | void sendHalLatencyModesChangedEvent_l() final; |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 326 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 327 | void processConfigEvents_l() final; |
| 328 | void setCheckOutputStageEffects() override {} |
| 329 | void updateOutDevices(const DeviceDescriptorBaseVector& outDevices) override; |
| 330 | void toAudioPortConfig(struct audio_port_config* config) override; |
| 331 | void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs) override; |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 332 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 333 | // see note at declaration of mStandby, mOutDevice and mInDevice |
| 334 | bool inStandby() const override { return mStandby; } |
| 335 | const DeviceTypeSet outDeviceTypes() const final { |
| 336 | return getAudioDeviceTypes(mOutDeviceTypeAddrs); |
| 337 | } |
| 338 | audio_devices_t inDeviceType() const final { return mInDeviceTypeAddr.mType; } |
| 339 | DeviceTypeSet getDeviceTypes() const final { |
| 340 | return isOutput() ? outDeviceTypes() : DeviceTypeSet({inDeviceType()}); |
| 341 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 342 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 343 | const AudioDeviceTypeAddrVector& outDeviceTypeAddrs() const final { |
| 344 | return mOutDeviceTypeAddrs; |
| 345 | } |
| 346 | const AudioDeviceTypeAddr& inDeviceTypeAddr() const final { |
| 347 | return mInDeviceTypeAddr; |
| 348 | } |
Andy Hung | 293558a | 2017-03-21 12:19:20 -0700 | [diff] [blame] | 349 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 350 | bool isOutput() const final { return mIsOut; } |
jiabin | 8f278ee | 2019-11-11 12:16:27 -0800 | [diff] [blame] | 351 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 352 | bool isOffloadOrMmap() const final { |
| 353 | switch (mType) { |
| 354 | case OFFLOAD: |
| 355 | case MMAP_PLAYBACK: |
| 356 | case MMAP_CAPTURE: |
| 357 | return true; |
| 358 | default: |
| 359 | return false; |
| 360 | } |
| 361 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 362 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 363 | sp<IAfEffectHandle> createEffect_l( |
Andy Hung | 88035ac | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 364 | const sp<Client>& client, |
Ytai Ben-Tsvi | 9cd8981 | 2020-07-01 17:12:06 -0700 | [diff] [blame] | 365 | const sp<media::IEffectClient>& effectClient, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 366 | int32_t priority, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 367 | audio_session_t sessionId, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 368 | effect_descriptor_t *desc, |
| 369 | int *enabled, |
Eric Laurent | 0d5a2ed | 2016-12-01 15:28:29 -0800 | [diff] [blame] | 370 | status_t *status /*non-NULL*/, |
Eric Laurent | 2fe0acd | 2020-03-13 14:30:46 -0700 | [diff] [blame] | 371 | bool pinned, |
Eric Laurent | de8caf4 | 2021-08-11 17:19:25 +0200 | [diff] [blame] | 372 | bool probe, |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 373 | bool notifyFramesProcessed) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 374 | |
| 375 | // return values for hasAudioSession (bit field) |
| 376 | enum effect_state { |
| 377 | EFFECT_SESSION = 0x1, // the audio session corresponds to at least one |
| 378 | // effect |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 379 | TRACK_SESSION = 0x2, // the audio session corresponds to at least one |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 380 | // track |
Eric Laurent | b62d036 | 2021-10-26 17:40:18 +0200 | [diff] [blame] | 381 | FAST_SESSION = 0x4, // the audio session corresponds to at least one |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 382 | // fast track |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 383 | SPATIALIZED_SESSION = 0x8, // the audio session corresponds to at least one |
| 384 | // spatialized track |
| 385 | BIT_PERFECT_SESSION = 0x10 // the audio session corresponds to at least one |
| 386 | // bit-perfect track |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 387 | }; |
| 388 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 389 | // get effect chain corresponding to session Id. |
| 390 | sp<IAfEffectChain> getEffectChain(audio_session_t sessionId) const final; |
| 391 | // same as getEffectChain() but must be called with ThreadBase mutex locked |
| 392 | sp<IAfEffectChain> getEffectChain_l(audio_session_t sessionId) const final; |
| 393 | std::vector<int> getEffectIds_l(audio_session_t sessionId) const final; |
| 394 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 395 | // lock all effect chains Mutexes. Must be called before releasing the |
| 396 | // ThreadBase mutex before processing the mixer and effects. This guarantees the |
| 397 | // integrity of the chains during the process. |
| 398 | // Also sets the parameter 'effectChains' to current value of mEffectChains. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 399 | void lockEffectChains_l(Vector<sp<IAfEffectChain>>& effectChains) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 400 | // unlock effect chains after process |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 401 | void unlockEffectChains(const Vector<sp<IAfEffectChain>>& effectChains) final; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 402 | // get a copy of mEffectChains vector |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 403 | Vector<sp<IAfEffectChain>> getEffectChains_l() const final { return mEffectChains; }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 404 | // set audio mode to all effect chains |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 405 | void setMode(audio_mode_t mode) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 406 | // get effect module with corresponding ID on specified audio session |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 407 | sp<IAfEffectModule> getEffect(audio_session_t sessionId, int effectId) const final; |
| 408 | sp<IAfEffectModule> getEffect_l(audio_session_t sessionId, int effectId) const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 409 | // add and effect module. Also creates the effect chain is none exists for |
Eric Laurent | 6c79632 | 2019-04-09 14:13:17 -0700 | [diff] [blame] | 410 | // the effects audio session. Only called in a context of moving an effect |
| 411 | // from one thread to another |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 412 | status_t addEffect_l(const sp<IAfEffectModule>& effect) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 413 | // remove and effect module. Also removes the effect chain is this was the last |
| 414 | // effect |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 415 | void removeEffect_l(const sp<IAfEffectModule>& effect, bool release = false) final; |
Eric Laurent | 0d5a2ed | 2016-12-01 15:28:29 -0800 | [diff] [blame] | 416 | // disconnect an effect handle from module and destroy module if last handle |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 417 | void disconnectEffectHandle(IAfEffectHandle* handle, bool unpinIfLast) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 418 | // detach all tracks connected to an auxiliary effect |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 419 | void detachAuxEffect_l(int /* effectId */) override {} |
Andy Hung | 99b1ba6 | 2023-07-14 11:00:08 -0700 | [diff] [blame] | 420 | // TODO(b/291317898) - remove hasAudioSession_l below. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 421 | uint32_t hasAudioSession_l(audio_session_t sessionId) const override = 0; |
| 422 | uint32_t hasAudioSession(audio_session_t sessionId) const final { |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 423 | Mutex::Autolock _l(mLock); |
| 424 | return hasAudioSession_l(sessionId); |
| 425 | } |
| 426 | |
Andy Hung | c3d62f9 | 2019-03-14 13:38:51 -0700 | [diff] [blame] | 427 | template <typename T> |
| 428 | uint32_t hasAudioSession_l(audio_session_t sessionId, const T& tracks) const { |
| 429 | uint32_t result = 0; |
| 430 | if (getEffectChain_l(sessionId) != 0) { |
| 431 | result = EFFECT_SESSION; |
| 432 | } |
| 433 | for (size_t i = 0; i < tracks.size(); ++i) { |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 434 | const sp<IAfTrackBase>& track = tracks[i]; |
Andy Hung | c3d62f9 | 2019-03-14 13:38:51 -0700 | [diff] [blame] | 435 | if (sessionId == track->sessionId() |
| 436 | && !track->isInvalid() // not yet removed from tracks. |
| 437 | && !track->isTerminated()) { |
| 438 | result |= TRACK_SESSION; |
| 439 | if (track->isFastTrack()) { |
| 440 | result |= FAST_SESSION; // caution, only represents first track. |
| 441 | } |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 442 | if (track->isSpatialized()) { |
Eric Laurent | b62d036 | 2021-10-26 17:40:18 +0200 | [diff] [blame] | 443 | result |= SPATIALIZED_SESSION; // caution, only first track. |
| 444 | } |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 445 | if (track->isBitPerfect()) { |
| 446 | result |= BIT_PERFECT_SESSION; |
| 447 | } |
Andy Hung | c3d62f9 | 2019-03-14 13:38:51 -0700 | [diff] [blame] | 448 | break; |
| 449 | } |
| 450 | } |
| 451 | return result; |
| 452 | } |
| 453 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 454 | // the value returned by default implementation is not important as the |
| 455 | // strategy is only meaningful for PlaybackThread which implements this method |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 456 | product_strategy_t getStrategyForSession_l( |
| 457 | audio_session_t /* sessionId */) const override { |
Ytai Ben-Tsvi | 0a4904a | 2021-01-06 12:57:05 -0800 | [diff] [blame] | 458 | return static_cast<product_strategy_t>(0); |
| 459 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 460 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 461 | // check if some effects must be suspended/restored when an effect is enabled |
| 462 | // or disabled |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 463 | void checkSuspendOnEffectEnabled(bool enabled, |
Eric Laurent | 6b446ce | 2019-12-13 10:56:31 -0800 | [diff] [blame] | 464 | audio_session_t sessionId, |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 465 | bool threadLocked) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 466 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 467 | |
Glenn Kasten | b880f5e | 2014-05-07 08:43:45 -0700 | [diff] [blame] | 468 | // Return a reference to a per-thread heap which can be used to allocate IMemory |
| 469 | // objects that will be read-only to client processes, read/write to mediaserver, |
| 470 | // and shared by all client processes of the thread. |
| 471 | // The heap is per-thread rather than common across all threads, because |
| 472 | // clients can't be trusted not to modify the offset of the IMemory they receive. |
| 473 | // If a thread does not have such a heap, this method returns 0. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 474 | sp<MemoryDealer> readOnlyHeap() const override { return nullptr; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 475 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 476 | sp<IMemory> pipeMemory() const override { return nullptr; } |
Glenn Kasten | 6181ffd | 2014-05-13 10:41:52 -0700 | [diff] [blame] | 477 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 478 | void systemReady() final; |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 479 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 480 | void broadcast_l() final; |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 481 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 482 | bool isTimestampCorrectionEnabled() const override { return false; } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 483 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 484 | bool isMsdDevice() const final { return mIsMsdDevice; } |
Andy Hung | c8fddf3 | 2018-08-08 18:32:37 -0700 | [diff] [blame] | 485 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 486 | void dump(int fd, const Vector<String16>& args) override; |
Andy Hung | dc099c2 | 2018-09-18 13:46:39 -0700 | [diff] [blame] | 487 | |
Andy Hung | d097981 | 2019-02-21 15:51:44 -0800 | [diff] [blame] | 488 | // deliver stats to mediametrics. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 489 | void sendStatistics(bool force) final; |
Andy Hung | d097981 | 2019-02-21 15:51:44 -0800 | [diff] [blame] | 490 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 491 | Mutex& mutex() const final { |
| 492 | return mLock; |
| 493 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 494 | mutable Mutex mLock; |
| 495 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 496 | void onEffectEnable(const sp<IAfEffectModule>& effect) final; |
| 497 | void onEffectDisable() final; |
Eric Laurent | 6b446ce | 2019-12-13 10:56:31 -0800 | [diff] [blame] | 498 | |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 499 | // invalidateTracksForAudioSession_l must be called with holding mLock. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 500 | void invalidateTracksForAudioSession_l(audio_session_t /* sessionId */) const override {} |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 501 | // Invalidate all the tracks with the given audio session. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 502 | void invalidateTracksForAudioSession(audio_session_t sessionId) const final { |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 503 | Mutex::Autolock _l(mLock); |
| 504 | invalidateTracksForAudioSession_l(sessionId); |
| 505 | } |
| 506 | |
| 507 | template <typename T> |
| 508 | void invalidateTracksForAudioSession_l(audio_session_t sessionId, |
| 509 | const T& tracks) const { |
| 510 | for (size_t i = 0; i < tracks.size(); ++i) { |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 511 | const sp<IAfTrackBase>& track = tracks[i]; |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 512 | if (sessionId == track->sessionId()) { |
| 513 | track->invalidate(); |
| 514 | } |
| 515 | } |
| 516 | } |
| 517 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 518 | void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor) override; |
| 519 | void stopMelComputation_l() override; |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 520 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 521 | protected: |
| 522 | |
| 523 | // entry describing an effect being suspended in mSuspendedSessions keyed vector |
| 524 | class SuspendedSessionDesc : public RefBase { |
| 525 | public: |
| 526 | SuspendedSessionDesc() : mRefCount(0) {} |
| 527 | |
| 528 | int mRefCount; // number of active suspend requests |
| 529 | effect_uuid_t mType; // effect type UUID |
| 530 | }; |
| 531 | |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 532 | void acquireWakeLock(); |
| 533 | virtual void acquireWakeLock_l(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 534 | void releaseWakeLock(); |
| 535 | void releaseWakeLock_l(); |
Andy Hung | d01b0f1 | 2016-11-07 16:10:30 -0800 | [diff] [blame] | 536 | void updateWakeLockUids_l(const SortedVector<uid_t> &uids); |
Marco Nelissen | 462fd2f | 2013-01-14 14:12:05 -0800 | [diff] [blame] | 537 | void getPowerManager_l(); |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 538 | // suspend or restore effects of the specified type (or all if type is NULL) |
| 539 | // on a given session. The number of suspend requests is counted and restore |
| 540 | // occurs when all suspend requests are cancelled. |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 541 | void setEffectSuspended_l(const effect_uuid_t *type, |
| 542 | bool suspend, |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 543 | audio_session_t sessionId) final; |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 544 | // updated mSuspendedSessions when an effect is suspended or restored |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 545 | void updateSuspendedSessions_l(const effect_uuid_t *type, |
| 546 | bool suspend, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 547 | audio_session_t sessionId); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 548 | // check if some effects must be suspended when an effect chain is added |
Andy Hung | 116bc26 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 549 | void checkSuspendOnAddEffectChain_l(const sp<IAfEffectChain>& chain); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 550 | |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 551 | // sends the metadata of the active tracks to the HAL |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 552 | struct MetadataUpdate { |
| 553 | std::vector<playback_track_metadata_v7_t> playbackMetadataUpdate; |
| 554 | std::vector<record_track_metadata_v7_t> recordMetadataUpdate; |
| 555 | }; |
| 556 | virtual MetadataUpdate updateMetadata_l() = 0; |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 557 | |
Narayan Kamath | 014e7fa | 2013-10-14 15:03:38 +0100 | [diff] [blame] | 558 | String16 getWakeLockTag(); |
| 559 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 560 | virtual void preExit() { } |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 561 | virtual void setMasterMono_l(bool mono __unused) { } |
| 562 | virtual bool requireMonoBlend() { return false; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 563 | |
Andy Hung | 1c86ebe | 2018-05-29 20:29:08 -0700 | [diff] [blame] | 564 | // called within the threadLoop to obtain timestamp from the HAL. |
| 565 | virtual status_t threadloop_getHalTimestamp_l( |
| 566 | ExtendedTimestamp *timestamp __unused) const { |
| 567 | return INVALID_OPERATION; |
| 568 | } |
Andy Hung | 116bc26 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 569 | public: |
Andy Hung | 99b1ba6 | 2023-07-14 11:00:08 -0700 | [diff] [blame] | 570 | // TODO(b/291317898) organize with publics |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 571 | product_strategy_t getStrategyForStream(audio_stream_type_t stream) const; |
Andy Hung | 116bc26 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 572 | protected: |
Eric Laurent | d66d7a1 | 2021-07-13 13:35:32 +0200 | [diff] [blame] | 573 | |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 574 | virtual void onHalLatencyModesChanged_l() {} |
| 575 | |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 576 | virtual void dumpInternals_l(int fd __unused, const Vector<String16>& args __unused) |
| 577 | { } |
| 578 | virtual void dumpTracks_l(int fd __unused, const Vector<String16>& args __unused) { } |
| 579 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 580 | const type_t mType; |
| 581 | |
| 582 | // Used by parameters, config events, addTrack_l, exit |
| 583 | Condition mWaitWorkCV; |
| 584 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 585 | const sp<IAfThreadCallback> mAfThreadCallback; |
Andy Hung | cf10d74 | 2020-04-28 15:38:24 -0700 | [diff] [blame] | 586 | ThreadMetrics mThreadMetrics; |
| 587 | const bool mIsOut; |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 588 | |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 589 | // updated by PlaybackThread::readOutputParameters_l() or |
| 590 | // RecordThread::readInputParameters_l() |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 591 | uint32_t mSampleRate; |
| 592 | size_t mFrameCount; // output HAL, direct output, record |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 593 | audio_channel_mask_t mChannelMask; |
Glenn Kasten | f6ed423 | 2013-07-16 11:16:27 -0700 | [diff] [blame] | 594 | uint32_t mChannelCount; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 595 | size_t mFrameSize; |
Glenn Kasten | 97b7b75 | 2014-09-28 13:04:24 -0700 | [diff] [blame] | 596 | // not HAL frame size, this is for output sink (to pipe to fast mixer) |
Andy Hung | 463be25 | 2014-07-10 16:56:07 -0700 | [diff] [blame] | 597 | audio_format_t mFormat; // Source format for Recording and |
| 598 | // Sink format for Playback. |
| 599 | // Sink format may be different than |
| 600 | // HAL format if Fastmixer is used. |
| 601 | audio_format_t mHALFormat; |
Glenn Kasten | 70949c4 | 2013-08-06 07:40:12 -0700 | [diff] [blame] | 602 | size_t mBufferSize; // HAL buffer size for read() or write() |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 603 | AudioDeviceTypeAddrVector mOutDeviceTypeAddrs; // output device types and addresses |
| 604 | AudioDeviceTypeAddr mInDeviceTypeAddr; // input device type and address |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 605 | Vector< sp<ConfigEvent> > mConfigEvents; |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 606 | Vector< sp<ConfigEvent> > mPendingConfigEvents; // events awaiting system ready |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 607 | |
| 608 | // These fields are written and read by thread itself without lock or barrier, |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 609 | // and read by other threads without lock or barrier via standby(), outDeviceTypes() |
| 610 | // and inDeviceType(). |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 611 | // Because of the absence of a lock or barrier, any other thread that reads |
| 612 | // these fields must use the information in isolation, or be prepared to deal |
| 613 | // with possibility that it might be inconsistent with other information. |
Glenn Kasten | 4944acb | 2013-08-19 08:39:20 -0700 | [diff] [blame] | 614 | bool mStandby; // Whether thread is currently in standby. |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 615 | |
Eric Laurent | 296fb13 | 2015-05-01 11:38:42 -0700 | [diff] [blame] | 616 | struct audio_patch mPatch; |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 617 | |
Glenn Kasten | f59497b | 2015-01-26 16:35:47 -0800 | [diff] [blame] | 618 | audio_source_t mAudioSource; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 619 | |
| 620 | const audio_io_handle_t mId; |
Andy Hung | 116bc26 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 621 | Vector<sp<IAfEffectChain>> mEffectChains; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 622 | |
Glenn Kasten | d7dca05 | 2015-03-05 16:05:54 -0800 | [diff] [blame] | 623 | static const int kThreadNameLength = 16; // prctl(PR_SET_NAME) limit |
| 624 | char mThreadName[kThreadNameLength]; // guaranteed NUL-terminated |
Chris Ye | 6597d73 | 2020-02-28 22:38:25 -0800 | [diff] [blame] | 625 | sp<os::IPowerManager> mPowerManager; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 626 | sp<IBinder> mWakeLockToken; |
| 627 | const sp<PMDeathRecipient> mDeathRecipient; |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 628 | // list of suspended effects per session and per type. The first (outer) vector is |
| 629 | // keyed by session ID, the second (inner) by type UUID timeLow field |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 630 | // Updated by updateSuspendedSessions_l() only. |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 631 | KeyedVector< audio_session_t, KeyedVector< int, sp<SuspendedSessionDesc> > > |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 632 | mSuspendedSessions; |
Sanna Catherine de Treville Wager | 2a6a945 | 2017-07-28 11:02:01 -0700 | [diff] [blame] | 633 | // TODO: add comment and adjust size as needed |
Glenn Kasten | ab7d72f | 2013-02-27 09:05:28 -0800 | [diff] [blame] | 634 | static const size_t kLogSize = 4 * 1024; |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 635 | sp<NBLog::Writer> mNBLogWriter; |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 636 | bool mSystemReady; |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 637 | ExtendedTimestamp mTimestamp; |
Andy Hung | 2e2c0bb | 2018-06-11 19:13:11 -0700 | [diff] [blame] | 638 | TimestampVerifier< // For timestamp statistics. |
| 639 | int64_t /* frame count */, int64_t /* time ns */> mTimestampVerifier; |
Dean Wheatley | 12473e9 | 2021-03-18 23:00:55 +1100 | [diff] [blame] | 640 | // DIRECT and OFFLOAD threads should reset frame count to zero on stop/flush |
| 641 | // TODO: add confirmation checks: |
| 642 | // 1) DIRECT threads and linear PCM format really resets to 0? |
| 643 | // 2) Is frame count really valid if not linear pcm? |
| 644 | // 3) Are all 64 bits of position returned, not just lowest 32 bits? |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 645 | // Timestamp corrected device should be a single device. |
| 646 | audio_devices_t mTimestampCorrectedDevice = AUDIO_DEVICE_NONE; |
Andy Hung | 446f4df | 2019-02-21 12:26:41 -0800 | [diff] [blame] | 647 | |
| 648 | // ThreadLoop statistics per iteration. |
| 649 | int64_t mLastIoBeginNs = -1; |
| 650 | int64_t mLastIoEndNs = -1; |
| 651 | |
Andy Hung | 44d648b | 2022-04-08 17:33:40 -0700 | [diff] [blame] | 652 | // ThreadSnapshot is thread-safe (internally locked) |
| 653 | mediautils::ThreadSnapshot mThreadSnapshot; |
| 654 | |
Andy Hung | 446f4df | 2019-02-21 12:26:41 -0800 | [diff] [blame] | 655 | // This should be read under ThreadBase lock (if not on the threadLoop thread). |
| 656 | audio_utils::Statistics<double> mIoJitterMs{0.995 /* alpha */}; |
| 657 | audio_utils::Statistics<double> mProcessTimeMs{0.995 /* alpha */}; |
Andy Hung | e6c3711 | 2019-02-26 17:38:10 -0800 | [diff] [blame] | 658 | audio_utils::Statistics<double> mLatencyMs{0.995 /* alpha */}; |
Robert Wu | 06db0a3 | 2021-08-10 19:05:34 +0000 | [diff] [blame] | 659 | audio_utils::Statistics<double> mMonopipePipeDepthStats{0.999 /* alpha */}; |
Andy Hung | 446f4df | 2019-02-21 12:26:41 -0800 | [diff] [blame] | 660 | |
Andy Hung | d097981 | 2019-02-21 15:51:44 -0800 | [diff] [blame] | 661 | // Save the last count when we delivered statistics to mediametrics. |
| 662 | int64_t mLastRecordedTimestampVerifierN = 0; |
| 663 | int64_t mLastRecordedTimeNs = 0; // BOOTTIME to include suspend. |
| 664 | |
Andy Hung | c8fddf3 | 2018-08-08 18:32:37 -0700 | [diff] [blame] | 665 | bool mIsMsdDevice = false; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 666 | // A condition that must be evaluated by the thread loop has changed and |
| 667 | // we must not wait for async write callback in the thread loop before evaluating it |
| 668 | bool mSignalPending; |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 669 | |
Andy Hung | 8946a28 | 2018-04-19 20:04:56 -0700 | [diff] [blame] | 670 | #ifdef TEE_SINK |
| 671 | NBAIO_Tee mTee; |
| 672 | #endif |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 673 | // ActiveTracks is a sorted vector of track type T representing the |
| 674 | // active tracks of threadLoop() to be considered by the locked prepare portion. |
| 675 | // ActiveTracks should be accessed with the ThreadBase lock held. |
| 676 | // |
| 677 | // During processing and I/O, the threadLoop does not hold the lock; |
| 678 | // hence it does not directly use ActiveTracks. Care should be taken |
| 679 | // to hold local strong references or defer removal of tracks |
| 680 | // if the threadLoop may still be accessing those tracks due to mix, etc. |
| 681 | // |
| 682 | // This class updates power information appropriately. |
| 683 | // |
| 684 | |
| 685 | template <typename T> |
| 686 | class ActiveTracks { |
| 687 | public: |
Andy Hung | 2c6c3bb | 2017-06-16 14:01:45 -0700 | [diff] [blame] | 688 | explicit ActiveTracks(SimpleLog *localLog = nullptr) |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 689 | : mActiveTracksGeneration(0) |
| 690 | , mLastActiveTracksGeneration(0) |
Andy Hung | 2c6c3bb | 2017-06-16 14:01:45 -0700 | [diff] [blame] | 691 | , mLocalLog(localLog) |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 692 | { } |
| 693 | |
| 694 | ~ActiveTracks() { |
| 695 | ALOGW_IF(!mActiveTracks.isEmpty(), |
| 696 | "ActiveTracks should be empty in destructor"); |
| 697 | } |
| 698 | // returns the last track added (even though it may have been |
| 699 | // subsequently removed from ActiveTracks). |
| 700 | // |
| 701 | // Used for DirectOutputThread to ensure a flush is called when transitioning |
| 702 | // to a new track (even though it may be on the same session). |
| 703 | // Used for OffloadThread to ensure that volume and mixer state is |
| 704 | // taken from the latest track added. |
| 705 | // |
| 706 | // The latest track is saved with a weak pointer to prevent keeping an |
| 707 | // otherwise useless track alive. Thus the function will return nullptr |
| 708 | // if the latest track has subsequently been removed and destroyed. |
| 709 | sp<T> getLatest() { |
| 710 | return mLatestActiveTrack.promote(); |
| 711 | } |
| 712 | |
| 713 | // SortedVector methods |
| 714 | ssize_t add(const sp<T> &track); |
| 715 | ssize_t remove(const sp<T> &track); |
| 716 | size_t size() const { |
| 717 | return mActiveTracks.size(); |
| 718 | } |
Eric Tan | 39ec8d6 | 2018-07-24 09:49:29 -0700 | [diff] [blame] | 719 | bool isEmpty() const { |
| 720 | return mActiveTracks.isEmpty(); |
| 721 | } |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 722 | ssize_t indexOf(const sp<T>& item) const { |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 723 | return mActiveTracks.indexOf(item); |
| 724 | } |
| 725 | sp<T> operator[](size_t index) const { |
| 726 | return mActiveTracks[index]; |
| 727 | } |
| 728 | typename SortedVector<sp<T>>::iterator begin() { |
| 729 | return mActiveTracks.begin(); |
| 730 | } |
| 731 | typename SortedVector<sp<T>>::iterator end() { |
| 732 | return mActiveTracks.end(); |
| 733 | } |
| 734 | |
| 735 | // Due to Binder recursion optimization, clear() and updatePowerState() |
| 736 | // cannot be called from a Binder thread because they may call back into |
| 737 | // the original calling process (system server) for BatteryNotifier |
| 738 | // (which requires a Java environment that may not be present). |
| 739 | // Hence, call clear() and updatePowerState() only from the |
| 740 | // ThreadBase thread. |
| 741 | void clear(); |
| 742 | // periodically called in the threadLoop() to update power state uids. |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 743 | void updatePowerState(const sp<ThreadBase>& thread, bool force = false); |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 744 | |
Kevin Rocard | c86a7f7 | 2018-04-03 09:00:09 -0700 | [diff] [blame] | 745 | /** @return true if one or move active tracks was added or removed since the |
Jasmine Cha | eaa10e4 | 2021-05-11 10:11:14 +0800 | [diff] [blame] | 746 | * last time this function was called or the vector was created. |
| 747 | * true if volume of one of active tracks was changed. |
| 748 | */ |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 749 | bool readAndClearHasChanged(); |
| 750 | |
Eric Laurent | dda206a | 2022-07-08 17:28:35 +0200 | [diff] [blame] | 751 | /** Force updating track metadata to audio HAL stream next time |
| 752 | * readAndClearHasChanged() is called. |
| 753 | */ |
| 754 | void setHasChanged() { mHasChanged = true; } |
| 755 | |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 756 | private: |
Andy Hung | 2c6c3bb | 2017-06-16 14:01:45 -0700 | [diff] [blame] | 757 | void logTrack(const char *funcName, const sp<T> &track) const; |
| 758 | |
Andy Hung | d01b0f1 | 2016-11-07 16:10:30 -0800 | [diff] [blame] | 759 | SortedVector<uid_t> getWakeLockUids() { |
| 760 | SortedVector<uid_t> wakeLockUids; |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 761 | for (const sp<T> &track : mActiveTracks) { |
| 762 | wakeLockUids.add(track->uid()); |
| 763 | } |
| 764 | return wakeLockUids; // moved by underlying SharedBuffer |
| 765 | } |
| 766 | |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 767 | SortedVector<sp<T>> mActiveTracks; |
| 768 | int mActiveTracksGeneration; |
| 769 | int mLastActiveTracksGeneration; |
| 770 | wp<T> mLatestActiveTrack; // latest track added to ActiveTracks |
Andy Hung | 2c6c3bb | 2017-06-16 14:01:45 -0700 | [diff] [blame] | 771 | SimpleLog * const mLocalLog; |
Kevin Rocard | c86a7f7 | 2018-04-03 09:00:09 -0700 | [diff] [blame] | 772 | // If the vector has changed since last call to readAndClearHasChanged |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 773 | bool mHasChanged = false; |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 774 | }; |
Andy Hung | 293558a | 2017-03-21 12:19:20 -0700 | [diff] [blame] | 775 | |
| 776 | SimpleLog mLocalLog; |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 777 | |
| 778 | private: |
| 779 | void dumpBase_l(int fd, const Vector<String16>& args); |
| 780 | void dumpEffectChains_l(int fd, const Vector<String16>& args); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 781 | }; |
| 782 | |
| 783 | // --- PlaybackThread --- |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 784 | class PlaybackThread : public ThreadBase, public virtual IAfPlaybackThread, |
| 785 | public StreamOutHalInterfaceCallback, |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 786 | public virtual VolumeInterface, public StreamOutHalInterfaceEventCallback { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 787 | public: |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 788 | sp<IAfPlaybackThread> asIAfPlaybackThread() final { |
| 789 | return sp<IAfPlaybackThread>::fromExisting(this); |
| 790 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 791 | |
Eric Laurent | e93cc03 | 2016-05-05 10:15:10 -0700 | [diff] [blame] | 792 | // retry count before removing active track in case of underrun on offloaded thread: |
| 793 | // we need to make sure that AudioTrack client has enough time to send large buffers |
| 794 | //FIXME may be more appropriate if expressed in time units. Need to revise how underrun is |
| 795 | // handled for offloaded tracks |
| 796 | static const int8_t kMaxTrackRetriesOffload = 20; |
| 797 | static const int8_t kMaxTrackStartupRetriesOffload = 100; |
Andy Hung | 8ed196a | 2018-01-05 13:21:11 -0800 | [diff] [blame] | 798 | static constexpr uint32_t kMaxTracksPerUid = 40; |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 799 | static constexpr size_t kMaxTracks = 256; |
Eric Laurent | e93cc03 | 2016-05-05 10:15:10 -0700 | [diff] [blame] | 800 | |
rago | 1bb9082 | 2017-05-02 18:31:48 -0700 | [diff] [blame] | 801 | // Maximum delay (in nanoseconds) for upcoming buffers in suspend mode, otherwise |
| 802 | // if delay is greater, the estimated time for timeLoopNextNs is reset. |
| 803 | // This allows for catch-up to be done for small delays, while resetting the estimate |
| 804 | // for initial conditions or large delays. |
| 805 | static const nsecs_t kMaxNextBufferDelayNs = 100000000; |
| 806 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 807 | PlaybackThread(const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 808 | audio_io_handle_t id, type_t type, bool systemReady, |
| 809 | audio_config_base_t *mixerConfig = nullptr); |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 810 | ~PlaybackThread() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 811 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 812 | // Thread virtuals |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 813 | bool threadLoop() final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 814 | |
| 815 | // RefBase |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 816 | void onFirstRef() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 817 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 818 | status_t checkEffectCompatibility_l( |
| 819 | const effect_descriptor_t* desc, audio_session_t sessionId) final; |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 820 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 821 | void addOutputTrack_l(const sp<IAfTrack>& track) final { |
| 822 | mTracks.add(track); |
| 823 | } |
| 824 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 825 | protected: |
| 826 | // Code snippets that were lifted up out of threadLoop() |
| 827 | virtual void threadLoop_mix() = 0; |
| 828 | virtual void threadLoop_sleepTime() = 0; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 829 | virtual ssize_t threadLoop_write(); |
| 830 | virtual void threadLoop_drain(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 831 | virtual void threadLoop_standby(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 832 | virtual void threadLoop_exit(); |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 833 | virtual void threadLoop_removeTracks(const Vector<sp<IAfTrack>>& tracksToRemove); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 834 | |
| 835 | // prepareTracks_l reads and writes mActiveTracks, and returns |
| 836 | // the pending set of tracks to remove via Vector 'tracksToRemove'. The caller |
| 837 | // is responsible for clearing or destroying this Vector later on, when it |
| 838 | // is safe to do so. That will drop the final ref count and destroy the tracks. |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 839 | virtual mixer_state prepareTracks_l(Vector<sp<IAfTrack>>* tracksToRemove) = 0; |
| 840 | void removeTracks_l(const Vector<sp<IAfTrack>>& tracksToRemove); |
Eric Laurent | eab9045 | 2019-06-24 15:17:46 -0700 | [diff] [blame] | 841 | status_t handleVoipVolume_l(float *volume); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 842 | |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 843 | // StreamOutHalInterfaceCallback implementation |
| 844 | virtual void onWriteReady(); |
| 845 | virtual void onDrainReady(); |
| 846 | virtual void onError(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 847 | |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 848 | public: // AsyncCallbackThread |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 849 | void resetWriteBlocked(uint32_t sequence); |
| 850 | void resetDraining(uint32_t sequence); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 851 | protected: |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 852 | |
| 853 | virtual bool waitingAsyncCallback(); |
| 854 | virtual bool waitingAsyncCallback_l(); |
| 855 | virtual bool shouldStandby_l(); |
Haynes Mathew George | 4c6a433 | 2014-01-15 12:31:39 -0800 | [diff] [blame] | 856 | virtual void onAddNewTrack_l(); |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 857 | public: // AsyncCallbackThread |
Haynes Mathew George | 4527b9e | 2016-07-07 19:54:17 -0700 | [diff] [blame] | 858 | void onAsyncError(); // error reported by AsyncCallbackThread |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 859 | protected: |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 860 | // StreamHalInterfaceCodecFormatCallback implementation |
| 861 | void onCodecFormatChanged( |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 862 | const std::basic_string<uint8_t>& metadataBs) final; |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 863 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 864 | // ThreadBase virtuals |
| 865 | virtual void preExit(); |
| 866 | |
Eric Laurent | 6466797 | 2016-03-30 18:19:46 -0700 | [diff] [blame] | 867 | virtual bool keepWakeLock() const { return true; } |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 868 | virtual void acquireWakeLock_l() { |
| 869 | ThreadBase::acquireWakeLock_l(); |
| 870 | mActiveTracks.updatePowerState(this, true /* force */); |
| 871 | } |
Eric Laurent | 6466797 | 2016-03-30 18:19:46 -0700 | [diff] [blame] | 872 | |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 873 | virtual void checkOutputStageEffects() {} |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 874 | virtual void setHalLatencyMode_l() {} |
| 875 | |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 876 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 877 | void dumpInternals_l(int fd, const Vector<String16>& args) override; |
| 878 | void dumpTracks_l(int fd, const Vector<String16>& args) final; |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 879 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 880 | public: |
| 881 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 882 | status_t initCheck() const final { return mOutput == nullptr ? NO_INIT : NO_ERROR; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 883 | |
| 884 | // return estimated latency in milliseconds, as reported by HAL |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 885 | uint32_t latency() const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 886 | // same, but lock must already be held |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 887 | uint32_t latency_l() const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 888 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 889 | // VolumeInterface |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 890 | void setMasterVolume(float value) final; |
| 891 | void setMasterBalance(float balance) override; |
| 892 | void setMasterMute(bool muted) final; |
| 893 | void setStreamVolume(audio_stream_type_t stream, float value) final; |
| 894 | void setStreamMute(audio_stream_type_t stream, bool muted) final; |
| 895 | float streamVolume(audio_stream_type_t stream) const final; |
| 896 | void setVolumeForOutput_l(float left, float right) const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 897 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 898 | sp<IAfTrack> createTrack_l( |
Andy Hung | 88035ac | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 899 | const sp<Client>& client, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 900 | audio_stream_type_t streamType, |
Kevin Rocard | 1f564ac | 2018-03-29 13:53:10 -0700 | [diff] [blame] | 901 | const audio_attributes_t& attr, |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 902 | uint32_t *sampleRate, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 903 | audio_format_t format, |
| 904 | audio_channel_mask_t channelMask, |
Glenn Kasten | 74935e4 | 2013-12-19 08:56:45 -0800 | [diff] [blame] | 905 | size_t *pFrameCount, |
Eric Laurent | 21da647 | 2017-11-09 16:29:26 -0800 | [diff] [blame] | 906 | size_t *pNotificationFrameCount, |
| 907 | uint32_t notificationsPerBuffer, |
| 908 | float speed, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 909 | const sp<IMemory>& sharedBuffer, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 910 | audio_session_t sessionId, |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 911 | audio_output_flags_t *flags, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 912 | pid_t creatorPid, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 913 | const AttributionSourceState& attributionSource, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 914 | pid_t tid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 915 | status_t *status /*non-NULL*/, |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 916 | audio_port_handle_t portId, |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 917 | const sp<media::IAudioTrackCallback>& callback, |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 918 | bool isSpatialized, |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 919 | bool isBitPerfect) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 920 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 921 | bool isTrackActive(const sp<IAfTrack>& track) const final { |
| 922 | return mActiveTracks.indexOf(track) >= 0; |
| 923 | } |
| 924 | |
| 925 | AudioStreamOut* getOutput_l() const final { return mOutput; } |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 926 | AudioStreamOut* getOutput() const final; |
| 927 | AudioStreamOut* clearOutput() final; |
| 928 | sp<StreamHalInterface> stream() const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 929 | |
| 930 | // a very large number of suspend() will eventually wraparound, but unlikely |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 931 | void suspend() final { (void) android_atomic_inc(&mSuspended); } |
| 932 | void restore() final |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 933 | { |
| 934 | // if restore() is done without suspend(), get back into |
| 935 | // range so that the next suspend() will operate correctly |
| 936 | if (android_atomic_dec(&mSuspended) <= 0) { |
| 937 | android_atomic_release_store(0, &mSuspended); |
| 938 | } |
| 939 | } |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 940 | bool isSuspended() const final |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 941 | { return android_atomic_acquire_load(&mSuspended) > 0; } |
| 942 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 943 | String8 getParameters(const String8& keys); |
| 944 | void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0, |
| 945 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) final; |
| 946 | status_t getRenderPosition(uint32_t* halFrames, uint32_t* dspFrames) const final; |
Andy Hung | 010a1a1 | 2014-03-13 13:57:33 -0700 | [diff] [blame] | 947 | // Consider also removing and passing an explicit mMainBuffer initialization |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 948 | // parameter to AF::IAfTrack::Track(). |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 949 | float* sinkBuffer() const final { |
Andy Hung | 319587b | 2023-05-23 14:01:03 -0700 | [diff] [blame] | 950 | return reinterpret_cast<float *>(mSinkBuffer); }; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 951 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 952 | void detachAuxEffect_l(int effectId) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 953 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 954 | status_t attachAuxEffect(const sp<IAfTrack>& track, int EffectId) final; |
| 955 | status_t attachAuxEffect_l(const sp<IAfTrack>& track, int EffectId) final; |
| 956 | |
| 957 | status_t addEffectChain_l(const sp<IAfEffectChain>& chain) final; |
| 958 | size_t removeEffectChain_l(const sp<IAfEffectChain>& chain) final; |
| 959 | uint32_t hasAudioSession_l(audio_session_t sessionId) const final { |
Andy Hung | c3d62f9 | 2019-03-14 13:38:51 -0700 | [diff] [blame] | 960 | return ThreadBase::hasAudioSession_l(sessionId, mTracks); |
| 961 | } |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 962 | product_strategy_t getStrategyForSession_l(audio_session_t sessionId) const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 963 | |
| 964 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 965 | status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) final; |
| 966 | bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const final; |
Glenn Kasten | fb1fdc9 | 2013-07-10 17:03:19 -0700 | [diff] [blame] | 967 | |
| 968 | // called with AudioFlinger lock held |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 969 | bool invalidateTracks_l(audio_stream_type_t streamType) final; |
| 970 | bool invalidateTracks_l(std::set<audio_port_handle_t>& portIds) final; |
| 971 | void invalidateTracks(audio_stream_type_t streamType) override; |
jiabin | c44b346 | 2022-12-08 12:52:31 -0800 | [diff] [blame] | 972 | // Invalidate tracks by a set of port ids. The port id will be removed from |
| 973 | // the given set if the corresponding track is found and invalidated. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 974 | void invalidateTracks(std::set<audio_port_handle_t>& portIds) override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 975 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 976 | size_t frameCount() const final { return mNormalFrameCount; } |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 977 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 978 | audio_channel_mask_t mixerChannelMask() const final { |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 979 | return mMixerChannelMask; |
| 980 | } |
| 981 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 982 | status_t getTimestamp_l(AudioTimestamp& timestamp) final; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 983 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 984 | void addPatchTrack(const sp<IAfPatchTrack>& track) final; |
| 985 | void deletePatchTrack(const sp<IAfPatchTrack>& track) final; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 986 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 987 | void toAudioPortConfig(struct audio_port_config* config) final; |
Eric Laurent | accc147 | 2013-09-20 09:36:34 -0700 | [diff] [blame] | 988 | |
Andy Hung | 10cbff1 | 2017-02-21 17:30:14 -0800 | [diff] [blame] | 989 | // Return the asynchronous signal wait time. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 990 | int64_t computeWaitTimeNs_l() const override { return INT64_MAX; } |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 991 | // returns true if the track is allowed to be added to the thread. |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 992 | bool isTrackAllowed_l( |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 993 | audio_channel_mask_t channelMask __unused, |
| 994 | audio_format_t format __unused, |
| 995 | audio_session_t sessionId __unused, |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 996 | uid_t uid) const override { |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 997 | return trackCountForUid_l(uid) < PlaybackThread::kMaxTracksPerUid |
| 998 | && mTracks.size() < PlaybackThread::kMaxTracks; |
| 999 | } |
| 1000 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1001 | bool isTimestampCorrectionEnabled() const final { |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 1002 | return audio_is_output_devices(mTimestampCorrectedDevice) |
| 1003 | && outDeviceTypes().count(mTimestampCorrectedDevice) != 0; |
Andy Hung | c8fddf3 | 2018-08-08 18:32:37 -0700 | [diff] [blame] | 1004 | } |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 1005 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1006 | bool isStreamInitialized() const final { |
Jasmine Cha | eaa10e4 | 2021-05-11 10:11:14 +0800 | [diff] [blame] | 1007 | return !(mOutput == nullptr || mOutput->stream == nullptr); |
| 1008 | } |
| 1009 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1010 | audio_channel_mask_t hapticChannelMask() const final { |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 1011 | return mHapticChannelMask; |
| 1012 | } |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1013 | |
| 1014 | uint32_t hapticChannelCount() const final { |
| 1015 | return mHapticChannelCount; |
| 1016 | } |
| 1017 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1018 | bool supportsHapticPlayback() const final { |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 1019 | return (mHapticChannelMask & AUDIO_CHANNEL_HAPTIC_ALL) != AUDIO_CHANNEL_NONE; |
| 1020 | } |
| 1021 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1022 | void setDownStreamPatch(const struct audio_patch* patch) final { |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 1023 | Mutex::Autolock _l(mLock); |
| 1024 | mDownStreamPatch = *patch; |
| 1025 | } |
| 1026 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1027 | IAfTrack* getTrackById_l(audio_port_handle_t trackId) final; |
jiabin | f042b9b | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 1028 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1029 | bool hasMixer() const final { |
Eric Laurent | 1c5e2e3 | 2021-08-18 18:50:28 +0200 | [diff] [blame] | 1030 | return mType == MIXER || mType == DUPLICATING || mType == SPATIALIZER; |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1031 | } |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1032 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1033 | status_t setRequestedLatencyMode( |
| 1034 | audio_latency_mode_t /* mode */) override { return INVALID_OPERATION; } |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1035 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1036 | status_t getSupportedLatencyModes( |
| 1037 | std::vector<audio_latency_mode_t>* /* modes */) override { |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1038 | return INVALID_OPERATION; |
| 1039 | } |
| 1040 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1041 | status_t setBluetoothVariableLatencyEnabled(bool /* enabled */) override{ |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1042 | return INVALID_OPERATION; |
| 1043 | } |
Eric Laurent | 5205764 | 2022-12-16 11:45:07 +0100 | [diff] [blame] | 1044 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1045 | void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor) override; |
| 1046 | void stopMelComputation_l() override; |
Vlad Popa | b042ee6 | 2022-10-20 18:05:00 +0200 | [diff] [blame] | 1047 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1048 | void setStandby() final { |
Eric Laurent | 19952e1 | 2023-04-20 10:08:29 +0200 | [diff] [blame] | 1049 | Mutex::Autolock _l(mLock); |
| 1050 | setStandby_l(); |
| 1051 | } |
| 1052 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1053 | void setStandby_l() final { |
Eric Laurent | 19952e1 | 2023-04-20 10:08:29 +0200 | [diff] [blame] | 1054 | mStandby = true; |
| 1055 | mHalStarted = false; |
| 1056 | mKernelPositionOnStandby = |
| 1057 | mTimestamp.mPosition[ExtendedTimestamp::LOCATION_KERNEL]; |
| 1058 | } |
| 1059 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1060 | bool waitForHalStart() final { |
Eric Laurent | 19952e1 | 2023-04-20 10:08:29 +0200 | [diff] [blame] | 1061 | Mutex::Autolock _l(mLock); |
| 1062 | static const nsecs_t kWaitHalTimeoutNs = seconds(2); |
| 1063 | nsecs_t endWaitTimetNs = systemTime() + kWaitHalTimeoutNs; |
| 1064 | while (!mHalStarted) { |
| 1065 | nsecs_t timeNs = systemTime(); |
| 1066 | if (timeNs >= endWaitTimetNs) { |
| 1067 | break; |
| 1068 | } |
| 1069 | nsecs_t waitTimeLeftNs = endWaitTimetNs - timeNs; |
| 1070 | mWaitHalStartCV.waitRelative(mLock, waitTimeLeftNs); |
| 1071 | } |
| 1072 | return mHalStarted; |
| 1073 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1074 | protected: |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 1075 | // updated by readOutputParameters_l() |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1076 | size_t mNormalFrameCount; // normal mixer and effects |
| 1077 | |
Andy Hung | 08fb174 | 2015-05-31 23:22:10 -0700 | [diff] [blame] | 1078 | bool mThreadThrottle; // throttle the thread processing |
Andy Hung | 40eb1a1 | 2015-06-18 13:42:02 -0700 | [diff] [blame] | 1079 | uint32_t mThreadThrottleTimeMs; // throttle time for MIXER threads |
| 1080 | uint32_t mThreadThrottleEndMs; // notify once per throttling |
Andy Hung | 08fb174 | 2015-05-31 23:22:10 -0700 | [diff] [blame] | 1081 | uint32_t mHalfBufferMs; // half the buffer size in milliseconds |
| 1082 | |
Andy Hung | 010a1a1 | 2014-03-13 13:57:33 -0700 | [diff] [blame] | 1083 | void* mSinkBuffer; // frame size aligned sink buffer |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1084 | |
Andy Hung | 98ef978 | 2014-03-04 14:46:50 -0800 | [diff] [blame] | 1085 | // TODO: |
| 1086 | // Rearrange the buffer info into a struct/class with |
| 1087 | // clear, copy, construction, destruction methods. |
| 1088 | // |
| 1089 | // mSinkBuffer also has associated with it: |
| 1090 | // |
| 1091 | // mSinkBufferSize: Sink Buffer Size |
| 1092 | // mFormat: Sink Buffer Format |
| 1093 | |
Andy Hung | 69aed5f | 2014-02-25 17:24:40 -0800 | [diff] [blame] | 1094 | // Mixer Buffer (mMixerBuffer*) |
| 1095 | // |
| 1096 | // In the case of floating point or multichannel data, which is not in the |
| 1097 | // sink format, it is required to accumulate in a higher precision or greater channel count |
| 1098 | // buffer before downmixing or data conversion to the sink buffer. |
| 1099 | |
| 1100 | // Set to "true" to enable the Mixer Buffer otherwise mixer output goes to sink buffer. |
| 1101 | bool mMixerBufferEnabled; |
| 1102 | |
| 1103 | // Storage, 32 byte aligned (may make this alignment a requirement later). |
| 1104 | // Due to constraints on mNormalFrameCount, the buffer size is a multiple of 16 frames. |
| 1105 | void* mMixerBuffer; |
| 1106 | |
| 1107 | // Size of mMixerBuffer in bytes: mNormalFrameCount * #channels * sampsize. |
| 1108 | size_t mMixerBufferSize; |
| 1109 | |
| 1110 | // The audio format of mMixerBuffer. Set to AUDIO_FORMAT_PCM_(FLOAT|16_BIT) only. |
| 1111 | audio_format_t mMixerBufferFormat; |
| 1112 | |
| 1113 | // An internal flag set to true by MixerThread::prepareTracks_l() |
| 1114 | // when mMixerBuffer contains valid data after mixing. |
| 1115 | bool mMixerBufferValid; |
| 1116 | |
Andy Hung | 98ef978 | 2014-03-04 14:46:50 -0800 | [diff] [blame] | 1117 | // Effects Buffer (mEffectsBuffer*) |
| 1118 | // |
| 1119 | // In the case of effects data, which is not in the sink format, |
| 1120 | // it is required to accumulate in a different buffer before data conversion |
| 1121 | // to the sink buffer. |
| 1122 | |
| 1123 | // Set to "true" to enable the Effects Buffer otherwise effects output goes to sink buffer. |
| 1124 | bool mEffectBufferEnabled; |
| 1125 | |
| 1126 | // Storage, 32 byte aligned (may make this alignment a requirement later). |
| 1127 | // Due to constraints on mNormalFrameCount, the buffer size is a multiple of 16 frames. |
| 1128 | void* mEffectBuffer; |
| 1129 | |
| 1130 | // Size of mEffectsBuffer in bytes: mNormalFrameCount * #channels * sampsize. |
| 1131 | size_t mEffectBufferSize; |
| 1132 | |
| 1133 | // The audio format of mEffectsBuffer. Set to AUDIO_FORMAT_PCM_16_BIT only. |
| 1134 | audio_format_t mEffectBufferFormat; |
| 1135 | |
| 1136 | // An internal flag set to true by MixerThread::prepareTracks_l() |
| 1137 | // when mEffectsBuffer contains valid data after mixing. |
| 1138 | // |
| 1139 | // When this is set, all mixer data is routed into the effects buffer |
| 1140 | // for any processing (including output processing). |
| 1141 | bool mEffectBufferValid; |
| 1142 | |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 1143 | // Set to "true" to enable when data has already copied to sink |
| 1144 | bool mHasDataCopiedToSinkBuffer = false; |
| 1145 | |
Eric Laurent | b62d036 | 2021-10-26 17:40:18 +0200 | [diff] [blame] | 1146 | // Frame size aligned buffer used as input and output to all post processing effects |
| 1147 | // except the Spatializer in a SPATIALIZER thread. Non spatialized tracks are mixed into |
| 1148 | // this buffer so that post processing effects can be applied. |
| 1149 | void* mPostSpatializerBuffer = nullptr; |
| 1150 | |
| 1151 | // Size of mPostSpatializerBuffer in bytes |
| 1152 | size_t mPostSpatializerBufferSize; |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 1153 | |
| 1154 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1155 | // suspend count, > 0 means suspended. While suspended, the thread continues to pull from |
| 1156 | // tracks and mix, but doesn't write to HAL. A2DP and SCO HAL implementations can't handle |
| 1157 | // concurrent use of both of them, so Audio Policy Service suspends one of the threads to |
| 1158 | // workaround that restriction. |
| 1159 | // 'volatile' means accessed via atomic operations and no lock. |
| 1160 | volatile int32_t mSuspended; |
| 1161 | |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 1162 | int64_t mBytesWritten; |
yucliu | 6cfb593 | 2022-07-20 17:40:39 -0700 | [diff] [blame] | 1163 | std::atomic<int64_t> mFramesWritten; // not reset on standby |
Dean Wheatley | 12473e9 | 2021-03-18 23:00:55 +1100 | [diff] [blame] | 1164 | int64_t mLastFramesWritten = -1; // track changes in timestamp |
| 1165 | // server frames written. |
Andy Hung | 238fa3d | 2016-07-28 10:53:22 -0700 | [diff] [blame] | 1166 | int64_t mSuspendedFrames; // not reset on standby |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 1167 | |
| 1168 | // mHapticChannelMask and mHapticChannelCount will only be valid when the thread support |
| 1169 | // haptic playback. |
| 1170 | audio_channel_mask_t mHapticChannelMask = AUDIO_CHANNEL_NONE; |
| 1171 | uint32_t mHapticChannelCount = 0; |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 1172 | |
| 1173 | audio_channel_mask_t mMixerChannelMask = AUDIO_CHANNEL_NONE; |
| 1174 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1175 | // mMasterMute is in both PlaybackThread and in AudioFlinger. When a |
| 1176 | // PlaybackThread needs to find out if master-muted, it checks it's local |
| 1177 | // copy rather than the one in AudioFlinger. This optimization saves a lock. |
| 1178 | bool mMasterMute; |
| 1179 | void setMasterMute_l(bool muted) { mMasterMute = muted; } |
Dean Wheatley | 12473e9 | 2021-03-18 23:00:55 +1100 | [diff] [blame] | 1180 | |
| 1181 | auto discontinuityForStandbyOrFlush() const { // call on threadLoop or with lock. |
| 1182 | return ((mType == DIRECT && !audio_is_linear_pcm(mFormat)) |
| 1183 | || mType == OFFLOAD) |
| 1184 | ? mTimestampVerifier.DISCONTINUITY_MODE_ZERO |
| 1185 | : mTimestampVerifier.DISCONTINUITY_MODE_CONTINUOUS; |
| 1186 | } |
| 1187 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1188 | ActiveTracks<IAfTrack> mActiveTracks; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1189 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1190 | // Time to sleep between cycles when: |
| 1191 | virtual uint32_t activeSleepTimeUs() const; // mixer state MIXER_TRACKS_ENABLED |
| 1192 | virtual uint32_t idleSleepTimeUs() const = 0; // mixer state MIXER_IDLE |
| 1193 | virtual uint32_t suspendSleepTimeUs() const = 0; // audio policy manager suspended us |
| 1194 | // No sleep when mixer state == MIXER_TRACKS_READY; relies on audio HAL stream->write() |
| 1195 | // No sleep in standby mode; waits on a condition |
| 1196 | |
| 1197 | // Code snippets that are temporarily lifted up out of threadLoop() until the merge |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1198 | virtual void checkSilentMode_l() final; // consider unification with MMapThread |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1199 | |
| 1200 | // Non-trivial for DUPLICATING only |
| 1201 | virtual void saveOutputTracks() { } |
| 1202 | virtual void clearOutputTracks() { } |
| 1203 | |
| 1204 | // Cache various calculated values, at threadLoop() entry and after a parameter change |
| 1205 | virtual void cacheParameters_l(); |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1206 | void setCheckOutputStageEffects() override { |
| 1207 | mCheckOutputStageEffects.store(true); |
| 1208 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1209 | |
| 1210 | virtual uint32_t correctLatency_l(uint32_t latency) const; |
| 1211 | |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1212 | virtual status_t createAudioPatch_l(const struct audio_patch *patch, |
| 1213 | audio_patch_handle_t *handle); |
| 1214 | virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle); |
| 1215 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1216 | bool usesHwAvSync() const final { return mType == DIRECT && mOutput != nullptr |
Phil Burk | 6fc2a7c | 2015-04-30 16:08:10 -0700 | [diff] [blame] | 1217 | && mHwSupportsPause |
| 1218 | && (mOutput->flags & AUDIO_OUTPUT_FLAG_HW_AV_SYNC); } |
Eric Laurent | 0f7b5f2 | 2014-12-19 10:43:21 -0800 | [diff] [blame] | 1219 | |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1220 | uint32_t trackCountForUid_l(uid_t uid) const; |
Eric Laurent | ad7dd96 | 2016-09-22 12:38:37 -0700 | [diff] [blame] | 1221 | |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 1222 | void invalidateTracksForAudioSession_l( |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1223 | audio_session_t sessionId) const override { |
jiabin | eb3bda0 | 2020-06-30 14:07:03 -0700 | [diff] [blame] | 1224 | ThreadBase::invalidateTracksForAudioSession_l(sessionId, mTracks); |
| 1225 | } |
| 1226 | |
Mikhail Naganov | bf49308 | 2017-04-17 17:37:12 -0700 | [diff] [blame] | 1227 | DISALLOW_COPY_AND_ASSIGN(PlaybackThread); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1228 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1229 | status_t addTrack_l(const sp<IAfTrack>& track) final; |
| 1230 | bool destroyTrack_l(const sp<IAfTrack>& track) final; |
| 1231 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1232 | void removeTrack_l(const sp<IAfTrack>& track); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1233 | |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 1234 | void readOutputParameters_l(); |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 1235 | MetadataUpdate updateMetadata_l() final; |
Kevin Rocard | c86a7f7 | 2018-04-03 09:00:09 -0700 | [diff] [blame] | 1236 | virtual void sendMetadataToBackend_l(const StreamOutHalInterface::SourceMetadata& metadata); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1237 | |
Dean Wheatley | 12473e9 | 2021-03-18 23:00:55 +1100 | [diff] [blame] | 1238 | void collectTimestamps_l(); |
| 1239 | |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1240 | // The Tracks class manages tracks added and removed from the Thread. |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1241 | template <typename T> |
| 1242 | class Tracks { |
| 1243 | public: |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 1244 | explicit Tracks(bool saveDeletedTrackIds) : |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1245 | mSaveDeletedTrackIds(saveDeletedTrackIds) { } |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1246 | |
| 1247 | // SortedVector methods |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1248 | ssize_t add(const sp<T> &track) { |
| 1249 | const ssize_t index = mTracks.add(track); |
| 1250 | LOG_ALWAYS_FATAL_IF(index < 0, "cannot add track"); |
| 1251 | return index; |
| 1252 | } |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1253 | ssize_t remove(const sp<T> &track); |
| 1254 | size_t size() const { |
| 1255 | return mTracks.size(); |
| 1256 | } |
| 1257 | bool isEmpty() const { |
| 1258 | return mTracks.isEmpty(); |
| 1259 | } |
| 1260 | ssize_t indexOf(const sp<T> &item) { |
| 1261 | return mTracks.indexOf(item); |
| 1262 | } |
| 1263 | sp<T> operator[](size_t index) const { |
| 1264 | return mTracks[index]; |
| 1265 | } |
| 1266 | typename SortedVector<sp<T>>::iterator begin() { |
| 1267 | return mTracks.begin(); |
| 1268 | } |
| 1269 | typename SortedVector<sp<T>>::iterator end() { |
| 1270 | return mTracks.end(); |
| 1271 | } |
| 1272 | |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 1273 | size_t processDeletedTrackIds(const std::function<void(int)>& f) { |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1274 | for (const int trackId : mDeletedTrackIds) { |
| 1275 | f(trackId); |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1276 | } |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1277 | return mDeletedTrackIds.size(); |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1278 | } |
| 1279 | |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1280 | void clearDeletedTrackIds() { mDeletedTrackIds.clear(); } |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1281 | |
| 1282 | private: |
Andy Hung | c069138 | 2018-09-12 18:01:57 -0700 | [diff] [blame] | 1283 | // Tracks pending deletion for MIXER type threads |
| 1284 | const bool mSaveDeletedTrackIds; // true to enable tracking |
| 1285 | std::set<int> mDeletedTrackIds; |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1286 | |
| 1287 | SortedVector<sp<T>> mTracks; // wrapped SortedVector. |
| 1288 | }; |
| 1289 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1290 | Tracks<IAfTrack> mTracks; |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1291 | |
Eric Laurent | 223fd5c | 2014-11-11 13:43:36 -0800 | [diff] [blame] | 1292 | stream_type_t mStreamTypes[AUDIO_STREAM_CNT]; |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 1293 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1294 | AudioStreamOut *mOutput; |
| 1295 | |
| 1296 | float mMasterVolume; |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1297 | std::atomic<float> mMasterBalance{}; |
| 1298 | audio_utils::Balance mBalance; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1299 | int mNumWrites; |
| 1300 | int mNumDelayedWrites; |
| 1301 | bool mInWrite; |
| 1302 | |
| 1303 | // FIXME rename these former local variables of threadLoop to standard "m" names |
Eric Laurent | ad9cb8b | 2015-05-26 16:38:19 -0700 | [diff] [blame] | 1304 | nsecs_t mStandbyTimeNs; |
Andy Hung | 25c2dac | 2014-02-27 14:56:00 -0800 | [diff] [blame] | 1305 | size_t mSinkBufferSize; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1306 | |
| 1307 | // cached copies of activeSleepTimeUs() and idleSleepTimeUs() made by cacheParameters_l() |
Eric Laurent | ad9cb8b | 2015-05-26 16:38:19 -0700 | [diff] [blame] | 1308 | uint32_t mActiveSleepTimeUs; |
| 1309 | uint32_t mIdleSleepTimeUs; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1310 | |
Eric Laurent | ad9cb8b | 2015-05-26 16:38:19 -0700 | [diff] [blame] | 1311 | uint32_t mSleepTimeUs; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1312 | |
| 1313 | // mixer status returned by prepareTracks_l() |
| 1314 | mixer_state mMixerStatus; // current cycle |
| 1315 | // previous cycle when in prepareTracks_l() |
| 1316 | mixer_state mMixerStatusIgnoringFastTracks; |
| 1317 | // FIXME or a separate ready state per track |
| 1318 | |
| 1319 | // FIXME move these declarations into the specific sub-class that needs them |
| 1320 | // MIXER only |
| 1321 | uint32_t sleepTimeShift; |
| 1322 | |
| 1323 | // same as AudioFlinger::mStandbyTimeInNsecs except for DIRECT which uses a shorter value |
Eric Laurent | ad9cb8b | 2015-05-26 16:38:19 -0700 | [diff] [blame] | 1324 | nsecs_t mStandbyDelayNs; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1325 | |
| 1326 | // MIXER only |
| 1327 | nsecs_t maxPeriod; |
| 1328 | |
| 1329 | // DUPLICATING only |
| 1330 | uint32_t writeFrames; |
| 1331 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1332 | size_t mBytesRemaining; |
| 1333 | size_t mCurrentWriteLength; |
| 1334 | bool mUseAsyncWrite; |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 1335 | // mWriteAckSequence contains current write sequence on bits 31-1. The write sequence is |
| 1336 | // incremented each time a write(), a flush() or a standby() occurs. |
| 1337 | // Bit 0 is set when a write blocks and indicates a callback is expected. |
| 1338 | // Bit 0 is reset by the async callback thread calling resetWriteBlocked(). Out of sequence |
| 1339 | // callbacks are ignored. |
| 1340 | uint32_t mWriteAckSequence; |
| 1341 | // mDrainSequence contains current drain sequence on bits 31-1. The drain sequence is |
| 1342 | // incremented each time a drain is requested or a flush() or standby() occurs. |
| 1343 | // Bit 0 is set when the drain() command is called at the HAL and indicates a callback is |
| 1344 | // expected. |
| 1345 | // Bit 0 is reset by the async callback thread calling resetDraining(). Out of sequence |
| 1346 | // callbacks are ignored. |
| 1347 | uint32_t mDrainSequence; |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 1348 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1349 | sp<AsyncCallbackThread> mCallbackThread; |
| 1350 | |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 1351 | Mutex mAudioTrackCbLock; |
| 1352 | // Record of IAudioTrackCallback |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1353 | std::map<sp<IAfTrack>, sp<media::IAudioTrackCallback>> mAudioTrackCallbacks; |
jiabin | f6eb4c3 | 2020-02-25 14:06:25 -0800 | [diff] [blame] | 1354 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1355 | // The HAL output sink is treated as non-blocking, but current implementation is blocking |
| 1356 | sp<NBAIO_Sink> mOutputSink; |
| 1357 | // If a fast mixer is present, the blocking pipe sink, otherwise clear |
| 1358 | sp<NBAIO_Sink> mPipeSink; |
| 1359 | // The current sink for the normal mixer to write it's (sub)mix, mOutputSink or mPipeSink |
| 1360 | sp<NBAIO_Sink> mNormalSink; |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 1361 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1362 | uint32_t mScreenState; // cached copy of gScreenState |
Sanna Catherine de Treville Wager | 2a6a945 | 2017-07-28 11:02:01 -0700 | [diff] [blame] | 1363 | // TODO: add comment and adjust size as needed |
Glenn Kasten | eef598c | 2017-04-03 14:41:13 -0700 | [diff] [blame] | 1364 | static const size_t kFastMixerLogSize = 8 * 1024; |
Glenn Kasten | 9e58b55 | 2013-01-18 15:09:48 -0800 | [diff] [blame] | 1365 | sp<NBLog::Writer> mFastMixerNBLogWriter; |
Andy Hung | 2148bf0 | 2016-11-28 19:01:02 -0800 | [diff] [blame] | 1366 | |
Dean Wheatley | 30d2842 | 2018-11-06 10:27:40 +1100 | [diff] [blame] | 1367 | // Downstream patch latency, available if mDownstreamLatencyStatMs.getN() > 0. |
| 1368 | audio_utils::Statistics<double> mDownstreamLatencyStatMs{0.999}; |
Andy Hung | 2148bf0 | 2016-11-28 19:01:02 -0800 | [diff] [blame] | 1369 | |
Eric Laurent | 19952e1 | 2023-04-20 10:08:29 +0200 | [diff] [blame] | 1370 | // output stream start detection based on render position returned by the kernel |
| 1371 | // condition signalled when the output stream has started |
| 1372 | Condition mWaitHalStartCV; |
| 1373 | // true when the output stream render position has moved, reset to false in standby |
| 1374 | bool mHalStarted = false; |
| 1375 | // last kernel render position saved when entering standby |
| 1376 | int64_t mKernelPositionOnStandby = 0; |
| 1377 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1378 | public: |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1379 | FastTrackUnderruns getFastTrackUnderruns(size_t /* fastIndex */) const override |
| 1380 | { return {}; } |
| 1381 | const std::atomic<int64_t>& framesWritten() const final { return mFramesWritten; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1382 | |
| 1383 | protected: |
| 1384 | // accessed by both binder threads and within threadLoop(), lock on mutex needed |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1385 | uint32_t& fastTrackAvailMask_l() final { return mFastTrackAvailMask; } |
| 1386 | uint32_t mFastTrackAvailMask; // bit i set if fast track [i] is available |
Eric Laurent | d1f69b0 | 2014-12-15 14:33:13 -0800 | [diff] [blame] | 1387 | bool mHwSupportsPause; |
| 1388 | bool mHwPaused; |
| 1389 | bool mFlushPending; |
Eric Laurent | 7c29ec9 | 2017-09-20 17:54:22 -0700 | [diff] [blame] | 1390 | // volumes last sent to audio HAL with stream->setVolume() |
| 1391 | float mLeftVolFloat; |
| 1392 | float mRightVolFloat; |
Eric Laurent | 74c38dc | 2020-12-23 18:19:44 +0100 | [diff] [blame] | 1393 | |
| 1394 | // audio patch used by the downstream software patch. |
| 1395 | // Only used if ThreadBase::mIsMsdDevice is true. |
| 1396 | struct audio_patch mDownStreamPatch; |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1397 | |
| 1398 | std::atomic_bool mCheckOutputStageEffects{}; |
ziyangch | 8f194f1 | 2021-12-01 13:48:04 -0800 | [diff] [blame] | 1399 | |
ziyangch | 8f194f1 | 2021-12-01 13:48:04 -0800 | [diff] [blame] | 1400 | |
Brian Lindahl | 65e9001 | 2022-07-27 18:01:07 +0200 | [diff] [blame] | 1401 | // Provides periodic checking for timestamp advancement for underrun detection. |
| 1402 | class IsTimestampAdvancing { |
| 1403 | public: |
| 1404 | // The timestamp will not be checked any faster than the specified time. |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 1405 | explicit IsTimestampAdvancing(nsecs_t minimumTimeBetweenChecksNs) |
Brian Lindahl | 65e9001 | 2022-07-27 18:01:07 +0200 | [diff] [blame] | 1406 | : mMinimumTimeBetweenChecksNs(minimumTimeBetweenChecksNs) |
| 1407 | { |
| 1408 | clear(); |
| 1409 | } |
| 1410 | // Check if the presentation position has advanced in the last periodic time. |
| 1411 | bool check(AudioStreamOut * output); |
| 1412 | // Clear the internal state when the playback state changes for the output |
| 1413 | // stream. |
| 1414 | void clear(); |
| 1415 | private: |
| 1416 | // The minimum time between timestamp checks. |
| 1417 | const nsecs_t mMinimumTimeBetweenChecksNs; |
| 1418 | // Add differential check on the timestamps to see if there is a change in the |
| 1419 | // timestamp frame position between the last call to check. |
| 1420 | uint64_t mPreviousPosition; |
| 1421 | // The time at which the last check occurred, to ensure we don't check too |
| 1422 | // frequently, giving the Audio HAL enough time to update its timestamps. |
| 1423 | nsecs_t mPreviousNs; |
| 1424 | // The valued is latched so we don't check timestamps too frequently. |
| 1425 | bool mLatchedValue; |
| 1426 | }; |
| 1427 | IsTimestampAdvancing mIsTimestampAdvancing; |
ziyangch | 8f194f1 | 2021-12-01 13:48:04 -0800 | [diff] [blame] | 1428 | |
Brian Lindahl | 65e9001 | 2022-07-27 18:01:07 +0200 | [diff] [blame] | 1429 | virtual void flushHw_l() { |
| 1430 | mIsTimestampAdvancing.clear(); |
| 1431 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1432 | }; |
| 1433 | |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1434 | class MixerThread : public PlaybackThread, |
| 1435 | public StreamOutHalInterfaceLatencyModeCallback { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1436 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1437 | MixerThread(const sp<IAfThreadCallback>& afThreadCallback, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1438 | AudioStreamOut* output, |
| 1439 | audio_io_handle_t id, |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 1440 | bool systemReady, |
Eric Laurent | f1f22e7 | 2021-07-13 14:04:14 +0200 | [diff] [blame] | 1441 | type_t type = MIXER, |
| 1442 | audio_config_base_t *mixerConfig = nullptr); |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1443 | ~MixerThread() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1444 | |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1445 | // RefBase |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1446 | void onFirstRef() override; |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1447 | |
| 1448 | // StreamOutHalInterfaceLatencyModeCallback |
| 1449 | void onRecommendedLatencyModeChanged( |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1450 | std::vector<audio_latency_mode_t> modes) final; |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1451 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1452 | // Thread virtuals |
| 1453 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1454 | bool checkForNewParameter_l(const String8& keyValuePair, status_t& status) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1455 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1456 | bool isTrackAllowed_l( |
Andy Hung | 1bc088a | 2018-02-09 15:57:31 -0800 | [diff] [blame] | 1457 | audio_channel_mask_t channelMask, audio_format_t format, |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1458 | audio_session_t sessionId, uid_t uid) const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1459 | protected: |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1460 | mixer_state prepareTracks_l(Vector<sp<IAfTrack>>* tracksToRemove) override; |
| 1461 | uint32_t idleSleepTimeUs() const final; |
| 1462 | uint32_t suspendSleepTimeUs() const final; |
| 1463 | void cacheParameters_l() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1464 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1465 | void acquireWakeLock_l() final { |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 1466 | PlaybackThread::acquireWakeLock_l(); |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 1467 | if (hasFastMixer()) { |
| 1468 | mFastMixer->setBoottimeOffset( |
| 1469 | mTimestamp.mTimebaseOffset[ExtendedTimestamp::TIMEBASE_BOOTTIME]); |
| 1470 | } |
| 1471 | } |
| 1472 | |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 1473 | void dumpInternals_l(int fd, const Vector<String16>& args) override; |
| 1474 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1475 | // threadLoop snippets |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1476 | ssize_t threadLoop_write() override; |
| 1477 | void threadLoop_standby() override; |
| 1478 | void threadLoop_mix() override; |
| 1479 | void threadLoop_sleepTime() override; |
| 1480 | uint32_t correctLatency_l(uint32_t latency) const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1481 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1482 | status_t createAudioPatch_l( |
| 1483 | const struct audio_patch* patch, audio_patch_handle_t* handle) final; |
| 1484 | status_t releaseAudioPatch_l(const audio_patch_handle_t handle) final; |
Eric Laurent | 054d9d3 | 2015-04-24 08:48:48 -0700 | [diff] [blame] | 1485 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1486 | AudioMixer* mAudioMixer; // normal mixer |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1487 | |
| 1488 | // Support low latency mode by default as unless explicitly indicated by the audio HAL |
| 1489 | // we assume the audio path is compatible with the head tracking latency requirements |
| 1490 | std::vector<audio_latency_mode_t> mSupportedLatencyModes = {AUDIO_LATENCY_MODE_LOW}; |
| 1491 | // default to invalid value to force first update to the audio HAL |
| 1492 | audio_latency_mode_t mSetLatencyMode = |
| 1493 | (audio_latency_mode_t)AUDIO_LATENCY_MODE_INVALID; |
| 1494 | |
| 1495 | // Bluetooth Variable latency control logic is enabled or disabled for this thread |
| 1496 | std::atomic_bool mBluetoothLatencyModesEnabled; |
| 1497 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1498 | private: |
| 1499 | // one-time initialization, no locks required |
Glenn Kasten | 4d23ca3 | 2014-05-13 10:39:51 -0700 | [diff] [blame] | 1500 | sp<FastMixer> mFastMixer; // non-0 if there is also a fast mixer |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1501 | sp<AudioWatchdog> mAudioWatchdog; // non-0 if there is an audio watchdog thread |
| 1502 | |
| 1503 | // contents are not guaranteed to be consistent, no locks required |
| 1504 | FastMixerDumpState mFastMixerDumpState; |
| 1505 | #ifdef STATE_QUEUE_DUMP |
| 1506 | StateQueueObserverDump mStateQueueObserverDump; |
| 1507 | StateQueueMutatorDump mStateQueueMutatorDump; |
| 1508 | #endif |
| 1509 | AudioWatchdogDump mAudioWatchdogDump; |
| 1510 | |
| 1511 | // accessible only within the threadLoop(), no locks required |
| 1512 | // mFastMixer->sq() // for mutating and pushing state |
| 1513 | int32_t mFastMixerFutex; // for cold idle |
| 1514 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1515 | std::atomic_bool mMasterMono; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1516 | public: |
Glenn Kasten | 4d23ca3 | 2014-05-13 10:39:51 -0700 | [diff] [blame] | 1517 | virtual bool hasFastMixer() const { return mFastMixer != 0; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1518 | virtual FastTrackUnderruns getFastTrackUnderruns(size_t fastIndex) const { |
Glenn Kasten | dc2c50b | 2016-04-21 08:13:14 -0700 | [diff] [blame] | 1519 | ALOG_ASSERT(fastIndex < FastMixerState::sMaxFastTracks); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1520 | return mFastMixerDumpState.mTracks[fastIndex].mUnderruns; |
| 1521 | } |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 1522 | |
Andy Hung | 1c86ebe | 2018-05-29 20:29:08 -0700 | [diff] [blame] | 1523 | status_t threadloop_getHalTimestamp_l( |
| 1524 | ExtendedTimestamp *timestamp) const override { |
| 1525 | if (mNormalSink.get() != nullptr) { |
| 1526 | return mNormalSink->getTimestamp(*timestamp); |
| 1527 | } |
| 1528 | return INVALID_OPERATION; |
| 1529 | } |
| 1530 | |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1531 | status_t getSupportedLatencyModes( |
| 1532 | std::vector<audio_latency_mode_t>* modes) override; |
| 1533 | |
| 1534 | status_t setBluetoothVariableLatencyEnabled(bool enabled) override; |
| 1535 | |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1536 | protected: |
| 1537 | virtual void setMasterMono_l(bool mono) { |
| 1538 | mMasterMono.store(mono); |
| 1539 | if (mFastMixer != nullptr) { /* hasFastMixer() */ |
| 1540 | mFastMixer->setMasterMono(mMasterMono); |
| 1541 | } |
| 1542 | } |
| 1543 | // the FastMixer performs mono blend if it exists. |
Glenn Kasten | 03c48d5 | 2016-01-27 17:25:17 -0800 | [diff] [blame] | 1544 | // Blending with limiter is not idempotent, |
| 1545 | // and blending without limiter is idempotent but inefficient to do twice. |
Andy Hung | 2ddee19 | 2015-12-18 17:34:44 -0800 | [diff] [blame] | 1546 | virtual bool requireMonoBlend() { return mMasterMono.load() && !hasFastMixer(); } |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1547 | |
| 1548 | void setMasterBalance(float balance) override { |
| 1549 | mMasterBalance.store(balance); |
| 1550 | if (hasFastMixer()) { |
| 1551 | mFastMixer->setMasterBalance(balance); |
| 1552 | } |
| 1553 | } |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1554 | |
| 1555 | void updateHalSupportedLatencyModes_l(); |
| 1556 | void onHalLatencyModesChanged_l() override; |
| 1557 | void setHalLatencyMode_l() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1558 | }; |
| 1559 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1560 | class DirectOutputThread : public PlaybackThread, public virtual IAfDirectOutputThread { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1561 | public: |
| 1562 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1563 | sp<IAfDirectOutputThread> asIAfDirectOutputThread() final { |
| 1564 | return sp<IAfDirectOutputThread>::fromExisting(this); |
| 1565 | } |
| 1566 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1567 | DirectOutputThread(const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
Gareth Fenn | b18c1a3 | 2022-10-05 13:42:36 -0700 | [diff] [blame] | 1568 | audio_io_handle_t id, bool systemReady, |
| 1569 | const audio_offload_info_t& offloadInfo) |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1570 | : DirectOutputThread(afThreadCallback, output, id, DIRECT, systemReady, offloadInfo) { } |
Andy Hung | 48f59ed | 2019-01-28 15:06:59 -0800 | [diff] [blame] | 1571 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1572 | virtual ~DirectOutputThread(); |
| 1573 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1574 | status_t selectPresentation(int presentationId, int programId) final; |
Mikhail Naganov | ac917ac | 2018-11-28 14:03:52 -0800 | [diff] [blame] | 1575 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1576 | // Thread virtuals |
| 1577 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 1578 | virtual bool checkForNewParameter_l(const String8& keyValuePair, |
| 1579 | status_t& status); |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1580 | |
ziyangch | 8f194f1 | 2021-12-01 13:48:04 -0800 | [diff] [blame] | 1581 | void flushHw_l() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1582 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1583 | void setMasterBalance(float balance) override; |
| 1584 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1585 | protected: |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1586 | virtual uint32_t activeSleepTimeUs() const; |
| 1587 | virtual uint32_t idleSleepTimeUs() const; |
| 1588 | virtual uint32_t suspendSleepTimeUs() const; |
| 1589 | virtual void cacheParameters_l(); |
| 1590 | |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 1591 | void dumpInternals_l(int fd, const Vector<String16>& args) override; |
| 1592 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1593 | // threadLoop snippets |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1594 | virtual mixer_state prepareTracks_l(Vector<sp<IAfTrack>>* tracksToRemove); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1595 | virtual void threadLoop_mix(); |
| 1596 | virtual void threadLoop_sleepTime(); |
Eric Laurent | d1f69b0 | 2014-12-15 14:33:13 -0800 | [diff] [blame] | 1597 | virtual void threadLoop_exit(); |
| 1598 | virtual bool shouldStandby_l(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1599 | |
Phil Burk | 43b4dcc | 2015-06-09 16:53:44 -0700 | [diff] [blame] | 1600 | virtual void onAddNewTrack_l(); |
| 1601 | |
Gareth Fenn | b18c1a3 | 2022-10-05 13:42:36 -0700 | [diff] [blame] | 1602 | const audio_offload_info_t mOffloadInfo; |
Andy Hung | 398ffa2 | 2022-12-13 19:19:53 -0800 | [diff] [blame] | 1603 | |
| 1604 | audioflinger::MonotonicFrameCounter mMonotonicFrameCounter; // for VolumeShaper |
Andy Hung | 48f59ed | 2019-01-28 15:06:59 -0800 | [diff] [blame] | 1605 | bool mVolumeShaperActive = false; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1606 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1607 | DirectOutputThread(const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
Gareth Fenn | b18c1a3 | 2022-10-05 13:42:36 -0700 | [diff] [blame] | 1608 | audio_io_handle_t id, ThreadBase::type_t type, bool systemReady, |
| 1609 | const audio_offload_info_t& offloadInfo); |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1610 | void processVolume_l(IAfTrack *track, bool lastTrack); |
Gareth Fenn | b18c1a3 | 2022-10-05 13:42:36 -0700 | [diff] [blame] | 1611 | bool isTunerStream() const { return (mOffloadInfo.content_id > 0); } |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1612 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1613 | // prepareTracks_l() tells threadLoop_mix() the name of the single active track |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1614 | sp<IAfTrack> mActiveTrack; |
Phil Burk | 43b4dcc | 2015-06-09 16:53:44 -0700 | [diff] [blame] | 1615 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1616 | wp<IAfTrack> mPreviousTrack; // used to detect track switch |
Phil Burk | 43b4dcc | 2015-06-09 16:53:44 -0700 | [diff] [blame] | 1617 | |
Richard Folke Tullberg | 3fae037 | 2017-01-13 09:04:25 +0100 | [diff] [blame] | 1618 | // This must be initialized for initial condition of mMasterBalance = 0 (disabled). |
| 1619 | float mMasterBalanceLeft = 1.f; |
| 1620 | float mMasterBalanceRight = 1.f; |
| 1621 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1622 | public: |
| 1623 | virtual bool hasFastMixer() const { return false; } |
Andy Hung | 10cbff1 | 2017-02-21 17:30:14 -0800 | [diff] [blame] | 1624 | |
| 1625 | virtual int64_t computeWaitTimeNs_l() const override; |
Andy Hung | f323451 | 2018-07-03 14:51:47 -0700 | [diff] [blame] | 1626 | |
| 1627 | status_t threadloop_getHalTimestamp_l(ExtendedTimestamp *timestamp) const override { |
| 1628 | // For DIRECT and OFFLOAD threads, query the output sink directly. |
| 1629 | if (mOutput != nullptr) { |
| 1630 | uint64_t uposition64; |
| 1631 | struct timespec time; |
| 1632 | if (mOutput->getPresentationPosition( |
| 1633 | &uposition64, &time) == OK) { |
| 1634 | timestamp->mPosition[ExtendedTimestamp::LOCATION_KERNEL] |
| 1635 | = (int64_t)uposition64; |
| 1636 | timestamp->mTimeNs[ExtendedTimestamp::LOCATION_KERNEL] |
| 1637 | = audio_utils_ns_from_timespec(&time); |
| 1638 | return NO_ERROR; |
| 1639 | } |
| 1640 | } |
| 1641 | return INVALID_OPERATION; |
| 1642 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1643 | }; |
| 1644 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1645 | class OffloadThread : public DirectOutputThread { |
| 1646 | public: |
| 1647 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1648 | OffloadThread(const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut* output, |
Gareth Fenn | b18c1a3 | 2022-10-05 13:42:36 -0700 | [diff] [blame] | 1649 | audio_io_handle_t id, bool systemReady, |
| 1650 | const audio_offload_info_t& offloadInfo); |
Eric Laurent | 6a51d7e | 2013-10-17 18:59:26 -0700 | [diff] [blame] | 1651 | virtual ~OffloadThread() {}; |
ziyangch | 8f194f1 | 2021-12-01 13:48:04 -0800 | [diff] [blame] | 1652 | void flushHw_l() override; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1653 | |
| 1654 | protected: |
| 1655 | // threadLoop snippets |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1656 | virtual mixer_state prepareTracks_l(Vector<sp<IAfTrack>>* tracksToRemove); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1657 | virtual void threadLoop_exit(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1658 | |
| 1659 | virtual bool waitingAsyncCallback(); |
| 1660 | virtual bool waitingAsyncCallback_l(); |
Haynes Mathew George | 05317d2 | 2016-05-03 16:34:26 -0700 | [diff] [blame] | 1661 | virtual void invalidateTracks(audio_stream_type_t streamType); |
jiabin | c44b346 | 2022-12-08 12:52:31 -0800 | [diff] [blame] | 1662 | void invalidateTracks(std::set<audio_port_handle_t>& portIds) override; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1663 | |
Eric Laurent | de0613d | 2016-07-22 18:19:11 -0700 | [diff] [blame] | 1664 | virtual bool keepWakeLock() const { return (mKeepWakeLock || (mDrainSequence & 1)); } |
Eric Laurent | 6466797 | 2016-03-30 18:19:46 -0700 | [diff] [blame] | 1665 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1666 | private: |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1667 | size_t mPausedWriteLength; // length in bytes of write interrupted by pause |
| 1668 | size_t mPausedBytesRemaining; // bytes still waiting in mixbuffer after resume |
Eric Laurent | 6466797 | 2016-03-30 18:19:46 -0700 | [diff] [blame] | 1669 | bool mKeepWakeLock; // keep wake lock while waiting for write callback |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1670 | }; |
| 1671 | |
| 1672 | class AsyncCallbackThread : public Thread { |
| 1673 | public: |
Chih-Hung Hsieh | e964d4e | 2016-08-09 14:31:32 -0700 | [diff] [blame] | 1674 | explicit AsyncCallbackThread(const wp<PlaybackThread>& playbackThread); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1675 | |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1676 | // Thread virtuals |
| 1677 | virtual bool threadLoop(); |
| 1678 | |
| 1679 | // RefBase |
| 1680 | virtual void onFirstRef(); |
| 1681 | |
| 1682 | void exit(); |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 1683 | void setWriteBlocked(uint32_t sequence); |
| 1684 | void resetWriteBlocked(); |
| 1685 | void setDraining(uint32_t sequence); |
| 1686 | void resetDraining(); |
Haynes Mathew George | 4527b9e | 2016-07-07 19:54:17 -0700 | [diff] [blame] | 1687 | void setAsyncError(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1688 | |
| 1689 | private: |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 1690 | const wp<PlaybackThread> mPlaybackThread; |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 1691 | // mWriteAckSequence corresponds to the last write sequence passed by the offload thread via |
| 1692 | // setWriteBlocked(). The sequence is shifted one bit to the left and the lsb is used |
| 1693 | // to indicate that the callback has been received via resetWriteBlocked() |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 1694 | uint32_t mWriteAckSequence; |
Eric Laurent | 3b4529e | 2013-09-05 18:09:19 -0700 | [diff] [blame] | 1695 | // mDrainSequence corresponds to the last drain sequence passed by the offload thread via |
| 1696 | // setDraining(). The sequence is shifted one bit to the left and the lsb is used |
| 1697 | // to indicate that the callback has been received via resetDraining() |
Eric Laurent | 4de9559 | 2013-09-26 15:28:21 -0700 | [diff] [blame] | 1698 | uint32_t mDrainSequence; |
| 1699 | Condition mWaitWorkCV; |
| 1700 | Mutex mLock; |
Haynes Mathew George | 4527b9e | 2016-07-07 19:54:17 -0700 | [diff] [blame] | 1701 | bool mAsyncError; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1702 | }; |
| 1703 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1704 | class DuplicatingThread : public MixerThread, public IAfDuplicatingThread { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1705 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1706 | DuplicatingThread(const sp<IAfThreadCallback>& afThreadCallback, |
| 1707 | IAfPlaybackThread* mainThread, |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 1708 | audio_io_handle_t id, bool systemReady); |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1709 | ~DuplicatingThread() override; |
| 1710 | |
| 1711 | sp<IAfDuplicatingThread> asIAfDuplicatingThread() final { |
| 1712 | return sp<IAfDuplicatingThread>::fromExisting(this); |
| 1713 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1714 | |
| 1715 | // Thread virtuals |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1716 | void addOutputTrack(IAfPlaybackThread* thread) final; |
| 1717 | void removeOutputTrack(IAfPlaybackThread* thread) final; |
| 1718 | uint32_t waitTimeMs() const final { return mWaitTimeMs; } |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 1719 | |
Kevin Rocard | c86a7f7 | 2018-04-03 09:00:09 -0700 | [diff] [blame] | 1720 | void sendMetadataToBackend_l( |
| 1721 | const StreamOutHalInterface::SourceMetadata& metadata) override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1722 | protected: |
| 1723 | virtual uint32_t activeSleepTimeUs() const; |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 1724 | void dumpInternals_l(int fd, const Vector<String16>& args) override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1725 | |
| 1726 | private: |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 1727 | bool outputsReady(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1728 | protected: |
| 1729 | // threadLoop snippets |
| 1730 | virtual void threadLoop_mix(); |
| 1731 | virtual void threadLoop_sleepTime(); |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 1732 | virtual ssize_t threadLoop_write(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1733 | virtual void threadLoop_standby(); |
| 1734 | virtual void cacheParameters_l(); |
| 1735 | |
| 1736 | private: |
| 1737 | // called from threadLoop, addOutputTrack, removeOutputTrack |
| 1738 | virtual void updateWaitTime_l(); |
| 1739 | protected: |
| 1740 | virtual void saveOutputTracks(); |
| 1741 | virtual void clearOutputTracks(); |
| 1742 | private: |
| 1743 | |
| 1744 | uint32_t mWaitTimeMs; |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1745 | SortedVector <sp<IAfOutputTrack>> outputTracks; |
| 1746 | SortedVector <sp<IAfOutputTrack>> mOutputTracks; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1747 | public: |
| 1748 | virtual bool hasFastMixer() const { return false; } |
Andy Hung | 1c86ebe | 2018-05-29 20:29:08 -0700 | [diff] [blame] | 1749 | status_t threadloop_getHalTimestamp_l( |
| 1750 | ExtendedTimestamp *timestamp) const override { |
| 1751 | if (mOutputTracks.size() > 0) { |
| 1752 | // forward the first OutputTrack's kernel information for timestamp. |
| 1753 | const ExtendedTimestamp trackTimestamp = |
| 1754 | mOutputTracks[0]->getClientProxyTimestamp(); |
| 1755 | if (trackTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL] > 0) { |
| 1756 | timestamp->mTimeNs[ExtendedTimestamp::LOCATION_KERNEL] = |
| 1757 | trackTimestamp.mTimeNs[ExtendedTimestamp::LOCATION_KERNEL]; |
| 1758 | timestamp->mPosition[ExtendedTimestamp::LOCATION_KERNEL] = |
| 1759 | trackTimestamp.mPosition[ExtendedTimestamp::LOCATION_KERNEL]; |
| 1760 | return OK; // discard server timestamp - that's ignored. |
| 1761 | } |
| 1762 | } |
| 1763 | return INVALID_OPERATION; |
| 1764 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1765 | }; |
| 1766 | |
Eric Laurent | b046394 | 2022-12-20 16:31:10 +0100 | [diff] [blame] | 1767 | class SpatializerThread : public MixerThread { |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1768 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1769 | SpatializerThread(const sp<IAfThreadCallback>& afThreadCallback, |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1770 | AudioStreamOut* output, |
| 1771 | audio_io_handle_t id, |
| 1772 | bool systemReady, |
| 1773 | audio_config_base_t *mixerConfig); |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1774 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1775 | bool hasFastMixer() const final { return false; } |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1776 | |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1777 | // RefBase |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1778 | void onFirstRef() final; |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1779 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1780 | status_t setRequestedLatencyMode(audio_latency_mode_t mode) final; |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1781 | |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1782 | protected: |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1783 | void checkOutputStageEffects() final; |
| 1784 | void setHalLatencyMode_l() final; |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1785 | |
| 1786 | private: |
Eric Laurent | 68a40a8 | 2022-05-03 18:15:04 +0200 | [diff] [blame] | 1787 | // Do not request a specific mode by default |
| 1788 | audio_latency_mode_t mRequestedLatencyMode = AUDIO_LATENCY_MODE_FREE; |
| 1789 | |
Andy Hung | 116bc26 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 1790 | sp<IAfEffectHandle> mFinalDownMixer; |
Eric Laurent | b3f315a | 2021-07-13 15:09:05 +0200 | [diff] [blame] | 1791 | }; |
| 1792 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1793 | // record thread |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1794 | class RecordThread : public IAfRecordThread, public ThreadBase |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1795 | { |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1796 | friend class ResamplerBufferProvider; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1797 | public: |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1798 | sp<IAfRecordThread> asIAfRecordThread() final { |
| 1799 | return sp<IAfRecordThread>::fromExisting(this); |
| 1800 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1801 | |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 1802 | RecordThread(const sp<IAfThreadCallback>& afThreadCallback, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1803 | AudioStreamIn *input, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1804 | audio_io_handle_t id, |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 1805 | bool systemReady |
Glenn Kasten | 46909e7 | 2013-02-26 09:20:22 -0800 | [diff] [blame] | 1806 | ); |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1807 | ~RecordThread() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1808 | |
| 1809 | // no addTrack_l ? |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1810 | void destroyTrack_l(const sp<IAfRecordTrack>& track) final; |
| 1811 | void removeTrack_l(const sp<IAfRecordTrack>& track) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1812 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1813 | // Thread virtuals |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1814 | bool threadLoop() final; |
| 1815 | void preExit() final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1816 | |
| 1817 | // RefBase |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1818 | void onFirstRef() final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1819 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1820 | status_t initCheck() const final { return mInput == nullptr ? NO_INIT : NO_ERROR; } |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 1821 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1822 | sp<MemoryDealer> readOnlyHeap() const final { return mReadOnlyHeap; } |
Glenn Kasten | b880f5e | 2014-05-07 08:43:45 -0700 | [diff] [blame] | 1823 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1824 | sp<IMemory> pipeMemory() const final { return mPipeMemory; } |
Glenn Kasten | 6dbb5e3 | 2014-05-13 10:38:42 -0700 | [diff] [blame] | 1825 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1826 | sp<IAfRecordTrack> createRecordTrack_l( |
Andy Hung | 88035ac | 2023-06-27 17:05:02 -0700 | [diff] [blame] | 1827 | const sp<Client>& client, |
Kevin Rocard | 1f564ac | 2018-03-29 13:53:10 -0700 | [diff] [blame] | 1828 | const audio_attributes_t& attr, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1829 | uint32_t *pSampleRate, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1830 | audio_format_t format, |
| 1831 | audio_channel_mask_t channelMask, |
Glenn Kasten | 74935e4 | 2013-12-19 08:56:45 -0800 | [diff] [blame] | 1832 | size_t *pFrameCount, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1833 | audio_session_t sessionId, |
Eric Laurent | f14db3c | 2017-12-08 14:20:36 -0800 | [diff] [blame] | 1834 | size_t *pNotificationFrameCount, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 1835 | pid_t creatorPid, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 1836 | const AttributionSourceState& attributionSource, |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 1837 | audio_input_flags_t *flags, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1838 | pid_t tid, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 1839 | status_t *status /*non-NULL*/, |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 1840 | audio_port_handle_t portId, |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1841 | int32_t maxSharedAudioHistoryMs) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1842 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1843 | status_t start(IAfRecordTrack* recordTrack, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1844 | AudioSystem::sync_event_t event, |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1845 | audio_session_t triggerSession) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1846 | |
| 1847 | // ask the thread to stop the specified track, and |
| 1848 | // return true if the caller should then do it's part of the stopping process |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1849 | bool stop(IAfRecordTrack* recordTrack) final; |
| 1850 | AudioStreamIn* getInput() const final { return mInput; } |
| 1851 | AudioStreamIn* clearInput() final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1852 | |
Andy Hung | 99b1ba6 | 2023-07-14 11:00:08 -0700 | [diff] [blame] | 1853 | // TODO(b/291317898) Unify with IAfThreadBase |
Mikhail Naganov | 1dc9867 | 2016-08-18 17:50:29 -0700 | [diff] [blame] | 1854 | virtual sp<StreamHalInterface> stream() const; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1855 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1856 | |
Eric Laurent | 1035194 | 2014-05-08 18:49:52 -0700 | [diff] [blame] | 1857 | virtual bool checkForNewParameter_l(const String8& keyValuePair, |
| 1858 | status_t& status); |
| 1859 | virtual void cacheParameters_l() {} |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1860 | virtual String8 getParameters(const String8& keys); |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1861 | void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0, |
| 1862 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) final; |
Eric Laurent | 1c333e2 | 2014-05-20 10:48:17 -0700 | [diff] [blame] | 1863 | virtual status_t createAudioPatch_l(const struct audio_patch *patch, |
| 1864 | audio_patch_handle_t *handle); |
| 1865 | virtual status_t releaseAudioPatch_l(const audio_patch_handle_t handle); |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 1866 | void updateOutDevices(const DeviceDescriptorBaseVector& outDevices) override; |
Eric Laurent | 5f0fd7b | 2021-05-07 16:33:26 +0200 | [diff] [blame] | 1867 | void resizeInputBuffer_l(int32_t maxSharedAudioHistoryMs) override; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 1868 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1869 | void addPatchTrack(const sp<IAfPatchRecord>& record) final; |
| 1870 | void deletePatchTrack(const sp<IAfPatchRecord>& record) final; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 1871 | |
Glenn Kasten | deca2ae | 2014-02-07 10:25:56 -0800 | [diff] [blame] | 1872 | void readInputParameters_l(); |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1873 | uint32_t getInputFramesLost() const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1874 | |
Andy Hung | 116bc26 | 2023-06-20 18:56:17 -0700 | [diff] [blame] | 1875 | virtual status_t addEffectChain_l(const sp<IAfEffectChain>& chain); |
| 1876 | virtual size_t removeEffectChain_l(const sp<IAfEffectChain>& chain); |
Andy Hung | c3d62f9 | 2019-03-14 13:38:51 -0700 | [diff] [blame] | 1877 | uint32_t hasAudioSession_l(audio_session_t sessionId) const override { |
| 1878 | return ThreadBase::hasAudioSession_l(sessionId, mTracks); |
| 1879 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1880 | |
| 1881 | // Return the set of unique session IDs across all tracks. |
| 1882 | // The keys are the session IDs, and the associated values are meaningless. |
| 1883 | // FIXME replace by Set [and implement Bag/Multiset for other uses]. |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 1884 | KeyedVector<audio_session_t, bool> sessionIds() const; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1885 | |
Andy Hung | 068e08e | 2023-05-15 19:02:55 -0700 | [diff] [blame] | 1886 | status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) override; |
| 1887 | bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1888 | |
Andy Hung | 068e08e | 2023-05-15 19:02:55 -0700 | [diff] [blame] | 1889 | static void syncStartEventCallback(const wp<audioflinger::SyncEvent>& event); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1890 | |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1891 | virtual size_t frameCount() const { return mFrameCount; } |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1892 | bool hasFastCapture() const final { return mFastCapture != 0; } |
Mikhail Naganov | dc76968 | 2018-05-04 15:34:08 -0700 | [diff] [blame] | 1893 | virtual void toAudioPortConfig(struct audio_port_config *config); |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1894 | |
Eric Laurent | 4c41506 | 2016-06-17 16:14:16 -0700 | [diff] [blame] | 1895 | virtual status_t checkEffectCompatibility_l(const effect_descriptor_t *desc, |
| 1896 | audio_session_t sessionId); |
| 1897 | |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 1898 | virtual void acquireWakeLock_l() { |
| 1899 | ThreadBase::acquireWakeLock_l(); |
| 1900 | mActiveTracks.updatePowerState(this, true /* force */); |
| 1901 | } |
| 1902 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1903 | void checkBtNrec() final; |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 1904 | |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1905 | // Sets the UID records silence |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1906 | void setRecordSilenced(audio_port_handle_t portId, bool silenced) final; |
Svet Ganov | f4ddfef | 2018-01-16 07:37:58 -0800 | [diff] [blame] | 1907 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1908 | status_t getActiveMicrophones( |
| 1909 | std::vector<media::MicrophoneInfoFw>* activeMicrophones) const final; |
| 1910 | status_t setPreferredMicrophoneDirection(audio_microphone_direction_t direction) final; |
| 1911 | status_t setPreferredMicrophoneFieldDimension(float zoom) final; |
Paul McLean | 03a6e6a | 2018-12-04 10:54:13 -0700 | [diff] [blame] | 1912 | |
Vlad Popa | 7e81cea | 2023-01-19 16:34:16 +0100 | [diff] [blame] | 1913 | MetadataUpdate updateMetadata_l() override; |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 1914 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1915 | bool fastTrackAvailable() const final { return mFastTrackAvail; } |
| 1916 | void setFastTrackAvailable(bool available) final { mFastTrackAvail = available; } |
jiabin | 01c8f56 | 2018-07-19 17:47:28 -0700 | [diff] [blame] | 1917 | |
Andy Hung | c8fddf3 | 2018-08-08 18:32:37 -0700 | [diff] [blame] | 1918 | bool isTimestampCorrectionEnabled() const override { |
| 1919 | // checks popcount for exactly one device. |
Atneya Nair | 497fff1 | 2022-01-18 16:23:04 -0500 | [diff] [blame] | 1920 | // Is currently disabled. Before enabling, |
| 1921 | // verify compressed record timestamps. |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 1922 | return audio_is_input_device(mTimestampCorrectedDevice) |
| 1923 | && inDeviceType() == mTimestampCorrectedDevice; |
Andy Hung | c8fddf3 | 2018-08-08 18:32:37 -0700 | [diff] [blame] | 1924 | } |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 1925 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1926 | status_t shareAudioHistory(const std::string& sharedAudioPackageName, |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 1927 | audio_session_t sharedSessionId = AUDIO_SESSION_NONE, |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1928 | int64_t sharedAudioStartMs = -1) final; |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 1929 | status_t shareAudioHistory_l(const std::string& sharedAudioPackageName, |
| 1930 | audio_session_t sharedSessionId = AUDIO_SESSION_NONE, |
| 1931 | int64_t sharedAudioStartMs = -1); |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 1932 | void resetAudioHistory_l() final; |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 1933 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 1934 | bool isStreamInitialized() const final { |
Jasmine Cha | eaa10e4 | 2021-05-11 10:11:14 +0800 | [diff] [blame] | 1935 | return !(mInput == nullptr || mInput->stream == nullptr); |
| 1936 | } |
| 1937 | |
Mikhail Naganov | 01dc5ca | 2019-03-29 10:12:12 -0700 | [diff] [blame] | 1938 | protected: |
| 1939 | void dumpInternals_l(int fd, const Vector<String16>& args) override; |
| 1940 | void dumpTracks_l(int fd, const Vector<String16>& args) override; |
| 1941 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1942 | private: |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1943 | // Enter standby if not already in standby, and set mStandby flag |
Glenn Kasten | 93e471f | 2013-08-19 08:40:07 -0700 | [diff] [blame] | 1944 | void standbyIfNotAlreadyInStandby(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1945 | |
| 1946 | // Call the HAL standby method unconditionally, and don't change mStandby flag |
Glenn Kasten | e198c36 | 2013-08-13 09:13:36 -0700 | [diff] [blame] | 1947 | void inputStandBy(); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1948 | |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 1949 | void checkBtNrec_l(); |
| 1950 | |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 1951 | int32_t getOldestFront_l(); |
| 1952 | void updateFronts_l(int32_t offset); |
| 1953 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1954 | AudioStreamIn *mInput; |
Mikhail Naganov | 2534b38 | 2019-09-25 13:05:02 -0700 | [diff] [blame] | 1955 | Source *mSource; |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1956 | SortedVector <sp<IAfRecordTrack>> mTracks; |
Glenn Kasten | 2b80640 | 2013-11-20 16:37:38 -0800 | [diff] [blame] | 1957 | // mActiveTracks has dual roles: it indicates the current active track(s), and |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1958 | // is used together with mStartStopCond to indicate start()/stop() progress |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 1959 | ActiveTracks<IAfRecordTrack> mActiveTracks; |
Andy Hung | dae2770 | 2016-10-31 14:01:16 -0700 | [diff] [blame] | 1960 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1961 | Condition mStartStopCond; |
Glenn Kasten | 9b58f63 | 2013-07-16 11:37:48 -0700 | [diff] [blame] | 1962 | |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1963 | // resampler converts input at HAL Hz to output at AudioRecord client Hz |
Glenn Kasten | 1b29184 | 2016-07-18 14:55:21 -0700 | [diff] [blame] | 1964 | void *mRsmpInBuffer; // size = mRsmpInFramesOA |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1965 | size_t mRsmpInFrames; // size of resampler input in frames |
| 1966 | size_t mRsmpInFramesP2;// size rounded up to a power-of-2 |
Glenn Kasten | 1b29184 | 2016-07-18 14:55:21 -0700 | [diff] [blame] | 1967 | size_t mRsmpInFramesOA;// mRsmpInFramesP2 + over-allocation |
Glenn Kasten | 6dd62fb | 2013-12-05 16:35:58 -0800 | [diff] [blame] | 1968 | |
| 1969 | // rolling index that is never cleared |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1970 | int32_t mRsmpInRear; // last filled frame + 1 |
Glenn Kasten | 8594843 | 2013-08-19 12:09:05 -0700 | [diff] [blame] | 1971 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 1972 | // For dumpsys |
Glenn Kasten | b880f5e | 2014-05-07 08:43:45 -0700 | [diff] [blame] | 1973 | const sp<MemoryDealer> mReadOnlyHeap; |
Glenn Kasten | 6dbb5e3 | 2014-05-13 10:38:42 -0700 | [diff] [blame] | 1974 | |
| 1975 | // one-time initialization, no locks required |
Glenn Kasten | b187de1 | 2014-12-30 08:18:15 -0800 | [diff] [blame] | 1976 | sp<FastCapture> mFastCapture; // non-0 if there is also |
| 1977 | // a fast capture |
Eric Laurent | 72e3f39 | 2015-05-20 14:43:50 -0700 | [diff] [blame] | 1978 | |
Glenn Kasten | 6dbb5e3 | 2014-05-13 10:38:42 -0700 | [diff] [blame] | 1979 | // FIXME audio watchdog thread |
| 1980 | |
| 1981 | // contents are not guaranteed to be consistent, no locks required |
| 1982 | FastCaptureDumpState mFastCaptureDumpState; |
| 1983 | #ifdef STATE_QUEUE_DUMP |
| 1984 | // FIXME StateQueue observer and mutator dump fields |
| 1985 | #endif |
| 1986 | // FIXME audio watchdog dump |
| 1987 | |
| 1988 | // accessible only within the threadLoop(), no locks required |
| 1989 | // mFastCapture->sq() // for mutating and pushing state |
| 1990 | int32_t mFastCaptureFutex; // for cold idle |
| 1991 | |
| 1992 | // The HAL input source is treated as non-blocking, |
| 1993 | // but current implementation is blocking |
| 1994 | sp<NBAIO_Source> mInputSource; |
| 1995 | // The source for the normal capture thread to read from: mInputSource or mPipeSource |
| 1996 | sp<NBAIO_Source> mNormalSource; |
| 1997 | // If a fast capture is present, the non-blocking pipe sink written to by fast capture, |
| 1998 | // otherwise clear |
| 1999 | sp<NBAIO_Sink> mPipeSink; |
| 2000 | // If a fast capture is present, the non-blocking pipe source read by normal thread, |
| 2001 | // otherwise clear |
| 2002 | sp<NBAIO_Source> mPipeSource; |
| 2003 | // Depth of pipe from fast capture to normal thread and fast clients, always power of 2 |
| 2004 | size_t mPipeFramesP2; |
| 2005 | // If a fast capture is present, the Pipe as IMemory, otherwise clear |
| 2006 | sp<IMemory> mPipeMemory; |
| 2007 | |
Sanna Catherine de Treville Wager | 2a6a945 | 2017-07-28 11:02:01 -0700 | [diff] [blame] | 2008 | // TODO: add comment and adjust size as needed |
Glenn Kasten | 6dbb5e3 | 2014-05-13 10:38:42 -0700 | [diff] [blame] | 2009 | static const size_t kFastCaptureLogSize = 4 * 1024; |
| 2010 | sp<NBLog::Writer> mFastCaptureNBLogWriter; |
| 2011 | |
| 2012 | bool mFastTrackAvail; // true if fast track available |
Eric Laurent | d8365c5 | 2017-07-16 15:27:05 -0700 | [diff] [blame] | 2013 | // common state to all record threads |
| 2014 | std::atomic_bool mBtNrecSuspended; |
Andy Hung | 6427e44 | 2018-08-09 12:51:02 -0700 | [diff] [blame] | 2015 | |
| 2016 | int64_t mFramesRead = 0; // continuous running counter. |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2017 | |
| 2018 | DeviceDescriptorBaseVector mOutDevices; |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 2019 | |
Eric Laurent | 5f0fd7b | 2021-05-07 16:33:26 +0200 | [diff] [blame] | 2020 | int32_t mMaxSharedAudioHistoryMs = 0; |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 2021 | std::string mSharedAudioPackageName = {}; |
Eric Laurent | 2407ce3 | 2021-04-26 14:56:03 +0200 | [diff] [blame] | 2022 | int32_t mSharedAudioStartFrames = -1; |
Eric Laurent | ec376dc | 2021-04-08 20:41:22 +0200 | [diff] [blame] | 2023 | audio_session_t mSharedAudioSessionId = AUDIO_SESSION_NONE; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 2024 | }; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2025 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2026 | class MmapThread : public ThreadBase, public virtual IAfMmapThread |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2027 | { |
| 2028 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 2029 | MmapThread(const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id, |
Andy Hung | 920f657 | 2022-10-06 12:09:49 -0700 | [diff] [blame] | 2030 | AudioHwDevice *hwDev, const sp<StreamHalInterface>& stream, bool systemReady, |
Andy Hung | cf10d74 | 2020-04-28 15:38:24 -0700 | [diff] [blame] | 2031 | bool isOut); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2032 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2033 | void configure(const audio_attributes_t* attr, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2034 | audio_stream_type_t streamType, |
| 2035 | audio_session_t sessionId, |
| 2036 | const sp<MmapStreamCallback>& callback, |
Eric Laurent | 7aa0ccb | 2017-08-28 11:12:52 -0700 | [diff] [blame] | 2037 | audio_port_handle_t deviceId, |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2038 | audio_port_handle_t portId) override; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2039 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2040 | void disconnect() final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2041 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2042 | // MmapStreamInterface for adapter. |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2043 | status_t createMmapBuffer(int32_t minSizeFrames, struct audio_mmap_buffer_info* info) final; |
| 2044 | status_t getMmapPosition(struct audio_mmap_position* position) const override; |
| 2045 | status_t start(const AudioClient& client, |
jiabin | d1f1cb6 | 2020-03-24 11:57:57 -0700 | [diff] [blame] | 2046 | const audio_attributes_t *attr, |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2047 | audio_port_handle_t* handle) final; |
| 2048 | status_t stop(audio_port_handle_t handle) final; |
| 2049 | status_t standby() final; |
| 2050 | status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const = 0; |
| 2051 | status_t reportData(const void* buffer, size_t frameCount) override; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2052 | |
| 2053 | // RefBase |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2054 | void onFirstRef() final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2055 | |
| 2056 | // Thread virtuals |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2057 | bool threadLoop() final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2058 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2059 | // Not in ThreadBase |
| 2060 | virtual void threadLoop_exit() final; |
| 2061 | virtual void threadLoop_standby() final; |
| 2062 | virtual bool shouldStandby_l() final { return false; } |
| 2063 | virtual status_t exitStandby_l() REQUIRES(mLock); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2064 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2065 | status_t initCheck() const final { return mHalStream == nullptr ? NO_INIT : NO_ERROR; } |
| 2066 | size_t frameCount() const final { return mFrameCount; } |
| 2067 | bool checkForNewParameter_l(const String8& keyValuePair, status_t& status) final; |
| 2068 | String8 getParameters(const String8& keys) final; |
| 2069 | void ioConfigChanged(audio_io_config_event_t event, pid_t pid = 0, |
| 2070 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2071 | void readHalParameters_l(); |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2072 | void cacheParameters_l() final {} |
| 2073 | status_t createAudioPatch_l( |
| 2074 | const struct audio_patch* patch, audio_patch_handle_t* handle) final; |
| 2075 | status_t releaseAudioPatch_l(const audio_patch_handle_t handle) final; |
| 2076 | void toAudioPortConfig(struct audio_port_config* config) override; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2077 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2078 | sp<StreamHalInterface> stream() const final { return mHalStream; } |
| 2079 | status_t addEffectChain_l(const sp<IAfEffectChain>& chain) final; |
| 2080 | size_t removeEffectChain_l(const sp<IAfEffectChain>& chain) final; |
| 2081 | status_t checkEffectCompatibility_l( |
| 2082 | const effect_descriptor_t *desc, audio_session_t sessionId) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2083 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2084 | uint32_t hasAudioSession_l(audio_session_t sessionId) const override { |
Andy Hung | c3d62f9 | 2019-03-14 13:38:51 -0700 | [diff] [blame] | 2085 | // Note: using mActiveTracks as no mTracks here. |
| 2086 | return ThreadBase::hasAudioSession_l(sessionId, mActiveTracks); |
| 2087 | } |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2088 | status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) final; |
| 2089 | bool isValidSyncEvent(const sp<audioflinger::SyncEvent>& event) const final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2090 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2091 | virtual void checkSilentMode_l() {} // cannot be const (RecordThread) |
| 2092 | virtual void processVolume_l() {} |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2093 | void checkInvalidTracks_l(); |
| 2094 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2095 | // Not in ThreadBase |
| 2096 | virtual audio_stream_type_t streamType() const { return AUDIO_STREAM_DEFAULT; } |
| 2097 | virtual void invalidateTracks(audio_stream_type_t /* streamType */) {} |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2098 | void invalidateTracks(std::set<audio_port_handle_t>& /* portIds */) override {} |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2099 | |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 2100 | // Sets the UID records silence |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2101 | void setRecordSilenced( |
| 2102 | audio_port_handle_t /* portId */, bool /* silenced */) override {} |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 2103 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2104 | bool isStreamInitialized() const override { return false; } |
Jasmine Cha | eaa10e4 | 2021-05-11 10:11:14 +0800 | [diff] [blame] | 2105 | |
jiabin | 0960903 | 2022-06-15 19:26:01 +0000 | [diff] [blame] | 2106 | void setClientSilencedState_l(audio_port_handle_t portId, bool silenced) { |
| 2107 | mClientSilencedStates[portId] = silenced; |
| 2108 | } |
| 2109 | |
| 2110 | size_t eraseClientSilencedState_l(audio_port_handle_t portId) { |
| 2111 | return mClientSilencedStates.erase(portId); |
| 2112 | } |
| 2113 | |
| 2114 | bool isClientSilenced_l(audio_port_handle_t portId) const { |
| 2115 | const auto it = mClientSilencedStates.find(portId); |
| 2116 | return it != mClientSilencedStates.end() ? it->second : false; |
| 2117 | } |
| 2118 | |
| 2119 | void setClientSilencedIfExists_l(audio_port_handle_t portId, bool silenced) { |
| 2120 | const auto it = mClientSilencedStates.find(portId); |
| 2121 | if (it != mClientSilencedStates.end()) { |
| 2122 | it->second = silenced; |
| 2123 | } |
| 2124 | } |
| 2125 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2126 | protected: |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2127 | void dumpInternals_l(int fd, const Vector<String16>& args) override; |
| 2128 | void dumpTracks_l(int fd, const Vector<String16>& args) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2129 | |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2130 | /** |
| 2131 | * @brief mDeviceId current device port unique identifier |
| 2132 | */ |
| 2133 | audio_port_handle_t mDeviceId = AUDIO_PORT_HANDLE_NONE; |
| 2134 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2135 | audio_attributes_t mAttr; |
| 2136 | audio_session_t mSessionId; |
| 2137 | audio_port_handle_t mPortId; |
| 2138 | |
Phil Burk | 7f6b40d | 2017-02-09 13:18:38 -0800 | [diff] [blame] | 2139 | wp<MmapStreamCallback> mCallback; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2140 | sp<StreamHalInterface> mHalStream; |
| 2141 | sp<DeviceHalInterface> mHalDevice; |
| 2142 | AudioHwDevice* const mAudioHwDev; |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 2143 | ActiveTracks<IAfMmapTrack> mActiveTracks; |
Eric Laurent | 67f9729 | 2018-04-20 18:05:41 -0700 | [diff] [blame] | 2144 | float mHalVolFloat; |
jiabin | 0960903 | 2022-06-15 19:26:01 +0000 | [diff] [blame] | 2145 | std::map<audio_port_handle_t, bool> mClientSilencedStates; |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 2146 | |
| 2147 | int32_t mNoCallbackWarningCount; |
| 2148 | static constexpr int32_t kMaxNoCallbackWarnings = 5; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2149 | }; |
| 2150 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2151 | class MmapPlaybackThread : public MmapThread, public IAfMmapPlaybackThread, |
| 2152 | public virtual VolumeInterface { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2153 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 2154 | MmapPlaybackThread(const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id, |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2155 | AudioHwDevice *hwDev, AudioStreamOut *output, bool systemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2156 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2157 | sp<IAfMmapPlaybackThread> asIAfMmapPlaybackThread() final { |
| 2158 | return sp<IAfMmapPlaybackThread>::fromExisting(this); |
| 2159 | } |
| 2160 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2161 | void configure(const audio_attributes_t* attr, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2162 | audio_stream_type_t streamType, |
| 2163 | audio_session_t sessionId, |
| 2164 | const sp<MmapStreamCallback>& callback, |
Eric Laurent | 7aa0ccb | 2017-08-28 11:12:52 -0700 | [diff] [blame] | 2165 | audio_port_handle_t deviceId, |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2166 | audio_port_handle_t portId) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2167 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2168 | AudioStreamOut* clearOutput() final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2169 | |
| 2170 | // VolumeInterface |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2171 | void setMasterVolume(float value) final; |
| 2172 | void setMasterBalance(float /* value */) final {} // Needs implementation? |
| 2173 | void setMasterMute(bool muted) final; |
| 2174 | void setStreamVolume(audio_stream_type_t stream, float value) final; |
| 2175 | void setStreamMute(audio_stream_type_t stream, bool muted) final; |
| 2176 | float streamVolume(audio_stream_type_t stream) const final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2177 | |
| 2178 | void setMasterMute_l(bool muted) { mMasterMute = muted; } |
| 2179 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2180 | void invalidateTracks(audio_stream_type_t streamType) final; |
| 2181 | void invalidateTracks(std::set<audio_port_handle_t>& portIds) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2182 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2183 | audio_stream_type_t streamType() const final { return mStreamType; } |
| 2184 | void checkSilentMode_l() final; |
| 2185 | void processVolume_l() final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2186 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2187 | MetadataUpdate updateMetadata_l() final; |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 2188 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2189 | void toAudioPortConfig(struct audio_port_config* config) final; |
Mikhail Naganov | 32abc2b | 2018-05-24 12:57:11 -0700 | [diff] [blame] | 2190 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2191 | status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const final; |
jiabin | b7d8c5a | 2020-08-26 17:24:52 -0700 | [diff] [blame] | 2192 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2193 | bool isStreamInitialized() const final { |
Jasmine Cha | eaa10e4 | 2021-05-11 10:11:14 +0800 | [diff] [blame] | 2194 | return !(mOutput == nullptr || mOutput->stream == nullptr); |
| 2195 | } |
| 2196 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2197 | status_t reportData(const void* buffer, size_t frameCount) final; |
jiabin | fc791ee | 2023-02-15 19:43:40 +0000 | [diff] [blame] | 2198 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2199 | void startMelComputation_l(const sp<audio_utils::MelProcessor>& processor) final; |
| 2200 | void stopMelComputation_l() final; |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 2201 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2202 | protected: |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2203 | void dumpInternals_l(int fd, const Vector<String16>& args) final; |
Eric Laurent | 1f9b5e6 | 2023-07-03 18:14:07 +0200 | [diff] [blame] | 2204 | float streamVolume_l() const { |
| 2205 | return mStreamTypes[mStreamType].volume; |
| 2206 | } |
| 2207 | bool streamMuted_l() const { |
| 2208 | return mStreamTypes[mStreamType].mute; |
| 2209 | } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2210 | |
Eric Laurent | 1f9b5e6 | 2023-07-03 18:14:07 +0200 | [diff] [blame] | 2211 | stream_type_t mStreamTypes[AUDIO_STREAM_CNT]; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2212 | audio_stream_type_t mStreamType; |
| 2213 | float mMasterVolume; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2214 | bool mMasterMute; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2215 | AudioStreamOut* mOutput; |
Vlad Popa | 6fbbfbf | 2023-02-22 15:05:43 +0100 | [diff] [blame] | 2216 | |
| 2217 | mediautils::atomic_sp<audio_utils::MelProcessor> mMelProcessor; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2218 | }; |
| 2219 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2220 | class MmapCaptureThread : public MmapThread, public IAfMmapCaptureThread |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2221 | { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2222 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 2223 | MmapCaptureThread(const sp<IAfThreadCallback>& afThreadCallback, audio_io_handle_t id, |
jiabin | c52b1ff | 2019-10-31 17:20:42 -0700 | [diff] [blame] | 2224 | AudioHwDevice *hwDev, AudioStreamIn *input, bool systemReady); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2225 | |
Andy Hung | 7aa7d10 | 2023-07-07 15:58:48 -0700 | [diff] [blame] | 2226 | sp<IAfMmapCaptureThread> asIAfMmapCaptureThread() final { |
| 2227 | return sp<IAfMmapCaptureThread>::fromExisting(this); |
| 2228 | } |
| 2229 | |
| 2230 | AudioStreamIn* clearInput() final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2231 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2232 | status_t exitStandby_l() REQUIRES(mLock) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2233 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2234 | MetadataUpdate updateMetadata_l() final; |
| 2235 | void processVolume_l() final; |
| 2236 | void setRecordSilenced(audio_port_handle_t portId, bool silenced) final; |
Kevin Rocard | 069c271 | 2018-03-29 19:09:14 -0700 | [diff] [blame] | 2237 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2238 | void toAudioPortConfig(struct audio_port_config* config) final; |
Mikhail Naganov | 32abc2b | 2018-05-24 12:57:11 -0700 | [diff] [blame] | 2239 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2240 | status_t getExternalPosition(uint64_t* position, int64_t* timeNanos) const final; |
jiabin | b7d8c5a | 2020-08-26 17:24:52 -0700 | [diff] [blame] | 2241 | |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2242 | bool isStreamInitialized() const final { |
Jasmine Cha | eaa10e4 | 2021-05-11 10:11:14 +0800 | [diff] [blame] | 2243 | return !(mInput == nullptr || mInput->stream == nullptr); |
| 2244 | } |
| 2245 | |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 2246 | protected: |
| 2247 | |
| 2248 | AudioStreamIn* mInput; |
| 2249 | }; |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 2250 | |
| 2251 | class BitPerfectThread : public MixerThread { |
| 2252 | public: |
Andy Hung | 583043b | 2023-07-17 17:05:00 -0700 | [diff] [blame] | 2253 | BitPerfectThread(const sp<IAfThreadCallback>& afThreadCallback, AudioStreamOut *output, |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 2254 | audio_io_handle_t id, bool systemReady); |
| 2255 | |
| 2256 | protected: |
Andy Hung | 440901d | 2023-06-29 21:19:25 -0700 | [diff] [blame] | 2257 | mixer_state prepareTracks_l(Vector<sp<IAfTrack>>* tracksToRemove) final; |
| 2258 | void threadLoop_mix() final; |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 2259 | |
| 2260 | private: |
| 2261 | bool mIsBitPerfect; |
jiabin | 76d9469 | 2022-12-15 21:51:21 +0000 | [diff] [blame] | 2262 | float mVolumeLeft = 0.f; |
| 2263 | float mVolumeRight = 0.f; |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 2264 | }; |
Andy Hung | a5a7fc9 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 2265 | |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame] | 2266 | } // namespace android |