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