Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 1 | /* |
| 2 | ** |
| 3 | ** Copyright 2017, 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 |
| 19 | |
| 20 | namespace android { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 21 | |
| 22 | // playback track |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 23 | class MmapTrack : public TrackBase, public IAfMmapTrack { |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 24 | public: |
Andy Hung | 87c693c | 2023-07-06 20:56:16 -0700 | [diff] [blame] | 25 | MmapTrack(IAfThreadBase* thread, |
Kevin Rocard | 1f564ac | 2018-03-29 13:53:10 -0700 | [diff] [blame] | 26 | const audio_attributes_t& attr, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 27 | uint32_t sampleRate, |
| 28 | audio_format_t format, |
| 29 | audio_channel_mask_t channelMask, |
| 30 | audio_session_t sessionId, |
Kevin Rocard | 5f2136e | 2018-05-11 22:03:00 -0700 | [diff] [blame] | 31 | bool isOut, |
Svet Ganov | 3e5f14f | 2021-05-13 22:51:08 +0000 | [diff] [blame] | 32 | const android::content::AttributionSourceState& attributionSource, |
Eric Laurent | 09f1ed2 | 2019-04-24 17:45:17 -0700 | [diff] [blame] | 33 | pid_t creatorPid, |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 34 | audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE); |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 35 | ~MmapTrack() override; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 36 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 37 | status_t initCheck() const final; |
| 38 | status_t start( |
| 39 | AudioSystem::sync_event_t event, audio_session_t triggerSession) final; |
| 40 | void stop() final; |
| 41 | bool isFastTrack() const final { return false; } |
| 42 | bool isDirect() const final { return true; } |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 43 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 44 | void appendDumpHeader(String8& result) const final; |
| 45 | void appendDump(String8& result, bool active) const final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 46 | |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 47 | // protected by MMapThread::mLock |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 48 | void setSilenced_l(bool silenced) final { mSilenced = silenced; |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 49 | mSilencedNotified = false;} |
| 50 | // protected by MMapThread::mLock |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 51 | bool isSilenced_l() const final { return mSilenced; } |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 52 | // protected by MMapThread::mLock |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 53 | bool getAndSetSilencedNotified_l() final { bool silencedNotified = mSilencedNotified; |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 54 | mSilencedNotified = true; |
| 55 | return silencedNotified; } |
Vlad Popa | ec1788e | 2022-08-04 11:23:30 +0200 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Updates the mute state and notifies the audio service. Call this only when holding player |
| 59 | * thread lock. |
| 60 | */ |
| 61 | void processMuteEvent_l(const sp<IAudioManager>& audioManager, |
| 62 | mute_state_t muteState) |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame^] | 63 | /* REQUIRES(MmapPlaybackThread::mLock) */ final; |
Mikhail Naganov | bf49308 | 2017-04-17 17:37:12 -0700 | [diff] [blame] | 64 | private: |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 65 | friend class MmapThread; |
| 66 | |
Mikhail Naganov | bf49308 | 2017-04-17 17:37:12 -0700 | [diff] [blame] | 67 | DISALLOW_COPY_AND_ASSIGN(MmapTrack); |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 68 | |
| 69 | // AudioBufferProvider interface |
| 70 | virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); |
| 71 | // releaseBuffer() not overridden |
| 72 | |
| 73 | // ExtendedAudioBufferProvider interface |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 74 | size_t framesReady() const final; |
| 75 | int64_t framesReleased() const final; |
| 76 | void onTimestamp(const ExtendedTimestamp ×tamp) final; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 77 | |
Andy Hung | d29af63 | 2023-06-23 19:27:19 -0700 | [diff] [blame] | 78 | const pid_t mPid; |
Eric Laurent | 331679c | 2018-04-16 17:03:16 -0700 | [diff] [blame] | 79 | bool mSilenced; // protected by MMapThread::mLock |
| 80 | bool mSilencedNotified; // protected by MMapThread::mLock |
Vlad Popa | ec1788e | 2022-08-04 11:23:30 +0200 | [diff] [blame] | 81 | |
| 82 | // TODO: replace PersistableBundle with own struct |
| 83 | // access these two variables only when holding player thread lock. |
| 84 | std::unique_ptr<os::PersistableBundle> mMuteEventExtras |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame^] | 85 | /* GUARDED_BY(MmapPlaybackThread::mLock) */; |
Vlad Popa | ec1788e | 2022-08-04 11:23:30 +0200 | [diff] [blame] | 86 | mute_state_t mMuteState |
Andy Hung | ee58e4a | 2023-07-07 13:47:37 -0700 | [diff] [blame^] | 87 | /* GUARDED_BY(MmapPlaybackThread::mLock) */; |
Eric Laurent | 6acd1d4 | 2017-01-04 14:23:29 -0800 | [diff] [blame] | 88 | }; // end of Track |
| 89 | |
Andy Hung | 8d31fd2 | 2023-06-26 19:20:57 -0700 | [diff] [blame] | 90 | } // namespace android |