15
15
*/
16
16
17
17
#include " DeviceAddressHelper.hpp"
18
+ #include " StringTokenizer.hpp"
18
19
#include < sstream>
19
20
20
21
std::string AndroidDeviceAddressHelper::getMacAddressString (MacAddress macAddress)
@@ -28,26 +29,91 @@ std::string AndroidDeviceAddressHelper::getMacAddressString(MacAddress macAddres
28
29
return ss.str ();
29
30
}
30
31
32
+ struct stDeviceString
33
+ {
34
+ AudioDevice device;
35
+ std::string description;
36
+ stDeviceString (AudioDevice device, std::string description):device(device), description(description){};
37
+ };
38
+
39
+ const static stDeviceString tbl[] =
40
+ {
41
+ stDeviceString (AUDIO_DEVICE_OUT_DEFAULT, " AUDIO_DEVICE_OUT_DEFAULT" ),
42
+ stDeviceString (AUDIO_DEVICE_OUT_LINE, " AUDIO_DEVICE_OUT_LINE" ),
43
+ stDeviceString (AUDIO_DEVICE_OUT_SPDIF, " AUDIO_DEVICE_OUT_SPDIF" ),
44
+ stDeviceString (AUDIO_DEVICE_OUT_HDMI_EARC, " AUDIO_DEVICE_OUT_HDMI_EARC" ),
45
+ stDeviceString (AUDIO_DEVICE_OUT_HDMI_ARC, " AUDIO_DEVICE_OUT_HDMI_ARC" ),
46
+ stDeviceString (AUDIO_DEVICE_OUT_USB_DEVICE, " AUDIO_DEVICE_OUT_USB_DEVICE" ),
47
+ stDeviceString (AUDIO_DEVICE_OUT_HDMI, " AUDIO_DEVICE_OUT_HDMI" ),
48
+ stDeviceString (AUDIO_DEVICE_OUT_BLUETOOTH_A2DP, " AUDIO_DEVICE_OUT_BLUETOOTH_A2DP" ),
49
+ stDeviceString (AUDIO_DEVICE_OUT_SPEAKER, " AUDIO_DEVICE_OUT_SPEAKER" ),
50
+ stDeviceString (AUDIO_DEVICE_OUT_BLUETOOTH_SCO, " AUDIO_DEVICE_OUT_BLUETOOTH_SCO" ),
51
+ stDeviceString (AUDIO_DEVICE_IN_BUILTIN_MIC, " AUDIO_DEVICE_IN_BUILTIN_MIC" ),
52
+ stDeviceString (AUDIO_DEVICE_IN_HDMI, " AUDIO_DEVICE_IN_HDMI" ),
53
+ stDeviceString (AUDIO_DEVICE_IN_USB_DEVICE, " AUDIO_DEVICE_IN_USB_DEVICE" ),
54
+ stDeviceString (AUDIO_DEVICE_IN_LINE, " AUDIO_DEVICE_IN_LINE" ),
55
+ stDeviceString (AUDIO_DEVICE_IN_DEFAULT, " AUDIO_DEVICE_IN_DEFAULT" ),
56
+ stDeviceString (AUDIO_DEVICE_IN_DEFAULT, " " ),
57
+ };
58
+
59
+
60
+ std::string AndroidDeviceAddressHelper::getDeviceString (AudioDevice device)
61
+ {
62
+ std::string result;
63
+
64
+ for ( int i=0 ; tbl[i].device != AUDIO_DEVICE_IN_DEFAULT && !tbl[i].description .empty (); ){
65
+ if ( tbl[i].device == device ){
66
+ result = tbl[i].description ;
67
+ break ;
68
+ }
69
+ }
70
+
71
+ return result;
72
+ }
73
+
74
+ AudioDevice AndroidDeviceAddressHelper::getDeviceFromDeviceString (std::string deviceString)
75
+ {
76
+ AudioDevice result = AUDIO_DEVICE_OUT_DEFAULT;
77
+
78
+ for ( int i=0 ; tbl[i].device != AUDIO_DEVICE_IN_DEFAULT && !tbl[i].description .empty (); ){
79
+ if ( tbl[i].description == deviceString ){
80
+ result = tbl[i].device ;
81
+ break ;
82
+ }
83
+ }
84
+
85
+ return result;
86
+ }
87
+
31
88
std::tuple<AudioDevice, std::string, std::string> AndroidDeviceAddressHelper::getTupleFromDeviceAddreess (DeviceAddress deviceAddress)
32
89
{
33
90
return std::make_tuple ( deviceAddress.device , getMacAddressString (deviceAddress.address .mac ), deviceAddress.busAddress );
34
91
}
35
92
36
93
std::string AndroidDeviceAddressHelper::getStringFromDeviceAddr (DeviceAddress deviceAddress)
37
94
{
38
- // TODO : FIX this
39
95
auto && id = getTupleFromDeviceAddreess (deviceAddress);
40
96
if ( !mDeviceConnected .contains ( id ) ){
41
97
mDeviceConnected .insert_or_assign ( id, std::make_tuple (deviceAddress, false ) );
42
98
}
43
99
44
- return deviceAddress.busAddress ;
100
+ // TODO : FIX this. Add the other identifier such as MacAddress, etc.
101
+ return deviceAddress.busAddress .empty () ? getDeviceString (deviceAddress.device ) : getDeviceString (deviceAddress.device ) + " :" + deviceAddress.busAddress ;
45
102
}
46
103
47
104
DeviceAddress AndroidDeviceAddressHelper::getDeviceAddrFromString (std::string deviceAddrString)
48
105
{
49
106
DeviceAddress deviceAddr;
50
- deviceAddr.busAddress = deviceAddrString;
107
+ StringTokenizer tok (deviceAddrString, " :" );
108
+ if ( tok.hasNext () ){
109
+ deviceAddr.device = getDeviceFromDeviceString ( tok.getNext () );
110
+ if ( tok.hasNext () ){
111
+ deviceAddr.busAddress = tok.getNext ();
112
+ }
113
+ } else {
114
+ deviceAddr.device = getDeviceFromDeviceString ( deviceAddrString );
115
+ }
116
+
51
117
return deviceAddr;
52
118
}
53
119
0 commit comments