1 /* 2 * Copyright 2021 HIMSA II K/S - www.himsa.com. 3 * Represented by EHIMA - www.ehima.com 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 <aics/api.h> 21 #include <hardware/bluetooth.h> 22 23 #include <string> 24 #include <variant> 25 26 #include "types/raw_address.h" 27 28 namespace bluetooth { 29 namespace vc { 30 31 // Must be kept in sync with BluetoothProfile.java 32 enum class ConnectionState { DISCONNECTED = 0, CONNECTING, CONNECTED, DISCONNECTING }; 33 34 /* Audio input types */ 35 enum class VolumeInputType : uint8_t { 36 Unspecified = 0x00, 37 Bluetooth, 38 Microphone, 39 Analog, 40 Digital, 41 Radio, 42 Streaming, 43 Ambient, 44 RFU 45 }; 46 47 enum class VolumeInputStatus : uint8_t { Inactive = 0x00, Active, RFU }; 48 49 class VolumeControlCallbacks { 50 public: 51 virtual ~VolumeControlCallbacks() = default; 52 53 /** Callback for profile connection state change */ 54 virtual void OnConnectionState(ConnectionState state, const RawAddress& address) = 0; 55 56 /* Callback for the volume change changed on the device */ 57 virtual void OnVolumeStateChanged(const RawAddress& address, uint8_t volume, bool mute, 58 uint8_t flags, bool isAutonomous) = 0; 59 60 /* Callback for the volume change changed on the group*/ 61 virtual void OnGroupVolumeStateChanged(int group_id, uint8_t volume, bool mute, 62 bool isAutonomous) = 0; 63 64 virtual void OnDeviceAvailable(const RawAddress& address, uint8_t num_offset, 65 uint8_t num_input) = 0; 66 67 /* Callbacks for Volume Offset Control Service (VOCS) - Extended Audio Outputs 68 */ 69 virtual void OnExtAudioOutVolumeOffsetChanged(const RawAddress& address, uint8_t ext_output_id, 70 int16_t offset) = 0; 71 virtual void OnExtAudioOutLocationChanged(const RawAddress& address, uint8_t ext_output_id, 72 uint32_t location) = 0; 73 virtual void OnExtAudioOutDescriptionChanged(const RawAddress& address, uint8_t ext_output_id, 74 std::string descr) = 0; 75 76 /* Callbacks for Audio Input Stream (AIS) - Extended Audio Inputs */ 77 virtual void OnExtAudioInStateChanged(const RawAddress& address, uint8_t ext_input_id, 78 int8_t gain_setting, bluetooth::aics::Mute mute, 79 bluetooth::aics::GainMode gain_mode) = 0; 80 virtual void OnExtAudioInSetGainSettingFailed(const RawAddress& address, 81 uint8_t ext_input_id) = 0; 82 virtual void OnExtAudioInSetMuteFailed(const RawAddress& address, uint8_t ext_input_id) = 0; 83 virtual void OnExtAudioInSetGainModeFailed(const RawAddress& address, uint8_t ext_input_id) = 0; 84 85 virtual void OnExtAudioInStatusChanged(const RawAddress& address, uint8_t ext_input_id, 86 VolumeInputStatus status) = 0; 87 88 virtual void OnExtAudioInTypeChanged(const RawAddress& address, uint8_t ext_input_id, 89 VolumeInputType type) = 0; 90 91 virtual void OnExtAudioInGainSettingPropertiesChanged(const RawAddress& address, 92 uint8_t ext_input_id, uint8_t unit, 93 int8_t min, int8_t max) = 0; 94 95 virtual void OnExtAudioInDescriptionChanged(const RawAddress& address, uint8_t ext_input_id, 96 std::string description, bool is_writable) = 0; 97 }; 98 99 class VolumeControlInterface { 100 public: 101 virtual ~VolumeControlInterface() = default; 102 103 /** Register the Volume Control callbacks */ 104 virtual void Init(VolumeControlCallbacks* callbacks) = 0; 105 106 /** Closes the interface */ 107 virtual void Cleanup(void) = 0; 108 109 /** Connect to Volume Control */ 110 virtual void Connect(const RawAddress& address) = 0; 111 112 /** Disconnect from Volume Control */ 113 virtual void Disconnect(const RawAddress& address) = 0; 114 115 /** Called when Volume control devices is unbonded */ 116 virtual void RemoveDevice(const RawAddress& address) = 0; 117 118 /** Set the volume */ 119 virtual void SetVolume(std::variant<RawAddress, int> addr_or_group_id, uint8_t volume) = 0; 120 /** Mute the volume */ 121 virtual void Mute(std::variant<RawAddress, int> addr_or_group_id) = 0; 122 123 /** Unmute the volume */ 124 virtual void Unmute(std::variant<RawAddress, int> addr_or_group_id) = 0; 125 126 virtual void GetExtAudioOutVolumeOffset(const RawAddress& address, uint8_t ext_output_id) = 0; 127 virtual void SetExtAudioOutVolumeOffset(const RawAddress& address, uint8_t ext_output_id, 128 int16_t offset_val) = 0; 129 virtual void GetExtAudioOutLocation(const RawAddress& address, uint8_t ext_output_id) = 0; 130 virtual void SetExtAudioOutLocation(const RawAddress& address, uint8_t ext_output_id, 131 uint32_t location) = 0; 132 virtual void GetExtAudioOutDescription(const RawAddress& address, uint8_t ext_output_id) = 0; 133 virtual void SetExtAudioOutDescription(const RawAddress& address, uint8_t ext_output_id, 134 std::string descr) = 0; 135 virtual void GetExtAudioInState(const RawAddress& address, uint8_t ext_input_id) = 0; 136 virtual void GetExtAudioInStatus(const RawAddress& address, uint8_t ext_input_id) = 0; 137 virtual void GetExtAudioInType(const RawAddress& address, uint8_t ext_input_id) = 0; 138 virtual void GetExtAudioInGainProps(const RawAddress& address, uint8_t ext_input_id) = 0; 139 virtual void GetExtAudioInDescription(const RawAddress& address, uint8_t ext_input_id) = 0; 140 virtual bool SetExtAudioInDescription(const RawAddress& address, uint8_t ext_input_id, 141 std::string descr) = 0; 142 virtual bool SetExtAudioInGainSetting(const RawAddress& address, uint8_t ext_input_id, 143 int8_t gain_setting) = 0; 144 virtual bool SetExtAudioInGainMode(const RawAddress& address, uint8_t ext_input_id, 145 bluetooth::aics::GainMode gain_mode) = 0; 146 virtual bool SetExtAudioInMute(const RawAddress& address, uint8_t ext_input_id, 147 bluetooth::aics::Mute mute) = 0; 148 }; 149 150 } /* namespace vc */ 151 } /* namespace bluetooth */ 152 153 namespace std { 154 template <> 155 struct formatter<bluetooth::vc::VolumeInputType> : enum_formatter<bluetooth::vc::VolumeInputType> { 156 }; 157 template <> 158 struct formatter<bluetooth::vc::VolumeInputStatus> 159 : enum_formatter<bluetooth::vc::VolumeInputStatus> {}; 160 } // namespace std 161