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 VIDEO_BIT_STREAM_FORMAT = static_cast<uint32_t>(Tag::VIDEO_BIT_STREAM_FORMAT), 67 }; 68 69 /// Used to store the capability in the key-value format. 70 using KeyMap = std::map<Key, ValueType>; 71 72 /// default constructor 73 Capability() = default; 74 75 /** 76 * @brief constructor one capability with mime of m 77 * 78 * @param m mime string 79 */ CapabilityCapability80 explicit Capability(std::string m):mime(std::move(m)){} 81 82 /** 83 * @brief Append one fix key into KeyMap 84 * 85 * @tparam T type of value 86 * @param key Capability::Key 87 * @param val value 88 * @return reference of object 89 */ 90 template<typename T> AppendFixedKeyCapability91 Capability& AppendFixedKey(Key key, const T& val) 92 { 93 keys[key] = val; 94 return *this; 95 } 96 97 /** 98 * @brief Append one interval key i.e. [rangeStart, rangeEnd] into KeyMap 99 * 100 * @tparam T type of value 101 * @param key Capability::Key 102 * @param rangeStart range start 103 * @param rangeEnd rang end 104 * @return reference of object 105 */ 106 template<typename T> AppendIntervalKeyCapability107 Capability& AppendIntervalKey(Key key, const T& rangeStart, const T& rangeEnd) 108 { 109 keys[key] = std::make_pair(rangeStart, rangeEnd); 110 return *this; 111 } 112 113 /** 114 * @brief Append one discrete key i.e. {val1, val2, ....} into KeyMap 115 * 116 * @tparam T type of value 117 * @param key Capability::Key 118 * @param discreteValues values 119 * @return reference of object 120 */ 121 template<typename T> AppendDiscreteKeysCapability122 Capability& AppendDiscreteKeys(Key key, DiscreteCapability<T> discreteValues) 123 { 124 keys[key] = std::move(discreteValues); 125 return *this; 126 } 127 128 /** 129 * @brief set mime of this capability 130 * 131 * @param val mime value 132 * @return reference of object 133 */ SetMimeCapability134 Capability& SetMime(std::string val) 135 { 136 mime = std::move(val); 137 return *this; 138 } 139 140 /// mime of capability. For details, see {@link constants.h} 141 std::string mime; 142 143 /// Store the parameters(Capability::Key, value pairs), which should be negotiated 144 KeyMap keys; 145 }; 146 147 /// A collection of multiple capabilities 148 using CapabilitySet = std::vector<Capability>; 149 } // namespace Plugin 150 } // namespace Media 151 } // namespace OHOS 152 #endif // HISTREAMER_PLUGIN_COMMON_CAPS_H 153