IOProfile.h revision a8ecc2c72ca26389bd6b0162181d60aaeaca8149
1/* 2 * Copyright (C) 2015 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#pragma once 18 19#include "AudioPort.h" 20#include "DeviceDescriptor.h" 21#include <utils/String8.h> 22#include <system/audio.h> 23 24namespace android { 25 26class HwModule; 27 28// the IOProfile class describes the capabilities of an output or input stream. 29// It is currently assumed that all combination of listed parameters are supported. 30// It is used by the policy manager to determine if an output or input is suitable for 31// a given use case, open/close it accordingly and connect/disconnect audio tracks 32// to/from it. 33class IOProfile : public AudioPort 34{ 35public: 36 IOProfile(const String8 &name, audio_port_role_t role); 37 virtual ~IOProfile(); 38 39 // This method is used for both output and input. 40 // If parameter updatedSamplingRate is non-NULL, it is assigned the actual sample rate. 41 // For input, flags is interpreted as audio_input_flags_t. 42 // TODO: merge audio_output_flags_t and audio_input_flags_t. 43 bool isCompatibleProfile(audio_devices_t device, 44 String8 address, 45 uint32_t samplingRate, 46 uint32_t *updatedSamplingRate, 47 audio_format_t format, 48 audio_format_t *updatedFormat, 49 audio_channel_mask_t channelMask, 50 audio_channel_mask_t *updatedChannelMask, 51 uint32_t flags) const; 52 53 void dump(int fd); 54 void log(); 55 56 bool hasSupportedDevices() const { return !mSupportedDevices.isEmpty(); } 57 58 bool supportDevice(audio_devices_t device) const 59 { 60 if (audio_is_output_devices(device)) { 61 return mSupportedDevices.types() & device; 62 } 63 return mSupportedDevices.types() & (device & ~AUDIO_DEVICE_BIT_IN); 64 } 65 66 bool supportDeviceAddress(const String8 &address) const 67 { 68 return mSupportedDevices[0]->mAddress == address; 69 } 70 71 // chose first device present in mSupportedDevices also part of deviceType 72 audio_devices_t getSupportedDeviceForType(audio_devices_t deviceType) const 73 { 74 for (size_t k = 0; k < mSupportedDevices.size(); k++) { 75 audio_devices_t profileType = mSupportedDevices[k]->type(); 76 if (profileType & deviceType) { 77 return profileType; 78 } 79 } 80 return AUDIO_DEVICE_NONE; 81 } 82 83 audio_devices_t getSupportedDevicesType() const { return mSupportedDevices.types(); } 84 85 void clearSupportedDevices() { mSupportedDevices.clear(); } 86 void addSupportedDevice(const sp<DeviceDescriptor> &device) 87 { 88 mSupportedDevices.add(device); 89 } 90 91 void setSupportedDevices(const DeviceVector &devices) 92 { 93 mSupportedDevices = devices; 94 } 95 96 sp<DeviceDescriptor> getSupportedDeviceByAddress(audio_devices_t type, String8 address) const 97 { 98 return mSupportedDevices.getDevice(type, address); 99 } 100 101 const DeviceVector &getSupportedDevices() const { return mSupportedDevices; } 102 103private: 104 DeviceVector mSupportedDevices; // supported devices 105 // (devices this output can be routed to) 106}; 107 108class InputProfile : public IOProfile 109{ 110public: 111 InputProfile(const String8 &name) : IOProfile(name, AUDIO_PORT_ROLE_SINK) {} 112}; 113 114class OutputProfile : public IOProfile 115{ 116public: 117 OutputProfile(const String8 &name) : IOProfile(name, AUDIO_PORT_ROLE_SOURCE) {} 118}; 119 120}; // namespace android 121