/* * Copyright (C) 2020 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #pragma once #include #include PATH(android/hardware/audio/FILE_VERSION/IStreamOut.h) #include PATH(android/hardware/audio/FILE_VERSION/IDevice.h) #include "stream_common.h" #include "io_thread.h" #include "primary_device.h" namespace android { namespace hardware { namespace audio { namespace CPP_VERSION { namespace implementation { using ::android::sp; using ::android::hardware::hidl_bitfield; using ::android::hardware::hidl_string; using ::android::hardware::hidl_vec; using ::android::hardware::Return; using namespace ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION; using namespace ::android::hardware::audio::CORE_TYPES_CPP_VERSION; using ::android::hardware::audio::CPP_VERSION::IStreamOut; struct StreamOut : public IStreamOut { StreamOut(sp dev, int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, hidl_vec flags, const SourceMetadata& sourceMetadata); ~StreamOut(); // IStream Return getFrameSize() override; Return getFrameCount() override; Return getBufferSize() override; Return getSupportedProfiles(getSupportedProfiles_cb _hidl_cb) override; Return getAudioProperties(getAudioProperties_cb _hidl_cb) override; Return setAudioProperties(const AudioConfigBaseOptional& config) override; Return addEffect(uint64_t effectId) override; Return removeEffect(uint64_t effectId) override; Return standby() override; Return getDevices(getDevices_cb _hidl_cb) override; Return setDevices(const hidl_vec& devices) override; Return setHwAvSync(uint32_t hwAvSync) override; Return getParameters(const hidl_vec& context, const hidl_vec& keys, getParameters_cb _hidl_cb) override; Return setParameters(const hidl_vec& context, const hidl_vec& parameters) override; Return start() override; Return stop() override; Return createMmapBuffer(int32_t minSizeFrames, createMmapBuffer_cb _hidl_cb) override; Return getMmapPosition(getMmapPosition_cb _hidl_cb) override; Return close() override; // IStreamOut Return getLatency() override; Return setVolume(float left, float right) override; Return updateSourceMetadata(const SourceMetadata& sourceMetadata) override; Return prepareForWriting(uint32_t frameSize, uint32_t framesCount, prepareForWriting_cb _hidl_cb) override; Return getRenderPosition(getRenderPosition_cb _hidl_cb) override; Return getNextWriteTimestamp(getNextWriteTimestamp_cb _hidl_cb) override; Return setCallback(const sp& callback) override; Return clearCallback() override; Return setEventCallback(const sp& callback) override; Return supportsPauseAndResume(supportsPauseAndResume_cb _hidl_cb) override; Return pause() override; Return resume() override; Return supportsDrain() override; Return drain(AudioDrain type) override; Return flush() override; Return getPresentationPosition(getPresentationPosition_cb _hidl_cb) override; Return selectPresentation(int32_t presentationId, int32_t programId) override; Return getDualMonoMode(getDualMonoMode_cb _hidl_cb) override; Return setDualMonoMode(DualMonoMode mode) override; Return getAudioDescriptionMixLevel(getAudioDescriptionMixLevel_cb _hidl_cb) override; Return setAudioDescriptionMixLevel(float leveldB) override; Return getPlaybackRateParameters(getPlaybackRateParameters_cb _hidl_cb) override; Return setPlaybackRateParameters(const PlaybackRate &playbackRate) override; #if MAJOR_VERSION == 7 && MINOR_VERSION == 1 Return setLatencyMode(LatencyMode mode) override; Return getRecommendedLatencyModes(getRecommendedLatencyModes_cb _hidl_cb) override; Return setLatencyModeCallback( const sp& callback) override; #endif void setMasterVolume(float volume); float getEffectiveVolume() const { return mEffectiveVolume; } const DeviceAddress &getDeviceAddress() const { return mCommon.m_device; } const AudioConfig &getAudioConfig() const { return mCommon.m_config; } const hidl_vec &getAudioOutputFlags() const { return mCommon.m_flags; } static bool validateDeviceAddress(const DeviceAddress& device); static bool validateFlags(const hidl_vec& flags); static bool validateSourceMetadata(const SourceMetadata& sourceMetadata); private: Result closeImpl(bool fromDctor); void updateEffectiveVolumeLocked(); sp mDev; const StreamCommon mCommon; const SourceMetadata mSourceMetadata; std::unique_ptr mWriteThread; float mMasterVolume = 1.0f; // requires mMutex float mStreamVolume = 1.0f; // requires mMutex std::atomic mEffectiveVolume = 1.0f; std::mutex mMutex; }; } // namespace implementation } // namespace CPP_VERSION } // namespace audio } // namespace hardware } // namespace android