1 /*
2  * Copyright (C) 2018 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 // clang-format off
18 #include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/IStreamIn.h)
19 #include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h)
20 #include PATH(android/hardware/audio/FILE_VERSION/IStreamOut.h)
21 #include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h)
22 // clang-format on
23 #include <hidl/HidlSupport.h>
24 
25 using ::android::hardware::hidl_bitfield;
26 using ::android::hardware::hidl_handle;
27 using ::android::hardware::hidl_string;
28 using ::android::hardware::hidl_vec;
29 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioChannelMask;
30 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioFormat;
31 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStream;
32 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::ParameterValue;
33 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::Result;
34 
35 using namespace ::android::hardware::audio::common::test::utility;
36 
37 using Rotation = ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IPrimaryDevice::Rotation;
38 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioContentType;
39 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioUsage;
40 using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::MicrophoneInfo;
41 #if MAJOR_VERSION < 5
42 using ::android::hardware::audio::CPP_VERSION::SinkMetadata;
43 using ::android::hardware::audio::CPP_VERSION::SourceMetadata;
44 #else
45 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::SinkMetadata;
46 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::SourceMetadata;
47 #endif
48 
49 struct Parameters {
50     template <class T, class ReturnIn>
getParameters51     static auto get(T t, hidl_vec<hidl_string> keys, ReturnIn returnIn) {
52         hidl_vec<ParameterValue> context;
53         return t->getParameters(context, keys, returnIn);
54     }
55     template <class T>
setParameters56     static auto set(T t, hidl_vec<ParameterValue> values) {
57         hidl_vec<ParameterValue> context;
58         return t->setParameters(context, values);
59     }
60 };
61 
62 #if MAJOR_VERSION <= 6
63 struct GetSupported {
getFormatGetSupported64     static auto getFormat(IStream* stream) {
65         auto ret = stream->getFormat();
66         EXPECT_TRUE(ret.isOk());
67         return ret.withDefault({});
68     }
sampleRatesGetSupported69     static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
70         Result res;
71         EXPECT_OK(stream->getSupportedSampleRates(getFormat(stream), returnIn(res, rates)));
72         return res;
73     }
74 
channelMasksGetSupported75     static Result channelMasks(IStream* stream,
76                                hidl_vec<hidl_bitfield<AudioChannelMask>>& channels) {
77         Result res;
78         EXPECT_OK(stream->getSupportedChannelMasks(getFormat(stream), returnIn(res, channels)));
79         return res;
80     }
81 
82 #if MAJOR_VERSION <= 5
formatsGetSupported83     static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
84         EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
85         return Result::OK;
86     }
87 #else  // MAJOR_VERSION == 6
formatsGetSupported88     static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
89         Result res;
90         EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
91         return res;
92     }
93 #endif
94 };
95 #endif  // MAJOR_VERSION <= 6
96 
97 template <class T>
dump(T t,hidl_handle handle)98 auto dump(T t, hidl_handle handle) {
99     return t->debug(handle, {/* options */});
100 }
101