summaryrefslogtreecommitdiff
path: root/audio/core/all-versions/vts/functional/4.0/AudioPrimaryHidlHalUtils.h
blob: 83ca9eba177a292d6288282ceb1bfc2e16dd3568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// clang-format off
#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/IStreamIn.h)
#include PATH(android/hardware/audio/CORE_TYPES_FILE_VERSION/types.h)
#include PATH(android/hardware/audio/FILE_VERSION/IStreamOut.h)
#include PATH(android/hardware/audio/common/COMMON_TYPES_FILE_VERSION/types.h)
// clang-format on
#include <hidl/HidlSupport.h>

using ::android::hardware::hidl_bitfield;
using ::android::hardware::hidl_handle;
using ::android::hardware::hidl_string;
using ::android::hardware::hidl_vec;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioChannelMask;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioFormat;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IStream;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::ParameterValue;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::Result;

using namespace ::android::hardware::audio::common::test::utility;

using Rotation = ::android::hardware::audio::CORE_TYPES_CPP_VERSION::IPrimaryDevice::Rotation;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioContentType;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::AudioUsage;
using ::android::hardware::audio::CORE_TYPES_CPP_VERSION::MicrophoneInfo;
#if MAJOR_VERSION < 5
using ::android::hardware::audio::CPP_VERSION::SinkMetadata;
using ::android::hardware::audio::CPP_VERSION::SourceMetadata;
#else
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::SinkMetadata;
using ::android::hardware::audio::common::COMMON_TYPES_CPP_VERSION::SourceMetadata;
#endif

struct Parameters {
    template <class T, class ReturnIn>
    static auto get(T t, hidl_vec<hidl_string> keys, ReturnIn returnIn) {
        hidl_vec<ParameterValue> context;
        return t->getParameters(context, keys, returnIn);
    }
    template <class T>
    static auto set(T t, hidl_vec<ParameterValue> values) {
        hidl_vec<ParameterValue> context;
        return t->setParameters(context, values);
    }
};

#if MAJOR_VERSION <= 6
struct GetSupported {
    static auto getFormat(IStream* stream) {
        auto ret = stream->getFormat();
        EXPECT_TRUE(ret.isOk());
        return ret.withDefault({});
    }
    static Result sampleRates(IStream* stream, hidl_vec<uint32_t>& rates) {
        Result res;
        EXPECT_OK(stream->getSupportedSampleRates(getFormat(stream), returnIn(res, rates)));
        return res;
    }

    static Result channelMasks(IStream* stream,
                               hidl_vec<hidl_bitfield<AudioChannelMask>>& channels) {
        Result res;
        EXPECT_OK(stream->getSupportedChannelMasks(getFormat(stream), returnIn(res, channels)));
        return res;
    }

#if MAJOR_VERSION <= 5
    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        EXPECT_OK(stream->getSupportedFormats(returnIn(capabilities)));
        return Result::OK;
    }
#else  // MAJOR_VERSION == 6
    static Result formats(IStream* stream, hidl_vec<AudioFormat>& capabilities) {
        Result res;
        EXPECT_OK(stream->getSupportedFormats(returnIn(res, capabilities)));
        return res;
    }
#endif
};
#endif  // MAJOR_VERSION <= 6

template <class T>
auto dump(T t, hidl_handle handle) {
    return t->debug(handle, {/* options */});
}