1 /*
2  * Copyright (C) 2020 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 #pragma once
18 #include <array>
19 #include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h)
20 #include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h)
21 #include <utils/Timers.h>
22 #include <cutils/sched_policy.h>
23 
24 namespace android {
25 namespace hardware {
26 namespace audio {
27 namespace CPP_VERSION {
28 namespace implementation {
29 namespace util {
30 
31 using ::android::hardware::hidl_bitfield;
32 using ::android::hardware::hidl_string;
33 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioFormat;
34 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioChannelMask;
35 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioConfig;
36 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioPortConfig;
37 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::MicrophoneInfo;
38 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::TimeSpec;
39 
40 MicrophoneInfo getMicrophoneInfo();
41 
42 size_t countChannels(const AudioChannelMask &mask);
43 size_t getBytesPerSample(const AudioFormat &format);
44 
45 bool checkAudioConfig(const AudioConfig &cfg);
46 bool checkAudioConfig(bool isOut,
47                       size_t duration_ms,
48                       size_t extraAlignment,
49                       const AudioConfig &cfg,
50                       AudioConfig &suggested);
51 
52 bool checkAudioPortConfig(const AudioPortConfig& cfg);
53 
54 TimeSpec nsecs2TimeSpec(nsecs_t);
55 
timespec2Nsecs(const TimeSpec & ts)56 inline constexpr nsecs_t timespec2Nsecs(const TimeSpec &ts) {
57     return s2ns(ts.tvSec) + ts.tvNSec;
58 }
59 
60 bool setThreadPriority(SchedPolicy policy, int prio);
61 
62 }  // namespace util
63 }  // namespace implementation
64 }  // namespace CPP_VERSION
65 }  // namespace audio
66 }  // namespace hardware
67 }  // namespace android
68