1 /* 2 * Copyright (c) 2021, Intel Corporation 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included 12 * in all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 */ 22 //! 23 //! \file media_user_setting_configure.h 24 //! \brief The interface of media user setting configure. 25 //! 26 27 #ifndef __MEDIA_USER_SETTING_CONFIGURE__H__ 28 #define __MEDIA_USER_SETTING_CONFIGURE__H__ 29 30 #include <string> 31 #include "mos_utilities.h" 32 #include "mos_os_specific.h" 33 #include "media_user_setting_value.h" 34 #include "media_user_setting_definition.h" 35 36 namespace MediaUserSetting { 37 38 //! 39 //! The media user setting group 40 //! Device - for regkeys which are touched per device 41 //! Sequence - for regkeys which are touched per video sequence 42 //! Frame - for regkeys which are touched per frame 43 //! MaxCount - is used to configure size of Configure::m_definitions array 44 //! Note: you must not assign any numeric values to the enum items, except for 45 //! the device being set to 0 46 //! 47 enum Group 48 { 49 Device = 0, 50 Sequence, 51 Frame, 52 MaxCount 53 }; 54 55 namespace Internal { 56 57 class Configure 58 { 59 public: 60 //! 61 //! \brief Constructor 62 //! 63 Configure(); 64 65 //! 66 //! \brief Destructor 67 //! 68 ~Configure(); 69 70 //! 71 //! \brief Register user setting item 72 //! \param [in] itemName 73 //! Name of the item 74 //! \param [in] group 75 //! Group of the item 76 //! \param [in] defaultValue 77 //! The default value of the item 78 //! \param [in] isReportKey 79 //! Whether this item can be reported 80 //! \param [in] debugOnly 81 //! Whether this item is only for debug/release-internal 82 //! \return MOS_STATUS 83 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason 84 //! 85 MOS_STATUS Register( 86 const std::string &itemName, 87 const Group &group, 88 const Value &defaultValue, 89 bool isReportKey, 90 bool debugOnly, 91 const std::string &customPath); 92 93 //! 94 //! \brief Read value of specific item 95 //! \param [out] value 96 //! The return value of the item 97 //! \param [in] itemName 98 //! Name of the item 99 //! \param [in] group 100 //! Group of the item 101 //! \param [in] mosContext 102 //! The pointer of mos context 103 //! \param [in] customValue 104 //! The custom value when failed 105 //! \param [in] useCustomValue 106 //! Whether use costom value when failed 107 //! \return MOS_STATUS 108 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason 109 //! 110 MOS_STATUS Read(Value &value, 111 const std::string &itemName, 112 const Group &group, 113 PMOS_CONTEXT mosContext, 114 const Value &customValue, 115 bool useCustomValue = false); 116 117 //! 118 //! \brief Write value to specific item 119 //! \param [in] itemName 120 //! Name of the item 121 //! \param [in] value 122 //! The value write to specific item 123 //! \param [in] group 124 //! Group of the item 125 //! \param [in] mosContext 126 //! The pointer of mos context 127 //! \param [in] isForReport 128 //! This call is for reporting a item value or modify the value of the item 129 //! \return MOS_STATUS 130 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason 131 //! 132 MOS_STATUS Write( 133 const std::string &itemName, 134 const Value &value, 135 const Group &group, 136 PMOS_CONTEXT mosContext, 137 bool isForReport); 138 139 //! 140 //! \brief Check whether definition of specific item name exist in all groups 141 //! \param [in] itemName 142 //! Item name 143 //! \return bool 144 //! true if exist, otherwise false 145 //! IsDefinitionExist(const std::string & itemName)146 inline bool IsDefinitionExist(const std::string &itemName) 147 { 148 bool ret = false; 149 for (auto defs : m_definitions) 150 { 151 auto it = defs.find(MakeHash(itemName)); 152 if (it != defs.end()) 153 { 154 ret = true; 155 break; 156 } 157 } 158 return ret; 159 } 160 161 protected: 162 //! 163 //! \brief Get media user setting definitions of specific group 164 //! \param [in] group 165 //! Group of the item 166 //! \return Media user setting definitions 167 //! Definitions of specific group, return definitions of device group if failed 168 //! GetDefinitions(const Group & group)169 inline Definitions &GetDefinitions(const Group &group) 170 { 171 if (group < Group::Device || group >= Group::MaxCount) 172 { 173 return m_definitions[Group::Device]; 174 } 175 176 return m_definitions[group]; 177 } 178 179 //! 180 //! \brief Get hash value of specific string 181 //! \param [in] str 182 //! Input string 183 //! \return size_t 184 //! Hash value 185 //! MakeHash(const std::string & str)186 size_t MakeHash(const std::string &str) 187 { 188 std::hash<std::string> HashFunc; 189 return HashFunc(str); 190 } 191 192 protected: 193 MosMutex m_mutexLock = {}; //!< mutex for protecting definitions 194 Definitions m_definitions[Group::MaxCount]{}; //!< definitions of media user setting 195 bool m_isDebugMode = false; //!< whether in debug/release-internal mode 196 197 static const UFKEY_NEXT m_rootKey; 198 static const char *m_configPath; 199 static const char *m_reportPath; 200 }; 201 202 }} 203 #endif