1 /* 2 * Copyright (c) 2021-2021 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_COMMON_CAPS_H 17 #define HISTREAMER_PLUGIN_COMMON_CAPS_H 18 19 #include <utility> 20 #include <vector> // NOLINT: used it 21 #include "plugin_tags.h" 22 23 namespace OHOS { 24 namespace Media { 25 namespace Plugin { 26 /// Indicates that the available capability type is an fixed value. 27 template <typename T> using FixedCapability = T; 28 29 /// Indicates that the available capability type is an interval value. 30 template <typename T> using IntervalCapability = std::pair<T, T>; 31 32 /// Indicates that the available capability types are discrete values. 33 template <typename T> using DiscreteCapability = std::vector<T>; 34 35 /** 36 * @brief The Capability describes the input and output capabilities of the plugin. 37 * 38 * It is basically a set of tags attached to the mime-type in order to 39 * describe the mime-type more closely. 40 * 41 * @since 1.0 42 * @version 1.0 43 */ 44 struct Capability { 45 /** 46 * @enum Capability ID is used to describe plugin capabilities or support capability matching. 47 * All Capability ID must come from Tag. 48 * 49 * For details about the definition and usage, to see enum Tag in file plugin_tags.h. 50 * 51 * @since 1.0 52 * @version 1.0 53 */ 54 enum struct Key : uint32_t { 55 MEDIA_BITRATE = static_cast<uint32_t>(Tag::MEDIA_BITRATE), 56 AUDIO_SAMPLE_RATE = static_cast<uint32_t>(Tag::AUDIO_SAMPLE_RATE), 57 AUDIO_CHANNELS = static_cast<uint32_t>(Tag::AUDIO_CHANNELS), 58 AUDIO_CHANNEL_LAYOUT = static_cast<uint32_t>(Tag::AUDIO_CHANNEL_LAYOUT), 59 AUDIO_SAMPLE_FORMAT = static_cast<uint32_t>(Tag::AUDIO_SAMPLE_FORMAT), 60 AUDIO_MPEG_VERSION = static_cast<uint32_t>(Tag::AUDIO_MPEG_VERSION), 61 AUDIO_MPEG_LAYER = static_cast<uint32_t>(Tag::AUDIO_MPEG_LAYER), 62 AUDIO_AAC_PROFILE = static_cast<uint32_t>(Tag::AUDIO_AAC_PROFILE), 63 AUDIO_AAC_LEVEL = static_cast<uint32_t>(Tag::AUDIO_AAC_LEVEL), 64 AUDIO_AAC_STREAM_FORMAT = static_cast<uint32_t>(Tag::AUDIO_AAC_STREAM_FORMAT), 65 VIDEO_PIXEL_FORMAT = static_cast<uint32_t>(Tag::VIDEO_PIXEL_FORMAT), 66 }; 67 68 /// Used to store the capability in the key-value format. 69 using KeyMap = std::map<Key, ValueType>; 70 71 /// default constructor 72 Capability() = default; 73 74 /** 75 * @brief constructor one capability with mime of m 76 * 77 * @param m mime string 78 */ CapabilityCapability79 explicit Capability(std::string m):mime(std::move(m)){} 80 81 /** 82 * @brief Append one fix key into KeyMap 83 * 84 * @tparam T type of value 85 * @param key Capability::Key 86 * @param val value 87 * @return reference of object 88 */ 89 template<typename T> AppendFixedKeyCapability90 Capability& AppendFixedKey(Key key, const T& val) 91 { 92 keys[key] = val; 93 return *this; 94 } 95 96 /** 97 * @brief Append one interval key i.e. [rangeStart, rangeEnd] into KeyMap 98 * 99 * @tparam T type of value 100 * @param key Capability::Key 101 * @param rangeStart range start 102 * @param rangeEnd rang end 103 * @return reference of object 104 */ 105 template<typename T> AppendIntervalKeyCapability106 Capability& AppendIntervalKey(Key key, const T& rangeStart, const T& rangeEnd) 107 { 108 keys[key] = std::make_pair(rangeStart, rangeEnd); 109 return *this; 110 } 111 112 /** 113 * @brief Append one discrete key i.e. {val1, val2, ....} into KeyMap 114 * 115 * @tparam T type of value 116 * @param key Capability::Key 117 * @param discreteValues values 118 * @return reference of object 119 */ 120 template<typename T> AppendDiscreteKeysCapability121 Capability& AppendDiscreteKeys(Key key, DiscreteCapability<T> discreteValues) 122 { 123 keys[key] = std::move(discreteValues); 124 return *this; 125 } 126 127 /** 128 * @brief set mime of this capability 129 * 130 * @param val mime value 131 * @return reference of object 132 */ SetMimeCapability133 Capability& SetMime(std::string val) 134 { 135 mime = std::move(val); 136 return *this; 137 } 138 139 /// mime of capability 140 std::string mime; 141 142 /// Store the parameters(Capability::Key, value pairs), which should be negotiated 143 KeyMap keys; 144 }; 145 146 /// A collection of multiple capabilities 147 using CapabilitySet = std::vector<Capability>; 148 } // namespace Plugin 149 } // namespace Media 150 } // namespace OHOS 151 #endif // HISTREAMER_PLUGIN_COMMON_CAPS_H 152