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