blob: 538ac1a6f8aaee16515104ad466c916cbcedd695 [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
49 if (device != AUDIO_DEVICE_NONE && mSupportedDevices.getDevice(device, address) == 0) {
50 return false;
51 }
52
53 if (samplingRate == 0) {
54 return false;
55 }
56 uint32_t myUpdatedSamplingRate = samplingRate;
57 if (isPlaybackThread && checkExactSamplingRate(samplingRate) != NO_ERROR) {
58 return false;
59 }
60 if (isRecordThread && checkCompatibleSamplingRate(samplingRate, &myUpdatedSamplingRate) !=
61 NO_ERROR) {
62 return false;
63 }
64
65 if (!audio_is_valid_format(format) || checkFormat(format) != NO_ERROR) {
66 return false;
67 }
68
69 if (isPlaybackThread && (!audio_is_output_channel(channelMask) ||
70 checkExactChannelMask(channelMask) != NO_ERROR)) {
71 return false;
72 }
73 if (isRecordThread && (!audio_is_input_channel(channelMask) ||
74 checkCompatibleChannelMask(channelMask) != NO_ERROR)) {
75 return false;
76 }
77
78 if (isPlaybackThread && (mFlags & flags) != flags) {
79 return false;
80 }
81 // The only input flag that is allowed to be different is the fast flag.
82 // An existing fast stream is compatible with a normal track request.
83 // An existing normal stream is compatible with a fast track request,
84 // but the fast request will be denied by AudioFlinger and converted to normal track.
85 if (isRecordThread && ((mFlags ^ flags) &
86 ~AUDIO_INPUT_FLAG_FAST)) {
87 return false;
88 }
89
90 if (updatedSamplingRate != NULL) {
91 *updatedSamplingRate = myUpdatedSamplingRate;
92 }
93 return true;
94}
95
96void IOProfile::dump(int fd)
97{
98 const size_t SIZE = 256;
99 char buffer[SIZE];
100 String8 result;
101
102 AudioPort::dump(fd, 4);
103
104 snprintf(buffer, SIZE, " - flags: 0x%04x\n", mFlags);
105 result.append(buffer);
106 snprintf(buffer, SIZE, " - devices:\n");
107 result.append(buffer);
108 write(fd, result.string(), result.size());
109 for (size_t i = 0; i < mSupportedDevices.size(); i++) {
110 mSupportedDevices[i]->dump(fd, 6, i);
111 }
112}
113
114void IOProfile::log()
115{
116 const size_t SIZE = 256;
117 char buffer[SIZE];
118 String8 result;
119
120 ALOGV(" - sampling rates: ");
121 for (size_t i = 0; i < mSamplingRates.size(); i++) {
122 ALOGV(" %d", mSamplingRates[i]);
123 }
124
125 ALOGV(" - channel masks: ");
126 for (size_t i = 0; i < mChannelMasks.size(); i++) {
127 ALOGV(" 0x%04x", mChannelMasks[i]);
128 }
129
130 ALOGV(" - formats: ");
131 for (size_t i = 0; i < mFormats.size(); i++) {
132 ALOGV(" 0x%08x", mFormats[i]);
133 }
134
135 ALOGV(" - devices: 0x%04x\n", mSupportedDevices.types());
136 ALOGV(" - flags: 0x%04x\n", mFlags);
137}
138
139}; // namespace android