/* * 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 #include #include namespace android { namespace hardware { namespace audio { namespace V6_0 { 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::V6_0; using namespace ::android::hardware::audio::V6_0; struct StreamIn; struct StreamOut; struct PrimaryDevice : public IPrimaryDevice { PrimaryDevice(); Return initCheck() override; Return setMasterVolume(float volume) override; Return getMasterVolume(getMasterVolume_cb _hidl_cb) override; Return setMicMute(bool mute) override; Return getMicMute(getMicMute_cb _hidl_cb) override; Return setMasterMute(bool mute) override; Return getMasterMute(getMasterMute_cb _hidl_cb) override; Return getInputBufferSize(const AudioConfig& config, getInputBufferSize_cb _hidl_cb) override; Return openOutputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, hidl_bitfield flags, const SourceMetadata& sourceMetadata, openOutputStream_cb _hidl_cb) override; Return openInputStream(int32_t ioHandle, const DeviceAddress& device, const AudioConfig& config, hidl_bitfield flags, const SinkMetadata& sinkMetadata, openInputStream_cb _hidl_cb) override; Return supportsAudioPatches() override; Return createAudioPatch(const hidl_vec& sources, const hidl_vec& sinks, createAudioPatch_cb _hidl_cb) override; Return releaseAudioPatch(AudioPatchHandle patch) override; Return getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override; Return setAudioPortConfig(const AudioPortConfig& config) override; Return setScreenState(bool turnedOn) override; Return getHwAvSync(getHwAvSync_cb _hidl_cb) 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 getMicrophones(getMicrophones_cb _hidl_cb) override; Return setConnectedState(const DeviceAddress& address, bool connected) override; Return close() override; Return addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; Return setVoiceVolume(float volume) override; Return setMode(AudioMode mode) override; Return setBtScoHeadsetDebugName(const hidl_string& name) override; Return getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) override; Return setBtScoNrecEnabled(bool enabled) override; Return getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) override; Return setBtScoWidebandEnabled(bool enabled) override; Return getTtyMode(getTtyMode_cb _hidl_cb) override; Return setTtyMode(IPrimaryDevice::TtyMode mode) override; Return getHacEnabled(getHacEnabled_cb _hidl_cb) override; Return setHacEnabled(bool enabled) override; Return getBtHfpEnabled(getBtHfpEnabled_cb _hidl_cb) override; Return setBtHfpEnabled(bool enabled) override; Return setBtHfpSampleRate(uint32_t sampleRateHz) override; Return setBtHfpVolume(float volume) override; Return updateRotation(IPrimaryDevice::Rotation rotation) override; private: friend StreamIn; friend StreamOut; void unrefDevice(StreamIn *); void unrefDevice(StreamOut *); void updateOutputStreamVolume(float masterVolume) const; void updateInputStreamMicMute(bool micMute) const; struct AudioPatch { AudioPortConfig source; AudioPortConfig sink; }; AudioPatchHandle mNextAudioPatchHandle = 0; std::unordered_map mAudioPatches; std::unordered_set mInputStreams; // requires mMutex std::unordered_set mOutputStreams; // requires mMutex mutable std::mutex mMutex; float mMasterVolume = 1.0f; bool mMasterMute = false; bool mMicMute = false; }; } // namespace implementation } // namespace V6_0 } // namespace audio } // namespace hardware } // namespace android