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_bitfield;
23 using ::android::hardware::hidl_handle;
24 using ::android::hardware::hidl_string;
25 using ::android::hardware::hidl_vec;
26 using ::android::hardware::audio::common::CPP_VERSION::AudioChannelMask;
27 using ::android::hardware::audio::common::CPP_VERSION::AudioFormat;
28 using ::android::hardware::audio::CPP_VERSION::IStream;
29 using ::android::hardware::audio::CPP_VERSION::ParameterValue;
30 using ::android::hardware::audio::CPP_VERSION::Result;
31 
32 using namespace ::android::hardware::audio::common::test::utility;
33 
34 using Rotation = ::android::hardware::audio::CPP_VERSION::IPrimaryDevice::Rotation;
35 using ::android::hardware::audio::common::CPP_VERSION::AudioContentType;
36 using ::android::hardware::audio::common::CPP_VERSION::AudioUsage;
37 using ::android::hardware::audio::CPP_VERSION::MicrophoneInfo;
38 #if MAJOR_VERSION < 5
39 using ::android::hardware::audio::CPP_VERSION::SinkMetadata;
40 using ::android::hardware::audio::CPP_VERSION::SourceMetadata;
41 #else
42 using ::android::hardware::audio::common::CPP_VERSION::SinkMetadata;
43 using ::android::hardware::audio::common::CPP_VERSION::SourceMetadata;
44 #endif
45 
46 struct Parameters {
47     template <class T, class ReturnIn>
getParameters48     static auto get(T t, hidl_vec<hidl_string> keys, ReturnIn returnIn) {
49         hidl_vec<ParameterValue> context;
50         return t->getParameters(context, keys, returnIn);
51     }
52     template <class T>
setParameters53     static auto set(T t, hidl_vec<ParameterValue> values) {
54         hidl_vec<ParameterValue> context;
55         return t->setParameters(context, values);
56     }
57 };
58 
59 struct GetSupported {
getFormatGetSupported60     static auto getFormat(IStream* stream) {
61         auto ret = stream->getFormat();
62         EXPECT_TRUE(ret.isOk());
63         return ret.withDefault({});
64     }
sampleRatesGetSupported65     static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
66         Result res;
67         EXPECT_OK(stream->getSupportedSampleRates(getFormat(stream), returnIn(res, rates)));
68         return res;
69     }
70 
channelMasksGetSupported71     static Result channelMasks(IStream* stream,
72                                hidl_vec<hidl_bitfield<AudioChannelMask>>& channels) {
73         Result res;
74         EXPECT_OK(stream->getSupportedChannelMasks(getFormat(stream), returnIn(res, channels)));
75         return res;
76     }
77 
78 #if MAJOR_VERSION <= 5
formatsGetSupported79     static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
80         EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
81         return Result::OK;
82     }
83 #elif MAJOR_VERSION >= 6
formatsGetSupported84     static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
85         Result res;
86         EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
87         return res;
88     }
89 #endif
90 };
91 
92 template <class T>
dump(T t,hidl_handle handle)93 auto dump(T t, hidl_handle handle) {
94     return t->debug(handle, {/* options */});
95 }
96