1 /* 2 * Copyright (C) 2014 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 package android.media; 18 19 import android.compat.annotation.UnsupportedAppUsage; 20 21 /** 22 * The AudioDevicePort is a specialized type of AudioPort 23 * describing an input (e.g microphone) or output device (e.g speaker) 24 * of the system. 25 * An AudioDevicePort is an AudioPort controlled by the audio HAL, almost always a physical 26 * device at the boundary of the audio system. 27 * In addition to base audio port attributes, the device descriptor contains: 28 * - the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) 29 * - the device address (e.g MAC adddress for AD2P sink). 30 * @see AudioPort 31 * @hide 32 */ 33 34 public class AudioDevicePort extends AudioPort { 35 36 private final int mType; 37 private final String mAddress; 38 39 @UnsupportedAppUsage AudioDevicePort(AudioHandle handle, String deviceName, int[] samplingRates, int[] channelMasks, int[] channelIndexMasks, int[] formats, AudioGain[] gains, int type, String address)40 AudioDevicePort(AudioHandle handle, String deviceName, 41 int[] samplingRates, int[] channelMasks, int[] channelIndexMasks, 42 int[] formats, AudioGain[] gains, int type, String address) { 43 super(handle, 44 (AudioManager.isInputDevice(type) == true) ? 45 AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK, 46 deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains); 47 mType = type; 48 mAddress = address; 49 } 50 51 /** 52 * Get the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) 53 */ 54 @UnsupportedAppUsage type()55 public int type() { 56 return mType; 57 } 58 59 /** 60 * Get the device address. Address format varies with the device type. 61 * - USB devices ({@link AudioManager#DEVICE_OUT_USB_DEVICE}, 62 * {@link AudioManager#DEVICE_IN_USB_DEVICE}) use an address composed of the ALSA card number 63 * and device number: "card=2;device=1" 64 * - Bluetooth devices ({@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, 65 * {@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, {@link AudioManager#DEVICE_OUT_BLUETOOTH_A2DP}) 66 * use the MAC address of the bluetooth device in the form "00:11:22:AA:BB:CC" as reported by 67 * {@link BluetoothDevice#getAddress()}. 68 * - Deivces that do not have an address will indicate an empty string "". 69 */ address()70 public String address() { 71 return mAddress; 72 } 73 74 /** 75 * Build a specific configuration of this audio device port for use by methods 76 * like AudioManager.connectAudioPatch(). 77 */ buildConfig(int samplingRate, int channelMask, int format, AudioGainConfig gain)78 public AudioDevicePortConfig buildConfig(int samplingRate, int channelMask, int format, 79 AudioGainConfig gain) { 80 return new AudioDevicePortConfig(this, samplingRate, channelMask, format, gain); 81 } 82 83 @Override equals(Object o)84 public boolean equals(Object o) { 85 if (o == null || !(o instanceof AudioDevicePort)) { 86 return false; 87 } 88 AudioDevicePort other = (AudioDevicePort)o; 89 if (mType != other.type()) { 90 return false; 91 } 92 if (mAddress == null && other.address() != null) { 93 return false; 94 } 95 if (!mAddress.equals(other.address())) { 96 return false; 97 } 98 return super.equals(o); 99 } 100 101 @Override toString()102 public String toString() { 103 String type = (mRole == ROLE_SOURCE ? 104 AudioSystem.getInputDeviceName(mType) : 105 AudioSystem.getOutputDeviceName(mType)); 106 return "{" + super.toString() 107 + ", mType: " + type 108 + ", mAddress: " + mAddress 109 + "}"; 110 } 111 } 112