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/FILE_VERSION/IStream.h)
19 #include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h)
20 #include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h)
21 // clang-format on
22 #include <hidl/HidlSupport.h>
23
24 using ::android::hardware::hidl_handle;
25 using ::android::hardware::hidl_string;
26 using ::android::hardware::hidl_vec;
27 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioChannelMask;
28 using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioFormat;
29 using ::android::hardware::audio::CPP_VERSION::IStream;
30 using ::android::hardware::audio::CPP_VERSION::ParameterValue;
31 using ::android::hardware::audio::CPP_VERSION::Result;
32
33 using namespace ::android::hardware::audio::common::test::utility;
34
35 struct Parameters {
36 template <class T, class ReturnIn>
getParameters37 static auto get(T t, hidl_vec<hidl_string> keys, ReturnIn returnIn) {
38 return t->getParameters(keys, returnIn);
39 }
40 template <class T>
setParameters41 static auto set(T t, hidl_vec<ParameterValue> values) {
42 return t->setParameters(values);
43 }
44 };
45
46 // The default hal should probably return a NOT_SUPPORTED if the hal
47 // does not expose
48 // capability retrieval. For now it returns an empty list if not
49 // implemented
50 struct GetSupported {
51 template <class Vec>
convertToResultGetSupported52 static Result convertToResult(const Vec& vec) {
53 return vec.size() == 0 ? Result::NOT_SUPPORTED : Result::OK;
54 }
55
sampleRatesGetSupported56 static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
57 EXPECT_OK(stream->getSupportedSampleRates(returnIn(rates)));
58 return convertToResult(rates);
59 }
60
channelMasksGetSupported61 static Result channelMasks(IStream* stream, hidl_vec<AudioChannelMask>& channels) {
62 EXPECT_OK(stream->getSupportedChannelMasks(returnIn(channels)));
63 return convertToResult(channels);
64 }
65
formatsGetSupported66 static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
67 EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
68 // TODO: this should be an optional function
69 return Result::OK;
70 }
71 };
72
73 template <class T>
dump(T t,hidl_handle handle)74 auto dump(T t, hidl_handle handle) {
75 return t->debugDump(handle);
76 }
77