IOProfile.cpp revision 322b4d25387a04c9afebe998326d005bbdf17ede
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#define LOG_TAG "APM::IOProfile" 18//#define LOG_NDEBUG 0 19 20#include "IOProfile.h" 21#include "HwModule.h" 22#include "AudioGain.h" 23 24namespace android { 25 26IOProfile::IOProfile(const String8& name, audio_port_role_t role) 27 : AudioPort(name, AUDIO_PORT_TYPE_MIX, role) 28{ 29} 30 31IOProfile::~IOProfile() 32{ 33} 34 35// checks if the IO profile is compatible with specified parameters. 36// Sampling rate, format and channel mask must be specified in order to 37// get a valid a match 38bool IOProfile::isCompatibleProfile(audio_devices_t device, 39 String8 address, 40 uint32_t samplingRate, 41 uint32_t *updatedSamplingRate, 42 audio_format_t format, 43 audio_channel_mask_t channelMask, 44 uint32_t flags) const 45{ 46 const bool isPlaybackThread = mType == AUDIO_PORT_TYPE_MIX && mRole == AUDIO_PORT_ROLE_SOURCE; 47 const bool isRecordThread = mType == AUDIO_PORT_TYPE_MIX && mRole == AUDIO_PORT_ROLE_SINK; 48 ALOG_ASSERT(isPlaybackThread != isRecordThread); 49 50 51 if (device != AUDIO_DEVICE_NONE) { 52 // just check types if multiple devices are selected 53 if (popcount(device & ~AUDIO_DEVICE_BIT_IN) > 1) { 54 if ((mSupportedDevices.types() & device) != device) { 55 return false; 56 } 57 } else if (mSupportedDevices.getDevice(device, address) == 0) { 58 return false; 59 } 60 } 61 62 if (samplingRate == 0) { 63 return false; 64 } 65 uint32_t myUpdatedSamplingRate = samplingRate; 66 if (isPlaybackThread && checkExactSamplingRate(samplingRate) != NO_ERROR) { 67 return false; 68 } 69 if (isRecordThread && checkCompatibleSamplingRate(samplingRate, &myUpdatedSamplingRate) != 70 NO_ERROR) { 71 return false; 72 } 73 74 if (!audio_is_valid_format(format) || checkFormat(format) != NO_ERROR) { 75 return false; 76 } 77 78 if (isPlaybackThread && (!audio_is_output_channel(channelMask) || 79 checkExactChannelMask(channelMask) != NO_ERROR)) { 80 return false; 81 } 82 if (isRecordThread && (!audio_is_input_channel(channelMask) || 83 checkCompatibleChannelMask(channelMask) != NO_ERROR)) { 84 return false; 85 } 86 87 if (isPlaybackThread && (mFlags & flags) != flags) { 88 return false; 89 } 90 // The only input flag that is allowed to be different is the fast flag. 91 // An existing fast stream is compatible with a normal track request. 92 // An existing normal stream is compatible with a fast track request, 93 // but the fast request will be denied by AudioFlinger and converted to normal track. 94 if (isRecordThread && ((mFlags ^ flags) & 95 ~AUDIO_INPUT_FLAG_FAST)) { 96 return false; 97 } 98 99 if (updatedSamplingRate != NULL) { 100 *updatedSamplingRate = myUpdatedSamplingRate; 101 } 102 return true; 103} 104 105void IOProfile::dump(int fd) 106{ 107 const size_t SIZE = 256; 108 char buffer[SIZE]; 109 String8 result; 110 111 AudioPort::dump(fd, 4); 112 113 snprintf(buffer, SIZE, " - flags: 0x%04x\n", mFlags); 114 result.append(buffer); 115 snprintf(buffer, SIZE, " - devices:\n"); 116 result.append(buffer); 117 write(fd, result.string(), result.size()); 118 for (size_t i = 0; i < mSupportedDevices.size(); i++) { 119 mSupportedDevices[i]->dump(fd, 6, i); 120 } 121} 122 123void IOProfile::log() 124{ 125 const size_t SIZE = 256; 126 char buffer[SIZE]; 127 String8 result; 128 129 ALOGV(" - sampling rates: "); 130 for (size_t i = 0; i < mSamplingRates.size(); i++) { 131 ALOGV(" %d", mSamplingRates[i]); 132 } 133 134 ALOGV(" - channel masks: "); 135 for (size_t i = 0; i < mChannelMasks.size(); i++) { 136 ALOGV(" 0x%04x", mChannelMasks[i]); 137 } 138 139 ALOGV(" - formats: "); 140 for (size_t i = 0; i < mFormats.size(); i++) { 141 ALOGV(" 0x%08x", mFormats[i]); 142 } 143 144 ALOGV(" - devices: 0x%04x\n", mSupportedDevices.types()); 145 ALOGV(" - flags: 0x%04x\n", mFlags); 146} 147 148}; // namespace android 149