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 <hardware/bluetooth.h> 21 #include <raw_address.h> 22 23 #include <variant> 24 25 namespace bluetooth { 26 namespace vc { 27 28 enum class ConnectionState { 29 DISCONNECTED = 0, 30 CONNECTING, 31 CONNECTED, 32 DISCONNECTING 33 }; 34 35 class VolumeControlCallbacks { 36 public: 37 virtual ~VolumeControlCallbacks() = default; 38 39 /** Callback for profile connection state change */ 40 virtual void OnConnectionState(ConnectionState state, 41 const RawAddress& address) = 0; 42 43 /* Callback for the volume change changed on the device */ 44 virtual void OnVolumeStateChanged(const RawAddress& address, uint8_t volume, 45 bool mute, bool isAutonomous) = 0; 46 47 /* Callback for the volume change changed on the group*/ 48 virtual void OnGroupVolumeStateChanged(int group_id, uint8_t volume, 49 bool mute, bool isAutonomous) = 0; 50 51 virtual void OnDeviceAvailable(const RawAddress& address, 52 uint8_t num_offset) = 0; 53 54 /* Callbacks for Volume Offset Control Service (VOCS) - Extended Audio Outputs 55 */ 56 virtual void OnExtAudioOutVolumeOffsetChanged(const RawAddress& address, 57 uint8_t ext_output_id, 58 int16_t offset) = 0; 59 virtual void OnExtAudioOutLocationChanged(const RawAddress& address, 60 uint8_t ext_output_id, 61 uint32_t location) = 0; 62 virtual void OnExtAudioOutDescriptionChanged(const RawAddress& address, 63 uint8_t ext_output_id, 64 std::string descr) = 0; 65 }; 66 67 class VolumeControlInterface { 68 public: 69 virtual ~VolumeControlInterface() = default; 70 71 /** Register the Volume Control callbacks */ 72 virtual void Init(VolumeControlCallbacks* callbacks) = 0; 73 74 /** Closes the interface */ 75 virtual void Cleanup(void) = 0; 76 77 /** Connect to Volume Control */ 78 virtual void Connect(const RawAddress& address) = 0; 79 80 /** Disconnect from Volume Control */ 81 virtual void Disconnect(const RawAddress& address) = 0; 82 83 /** Called when Volume control devices is unbonded */ 84 virtual void RemoveDevice(const RawAddress& address) = 0; 85 86 /** Set the volume */ 87 virtual void SetVolume(std::variant<RawAddress, int> addr_or_group_id, 88 uint8_t volume) = 0; 89 /** Mute the volume */ 90 virtual void Mute(std::variant<RawAddress, int> addr_or_group_id) = 0; 91 92 /** Unmute the volume */ 93 virtual void Unmute(std::variant<RawAddress, int> addr_or_group_id) = 0; 94 95 virtual void GetExtAudioOutVolumeOffset(const RawAddress& address, 96 uint8_t ext_output_id) = 0; 97 virtual void SetExtAudioOutVolumeOffset(const RawAddress& address, 98 uint8_t ext_output_id, 99 int16_t offset_val) = 0; 100 virtual void GetExtAudioOutLocation(const RawAddress& address, 101 uint8_t ext_output_id) = 0; 102 virtual void SetExtAudioOutLocation(const RawAddress& address, 103 uint8_t ext_output_id, 104 uint32_t location) = 0; 105 virtual void GetExtAudioOutDescription(const RawAddress& address, 106 uint8_t ext_output_id) = 0; 107 virtual void SetExtAudioOutDescription(const RawAddress& address, 108 uint8_t ext_output_id, 109 std::string descr) = 0; 110 }; 111 112 } /* namespace vc */ 113 } /* namespace bluetooth */ 114