1
2 /*
3 * Copyright (c) 2021-2023, Intel Corporation
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 * OTHER DEALINGS IN THE SOFTWARE.
22 */
23 //!
24 //! \file media_user_setting.h
25 //! \brief The interface of media user setting
26 //! \details This class is the implementation of media user setting interface. We need several steps to use the media
27 //! user setting.
28 //! 1) Declare the definition of media user setting item in initialize function, just like:
29 //! DeclareUserSettingKey("User Setting", MediaUserSetting::Device, MediaUserSetting::Value(true), true);
30 //! If the setting item is only can be user in relase-internal/debug mode:
31 //! DeclareUserSettingKeyForDebug("User Setting", MediaUserSetting::Device, MediaUserSetting::Value(true), true);
32 //! If the return value is MOS_STATUS_FILE_EXISTS, means "User Setting" has been used.
33 //! 2) Then we can use ReadUserSetting to read the value of the specific media user setting item.
34 //! If you want to provide the customized default value if failed call like:
35 //! ReadUserSetting(value, "User Setting", MediaUserSetting::Device, m_osInterface->pOsContext, true, true);
36 //! If you don't want to provide the customized default value:
37 //! ReadUserSetting(value, "User Setting", MediaUserSetting::Device, m_osInterface->pOsContext);
38 //! 3) If you want to write specific media user setting to configuration path, call:
39 //! WriteUserSetting("User Setting", MediaUserSetting::Value(false), m_osInterface->pOsContext)
40 //! If you just want to report the value of specific setting item, need to call like:
41 //! ReportUserSetting("User Setting", MediaUserSetting::Value(false), m_osInterface->pOsContext)
42 //!
43
44 #ifndef __MEDIA_USER_SETTING__H__
45 #define __MEDIA_USER_SETTING__H__
46
47 #include <string>
48 #include <map>
49 #include "media_user_setting_configure.h"
50
51 #define MOS_UserFeature_ReadValue_ID(pOsUserFeatureInterface, valueID, pValueData, osCtx) \
52 UserFeatureReadValue(pOsUserFeatureInterface, valueID, pValueData, osCtx)
53
54 #define MOS_UserFeature_WriteValues_ID(pOsUserFeatureInterface, pWriteValues, uiNumOfValues, osCtx) \
55 UserFeatureWriteValue(pOsUserFeatureInterface, pWriteValues, uiNumOfValues, osCtx)
56
57 #define WriteUserFeature(key, value, osCtx) \
58 { \
59 MOS_USER_FEATURE_VALUE_WRITE_DATA UserFeatureWriteData = __NULL_USER_FEATURE_VALUE_WRITE_DATA__; \
60 UserFeatureWriteData.Value.i32Data = (value); \
61 UserFeatureWriteData.ValueID = (key); \
62 UserFeatureWriteValue(nullptr, &UserFeatureWriteData, 1, osCtx); \
63 }
64
65 namespace MediaUserSetting {
66
67 class MediaUserSetting
68 {
69 public:
70 //!
71 //! \brief Constructor
72 //!
73 MediaUserSetting();
74
75 //!
76 //! \brief Constructor
77 //!
78 MediaUserSetting(MOS_USER_FEATURE_KEY_PATH_INFO *keyPathInfo);
79
80 //!
81 //! \brief Destructor
82 //!
83 virtual ~MediaUserSetting();
84
85 //!
86 //! \brief Register user setting item
87 //! \param [in] valueName
88 //! Name of the item
89 //! \param [in] group
90 //! Group of the item
91 //! \param [in] defaultValue
92 //! The default value of the item
93 //! \param [in] isReportKey
94 //! Whether this item can be reported
95 //! \param [in] debugOnly
96 //! Whether this item is only for debug/release-internal
97 //! \param [in] useCustomPath
98 //! Specifiy a read path
99 //! \param [in] customPath
100 //! The specified read path
101 //! \return MOS_STATUS
102 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
103 //!
104 virtual MOS_STATUS Register(
105 const std::string &valueName,
106 const Group &group,
107 const Value &defaultValue,
108 bool isReportKey = false,
109 bool debugOnly = false,
110 bool useCustomPath = false,
111 const std::string &customPath = "",
112 bool statePath = true);
113
114 //!
115 //! \brief Read value of specific item
116 //! \param [out] value
117 //! The return value of the item
118 //! \param [in] valueName
119 //! Name of the item
120 //! \param [in] group
121 //! Group of the item
122 //! \param [in] mosContext
123 //! The pointer of mos context
124 //! \param [in] customValue
125 //! The custom value when failed
126 //! \param [in] useCustomValue
127 //! Whether use costom value when failed
128 //! \return MOS_STATUS
129 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
130 //!
131 virtual MOS_STATUS Read(Value &value,
132 const std::string &valueName,
133 const Group &group,
134 const Value &customValue = Value(),
135 bool useCustomValue = false,
136 uint32_t option = MEDIA_USER_SETTING_INTERNAL);
137
138 //!
139 //! \brief Write value to specific item
140 //! \param [in] valueName
141 //! Name of the item
142 //! \param [in] value
143 //! The value write to specific item
144 //! \param [in] group
145 //! Group of the item
146 //! \param [in] mosContext
147 //! The pointer of mos context
148 //! \param [in] isForReport
149 //! This call is for reporting a item value or modify the value of the item
150 //! \return MOS_STATUS
151 //! MOS_STATUS_SUCCESS if no error, otherwise will return failed reason
152 //!
153 virtual MOS_STATUS Write(
154 const std::string &valueName,
155 const Value &value,
156 const Group &group,
157 bool isForReport = false,
158 uint32_t option = MEDIA_USER_SETTING_INTERNAL);
159
160 //!
161 //! \brief Check whether the key has been registered
162 //! \param [in] valueName
163 //! Name of the item
164 //! \return bool
165 //! true if user setting key has registered, otherwise will return false
166 //!
167 bool IsDeclaredUserSetting(const std::string &valueName);
168
169 //!
170 //! \brief Read single value from User Feature
171 //! \param [in] pOsUserFeatureInterface
172 //! Pointer to OS User Interface structure
173 //! \param [in] valueID
174 //! value of enum type in MOS_USER_FEATURE_VALUE_TYPE. declares the user feature key to be readed
175 //! \param [in,out] pValueData
176 //! Pointer to User Feature Data
177 //! \param [in] mosCtx
178 //! Pointer to DDI device context
179 //! \return MOS_STATUS
180 //! Returns one of the MOS_STATUS error codes if failed
181 //!
182 virtual MOS_STATUS UserFeatureReadValue(
183 PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface,
184 uint32_t valueID,
185 PMOS_USER_FEATURE_VALUE_DATA pValueData,
186 MOS_CONTEXT_HANDLE mosCtx);
187
188 //!
189 //! \brief Write Values to User Feature with specified ID
190 //! \param [in] pOsUserFeatureInterface
191 //! Pointer to OS User Interface structure
192 //! \param [in] pWriteValues
193 //! Pointer to User Feature Data, and related User Feature Key ID (enum type in MOS_USER_FEATURE_VALUE_TYPE)
194 //! \param [in] uiNumOfValues
195 //! number of user feature keys to be written.
196 //! \param [in] mosCtx
197 //! Pointer to DDI device context
198 //! \return MOS_STATUS
199 //! Returns one of the MOS_STATUS error codes if failed,
200 //! else MOS_STATUS_SUCCESS
201 //!
202 virtual MOS_STATUS UserFeatureWriteValue(
203 PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface,
204 PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues,
205 uint32_t uiNumOfValues,
206 MOS_CONTEXT_HANDLE mosCtx);
207
208 //!
209 //! \brief Get media user setting definitions of specific group
210 //! \param [in] group
211 //! Group of the item
212 //! \return Media user setting definitions
213 //! Definitions of specific group, return definitions of device group if failed
214 //!
GetDefinitions(const Group & group)215 inline Internal::Definitions &GetDefinitions(const Group &group)
216 {
217 return m_configure.GetDefinitions(group);
218 }
219
220 protected:
221 Internal::Configure m_configure{}; //!< The pointer of Configure
222 };
223
224 }
225
226 inline MOS_STATUS DeclareUserSettingKey(
227 MediaUserSettingSharedPtr userSetting,
228 const std::string &valueName,
229 const MediaUserSetting::Group &group,
230 const MediaUserSetting::Value &defaultValue,
231 bool isReportKey,
232 bool useCustomPath = false,
233 const std::string &customPath = "",
234 bool statePath = true)
235 {
236 if (nullptr == userSetting)
237 {
238 return MOS_STATUS_NULL_POINTER;
239 }
240 return userSetting->Register(valueName, group, defaultValue, isReportKey, false, useCustomPath, customPath, statePath);
241 }
242
243 inline MOS_STATUS ReadUserSetting(
244 MediaUserSettingSharedPtr userSetting,
245 MediaUserSetting::Value &value,
246 const std::string &valueName,
247 const MediaUserSetting::Group &group,
248 const MediaUserSetting::Value &customValue = MediaUserSetting::Value(),
249 bool useCustomValue = false,
250 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
251 {
252 if (nullptr == userSetting)
253 {
254 return MOS_STATUS_NULL_POINTER;
255 }
256 return userSetting->Read(value, valueName, group, customValue, useCustomValue, option);
257 }
258
259 template <typename T>
260 inline MOS_STATUS ReadUserSetting(
261 MediaUserSettingSharedPtr userSetting,
262 T &value,
263 const std::string &valueName,
264 const MediaUserSetting::Group &group,
265 const MediaUserSetting::Value &customValue = MediaUserSetting::Value(),
266 bool useCustomValue = false,
267 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
268 {
269 MediaUserSetting::Value outValue;
270 MOS_STATUS status = ReadUserSetting(userSetting, outValue, valueName, group, customValue, useCustomValue, option);
271 //If the user setting is not registered, it is not allowed to read a value for it.for internal user setting, Set it with the inital outValue; for external user setting, keep input value
272 //If user setting is not set, internal user setting outValue is the default value or customValue value if useCustomValue == true; for external user setting, keep input value
273 if (option != MEDIA_USER_SETTING_INTERNAL && status != MOS_STATUS_SUCCESS)
274 {
275 return status;
276 }
277 value = outValue.Get<T>();
278 return status;
279 }
280
281 inline MOS_STATUS WriteUserSetting(
282 MediaUserSettingSharedPtr userSetting,
283 const std::string &valueName,
284 const MediaUserSetting::Value &value,
285 const MediaUserSetting::Group &group,
286 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
287 {
288 if (nullptr == userSetting)
289 {
290 return MOS_STATUS_NULL_POINTER;
291 }
292 return userSetting->Write(valueName, value, group);
293 }
294
295 inline MOS_STATUS ReportUserSetting(
296 MediaUserSettingSharedPtr userSetting,
297 const std::string &valueName,
298 const MediaUserSetting::Value &value,
299 const MediaUserSetting::Group &group,
300 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
301 {
302 if (nullptr == userSetting)
303 {
304 return MOS_STATUS_NULL_POINTER;
305 }
306 return userSetting->Write(valueName, value, group, true, option);
307 }
308
IsDeclaredUserSetting(MediaUserSettingSharedPtr userSetting,const std::string & valueName)309 inline bool IsDeclaredUserSetting(
310 MediaUserSettingSharedPtr userSetting,
311 const std::string &valueName)
312 {
313 if (nullptr == userSetting)
314 {
315 return false;
316 }
317 return userSetting->IsDeclaredUserSetting(valueName);
318 }
319
320 #if (_DEBUG || _RELEASE_INTERNAL)
321 inline MOS_STATUS DeclareUserSettingKeyForDebug(
322 MediaUserSettingSharedPtr userSetting,
323 const std::string &valueName,
324 const MediaUserSetting::Group &group,
325 const MediaUserSetting::Value &defaultValue,
326 bool isReportKey,
327 bool useCustomPath = false,
328 const std::string &customPath = "",
329 bool statePath = true)
330 {
331 if (nullptr == userSetting)
332 {
333 return MOS_STATUS_NULL_POINTER;
334 }
335 return userSetting->Register(valueName, group, defaultValue, isReportKey, true, useCustomPath, customPath, statePath);
336 }
337
338 inline MOS_STATUS ReadUserSettingForDebug(
339 MediaUserSettingSharedPtr userSetting,
340 MediaUserSetting::Value &value,
341 const std::string &valueName,
342 const MediaUserSetting::Group &group,
343 const MediaUserSetting::Value &customValue = MediaUserSetting::Value(),
344 bool useCustomValue = false,
345 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
346 {
347 if (nullptr == userSetting)
348 {
349 return MOS_STATUS_NULL_POINTER;
350 }
351 return userSetting->Read(value, valueName, group, customValue, useCustomValue, option);
352 }
353
354 template <typename T>
355 inline MOS_STATUS ReadUserSettingForDebug(
356 MediaUserSettingSharedPtr userSetting,
357 T &value,
358 const std::string &valueName,
359 const MediaUserSetting::Group &group,
360 const MediaUserSetting::Value &customValue = MediaUserSetting::Value(),
361 bool useCustomValue = false,
362 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
363 {
364 MediaUserSetting::Value outValue;
365 MOS_STATUS status = ReadUserSettingForDebug(userSetting, outValue, valueName, group, customValue, useCustomValue, option);
366
367 //If the user setting is not registered, it is not allowed to read a value for it.for internal user setting, Set it with the inital outValue; for external user setting, keep input value
368 //If user setting is not set, internal user setting outValue is the default value or customValue value if useCustomValue == true; for external user setting, keep input value
369 if (option != MEDIA_USER_SETTING_INTERNAL && status != MOS_STATUS_SUCCESS)
370 {
371 return status;
372 }
373 value = outValue.Get<T>();
374 return status;
375 }
376
377 inline MOS_STATUS WriteUserSettingForDebug(
378 MediaUserSettingSharedPtr userSetting,
379 const std::string &valueName,
380 const MediaUserSetting::Value &value,
381 const MediaUserSetting::Group &group,
382 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
383 {
384 if (nullptr == userSetting)
385 {
386 return MOS_STATUS_NULL_POINTER;
387 }
388 return userSetting->Write(valueName, value, group);
389 }
390
391 inline MOS_STATUS ReportUserSettingForDebug(
392 MediaUserSettingSharedPtr userSetting,
393 const std::string &valueName,
394 const MediaUserSetting::Value &value,
395 const MediaUserSetting::Group &group,
396 uint32_t option = MEDIA_USER_SETTING_INTERNAL)
397 {
398 if (nullptr == userSetting)
399 {
400 return MOS_STATUS_NULL_POINTER;
401 }
402 return userSetting->Write(valueName, value, group, true, option);
403 }
404
405 #else
406 #define DeclareUserSettingKeyForDebug(userSetting, valueName, group, defaultValue, isReportKey, ...) MOS_STATUS_SUCCESS
407 #define ReadUserSettingForDebug(userSetting, value, valueName, group, ...) MOS_STATUS_SUCCESS
408 #define WriteUserSettingForDebug(userSetting, valueName, value, group, ...) MOS_STATUS_SUCCESS
409 #define ReportUserSettingForDebug(userSetting, valueName, value, group, ...) MOS_STATUS_SUCCESS
410 #endif
411
412 #endif