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