blob: b8abb8edaf6cddc7f5245a4809730244e748d306 [file] [log] [blame]
Jiabin Huangebe64102021-09-07 20:01:07 +00001/*
2 * Copyright (C) 2021 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#include <aaudio/AAudio.h>
18#include <aaudio/AAudioTesting.h>
19#include <android/media/AudioMMapPolicy.h>
20#include <cutils/properties.h>
21
22#include "PropertyUtils.h"
23
24namespace android {
25
26std::string getMmapPolicyProperty(media::AudioMMapPolicyType policyType) {
27 switch (policyType) {
28 case media::AudioMMapPolicyType::DEFAULT:
29 return "aaudio.mmap_policy";
30 case media::AudioMMapPolicyType::EXCLUSIVE:
31 return "aaudio.mmap_exclusive_policy";
32 default:
33 return "";
34 }
35}
36
37int getDefaultPolicyFromType(media::AudioMMapPolicyType policyType) {
38 switch (policyType) {
39 case media::AudioMMapPolicyType::EXCLUSIVE:
40 return AAUDIO_UNSPECIFIED;
41 case media::AudioMMapPolicyType::DEFAULT:
42 default:
43 return AAUDIO_POLICY_NEVER;
44 }
45}
46
47media::AudioMMapPolicy legacy2aidl_aaudio_policy_t_AudioMMapPolicy(aaudio_policy_t legacy) {
48 switch (legacy) {
49 case AAUDIO_POLICY_NEVER:
50 return media::AudioMMapPolicy::NEVER;
51 case AAUDIO_POLICY_AUTO:
52 return media::AudioMMapPolicy::AUTO;
53 case AAUDIO_POLICY_ALWAYS:
54 return media::AudioMMapPolicy::ALWAYS;
55 case AAUDIO_UNSPECIFIED:
56 return media::AudioMMapPolicy::UNSPECIFIED;
57 default:
58 ALOGE("%s unknown aaudio policy: %d", __func__, legacy);
59 return media::AudioMMapPolicy::UNSPECIFIED;
60 }
61}
62
63status_t getMmapPolicyInfosFromSystemProperty(
64 media::AudioMMapPolicyType policyType,
65 std::vector<media::AudioMMapPolicyInfo> *policyInfos) {
66 media::AudioMMapPolicyInfo policyInfo;
67 const std::string propertyStr = getMmapPolicyProperty(policyType);
68 if (propertyStr.empty()) {
69 return BAD_VALUE;
70 }
71 policyInfo.mmapPolicy = legacy2aidl_aaudio_policy_t_AudioMMapPolicy(
72 property_get_int32(propertyStr.c_str(), getDefaultPolicyFromType(policyType)));
73 policyInfos->push_back(policyInfo);
74 return NO_ERROR;
75}
76
77} // namespace android