blob: 259136be9f29e8ff2fffd8f52201239363e5fcf4 [file] [log] [blame]
Eric Laurent6acd1d42017-01-04 14:23:29 -08001/*
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 Hung8d31fd22023-06-26 19:20:57 -070018#pragma once
19
Andy Hung0f725b42023-07-19 11:40:07 -070020#include "TrackBase.h"
21
22#include <android/content/AttributionSourceState.h>
23
Andy Hung8d31fd22023-06-26 19:20:57 -070024namespace android {
Eric Laurent6acd1d42017-01-04 14:23:29 -080025
26// playback track
Andy Hungd29af632023-06-23 19:27:19 -070027class MmapTrack : public TrackBase, public IAfMmapTrack {
Eric Laurent6acd1d42017-01-04 14:23:29 -080028public:
Andy Hung87c693c2023-07-06 20:56:16 -070029 MmapTrack(IAfThreadBase* thread,
Kevin Rocard1f564ac2018-03-29 13:53:10 -070030 const audio_attributes_t& attr,
Eric Laurent6acd1d42017-01-04 14:23:29 -080031 uint32_t sampleRate,
32 audio_format_t format,
33 audio_channel_mask_t channelMask,
34 audio_session_t sessionId,
Kevin Rocard5f2136e2018-05-11 22:03:00 -070035 bool isOut,
Svet Ganov3e5f14f2021-05-13 22:51:08 +000036 const android::content::AttributionSourceState& attributionSource,
Eric Laurent09f1ed22019-04-24 17:45:17 -070037 pid_t creatorPid,
Andy Hung6b137d12024-08-27 22:35:17 +000038 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE,
Vlad Popa1e865e62024-08-15 19:11:42 -070039 float volume = 0.0f,
40 bool muted = false);
Andy Hungd29af632023-06-23 19:27:19 -070041 ~MmapTrack() override;
Eric Laurent6acd1d42017-01-04 14:23:29 -080042
Andy Hungd29af632023-06-23 19:27:19 -070043 status_t initCheck() const final;
44 status_t start(
45 AudioSystem::sync_event_t event, audio_session_t triggerSession) final;
46 void stop() final;
47 bool isFastTrack() const final { return false; }
48 bool isDirect() const final { return true; }
Eric Laurent6acd1d42017-01-04 14:23:29 -080049
Andy Hungd29af632023-06-23 19:27:19 -070050 void appendDumpHeader(String8& result) const final;
51 void appendDump(String8& result, bool active) const final;
Eric Laurent6acd1d42017-01-04 14:23:29 -080052
Eric Laurent331679c2018-04-16 17:03:16 -070053 // protected by MMapThread::mLock
Andy Hungd29af632023-06-23 19:27:19 -070054 void setSilenced_l(bool silenced) final { mSilenced = silenced;
Eric Laurent331679c2018-04-16 17:03:16 -070055 mSilencedNotified = false;}
56 // protected by MMapThread::mLock
Andy Hungd29af632023-06-23 19:27:19 -070057 bool isSilenced_l() const final { return mSilenced; }
Eric Laurent331679c2018-04-16 17:03:16 -070058 // protected by MMapThread::mLock
Andy Hungd29af632023-06-23 19:27:19 -070059 bool getAndSetSilencedNotified_l() final { bool silencedNotified = mSilencedNotified;
Eric Laurent331679c2018-04-16 17:03:16 -070060 mSilencedNotified = true;
61 return silencedNotified; }
Vlad Popaec1788e2022-08-04 11:23:30 +020062
63 /**
64 * Updates the mute state and notifies the audio service. Call this only when holding player
65 * thread lock.
66 */
67 void processMuteEvent_l(const sp<IAudioManager>& audioManager,
68 mute_state_t muteState)
Andy Hungee58e4a2023-07-07 13:47:37 -070069 /* REQUIRES(MmapPlaybackThread::mLock) */ final;
Andy Hung6b137d12024-08-27 22:35:17 +000070
71 // VolumePortInterface implementation
72 void setPortVolume(float volume) override {
73 mVolume = volume;
74 }
Vlad Popa1e865e62024-08-15 19:11:42 -070075 void setPortMute(bool muted) override {
Vlad Popa6e3e81e2024-10-23 19:41:59 -070076 mMutedFromPort = muted;
Vlad Popa1e865e62024-08-15 19:11:42 -070077 }
Andy Hung6b137d12024-08-27 22:35:17 +000078 float getPortVolume() const override { return mVolume; }
Vlad Popa6e3e81e2024-10-23 19:41:59 -070079 bool getPortMute() const override { return mMutedFromPort; }
Andy Hung6b137d12024-08-27 22:35:17 +000080
Andy Hungf767de02024-10-30 19:47:50 -070081 std::string trackFlagsAsString() const final { return {}; }
Mikhail Naganovbf493082017-04-17 17:37:12 -070082private:
Mikhail Naganovbf493082017-04-17 17:37:12 -070083 DISALLOW_COPY_AND_ASSIGN(MmapTrack);
Eric Laurent6acd1d42017-01-04 14:23:29 -080084
85 // AudioBufferProvider interface
86 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer);
87 // releaseBuffer() not overridden
88
89 // ExtendedAudioBufferProvider interface
Andy Hungd29af632023-06-23 19:27:19 -070090 size_t framesReady() const final;
91 int64_t framesReleased() const final;
92 void onTimestamp(const ExtendedTimestamp &timestamp) final;
Eric Laurent6acd1d42017-01-04 14:23:29 -080093
Andy Hungd29af632023-06-23 19:27:19 -070094 const pid_t mPid;
Atneya Nairb01390f2024-10-09 23:33:27 +000095 const uid_t mUid;
Eric Laurent331679c2018-04-16 17:03:16 -070096 bool mSilenced; // protected by MMapThread::mLock
97 bool mSilencedNotified; // protected by MMapThread::mLock
Vlad Popaec1788e2022-08-04 11:23:30 +020098
99 // TODO: replace PersistableBundle with own struct
100 // access these two variables only when holding player thread lock.
101 std::unique_ptr<os::PersistableBundle> mMuteEventExtras
Andy Hungee58e4a2023-07-07 13:47:37 -0700102 /* GUARDED_BY(MmapPlaybackThread::mLock) */;
Vlad Popaec1788e2022-08-04 11:23:30 +0200103 mute_state_t mMuteState
Andy Hungee58e4a2023-07-07 13:47:37 -0700104 /* GUARDED_BY(MmapPlaybackThread::mLock) */;
Vlad Popa6e3e81e2024-10-23 19:41:59 -0700105 bool mMutedFromPort;
Andy Hung6b137d12024-08-27 22:35:17 +0000106
107 float mVolume = 0.0f;
Eric Laurent6acd1d42017-01-04 14:23:29 -0800108}; // end of Track
109
Atneya Nairb01390f2024-10-09 23:33:27 +0000110} // namespace android