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 #include <media/AppOpsSession.h> 24 25 namespace android { 26 27 // playback track 28 class MmapTrack : public TrackBase, public IAfMmapTrack { 29 public: 30 MmapTrack(IAfThreadBase* thread, 31 const audio_attributes_t& attr, 32 uint32_t sampleRate, 33 audio_format_t format, 34 audio_channel_mask_t channelMask, 35 audio_session_t sessionId, 36 bool isOut, 37 const android::content::AttributionSourceState& attributionSource, 38 pid_t creatorPid, 39 audio_port_handle_t portId = AUDIO_PORT_HANDLE_NONE, 40 float volume = 0.0f, 41 bool muted = false); 42 ~MmapTrack() override; 43 44 status_t initCheck() const final; 45 status_t start( 46 AudioSystem::sync_event_t event, audio_session_t triggerSession) final; 47 void stop() final; isFastTrack()48 bool isFastTrack() const final { return false; } isDirect()49 bool isDirect() const final { return true; } 50 51 void appendDumpHeader(String8& result) const final; 52 void appendDump(String8& result, bool active) const final; 53 54 // protected by MMapThread::mLock setSilenced_l(bool silenced)55 void setSilenced_l(bool silenced) final { mSilenced = silenced; 56 mSilencedNotified = false;} 57 // protected by MMapThread::mLock isSilenced_l()58 bool isSilenced_l() const final { return mSilenced; } 59 // protected by MMapThread::mLock getAndSetSilencedNotified_l()60 bool getAndSetSilencedNotified_l() final { bool silencedNotified = mSilencedNotified; 61 mSilencedNotified = true; 62 return silencedNotified; } 63 trackFlagsAsString()64 std::string trackFlagsAsString() const final { return {}; } 65 private: 66 DISALLOW_COPY_AND_ASSIGN(MmapTrack); 67 68 // AudioBufferProvider interface 69 virtual status_t getNextBuffer(AudioBufferProvider::Buffer* buffer); 70 // releaseBuffer() not overridden 71 72 // ExtendedAudioBufferProvider interface 73 size_t framesReady() const final; 74 int64_t framesReleased() const final; 75 void onTimestamp(const ExtendedTimestamp ×tamp) final; 76 77 const pid_t mPid; 78 const uid_t mUid; 79 bool mSilenced; // protected by MMapThread::mLock 80 bool mSilencedNotified; // protected by MMapThread::mLock 81 }; // end of Track 82 83 } // namespace android 84