Home | History | Annotate | Download | only in default
      1 /*
      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 
     21 namespace android {
     22 namespace hardware {
     23 namespace audio {
     24 namespace V2_0 {
     25 namespace implementation {
     26 
     27 std::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     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)) {
     36         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]);
     40     } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_IP) != 0)
     41             || (isInput && (halDevice & AUDIO_DEVICE_IN_IP) != 0)) {
     42         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]);
     46     } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_ALL_USB) != 0)
     47             || (isInput && (halDevice & AUDIO_DEVICE_IN_ALL_USB) != 0)) {
     48         snprintf(halAddress, sizeof(halAddress),
     49                 "card=%d;device=%d",
     50                 address.address.alsa.card, address.address.alsa.device);
     51     } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_BUS) != 0)
     52             || (isInput && (halDevice & AUDIO_DEVICE_IN_BUS) != 0)) {
     53         snprintf(halAddress, sizeof(halAddress),
     54                 "%s", address.busAddress.c_str());
     55     } else if ((!isInput && (halDevice & AUDIO_DEVICE_OUT_REMOTE_SUBMIX)) != 0
     56             || (isInput && (halDevice & AUDIO_DEVICE_IN_REMOTE_SUBMIX) != 0)) {
     57         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
     68