blob: 1ba16e1c614d1492d14cec94a59b1822de0aa60b [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);
32 if ((halDevice & AUDIO_DEVICE_OUT_ALL_A2DP) != 0
33 || (halDevice & AUDIO_DEVICE_IN_BLUETOOTH_A2DP) != 0) {
34 snprintf(halAddress, sizeof(halAddress),
35 "%02X:%02X:%02X:%02X:%02X:%02X",
36 address.address.mac[0], address.address.mac[1], address.address.mac[2],
37 address.address.mac[3], address.address.mac[4], address.address.mac[5]);
38 } else if ((halDevice & AUDIO_DEVICE_OUT_IP) != 0 || (halDevice & AUDIO_DEVICE_IN_IP) != 0) {
39 snprintf(halAddress, sizeof(halAddress),
40 "%d.%d.%d.%d",
41 address.address.ipv4[0], address.address.ipv4[1],
42 address.address.ipv4[2], address.address.ipv4[3]);
43 } else if ((halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0
44 || (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0) {
45 snprintf(halAddress, sizeof(halAddress),
46 "card=%d;device=%d",
47 address.address.alsa.card, address.address.alsa.device);
48 } else if ((halDevice & AUDIO_DEVICE_OUT_BUS) != 0 || (halDevice & AUDIO_DEVICE_IN_BUS) != 0) {
49 snprintf(halAddress, sizeof(halAddress),
50 "%s", address.busAddress.c_str());
51 } else if ((halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX) != 0
52 || (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0) {
53 snprintf(halAddress, sizeof(halAddress),
54 "%s", address.rSubmixAddress.c_str());
55 }
56 return halAddress;
57}
58
59} // namespace implementation
60} // namespace V2_0
61} // namespace audio
62} // namespace hardware
63} // namespace android