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 | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 18 | #pragma once |
Andy Hung | 0f725b4 | 2023-07-19 11:40:07 -0700 | [diff] [blame] | 19 | |
| 20 | #include "TrackBase.h" |
| 21 | |
| 22 | #include <android/os/BnExternalVibrationController.h> |
Andy Hung | 0169fbc | 2023-08-28 19:12:14 -0700 | [diff] [blame] | 23 | #include <audio_utils/mutex.h> |
Andy Hung | 0f725b4 | 2023-07-19 11:40:07 -0700 | [diff] [blame] | 24 | #include <audio_utils/LinearMap.h> |
| 25 | #include <binder/AppOpsManager.h> |
Jiabin Huang | 73f9705 | 2023-12-12 20:08:03 +0000 | [diff] [blame] | 26 | #include <utils/RWLock.h> |
Lais Andrade | bc3f37a | 2021-07-02 00:13:19 +0100 | [diff] [blame] | 27 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 28 | namespace android { |
| 29 | |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 30 | // Checks and monitors OP_PLAY_AUDIO |
| 31 | class OpPlayAudioMonitor : public RefBase { |
Vlad Popa | 9d7c6f8 | 2023-07-10 20:27:41 -0700 | [diff] [blame] | 32 | friend class sp<OpPlayAudioMonitor>; |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 33 | public: |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 34 | ~OpPlayAudioMonitor() override; |
| 35 | bool hasOpPlayAudio() const; |
| 36 | |
Mikhail Naganov | f7e3a3a | 2019-04-22 16:43:26 -0700 | [diff] [blame] | 37 | static sp<OpPlayAudioMonitor> createIfNeeded( |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 38 | IAfThreadBase* thread, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 39 | const AttributionSourceState& attributionSource, |
Philip P. Moltmann | bda4575 | 2020-07-17 16:41:18 -0700 | [diff] [blame] | 40 | const audio_attributes_t& attr, int id, |
| 41 | audio_stream_type_t streamType); |
Mikhail Naganov | f7e3a3a | 2019-04-22 16:43:26 -0700 | [diff] [blame] | 42 | |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 43 | private: |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 44 | OpPlayAudioMonitor(IAfThreadBase* thread, |
Vlad Popa | 9d7c6f8 | 2023-07-10 20:27:41 -0700 | [diff] [blame] | 45 | const AttributionSourceState& attributionSource, |
| 46 | audio_usage_t usage, int id, uid_t uid); |
Mikhail Naganov | f7e3a3a | 2019-04-22 16:43:26 -0700 | [diff] [blame] | 47 | void onFirstRef() override; |
Eric Laurent | 9066ad3 | 2019-05-20 14:40:10 -0700 | [diff] [blame] | 48 | static void getPackagesForUid(uid_t uid, Vector<String16>& packages); |
Mikhail Naganov | f7e3a3a | 2019-04-22 16:43:26 -0700 | [diff] [blame] | 49 | |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 50 | AppOpsManager mAppOpsManager; |
| 51 | |
| 52 | class PlayAudioOpCallback : public BnAppOpsCallback { |
| 53 | public: |
| 54 | explicit PlayAudioOpCallback(const wp<OpPlayAudioMonitor>& monitor); |
| 55 | void opChanged(int32_t op, const String16& packageName) override; |
| 56 | |
| 57 | private: |
| 58 | const wp<OpPlayAudioMonitor> mMonitor; |
| 59 | }; |
| 60 | |
| 61 | sp<PlayAudioOpCallback> mOpCallback; |
| 62 | // called by PlayAudioOpCallback when OP_PLAY_AUDIO is updated in AppOp callback |
Vlad Popa | d585959 | 2023-08-02 18:36:04 -0700 | [diff] [blame] | 63 | void checkPlayAudioForUsage(bool doBroadcast); |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 64 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 65 | wp<IAfThreadBase> mThread; |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 66 | std::atomic_bool mHasOpPlayAudio; |
Shunkai Yao | af7990a | 2023-08-18 02:24:01 +0000 | [diff] [blame] | 67 | const int32_t mUsage; // on purpose not audio_usage_t because always checked in appOps as |
| 68 | // int32_t |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 69 | const int mId; // for logging purposes only |
Vlad Popa | 9d7c6f8 | 2023-07-10 20:27:41 -0700 | [diff] [blame] | 70 | const uid_t mUid; |
| 71 | const String16 mPackageName; |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 72 | }; |
| 73 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 74 | // playback track |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 75 | class Track : public TrackBase, public virtual IAfTrack, public VolumeProvider { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 76 | public: |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 77 | Track(IAfPlaybackThread* thread, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 78 | const sp<Client>& client, |
| 79 | audio_stream_type_t streamType, |
Kevin Rocard | 1f564ac | 2018-03-29 13:53:10 -0700 | [diff] [blame] | 80 | const audio_attributes_t& attr, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 81 | uint32_t sampleRate, |
| 82 | audio_format_t format, |
| 83 | audio_channel_mask_t channelMask, |
| 84 | size_t frameCount, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 85 | void *buffer, |
Andy Hung | 8fe6803 | 2017-06-05 16:17:51 -0700 | [diff] [blame] | 86 | size_t bufferSize, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 87 | const sp<IMemory>& sharedBuffer, |
Glenn Kasten | d848eb4 | 2016-03-08 13:42:11 -0800 | [diff] [blame] | 88 | audio_session_t sessionId, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 89 | pid_t creatorPid, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 90 | const AttributionSourceState& attributionSource, |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 91 | audio_output_flags_t flags, |
Eric Laurent | 20b9ef0 | 2016-12-05 11:03:16 -0800 | [diff] [blame] | 92 | track_type type, |
Kevin Rocard | 01c7d9e | 2019-09-18 11:24:52 +0100 | [diff] [blame] | 93 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE, |
| 94 | /** default behaviour is to start when there are as many frames |
| 95 | * ready as possible (aka. Buffer is full). */ |
jiabin | f042b9b | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 96 | size_t frameCountToBeReady = SIZE_MAX, |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 97 | float speed = 1.0f, |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 98 | bool isSpatialized = false, |
| 99 | bool isBitPerfect = false); |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 100 | ~Track() override; |
| 101 | status_t initCheck() const final; |
| 102 | void appendDumpHeader(String8& result) const final; |
| 103 | void appendDump(String8& result, bool active) const final; |
| 104 | status_t start(AudioSystem::sync_event_t event = AudioSystem::SYNC_EVENT_NONE, |
| 105 | audio_session_t triggerSession = AUDIO_SESSION_NONE) override; |
| 106 | void stop() override; |
| 107 | void pause() final; |
| 108 | void flush() final; |
| 109 | void destroy() final; |
| 110 | uint32_t sampleRate() const final; |
| 111 | audio_stream_type_t streamType() const final { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 112 | return mStreamType; |
| 113 | } |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 114 | bool isOffloaded() const final |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 115 | { return (mFlags & AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD) != 0; } |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 116 | bool isDirect() const final |
Mikhail Naganov | 7c6ae98 | 2018-06-14 12:33:38 -0700 | [diff] [blame] | 117 | { return (mFlags & AUDIO_OUTPUT_FLAG_DIRECT) != 0; } |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 118 | bool isOffloadedOrDirect() const final { return (mFlags |
Andy Hung | 10cbff1 | 2017-02-21 17:30:14 -0800 | [diff] [blame] | 119 | & (AUDIO_OUTPUT_FLAG_COMPRESS_OFFLOAD |
| 120 | | AUDIO_OUTPUT_FLAG_DIRECT)) != 0; } |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 121 | bool isStatic() const final { return mSharedBuffer.get() != nullptr; } |
Andy Hung | 10cbff1 | 2017-02-21 17:30:14 -0800 | [diff] [blame] | 122 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 123 | status_t setParameters(const String8& keyValuePairs) final; |
| 124 | status_t selectPresentation(int presentationId, int programId) final; |
| 125 | status_t attachAuxEffect(int EffectId) final; |
| 126 | void setAuxBuffer(int EffectId, int32_t* buffer) final; |
| 127 | int32_t* auxBuffer() const final { return mAuxBuffer; } |
| 128 | void setMainBuffer(float* buffer) final { mMainBuffer = buffer; } |
| 129 | float* mainBuffer() const final { return mMainBuffer; } |
| 130 | int auxEffectId() const final { return mAuxEffectId; } |
| 131 | status_t getTimestamp(AudioTimestamp& timestamp) final; |
| 132 | void signal() final; |
| 133 | status_t getDualMonoMode(audio_dual_mono_mode_t* mode) const final; |
| 134 | status_t setDualMonoMode(audio_dual_mono_mode_t mode) final; |
| 135 | status_t getAudioDescriptionMixLevel(float* leveldB) const final; |
| 136 | status_t setAudioDescriptionMixLevel(float leveldB) final; |
| 137 | status_t getPlaybackRateParameters(audio_playback_rate_t* playbackRate) const final; |
| 138 | status_t setPlaybackRateParameters(const audio_playback_rate_t& playbackRate) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 139 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 140 | // implement FastMixerState::VolumeProvider interface |
| 141 | gain_minifloat_packed_t getVolumeLR() const final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 142 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 143 | status_t setSyncEvent(const sp<audioflinger::SyncEvent>& event) final; |
| 144 | bool isFastTrack() const final { return (mFlags & AUDIO_OUTPUT_FLAG_FAST) != 0; } |
| 145 | double bufferLatencyMs() const final { |
Andy Hung | cef2daa | 2018-06-01 15:31:49 -0700 | [diff] [blame] | 146 | return isStatic() ? 0. : TrackBase::bufferLatencyMs(); |
| 147 | } |
Andy Hung | f6ab58d | 2018-05-25 12:50:39 -0700 | [diff] [blame] | 148 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 149 | // implement volume handling. |
Ivan Lozano | 8cf3a07 | 2017-08-09 09:01:33 -0700 | [diff] [blame] | 150 | media::VolumeShaper::Status applyVolumeShaper( |
| 151 | const sp<media::VolumeShaper::Configuration>& configuration, |
| 152 | const sp<media::VolumeShaper::Operation>& operation); |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 153 | sp<media::VolumeShaper::State> getVolumeShaperState(int id) const final; |
| 154 | sp<media::VolumeHandler> getVolumeHandler() const final{ return mVolumeHandler; } |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 155 | /** Set the computed normalized final volume of the track. |
| 156 | * !masterMute * masterVolume * streamVolume * averageLRVolume */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 157 | void setFinalVolume(float volumeLeft, float volumeRight) final; |
| 158 | float getFinalVolume() const final { return mFinalVolume; } |
| 159 | void getFinalVolume(float* left, float* right) const final { |
jiabin | 76d9469 | 2022-12-15 21:51:21 +0000 | [diff] [blame] | 160 | *left = mFinalVolumeLeft; |
| 161 | *right = mFinalVolumeRight; |
| 162 | } |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 163 | |
Eric Laurent | 9457917 | 2020-11-20 18:41:04 +0100 | [diff] [blame] | 164 | using SourceMetadatas = std::vector<playback_track_metadata_v7_t>; |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 165 | using MetadataInserter = std::back_insert_iterator<SourceMetadatas>; |
| 166 | /** Copy the track metadata in the provided iterator. Thread safe. */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 167 | void copyMetadataTo(MetadataInserter& backInserter) const override; |
| 168 | |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 169 | |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 170 | /** Return haptic playback of the track is enabled or not, used in mixer. */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 171 | bool getHapticPlaybackEnabled() const final { return mHapticPlaybackEnabled; } |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 172 | /** Set haptic playback of the track is enabled or not, should be |
| 173 | * set after query or get callback from vibrator service */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 174 | void setHapticPlaybackEnabled(bool hapticPlaybackEnabled) final { |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 175 | mHapticPlaybackEnabled = hapticPlaybackEnabled; |
| 176 | } |
Ahmad Khalil | 229466a | 2024-02-05 12:15:30 +0000 | [diff] [blame] | 177 | /** Return the haptics scale, used in mixer. */ |
| 178 | os::HapticScale getHapticScale() const final { return mHapticScale; } |
Lais Andrade | bc3f37a | 2021-07-02 00:13:19 +0100 | [diff] [blame] | 179 | /** Return the maximum amplitude allowed for haptics data, used in mixer. */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 180 | float getHapticMaxAmplitude() const final { return mHapticMaxAmplitude; } |
jiabin | 77270b8 | 2018-12-18 15:41:29 -0800 | [diff] [blame] | 181 | /** Set intensity of haptic playback, should be set after querying vibrator service. */ |
Ahmad Khalil | 229466a | 2024-02-05 12:15:30 +0000 | [diff] [blame] | 182 | void setHapticScale(os::HapticScale hapticScale) final { |
| 183 | if (os::isValidHapticScale(hapticScale)) { |
| 184 | mHapticScale = hapticScale; |
| 185 | setHapticPlaybackEnabled(!mHapticScale.isScaleMute()); |
jiabin | 77270b8 | 2018-12-18 15:41:29 -0800 | [diff] [blame] | 186 | } |
| 187 | } |
Lais Andrade | bc3f37a | 2021-07-02 00:13:19 +0100 | [diff] [blame] | 188 | /** Set maximum amplitude allowed for haptic data, should be set after querying |
| 189 | * vibrator service. |
| 190 | */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 191 | void setHapticMaxAmplitude(float maxAmplitude) final { |
Lais Andrade | bc3f37a | 2021-07-02 00:13:19 +0100 | [diff] [blame] | 192 | mHapticMaxAmplitude = maxAmplitude; |
| 193 | } |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 194 | sp<os::ExternalVibration> getExternalVibration() const final { return mExternalVibration; } |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 195 | |
Jiabin Huang | fb47684 | 2022-12-06 03:18:10 +0000 | [diff] [blame] | 196 | // This function should be called with holding thread lock. |
Andy Hung | f302e81 | 2024-01-26 11:55:15 -0800 | [diff] [blame] | 197 | void updateTeePatches_l() final REQUIRES(audio_utils::ThreadBase_Mutex) |
| 198 | EXCLUDES_BELOW_ThreadBase_Mutex; |
Andy Hung | 16ed0da | 2023-07-14 11:45:38 -0700 | [diff] [blame] | 199 | void setTeePatchesToUpdate_l(TeePatches teePatchesToUpdate) final; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 200 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 201 | void tallyUnderrunFrames(size_t frames) final { |
Andy Hung | c2b11cb | 2020-04-22 09:04:01 -0700 | [diff] [blame] | 202 | if (isOut()) { // we expect this from output tracks only |
| 203 | mAudioTrackServerProxy->tallyUnderrunFrames(frames); |
| 204 | // Fetch absolute numbers from AudioTrackShared as it counts |
| 205 | // contiguous underruns as a one -- we want a consistent number. |
| 206 | // TODO: isolate this counting into a class. |
| 207 | mTrackMetrics.logUnderruns(mAudioTrackServerProxy->getUnderrunCount(), |
| 208 | mAudioTrackServerProxy->getUnderrunFrames()); |
| 209 | } |
| 210 | } |
jiabin | f042b9b | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 211 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 212 | audio_output_flags_t getOutputFlags() const final { return mFlags; } |
| 213 | float getSpeed() const final { return mSpeed; } |
| 214 | bool isSpatialized() const final { return mIsSpatialized; } |
| 215 | bool isBitPerfect() const final { return mIsBitPerfect; } |
Eric Laurent | 3909598 | 2021-08-24 18:29:27 +0200 | [diff] [blame] | 216 | |
Vlad Popa | e8d9947 | 2022-06-30 16:02:48 +0200 | [diff] [blame] | 217 | /** |
| 218 | * Updates the mute state and notifies the audio service. Call this only when holding player |
| 219 | * thread lock. |
| 220 | */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 221 | void processMuteEvent_l(const sp<IAudioManager>& audioManager, mute_state_t muteState) final; |
Vlad Popa | e8d9947 | 2022-06-30 16:02:48 +0200 | [diff] [blame] | 222 | |
jiabin | 220eea1 | 2024-05-17 17:55:20 +0000 | [diff] [blame] | 223 | bool getInternalMute() const final { return mInternalMute; } |
| 224 | void setInternalMute(bool muted) final { mInternalMute = muted; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 225 | protected: |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 226 | |
Mikhail Naganov | bf49308 | 2017-04-17 17:37:12 -0700 | [diff] [blame] | 227 | DISALLOW_COPY_AND_ASSIGN(Track); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 228 | |
| 229 | // AudioBufferProvider interface |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 230 | status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) override; |
| 231 | void releaseBuffer(AudioBufferProvider::Buffer* buffer) override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 232 | |
Glenn Kasten | 6466c9e | 2013-08-23 10:54:07 -0700 | [diff] [blame] | 233 | // ExtendedAudioBufferProvider interface |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 234 | size_t framesReady() const override; |
| 235 | int64_t framesReleased() const override; |
| 236 | void onTimestamp(const ExtendedTimestamp ×tamp) override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 237 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 238 | // Used by thread |
| 239 | bool isPausing() const final { return mState == PAUSING; } |
| 240 | bool isPaused() const final { return mState == PAUSED; } |
| 241 | bool isResuming() const final { return mState == RESUMING; } |
| 242 | bool isReady() const final; |
| 243 | void setPaused() final { mState = PAUSED; } |
| 244 | void reset() final; |
| 245 | bool isFlushPending() const final { return mFlushHwPending; } |
| 246 | void flushAck() final; |
| 247 | bool isResumePending() const final; |
| 248 | void resumeAck() final; |
Kuowei Li | 2366647 | 2021-01-20 10:23:25 +0800 | [diff] [blame] | 249 | // For direct or offloaded tracks ensure that the pause state is acknowledged |
| 250 | // by the playback thread in case of an immediate flush. |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 251 | bool isPausePending() const final { return mPauseHwPending; } |
| 252 | void pauseAck() final; |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 253 | void updateTrackFrameInfo(int64_t trackFramesReleased, int64_t sinkFramesWritten, |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 254 | uint32_t halSampleRate, const ExtendedTimestamp& timeStamp) final; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 255 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 256 | sp<IMemory> sharedBuffer() const final { return mSharedBuffer; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 257 | |
Andy Hung | 59de426 | 2021-06-14 10:53:54 -0700 | [diff] [blame] | 258 | // presentationComplete checked by frames. (Mixed Tracks). |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 259 | // framesWritten is cumulative, never reset, and is shared all tracks |
| 260 | // audioHalFrames is derived from output latency |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 261 | bool presentationComplete(int64_t framesWritten, size_t audioHalFrames) final; |
Andy Hung | 59de426 | 2021-06-14 10:53:54 -0700 | [diff] [blame] | 262 | |
| 263 | // presentationComplete checked by time. (Direct Tracks). |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 264 | bool presentationComplete(uint32_t latencyMs) final; |
Andy Hung | 59de426 | 2021-06-14 10:53:54 -0700 | [diff] [blame] | 265 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 266 | void resetPresentationComplete() final { |
Andy Hung | 59de426 | 2021-06-14 10:53:54 -0700 | [diff] [blame] | 267 | mPresentationCompleteFrames = 0; |
| 268 | mPresentationCompleteTimeNs = 0; |
| 269 | } |
| 270 | |
| 271 | // notifyPresentationComplete is called when presentationComplete() detects |
| 272 | // that the track is finished stopping. |
| 273 | void notifyPresentationComplete(); |
| 274 | |
Eric Laurent | 4d231dc | 2016-03-11 18:38:23 -0800 | [diff] [blame] | 275 | void signalClientFlag(int32_t flag); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 276 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 277 | void triggerEvents(AudioSystem::sync_event_t type) final; |
| 278 | void invalidate() final; |
| 279 | void disable() final; |
Eric Laurent | 022a513 | 2024-04-12 17:02:51 +0000 | [diff] [blame] | 280 | bool isDisabled() const final; |
| 281 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 282 | int& fastIndex() final { return mFastIndex; } |
| 283 | bool isPlaybackRestricted() const final { |
Mikhail Naganov | f7e3a3a | 2019-04-22 16:43:26 -0700 | [diff] [blame] | 284 | // The monitor is only created for tracks that can be silenced. |
| 285 | return mOpPlayAudioMonitor ? !mOpPlayAudioMonitor->hasOpPlayAudio() : false; } |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 286 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 287 | const sp<AudioTrackServerProxy>& audioTrackServerProxy() const final { |
| 288 | return mAudioTrackServerProxy; |
| 289 | } |
| 290 | bool hasVolumeController() const final { return mHasVolumeController; } |
| 291 | void setHasVolumeController(bool hasVolumeController) final { |
| 292 | mHasVolumeController = hasVolumeController; |
| 293 | } |
| 294 | void setCachedVolume(float volume) final { |
| 295 | mCachedVolume = volume; |
| 296 | } |
| 297 | void setResetDone(bool resetDone) final { |
| 298 | mResetDone = resetDone; |
| 299 | } |
| 300 | ExtendedAudioBufferProvider* asExtendedAudioBufferProvider() final { |
| 301 | return this; |
| 302 | } |
| 303 | VolumeProvider* asVolumeProvider() final { |
| 304 | return this; |
| 305 | } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 306 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 307 | FillingStatus& fillingStatus() final { return mFillingStatus; } |
| 308 | int8_t& retryCount() final { return mRetryCount; } |
| 309 | FastTrackUnderruns& fastTrackUnderruns() final { return mObservedUnderruns; } |
| 310 | |
| 311 | protected: |
| 312 | mutable FillingStatus mFillingStatus; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 313 | int8_t mRetryCount; |
Glenn Kasten | 0c72b24 | 2013-09-11 09:14:16 -0700 | [diff] [blame] | 314 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 315 | // see comment at ~Track for why this can't be const |
Glenn Kasten | 0c72b24 | 2013-09-11 09:14:16 -0700 | [diff] [blame] | 316 | sp<IMemory> mSharedBuffer; |
| 317 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 318 | bool mResetDone; |
| 319 | const audio_stream_type_t mStreamType; |
Andy Hung | 319587b | 2023-05-23 14:01:03 -0700 | [diff] [blame] | 320 | float *mMainBuffer; |
rago | 94a1ee8 | 2017-07-21 15:11:02 -0700 | [diff] [blame] | 321 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 322 | int32_t *mAuxBuffer; |
| 323 | int mAuxEffectId; |
| 324 | bool mHasVolumeController; |
Andy Hung | e10393e | 2015-06-12 13:59:33 -0700 | [diff] [blame] | 325 | |
| 326 | // access these three variables only when holding thread lock. |
Andy Hung | 818e7a3 | 2016-02-16 18:08:07 -0800 | [diff] [blame] | 327 | LinearMap<int64_t> mFrameMap; // track frame to server frame mapping |
| 328 | |
| 329 | ExtendedTimestamp mSinkTimestamp; |
Andy Hung | e10393e | 2015-06-12 13:59:33 -0700 | [diff] [blame] | 330 | |
Ivan Lozano | 8cf3a07 | 2017-08-09 09:01:33 -0700 | [diff] [blame] | 331 | sp<media::VolumeHandler> mVolumeHandler; // handles multiple VolumeShaper configs and operations |
Andy Hung | 9fc8b5c | 2017-01-24 13:36:48 -0800 | [diff] [blame] | 332 | |
Jean-Michel Trivi | 74e01fa | 2019-02-25 12:18:09 -0800 | [diff] [blame] | 333 | sp<OpPlayAudioMonitor> mOpPlayAudioMonitor; |
| 334 | |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 335 | bool mHapticPlaybackEnabled = false; // indicates haptic playback enabled or not |
Ahmad Khalil | 229466a | 2024-02-05 12:15:30 +0000 | [diff] [blame] | 336 | // scale to play haptic data |
| 337 | os::HapticScale mHapticScale = os::HapticScale::mute(); |
Lais Andrade | bc3f37a | 2021-07-02 00:13:19 +0100 | [diff] [blame] | 338 | // max amplitude allowed for haptic data |
| 339 | float mHapticMaxAmplitude = NAN; |
jiabin | 57303cc | 2018-12-18 15:45:57 -0800 | [diff] [blame] | 340 | class AudioVibrationController : public os::BnExternalVibrationController { |
| 341 | public: |
| 342 | explicit AudioVibrationController(Track* track) : mTrack(track) {} |
| 343 | binder::Status mute(/*out*/ bool *ret) override; |
| 344 | binder::Status unmute(/*out*/ bool *ret) override; |
| 345 | private: |
| 346 | Track* const mTrack; |
SPeak Shen | c19aa9e | 2022-11-11 00:28:50 +0800 | [diff] [blame] | 347 | bool setMute(bool muted); |
jiabin | 57303cc | 2018-12-18 15:45:57 -0800 | [diff] [blame] | 348 | }; |
| 349 | sp<AudioVibrationController> mAudioVibrationController; |
| 350 | sp<os::ExternalVibration> mExternalVibration; |
jiabin | 245cdd9 | 2018-12-07 17:55:15 -0800 | [diff] [blame] | 351 | |
Kuowei Li | d4adbdb | 2020-08-13 14:44:25 +0800 | [diff] [blame] | 352 | audio_dual_mono_mode_t mDualMonoMode = AUDIO_DUAL_MONO_MODE_OFF; |
| 353 | float mAudioDescriptionMixLevel = -std::numeric_limits<float>::infinity(); |
| 354 | audio_playback_rate_t mPlaybackRateParameters = AUDIO_PLAYBACK_RATE_INITIALIZER; |
| 355 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 356 | private: |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 357 | void interceptBuffer(const AudioBufferProvider::Buffer& buffer); |
jiabin | 7434e81 | 2023-06-27 18:22:35 +0000 | [diff] [blame] | 358 | // Must hold thread lock to access tee patches |
Kevin Rocard | c43ea14 | 2019-01-31 18:17:37 -0800 | [diff] [blame] | 359 | template <class F> |
jiabin | 7434e81 | 2023-06-27 18:22:35 +0000 | [diff] [blame] | 360 | void forEachTeePatchTrack_l(F f) { |
Jiabin Huang | 73f9705 | 2023-12-12 20:08:03 +0000 | [diff] [blame] | 361 | RWLock::AutoRLock readLock(mTeePatchesRWLock); |
Kevin Rocard | c43ea14 | 2019-01-31 18:17:37 -0800 | [diff] [blame] | 362 | for (auto& tp : mTeePatches) { f(tp.patchTrack); } |
| 363 | }; |
Kevin Rocard | 153f92d | 2018-12-18 18:33:28 -0800 | [diff] [blame] | 364 | |
Andy Hung | 59de426 | 2021-06-14 10:53:54 -0700 | [diff] [blame] | 365 | size_t mPresentationCompleteFrames = 0; // (Used for Mixed tracks) |
| 366 | // The number of frames written to the |
| 367 | // audio HAL when this track is considered fully rendered. |
| 368 | // Zero means not monitoring. |
| 369 | int64_t mPresentationCompleteTimeNs = 0; // (Used for Direct tracks) |
| 370 | // The time when this track is considered fully rendered. |
| 371 | // Zero means not monitoring. |
| 372 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 373 | // The following fields are only for fast tracks, and should be in a subclass |
| 374 | int mFastIndex; // index within FastMixerState::mFastTracks[]; |
| 375 | // either mFastIndex == -1 if not isFastTrack() |
| 376 | // or 0 < mFastIndex < FastMixerState::kMaxFast because |
| 377 | // index 0 is reserved for normal mixer's submix; |
| 378 | // index is allocated statically at track creation time |
| 379 | // but the slot is only used if track is active |
| 380 | FastTrackUnderruns mObservedUnderruns; // Most recently observed value of |
| 381 | // mFastMixerDumpState.mTracks[mFastIndex].mUnderruns |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 382 | volatile float mCachedVolume; // combined master volume and stream type volume; |
| 383 | // 'volatile' means accessed without lock or |
| 384 | // barrier, but is read/written atomically |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 385 | float mFinalVolume; // combine master volume, stream type volume and track volume |
jiabin | 76d9469 | 2022-12-15 21:51:21 +0000 | [diff] [blame] | 386 | float mFinalVolumeLeft; // combine master volume, stream type volume and track |
| 387 | // volume |
| 388 | float mFinalVolumeRight; // combine master volume, stream type volume and track |
| 389 | // volume |
Eric Laurent | 5bba2f6 | 2016-03-18 11:14:14 -0700 | [diff] [blame] | 390 | sp<AudioTrackServerProxy> mAudioTrackServerProxy; |
Eric Laurent | bfb1b83 | 2013-01-07 09:53:42 -0800 | [diff] [blame] | 391 | bool mResumeToStopping; // track was paused in stopping state. |
Haynes Mathew George | 7844f67 | 2014-01-15 12:32:55 -0800 | [diff] [blame] | 392 | bool mFlushHwPending; // track requests for thread flush |
Kuowei Li | 2366647 | 2021-01-20 10:23:25 +0800 | [diff] [blame] | 393 | bool mPauseHwPending = false; // direct/offload track request for thread pause |
Eric Laurent | 0506778 | 2016-06-01 18:27:28 -0700 | [diff] [blame] | 394 | audio_output_flags_t mFlags; |
Andy Hung | 16ed0da | 2023-07-14 11:45:38 -0700 | [diff] [blame] | 395 | TeePatches mTeePatches; |
| 396 | std::optional<TeePatches> mTeePatchesToUpdate; |
Jiabin Huang | 73f9705 | 2023-12-12 20:08:03 +0000 | [diff] [blame] | 397 | RWLock mTeePatchesRWLock; |
jiabin | f042b9b | 2021-05-07 23:46:28 +0000 | [diff] [blame] | 398 | const float mSpeed; |
Eric Laurent | b0a7bc9 | 2022-04-05 15:06:08 +0200 | [diff] [blame] | 399 | const bool mIsSpatialized; |
jiabin | c658e45 | 2022-10-21 20:52:21 +0000 | [diff] [blame] | 400 | const bool mIsBitPerfect; |
Vlad Popa | e8d9947 | 2022-06-30 16:02:48 +0200 | [diff] [blame] | 401 | |
| 402 | // TODO: replace PersistableBundle with own struct |
| 403 | // access these two variables only when holding player thread lock. |
| 404 | std::unique_ptr<os::PersistableBundle> mMuteEventExtras; |
| 405 | mute_state_t mMuteState; |
jiabin | 220eea1 | 2024-05-17 17:55:20 +0000 | [diff] [blame] | 406 | |
| 407 | bool mInternalMute = false; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 408 | }; // end of Track |
| 409 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 410 | |
| 411 | // playback track, used by DuplicatingThread |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 412 | class OutputTrack : public Track, public IAfOutputTrack { |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 413 | public: |
| 414 | |
| 415 | class Buffer : public AudioBufferProvider::Buffer { |
| 416 | public: |
Andy Hung | c25b84a | 2015-01-14 19:04:10 -0800 | [diff] [blame] | 417 | void *mBuffer; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 418 | }; |
| 419 | |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 420 | OutputTrack(IAfPlaybackThread* thread, |
| 421 | IAfDuplicatingThread* sourceThread, |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 422 | uint32_t sampleRate, |
| 423 | audio_format_t format, |
| 424 | audio_channel_mask_t channelMask, |
Marco Nelissen | 462fd2f | 2013-01-14 14:12:05 -0800 | [diff] [blame] | 425 | size_t frameCount, |
Svet Ganov | 3376113 | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 426 | const AttributionSourceState& attributionSource); |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 427 | ~OutputTrack() override; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 428 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 429 | status_t start(AudioSystem::sync_event_t event = |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 430 | AudioSystem::SYNC_EVENT_NONE, |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 431 | audio_session_t triggerSession = AUDIO_SESSION_NONE) final; |
| 432 | void stop() final; |
| 433 | ssize_t write(void* data, uint32_t frames) final; |
| 434 | bool bufferQueueEmpty() const final { return mBufferQueue.size() == 0; } |
| 435 | bool isActive() const final { return mActive; } |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 436 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 437 | void copyMetadataTo(MetadataInserter& backInserter) const final; |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 438 | /** Set the metadatas of the upstream tracks. Thread safe. */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 439 | void setMetadatas(const SourceMetadatas& metadatas) final; |
Andy Hung | 1c86ebe | 2018-05-29 20:29:08 -0700 | [diff] [blame] | 440 | /** returns client timestamp to the upstream duplicating thread. */ |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 441 | ExtendedTimestamp getClientProxyTimestamp() const final { |
Andy Hung | 1c86ebe | 2018-05-29 20:29:08 -0700 | [diff] [blame] | 442 | // server - kernel difference is not true latency when drained |
| 443 | // i.e. mServerProxy->isDrained(). |
| 444 | ExtendedTimestamp timestamp; |
| 445 | (void) mClientProxy->getTimestamp(×tamp); |
| 446 | // On success, the timestamp LOCATION_SERVER and LOCATION_KERNEL |
| 447 | // entries will be properly filled. If getTimestamp() |
| 448 | // is unsuccessful, then a default initialized timestamp |
| 449 | // (with mTimeNs[] filled with -1's) is returned. |
| 450 | return timestamp; |
| 451 | } |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 452 | private: |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 453 | status_t obtainBuffer(AudioBufferProvider::Buffer* buffer, |
| 454 | uint32_t waitTimeMs); |
Eric Laurent | 19952e1 | 2023-04-20 10:08:29 +0200 | [diff] [blame] | 455 | void queueBuffer(Buffer& inBuffer); |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 456 | void clearBufferQueue(); |
| 457 | |
Andy Hung | 56ce2ed | 2024-06-12 16:03:16 -0700 | [diff] [blame] | 458 | void restartIfDisabled() override; |
Eric Laurent | 4d231dc | 2016-03-11 18:38:23 -0800 | [diff] [blame] | 459 | |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 460 | // Maximum number of pending buffers allocated by OutputTrack::write() |
| 461 | static const uint8_t kMaxOverFlowBuffers = 10; |
| 462 | |
| 463 | Vector < Buffer* > mBufferQueue; |
| 464 | AudioBufferProvider::Buffer mOutBuffer; |
| 465 | bool mActive; |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 466 | IAfDuplicatingThread* const mSourceThread; // for waitTimeMs() in write() |
Eric Laurent | 5bba2f6 | 2016-03-18 11:14:14 -0700 | [diff] [blame] | 467 | sp<AudioTrackClientProxy> mClientProxy; |
Andy Hung | 1c86ebe | 2018-05-29 20:29:08 -0700 | [diff] [blame] | 468 | |
Kevin Rocard | 1238109 | 2018-04-11 09:19:59 -0700 | [diff] [blame] | 469 | /** Attributes of the source tracks. |
| 470 | * |
| 471 | * This member must be accessed with mTrackMetadatasMutex taken. |
| 472 | * There is one writer (duplicating thread) and one reader (downstream mixer). |
| 473 | * |
| 474 | * That means that the duplicating thread can block the downstream mixer |
| 475 | * thread and vice versa for the time of the copy. |
| 476 | * If this becomes an issue, the metadata could be stored in an atomic raw pointer, |
| 477 | * and a exchange with nullptr and delete can be used. |
| 478 | * Alternatively a read-copy-update might be implemented. |
| 479 | */ |
| 480 | SourceMetadatas mTrackMetadatas; |
| 481 | /** Protects mTrackMetadatas against concurrent access. */ |
Andy Hung | c5007f8 | 2023-08-29 14:26:09 -0700 | [diff] [blame] | 482 | audio_utils::mutex& trackMetadataMutex() const { return mTrackMetadataMutex; } |
Andy Hung | a6f1cbb | 2023-10-12 18:18:13 -0700 | [diff] [blame] | 483 | mutable audio_utils::mutex mTrackMetadataMutex{ |
| 484 | audio_utils::MutexOrder::kOutputTrack_TrackMetadataMutex}; |
Eric Laurent | 81784c3 | 2012-11-19 14:55:58 -0800 | [diff] [blame] | 485 | }; // end of OutputTrack |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 486 | |
| 487 | // playback track, used by PatchPanel |
Andy Hung | ca9be05 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 488 | class PatchTrack : public Track, public PatchTrackBase, public IAfPatchTrack { |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 489 | public: |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 490 | PatchTrack(IAfPlaybackThread* playbackThread, |
Eric Laurent | 3bcf859 | 2015-04-03 12:13:24 -0700 | [diff] [blame] | 491 | audio_stream_type_t streamType, |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 492 | uint32_t sampleRate, |
| 493 | audio_channel_mask_t channelMask, |
| 494 | audio_format_t format, |
| 495 | size_t frameCount, |
| 496 | void *buffer, |
Andy Hung | 8fe6803 | 2017-06-05 16:17:51 -0700 | [diff] [blame] | 497 | size_t bufferSize, |
Kevin Rocard | 45986c7 | 2018-12-18 18:22:59 -0800 | [diff] [blame] | 498 | audio_output_flags_t flags, |
Kevin Rocard | 01c7d9e | 2019-09-18 11:24:52 +0100 | [diff] [blame] | 499 | const Timeout& timeout = {}, |
guonaichao | 3acc9b1 | 2024-06-07 09:27:21 +0800 | [diff] [blame] | 500 | size_t frameCountToBeReady = 1, /** Default behaviour is to start |
Kevin Rocard | 01c7d9e | 2019-09-18 11:24:52 +0100 | [diff] [blame] | 501 | * as soon as possible to have |
| 502 | * the lowest possible latency |
guonaichao | 3acc9b1 | 2024-06-07 09:27:21 +0800 | [diff] [blame] | 503 | * even if it might glitch. */ |
| 504 | float speed = 1.0f); |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 505 | ~PatchTrack() override; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 506 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 507 | size_t framesReady() const final; |
Mikhail Naganov | caf5994 | 2019-09-25 14:05:29 -0700 | [diff] [blame] | 508 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 509 | status_t start(AudioSystem::sync_event_t event = |
Eric Laurent | 4d231dc | 2016-03-11 18:38:23 -0800 | [diff] [blame] | 510 | AudioSystem::SYNC_EVENT_NONE, |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 511 | audio_session_t triggerSession = AUDIO_SESSION_NONE) final; |
Eric Laurent | 4d231dc | 2016-03-11 18:38:23 -0800 | [diff] [blame] | 512 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 513 | // AudioBufferProvider interface |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 514 | status_t getNextBuffer(AudioBufferProvider::Buffer* buffer) final; |
| 515 | void releaseBuffer(AudioBufferProvider::Buffer* buffer) final; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 516 | |
| 517 | // PatchProxyBufferProvider interface |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 518 | status_t obtainBuffer(Proxy::Buffer* buffer, const struct timespec* timeOut = nullptr) final; |
| 519 | void releaseBuffer(Proxy::Buffer* buffer) final; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 520 | |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 521 | private: |
Andy Hung | 56ce2ed | 2024-06-12 16:03:16 -0700 | [diff] [blame] | 522 | void restartIfDisabled() override; |
Eric Laurent | 83b8808 | 2014-06-20 18:31:16 -0700 | [diff] [blame] | 523 | }; // end of PatchTrack |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 524 | |
| 525 | } // namespace android |