1 /*
2  * Copyright (C) 2021 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 #ifndef GD_RUST_TOPSHIM_BTAV_BTAV_SHIM_H
17 #define GD_RUST_TOPSHIM_BTAV_BTAV_SHIM_H
18 
19 #include <memory>
20 
21 #include "audio_hal_interface/a2dp_encoding_host.h"
22 #include "include/hardware/avrcp/avrcp.h"
23 #include "include/hardware/bt_av.h"
24 #include "rust/cxx.h"
25 #include "types/raw_address.h"
26 
27 namespace bluetooth {
28 namespace topshim {
29 namespace rust {
30 
31 struct A2dpCodecConfig;
32 struct RustPresentationPosition;
33 struct RustPlayStatus;
34 
35 class A2dpIntf {
36  public:
A2dpIntf(const btav_source_interface_t * intf)37   A2dpIntf(const btav_source_interface_t* intf) : intf_(intf){};
38   ~A2dpIntf();
39 
40   // interface for Settings
41   int init() const;
42   uint32_t connect(RawAddress addr) const;
43   uint32_t disconnect(RawAddress addr) const;
44   int set_silence_device(RawAddress addr, bool silent) const;
45   int set_active_device(RawAddress addr) const;
46   int config_codec(RawAddress addr, ::rust::Vec<A2dpCodecConfig> codec_preferences) const;
47   void cleanup() const;
48 
49   // interface for Audio server
50   bool set_audio_config(A2dpCodecConfig rconfig) const;
51   bool start_audio_request() const;
52   bool stop_audio_request() const;
53   bool suspend_audio_request() const;
54   RustPresentationPosition get_presentation_position() const;
55 
56  private:
57   const btav_source_interface_t* intf_;
58 };
59 
60 std::unique_ptr<A2dpIntf> GetA2dpProfile(const unsigned char* btif);
61 
62 class AvrcpIntf {
63  public:
AvrcpIntf(bluetooth::avrcp::ServiceInterface * intf)64   AvrcpIntf(bluetooth::avrcp::ServiceInterface* intf) : intf_(intf) {}
65   ~AvrcpIntf();
66 
67   void init();
68   void cleanup();
69   uint32_t connect(RawAddress addr);
70   uint32_t disconnect(RawAddress addr);
71 
72   // interface for Audio server
73   void set_volume(int8_t volume);
74 
75   void set_playback_status(const ::rust::String& status);
76   void set_position(int64_t position_us);
77   void set_metadata(
78       const ::rust::String& title, const ::rust::String& artist, const ::rust::String& album, int64_t length_us);
79   // Used by qualification
80   uint16_t add_player(const ::rust::String& name, bool browsing_supported);
81 
82  private:
83   bluetooth::avrcp::ServiceInterface* intf_;
84 };
85 
86 std::unique_ptr<AvrcpIntf> GetAvrcpProfile(const unsigned char* btif);
87 
88 }  // namespace rust
89 }  // namespace topshim
90 }  // namespace bluetooth
91 
92 #endif  // GD_RUST_TOPSHIM_BTAV_BTAV_SHIM_H
93