1a198a29250acb7c3e918f1566727190966bb336fEric Laurent/* 2a198a29250acb7c3e918f1566727190966bb336fEric Laurent * Copyright (C) 2014 The Android Open Source Project 3a198a29250acb7c3e918f1566727190966bb336fEric Laurent * 4a198a29250acb7c3e918f1566727190966bb336fEric Laurent * Licensed under the Apache License, Version 2.0 (the "License"); 5a198a29250acb7c3e918f1566727190966bb336fEric Laurent * you may not use this file except in compliance with the License. 6a198a29250acb7c3e918f1566727190966bb336fEric Laurent * You may obtain a copy of the License at 7a198a29250acb7c3e918f1566727190966bb336fEric Laurent * 8a198a29250acb7c3e918f1566727190966bb336fEric Laurent * http://www.apache.org/licenses/LICENSE-2.0 9a198a29250acb7c3e918f1566727190966bb336fEric Laurent * 10a198a29250acb7c3e918f1566727190966bb336fEric Laurent * Unless required by applicable law or agreed to in writing, software 11a198a29250acb7c3e918f1566727190966bb336fEric Laurent * distributed under the License is distributed on an "AS IS" BASIS, 12a198a29250acb7c3e918f1566727190966bb336fEric Laurent * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13a198a29250acb7c3e918f1566727190966bb336fEric Laurent * See the License for the specific language governing permissions and 14a198a29250acb7c3e918f1566727190966bb336fEric Laurent * limitations under the License. 15a198a29250acb7c3e918f1566727190966bb336fEric Laurent */ 16a198a29250acb7c3e918f1566727190966bb336fEric Laurent 17a198a29250acb7c3e918f1566727190966bb336fEric Laurentpackage android.media; 18a198a29250acb7c3e918f1566727190966bb336fEric Laurent 1907cd124b09a63985f0b200de248fab165f736ae4Mike Lockwoodimport android.media.AudioSystem; 2007cd124b09a63985f0b200de248fab165f736ae4Mike Lockwood 21a198a29250acb7c3e918f1566727190966bb336fEric Laurent/** 22a198a29250acb7c3e918f1566727190966bb336fEric Laurent * The AudioDevicePort is a specialized type of AudioPort 23a198a29250acb7c3e918f1566727190966bb336fEric Laurent * describing an input (e.g microphone) or output device (e.g speaker) 24a198a29250acb7c3e918f1566727190966bb336fEric Laurent * of the system. 25a198a29250acb7c3e918f1566727190966bb336fEric Laurent * An AudioDevicePort is an AudioPort controlled by the audio HAL, almost always a physical 26a198a29250acb7c3e918f1566727190966bb336fEric Laurent * device at the boundary of the audio system. 27a198a29250acb7c3e918f1566727190966bb336fEric Laurent * In addition to base audio port attributes, the device descriptor contains: 28a198a29250acb7c3e918f1566727190966bb336fEric Laurent * - the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) 29a198a29250acb7c3e918f1566727190966bb336fEric Laurent * - the device address (e.g MAC adddress for AD2P sink). 30a198a29250acb7c3e918f1566727190966bb336fEric Laurent * @see AudioPort 31a198a29250acb7c3e918f1566727190966bb336fEric Laurent * @hide 32a198a29250acb7c3e918f1566727190966bb336fEric Laurent */ 33a198a29250acb7c3e918f1566727190966bb336fEric Laurent 34a198a29250acb7c3e918f1566727190966bb336fEric Laurentpublic class AudioDevicePort extends AudioPort { 35a198a29250acb7c3e918f1566727190966bb336fEric Laurent 36a198a29250acb7c3e918f1566727190966bb336fEric Laurent private final int mType; 37a198a29250acb7c3e918f1566727190966bb336fEric Laurent private final String mAddress; 38a198a29250acb7c3e918f1566727190966bb336fEric Laurent 3910804eb2818ab59b763a37b4f6151693c2ebba7bPaul McLean AudioDevicePort(AudioHandle handle, String deviceName, 40f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean int[] samplingRates, int[] channelMasks, int[] channelIndexMasks, 41a198a29250acb7c3e918f1566727190966bb336fEric Laurent int[] formats, AudioGain[] gains, int type, String address) { 42a198a29250acb7c3e918f1566727190966bb336fEric Laurent super(handle, 43a198a29250acb7c3e918f1566727190966bb336fEric Laurent (AudioManager.isInputDevice(type) == true) ? 44a198a29250acb7c3e918f1566727190966bb336fEric Laurent AudioPort.ROLE_SOURCE : AudioPort.ROLE_SINK, 45f29e5f34b39a5688925ca4654be0eab11277b1ccPaul McLean deviceName, samplingRates, channelMasks, channelIndexMasks, formats, gains); 46a198a29250acb7c3e918f1566727190966bb336fEric Laurent mType = type; 47a198a29250acb7c3e918f1566727190966bb336fEric Laurent mAddress = address; 48a198a29250acb7c3e918f1566727190966bb336fEric Laurent } 49a198a29250acb7c3e918f1566727190966bb336fEric Laurent 50a198a29250acb7c3e918f1566727190966bb336fEric Laurent /** 51a198a29250acb7c3e918f1566727190966bb336fEric Laurent * Get the device type (e.g AudioManager.DEVICE_OUT_SPEAKER) 52a198a29250acb7c3e918f1566727190966bb336fEric Laurent */ 53a198a29250acb7c3e918f1566727190966bb336fEric Laurent public int type() { 54a198a29250acb7c3e918f1566727190966bb336fEric Laurent return mType; 55a198a29250acb7c3e918f1566727190966bb336fEric Laurent } 56a198a29250acb7c3e918f1566727190966bb336fEric Laurent 57a198a29250acb7c3e918f1566727190966bb336fEric Laurent /** 58a198a29250acb7c3e918f1566727190966bb336fEric Laurent * Get the device address. Address format varies with the device type. 59a198a29250acb7c3e918f1566727190966bb336fEric Laurent * - USB devices ({@link AudioManager#DEVICE_OUT_USB_DEVICE}, 60a198a29250acb7c3e918f1566727190966bb336fEric Laurent * {@link AudioManager#DEVICE_IN_USB_DEVICE}) use an address composed of the ALSA card number 61a198a29250acb7c3e918f1566727190966bb336fEric Laurent * and device number: "card=2;device=1" 62a198a29250acb7c3e918f1566727190966bb336fEric Laurent * - Bluetooth devices ({@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, 63a198a29250acb7c3e918f1566727190966bb336fEric Laurent * {@link AudioManager#DEVICE_OUT_BLUETOOTH_SCO}, {@link AudioManager#DEVICE_OUT_BLUETOOTH_A2DP}) 64a198a29250acb7c3e918f1566727190966bb336fEric Laurent * use the MAC address of the bluetooth device in the form "00:11:22:AA:BB:CC" as reported by 65a198a29250acb7c3e918f1566727190966bb336fEric Laurent * {@link BluetoothDevice#getAddress()}. 66a198a29250acb7c3e918f1566727190966bb336fEric Laurent * - Deivces that do not have an address will indicate an empty string "". 67a198a29250acb7c3e918f1566727190966bb336fEric Laurent */ 68a198a29250acb7c3e918f1566727190966bb336fEric Laurent public String address() { 69a198a29250acb7c3e918f1566727190966bb336fEric Laurent return mAddress; 70a198a29250acb7c3e918f1566727190966bb336fEric Laurent } 71a198a29250acb7c3e918f1566727190966bb336fEric Laurent 72a198a29250acb7c3e918f1566727190966bb336fEric Laurent /** 73a198a29250acb7c3e918f1566727190966bb336fEric Laurent * Build a specific configuration of this audio device port for use by methods 74a198a29250acb7c3e918f1566727190966bb336fEric Laurent * like AudioManager.connectAudioPatch(). 75a198a29250acb7c3e918f1566727190966bb336fEric Laurent */ 76a198a29250acb7c3e918f1566727190966bb336fEric Laurent public AudioDevicePortConfig buildConfig(int samplingRate, int channelMask, int format, 77a198a29250acb7c3e918f1566727190966bb336fEric Laurent AudioGainConfig gain) { 78a198a29250acb7c3e918f1566727190966bb336fEric Laurent return new AudioDevicePortConfig(this, samplingRate, channelMask, format, gain); 79a198a29250acb7c3e918f1566727190966bb336fEric Laurent } 80a198a29250acb7c3e918f1566727190966bb336fEric Laurent 81a198a29250acb7c3e918f1566727190966bb336fEric Laurent @Override 82a198a29250acb7c3e918f1566727190966bb336fEric Laurent public boolean equals(Object o) { 83a198a29250acb7c3e918f1566727190966bb336fEric Laurent if (o == null || !(o instanceof AudioDevicePort)) { 84a198a29250acb7c3e918f1566727190966bb336fEric Laurent return false; 85a198a29250acb7c3e918f1566727190966bb336fEric Laurent } 864bcdba848449b33d7022de527c526943aff1f5fdEric Laurent AudioDevicePort other = (AudioDevicePort)o; 874bcdba848449b33d7022de527c526943aff1f5fdEric Laurent if (mType != other.type()) { 884bcdba848449b33d7022de527c526943aff1f5fdEric Laurent return false; 894bcdba848449b33d7022de527c526943aff1f5fdEric Laurent } 904bcdba848449b33d7022de527c526943aff1f5fdEric Laurent if (mAddress == null && other.address() != null) { 914bcdba848449b33d7022de527c526943aff1f5fdEric Laurent return false; 924bcdba848449b33d7022de527c526943aff1f5fdEric Laurent } 934bcdba848449b33d7022de527c526943aff1f5fdEric Laurent if (!mAddress.equals(other.address())) { 944bcdba848449b33d7022de527c526943aff1f5fdEric Laurent return false; 954bcdba848449b33d7022de527c526943aff1f5fdEric Laurent } 96a198a29250acb7c3e918f1566727190966bb336fEric Laurent return super.equals(o); 97a198a29250acb7c3e918f1566727190966bb336fEric Laurent } 982754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood 992754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood @Override 1002754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood public String toString() { 10107cd124b09a63985f0b200de248fab165f736ae4Mike Lockwood String type = (mRole == ROLE_SOURCE ? 10207cd124b09a63985f0b200de248fab165f736ae4Mike Lockwood AudioSystem.getInputDeviceName(mType) : 10307cd124b09a63985f0b200de248fab165f736ae4Mike Lockwood AudioSystem.getOutputDeviceName(mType)); 1042754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood return "{" + super.toString() 10507cd124b09a63985f0b200de248fab165f736ae4Mike Lockwood + ", mType: " + type 1062754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood + ", mAddress: " + mAddress 1072754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood + "}"; 1082754fd0cd3f055b1d5f7f2ea1470b4d84011b379Mike Lockwood } 109a198a29250acb7c3e918f1566727190966bb336fEric Laurent} 110