1 /* 2 * Copyright (C) 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #pragma once 18 #include <android/hardware/audio/6.0/IPrimaryDevice.h> 19 #include <mutex> 20 #include <unordered_map> 21 #include <unordered_set> 22 23 namespace android { 24 namespace hardware { 25 namespace audio { 26 namespace V6_0 { 27 namespace implementation { 28 29 using ::android::sp; 30 using ::android::hardware::hidl_bitfield; 31 using ::android::hardware::hidl_string; 32 using ::android::hardware::hidl_vec; 33 using ::android::hardware::Return; 34 35 using namespace ::android::hardware::audio::common::V6_0; 36 using namespace ::android::hardware::audio::V6_0; 37 38 struct StreamIn; 39 struct StreamOut; 40 41 struct PrimaryDevice : public IPrimaryDevice { 42 PrimaryDevice(); 43 44 Return<Result> initCheck() override; 45 Return<Result> setMasterVolume(float volume) override; 46 Return<void> getMasterVolume(getMasterVolume_cb _hidl_cb) override; 47 Return<Result> setMicMute(bool mute) override; 48 Return<void> getMicMute(getMicMute_cb _hidl_cb) override; 49 Return<Result> setMasterMute(bool mute) override; 50 Return<void> getMasterMute(getMasterMute_cb _hidl_cb) override; 51 Return<void> getInputBufferSize(const AudioConfig& config, 52 getInputBufferSize_cb _hidl_cb) override; 53 Return<void> openOutputStream(int32_t ioHandle, 54 const DeviceAddress& device, 55 const AudioConfig& config, 56 hidl_bitfield<AudioOutputFlag> flags, 57 const SourceMetadata& sourceMetadata, 58 openOutputStream_cb _hidl_cb) override; 59 Return<void> openInputStream(int32_t ioHandle, 60 const DeviceAddress& device, 61 const AudioConfig& config, 62 hidl_bitfield<AudioInputFlag> flags, 63 const SinkMetadata& sinkMetadata, 64 openInputStream_cb _hidl_cb) override; 65 Return<bool> supportsAudioPatches() override; 66 Return<void> createAudioPatch(const hidl_vec<AudioPortConfig>& sources, 67 const hidl_vec<AudioPortConfig>& sinks, 68 createAudioPatch_cb _hidl_cb) override; 69 Return<void> updateAudioPatch(AudioPatchHandle previousPatch, 70 const hidl_vec<AudioPortConfig>& sources, 71 const hidl_vec<AudioPortConfig>& sinks, 72 updateAudioPatch_cb _hidl_cb) override; 73 Return<Result> releaseAudioPatch(AudioPatchHandle patch) override; 74 Return<void> getAudioPort(const AudioPort& port, getAudioPort_cb _hidl_cb) override; 75 Return<Result> setAudioPortConfig(const AudioPortConfig& config) override; 76 Return<Result> setScreenState(bool turnedOn) override; 77 Return<void> getHwAvSync(getHwAvSync_cb _hidl_cb) override; 78 Return<void> getParameters(const hidl_vec<ParameterValue>& context, 79 const hidl_vec<hidl_string>& keys, 80 getParameters_cb _hidl_cb) override; 81 Return<Result> setParameters(const hidl_vec<ParameterValue>& context, 82 const hidl_vec<ParameterValue>& parameters) override; 83 Return<void> getMicrophones(getMicrophones_cb _hidl_cb) override; 84 Return<Result> setConnectedState(const DeviceAddress& address, bool connected) override; 85 Return<Result> close() override; 86 Return<Result> addDeviceEffect(AudioPortHandle device, uint64_t effectId) override; 87 Return<Result> removeDeviceEffect(AudioPortHandle device, uint64_t effectId) override; 88 Return<Result> setVoiceVolume(float volume) override; 89 Return<Result> setMode(AudioMode mode) override; 90 Return<Result> setBtScoHeadsetDebugName(const hidl_string& name) override; 91 Return<void> getBtScoNrecEnabled(getBtScoNrecEnabled_cb _hidl_cb) override; 92 Return<Result> setBtScoNrecEnabled(bool enabled) override; 93 Return<void> getBtScoWidebandEnabled(getBtScoWidebandEnabled_cb _hidl_cb) override; 94 Return<Result> setBtScoWidebandEnabled(bool enabled) override; 95 Return<void> getTtyMode(getTtyMode_cb _hidl_cb) override; 96 Return<Result> setTtyMode(IPrimaryDevice::TtyMode mode) override; 97 Return<void> getHacEnabled(getHacEnabled_cb _hidl_cb) override; 98 Return<Result> setHacEnabled(bool enabled) override; 99 Return<void> getBtHfpEnabled(getBtHfpEnabled_cb _hidl_cb) override; 100 Return<Result> setBtHfpEnabled(bool enabled) override; 101 Return<Result> setBtHfpSampleRate(uint32_t sampleRateHz) override; 102 Return<Result> setBtHfpVolume(float volume) override; 103 Return<Result> updateRotation(IPrimaryDevice::Rotation rotation) override; 104 105 private: 106 friend StreamIn; 107 friend StreamOut; 108 109 void unrefDevice(StreamIn *); 110 void unrefDevice(StreamOut *); 111 void updateOutputStreamVolume(float masterVolume) const; 112 void updateInputStreamMicMute(bool micMute) const; 113 114 struct AudioPatch { 115 AudioPortConfig source; 116 AudioPortConfig sink; 117 }; 118 119 AudioPatchHandle mNextAudioPatchHandle = 0; 120 std::unordered_map<AudioPatchHandle, AudioPatch> mAudioPatches; 121 122 std::unordered_set<StreamIn *> mInputStreams; // requires mMutex 123 std::unordered_set<StreamOut *> mOutputStreams; // requires mMutex 124 mutable std::mutex mMutex; 125 126 float mMasterVolume = 1.0f; 127 bool mMasterMute = false; 128 bool mMicMute = false; 129 }; 130 131 } // namespace implementation 132 } // namespace V6_0 133 } // namespace audio 134 } // namespace hardware 135 } // namespace android 136