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