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 18 #pragma once 19 20 #include "TrackBase.h" 21 22 #include <android/content/AttributionSourceState.h> 23 24 namespace android { 25 26 // playback track 27 class MmapTrack : public TrackBase, public IAfMmapTrack { 28 public: 29 MmapTrack(IAfThreadBase* thread, 30 const audio_attributes_t& attr, 31 uint32_t sampleRate, 32 audio_format_t format, 33 audio_channel_mask_t channelMask, 34 audio_session_t sessionId, 35 bool isOut, 36 const android::content::AttributionSourceState& attributionSource, 37 pid_t creatorPid, 38 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE, 39 float volume = 0.0f, 40 bool muted = false); 41 ~MmapTrack() override; 42 43 status_t initCheck() const final; 44 status_t start( 45 AudioSystem::sync_event_t event, audio_session_t triggerSession) final; 46 void stop() final; isFastTrack()47 bool isFastTrack() const final { return false; } isDirect()48 bool isDirect() const final { return true; } 49 50 void appendDumpHeader(String8& result) const final; 51 void appendDump(String8& result, bool active) const final; 52 53 // protected by MMapThread::mLock setSilenced_l(bool silenced)54 void setSilenced_l(bool silenced) final { mSilenced = silenced; 55 mSilencedNotified = false;} 56 // protected by MMapThread::mLock isSilenced_l()57 bool isSilenced_l() const final { return mSilenced; } 58 // protected by MMapThread::mLock getAndSetSilencedNotified_l()59 bool getAndSetSilencedNotified_l() final { bool silencedNotified = mSilencedNotified; 60 mSilencedNotified = true; 61 return silencedNotified; } 62 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) 69 /* REQUIRES(MmapPlaybackThread::mLock) */ final; 70 71 // VolumePortInterface implementation setPortVolume(float volume)72 void setPortVolume(float volume) override { 73 mVolume = volume; 74 } setPortMute(bool muted)75 void setPortMute(bool muted) override { 76 mMutedFromPort = muted; 77 } getPortVolume()78 float getPortVolume() const override { return mVolume; } getPortMute()79 bool getPortMute() const override { return mMutedFromPort; } 80 trackFlagsAsString()81 std::string trackFlagsAsString() const final { return {}; } 82 private: 83 DISALLOW_COPY_AND_ASSIGN(MmapTrack); 84 85 // AudioBufferProvider interface 86 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); 87 // releaseBuffer() not overridden 88 89 // ExtendedAudioBufferProvider interface 90 size_t framesReady() const final; 91 int64_t framesReleased() const final; 92 void onTimestamp(const ExtendedTimestamp ×tamp) final; 93 94 const pid_t mPid; 95 const uid_t mUid; 96 bool mSilenced; // protected by MMapThread::mLock 97 bool mSilencedNotified; // protected by MMapThread::mLock 98 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 102 /* GUARDED_BY(MmapPlaybackThread::mLock) */; 103 mute_state_t mMuteState 104 /* GUARDED_BY(MmapPlaybackThread::mLock) */; 105 bool mMutedFromPort; 106 107 float mVolume = 0.0f; 108 }; // end of Track 109 110 } // namespace android 111