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.media.AudioSystem; 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 AudioDevicePort(AudioHandle handle, String deviceName, int[] samplingRates, int[] channelMasks, int[] channelIndexMasks, int[] formats, AudioGain[] gains, int type, String address)39 AudioDevicePort(AudioHandle handle, String deviceName, 40 int[] samplingRates, int[] channelMasks, int[] channelIndexMasks, 41 int[] formats, AudioGain[] gains, int type, String address) { 42 super(handle, 43 (AudioManager.isInputDevice(type) == true) ? 44 AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK, 45 deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains); 46 mType = type; 47 mAddress = address; 48 } 49 50 /** 51 * Get the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) 52 */ type()53 public int type() { 54 return mType; 55 } 56 57 /** 58 * Get the device address. Address format varies with the device type. 59 * - USB devices ({@link AudioManager#DEVICE_OUT_USB_DEVICE}, 60 * {@link AudioManager#DEVICE_IN_USB_DEVICE}) use an address composed of the ALSA card number 61 * and device number: "card=2;device=1" 62 * - Bluetooth devices ({@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, 63 * {@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, {@link AudioManager#DEVICE_OUT_BLUETOOTH_A2DP}) 64 * use the MAC address of the bluetooth device in the form "00:11:22:AA:BB:CC" as reported by 65 * {@link BluetoothDevice#getAddress()}. 66 * - Deivces that do not have an address will indicate an empty string "". 67 */ address()68 public String address() { 69 return mAddress; 70 } 71 72 /** 73 * Build a specific configuration of this audio device port for use by methods 74 * like AudioManager.connectAudioPatch(). 75 */ buildConfig(int samplingRate, int channelMask, int format, AudioGainConfig gain)76 public AudioDevicePortConfig buildConfig(int samplingRate, int channelMask, int format, 77 AudioGainConfig gain) { 78 return new AudioDevicePortConfig(this, samplingRate, channelMask, format, gain); 79 } 80 81 @Override equals(Object o)82 public boolean equals(Object o) { 83 if (o == null || !(o instanceof AudioDevicePort)) { 84 return false; 85 } 86 AudioDevicePort other = (AudioDevicePort)o; 87 if (mType != other.type()) { 88 return false; 89 } 90 if (mAddress == null && other.address() != null) { 91 return false; 92 } 93 if (!mAddress.equals(other.address())) { 94 return false; 95 } 96 return super.equals(o); 97 } 98 99 @Override toString()100 public String toString() { 101 String type = (mRole == ROLE_SOURCE ? 102 AudioSystem.getInputDeviceName(mType) : 103 AudioSystem.getOutputDeviceName(mType)); 104 return "{" + super.toString() 105 + ", mType: " + type 106 + ", mAddress: " + mAddress 107 + "}"; 108 } 109 } 110