blob: e6691851bbaf3175c4003430208a5a763e9f322d [file] [log] [blame]
Mikhail Naganov10548292016-10-31 10:39:47 -07001/*
2 * Copyright (C) 2016 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#include <stdio.h>
18
19#include "Conversions.h"
20
21namespace android {
22namespace hardware {
23namespace audio {
24namespace V2_0 {
25namespace implementation {
26
27std::string deviceAddressToHal(const DeviceAddress& address) {
28 // HAL assumes that the address is NUL-terminated.
29 char halAddress[AUDIO_DEVICE_MAX_ADDRESS_LEN];
30 memset(halAddress, 0, sizeof(halAddress));
31 uint32_t halDevice = static_cast<uint32_t>(address.device);
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080032 const bool isInput = (halDevice & AUDIO_DEVICE_BIT_IN) != 0;
33 if (isInput) halDevice &= ~AUDIO_DEVICE_BIT_IN;
34 if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0)
35 || (isInput && (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0)) {
Mikhail Naganov10548292016-10-31 10:39:47 -070036 snprintf(halAddress, sizeof(halAddress),
37 "%02X:%02X:%02X:%02X:%02X:%02X",
38 address.address.mac[0], address.address.mac[1], address.address.mac[2],
39 address.address.mac[3], address.address.mac[4], address.address.mac[5]);
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080040 } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_IP) != 0)
41 || (isInput && (halDevice & AUDIO_DEVICE_IN_IP) != 0)) {
Mikhail Naganov10548292016-10-31 10:39:47 -070042 snprintf(halAddress, sizeof(halAddress),
43 "%d.%d.%d.%d",
44 address.address.ipv4[0], address.address.ipv4[1],
45 address.address.ipv4[2], address.address.ipv4[3]);
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080046 } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0)
47 || (isInput && (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0)) {
Mikhail Naganov10548292016-10-31 10:39:47 -070048 snprintf(halAddress, sizeof(halAddress),
49 "card=%d;device=%d",
50 address.address.alsa.card, address.address.alsa.device);
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080051 } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_BUS) != 0)
52 || (isInput && (halDevice & AUDIO_DEVICE_IN_BUS) != 0)) {
Mikhail Naganov10548292016-10-31 10:39:47 -070053 snprintf(halAddress, sizeof(halAddress),
54 "%s", address.busAddress.c_str());
Mikhail Naganov6e81e9b2016-11-16 16:30:17 -080055 } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0
56 || (isInput && (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) {
Mikhail Naganov10548292016-10-31 10:39:47 -070057 snprintf(halAddress, sizeof(halAddress),
58 "%s", address.rSubmixAddress.c_str());
59 }
60 return halAddress;
61}
62
63} // namespace implementation
64} // namespace V2_0
65} // namespace audio
66} // namespace hardware
67} // namespace android