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 #if MAJOR_VERSION <= 6
60 struct GetSupported {
getFormatGetSupported61 static auto getFormat(IStream* stream) {
62 auto ret = stream->getFormat();
63 EXPECT_TRUE(ret.isOk());
64 return ret.withDefault({});
65 }
sampleRatesGetSupported66 static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
67 Result res;
68 EXPECT_OK(stream->getSupportedSampleRates(getFormat(stream), returnIn(res, rates)));
69 return res;
70 }
71
channelMasksGetSupported72 static Result channelMasks(IStream* stream,
73 hidl_vec<hidl_bitfield<AudioChannelMask>>& channels) {
74 Result res;
75 EXPECT_OK(stream->getSupportedChannelMasks(getFormat(stream), returnIn(res, channels)));
76 return res;
77 }
78
79 #if MAJOR_VERSION <= 5
formatsGetSupported80 static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
81 EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
82 return Result::OK;
83 }
84 #else // MAJOR_VERSION == 6
formatsGetSupported85 static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
86 Result res;
87 EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
88 return res;
89 }
90 #endif
91 };
92 #endif // MAJOR_VERSION <= 6
93
94 template <class T>
dump(T t,hidl_handle handle)95 auto dump(T t, hidl_handle handle) {
96 return t->debug(handle, {/* options */});
97 }
98