1/*
2 * Copyright (c) 2023-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16#ifndef HISTREAMER_PLUGIN_CAPS_H
17#define HISTREAMER_PLUGIN_CAPS_H
18
19#include <utility>
20#include <map> // NOLINT: used it
21#include <vector> // NOLINT: used it
22#include "meta/meta_key.h"
23#include "meta/any.h"
24
25namespace OHOS {
26namespace Media {
27namespace Plugins {
28/// Indicates that the available capability type is an fixed value.
29template <typename T> using FixedCapability = T;
30
31/// Indicates that the available capability type is an interval value.
32template <typename T> using IntervalCapability  = std::pair<T, T>;
33
34/// Indicates that the available capability types are discrete values.
35template <typename T> using DiscreteCapability = std::vector<T>;
36
37/**
38 * @brief The Capability describes the input and output capabilities of the plugin.
39 *
40 * It is basically a set of tags attached to the mime-type in order to
41 * describe the mime-type more closely.
42 *
43 * @since 1.0
44 * @version 1.0
45 */
46struct Capability {
47    /// default constructor
48    Capability() = default;
49
50    /**
51     * @brief constructor one capability with mime of m
52     *
53     * @param m mime string
54     */
55    explicit Capability(std::string m) : mime(std::move(m)) {}
56
57    /**
58     * @brief Append one fix key into KeyMap
59     *
60     * @tparam T type of value
61     * @param key Capability::Key
62     * @param val value
63     * @return reference of object
64     */
65    template<typename T>
66    Capability& AppendFixedKey(TagType key, const T& val)
67    {
68        keys[key] = val;
69        return *this;
70    }
71
72    template<typename T>
73    void GetFixedValue(TagType key, T& val)
74    {
75        auto it = keys.find(key);
76        if (it != keys.end()) {
77            val = it->second;
78        }
79    }
80
81    /**
82     * @brief Append one interval key i.e. [rangeStart, rangeEnd] into KeyMap
83     *
84     * @tparam T type of value
85     * @param key Capability::Key
86     * @param rangeStart range start
87     * @param rangeEnd rang end
88     * @return reference of object
89     */
90    template<typename T>
91    Capability& AppendIntervalKey(TagType key, const T& rangeStart, const T& rangeEnd)
92    {
93        keys[key] = std::make_pair(rangeStart, rangeEnd);
94        return *this;
95    }
96
97    /**
98     * @brief Append one discrete key i.e. {val1, val2, ....} into KeyMap
99     *
100     * @tparam T type of value
101     * @param key Capability::Key
102     * @param discreteValues values
103     * @return reference of object
104     */
105    template<typename T>
106    Capability& AppendDiscreteKeys(TagType key, DiscreteCapability<T> discreteValues)
107    {
108        keys[key] = std::move(discreteValues);
109        return *this;
110    }
111
112    /**
113     * @brief set mime of this capability
114     *
115     * @param val mime value
116     * @return reference of object
117     */
118    Capability& SetMime(std::string val)
119    {
120        mime = std::move(val);
121        return *this;
122    }
123
124    /// mime of capability. For details, see {@link constants.h}
125    std::string mime;
126
127    /// Store the parameters(Capability::Key, value pairs), which should be negotiated
128    std::map<TagType, Any> keys;
129};
130
131/// A collection of multiple capabilities
132using CapabilitySet = std::vector<Capability>;
133using ValueType = Any;
134} // namespace Plugins
135} // namespace Media
136} // namespace OHOS
137#endif // HISTREAMER_PLUGIN_CAPS_H
138