| 1 |
/* |
| 2 |
* Copyright (c) 2019-2022, 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 mos_utilities.h |
| 24 |
//! \brief Common OS service across different platform |
| 25 |
//! \details Common OS service across different platform |
| 26 |
//! |
| 27 |
#ifndef __MOS_UTILITIES_H__ |
| 28 |
#define __MOS_UTILITIES_H__ |
| 29 |
#include <fstream> |
| 30 |
#include <memory> |
| 31 |
#include <string> |
| 32 |
#include <vector> |
| 33 |
#include <stdint.h> |
| 34 |
#include <fstream> |
| 35 |
#include <map> |
| 36 |
#include <mutex> |
| 37 |
#include "mos_utilities_common.h" |
| 38 |
#include "media_class_trace.h" |
| 39 |
#include "mos_utilities_specific.h" |
| 40 |
#include "mos_resource_defs.h" |
| 41 |
#include "mos_os_trace_event.h" |
| 42 |
|
| 43 |
#define MOS_MAX_PERF_FILENAME_LEN 260 |
| 44 |
|
| 45 |
//------------------------------------------------------------------------------ |
| 46 |
// SECTION: Media User Feature Control |
| 47 |
// |
| 48 |
// ABSTRACT: Is an abstraction to read and write system level settings relating |
| 49 |
// to GEN media driver. |
| 50 |
//------------------------------------------------------------------------------ |
| 51 |
class MediaUserSettingsMgr; |
| 52 |
|
| 53 |
class MosMutex; |
| 54 |
typedef uint64_t REGHANDLE; |
| 55 |
typedef struct _EVENT_DESCRIPTOR EVENT_DESCRIPTOR; |
| 56 |
typedef const EVENT_DESCRIPTOR* PCEVENT_DESCRIPTOR; |
| 57 |
typedef struct _EVENT_DATA_DESCRIPTOR EVENT_DATA_DESCRIPTOR; |
| 58 |
|
| 59 |
namespace CommonLib |
| 60 |
{ |
| 61 |
class MosCallback; |
| 62 |
} |
| 63 |
|
| 64 |
class MosUtilities |
| 65 |
{ |
| 66 |
public: |
| 67 |
MosUtilities() = delete; |
| 68 |
~MosUtilities() = delete; |
| 69 |
|
| 70 |
MOS_FUNC_EXPORT static void MosSetUltFlag(uint8_t ultFlag); |
| 71 |
MOS_FUNC_EXPORT static int32_t MosGetMemNinjaCounter(); |
| 72 |
MOS_FUNC_EXPORT static int32_t MosGetMemNinjaCounterGfx(); |
| 73 |
|
| 74 |
friend class CommonLib::MosCallback; |
| 75 |
|
| 76 |
//! |
| 77 |
//! \brief Set trace setup info |
| 78 |
//! \details Set trace setup info |
| 79 |
//! \return MOS_STATUS |
| 80 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 81 |
//! else MOS_STATUS_SUCCESS |
| 82 |
//! |
| 83 |
static MOS_STATUS MosTraceSetupInfoInCommon(uint32_t DrvVer, uint32_t PlatFamily, uint32_t RenderFamily, uint32_t DeviceID); |
| 84 |
|
| 85 |
//! |
| 86 |
//! \brief Callback funtion for C Runtime (CRT) fwrite |
| 87 |
//! \details Every DLL has its own CRT |
| 88 |
//! When we share CRT objects such as file handles, we should use callback function. |
| 89 |
//! \param [in] buf |
| 90 |
//! Content Buffer |
| 91 |
//! \param [in] size |
| 92 |
//! Element size |
| 93 |
//! \param [in] count |
| 94 |
//! Element count |
| 95 |
//! \param [in] file |
| 96 |
//! Pointer to file |
| 97 |
//! \return MOS_STATUS |
| 98 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 99 |
//! else MOS_STATUS_SUCCESS |
| 100 |
//! |
| 101 |
static MOS_STATUS MosWriteFileInCommon(void const *buf, size_t size, size_t count, FILE *file); |
| 102 |
|
| 103 |
//! |
| 104 |
//! \brief Callback funtion for C Runtime (CRT) fflush |
| 105 |
//! \details Every DLL has its own CRT |
| 106 |
//! When we share CRT objects such as file handles, we should use callback function. |
| 107 |
//! \param [in] file |
| 108 |
//! Pointer to file |
| 109 |
//! \return MOS_STATUS |
| 110 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 111 |
//! else MOS_STATUS_SUCCESS |
| 112 |
//! |
| 113 |
static MOS_STATUS MosFlushToFileInCommon(FILE *file); |
| 114 |
|
| 115 |
static MOS_STATUS MosEventWriteInCommon( |
| 116 |
REGHANDLE regHandle, |
| 117 |
PCEVENT_DESCRIPTOR eventDescriptor, |
| 118 |
uint32_t userDataCount, |
| 119 |
EVENT_DATA_DESCRIPTOR* userData); |
| 120 |
|
| 121 |
//! |
| 122 |
//! \brief Get current run time |
| 123 |
//! \details Get current run time in us |
| 124 |
//! \return double |
| 125 |
//! Returns time in us |
| 126 |
//! |
| 127 |
static double MosGetTime(); |
| 128 |
|
| 129 |
//! |
| 130 |
//! \brief Print CPU Allocate Memory |
| 131 |
//! \details Print CPU Allocate Memory |
| 132 |
//! \return MOS_STATUS |
| 133 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 134 |
//! else MOS_STATUS_SUCCESS |
| 135 |
static MOS_STATUS MosPrintCPUAllocateMemory(int32_t event_id, int32_t level, |
| 136 |
int32_t param_id_1, int64_t value_1, int32_t param_id_2, int64_t value_2, const char *funName, const char *fileName, int32_t line); |
| 137 |
|
| 138 |
//! |
| 139 |
//! \brief Print CPU Destroy Memory |
| 140 |
//! \details Print CPU Destroy Memory |
| 141 |
//! \return MOS_STATUS |
| 142 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 143 |
//! else MOS_STATUS_SUCCESS |
| 144 |
static MOS_STATUS MosPrintCPUDestroyMemory(int32_t event_id, int32_t level, |
| 145 |
int32_t param_id_1, int64_t value_1, const char *funName, const char *fileName, int32_t line); |
| 146 |
|
| 147 |
//! |
| 148 |
//! \brief Get current run time |
| 149 |
//! \details Get current run time in us |
| 150 |
//! \return double |
| 151 |
//! Returns time in us |
| 152 |
//! |
| 153 |
static uint64_t MosGetCurTime(); |
| 154 |
|
| 155 |
#if MOS_MESSAGES_ENABLED |
| 156 |
template<class _Ty, class... _Types> |
| 157 |
static _Ty* MosNewUtil(const char* functionName, |
| 158 |
const char* filename, |
| 159 |
int32_t line, _Types&&... _Args); |
| 160 |
#else |
| 161 |
template<class _Ty, class... _Types> |
| 162 |
static _Ty* MosNewUtil(_Types&&... _Args); |
| 163 |
#endif |
| 164 |
|
| 165 |
#if MOS_MESSAGES_ENABLED |
| 166 |
template<class _Ty, class... _Types> |
| 167 |
static _Ty* MosNewArrayUtil(const char* functionName, |
| 168 |
const char* filename, |
| 169 |
int32_t line, size_t numElements); |
| 170 |
#else |
| 171 |
template<class _Ty, class... _Types> |
| 172 |
static _Ty* MosNewArrayUtil(size_t numElements); |
| 173 |
#endif |
| 174 |
|
| 175 |
#if MOS_MESSAGES_ENABLED |
| 176 |
template<class _Ty> |
| 177 |
static void MosDeleteUtil( |
| 178 |
const char* functionName, |
| 179 |
const char* filename, |
| 180 |
int32_t line, |
| 181 |
_Ty& ptr); |
| 182 |
#else |
| 183 |
template<class _Ty> |
| 184 |
static void MosDeleteUtil(_Ty& ptr); |
| 185 |
#endif |
| 186 |
|
| 187 |
#if MOS_MESSAGES_ENABLED |
| 188 |
template<class _Ty> |
| 189 |
static void MosDeleteArrayUtil( |
| 190 |
const char *functionName, |
| 191 |
const char *filename, |
| 192 |
int32_t line, |
| 193 |
_Ty& ptr); |
| 194 |
#else |
| 195 |
template <class _Ty> |
| 196 |
static void MosDeleteArrayUtil(_Ty& ptr); |
| 197 |
#endif |
| 198 |
|
| 199 |
//! |
| 200 |
//! \brief Init Function for MOS utilitiesNext |
| 201 |
//! \details Initial MOS utilitiesNext related structures, and only execute once for multiple entries |
| 202 |
//! \param [in] userSettingPtr |
| 203 |
//! user setting ptr |
| 204 |
//! \return MOS_STATUS |
| 205 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 206 |
//! else MOS_STATUS_SUCCESS |
| 207 |
//! |
| 208 |
static MOS_STATUS MosUtilitiesInit(MediaUserSettingSharedPtr userSettingPtr); |
| 209 |
|
| 210 |
//! |
| 211 |
//! \brief Close Function for MOS utilitiesNext |
| 212 |
//! \details close/remove MOS utilitiesNext related structures, and only execute once for multiple entries |
| 213 |
//! \param [in] userSettingPtr |
| 214 |
//! MediaUserSettingSharedPtr |
| 215 |
//! \return MOS_STATUS |
| 216 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 217 |
//! else MOS_STATUS_SUCCESS |
| 218 |
//! |
| 219 |
static MOS_STATUS MosUtilitiesClose(MediaUserSettingSharedPtr userSettingPtr); |
| 220 |
|
| 221 |
private: |
| 222 |
|
| 223 |
//! |
| 224 |
//! \brief Init user feature |
| 225 |
//! \details Initial MOS OS specific utilitiesNext related structures, and only execute once for multiple entries |
| 226 |
//! \return MOS_STATUS |
| 227 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 228 |
//! else MOS_STATUS_SUCCESS |
| 229 |
//! |
| 230 |
static MOS_STATUS MosDeclareUserFeature(); |
| 231 |
|
| 232 |
//! |
| 233 |
//! \brief Init Function for MOS OS specific utilitiesNext |
| 234 |
//! \details Initial MOS OS specific utilitiesNext related structures, and only execute once for multiple entries |
| 235 |
//! \param [in] userSettingPtr |
| 236 |
//! MediaUserSettingSharedPtr |
| 237 |
//! \return MOS_STATUS |
| 238 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 239 |
//! else MOS_STATUS_SUCCESS |
| 240 |
//! |
| 241 |
static MOS_STATUS MosOsUtilitiesInit(MediaUserSettingSharedPtr userSettingPtr); |
| 242 |
|
| 243 |
//! |
| 244 |
//! \brief Init Mos os utilities in common dll |
| 245 |
//! \details Init Mos os utilities in common dll |
| 246 |
//! \param [in] userSettingPtr |
| 247 |
//! MediaUserSettingSharedPtr |
| 248 |
//! \return MOS_STATUS |
| 249 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 250 |
//! else MOS_STATUS_SUCCESS |
| 251 |
//! |
| 252 |
static MOS_STATUS MosOsUtilitiesInitInCommon(MediaUserSettingSharedPtr userSettingPtr); |
| 253 |
|
| 254 |
//! |
| 255 |
//! \brief Close Mos os utilities in common dll |
| 256 |
//! \details Close Mos os utilities in common dll |
| 257 |
//! \param [in] userSettingPtr |
| 258 |
//! MediaUserSettingSharedPtr |
| 259 |
//! \return MOS_STATUS |
| 260 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 261 |
//! else MOS_STATUS_SUCCESS |
| 262 |
//! |
| 263 |
static MOS_STATUS MosOsUtilitiesCloseInCommon(MediaUserSettingSharedPtr userSettingPtr); |
| 264 |
|
| 265 |
//! |
| 266 |
//! \brief Init mos utilities values from common dll |
| 267 |
//! \details Init mos utilities values from common dll |
| 268 |
//! \return MOS_STATUS |
| 269 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 270 |
//! else MOS_STATUS_SUCCESS |
| 271 |
//! |
| 272 |
static MOS_STATUS MosInitOsUtilitiesValuesFromCommon(); |
| 273 |
|
| 274 |
//! |
| 275 |
//! \brief Clear mos utilities values from common dll |
| 276 |
//! \details Clear mos utilities values from common dll |
| 277 |
//! \return MOS_STATUS |
| 278 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 279 |
//! else MOS_STATUS_SUCCESS |
| 280 |
//! |
| 281 |
static MOS_STATUS MosClearOsUtilitiesValuesFromCommon(); |
| 282 |
|
| 283 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 284 |
//! |
| 285 |
//! \brief Init simulate random memory allocation fail flag in Common dll |
| 286 |
//! \details Init simulate random memory allocation fail flag in Common dll |
| 287 |
//! \param [in] userSettingPtr |
| 288 |
//! MediaUserSettingSharedPtr |
| 289 |
//! \return void |
| 290 |
//! |
| 291 |
static MOS_STATUS MosInitAllocFailSimulateFlagInCommon(MediaUserSettingSharedPtr userSettingPtr); |
| 292 |
#endif |
| 293 |
|
| 294 |
//! |
| 295 |
//! \brief Init user feature |
| 296 |
//! \details Initial MOS OS specific utilitiesNext related structures, and only execute once for multiple entries |
| 297 |
//! \return MOS_STATUS |
| 298 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 299 |
//! else MOS_STATUS_SUCCESS |
| 300 |
//! |
| 301 |
static MOS_STATUS MosDestroyUserFeature(); |
| 302 |
|
| 303 |
//! |
| 304 |
//! \brief Close Function for MOS OS utilitiesNext |
| 305 |
//! \details close/remove MOS OS utilitiesNext related structures, and only execute once for multiple entries |
| 306 |
//! \return MOS_STATUS |
| 307 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 308 |
//! else MOS_STATUS_SUCCESS |
| 309 |
//! |
| 310 |
static MOS_STATUS MosOsUtilitiesClose(MediaUserSettingSharedPtr userSettingPtr); |
| 311 |
|
| 312 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 313 |
//! |
| 314 |
//! \brief Init simulate random memory allocation fail flag |
| 315 |
//! \details init MosSimulateRandomAllocMemoryFailFlag according user feature value: |
| 316 |
//! __MEDIA_USER_FEATURE_VALUE_SIMULATE_RANDOM_ALLOC_MEMORY_FAIL |
| 317 |
//! \param [in] userSettingPtr |
| 318 |
//! MediaUserSettingSharedPtr |
| 319 |
//! \return void |
| 320 |
//! |
| 321 |
static void MosInitAllocMemoryFailSimulateFlag(MediaUserSettingSharedPtr userSettingPtr); |
| 322 |
|
| 323 |
static bool MosSimulateAllocMemoryFail( |
| 324 |
size_t size, |
| 325 |
size_t alignment, |
| 326 |
const char *functionName, |
| 327 |
const char *filename, |
| 328 |
int32_t line); |
| 329 |
|
| 330 |
#endif //(_DEBUG || _RELEASE_INTERNAL) |
| 331 |
public: |
| 332 |
//------------------------------------------------------------------------------ |
| 333 |
// Allocate, free and set a memory region |
| 334 |
//------------------------------------------------------------------------------ |
| 335 |
//! |
| 336 |
//! \brief Allocates aligned memory and performs error checking |
| 337 |
//! \details Wrapper for aligned_malloc(). Performs error checking. |
| 338 |
//! It increases memory allocation counter variable |
| 339 |
//! m_mosMemAllocCounter for checking memory leaks. |
| 340 |
//! \param [in] size |
| 341 |
//! Size of memorry to be allocated |
| 342 |
//! \param [in] alignment |
| 343 |
//! alignment |
| 344 |
//! \return void * |
| 345 |
//! Pointer to allocated memory |
| 346 |
//! |
| 347 |
// APO_MOS_WRAPPER |
| 348 |
#if MOS_MESSAGES_ENABLED |
| 349 |
static void *MosAlignedAllocMemoryUtils( |
| 350 |
size_t size, |
| 351 |
size_t alignment, |
| 352 |
const char *functionName, |
| 353 |
const char *filename, |
| 354 |
int32_t line); |
| 355 |
|
| 356 |
#else // !MOS_MESSAGES_ENABLED |
| 357 |
|
| 358 |
static void *MosAlignedAllocMemory( |
| 359 |
size_t size, |
| 360 |
size_t alignment); |
| 361 |
|
| 362 |
#endif // MOS_MESSAGES_ENABLED |
| 363 |
|
| 364 |
//! |
| 365 |
//! \brief Wrapper for aligned_free(). Performs error checking. |
| 366 |
//! \details Wrapper for aligned_free() - Free a block of memory that was allocated by MOS_AlignedAllocMemory. |
| 367 |
//! Performs error checking. |
| 368 |
//! It decreases memory allocation counter variable |
| 369 |
//! m_mosMemAllocCounter for checking memory leaks. |
| 370 |
//! \param [in] ptr |
| 371 |
//! Pointer to the memory to be freed |
| 372 |
//! \return void |
| 373 |
//! |
| 374 |
#if MOS_MESSAGES_ENABLED |
| 375 |
static void MosAlignedFreeMemoryUtils( |
| 376 |
void *ptr, |
| 377 |
const char *functionName, |
| 378 |
const char *filename, |
| 379 |
int32_t line); |
| 380 |
|
| 381 |
#else // !MOS_MESSAGES_ENABLED |
| 382 |
|
| 383 |
static void MosAlignedFreeMemory(void *ptr); |
| 384 |
|
| 385 |
#endif // MOS_MESSAGES_ENABLED |
| 386 |
|
| 387 |
//! |
| 388 |
//! \brief Allocates memory and performs error checking |
| 389 |
//! \details Wrapper for malloc(). Performs error checking. |
| 390 |
//! It increases memory allocation counter variable |
| 391 |
//! m_mosMemAllocCounter for checking memory leaks. |
| 392 |
//! \param [in] size |
| 393 |
//! Size of memorry to be allocated |
| 394 |
//! \return void * |
| 395 |
//! Pointer to allocated memory |
| 396 |
//! |
| 397 |
// APO_MOS_WRAPPER |
| 398 |
#if MOS_MESSAGES_ENABLED |
| 399 |
static void *MosAllocMemoryUtils( |
| 400 |
size_t size, |
| 401 |
const char *functionName, |
| 402 |
const char *filename, |
| 403 |
int32_t line); |
| 404 |
|
| 405 |
#else // !MOS_MESSAGES_ENABLED |
| 406 |
|
| 407 |
static void *MosAllocMemory( |
| 408 |
size_t size); |
| 409 |
|
| 410 |
#endif // MOS_MESSAGES_ENABLED |
| 411 |
|
| 412 |
//! |
| 413 |
//! \brief Allocates and fills memory with 0 |
| 414 |
//! \details Wrapper for malloc(). Performs error checking, |
| 415 |
//! and fills the allocated memory with 0. |
| 416 |
//! It increases memory allocation counter variable |
| 417 |
//! m_mosMemAllocCounter for checking memory leaks. |
| 418 |
//! \param [in] size |
| 419 |
//! Size of memorry to be allocated |
| 420 |
//! \return void * |
| 421 |
//! Pointer to allocated memory |
| 422 |
//! |
| 423 |
#if MOS_MESSAGES_ENABLED |
| 424 |
static void *MosAllocAndZeroMemoryUtils( |
| 425 |
size_t size, |
| 426 |
const char *functionName, |
| 427 |
const char *filename, |
| 428 |
int32_t line); |
| 429 |
|
| 430 |
#else // !MOS_MESSAGES_ENABLED |
| 431 |
static void *MosAllocAndZeroMemory( |
| 432 |
size_t size); |
| 433 |
#endif // MOS_MESSAGES_ENABLED |
| 434 |
|
| 435 |
//! |
| 436 |
//! \brief Reallocate memory |
| 437 |
//! \details Wrapper for realloc(). Performs error checking. |
| 438 |
//! It modifies memory allocation counter variable |
| 439 |
//! m_mosMemAllocCounter for checking memory leaks. |
| 440 |
//! \param [in] ptr |
| 441 |
//! Pointer to be reallocated |
| 442 |
//! \param [in] new_size |
| 443 |
//! Size of memory to be allocated |
| 444 |
//! \return void * |
| 445 |
//! Pointer to allocated memory |
| 446 |
//! |
| 447 |
#if MOS_MESSAGES_ENABLED |
| 448 |
static void *MosReallocMemoryUtils( |
| 449 |
void *ptr, |
| 450 |
size_t newSize, |
| 451 |
const char *functionName, |
| 452 |
const char *filename, |
| 453 |
int32_t line); |
| 454 |
|
| 455 |
#else // !MOS_MESSAGES_ENABLED |
| 456 |
static void *MosReallocMemory( |
| 457 |
void *ptr, |
| 458 |
size_t newSize); |
| 459 |
#endif // MOS_MESSAGES_ENABLED |
| 460 |
|
| 461 |
//! |
| 462 |
//! \brief Wrapper for free(). Performs error checking. |
| 463 |
//! \details Wrapper for free(). Performs error checking. |
| 464 |
//! It decreases memory allocation counter variable |
| 465 |
//! m_mosMemAllocCounter for checking memory leaks. |
| 466 |
//! \param [in] ptr |
| 467 |
//! Pointer to the memory to be freed |
| 468 |
//! \return void |
| 469 |
//! |
| 470 |
// APO_MOS_WRAPPER |
| 471 |
#if MOS_MESSAGES_ENABLED |
| 472 |
static void MosFreeMemoryUtils( |
| 473 |
void *ptr, |
| 474 |
const char *functionName, |
| 475 |
const char *filename, |
| 476 |
int32_t line); |
| 477 |
|
| 478 |
#else // !MOS_MESSAGES_ENABLED |
| 479 |
static void MosFreeMemory( |
| 480 |
void *ptr); |
| 481 |
#endif // MOS_MESSAGES_ENABLED |
| 482 |
|
| 483 |
//! |
| 484 |
//! \brief Wrapper to set a block of memory with zeros. |
| 485 |
//! \details Wrapper to set a block of memory with zeros. |
| 486 |
//! \param [in] pDestination |
| 487 |
//! A pointer to the starting address of the memory |
| 488 |
//! block to fill with zeros. |
| 489 |
//! \param [in] stLength |
| 490 |
//! Size of the memory block in bytes to be filled |
| 491 |
//! \return void |
| 492 |
//! |
| 493 |
// APO_MOS_WRAPPER |
| 494 |
static void MosZeroMemory( |
| 495 |
void *pDestination, |
| 496 |
size_t stLength); |
| 497 |
|
| 498 |
//! |
| 499 |
//! \brief Wrapper to set a block of memory with a specified value. |
| 500 |
//! \details Wrapper to set a block of memory with a specified value. |
| 501 |
//! \param [in] pDestination |
| 502 |
//! A pointer to the starting address of the memory |
| 503 |
//! block to fill with specified value bFill |
| 504 |
//! \param [in] stLength |
| 505 |
//! Size of the memory block in bytes to be filled |
| 506 |
//! \param [in] bFill |
| 507 |
//! The byte value with which to fill the memory block |
| 508 |
//! \return void |
| 509 |
//! |
| 510 |
// APO_MOS_WRAPPER |
| 511 |
static void MosFillMemory( |
| 512 |
void *pDestination, |
| 513 |
size_t stLength, |
| 514 |
uint8_t bFill); |
| 515 |
|
| 516 |
//------------------------------------------------------------------------------ |
| 517 |
// File I/O Functions |
| 518 |
//------------------------------------------------------------------------------ |
| 519 |
//! |
| 520 |
//! \brief Allocate a buffer and read contents from a file into this buffer |
| 521 |
//! \details Allocate a buffer and read contents from a file into this buffer |
| 522 |
//! \param [in] PpFilename |
| 523 |
//! ointer to the filename from which to read |
| 524 |
//! \param [out] lpNumberOfBytesRead, |
| 525 |
//! pointer to return the number of bytes read |
| 526 |
//! \param [out] ppReadBuffer |
| 527 |
//! Pointer to return the buffer pointer where |
| 528 |
//! the contents from the file are read to |
| 529 |
//! \return MOS_STATUS |
| 530 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 531 |
//! else MOS_STATUS_SUCCESS |
| 532 |
//! |
| 533 |
static MOS_STATUS MosReadFileToPtr( |
| 534 |
const char *pFilename, |
| 535 |
uint32_t *lpNumberOfBytesRead, |
| 536 |
void **ppReadBuffer); |
| 537 |
|
| 538 |
//! |
| 539 |
//! \brief Writes contents of buffer into a file |
| 540 |
//! \details Writes contents of buffer into a file |
| 541 |
//! \param [in] pFilename |
| 542 |
//! Pointer to the filename to write the contents to |
| 543 |
//! \param [in] lpBuffer |
| 544 |
//! Pointer to the buffer whose contents will be written to the file |
| 545 |
//! \param [in] writeSize |
| 546 |
//! Number of bytes to write to the file |
| 547 |
//! \return MOS_STATUS |
| 548 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 549 |
//! else MOS_STATUS_SUCCESS |
| 550 |
//! |
| 551 |
static MOS_STATUS MosWriteFileFromPtr( |
| 552 |
const char *pFilename, |
| 553 |
void *lpBuffer, |
| 554 |
uint32_t writeSize); |
| 555 |
|
| 556 |
//! |
| 557 |
//! \brief Retrieves the size of the specified File. |
| 558 |
//! \details Retrieves the size of the specified File. |
| 559 |
//! \param [in] hFile |
| 560 |
//! Handle to the File. |
| 561 |
//! \param [out] lpFileSizeLow |
| 562 |
//! Pointer to a variable where filesize is returned |
| 563 |
//! \param lpFileSizeHigh |
| 564 |
//! Reserved for now. Used to return higher uint32_t for |
| 565 |
//! filesizes more than 32 bit |
| 566 |
//! \return MOS_STATUS |
| 567 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 568 |
//! else MOS_STATUS_SUCCESS |
| 569 |
//! |
| 570 |
static MOS_STATUS MosGetFileSize( |
| 571 |
HANDLE hFile, |
| 572 |
uint32_t *lpFileSizeLow, |
| 573 |
uint32_t *lpFileSizeHigh); |
| 574 |
|
| 575 |
//! |
| 576 |
//! \brief Creates a directory |
| 577 |
//! \details Creates a directory |
| 578 |
//! \param [in] lpPathName |
| 579 |
//! Pointer to the path name |
| 580 |
//! \return MOS_STATUS |
| 581 |
//! Returns MOS_STATUS_SUCCESS if directory was created or was already exists, |
| 582 |
//! else MOS_STATUS_DIR_CREATE_FAILED |
| 583 |
//! |
| 584 |
static MOS_STATUS MosCreateDirectory( |
| 585 |
char * const lpPathName); |
| 586 |
|
| 587 |
//! |
| 588 |
//! \brief Creates or opens a file/object |
| 589 |
//! \details Creates or opens a file/object |
| 590 |
//! The definitions of the mode flags for iOpenFlag are in OS's fcntl.h |
| 591 |
//! \param [out] pHandle |
| 592 |
//! Pointer to a variable that recieves the handle |
| 593 |
//! of the file or object oepned |
| 594 |
//! \param [in] lpFileName |
| 595 |
//! Pointer to the file name |
| 596 |
//! \param [in] iOpenFlag |
| 597 |
//! Flag specifying mode and other options for Creating |
| 598 |
//! \return MOS_STATUS |
| 599 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 600 |
//! else MOS_STATUS_SUCCESS |
| 601 |
//! |
| 602 |
static MOS_STATUS MosCreateFile( |
| 603 |
PHANDLE pHandle, |
| 604 |
char * const lpFileName, |
| 605 |
uint32_t iOpenFlag); |
| 606 |
|
| 607 |
//! |
| 608 |
//! \brief Read data from a file |
| 609 |
//! \details Read data from a file |
| 610 |
//! \param [in] hFile |
| 611 |
//! Handle to the file to be read |
| 612 |
//! \param [out] lpBuffer |
| 613 |
//! Pointer to the buffer where the data read is placed |
| 614 |
//! \param [in] bytesToRead |
| 615 |
//! The maximum number of bytes to be read |
| 616 |
//! \param [out] pbytesRead |
| 617 |
//! Pointer to a variable that receives the number of bytes read |
| 618 |
//! \param [in/out] lpOverlapped |
| 619 |
//! Not used currently, can be nullptr |
| 620 |
//! When the hFile parameter was opened with FILE_FLAG_OVERLAPPED |
| 621 |
//! It should point to a valid OVERLAPPED structure |
| 622 |
//! \return MOS_STATUS |
| 623 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 624 |
//! else MOS_STATUS_SUCCESS |
| 625 |
//! |
| 626 |
static MOS_STATUS MosReadFile( |
| 627 |
HANDLE hFile, |
| 628 |
void *lpBuffer, |
| 629 |
uint32_t bytesToRead, |
| 630 |
uint32_t *pbytesRead, |
| 631 |
void *lpOverlapped); |
| 632 |
|
| 633 |
//! |
| 634 |
//! \brief Write data to a file |
| 635 |
//! \details Write data to a file |
| 636 |
//! \param [in] hFile |
| 637 |
//! Handle to the file to which data will be written |
| 638 |
//! \param [in] lpBuffer |
| 639 |
//! Pointer to the buffer from where the data is read |
| 640 |
//! \param [in] bytesToWrite |
| 641 |
//! The maximum number of bytes to be written |
| 642 |
//! \param [out] pbytesWritten |
| 643 |
//! Pointer to a variable that receives the number of bytes written |
| 644 |
//! \param [in/out] lpOverlapped |
| 645 |
//! Not used currently, can be nullptr |
| 646 |
//! When the hFile parameter was opened with FILE_FLAG_OVERLAPPED |
| 647 |
//! It should point to a valid OVERLAPPED structure |
| 648 |
//! \return MOS_STATUS |
| 649 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 650 |
//! else MOS_STATUS_SUCCESS |
| 651 |
//! |
| 652 |
static MOS_STATUS MosWriteFile( |
| 653 |
HANDLE hFile, |
| 654 |
void *lpBuffer, |
| 655 |
uint32_t bytesToWrite, |
| 656 |
uint32_t *pbytesWritten, |
| 657 |
void *lpOverlapped); |
| 658 |
|
| 659 |
//! |
| 660 |
//! \brief Moves the File pointer to the specified position |
| 661 |
//! \details Moves the File pointer to the specified position |
| 662 |
//! Specify dwMoveMethod as the same as fseek() |
| 663 |
//! \param [in] hFile |
| 664 |
//! Handle to the file |
| 665 |
//! \param [in] lDistanceToMove |
| 666 |
//! Specifies no. of bytes to move the pointer |
| 667 |
//! \param [in] lpDistanceToMoveHigh |
| 668 |
//! Pointer to the high order 32-bits of |
| 669 |
//! the signed 64-bit distance to move. |
| 670 |
//! \param [in] dwMoveMethod |
| 671 |
//! Starting point for the file pointer move |
| 672 |
//! \return MOS_STATUS |
| 673 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 674 |
//! else MOS_STATUS_SUCCESS |
| 675 |
//! |
| 676 |
static MOS_STATUS MosSetFilePointer( |
| 677 |
HANDLE hFile, |
| 678 |
int32_t lDistanceToMove, |
| 679 |
int32_t *lpDistanceToMoveHigh, |
| 680 |
int32_t dwMoveMethod); |
| 681 |
|
| 682 |
//! |
| 683 |
//! \brief Closes an open object handle |
| 684 |
//! \details Closes an open object handle. |
| 685 |
//! \param [in] hObject |
| 686 |
//! A valid handle to an open object. |
| 687 |
//! \return int32_t |
| 688 |
//! true if success else false |
| 689 |
//! |
| 690 |
static int32_t MosCloseHandle( |
| 691 |
HANDLE hObject); |
| 692 |
|
| 693 |
//! |
| 694 |
//! \brief Link the m_mosUserFeatureDescFields table items to MosUtilUserInterface::m_userFeatureKeyMap |
| 695 |
//! \details Link the m_mosUserFeatureDescFields table items to MosUtilUserInterface::m_userFeatureKeyMap |
| 696 |
//! according to ID sequence and do some post processing such as malloc related memory |
| 697 |
//! \return MOS_STATUS |
| 698 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 699 |
//! else MOS_STATUS_SUCCESS |
| 700 |
//! |
| 701 |
static MOS_STATUS MosDeclareUserFeatureKeysForAllDescFields(); |
| 702 |
|
| 703 |
//! |
| 704 |
//! \brief Appends at the end of File |
| 705 |
//! \details Appends at the end of File |
| 706 |
//! \param [in] pFilename |
| 707 |
//! Pointer to the filename to append the contents to |
| 708 |
//! \param [in] pData |
| 709 |
//! Pointer to the buffer whose contents will be appeneded to the file |
| 710 |
//! \param [in] dwSize |
| 711 |
//! Number of bytes to append to the file |
| 712 |
//! \return MOS_STATUS |
| 713 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 714 |
//! else MOS_STATUS_SUCCESS |
| 715 |
//! |
| 716 |
static MOS_STATUS MosAppendFileFromPtr( |
| 717 |
const char *pFilename, |
| 718 |
void *pData, |
| 719 |
uint32_t dwSize); |
| 720 |
|
| 721 |
//! |
| 722 |
//! \brief Generate a User Feature Keys XML file according to user feature keys table in MOS |
| 723 |
//! \details Generate a User Feature Keys XML files according to m_mosUserFeatureDescFields |
| 724 |
//! \param [in] mosCtx |
| 725 |
//! os device ctx handle |
| 726 |
//! \return MOS_STATUS |
| 727 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 728 |
//! else MOS_STATUS_SUCCESS |
| 729 |
//! |
| 730 |
static MOS_STATUS MosGenerateUserFeatureKeyXML(MOS_CONTEXT_HANDLE mosCtx); |
| 731 |
|
| 732 |
//! |
| 733 |
//! \brief Link user feature key description table items to specified UserFeatureKeyTable |
| 734 |
//! \details Link user feature key description table items to specified UserFeatureKeyTable |
| 735 |
//! according to ID sequence and do some post processing such as malloc related memory |
| 736 |
//! \param [in] userValueDescTable |
| 737 |
//! The user feature key description table |
| 738 |
//! \param [in] numOfValues |
| 739 |
//! Number of user feature keys described in the table |
| 740 |
//! \param [in] maxId |
| 741 |
//! Max value ID in the table |
| 742 |
//! \param [out] keyValueMap |
| 743 |
//! optional pointer to the value map where the table items will be linked to, could be nullptr |
| 744 |
//! \return MOS_STATUS |
| 745 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 746 |
//! else MOS_STATUS_SUCCESS |
| 747 |
//! |
| 748 |
static MOS_STATUS MosDeclareUserFeatureKeysFromDescFields( |
| 749 |
MOS_USER_FEATURE_VALUE *userValueDescTable, |
| 750 |
uint32_t numOfValues, |
| 751 |
uint32_t maxId); |
| 752 |
|
| 753 |
//! |
| 754 |
//! |
| 755 |
//! \brief Destroy the User Feature Value pointer according to the DescField Table |
| 756 |
//! \details Destroy the User Feature Value pointer according to the DescField Table |
| 757 |
//! destroy the user feature key value Map according to Declare Count |
| 758 |
//! \param [in] descTable |
| 759 |
//! The user feature key description table |
| 760 |
//! \param [in] numOfItems |
| 761 |
//! Number of user feature keys described in the table |
| 762 |
//! \param [in] maxId |
| 763 |
//! Max value ID in the table |
| 764 |
//! \return MOS_STATUS |
| 765 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 766 |
//! else MOS_STATUS_SUCCESS |
| 767 |
//! |
| 768 |
static MOS_STATUS MosDestroyUserFeatureKeysFromDescFields( |
| 769 |
MOS_USER_FEATURE_VALUE *descTable, |
| 770 |
uint32_t numOfItems, |
| 771 |
uint32_t maxId); |
| 772 |
|
| 773 |
//! |
| 774 |
//! \brief Unlink the user feature key Desc Fields table items to key value map |
| 775 |
//! \details Unlink the user feature key Desc Fields table items to key value map |
| 776 |
//! according to ID sequence and do some post processing by calling MosDestroyUserFeatureData |
| 777 |
//! \param [in] pUserFeatureKey |
| 778 |
//! Pointer to the User Feature Value needed to be destroyed |
| 779 |
//! \return MOS_STATUS |
| 780 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 781 |
//! else MOS_STATUS_SUCCESS |
| 782 |
//! |
| 783 |
static MOS_STATUS MosDestroyUserFeatureKey(PMOS_USER_FEATURE_VALUE pUserFeatureKey); |
| 784 |
|
| 785 |
//! |
| 786 |
//! \brief Link the user feature key Desc Fields table items to key value map |
| 787 |
//! \details Link the user feature key Desc Fields table items to key value map |
| 788 |
//! according to ID sequence and do some post processing by calling MosAssignUserFeatureValueData |
| 789 |
//! \param [in] pUserFeatureKey |
| 790 |
//! Pointer to the User Feature Value needed to be declared |
| 791 |
//! \return MOS_STATUS |
| 792 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 793 |
//! else MOS_STATUS_SUCCESS |
| 794 |
//! |
| 795 |
static MOS_STATUS MosDeclareUserFeatureKey(PMOS_USER_FEATURE_VALUE pUserFeatureKey); |
| 796 |
|
| 797 |
//! |
| 798 |
//! \brief Copy the VALUE_DATA from source to destination pointer |
| 799 |
//! \details Copy the VALUE_DATA from source to destination pointer |
| 800 |
//! \param [in] pSrcData |
| 801 |
//! Pointer to the Source Value Data |
| 802 |
//! \param [in] pDstData |
| 803 |
//! Pointer to the Destination Value Data |
| 804 |
//! \param [in] ValueType |
| 805 |
//! Value Type for the copy data |
| 806 |
//! \return MOS_STATUS |
| 807 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 808 |
//! else MOS_STATUS_SUCCESS |
| 809 |
//! |
| 810 |
static MOS_STATUS MosCopyUserFeatureValueData( |
| 811 |
PMOS_USER_FEATURE_VALUE_DATA pSrcData, |
| 812 |
PMOS_USER_FEATURE_VALUE_DATA pDstData, |
| 813 |
MOS_USER_FEATURE_VALUE_TYPE ValueType |
| 814 |
); |
| 815 |
|
| 816 |
//! |
| 817 |
//! \brief Read Single Value from User Feature based on value of enum type in MOS_USER_FEATURE_VALUE_TYPE |
| 818 |
//! \details This is a unified funtion to read user feature key for all components. |
| 819 |
//! (Codec/VP/CP/CM) |
| 820 |
//! It is required to prepare all memories for buffers before calling this function. |
| 821 |
//! User can choose to use array variable or allocated memory for the buffer. |
| 822 |
//! If the buffer is allocated dynamically, it must be freed by user to avoid memory leak. |
| 823 |
//! ------------------------------------------------------------------------------------ |
| 824 |
//! Usage example: |
| 825 |
//! a) Initiation: |
| 826 |
//! MosZeroMemory(&UserFeatureData, sizeof(UserFeatureData)); |
| 827 |
//! b.0) Don't need to input a default value if the default value in user feature key Desc Fields table item is good |
| 828 |
//! for your case |
| 829 |
//! b.1) For uint32_t type: |
| 830 |
//! UserFeatureData.u32Data = 1; // overwrite a custom default value |
| 831 |
//! UserFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE; |
| 832 |
//! // raise a flag to use this custom default value instead of |
| 833 |
//! default value in user feature key Desc Fields table item |
| 834 |
//! b.2) For String/Binary type: |
| 835 |
//! char cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE]; |
| 836 |
//! UserFeatureData.StringData.pStringData = cStringData; // make sure the pointer is valid |
| 837 |
//! b.3) For MultiString type: |
| 838 |
//! char cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE]; |
| 839 |
//! MOS_USER_FEATURE_VALUE_STRING Strings[__MAX_MULTI_STRING_COUNT]; |
| 840 |
//! UserFeatureData.MultiStringData.pMultStringData = cStringData; // make sure the pointer is valid |
| 841 |
//! for (ui = 0; ui < VPHAL_3P_MAX_LIB_PATH_COUNT; ui++) |
| 842 |
//! { |
| 843 |
//! Strings[ui].pStringData = (char *)MOS_AllocAndZeroMemory(MOS_USER_CONTROL_MAX_DATA_SIZE); |
| 844 |
//! } |
| 845 |
//! UserFeatureData.MultiStringData.pStrings = Strings; |
| 846 |
//! c) Read user feature key: |
| 847 |
//! MosUserFeatureReadValueID(); |
| 848 |
//! ------------------------------------------------------------------------------------- |
| 849 |
//! Important note: The pointer pStringData/pMultStringData may be modified if the |
| 850 |
//! previous MOS_UserFeature_ReadValue() doesn't read a same user feature key type. So it's |
| 851 |
//! suggested to set the union members in UserFeatureValue every time before |
| 852 |
//! MOS_UserFeature_ReadValue() if you are not familiar with the details of this function. |
| 853 |
//! If a new key is added, please make sure to declare a definition in corresponding |
| 854 |
//! user feature key Desc Fields tableby MOS_DECLARE_UF_KEY |
| 855 |
//! \param [in] pOsUserFeatureInterface |
| 856 |
//! Pointer to OS User Interface structure |
| 857 |
//! \param [in] ValueID |
| 858 |
//! value of enum type in MOS_USER_FEATURE_VALUE_TYPE. declares the user feature key to be readed |
| 859 |
//! \param [in,out] pValueData |
| 860 |
//! Pointer to User Feature Data |
| 861 |
//! \param [in] mosCtx |
| 862 |
//! Pointer to DDI device context |
| 863 |
//! \return MOS_STATUS |
| 864 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 865 |
//! else MOS_STATUS_SUCCESS |
| 866 |
//! For pValueData return value: |
| 867 |
//! MOS_STATUS_SUCCESS: pValueData is from User Feature Key |
| 868 |
//! MOS_STATUS_USER_FEATURE_KEY_OPEN_FAILED: pValueData is from default value |
| 869 |
//! MOS_STATUS_UNKNOWN: pValueData is from default value |
| 870 |
//! MOS_STATUS_USER_FEATURE_KEY_READ_FAILED: pValueData is from default value |
| 871 |
//! MOS_STATUS_NULL_POINTER: NO USER FEATURE KEY DEFINITION in corresponding user feature key Desc Field table, |
| 872 |
//! No default value or User Feature Key value return |
| 873 |
//! |
| 874 |
//! |
| 875 |
static MOS_STATUS MosUserFeatureReadValueID( |
| 876 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 877 |
uint32_t ValueID, |
| 878 |
PMOS_USER_FEATURE_VALUE_DATA pValueData, |
| 879 |
MOS_CONTEXT_HANDLE mosCtx); |
| 880 |
|
| 881 |
//! \param [in] pOsUserFeatureInterface |
| 882 |
//! Pointer to OS User Interface structure |
| 883 |
//! \param [in] ValueID |
| 884 |
//! value of enum type in MOS_USER_FEATURE_VALUE_TYPE. declares the user feature key to be readed |
| 885 |
//! \param [in/out] pUserData |
| 886 |
//! Pointer to User Feature Data |
| 887 |
//! \param [in] pUserData |
| 888 |
//! Pointer to User Feature Data |
| 889 |
//! \param [in] ufInfo |
| 890 |
//! Pointer to MOS_USER_FEATURE_KEY_PATH_INFO |
| 891 |
//! \return MOS_STATUS |
| 892 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 893 |
//! else MOS_STATUS_SUCCESS |
| 894 |
static MOS_STATUS MosUserFeatureReadValueID( |
| 895 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 896 |
uint32_t ValueID, |
| 897 |
PMOS_USER_FEATURE_VALUE_DATA pValueData, |
| 898 |
MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo); |
| 899 |
|
| 900 |
//! |
| 901 |
//! \brief Write Values to User Feature with specified ID |
| 902 |
//! \details Write Values to User Feature with specified ID |
| 903 |
//! The caller is responsible to allocate values / names |
| 904 |
//! and free them later if necessary |
| 905 |
//! \param [in] pOsUserFeatureInterface |
| 906 |
//! Pointer to OS User Interface structure |
| 907 |
//! \param [in] pWriteValues |
| 908 |
//! Pointer to User Feature Data, and related User Feature Key ID (enum type in MOS_USER_FEATURE_VALUE_TYPE) |
| 909 |
//! \param [in] uiNumOfValues |
| 910 |
//! number of user feature keys to be written. |
| 911 |
//! \param [in] mosCtx |
| 912 |
//! Pointer to DDI device context |
| 913 |
//! \return MOS_STATUS |
| 914 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 915 |
//! else MOS_STATUS_SUCCESS |
| 916 |
//! |
| 917 |
static MOS_STATUS MosUserFeatureWriteValuesID( |
| 918 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 919 |
PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues, |
| 920 |
uint32_t uiNumOfValues, |
| 921 |
MOS_CONTEXT_HANDLE mosCtx); |
| 922 |
|
| 923 |
//! |
| 924 |
//! \brief Write Values to User Feature with specified ID |
| 925 |
//! \details Write Values to User Feature with specified ID |
| 926 |
//! The caller is responsible to allocate values / names |
| 927 |
//! and free them later if necessary |
| 928 |
//! \param [in] pOsUserFeatureInterface |
| 929 |
//! Pointer to OS User Interface structure |
| 930 |
//! \param [in] pWriteValues |
| 931 |
//! Pointer to User Feature Data, and related User Feature Key ID (enum type in MOS_USER_FEATURE_VALUE_TYPE) |
| 932 |
//! \param [in] uiNumOfValues |
| 933 |
//! number of user feature keys to be written. |
| 934 |
//! \param [in] ufInfo |
| 935 |
//! Pointer to MOS_USER_FEATURE_KEY_PATH_INFO |
| 936 |
//! \return MOS_STATUS |
| 937 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 938 |
//! else MOS_STATUS_SUCCESS |
| 939 |
//! |
| 940 |
static MOS_STATUS MosUserFeatureWriteValuesID( |
| 941 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 942 |
PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues, |
| 943 |
uint32_t uiNumOfValues, |
| 944 |
MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo); |
| 945 |
|
| 946 |
//! |
| 947 |
//! \brief Lookup the user feature value name associated with the ID |
| 948 |
//! \details Lookup the user feature value name associated with the ID |
| 949 |
//! \param [in] ValueId |
| 950 |
//! The user feature value ID to be looked up |
| 951 |
//! \return const char* |
| 952 |
//! pointer to the char array holding the user feature value name |
| 953 |
//! |
| 954 |
static const char *MosUserFeatureLookupValueName(uint32_t ValueID); |
| 955 |
|
| 956 |
//! |
| 957 |
//! \brief Lookup the read path associated with the ID |
| 958 |
//! \param [in] ValueId |
| 959 |
//! The user feature value ID to be looked up |
| 960 |
//! \return pointer to the char array holding the read path |
| 961 |
//! |
| 962 |
static const char *MosUserFeatureLookupReadPath(uint32_t ValueID); |
| 963 |
|
| 964 |
//! |
| 965 |
//! \brief Lookup the write path associated with the ID |
| 966 |
//! \param [in] ValueId |
| 967 |
//! The user feature value ID to be looked up |
| 968 |
//! \return pointer to the char array holding the write path |
| 969 |
//! |
| 970 |
static const char *MosUserFeatureLookupWritePath(uint32_t ValueID); |
| 971 |
|
| 972 |
//! |
| 973 |
//! \brief Enable user feature change notification |
| 974 |
//! \details Enable user feature change notification |
| 975 |
//! Create notification data and register the wait event |
| 976 |
//! \param [in] pOsUserFeatureInterface |
| 977 |
//! Pointer to OS User Interface structure |
| 978 |
//! \param [in/out] pNotification |
| 979 |
//! Pointer to User Feature Notification Data |
| 980 |
//! \param [in] mosCtx |
| 981 |
//! Pointer to DDI device handle |
| 982 |
//! \return MOS_STATUS |
| 983 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 984 |
//! else MOS_STATUS_SUCCESS |
| 985 |
//! |
| 986 |
static MOS_STATUS MosUserFeatureEnableNotification( |
| 987 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 988 |
PMOS_USER_FEATURE_NOTIFY_DATA pNotification, |
| 989 |
MOS_CONTEXT_HANDLE mosCtx); |
| 990 |
|
| 991 |
//! |
| 992 |
//! \brief Disable user feature change notification |
| 993 |
//! \details Disable user feature change notification |
| 994 |
//! Unregister the wait event and frees notification data |
| 995 |
//! \param [in] pOsUserFeatureInterface |
| 996 |
//! Pointer to OS User Interface structure |
| 997 |
//! \param [in/out] pNotification |
| 998 |
//! Pointer to User Feature Notification Data |
| 999 |
//! \return MOS_STATUS |
| 1000 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1001 |
//! else MOS_STATUS_SUCCESS |
| 1002 |
//! |
| 1003 |
static MOS_STATUS MosUserFeatureDisableNotification( |
| 1004 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 1005 |
PMOS_USER_FEATURE_NOTIFY_DATA pNotification); |
| 1006 |
|
| 1007 |
//! |
| 1008 |
//! \brief Parses the user feature path and gets type and sub path |
| 1009 |
//! \details Parses the user feature path and gets type and sub path |
| 1010 |
//! It verifies if the user feature path is valid, |
| 1011 |
//! and check if it belongs to UFEXT or UFINT UFKEY. |
| 1012 |
//! The identified type and subpath are set accordingly. |
| 1013 |
//! \param [in] pOsUserFeatureInterface, |
| 1014 |
//! Pointer to OS User Interface structure |
| 1015 |
//! \param [in] pInputPath |
| 1016 |
//! The input user feature path |
| 1017 |
//! \param [out] pUserFeatureType |
| 1018 |
//! Pointer to the variable to receive user feature type |
| 1019 |
//! \param [out] ppSubPath |
| 1020 |
//! Pointer to a variable that accepts the pointer to the subpath |
| 1021 |
//! \return MOS_STATUS |
| 1022 |
//! Returns MOS_STATUS_INVALID_PARAMETER if failed, else MOS_STATUS_SUCCESS |
| 1023 |
//! |
| 1024 |
static MOS_STATUS MosUserFeatureParsePath( |
| 1025 |
PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface, |
| 1026 |
char * const pInputPath, |
| 1027 |
PMOS_USER_FEATURE_TYPE pUserFeatureType, |
| 1028 |
char **ppSubPath); |
| 1029 |
|
| 1030 |
//! |
| 1031 |
//! \brief Set the User Feature Default Value |
| 1032 |
//! \details Set the User Feature Default Value in the user feature key map |
| 1033 |
//! \param PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface |
| 1034 |
//! [in] Pointer to OS User Interface structure |
| 1035 |
//! \param PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues |
| 1036 |
//! [in] Pointer to User Feature Write Datas |
| 1037 |
//! \return MOS_STATUS |
| 1038 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1039 |
//! else MOS_STATUS_SUCCESS |
| 1040 |
//! |
| 1041 |
MOS_STATUS MosUserFeatureSetDefaultValues( |
| 1042 |
PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues, |
| 1043 |
uint32_t uiNumOfValues); |
| 1044 |
|
| 1045 |
//! |
| 1046 |
//! \brief Read the User Feature Value of ApoMosEnabled |
| 1047 |
//! \details Read the User Feature Value of ApoMosEnabled |
| 1048 |
//! \param uint32_t& userfeatureValue |
| 1049 |
//! [in] reference to a userfeatureValue |
| 1050 |
//! \param char *path |
| 1051 |
//! [in] stated uf key path |
| 1052 |
//! \param MediaUserSettingSharedPtr |
| 1053 |
//! [in] shared ptr to usersetting instance of a device |
| 1054 |
//! \return MOS_STATUS |
| 1055 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1056 |
//! else MOS_STATUS_SUCCESS |
| 1057 |
//! |
| 1058 |
static MOS_STATUS MosReadApoMosEnabledUserFeature(uint32_t &userfeatureValue, char *path, MediaUserSettingSharedPtr userSettingPtr); |
| 1059 |
|
| 1060 |
//! |
| 1061 |
//! \brief Read the User Feature Value of ApoDdiEnabled |
| 1062 |
//! \details Read the User Feature Value of ApoDdiEnabled |
| 1063 |
//! \param uint32_t& userfeatureValue |
| 1064 |
//! [in] reference to a userfeatureValue |
| 1065 |
//! \param char *path |
| 1066 |
//! [in] stated uf key path |
| 1067 |
//! \param MediaUserSettingSharedPtr |
| 1068 |
//! [in] shared ptr to usersetting instance of a device |
| 1069 |
//! \return MOS_STATUS |
| 1070 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1071 |
//! else MOS_STATUS_SUCCESS |
| 1072 |
//! |
| 1073 |
static MOS_STATUS MosReadApoDdiEnabledUserFeature(uint32_t &userfeatureValue, char *path, MediaUserSettingSharedPtr userSettingPtr); |
| 1074 |
|
| 1075 |
//! \brief Read the User Feature Value of Media Solo |
| 1076 |
//! \details Read the User Feature Value of Media Solo |
| 1077 |
//! \param uint32_t& mediasoloEnabled |
| 1078 |
//! [out] media solo statue |
| 1079 |
//! \return MOS_STATUS |
| 1080 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1081 |
//! else MOS_STATUS_SUCCESS |
| 1082 |
//! |
| 1083 |
static MOS_STATUS MosReadMediaSoloEnabledUserFeature(bool &mediasoloEnabled); |
| 1084 |
|
| 1085 |
//------------------------------------------------------------------------------ |
| 1086 |
// String Functions |
| 1087 |
//------------------------------------------------------------------------------ |
| 1088 |
//! |
| 1089 |
//! \brief String concatenation with security checks. |
| 1090 |
//! \details String concatenation with security checks. |
| 1091 |
//! Append strSource to strDestination, with buffer size checking |
| 1092 |
//! \param [in/out] strDestination |
| 1093 |
//! Pointer to destination string |
| 1094 |
//! \param [in] numberOfElements |
| 1095 |
//! Size of the destination buffer |
| 1096 |
//! \param [in] strSource |
| 1097 |
//! Pointer to the source string |
| 1098 |
//! \return MOS_STATUS |
| 1099 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1100 |
//! else MOS_STATUS_SUCCESS |
| 1101 |
//! |
| 1102 |
static MOS_STATUS MosSecureStrcat( |
| 1103 |
char *strDestination, |
| 1104 |
size_t numberOfElements, |
| 1105 |
const char * const strSource); |
| 1106 |
|
| 1107 |
//! |
| 1108 |
//! \brief Find string token with security checks. |
| 1109 |
//! \details Find string token with security checks. |
| 1110 |
//! Subsequent calls with nullptr in strToken and same contex to get |
| 1111 |
//! remaining tokens |
| 1112 |
//! \param [in/out] strToken |
| 1113 |
//! String containing token or tokens |
| 1114 |
//! Pass nullptr for this parameter in subsequent calls |
| 1115 |
//! to MosSecureStrtok to find the remaining tokens |
| 1116 |
//! \param [in] strDelimit |
| 1117 |
//! Set of delimiter characters |
| 1118 |
//! \param [in/out] contex |
| 1119 |
//! Used to store position information between calls to MosSecureStrtok |
| 1120 |
//! \return char * |
| 1121 |
//! Returns tokens else nullptr |
| 1122 |
//! |
| 1123 |
static char *MosSecureStrtok( |
| 1124 |
char *strToken, |
| 1125 |
const char *strDelimit, |
| 1126 |
char **contex); |
| 1127 |
|
| 1128 |
//! |
| 1129 |
//! \brief String copy with security checks. |
| 1130 |
//! \details String copy with security checks. |
| 1131 |
//! Copy strSource to strDestination, with buffer size checking |
| 1132 |
//! \param [out] strDestination |
| 1133 |
//! Pointer to destination string |
| 1134 |
//! \param [in] numberOfElements |
| 1135 |
//! Size of the destination buffer |
| 1136 |
//! \param [in] strSource |
| 1137 |
//! Pointer to the source string |
| 1138 |
//! \return MOS_STATUS |
| 1139 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1140 |
//! else MOS_STATUS_SUCCESS |
| 1141 |
//! |
| 1142 |
static MOS_STATUS MosSecureStrcpy( |
| 1143 |
char *strDestination, |
| 1144 |
size_t numberOfElements, |
| 1145 |
const char * const strSource); |
| 1146 |
|
| 1147 |
//! |
| 1148 |
//! \brief String copy with security checks. |
| 1149 |
//! \details String copy with security checks. |
| 1150 |
//! Copy strSource to strDestination, with buffer size checking |
| 1151 |
//! \param [out] strDestination |
| 1152 |
//! Pointer to the character array to copy to, destsz |
| 1153 |
//! \param [in] destsz |
| 1154 |
//! Size of the destination buffer |
| 1155 |
//! \param [in] strSource |
| 1156 |
//! Pointer to the character array to copy from |
| 1157 |
//! \param [in] maxCount |
| 1158 |
//! Maximum number of characters to copy |
| 1159 |
//! \return MOS_STATUS |
| 1160 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1161 |
//! else MOS_STATUS_SUCCESS |
| 1162 |
//! |
| 1163 |
static MOS_STATUS MosSecureStrncpy( |
| 1164 |
char *strDestination, |
| 1165 |
size_t destSz, |
| 1166 |
const char* const strSource, |
| 1167 |
size_t maxCount); |
| 1168 |
|
| 1169 |
//! |
| 1170 |
//! \brief Memory copy with security checks. |
| 1171 |
//! \details Memory copy with security checks. |
| 1172 |
//! Copy pSource to pDestination, with buffer size checking |
| 1173 |
//! \param [out] pDestination |
| 1174 |
//! Pointer to destination buffer |
| 1175 |
//! \param [in] dstLength |
| 1176 |
//! Size of the destination buffer |
| 1177 |
//! \param [in] pSource |
| 1178 |
//! Pointer to the source buffer |
| 1179 |
//! \param [in] srcLength |
| 1180 |
//! Number of bytes to copy from source to destination |
| 1181 |
//! \return MOS_STATUS |
| 1182 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1183 |
//! else MOS_STATUS_SUCCESS |
| 1184 |
//! |
| 1185 |
static MOS_STATUS MosSecureMemcpy( |
| 1186 |
void *pDestination, |
| 1187 |
size_t dstLength, |
| 1188 |
const void *pSource, |
| 1189 |
size_t srcLength); |
| 1190 |
|
| 1191 |
//! |
| 1192 |
//! \brief Open a file with security checks. |
| 1193 |
//! \details Open a file with security checks. |
| 1194 |
//! \param [out] ppFile |
| 1195 |
//! Pointer to a variable that receives the file pointer. |
| 1196 |
//! \param [in] filename |
| 1197 |
//! Pointer to the file name string |
| 1198 |
//! \param [in] mode |
| 1199 |
//! Specifies open mode such as read, write etc |
| 1200 |
//! \return MOS_STATUS |
| 1201 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1202 |
//! else MOS_STATUS_SUCCESS |
| 1203 |
//! |
| 1204 |
static MOS_STATUS MosSecureFileOpen( |
| 1205 |
FILE **ppFile, |
| 1206 |
const char *filename, |
| 1207 |
const char *mode); |
| 1208 |
|
| 1209 |
//! |
| 1210 |
//! \brief Write formatted data to a string with security checks. |
| 1211 |
//! \details Write formatted data to a string with security checks. |
| 1212 |
//! Optional arguments are passed in individually |
| 1213 |
//! Buffer must have space for null character after copying length |
| 1214 |
//! \param [out] buffer |
| 1215 |
//! Pointer to a string to which formatted data is printed |
| 1216 |
//! \param [in] bufSize |
| 1217 |
//! Size of the buffer where the data is printed |
| 1218 |
//! \param [in] length |
| 1219 |
//! Number of characters to be printed |
| 1220 |
//! \param [in] format |
| 1221 |
//! Format string to be printed |
| 1222 |
//! \return int32_t |
| 1223 |
//! Returns the number of characters printed or -1 if an error occurs |
| 1224 |
//! |
| 1225 |
static int32_t MosSecureStringPrint( |
| 1226 |
char *buffer, |
| 1227 |
size_t bufSize, |
| 1228 |
size_t length, |
| 1229 |
const char * const format, |
| 1230 |
...); |
| 1231 |
|
| 1232 |
//! |
| 1233 |
//! \brief Write formatted data to a string with security checks, va_list version |
| 1234 |
//! \details Write formatted data to a string with security checks. |
| 1235 |
//! Pointer to an optional arguments list is passed in |
| 1236 |
//! Buffer must have space for null character after copying length |
| 1237 |
//! \param [out] buffer |
| 1238 |
//! Pointer to a string to which formatted data is printed |
| 1239 |
//! \param [in] bufSize |
| 1240 |
//! Size of the buffer where the data is printed |
| 1241 |
//! \param [in] length |
| 1242 |
//! Number of characters to be printed |
| 1243 |
//! \param [in] format |
| 1244 |
//! Format string to be printed |
| 1245 |
//! \param [in] var_args |
| 1246 |
//! Optional argument list |
| 1247 |
//! \return int32_t |
| 1248 |
//! Returns the number of characters printed or -1 if an error occurs |
| 1249 |
//! |
| 1250 |
static MOS_STATUS MosSecureVStringPrint( |
| 1251 |
char *buffer, |
| 1252 |
size_t bufSize, |
| 1253 |
size_t length, |
| 1254 |
const char * const format, |
| 1255 |
va_list var_args); |
| 1256 |
|
| 1257 |
//------------------------------------------------------------------------------ |
| 1258 |
// Library, process and OS related functions |
| 1259 |
//------------------------------------------------------------------------------ |
| 1260 |
//! |
| 1261 |
//! \brief Maps the specified executable module into the address space of |
| 1262 |
//! the calling process. |
| 1263 |
//! \details Maps the specified executable module into the address space of |
| 1264 |
//! the calling process. |
| 1265 |
//! \param [in] lpLibFileName |
| 1266 |
//! A valid handle to an open object. |
| 1267 |
//! \param [out] phModule |
| 1268 |
//! Pointer variable that accepts the module handle |
| 1269 |
//! \return MOS_STATUS |
| 1270 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 1271 |
//! else MOS_STATUS_SUCCESS |
| 1272 |
//! |
| 1273 |
static MOS_STATUS MosLoadLibrary( |
| 1274 |
const char * const lpLibFileName, |
| 1275 |
PHMODULE phModule); |
| 1276 |
|
| 1277 |
//! |
| 1278 |
//! \brief Free the loaded dynamic-link library |
| 1279 |
//! \details Free the loaded dynamic-link library |
| 1280 |
//! \param [in] hLibModule |
| 1281 |
//! A handle to the loaded DLL module |
| 1282 |
//! \return int32_t |
| 1283 |
//! true if success else false |
| 1284 |
//! |
| 1285 |
static int32_t MosFreeLibrary(HMODULE hLibModule); |
| 1286 |
|
| 1287 |
//! |
| 1288 |
//! \brief Retrieves the address of an exported function or variable from |
| 1289 |
//! the specified dynamic-link library |
| 1290 |
//! \details Retrieves the address of an exported function or variable from |
| 1291 |
//! the specified dynamic-link library |
| 1292 |
//! \param [in] hLibModule |
| 1293 |
//! A handle to the loaded DLL module. |
| 1294 |
//! The LoadLibrary function returns this handle. |
| 1295 |
//! \param [in] lpProcName |
| 1296 |
//! The function or variable name, or the function's ordinal value. |
| 1297 |
//! \return void * |
| 1298 |
//! If succeeds, the return value is the address of the exported |
| 1299 |
//! function or variable. If fails, the return value is NULL. |
| 1300 |
//! To get extended error information, call GetLastError. |
| 1301 |
//! |
| 1302 |
static void *MosGetProcAddress( |
| 1303 |
HMODULE hModule, |
| 1304 |
const char *lpProcName); |
| 1305 |
|
| 1306 |
//! |
| 1307 |
//! \brief Retrieves the current process id |
| 1308 |
//! \details Retrieves the current process id |
| 1309 |
//! \return int32_t |
| 1310 |
//! Return the current process id |
| 1311 |
//! |
| 1312 |
static int32_t MosGetPid(); |
| 1313 |
|
| 1314 |
//! |
| 1315 |
//! \brief Retrieves the frequency of the high-resolution performance |
| 1316 |
//! counter, if one exists. |
| 1317 |
//! \details Retrieves the frequency of the high-resolution performance |
| 1318 |
//! counter, if one exists. |
| 1319 |
//! \param [out] pFrequency |
| 1320 |
//! Pointer to a variable that receives the current |
| 1321 |
//! performance-counter frequency, in counts per second. |
| 1322 |
//! \return int32_t |
| 1323 |
//! If the installed hardware supports a high-resolution performance |
| 1324 |
//! counter, the return value is nonzero. If the function fails, the |
| 1325 |
//! return value is zero. |
| 1326 |
//! |
| 1327 |
static int32_t MosQueryPerformanceFrequency( |
| 1328 |
uint64_t *pFrequency); |
| 1329 |
|
| 1330 |
//! |
| 1331 |
//! \brief Retrieves the current value of the high-resolution performance |
| 1332 |
//! counter |
| 1333 |
//! \details Retrieves the current value of the high-resolution performance |
| 1334 |
//! counter |
| 1335 |
//! \param [out] pPerformanceCount |
| 1336 |
//! Pointer to a variable that receives the current |
| 1337 |
//! performance-counter value, in counts. |
| 1338 |
//! \return int32_t |
| 1339 |
//! If the installed hardware supports a high-resolution performance |
| 1340 |
//! counter, the return value is nonzero. If the function fails, the |
| 1341 |
//! return value is zero. To get extended error information, call GetLastError. |
| 1342 |
//! |
| 1343 |
static int32_t MosQueryPerformanceCounter( |
| 1344 |
uint64_t *pPerformanceCount); |
| 1345 |
|
| 1346 |
//! |
| 1347 |
//! \brief Sleep for given duration in ms |
| 1348 |
//! \details Sleep for given duration ms |
| 1349 |
//! \param [in] mSec |
| 1350 |
//! Sleep duration in ms |
| 1351 |
//! \return void |
| 1352 |
//! |
| 1353 |
static void MosSleep( |
| 1354 |
uint32_t mSec); |
| 1355 |
|
| 1356 |
//! |
| 1357 |
//! \brief Initialize reg related resources |
| 1358 |
//! |
| 1359 |
static MOS_STATUS MosInitializeReg(RegBufferMap ®BufferMap); |
| 1360 |
|
| 1361 |
//! |
| 1362 |
//! \brief Uninitialize reg related resources |
| 1363 |
//! |
| 1364 |
static MOS_STATUS MosUninitializeReg(RegBufferMap ®BufferMap); |
| 1365 |
//! |
| 1366 |
//! \brief Creates the specified reg key |
| 1367 |
//! \details Creates the specified reg key. If the key already exists, |
| 1368 |
//! the function opens it. |
| 1369 |
//! \param [in] keyHandle |
| 1370 |
//! Handle to a currently open key. |
| 1371 |
//! \param [in] subKey |
| 1372 |
//! Pointer to a null-terminated string specifying the name of a |
| 1373 |
//! subkey that this function opens or creates. |
| 1374 |
//! \param [in] samDesired |
| 1375 |
//! A mask that specifies the access rights for the key to be created. |
| 1376 |
//! \param [out] key |
| 1377 |
//! A pointer to a variable that receives a handle to the opened or created key. |
| 1378 |
//! \param [in] regBufferMap |
| 1379 |
//! A reference to RegBuffermap. |
| 1380 |
//! \return MOS_STATUS |
| 1381 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1382 |
//! If the function fails, the return value is a error code. |
| 1383 |
//! |
| 1384 |
static MOS_STATUS MosCreateRegKey( |
| 1385 |
UFKEY_NEXT keyHandle, |
| 1386 |
const std::string &subKey, |
| 1387 |
uint32_t samDesired, |
| 1388 |
PUFKEY_NEXT key, |
| 1389 |
RegBufferMap ®BufferMap); |
| 1390 |
|
| 1391 |
//! |
| 1392 |
//! \brief Opens the specified reg key. |
| 1393 |
//! \details Opens the specified reg key. |
| 1394 |
//! \param [in] keyHandle |
| 1395 |
//! A handle to an open reg key. |
| 1396 |
//! \param [in] subKey |
| 1397 |
//! The name of the reg subkey to be opened. |
| 1398 |
//! \param [in] samDesired |
| 1399 |
//! A mask that specifies the desired access rights to the key to be opened. |
| 1400 |
//! \param [out] key |
| 1401 |
//! A pointer to a variable that receives a handle to the opened key. |
| 1402 |
//! \param [in] regBufferMap |
| 1403 |
//! A reference to RegBuffermap. |
| 1404 |
//! \return MOS_STATUS |
| 1405 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1406 |
//! If the function fails, the return value is a error code. |
| 1407 |
//! |
| 1408 |
static MOS_STATUS MosOpenRegKey( |
| 1409 |
UFKEY_NEXT keyHandle, |
| 1410 |
const std::string &subKey, |
| 1411 |
uint32_t samDesired, |
| 1412 |
PUFKEY_NEXT key, |
| 1413 |
RegBufferMap ®BufferMap); |
| 1414 |
|
| 1415 |
//! |
| 1416 |
//! \brief Closes a handle to the specified reg key. |
| 1417 |
//! \details Closes a handle to the specified reg key. |
| 1418 |
//! \param [in] keyHandle |
| 1419 |
//! A handle to an open reg key. |
| 1420 |
//! \return MOS_STATUS |
| 1421 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1422 |
//! If the function fails, the return value is a error code. |
| 1423 |
//! |
| 1424 |
static MOS_STATUS MosCloseRegKey( |
| 1425 |
UFKEY_NEXT keyHandle); |
| 1426 |
|
| 1427 |
//! |
| 1428 |
//! \brief Retrieves the type and data for the specified env variable. |
| 1429 |
//! \details Retrieves the type and data for the specified env variable. |
| 1430 |
//! \param [in] keyHandle |
| 1431 |
//! A handle to an open reg key. |
| 1432 |
//! \param [in] valueName |
| 1433 |
//! The name of the reg value. |
| 1434 |
//! \param [in] type |
| 1435 |
//! A pointer to a variable that receives a code indicating the |
| 1436 |
//! type of data stored in the specified value. |
| 1437 |
//! \param [out] data |
| 1438 |
//! Buffer that receives the value's data. |
| 1439 |
//! \return MOS_STATUS |
| 1440 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1441 |
//! If the function fails, the return value is a error code. |
| 1442 |
//! |
| 1443 |
static MOS_STATUS MosReadEnvVariable( |
| 1444 |
const std::string &valueName, |
| 1445 |
MOS_USER_FEATURE_VALUE_TYPE type, |
| 1446 |
MediaUserSetting::Value &data); |
| 1447 |
|
| 1448 |
static bool MosEnvVariableEqual( |
| 1449 |
const std::string envName, |
| 1450 |
const std::string targetVal); |
| 1451 |
|
| 1452 |
//! |
| 1453 |
//! \brief Retrieves the type and data for the specified reg value. |
| 1454 |
//! \details Retrieves the type and data for the specified reg value. |
| 1455 |
//! \param [in] keyHandle |
| 1456 |
//! A handle to an open reg key. |
| 1457 |
//! \param [in] valueName |
| 1458 |
//! The name of the reg value. |
| 1459 |
//! \param [in] type |
| 1460 |
//! A pointer to a variable that receives a code indicating the |
| 1461 |
//! type of data stored in the specified value. |
| 1462 |
//! \param [out] data |
| 1463 |
//! Buffer that receives the value's data. |
| 1464 |
//! \param [out] size |
| 1465 |
//! A pointer to a variable that specifies the size of the buffer |
| 1466 |
//! pointed to by the data parameter, in bytes. |
| 1467 |
//! \param [in] regBufferMap |
| 1468 |
//! A reference to RegBuffermap. |
| 1469 |
//! \return MOS_STATUS |
| 1470 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1471 |
//! If the function fails, the return value is a error code. |
| 1472 |
//! |
| 1473 |
static MOS_STATUS MosGetRegValue( |
| 1474 |
UFKEY_NEXT keyHandle, |
| 1475 |
const std::string &valueName, |
| 1476 |
MOS_USER_FEATURE_VALUE_TYPE defaultType, |
| 1477 |
MediaUserSetting::Value &data, |
| 1478 |
RegBufferMap ®BufferMap); |
| 1479 |
|
| 1480 |
//! |
| 1481 |
//! \brief Sets the data and type of a specified value under a reg key. |
| 1482 |
//! \details Sets the data and type of a specified value under a reg key. |
| 1483 |
//! \param [in] keyHandle |
| 1484 |
//! A handle to an open reg key. |
| 1485 |
//! \param [in] valueName |
| 1486 |
//! The name of the value to be set. |
| 1487 |
//! \param [in] type |
| 1488 |
//! The type of data parameter. |
| 1489 |
//! \param [out] data |
| 1490 |
//! The data to be stored. |
| 1491 |
//! \return MOS_STATUS |
| 1492 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1493 |
//! If the function fails, the return value is a error code. |
| 1494 |
//! |
| 1495 |
static MOS_STATUS MosSetRegValue( |
| 1496 |
UFKEY_NEXT keyHandle, |
| 1497 |
const std::string &valueName, |
| 1498 |
const MediaUserSetting::Value &data, |
| 1499 |
RegBufferMap ®BufferMap); |
| 1500 |
|
| 1501 |
//------------------------------------------------------------------------------ |
| 1502 |
// Wrappers for OS Specific User Feature Functions Implementations |
| 1503 |
//------------------------------------------------------------------------------ |
| 1504 |
//! |
| 1505 |
//! \brief Opens the specified user feature key |
| 1506 |
//! \details Opens the specified user feature key |
| 1507 |
//! \param [in] ufKey |
| 1508 |
//! A handle to an open user feature key. |
| 1509 |
//! \param [in] lpSubKey |
| 1510 |
//! The name of the user feature subkey to be opened. |
| 1511 |
//! \param [in] lOptions |
| 1512 |
//! This parameter is reserved and must be zero. |
| 1513 |
//! \param [in] samDesired |
| 1514 |
//! Reserved, could be any REGSAM type value |
| 1515 |
//! \param [out] phkResult |
| 1516 |
//! A pointer to a variable that receives a handle to the opened key. |
| 1517 |
//! \param [in] ufInfo |
| 1518 |
//! Poniter to MOS_USER_FEATURE_KEY_PATH_INFO |
| 1519 |
//! \return MOS_STATUS |
| 1520 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1521 |
//! If the function fails, the return value is a error code defined |
| 1522 |
//! in mos_utilitiesNext.h. |
| 1523 |
//! |
| 1524 |
static MOS_STATUS MosUserFeatureOpenKey( |
| 1525 |
void *ufKey, |
| 1526 |
const char *lpSubKey, |
| 1527 |
uint32_t ulOptions, |
| 1528 |
uint32_t samDesired, |
| 1529 |
void **phkResult, |
| 1530 |
MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo); |
| 1531 |
|
| 1532 |
//! |
| 1533 |
//! \brief Closes a handle to the specified user feature key |
| 1534 |
//! \details Closes a handle to the specified user feature key |
| 1535 |
//! \param [in] ufKey |
| 1536 |
//! A handle to an open user feature key. |
| 1537 |
//! \return MOS_STATUS |
| 1538 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1539 |
//! If the function fails, the return value is a error code defined |
| 1540 |
//! in mos_utilitiesNext.h. |
| 1541 |
//! |
| 1542 |
static MOS_STATUS MosUserFeatureCloseKey( |
| 1543 |
void *ufKey); |
| 1544 |
|
| 1545 |
//! |
| 1546 |
//! \brief Retrieves the type and data for the specified user feature value |
| 1547 |
//! \details Retrieves the type and data for the specified user feature value |
| 1548 |
//! \param [in] UFKey |
| 1549 |
//! A handle to an open user feature key. |
| 1550 |
//! \param [in] lpSubKey |
| 1551 |
//! The name of the user feature key. This key must be a |
| 1552 |
//! subkey of the key specified by the hkey parameter |
| 1553 |
//! \param [in] lpValue |
| 1554 |
//! The name of the user feature value |
| 1555 |
//! \param [in] dwFlags |
| 1556 |
//! The flags that restrict the data type of value to be queried |
| 1557 |
//! \param [out] pdwType |
| 1558 |
//! A pointer to a variable that receives a code indicating the type |
| 1559 |
//! of data stored in the specified value. |
| 1560 |
//! \param [out] pvData |
| 1561 |
//! A pointer to a buffer that receives the value's data. |
| 1562 |
//! \param [in/out] pcbData |
| 1563 |
//! A pointer to a variable that specifies the size of the buffer |
| 1564 |
//! pointed to by the pvData parameter, in bytes. When the function |
| 1565 |
//! returns, this variable contains the size of the data copied to lpData. |
| 1566 |
//! \return MOS_STATUS |
| 1567 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1568 |
//! If the function fails, the return value is a error code defined |
| 1569 |
//! in mos_utilitiesNext.h. |
| 1570 |
//! |
| 1571 |
static MOS_STATUS MosUserFeatureGetValue( |
| 1572 |
void *UFKey, |
| 1573 |
const char *lpSubKey, |
| 1574 |
const char *lpValue, |
| 1575 |
uint32_t dwFlags, |
| 1576 |
uint32_t *pdwType, |
| 1577 |
void *pvData, |
| 1578 |
uint32_t *pcbData); |
| 1579 |
|
| 1580 |
//! |
| 1581 |
//! \brief Retrieves the type and data for the specified value name |
| 1582 |
//! associated with an open user feature key. |
| 1583 |
//! \details Retrieves the type and data for the specified value name |
| 1584 |
//! associated with an open user feature key. |
| 1585 |
//! \param [in] UFKey |
| 1586 |
//! A handle to an open user feature key |
| 1587 |
//! \param [in] lpValueName |
| 1588 |
//! The name of the user feature value |
| 1589 |
//! \param [in] lpReserved |
| 1590 |
//! This parameter is reserved and must be NULL. |
| 1591 |
//! \param [out] lpType |
| 1592 |
//! A pointer to a variable that receives a code indicating |
| 1593 |
//! the type of data stored in the specified value. |
| 1594 |
//! \param [out] lpData |
| 1595 |
//! A pointer to a buffer that receives the value's data. |
| 1596 |
//! \param [in/out] lpcbData |
| 1597 |
//! A pointer to a variable that specifies the size |
| 1598 |
//! of the buffer pointed to by the pvData parameter, |
| 1599 |
//! in bytes. When the function returns, this variable |
| 1600 |
//! contains the size of the data copied to lpData. |
| 1601 |
//! \return MOS_STATUS |
| 1602 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1603 |
//! If the function fails, the return value is a error code defined |
| 1604 |
//! in mos_utilitiesNext.h. |
| 1605 |
//! |
| 1606 |
static MOS_STATUS MosUserFeatureQueryValueEx( |
| 1607 |
void *UFKey, |
| 1608 |
char *lpValueName, |
| 1609 |
uint32_t *lpReserved, |
| 1610 |
uint32_t *lpType, |
| 1611 |
char *lpData, |
| 1612 |
uint32_t *lpcbData); |
| 1613 |
|
| 1614 |
//! |
| 1615 |
//! \brief Sets the data and type of a specified value under a user feature key |
| 1616 |
//! \details Sets the data and type of a specified value under a user feature key |
| 1617 |
//! \param [in] UFKey |
| 1618 |
//! A handle to an open user feature key |
| 1619 |
//! \param [in] lpValueName |
| 1620 |
//! The name of the user feature value |
| 1621 |
//! \param [in] Reserved |
| 1622 |
//! This parameter is reserved and must be nullptr |
| 1623 |
//! \param [in] dwType |
| 1624 |
//! The type of data pointed to by the lpData parameter |
| 1625 |
//! \param [in] lpData |
| 1626 |
//! The data to be stored. |
| 1627 |
//! \param [in] cbData |
| 1628 |
//! The size of the information pointed to by the lpData parameter, in bytes. |
| 1629 |
//! \return MOS_STATUS |
| 1630 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1631 |
//! If the function fails, the return value is a error code defined |
| 1632 |
//! in mos_utilitiesNext.h. |
| 1633 |
//! |
| 1634 |
static MOS_STATUS MosUserFeatureSetValueEx( |
| 1635 |
void *UFKey, |
| 1636 |
const char *lpValueName, |
| 1637 |
uint32_t Reserved, |
| 1638 |
uint32_t dwType, |
| 1639 |
uint8_t *lpData, |
| 1640 |
uint32_t cbData); |
| 1641 |
|
| 1642 |
//! |
| 1643 |
//! \brief Notifies the caller about changes to the attributes or contents |
| 1644 |
//! of a specified user feature key |
| 1645 |
//! \details Notifies the caller about changes to the attributes or contents |
| 1646 |
//! of a specified user feature key |
| 1647 |
//! Used internally by MosUserFeatureEnableNotification() |
| 1648 |
//! \param [in] UFKey |
| 1649 |
//! A handle to an open user feature key. |
| 1650 |
//! The key must have been opened with the KEY_NOTIFY access right. |
| 1651 |
//! \param [in] bWatchSubtree |
| 1652 |
//! true including subkey changes; false for the key itself |
| 1653 |
//! \param [in] hEvent |
| 1654 |
//! A handle to an event to be signaled when key changes if is true |
| 1655 |
//! \param [in] fAsynchronous |
| 1656 |
//! true: Return immediately and signal the hEvent when key change |
| 1657 |
//! false: Does not return until a change has occured |
| 1658 |
//! \return MOS_STATUS |
| 1659 |
//! If the function succeeds, the return value is MOS_STATUS_SUCCESS. |
| 1660 |
//! If the function fails, the return value is a error code defined |
| 1661 |
//! in mos_utilitiesNext.h. |
| 1662 |
//! |
| 1663 |
static MOS_STATUS MosUserFeatureNotifyChangeKeyValue( |
| 1664 |
void *UFKey, |
| 1665 |
int32_t bWatchSubtree, |
| 1666 |
HANDLE hEvent, |
| 1667 |
int32_t fAsynchronous); |
| 1668 |
|
| 1669 |
//! |
| 1670 |
//! \brief Creates or opens a event object and returns a handle to the object |
| 1671 |
//! \details Creates or opens a event object and returns a handle to the object |
| 1672 |
//! \param [in] lpEventAttributes |
| 1673 |
//! A pointer to a SECURITY_ATTRIBUTES structure. |
| 1674 |
//! If lpEventAttributes is nullptr, the event handle cannot be inherited |
| 1675 |
//! by child processes. |
| 1676 |
//! \param [in] lpName |
| 1677 |
//! The name of the event object.If lpName is nullptr, the event object is |
| 1678 |
//! created without a name. |
| 1679 |
//! \param [in] dwFlags |
| 1680 |
//! Combines the following flags |
| 1681 |
//! CREATE_EVENT_INITIAL_SET: Singal initial state or not |
| 1682 |
//! CREATE_EVENT_MANUAL_RESET: Must be manually reset or not |
| 1683 |
//! \return HANDLE |
| 1684 |
//! If the function succeeds, the return value is a handle to the |
| 1685 |
//! event object. If failed, returns NULL. To get extended error |
| 1686 |
//! information, call GetLastError. |
| 1687 |
//! |
| 1688 |
static HANDLE MosCreateEventEx( |
| 1689 |
void *lpEventAttributes, |
| 1690 |
char *lpName, |
| 1691 |
uint32_t dwFlags); |
| 1692 |
|
| 1693 |
//! |
| 1694 |
//! \brief Create a wait thread to wait on the object |
| 1695 |
//! \details Create a wait thread to wait on the object |
| 1696 |
//! Add this function to capatible WDK-9200 on vs2012. |
| 1697 |
//! \param [out] phNewWaitObject |
| 1698 |
//! A pointer to a variable that receives a wait handle on return. |
| 1699 |
//! \param [in] hObject |
| 1700 |
//! A handle to the object |
| 1701 |
//! \param [in] Callback |
| 1702 |
//! A pointer to the application-defined function of type |
| 1703 |
//! WAITORTIMERCALLBACK to be executed when wait ends. |
| 1704 |
//! \param [in] Context |
| 1705 |
//! A single value that is passed to the callback function |
| 1706 |
//! \return int32_t |
| 1707 |
//! The return value is int32_t type. If the function succeeds, |
| 1708 |
//! the return value is nonzero. If the function fails, the |
| 1709 |
//! return value is zero. |
| 1710 |
//! |
| 1711 |
static int32_t MosUserFeatureWaitForSingleObject( |
| 1712 |
PTP_WAIT *phNewWaitObject, |
| 1713 |
HANDLE hObject, |
| 1714 |
void *Callback, |
| 1715 |
void *Context); |
| 1716 |
|
| 1717 |
//! |
| 1718 |
//! \brief Cancels a registered wait operation issued by the |
| 1719 |
//! RegisterWaitForSingleObject function |
| 1720 |
//! \details Cancels a registered wait operation issued by the |
| 1721 |
//! RegisterWaitForSingleObject function |
| 1722 |
//! \param [in] hWaitHandle |
| 1723 |
//! The wait handle. This handle is returned by the |
| 1724 |
//! RegisterWaitForSingleObject function |
| 1725 |
//! \return int32_t |
| 1726 |
//! The return value is int32_t type. If the function succeeds, |
| 1727 |
//! the return value is nonzero. If the function fails, the |
| 1728 |
//! return value is zero. |
| 1729 |
//! |
| 1730 |
static int32_t MosUnregisterWaitEx( |
| 1731 |
PTP_WAIT hWaitHandle); |
| 1732 |
|
| 1733 |
//! |
| 1734 |
//! \brief Get logical core number of current CPU |
| 1735 |
//! \details Get logical core number of current CPU |
| 1736 |
//! \return uint32_t |
| 1737 |
//! If the function succeeds, the return value is the number of |
| 1738 |
//! current CPU. |
| 1739 |
//! |
| 1740 |
static uint32_t MosGetLogicalCoreNumber(); |
| 1741 |
|
| 1742 |
//! |
| 1743 |
//! \brief Creates or opens a thread object and returns a handle to the object |
| 1744 |
//! \details Creates or opens a thread object and returns a handle to the object |
| 1745 |
//! \param [in] ThreadFunction |
| 1746 |
//! A pointer to a thread function. |
| 1747 |
//! \param [in] ThreadData |
| 1748 |
//! A pointer to thread data. |
| 1749 |
//! \return MOS_THREADHANDLE |
| 1750 |
//! If the function succeeds, the return value is a handle to the |
| 1751 |
//! thread object. If failed, returns NULL. |
| 1752 |
//! |
| 1753 |
static MOS_THREADHANDLE MosCreateThread( |
| 1754 |
void *ThreadFunction, |
| 1755 |
void *ThreadData); |
| 1756 |
|
| 1757 |
//! |
| 1758 |
//! \brief Get thread id |
| 1759 |
//! \details Get thread id |
| 1760 |
//! \param [in] hThread |
| 1761 |
//! A handle of thread object. |
| 1762 |
//! \return uint32_t |
| 1763 |
//! Return the current thread id |
| 1764 |
//! |
| 1765 |
static uint32_t MosGetThreadId( |
| 1766 |
MOS_THREADHANDLE hThread); |
| 1767 |
|
| 1768 |
//! |
| 1769 |
//! \brief Retrieves the current thread id |
| 1770 |
//! \details Retrieves the current thread id |
| 1771 |
//! \return uint32_t |
| 1772 |
//! Return the current thread id |
| 1773 |
//! |
| 1774 |
static uint32_t MosGetCurrentThreadId(); |
| 1775 |
|
| 1776 |
//! |
| 1777 |
//! \brief Wait for thread to terminate |
| 1778 |
//! \details Wait for thread to terminate |
| 1779 |
//! \param [in] hThread |
| 1780 |
//! A handle of thread object. |
| 1781 |
//! \return MOS_STATUS |
| 1782 |
//! |
| 1783 |
static MOS_STATUS MosWaitThread( |
| 1784 |
MOS_THREADHANDLE hThread); |
| 1785 |
|
| 1786 |
//! |
| 1787 |
//! \brief Create mutex for context protection across threads |
| 1788 |
//! \details Create mutex for context protection across threads |
| 1789 |
//! Used for multi-threading of Hybrid Decoder |
| 1790 |
//! \param [in] spinCount |
| 1791 |
//! The spin count for the critical section object. |
| 1792 |
//! \return PMOS_MUTEX |
| 1793 |
//! Pointer of mutex |
| 1794 |
//! |
| 1795 |
static PMOS_MUTEX MosCreateMutex(uint32_t spinCount = 0); |
| 1796 |
|
| 1797 |
//! |
| 1798 |
//! \brief Destroy mutex for context protection across threads |
| 1799 |
//! \details Destroy mutex for context protection across threads |
| 1800 |
//! Used for multi-threading of Hybrid Decoder |
| 1801 |
//! \param [in] pMutex |
| 1802 |
//! Pointer of mutex |
| 1803 |
//! \return MOS_STATUS |
| 1804 |
//! |
| 1805 |
static MOS_STATUS MosDestroyMutex(PMOS_MUTEX &pMutex); |
| 1806 |
|
| 1807 |
//! |
| 1808 |
//! \brief Lock mutex for context protection across threads |
| 1809 |
//! \details Lock mutex for context protection across threads |
| 1810 |
//! Used for multi-threading of Hybrid Decoder |
| 1811 |
//! \param [in] pMutex |
| 1812 |
//! Pointer of mutex |
| 1813 |
//! \return MOS_STATUS |
| 1814 |
//! |
| 1815 |
static MOS_STATUS MosLockMutex(PMOS_MUTEX pMutex); |
| 1816 |
|
| 1817 |
//! |
| 1818 |
//! \brief Unlock mutex for context protection across threads |
| 1819 |
//! \details Unlock mutex for context protection across threads |
| 1820 |
//! Used for multi-threading of Hybrid Decoder |
| 1821 |
//! \param [in] pMutex |
| 1822 |
//! Pointer of mutex |
| 1823 |
//! \return MOS_STATUS |
| 1824 |
//! |
| 1825 |
static MOS_STATUS MosUnlockMutex(PMOS_MUTEX pMutex); |
| 1826 |
|
| 1827 |
//! |
| 1828 |
//! \brief Creates or opens a semaphore object and returns a handle to the object |
| 1829 |
//! \details Creates or opens a semaphore object and returns a handle to the object |
| 1830 |
//! \param [in] uiInitialCount |
| 1831 |
//! Initial count of semaphore usage. |
| 1832 |
//! \param [in] uiMaximumCount |
| 1833 |
//! Maximum count of semaphore usage. |
| 1834 |
//! \return PMOS_SEMAPHORE |
| 1835 |
//! If the function succeeds, the return value is a handle to the |
| 1836 |
//! semaphore object. If failed, returns NULL. To get extended error |
| 1837 |
//! information, call GetLastError. |
| 1838 |
//! |
| 1839 |
static PMOS_SEMAPHORE MosCreateSemaphore( |
| 1840 |
uint32_t uiInitialCount, |
| 1841 |
uint32_t uiMaximumCount); |
| 1842 |
|
| 1843 |
//! |
| 1844 |
//! \brief Destroy a semaphore object |
| 1845 |
//! \details Destroy a semaphore object |
| 1846 |
//! \param [in] pSemaphore |
| 1847 |
//! A handle of semaphore object. |
| 1848 |
//! \return MOS_STATUS |
| 1849 |
//! |
| 1850 |
static MOS_STATUS MosDestroySemaphore( |
| 1851 |
PMOS_SEMAPHORE &pSemaphore); |
| 1852 |
|
| 1853 |
//! |
| 1854 |
//! \brief Wait a semaphore object |
| 1855 |
//! \details Wait a semaphore object |
| 1856 |
//! \param [in] pSemaphore |
| 1857 |
//! A handle of semaphore object. |
| 1858 |
//! \param [in] uiMilliseconds |
| 1859 |
//! Wait time. |
| 1860 |
//! \return MOS_STATUS |
| 1861 |
//! |
| 1862 |
static MOS_STATUS MosWaitSemaphore( |
| 1863 |
PMOS_SEMAPHORE pSemaphore, |
| 1864 |
uint32_t uiMilliseconds); |
| 1865 |
|
| 1866 |
//! |
| 1867 |
//! \brief Post a semaphore object |
| 1868 |
//! \details Post a semaphore object |
| 1869 |
//! \param [in] pSemaphore |
| 1870 |
//! A handle of semaphore object. |
| 1871 |
//! \param [in] uiPostCount |
| 1872 |
//! semaphore post count. |
| 1873 |
//! \return MOS_STATUS |
| 1874 |
//! |
| 1875 |
static MOS_STATUS MosPostSemaphore( |
| 1876 |
PMOS_SEMAPHORE pSemaphore, |
| 1877 |
uint32_t uiPostCount); |
| 1878 |
|
| 1879 |
//! |
| 1880 |
//! \brief Wait for single object of semaphore/mutex/thread and returns the result |
| 1881 |
//! \details Wait for single object of semaphore/mutex/thread and returns the result |
| 1882 |
//! \param [in] pObject |
| 1883 |
//! Object handle. |
| 1884 |
//! \param [in] uiMilliseconds |
| 1885 |
//! Wait time. |
| 1886 |
//! \return uint32_t |
| 1887 |
//! If the function succeeds, the return value is the wait result of the |
| 1888 |
//! semaphore/mutex/thread object. |
| 1889 |
//! |
| 1890 |
static uint32_t MosWaitForSingleObject( |
| 1891 |
void *pObject, |
| 1892 |
uint32_t uiMilliseconds); |
| 1893 |
|
| 1894 |
//! |
| 1895 |
//! \brief Wait for multiple objects of semaphore/mutex/thread and returns the result |
| 1896 |
//! \details Wait for multiple objects of semaphore/mutex/thread and returns the result |
| 1897 |
//! \param [in] uiThreadCount |
| 1898 |
//! The number of object handles in the array pointed to by ppObjects. |
| 1899 |
//! \param [in] ppObjects |
| 1900 |
//! An array of object handles. |
| 1901 |
//! \param [in] bWaitAll |
| 1902 |
//! If true, the function returns when the state of all objects in the ppObjects array is signaled. |
| 1903 |
//! If false, the function returns when the state of any one of the objects is set to signaled. |
| 1904 |
//! \param [in] uiMilliseconds |
| 1905 |
//! The time-out interval, in milliseconds. |
| 1906 |
//! \return uint32_t |
| 1907 |
//! Return the wait result |
| 1908 |
//! |
| 1909 |
static uint32_t MosWaitForMultipleObjects( |
| 1910 |
uint32_t uiThreadCount, |
| 1911 |
void **ppObjects, |
| 1912 |
uint32_t bWaitAll, |
| 1913 |
uint32_t uiMilliseconds); |
| 1914 |
|
| 1915 |
//! |
| 1916 |
//! \brief Increments (increases by one) the value of the specified int32_t variable as an atomic operation. |
| 1917 |
//! \param [in] pValue |
| 1918 |
//! A pointer to the variable to be incremented. |
| 1919 |
//! \return int32_t |
| 1920 |
//! The function returns the resulting incremented value. |
| 1921 |
//! |
| 1922 |
static int32_t MosAtomicIncrement( |
| 1923 |
int32_t *pValue); |
| 1924 |
|
| 1925 |
//! |
| 1926 |
//! \brief Decrements (decreases by one) the value of the specified int32_t variable as an atomic operation. |
| 1927 |
//! \param [in] pValue |
| 1928 |
//! A pointer to the variable to be decremented. |
| 1929 |
//! \return int32_t |
| 1930 |
//! The function returns the resulting decremented value. |
| 1931 |
//! |
| 1932 |
static int32_t MosAtomicDecrement( |
| 1933 |
int32_t *pValue); |
| 1934 |
|
| 1935 |
//! |
| 1936 |
//! \brief Convert MOS_STATUS to OS dependent RESULT/Status |
| 1937 |
//! \param [in] eStatus |
| 1938 |
//! MOS_STATUS that will be converted |
| 1939 |
//! \return MOS_OSRESULT |
| 1940 |
//! Corresponding return code on different OSes |
| 1941 |
//! |
| 1942 |
static MOS_OSRESULT MosStatusToOsResult( |
| 1943 |
MOS_STATUS eStatus); |
| 1944 |
|
| 1945 |
//! |
| 1946 |
//! \brief Convert OS dependent RESULT/Status to MOS_STATUS |
| 1947 |
//! \param [in] eResult |
| 1948 |
//! OS dependent result that will be converted |
| 1949 |
//! \return MOS_STATUS |
| 1950 |
//! Corresponding MOS_STATUS |
| 1951 |
//! |
| 1952 |
static MOS_STATUS OsResultToMOSStatus( |
| 1953 |
MOS_OSRESULT eResult); |
| 1954 |
|
| 1955 |
//! |
| 1956 |
//! \brief sinc |
| 1957 |
//! \details Calculate sinc(x) |
| 1958 |
//! \param [in] x |
| 1959 |
//! float |
| 1960 |
//! \return float |
| 1961 |
//! sinc(x) |
| 1962 |
//! |
| 1963 |
static float MosSinc( |
| 1964 |
float x); |
| 1965 |
|
| 1966 |
//! |
| 1967 |
//! \brief Lanczos |
| 1968 |
//! \details Calculate lanczos(x) |
| 1969 |
//! Basic formula is: lanczos(x)= MosSinc(x) * MosSinc(x / fLanczosT) |
| 1970 |
//! \param [in] x |
| 1971 |
//! float |
| 1972 |
//! \param [in] dwNumEntries |
| 1973 |
//! dword |
| 1974 |
//! \param [in] fLanczosT |
| 1975 |
//! |
| 1976 |
//! \return float |
| 1977 |
//! lanczos(x) |
| 1978 |
//! |
| 1979 |
static float MosLanczos( |
| 1980 |
float x, |
| 1981 |
uint32_t dwNumEntries, |
| 1982 |
float fLanczosT); |
| 1983 |
|
| 1984 |
//! |
| 1985 |
//! \brief General Lanczos |
| 1986 |
//! \details Calculate lanczos(x) with odd entry num support |
| 1987 |
//! Basic formula is: lanczos(x)= MosSinc(x) * MosSinc(x / fLanczosT) |
| 1988 |
//! \param [in] x |
| 1989 |
//! float |
| 1990 |
//! \param [in] dwNumEntries |
| 1991 |
//! dword |
| 1992 |
//! \param [in]fLanczosT |
| 1993 |
//! |
| 1994 |
//! \return float |
| 1995 |
//! lanczos(x) |
| 1996 |
//! |
| 1997 |
static float MosLanczosG( |
| 1998 |
float x, |
| 1999 |
uint32_t dwNumEntries, |
| 2000 |
float fLanczosT); |
| 2001 |
|
| 2002 |
//! |
| 2003 |
//! \brief GCD |
| 2004 |
//! \details Recursive GCD calculation of two numbers |
| 2005 |
//! \param [in] a |
| 2006 |
//! uint32_t |
| 2007 |
//! \param [in] b |
| 2008 |
//! uint32_t |
| 2009 |
//! \return uint32_t |
| 2010 |
//! MosGCD(a, b) |
| 2011 |
//! |
| 2012 |
static uint32_t MosGCD( |
| 2013 |
uint32_t a, |
| 2014 |
uint32_t b); |
| 2015 |
|
| 2016 |
//! |
| 2017 |
//! \brief Get local time |
| 2018 |
//! \details Get local time |
| 2019 |
//! \param [out] tm |
| 2020 |
//! tm struct |
| 2021 |
//! \return MOS_STATUS |
| 2022 |
//! |
| 2023 |
static MOS_STATUS MosGetLocalTime( |
| 2024 |
struct tm* tm); |
| 2025 |
|
| 2026 |
//! |
| 2027 |
//! \brief Swizzles the given linear offset via the specified tiling params. |
| 2028 |
//! \details Swizzles the given linear offset via the specified tiling parameters. |
| 2029 |
//! Used to provide linear access to raw, tiled data. |
| 2030 |
//! \param [in] OffsetX |
| 2031 |
//! Horizontal byte offset from left edge of tiled surface. |
| 2032 |
//! \param [in] OffsetY |
| 2033 |
//! Vertical offset from top of tiled surface. |
| 2034 |
//! \param [in] Pitch |
| 2035 |
//! Row-to-row byte stride. |
| 2036 |
//! \param [in] TileFormat |
| 2037 |
//! Either 'x' or 'y'--for X-Major or Y-Major tiling, respectively. |
| 2038 |
//! \param [in] CsxSwizzle |
| 2039 |
//! (Boolean) Additionally perform Channel Select XOR swizzling. |
| 2040 |
//! \param [in] flags |
| 2041 |
//! More flags to indicate different tileY. |
| 2042 |
//! \return int32_t |
| 2043 |
//! Return SwizzleOffset |
| 2044 |
//! |
| 2045 |
static int32_t MosSwizzleOffset( |
| 2046 |
int32_t OffsetX, |
| 2047 |
int32_t OffsetY, |
| 2048 |
int32_t Pitch, |
| 2049 |
MOS_TILE_TYPE TileFormat, |
| 2050 |
int32_t CsxSwizzle, |
| 2051 |
int32_t flags); |
| 2052 |
|
| 2053 |
#ifdef _MOS_UTILITY_EXT |
| 2054 |
static int32_t MosSwizzleOffsetExt( |
| 2055 |
int32_t OffsetX, |
| 2056 |
int32_t OffsetY, |
| 2057 |
int32_t Pitch, |
| 2058 |
MOS_TILE_TYPE TileFormat, |
| 2059 |
int32_t CsxSwizzle, |
| 2060 |
int32_t extFlags); |
| 2061 |
#endif |
| 2062 |
|
| 2063 |
static int32_t MosSwizzleOffsetWrapper( |
| 2064 |
int32_t OffsetX, |
| 2065 |
int32_t OffsetY, |
| 2066 |
int32_t Pitch, |
| 2067 |
MOS_TILE_TYPE TileFormat, |
| 2068 |
int32_t CsxSwizzle, |
| 2069 |
int32_t flags); |
| 2070 |
|
| 2071 |
//! |
| 2072 |
//! \brief Wrapper function for SwizzleOffset |
| 2073 |
//! \details Wrapper function for SwizzleOffset in Mos |
| 2074 |
//! \param [in] pSrc |
| 2075 |
//! Pointer to source data. |
| 2076 |
//! \param [out] pDst |
| 2077 |
//! Pointer to destiny data. |
| 2078 |
//! \param [in] SrcTiling |
| 2079 |
//! Source Tile Type |
| 2080 |
//! \param [in] DstTiling |
| 2081 |
//! Destiny Tile Type |
| 2082 |
//! \param [in] iHeight |
| 2083 |
//! Height |
| 2084 |
//! \param [in] iPitch |
| 2085 |
//! Pitch |
| 2086 |
//! \param [in] extended flags |
| 2087 |
//! Pitch |
| 2088 |
//! \return void |
| 2089 |
//! |
| 2090 |
static void MosSwizzleData( |
| 2091 |
uint8_t *pSrc, |
| 2092 |
uint8_t *pDst, |
| 2093 |
MOS_TILE_TYPE SrcTiling, |
| 2094 |
MOS_TILE_TYPE DstTiling, |
| 2095 |
int32_t iHeight, |
| 2096 |
int32_t iPitch, |
| 2097 |
int32_t extFlags); |
| 2098 |
|
| 2099 |
//! |
| 2100 |
//! \brief MOS trace event initialize |
| 2101 |
//! \details register provide Global ID to the system. |
| 2102 |
//! \param void |
| 2103 |
//! \return void |
| 2104 |
//! |
| 2105 |
static void MosTraceEventInit(); |
| 2106 |
|
| 2107 |
//! |
| 2108 |
//! \brief MOS trace event close |
| 2109 |
//! \details un-register provider Global ID. |
| 2110 |
//! \param void |
| 2111 |
//! \return void |
| 2112 |
//! |
| 2113 |
static void MosTraceEventClose(); |
| 2114 |
|
| 2115 |
//! |
| 2116 |
//! \brief setup static platform info for trace events |
| 2117 |
//! \details send static platform info to trace struct, which itself determine when to send them. |
| 2118 |
//! static platform info should only send 1 time per trace capture, no more no less. |
| 2119 |
//! \param [in] driver version |
| 2120 |
//! \param [in] platform family |
| 2121 |
//! \param [in] render family |
| 2122 |
//! \param [in] device id |
| 2123 |
//! \return void |
| 2124 |
//! |
| 2125 |
static void MosTraceSetupInfo(uint32_t DrvVer, uint32_t PlatFamily, uint32_t RenderFamily, uint32_t DeviceID); |
| 2126 |
|
| 2127 |
//! |
| 2128 |
//! \brief check if trace key is enabled |
| 2129 |
//! \details if a trace key is enabled, returns true, otherwise false |
| 2130 |
//! \param [in] trace event key |
| 2131 |
//! \return bool |
| 2132 |
//! |
| 2133 |
static bool TraceKeyEnabled(MEDIA_EVENT_FILTER_KEYID key) |
| 2134 |
{ |
| 2135 |
return m_mosTraceEnable && m_mosTraceFilter(key); |
| 2136 |
} |
| 2137 |
|
| 2138 |
//! |
| 2139 |
//! \brief check if trace level is enabled |
| 2140 |
//! \details if a trace level is enabled, returns true, otherwise false |
| 2141 |
//! \param [in] trace event level |
| 2142 |
//! \return bool |
| 2143 |
//! |
| 2144 |
static bool TracelevelEnabled(MT_EVENT_LEVEL level) |
| 2145 |
{ |
| 2146 |
return m_mosTraceLevel(level); |
| 2147 |
} |
| 2148 |
|
| 2149 |
//! |
| 2150 |
//! \brief check if trace level is enabled |
| 2151 |
//! \details if a trace level is enabled, returns true, otherwise false |
| 2152 |
//! \param [in] trace event level |
| 2153 |
//! \return bool |
| 2154 |
//! |
| 2155 |
static bool TracelevelEnabled(MT_DATA_LEVEL level) |
| 2156 |
{ |
| 2157 |
return m_mosTraceLevel(level); |
| 2158 |
} |
| 2159 |
|
| 2160 |
//! |
| 2161 |
//! \brief check if trace level is enabled |
| 2162 |
//! \details if a trace level is enabled, returns true, otherwise false |
| 2163 |
//! \param [in] trace event level |
| 2164 |
//! \return bool |
| 2165 |
//! |
| 2166 |
static bool TracelevelEnabled(MT_LOG_LEVEL level) |
| 2167 |
{ |
| 2168 |
return m_mosTraceLevel(level); |
| 2169 |
} |
| 2170 |
|
| 2171 |
//! |
| 2172 |
//! \brief get trace setting |
| 2173 |
//! \details return a pointer to trace setting if trace is enabled or a nullptr otherwise |
| 2174 |
//! \return bool |
| 2175 |
//! |
| 2176 |
static const MtSetting *GetTraceSetting() |
| 2177 |
{ |
| 2178 |
return m_mosTraceControlData ? &m_mosTraceControlData->setting : nullptr; |
| 2179 |
} |
| 2180 |
|
| 2181 |
//! |
| 2182 |
//! \brief MOS log trace event |
| 2183 |
//! \details log trace event by id and event type, arg1 and arg2 are optional arguments |
| 2184 |
//! arguments are in raw data format, need match data structure in manifest. |
| 2185 |
//! \param [in] usId |
| 2186 |
//! Indicates event id |
| 2187 |
//! \param [in] ucType |
| 2188 |
//! Indicates event type |
| 2189 |
//! \param [in] pArg1 |
| 2190 |
//! event data address |
| 2191 |
//! \param [in] dwSize1 |
| 2192 |
//! event data size |
| 2193 |
//! \param [in] pArg2 |
| 2194 |
//! event data address |
| 2195 |
//! \param [in] dwSize2 |
| 2196 |
//! event data size |
| 2197 |
//! \return void |
| 2198 |
//! |
| 2199 |
static void MosTraceEvent( |
| 2200 |
uint16_t usId, |
| 2201 |
uint8_t ucType, |
| 2202 |
const void *pArg1, |
| 2203 |
uint32_t dwSize1, |
| 2204 |
const void *pArg2, |
| 2205 |
uint32_t dwSize2); |
| 2206 |
|
| 2207 |
//! |
| 2208 |
//! \brief if MOS event msg should be traced |
| 2209 |
//! \details return a bool to indicate if MOS event msg should be traced |
| 2210 |
//! \param [in] level |
| 2211 |
//! msg level |
| 2212 |
//! \param [in] compID |
| 2213 |
//! msg compID |
| 2214 |
//! \return bool |
| 2215 |
//! |
| 2216 |
static bool MosShouldTraceEventMsg( |
| 2217 |
uint8_t level, |
| 2218 |
uint8_t compID); |
| 2219 |
|
| 2220 |
//! |
| 2221 |
//! \brief MOS log trace event Msg |
| 2222 |
//! \details log trace event msg w/ level/compID/functionname/lineNum arguments |
| 2223 |
//! arguments are in raw data format, need match data structure in manifest. |
| 2224 |
//! \param [in] level |
| 2225 |
//! Indicates msg level |
| 2226 |
//! \param [in] compID |
| 2227 |
//! Indicates compID |
| 2228 |
//! \param [in] message |
| 2229 |
//! event msg |
| 2230 |
//! \param [in] functionName |
| 2231 |
//! func name |
| 2232 |
//! \param [in] lineNum |
| 2233 |
//! event line number |
| 2234 |
//! \return void |
| 2235 |
//! |
| 2236 |
static void MosTraceEventMsg( |
| 2237 |
uint8_t level, |
| 2238 |
uint8_t compID, |
| 2239 |
void* message, |
| 2240 |
void* functionName, |
| 2241 |
uint32_t lineNum); |
| 2242 |
|
| 2243 |
static void MosTraceDataDump( |
| 2244 |
const char *pcName, |
| 2245 |
uint32_t flags, |
| 2246 |
const void *pBuf, |
| 2247 |
uint32_t dwSize); |
| 2248 |
|
| 2249 |
//! |
| 2250 |
//! \brief MOS log data dictionary item |
| 2251 |
//! \details Dictionary is name:value pair |
| 2252 |
//! \param [in] name |
| 2253 |
//! Indicates item name |
| 2254 |
//! \param [in] pBuf |
| 2255 |
//! Indicates value address |
| 2256 |
//! \param [in] size |
| 2257 |
//! Indicates value size |
| 2258 |
//! \return void |
| 2259 |
//! |
| 2260 |
static void MosTraceDataDictionary( |
| 2261 |
const char* pcName, |
| 2262 |
const void* pBuf, |
| 2263 |
uint32_t dwSize); |
| 2264 |
|
| 2265 |
//! |
| 2266 |
//! \brief MosGfxInfoRTErr |
| 2267 |
//! \details Custom gfx info trace to report runtime errors detected by each component. |
| 2268 |
//! \param [in] ver |
| 2269 |
//! Version |
| 2270 |
//! \param [in] compId |
| 2271 |
//! Component ID defined in GFXINFO_COMP_ID |
| 2272 |
//! \param [in] FtrId |
| 2273 |
//! Feature ID, an unique identifier for each component. |
| 2274 |
//! \param [in] ErrorCode |
| 2275 |
//! Error code that will be recorded. |
| 2276 |
//! \param [in] num_of_triples |
| 2277 |
//! Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element |
| 2278 |
//! \param [in] ... |
| 2279 |
//! Triples (name, type, value), for example |
| 2280 |
//! int8_t i = 3; |
| 2281 |
//! "Name1", GFXINFO_PTYPE_UINT8, &i |
| 2282 |
//! "Name2", GFXINFO_PTYPE_ANSISTRING, "string value" |
| 2283 |
//! \return void |
| 2284 |
//! |
| 2285 |
static void MosGfxInfoRTErr(uint8_t ver, |
| 2286 |
uint16_t compId, |
| 2287 |
uint16_t FtrId, |
| 2288 |
uint32_t ErrorCode, |
| 2289 |
uint8_t num_of_triples, |
| 2290 |
...); |
| 2291 |
|
| 2292 |
//! |
| 2293 |
//! \brief MosGfxInfoRTErrInternal |
| 2294 |
//! \details Custom gfx info trace to report runtime errors detected by each component. |
| 2295 |
//! \param [in] ver |
| 2296 |
//! Version |
| 2297 |
//! \param [in] compId |
| 2298 |
//! Component ID defined in GFXINFO_COMP_ID |
| 2299 |
//! \param [in] FtrId |
| 2300 |
//! Feature ID, an unique identifier for each component. |
| 2301 |
//! \param [in] ErrorCode |
| 2302 |
//! Error code that will be recorded. |
| 2303 |
//! \param [in] num_of_triples |
| 2304 |
//! Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element |
| 2305 |
//! \param [in] var_args |
| 2306 |
//! Triples (name, type, value), for example |
| 2307 |
//! int8_t i = 3; |
| 2308 |
//! "Name1", GFXINFO_PTYPE_UINT8, &i |
| 2309 |
//! "Name2", GFXINFO_PTYPE_ANSISTRING, "string value" |
| 2310 |
//! \return void |
| 2311 |
//! |
| 2312 |
static void MosGfxInfoRTErrInternal(uint8_t ver, |
| 2313 |
uint16_t compId, |
| 2314 |
uint16_t FtrId, |
| 2315 |
uint32_t ErrorCode, |
| 2316 |
uint8_t num_of_triples, |
| 2317 |
va_list args); |
| 2318 |
|
| 2319 |
//! |
| 2320 |
//! \brief MosGfxInfo |
| 2321 |
//! \details A helper function to help to compose gfx info xml string |
| 2322 |
//! \param [in] ver |
| 2323 |
//! Version |
| 2324 |
//! \param [in] compId |
| 2325 |
//! Component ID defined in GFXINFO_COMP_ID |
| 2326 |
//! \param [in] tmtryID |
| 2327 |
//! Gfx info ID, an unique identifier for each component. |
| 2328 |
//! \param [in] num_of_triples |
| 2329 |
//! Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element |
| 2330 |
//! \param [in] ... |
| 2331 |
//! Triples (name, type, value), for example |
| 2332 |
//! int8_t i = 3; |
| 2333 |
//! "Name1", GFXINFO_PTYPE_UINT8, &i |
| 2334 |
//! "Name2", GFXINFO_PTYPE_ANSISTRING, "string value" |
| 2335 |
//! \return void |
| 2336 |
//! |
| 2337 |
static void MosGfxInfo( |
| 2338 |
uint8_t ver, |
| 2339 |
uint16_t compId, |
| 2340 |
uint32_t tmtryID, |
| 2341 |
uint8_t num_of_triples, |
| 2342 |
...); |
| 2343 |
|
| 2344 |
//! |
| 2345 |
//! \brief MosGfxInfoInternal |
| 2346 |
//! \details A helper function to help to compose gfx info xml string |
| 2347 |
//! \param [in] ver |
| 2348 |
//! Version |
| 2349 |
//! \param [in] compId |
| 2350 |
//! Component ID defined in GFXINFO_COMP_ID |
| 2351 |
//! \param [in] tmtryID |
| 2352 |
//! Gfx info ID, an unique identifier for each component. |
| 2353 |
//! \param [in] num_of_triples |
| 2354 |
//! Number of triples (name, type, value) to be compose as an <I N='name'>value</I> XML element |
| 2355 |
//! \param [in] var_args |
| 2356 |
//! Triples (name, type, value), for example |
| 2357 |
//! int8_t i = 3; |
| 2358 |
//! "Name1", GFXINFO_PTYPE_UINT8, &i |
| 2359 |
//! "Name2", GFXINFO_PTYPE_ANSISTRING, "string value" |
| 2360 |
//! \return void |
| 2361 |
//! |
| 2362 |
static void MosGfxInfoInternal( |
| 2363 |
uint8_t ver, |
| 2364 |
uint16_t compId, |
| 2365 |
uint32_t tmtryID, |
| 2366 |
uint8_t num_of_triples, |
| 2367 |
va_list args); |
| 2368 |
|
| 2369 |
//! |
| 2370 |
//! \brief MosIsProfilerDumpEnabled |
| 2371 |
//! \details Function: if to enable UMD profiler dump |
| 2372 |
//! \return bool |
| 2373 |
//! |
| 2374 |
static bool MosIsProfilerDumpEnabled(); |
| 2375 |
|
| 2376 |
static const uint32_t GetRegAccessDataType(MOS_USER_FEATURE_VALUE_TYPE type); |
| 2377 |
|
| 2378 |
static MOS_STATUS StrToMediaUserSettingValue( |
| 2379 |
std::string &strValue, |
| 2380 |
MOS_USER_FEATURE_VALUE_TYPE type, |
| 2381 |
MediaUserSetting::Value &dstValue); |
| 2382 |
|
| 2383 |
static MOS_STATUS DataToMediaUserSettingValue( |
| 2384 |
uint8_t *data, |
| 2385 |
size_t dataSize, |
| 2386 |
MediaUserSetting::Value &dstValue, |
| 2387 |
MOS_USER_FEATURE_VALUE_TYPE type); |
| 2388 |
|
| 2389 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 2390 |
|
| 2391 |
//! |
| 2392 |
//! \brief MosMMPWriteFile |
| 2393 |
//! \details Accelerate Writing file's IO speed using Memory Map |
| 2394 |
//! \param [in] name |
| 2395 |
//! [in] data |
| 2396 |
//! [in] size |
| 2397 |
//! \return void |
| 2398 |
//! |
| 2399 |
static void MosMMPWriteFile( |
| 2400 |
const std::string &name, |
| 2401 |
const void *data, |
| 2402 |
size_t size); |
| 2403 |
#endif |
| 2404 |
|
| 2405 |
private: |
| 2406 |
|
| 2407 |
//! |
| 2408 |
//! |
| 2409 |
//! \brief Destroy the User Feature Value pointer according to the Global DescField Table |
| 2410 |
//! \details Destroy the User Feature Value pointer according to the Global DescField Table |
| 2411 |
//! destroy the gc_UserFeatureKeysMap according to Declare Count |
| 2412 |
//! \return MOS_STATUS |
| 2413 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2414 |
//! else MOS_STATUS_SUCCESS |
| 2415 |
//! |
| 2416 |
static MOS_STATUS MosDestroyUserFeatureKeysForAllDescFields(); |
| 2417 |
|
| 2418 |
//! |
| 2419 |
//! \brief Write one user feature key into XML file |
| 2420 |
//! \details Write one user feature key into XML file |
| 2421 |
//! \param [out] keyValueMap |
| 2422 |
//! Unused in this function |
| 2423 |
//! \param [in] pUserFeature |
| 2424 |
//! Pointer to User Feature Value that is needed to be written |
| 2425 |
//! \return MOS_STATUS |
| 2426 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2427 |
//! else MOS_STATUS_SUCCESS |
| 2428 |
//! |
| 2429 |
static MOS_STATUS MosWriteOneUserFeatureKeyToXML(PMOS_USER_FEATURE_VALUE pUserFeature); |
| 2430 |
|
| 2431 |
//! |
| 2432 |
//! \brief Write one User Feature Group into XML file |
| 2433 |
//! \details Write one User Feature Group into XML file |
| 2434 |
//! \param MOS_USER_FEATURE_VALUE UserFeatureFilter |
| 2435 |
//! [in] Pointer to User Feature Value filter that contains the targeted group |
| 2436 |
//! \return MOS_STATUS |
| 2437 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2438 |
//! else MOS_STATUS_SUCCESS |
| 2439 |
//! |
| 2440 |
static MOS_STATUS MosWriteOneUserFeatureGroupToXML(MOS_USER_FEATURE_VALUE UserFeatureFilter); |
| 2441 |
|
| 2442 |
//! |
| 2443 |
//! \brief Read Single Value from User Feature based on value of enum type in MOS_USER_FEATURE_VALUE_TYPE with specified map table |
| 2444 |
//! \details This is a unified funtion to read user feature key for all components. |
| 2445 |
//! (Codec/VP/CP/CM) |
| 2446 |
//! It is required to prepare all memories for buffers before calling this function. |
| 2447 |
//! User can choose to use array variable or allocated memory for the buffer. |
| 2448 |
//! If the buffer is allocated dynamically, it must be freed by user to avoid memory leak. |
| 2449 |
//! ------------------------------------------------------------------------------------ |
| 2450 |
//! Usage example: |
| 2451 |
//! a) Initiation: |
| 2452 |
//! MosZeroMemory(&UserFeatureData, sizeof(UserFeatureData)); |
| 2453 |
//! b.0) Don't need to input a default value if the default value in user feature key Desc Fields table is good |
| 2454 |
//! for your case |
| 2455 |
//! b.1) For uint32_t type: |
| 2456 |
//! UserFeatureData.u32Data = 1; // overwrite a custom default value |
| 2457 |
//! UserFeatureData.i32DataFlag = MOS_USER_FEATURE_VALUE_DATA_FLAG_CUSTOM_DEFAULT_VALUE_TYPE; |
| 2458 |
//! // raise a flag to use this custom default value instead of |
| 2459 |
//! default value in user feature key Desc Fields table |
| 2460 |
//! b.2) For String/Binary type: |
| 2461 |
//! char cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE]; |
| 2462 |
//! UserFeatureData.StringData.pStringData = cStringData; // make sure the pointer is valid |
| 2463 |
//! b.3) For MultiString type: |
| 2464 |
//! char cStringData[MOS_USER_CONTROL_MAX_DATA_SIZE]; |
| 2465 |
//! MOS_USER_FEATURE_VALUE_STRING Strings[__MAX_MULTI_STRING_COUNT]; |
| 2466 |
//! UserFeatureData.MultiStringData.pMultStringData = cStringData; // make sure the pointer is valid |
| 2467 |
//! for (ui = 0; ui < VPHAL_3P_MAX_LIB_PATH_COUNT; ui++) |
| 2468 |
//! { |
| 2469 |
//! Strings[ui].pStringData = (char *)MOS_AllocAndZeroMemory(MOS_USER_CONTROL_MAX_DATA_SIZE); |
| 2470 |
//! } |
| 2471 |
//! UserFeatureData.MultiStringData.pStrings = Strings; |
| 2472 |
//! c) Read user feature key: |
| 2473 |
//! MosUserFeatureReadValueID(); |
| 2474 |
//! ------------------------------------------------------------------------------------- |
| 2475 |
//! Important note: The pointer pStringData/pMultStringData may be modified if the |
| 2476 |
//! previous MOS_UserFeature_ReadValue() doesn't read a same user feature key type. So it's |
| 2477 |
//! suggested to set the union members in UserFeatureValue every time before |
| 2478 |
//! MOS_UserFeature_ReadValue() if you are not familiar with the details of this function. |
| 2479 |
//! If a new key is added, please make sure to declare a definition in corresponding |
| 2480 |
//! user feature key Desc Fields table by MOS_DECLARE_UF_KEY |
| 2481 |
//! \param [in] ValueID |
| 2482 |
//! value of enum type in MOS_USER_FEATURE_VALUE_TYPE. declares the user feature key to be readed |
| 2483 |
//! \param [in,out] pValueData |
| 2484 |
//! Pointer to User Feature value Data |
| 2485 |
//! \param [in] ufInfo |
| 2486 |
//! user feature path suffix |
| 2487 |
//! \return MOS_STATUS |
| 2488 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2489 |
//! else MOS_STATUS_SUCCESS |
| 2490 |
//! For pValueData return value: |
| 2491 |
//! MOS_STATUS_SUCCESS: pValueData is from User Feature Key |
| 2492 |
//! MOS_STATUS_USER_FEATURE_KEY_OPEN_FAILED: pValueData is from default value |
| 2493 |
//! MOS_STATUS_UNKNOWN: pValueData is from default value |
| 2494 |
//! MOS_STATUS_USER_FEATURE_KEY_READ_FAILED: pValueData is from default value |
| 2495 |
//! MOS_STATUS_NULL_POINTER: NO USER FEATURE KEY DEFINITION in corresponding user feature key Desc Field table, |
| 2496 |
//! No default value or User Feature Key value return |
| 2497 |
//! |
| 2498 |
//! |
| 2499 |
static MOS_STATUS MosUserFeatureReadValueFromMapID( |
| 2500 |
uint32_t ValueID, |
| 2501 |
PMOS_USER_FEATURE_VALUE_DATA pValueData, |
| 2502 |
MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo = nullptr); |
| 2503 |
|
| 2504 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 2505 |
//! |
| 2506 |
//! \brief Get the User Feature File location |
| 2507 |
//! \details Get the User Feature File location |
| 2508 |
//! \param uint32_t& userfeatureValue |
| 2509 |
//! [in] reference to a userfeatureValue |
| 2510 |
//! \return MOS_STATUS |
| 2511 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2512 |
//! else MOS_STATUS_SUCCESS |
| 2513 |
//! |
| 2514 |
static MOS_STATUS MosGetApoMosEnabledUserFeatureFile(); |
| 2515 |
|
| 2516 |
#endif |
| 2517 |
|
| 2518 |
//! |
| 2519 |
//! \brief User Feature Callback function |
| 2520 |
//! \details User Feature Callback function |
| 2521 |
//! Notifies the caller that the CB is triggered |
| 2522 |
//! \param void *pvParameter |
| 2523 |
//! [out] Pointer to the User Feature Notification Data for |
| 2524 |
//! which callback is requested |
| 2525 |
//! \param int32_t TimerOrWait |
| 2526 |
//! [in/out] Flag to indicate if a timer or wait is applied |
| 2527 |
//! (Not used currently) |
| 2528 |
//! \return void |
| 2529 |
//! |
| 2530 |
static void MosUserFeatureCallback( |
| 2531 |
PTP_CALLBACK_INSTANCE Instance, |
| 2532 |
void * pvParameter, |
| 2533 |
PTP_WAIT Wait, |
| 2534 |
TP_WAIT_RESULT WaitResult); |
| 2535 |
|
| 2536 |
//! |
| 2537 |
//! \brief Open the user feature based on the access type requested |
| 2538 |
//! \details Open the user feature based on the access type requested |
| 2539 |
//! MOS_USER_FEATURE_TYPE_USER will be UFINT |
| 2540 |
//! MOS_USER_FEATURE_TYPE_SYSTEM will be UFEXT |
| 2541 |
//! \param MOS_USER_FEATURE_TYPE KeyType |
| 2542 |
//! [in] User Feature Type |
| 2543 |
//! \param char *pSubKey |
| 2544 |
//! [in] Pointer to the subkey |
| 2545 |
//! \param uint32_t dwAccess, |
| 2546 |
//! [in] Desired access rights |
| 2547 |
//! \param void ** pUFKey |
| 2548 |
//! [out] Pointer to the variable that accepts the handle to |
| 2549 |
//! the user feature key opened |
| 2550 |
//! [in] in ConfigFS implementation, use pUFKey to pass the pUserFeature as a handler |
| 2551 |
//! \param MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo, |
| 2552 |
//! [in] user feature key path info |
| 2553 |
//! \return MOS_STATUS |
| 2554 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2555 |
//! else MOS_STATUS_SUCCESS |
| 2556 |
//! |
| 2557 |
static MOS_STATUS MosUserFeatureOpen( |
| 2558 |
MOS_USER_FEATURE_TYPE KeyType, |
| 2559 |
const char *pSubKey, |
| 2560 |
uint32_t dwAccess, |
| 2561 |
void **pUFKey, |
| 2562 |
MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo); |
| 2563 |
|
| 2564 |
//! |
| 2565 |
//! \brief Write Values to User Feature with specified Table and ID |
| 2566 |
//! \details Write Values to User Feature with specified Table and ID |
| 2567 |
//! The caller is responsible to allocate values / names |
| 2568 |
//! and free them later if necessary |
| 2569 |
//! \param PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface |
| 2570 |
//! [in] Pointer to OS User Interface structure |
| 2571 |
//! \param PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues |
| 2572 |
//! [in] Pointer to User Feature Data, and related User Feature Key ID (enum type in MOS_USER_FEATURE_VALUE_TYPE) |
| 2573 |
//! \param uint32_t uiNumOfValues |
| 2574 |
//! [in] number of user feature keys to be written. |
| 2575 |
//! \return MOS_STATUS |
| 2576 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2577 |
//! else MOS_STATUS_SUCCESS |
| 2578 |
//! |
| 2579 |
static MOS_STATUS MosUserFeatureWriteValuesTblID( |
| 2580 |
PMOS_USER_FEATURE_VALUE_WRITE_DATA pWriteValues, |
| 2581 |
uint32_t uiNumOfValues, |
| 2582 |
MOS_USER_FEATURE_KEY_PATH_INFO *ufInfo = nullptr); |
| 2583 |
|
| 2584 |
//! |
| 2585 |
//! \brief Wrapper for user feature value string free(). Performs error checking. |
| 2586 |
//! \details Wrapper for user feature value string free(). Performs error checking. |
| 2587 |
//! \param PMOS_USER_FEATURE_VALUE_STRING pUserString |
| 2588 |
//! [in] Pointer to the string structure with memory to be freed |
| 2589 |
//! \return void |
| 2590 |
//! |
| 2591 |
static void MosFreeUserFeatureValueString(PMOS_USER_FEATURE_VALUE_STRING pUserString); |
| 2592 |
|
| 2593 |
//! |
| 2594 |
//! \brief Free the allocated memory for the related Value type |
| 2595 |
//! \details Free the allocated memory for the related Value type |
| 2596 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pData |
| 2597 |
//! [in] Pointer to the User Feature Value Data |
| 2598 |
//! \param MOS_USER_FEATURE_VALUE_TYPE ValueType |
| 2599 |
//! [in] related Value Type needed to be deallocated. |
| 2600 |
//! \return MOS_STATUS |
| 2601 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2602 |
//! else MOS_STATUS_SUCCESS |
| 2603 |
//! |
| 2604 |
static MOS_STATUS MosDestroyUserFeatureData(PMOS_USER_FEATURE_VALUE_DATA pData, MOS_USER_FEATURE_VALUE_TYPE ValueType); |
| 2605 |
|
| 2606 |
//! |
| 2607 |
//! \brief Assign the value as a string type to destination Value Data pointer |
| 2608 |
//! \details Assign the value as a string type to destination Value Data pointer |
| 2609 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pDstData |
| 2610 |
//! [in] Pointer to the Destination Value Data |
| 2611 |
//! \param const char * pData |
| 2612 |
//! [in] Pointer to the Value Data as string type |
| 2613 |
//! \param MOS_USER_FEATURE_VALUE_TYPE ValueType |
| 2614 |
//! [in] Value Type for the copy data |
| 2615 |
//! \return MOS_STATUS |
| 2616 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2617 |
//! else MOS_STATUS_SUCCESS |
| 2618 |
//! |
| 2619 |
static MOS_STATUS MosAssignUserFeatureValueData( |
| 2620 |
PMOS_USER_FEATURE_VALUE_DATA pDstData, |
| 2621 |
const char *pData, |
| 2622 |
MOS_USER_FEATURE_VALUE_TYPE ValueType); |
| 2623 |
|
| 2624 |
//! |
| 2625 |
//! \brief check the input Default Value type |
| 2626 |
//! \details check the input Default Value type |
| 2627 |
//! \param const char * pData |
| 2628 |
//! [in] Pointer to the Default Value String |
| 2629 |
//! \param MOS_USER_FEATURE_VALUE_TYPE ValueType |
| 2630 |
//! [in] User Feature Value type needed to be check |
| 2631 |
//! \return MOS_STATUS |
| 2632 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2633 |
//! else MOS_STATUS_SUCCESS |
| 2634 |
//! |
| 2635 |
static MOS_STATUS MosIsCorrectDefaultValueType( |
| 2636 |
const char *pData, |
| 2637 |
MOS_USER_FEATURE_VALUE_TYPE ValueType); |
| 2638 |
|
| 2639 |
//! |
| 2640 |
//! \brief Check the User Feature Value correct or not |
| 2641 |
//! \details Check the User Feature Value correct or not |
| 2642 |
//! \param [in] pUserFeatureKey |
| 2643 |
//! Pointer to the User Feature Value needed to be checked |
| 2644 |
//! \param [in] maxKeyID |
| 2645 |
//! The max possible key ID in the corresponding table |
| 2646 |
//! \return MOS_STATUS |
| 2647 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2648 |
//! else MOS_STATUS_SUCCESS |
| 2649 |
//! |
| 2650 |
static MOS_STATUS MosIsCorrectUserFeatureDescField(PMOS_USER_FEATURE_VALUE pUserFeatureKey, uint32_t maxKeyID); |
| 2651 |
|
| 2652 |
//! |
| 2653 |
//! \brief Get the User Feature Value from Table |
| 2654 |
//! \details Get the related User Feature Value item according to Filter rules , and pass the item |
| 2655 |
//! into return callback function |
| 2656 |
//! \param [in] descTable |
| 2657 |
//! The user feature key description table |
| 2658 |
//! \param [in] numOfItems |
| 2659 |
//! Number of user feature keys described in the table |
| 2660 |
//! \param [in] maxId |
| 2661 |
//! Max value ID in the table |
| 2662 |
//! \param [out] keyValueMap |
| 2663 |
//! Optional pointer to the value map where the table items will be linked to, could be nullptr |
| 2664 |
//! \param [in] CallbackFunc |
| 2665 |
//! Pointer to the Callback function, and pass the User Feature Value item as its parameter |
| 2666 |
//! \param [in] pUserFeatureKeyFilter |
| 2667 |
//! use the filter rule to select some User Feature Value item |
| 2668 |
//! \return MOS_STATUS |
| 2669 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2670 |
//! else MOS_STATUS_SUCCESS |
| 2671 |
//! |
| 2672 |
static MOS_STATUS MosGetItemFromMosUserFeatureDescField( |
| 2673 |
MOS_USER_FEATURE_VALUE *descTable, |
| 2674 |
uint32_t numOfItems, |
| 2675 |
uint32_t maxId, |
| 2676 |
MOS_STATUS(*CallbackFunc)(PMOS_USER_FEATURE_VALUE), |
| 2677 |
PMOS_USER_FEATURE_VALUE pUserFeatureKeyFilter); |
| 2678 |
|
| 2679 |
//! |
| 2680 |
//! \brief Write string value to the user feature |
| 2681 |
//! \details Write string value to the user feature |
| 2682 |
//! \param void *UFKey |
| 2683 |
//! [in] Handle to the user feature key |
| 2684 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2685 |
//! [in] Pointer to User Feature that contains user feature key info |
| 2686 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pDataValue |
| 2687 |
//! [in] Pointer to User Feature Data that contains the string |
| 2688 |
//! \return MOS_STATUS |
| 2689 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2690 |
//! else MOS_STATUS_SUCCESS |
| 2691 |
//! |
| 2692 |
static MOS_STATUS MosUserFeatureWriteValueString( |
| 2693 |
void *UFKey, |
| 2694 |
PMOS_USER_FEATURE_VALUE pFeatureValue, |
| 2695 |
PMOS_USER_FEATURE_VALUE_DATA pDataValue); |
| 2696 |
|
| 2697 |
//! |
| 2698 |
//! \brief Write multi string value to the user feature |
| 2699 |
//! \details Write multi string value to the user feature |
| 2700 |
//! It combines the multi string into a temp buffer |
| 2701 |
//! and call routine to write the user feature |
| 2702 |
//! \param void *UFKey |
| 2703 |
//! [in] Handle to the user feature key |
| 2704 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2705 |
//! [in] Pointer to User Feature that contains user feature key info |
| 2706 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pDataValue |
| 2707 |
//! [in] Pointer to User Feature Data that contains the multi string |
| 2708 |
//! \return MOS_STATUS |
| 2709 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2710 |
//! else MOS_STATUS_SUCCESS |
| 2711 |
//! |
| 2712 |
static MOS_STATUS MosUserFeatureWriteValueMultiString( |
| 2713 |
void *UFKey, |
| 2714 |
PMOS_USER_FEATURE_VALUE pFeatureValue, |
| 2715 |
PMOS_USER_FEATURE_VALUE_DATA pDataValue); |
| 2716 |
|
| 2717 |
//! |
| 2718 |
//! \brief Write Binary value to the user feature |
| 2719 |
//! \details Write Binary value to the user feature |
| 2720 |
//! \param void *UFKey |
| 2721 |
//! [in] Handle to the user feature key |
| 2722 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2723 |
//! [in] Pointer to User Feature that contains user feature key info |
| 2724 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pDataValue |
| 2725 |
//! [in] Pointer to User Feature Data that contains the binary data |
| 2726 |
//! \return MOS_STATUS |
| 2727 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2728 |
//! else MOS_STATUS_SUCCESS |
| 2729 |
//! |
| 2730 |
static MOS_STATUS MosUserFeatureWriteValueBinary( |
| 2731 |
void *UFKey, |
| 2732 |
PMOS_USER_FEATURE_VALUE pFeatureValue, |
| 2733 |
PMOS_USER_FEATURE_VALUE_DATA pDataValue); |
| 2734 |
|
| 2735 |
//! |
| 2736 |
//! \brief Write Primitive data value to the user feature |
| 2737 |
//! \details Write Primitive data value to the user feature |
| 2738 |
//! \param void *UFKey |
| 2739 |
//! [in] Handle to the user feature key |
| 2740 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2741 |
//! [in] Pointer to User Feature that contains user feature key info |
| 2742 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pDataValue |
| 2743 |
//! [in] Pointer to User Feature Data that contains the primitive data |
| 2744 |
//! \return MOS_STATUS |
| 2745 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2746 |
//! else MOS_STATUS_SUCCESS |
| 2747 |
//! |
| 2748 |
static MOS_STATUS MosUserFeatureWriteValuePrimitive( |
| 2749 |
void *UFKey, |
| 2750 |
PMOS_USER_FEATURE_VALUE pFeatureValue, |
| 2751 |
PMOS_USER_FEATURE_VALUE_DATA pDataValue); |
| 2752 |
|
| 2753 |
//! |
| 2754 |
//! \brief Read binary value from the user feature |
| 2755 |
//! \details Read binary value from the user feature, |
| 2756 |
//! and store it into the user feature data |
| 2757 |
//! \param void *UFKey |
| 2758 |
//! [in] Handle to the user feature key |
| 2759 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2760 |
//! [in/out] Pointer to User Feature Data |
| 2761 |
//! \return MOS_STATUS |
| 2762 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2763 |
//! else MOS_STATUS_SUCCESS |
| 2764 |
//! |
| 2765 |
static MOS_STATUS MosUserFeatureReadValueBinary( |
| 2766 |
void *UFKey, |
| 2767 |
PMOS_USER_FEATURE_VALUE pFeatureValue); |
| 2768 |
|
| 2769 |
//! |
| 2770 |
//! \brief Read string value from the user feature |
| 2771 |
//! \details Read string value from the user feature, |
| 2772 |
//! and store it into the user feature data |
| 2773 |
//! \param void *UFKey |
| 2774 |
//! [in] Handle to the user feature key |
| 2775 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2776 |
//! [in/out] Pointer to User Feature Data |
| 2777 |
//! \return MOS_STATUS |
| 2778 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2779 |
//! else MOS_STATUS_SUCCESS |
| 2780 |
//! |
| 2781 |
static MOS_STATUS MosUserFeatureReadValueString( |
| 2782 |
void *UFKey, |
| 2783 |
PMOS_USER_FEATURE_VALUE pFeatureValue); |
| 2784 |
|
| 2785 |
//! |
| 2786 |
//! \brief Read multi string value from the user feature |
| 2787 |
//! \details Read multi string value from the user feature, |
| 2788 |
//! and store it into the user feature data |
| 2789 |
//! \param void *UFKey |
| 2790 |
//! [in] Handle to the user feature key |
| 2791 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2792 |
//! [in/out] Pointer to User Feature Data |
| 2793 |
//! \return MOS_STATUS |
| 2794 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2795 |
//! else MOS_STATUS_SUCCESS |
| 2796 |
//! |
| 2797 |
static MOS_STATUS MosUserFeatureReadValueMultiString( |
| 2798 |
void *UFKey, |
| 2799 |
PMOS_USER_FEATURE_VALUE pFeatureValue); |
| 2800 |
|
| 2801 |
//! |
| 2802 |
//! \brief Read Primitive data value from the user feature |
| 2803 |
//! \details Read Primitive data value from the user feature, |
| 2804 |
//! and store it into the user feature data |
| 2805 |
//! \param void *UFKey |
| 2806 |
//! [in] Handle to the user feature key |
| 2807 |
//! \param PMOS_USER_FEATURE_VALUE pFeatureValue |
| 2808 |
//! [in/out] Pointer to User Feature Data |
| 2809 |
//! \return MOS_STATUS |
| 2810 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2811 |
//! else MOS_STATUS_SUCCESS |
| 2812 |
//! |
| 2813 |
static MOS_STATUS MosUserFeatureReadValuePrimitive( |
| 2814 |
void *UFKey, |
| 2815 |
PMOS_USER_FEATURE_VALUE pFeatureValue); |
| 2816 |
|
| 2817 |
//! |
| 2818 |
//! \brief Initializes read user feature value function |
| 2819 |
//! \details Initializes read user feature value function |
| 2820 |
//! This is an internal function of MOS utilitiesNext. |
| 2821 |
//! It is implemented to support two differnt usages of MOS_UserFeature_ReadValue() |
| 2822 |
//! One usage comes with user pre-allocated user value, |
| 2823 |
//! the other comes with nullptr user value, and this function will allocate for it. |
| 2824 |
//! Please refer to MOS_UserFeature_ReadValue() or function body for details. |
| 2825 |
//! \param PMOS_USER_FEATURE_INTERFACE pOsUserFeatureInterface |
| 2826 |
//! [in] Pointer to OS user feature interface |
| 2827 |
//! \param PMOS_USER_FEATURE pUserFeature |
| 2828 |
//! [in/out] Pointer to user feature interface |
| 2829 |
//! \param char *pValueName, |
| 2830 |
//! [in] Pointer to value name |
| 2831 |
//! \param MOS_USER_FEATURE_VALUE_TYPE ValueType |
| 2832 |
//! [in] User Feature Value type |
| 2833 |
//! \return MOS_STATUS |
| 2834 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2835 |
//! else MOS_STATUS_SUCCESS |
| 2836 |
//! |
| 2837 |
static MOS_STATUS MosUserFeatureReadValueInit( |
| 2838 |
uint32_t uiNumValues); |
| 2839 |
|
| 2840 |
//! |
| 2841 |
//! \brief Set the Multi String Value to Settings Data |
| 2842 |
//! \details Set the Multi String Value to Settings Data |
| 2843 |
//! It parses the given multi string value, |
| 2844 |
//! assign UserFeatureValue's multistring data |
| 2845 |
//! with pointers to the strings |
| 2846 |
//! \param PMOS_USER_FEATURE_VALUE_DATA pFeatureData |
| 2847 |
//! [out] Pointer to User Feature Data |
| 2848 |
//! \param void *pvData |
| 2849 |
//! [in] Pointer to the multi string value |
| 2850 |
//! \param uint32_t dwSize |
| 2851 |
//! [in] Size of the multi string value |
| 2852 |
//! \return MOS_STATUS |
| 2853 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2854 |
//! else MOS_STATUS_SUCCESS |
| 2855 |
//! |
| 2856 |
static MOS_STATUS MosUserFeatureSetMultiStringValue( |
| 2857 |
PMOS_USER_FEATURE_VALUE_DATA pFeatureData, |
| 2858 |
uint32_t dwSize); |
| 2859 |
|
| 2860 |
//! |
| 2861 |
//! \brief MOS gfx info initialize |
| 2862 |
//! \details Load igdinfoXX.dll library and get gfx info function pointer |
| 2863 |
//! \param void |
| 2864 |
//! \return MOS_STATUS |
| 2865 |
//! Returns one of the MOS_STATUS error codes if failed, |
| 2866 |
//! else MOS_STATUS_SUCCESS |
| 2867 |
//! |
| 2868 |
static MOS_STATUS MosGfxInfoInit(); |
| 2869 |
|
| 2870 |
//! |
| 2871 |
//! \brief MOS gfx info close |
| 2872 |
//! \details Release igdinfoXX.dll library |
| 2873 |
//! \param void |
| 2874 |
//! \return void |
| 2875 |
//! |
| 2876 |
static void MosGfxInfoClose(); |
| 2877 |
|
| 2878 |
public: |
| 2879 |
static uint8_t *m_mosUltFlag; |
| 2880 |
static int32_t m_mosMemAllocCounterNoUserFeature; |
| 2881 |
static int32_t m_mosMemAllocCounterNoUserFeatureGfx; |
| 2882 |
|
| 2883 |
//Temporarily defined as the reference to compatible with the cases using uf key to enable/disable APG. |
| 2884 |
static int32_t *m_mosMemAllocCounter; |
| 2885 |
static int32_t *m_mosMemAllocIndex; |
| 2886 |
static int32_t *m_mosMemAllocFakeCounter; |
| 2887 |
static int32_t *m_mosMemAllocCounterGfx; |
| 2888 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 2889 |
static int32_t *m_mosAllocMemoryFailSimulateAllocCounter; |
| 2890 |
#endif |
| 2891 |
|
| 2892 |
static bool m_enableAddressDump; |
| 2893 |
|
| 2894 |
static MOS_USER_FEATURE_VALUE m_mosUserFeatureDescFields[__MOS_USER_FEATURE_KEY_MAX_ID]; |
| 2895 |
private: |
| 2896 |
static const MtControlData *m_mosTraceControlData; |
| 2897 |
static MtEnable m_mosTraceEnable; |
| 2898 |
static MtFilter m_mosTraceFilter; |
| 2899 |
static MtLevel m_mosTraceLevel; |
| 2900 |
static MosMutex m_mutexLock; |
| 2901 |
static uint32_t m_mosUtilInitCount; // number count of mos utilities init |
| 2902 |
#if _MEDIA_RESERVED |
| 2903 |
static MediaUserSettingsMgr* m_codecUserFeatureExt; |
| 2904 |
static MediaUserSettingsMgr* m_vpUserFeatureExt; |
| 2905 |
#endif |
| 2906 |
static MediaUserSettingsMgr* m_mediaUserFeatureSpecific; |
| 2907 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 2908 |
static uint32_t m_mosAllocMemoryFailSimulateMode; |
| 2909 |
static uint32_t m_mosAllocMemoryFailSimulateFreq; |
| 2910 |
static uint32_t m_mosAllocMemoryFailSimulateHint; |
| 2911 |
#endif |
| 2912 |
MEDIA_CLASS_DEFINE_END(MosUtilities) |
| 2913 |
}; |
| 2914 |
|
| 2915 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 2916 |
#define MEMORY_ALLOC_FAIL_SIMULATE_MODE_DEFAULT (0) |
| 2917 |
#define MEMORY_ALLOC_FAIL_SIMULATE_MODE_RANDOM (1) |
| 2918 |
#define MEMORY_ALLOC_FAIL_SIMULATE_MODE_TRAVERSE (2) |
| 2919 |
|
| 2920 |
#define MIN_MEMORY_ALLOC_FAIL_FREQ (1) //max memory allcation fail rate 100% |
| 2921 |
#define MAX_MEMORY_ALLOC_FAIL_FREQ (10000) //min memory allcation fail rate 1/10000 |
| 2922 |
|
| 2923 |
#define MosAllocMemoryFailSimulationEnabled \ |
| 2924 |
(m_mosAllocMemoryFailSimulateMode == MEMORY_ALLOC_FAIL_SIMULATE_MODE_RANDOM || \ |
| 2925 |
m_mosAllocMemoryFailSimulateMode == MEMORY_ALLOC_FAIL_SIMULATE_MODE_TRAVERSE) |
| 2926 |
#endif |
| 2927 |
|
| 2928 |
class MosMutex |
| 2929 |
{ |
| 2930 |
public: |
| 2931 |
MosMutex(void) |
| 2932 |
{ |
| 2933 |
m_lock = MosUtilities::MosCreateMutex(); |
| 2934 |
} |
| 2935 |
|
| 2936 |
~MosMutex() |
| 2937 |
{ |
| 2938 |
MosUtilities::MosDestroyMutex(m_lock); |
| 2939 |
} |
| 2940 |
|
| 2941 |
void Lock() |
| 2942 |
{ |
| 2943 |
MosUtilities::MosLockMutex(m_lock); |
| 2944 |
} |
| 2945 |
|
| 2946 |
void Unlock() |
| 2947 |
{ |
| 2948 |
MosUtilities::MosUnlockMutex(m_lock); |
| 2949 |
} |
| 2950 |
|
| 2951 |
private: |
| 2952 |
PMOS_MUTEX m_lock = nullptr; |
| 2953 |
MEDIA_CLASS_DEFINE_END(MosMutex) |
| 2954 |
}; |
| 2955 |
|
| 2956 |
#include "mos_util_debug.h" |
| 2957 |
|
| 2958 |
//! Helper Macros for MEMNINJA debug messages |
| 2959 |
#define MOS_MEMNINJA_ALLOC_MESSAGE(ptr, size, functionName, filename, line) \ |
| 2960 |
MOS_OS_MEMNINJAMESSAGE( \ |
| 2961 |
"MemNinjaSysAlloc: Time = %f, MemNinjaCounter = %d, memPtr = %p, size = %d, functionName = \"%s\", " \ |
| 2962 |
"filename = \"%s\", line = %d/", MosUtilities::MosGetTime(), (MosUtilities::m_mosMemAllocCounter ? *MosUtilities::m_mosMemAllocCounter : 0), ptr, size, functionName, filename, line); \ |
| 2963 |
|
| 2964 |
|
| 2965 |
#define MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line) \ |
| 2966 |
MOS_OS_MEMNINJAMESSAGE( \ |
| 2967 |
"MemNinjaSysFree: Time = %f, MemNinjaCounter = %d, memPtr = %p, functionName = \"%s\", " \ |
| 2968 |
"filename = \"%s\", line = %d/", MosUtilities::MosGetTime(), (MosUtilities::m_mosMemAllocCounter ? *MosUtilities::m_mosMemAllocCounter : 0), ptr, functionName, filename, line); \ |
| 2969 |
|
| 2970 |
|
| 2971 |
#define MOS_MEMNINJA_GFX_ALLOC_MESSAGE(ptr, bufName, component, size, arraySize, functionName, filename, line) \ |
| 2972 |
MOS_OS_MEMNINJAMESSAGE( \ |
| 2973 |
"MemNinjaGfxAlloc: Time = %f, MemNinjaCounterGfx = %d, memPtr = %p, bufName = %s, component = %d, size = %lld, " \ |
| 2974 |
"arraySize = %d, functionName = \"%s\", filename = \"%s\", line = %d/", MosUtilities::MosGetTime(), (MosUtilities::m_mosMemAllocCounterGfx ? *MosUtilities::m_mosMemAllocCounterGfx : 0), ptr, \ |
| 2975 |
bufName, component, size, arraySize, functionName, filename, line); \ |
| 2976 |
|
| 2977 |
#define MOS_MEMNINJA_GFX_FREE_MESSAGE(ptr, functionName, filename, line) \ |
| 2978 |
MOS_OS_MEMNINJAMESSAGE( \ |
| 2979 |
"MemNinjaGfxFree: Time = %f, MemNinjaCounterGfx = %d, memPtr = %p, functionName = \"%s\", " \ |
| 2980 |
"filename = \"%s\", line = %d/", MosUtilities::MosGetTime(), (MosUtilities::m_mosMemAllocCounterGfx ? *MosUtilities::m_mosMemAllocCounterGfx : 0), ptr, functionName, filename, line); \ |
| 2981 |
|
| 2982 |
#if MOS_MESSAGES_ENABLED |
| 2983 |
#define PRINT_ALLOCATE_MEMORY(id, lvl, p1, v1, p2, v2, FunName, FileName, Line) MosUtilities::MosPrintCPUAllocateMemory(id, lvl, p1, v1, p2, v2, FunName, FileName, Line) |
| 2984 |
#define PRINT_DESTROY_MEMORY(id, lvl, p1, v1, FunName, FileName, Line) MosUtilities::MosPrintCPUDestroyMemory(id, lvl, p1, v1, FunName, FileName, Line) |
| 2985 |
#else |
| 2986 |
#define PRINT_ALLOCATE_MEMORY(id, lvl, p1, v1, p2, v2, FunName, FileName, Line) |
| 2987 |
#define PRINT_DESTROY_MEMORY(id, lvl, p1, v1, FunName, FileName, Line) |
| 2988 |
#endif |
| 2989 |
|
| 2990 |
|
| 2991 |
#if MOS_MESSAGES_ENABLED |
| 2992 |
template<class _Ty, class... _Types> inline |
| 2993 |
_Ty* MosUtilities::MosNewUtil(const char *functionName, |
| 2994 |
const char *filename, |
| 2995 |
int32_t line, _Types&&... _Args) |
| 2996 |
#else |
| 2997 |
template<class _Ty, class... _Types> inline |
| 2998 |
_Ty* MosUtilities::MosNewUtil(_Types&&... _Args) |
| 2999 |
#endif |
| 3000 |
{ |
| 3001 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 3002 |
//Simulate allocate memory fail if flag turned on |
| 3003 |
if (MosSimulateAllocMemoryFail(sizeof(_Ty), NO_ALLOC_ALIGNMENT, functionName, filename, line)) |
| 3004 |
{ |
| 3005 |
return nullptr; |
| 3006 |
} |
| 3007 |
#endif |
| 3008 |
_Ty* ptr = new (std::nothrow) _Ty(std::forward<_Types>(_Args)...); |
| 3009 |
if (ptr != nullptr) |
| 3010 |
{ |
| 3011 |
MosAtomicIncrement(m_mosMemAllocCounter); |
| 3012 |
MOS_MEMNINJA_ALLOC_MESSAGE(ptr, sizeof(_Ty), functionName, filename, line); |
| 3013 |
PRINT_ALLOCATE_MEMORY(MT_MOS_ALLOCATE_MEMORY, MT_NORMAL, |
| 3014 |
MT_MEMORY_PTR, (int64_t)(ptr), |
| 3015 |
MT_MEMORY_SIZE, static_cast<int64_t>(sizeof(_Ty)), |
| 3016 |
functionName, filename, line); |
| 3017 |
} |
| 3018 |
else |
| 3019 |
{ |
| 3020 |
MOS_OS_ASSERTMESSAGE("Fail to create class."); |
| 3021 |
} |
| 3022 |
return ptr; |
| 3023 |
} |
| 3024 |
|
| 3025 |
#if MOS_MESSAGES_ENABLED |
| 3026 |
template<class _Ty, class... _Types> inline |
| 3027 |
_Ty *MosUtilities::MosNewArrayUtil(const char *functionName, |
| 3028 |
const char *filename, |
| 3029 |
int32_t line, size_t numElements) |
| 3030 |
#else |
| 3031 |
template<class _Ty, class... _Types> inline |
| 3032 |
_Ty* MosUtilities::MosNewArrayUtil(size_t numElements) |
| 3033 |
#endif |
| 3034 |
{ |
| 3035 |
if (numElements > PTRDIFF_MAX) |
| 3036 |
{ |
| 3037 |
return nullptr; |
| 3038 |
} |
| 3039 |
|
| 3040 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 3041 |
//Simulate allocate memory fail if flag turned on |
| 3042 |
if (MosSimulateAllocMemoryFail(sizeof(_Ty) * numElements, NO_ALLOC_ALIGNMENT, functionName, filename, line)) |
| 3043 |
{ |
| 3044 |
return nullptr; |
| 3045 |
} |
| 3046 |
#endif |
| 3047 |
_Ty* ptr = new (std::nothrow) _Ty[numElements](); |
| 3048 |
if (ptr != nullptr) |
| 3049 |
{ |
| 3050 |
MosAtomicIncrement(m_mosMemAllocCounter); |
| 3051 |
MOS_MEMNINJA_ALLOC_MESSAGE(ptr, numElements*sizeof(_Ty), functionName, filename, line); |
| 3052 |
PRINT_ALLOCATE_MEMORY(MT_MOS_ALLOCATE_MEMORY, MT_NORMAL, |
| 3053 |
MT_MEMORY_PTR, (int64_t)(ptr), |
| 3054 |
MT_MEMORY_SIZE, (static_cast<int64_t>(numElements))*(static_cast<int64_t>(sizeof(_Ty))), |
| 3055 |
functionName, filename, line); |
| 3056 |
} |
| 3057 |
return ptr; |
| 3058 |
} |
| 3059 |
|
| 3060 |
#if MOS_MESSAGES_ENABLED |
| 3061 |
template<class _Ty> inline |
| 3062 |
void MosUtilities::MosDeleteUtil( |
| 3063 |
const char *functionName, |
| 3064 |
const char *filename, |
| 3065 |
int32_t line, |
| 3066 |
_Ty& ptr) |
| 3067 |
#else |
| 3068 |
template<class _Ty> inline |
| 3069 |
void MosUtilities::MosDeleteUtil(_Ty& ptr) |
| 3070 |
#endif |
| 3071 |
{ |
| 3072 |
if (ptr != nullptr) |
| 3073 |
{ |
| 3074 |
MosAtomicDecrement(m_mosMemAllocCounter); |
| 3075 |
MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line); |
| 3076 |
PRINT_DESTROY_MEMORY(MT_MOS_DESTROY_MEMORY, MT_NORMAL, |
| 3077 |
MT_MEMORY_PTR, (int64_t)(ptr), |
| 3078 |
functionName, filename, line); |
| 3079 |
delete(ptr); |
| 3080 |
ptr = nullptr; |
| 3081 |
} |
| 3082 |
} |
| 3083 |
|
| 3084 |
#if MOS_MESSAGES_ENABLED |
| 3085 |
template<class _Ty> inline |
| 3086 |
void MosUtilities::MosDeleteArrayUtil( |
| 3087 |
const char *functionName, |
| 3088 |
const char *filename, |
| 3089 |
int32_t line, |
| 3090 |
_Ty& ptr) |
| 3091 |
#else |
| 3092 |
template <class _Ty> inline |
| 3093 |
void MosUtilities::MosDeleteArrayUtil(_Ty& ptr) |
| 3094 |
#endif |
| 3095 |
{ |
| 3096 |
if (ptr != nullptr) |
| 3097 |
{ |
| 3098 |
MosAtomicDecrement(m_mosMemAllocCounter); |
| 3099 |
MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line); |
| 3100 |
PRINT_DESTROY_MEMORY(MT_MOS_DESTROY_MEMORY, MT_NORMAL, |
| 3101 |
MT_MEMORY_PTR, (int64_t)(ptr), |
| 3102 |
functionName, filename, line); |
| 3103 |
delete[](ptr); |
| 3104 |
ptr = nullptr; |
| 3105 |
} |
| 3106 |
} |
| 3107 |
|
| 3108 |
|
| 3109 |
//template<class _Ty, class... _Types> inline |
| 3110 |
//std::shared_ptr<_Ty> MOS_MakeShared(_Types&&... _Args) |
| 3111 |
//{ |
| 3112 |
// try |
| 3113 |
// { |
| 3114 |
// return std::make_shared<_Ty>(std::forward<_Types>(_Args)...); |
| 3115 |
// } |
| 3116 |
// catch (const std::bad_alloc&) |
| 3117 |
// { |
| 3118 |
// return nullptr; |
| 3119 |
// } |
| 3120 |
//} |
| 3121 |
|
| 3122 |
#if MOS_MESSAGES_ENABLED |
| 3123 |
#define MOS_NewArray(classType, numElements) MosUtilities::MosNewArrayUtil<classType>(__FUNCTION__, __FILE__, __LINE__, numElements) |
| 3124 |
#define MOS_New(classType, ...) MosUtilities::MosNewUtil<classType>(__FUNCTION__, __FILE__, __LINE__, ##__VA_ARGS__) |
| 3125 |
#else |
| 3126 |
#define MOS_NewArray(classType, numElements) MosUtilities::MosNewArrayUtil<classType>(numElements) |
| 3127 |
#define MOS_New(classType, ...) MosUtilities::MosNewUtil<classType>(__VA_ARGS__) |
| 3128 |
#endif |
| 3129 |
|
| 3130 |
#if MOS_MESSAGES_ENABLED |
| 3131 |
#define MOS_DeleteUtil(functionName, filename, line, ptr) \ |
| 3132 |
if (ptr != nullptr) \ |
| 3133 |
{ \ |
| 3134 |
MosUtilities::MosAtomicDecrement(MosUtilities::m_mosMemAllocCounter); \ |
| 3135 |
MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line); \ |
| 3136 |
PRINT_DESTROY_MEMORY(MT_MOS_DESTROY_MEMORY, MT_NORMAL, MT_MEMORY_PTR, (int64_t)(ptr), functionName, filename, line); \ |
| 3137 |
delete(ptr); \ |
| 3138 |
ptr = nullptr; \ |
| 3139 |
} |
| 3140 |
#else |
| 3141 |
#define MOS_DeleteUtil(ptr) \ |
| 3142 |
if (ptr != nullptr) \ |
| 3143 |
{ \ |
| 3144 |
MosUtilities::MosAtomicDecrement(MosUtilities::m_mosMemAllocCounter); \ |
| 3145 |
MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line); \ |
| 3146 |
delete(ptr); \ |
| 3147 |
ptr = nullptr; \ |
| 3148 |
} |
| 3149 |
#endif |
| 3150 |
|
| 3151 |
#if MOS_MESSAGES_ENABLED |
| 3152 |
#define MOS_DeleteArrayUtil(functionName, filename, line, ptr) \ |
| 3153 |
if (ptr != nullptr) \ |
| 3154 |
{ \ |
| 3155 |
MosUtilities::MosAtomicDecrement(MosUtilities::m_mosMemAllocCounter); \ |
| 3156 |
MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line); \ |
| 3157 |
PRINT_DESTROY_MEMORY(MT_MOS_DESTROY_MEMORY, MT_NORMAL, MT_MEMORY_PTR, (int64_t)(ptr), functionName, filename, line); \ |
| 3158 |
delete[](ptr); \ |
| 3159 |
ptr = nullptr; \ |
| 3160 |
} |
| 3161 |
#else |
| 3162 |
#define MOS_DeleteArrayUtil(ptr) \ |
| 3163 |
if (ptr != nullptr) \ |
| 3164 |
{ \ |
| 3165 |
MosUtilities::MosAtomicDecrement(MosUtilities::m_mosMemAllocCounter); \ |
| 3166 |
MOS_MEMNINJA_FREE_MESSAGE(ptr, functionName, filename, line); \ |
| 3167 |
delete[](ptr); \ |
| 3168 |
ptr = nullptr; \ |
| 3169 |
} |
| 3170 |
#endif |
| 3171 |
|
| 3172 |
#if MOS_MESSAGES_ENABLED |
| 3173 |
#define MOS_DeleteArray(ptr) MOS_DeleteArrayUtil(__FUNCTION__, __FILE__, __LINE__, ptr) |
| 3174 |
#define MOS_Delete(ptr) MOS_DeleteUtil(__FUNCTION__, __FILE__, __LINE__, ptr) |
| 3175 |
#else |
| 3176 |
#define MOS_DeleteArray(ptr) MOS_DeleteArrayUtil(ptr) |
| 3177 |
#define MOS_Delete(ptr) MOS_DeleteUtil(ptr) |
| 3178 |
#endif |
| 3179 |
|
| 3180 |
//------------------------------------------------------------------------------ |
| 3181 |
// Allocate, free and set a memory region |
| 3182 |
//------------------------------------------------------------------------------ |
| 3183 |
|
| 3184 |
#if MOS_MESSAGES_ENABLED |
| 3185 |
|
| 3186 |
#define MOS_AlignedAllocMemory(size, alignment) \ |
| 3187 |
MosUtilities::MosAlignedAllocMemoryUtils(size, alignment, __FUNCTION__, __FILE__, __LINE__) |
| 3188 |
#define MOS_AlignedFreeMemory(ptr) \ |
| 3189 |
MosUtilities::MosAlignedFreeMemoryUtils(ptr, __FUNCTION__, __FILE__, __LINE__) |
| 3190 |
|
| 3191 |
#define MOS_AllocMemory(size) \ |
| 3192 |
MosUtilities::MosAllocMemoryUtils(size, __FUNCTION__, __FILE__, __LINE__) |
| 3193 |
#define MOS_FreeMemory(ptr) \ |
| 3194 |
MosUtilities::MosFreeMemoryUtils(ptr, __FUNCTION__, __FILE__, __LINE__) |
| 3195 |
|
| 3196 |
#define MOS_AllocAndZeroMemory(size) \ |
| 3197 |
MosUtilities::MosAllocAndZeroMemoryUtils(size, __FUNCTION__, __FILE__, __LINE__) |
| 3198 |
|
| 3199 |
#define MOS_ReallocMemory(ptr, newSize) \ |
| 3200 |
MosUtilities::MosReallocMemoryUtils(ptr, newSize, __FUNCTION__, __FILE__, __LINE__) |
| 3201 |
|
| 3202 |
#else // !MOS_MESSAGES_ENABLED |
| 3203 |
|
| 3204 |
#define MOS_AlignedAllocMemory(size, alignment) \ |
| 3205 |
MosUtilities::MosAlignedAllocMemory(size, alignment) |
| 3206 |
#define MOS_AlignedFreeMemory(ptr) \ |
| 3207 |
MosUtilities::MosAlignedFreeMemory(ptr) |
| 3208 |
|
| 3209 |
#define MOS_AllocMemory(size) \ |
| 3210 |
MosUtilities::MosAllocMemory(size) |
| 3211 |
#define MOS_FreeMemory(ptr) \ |
| 3212 |
MosUtilities::MosFreeMemory(ptr) |
| 3213 |
|
| 3214 |
#define MOS_AllocAndZeroMemory(size) \ |
| 3215 |
MosUtilities::MosAllocAndZeroMemory(size) |
| 3216 |
|
| 3217 |
#define MOS_ReallocMemory(ptr, newSize) \ |
| 3218 |
MosUtilities::MosReallocMemory(ptr, newSize) |
| 3219 |
|
| 3220 |
#endif // MOS_MESSAGES_ENABLED |
| 3221 |
|
| 3222 |
#define MOS_FreeMemAndSetNull(ptr) \ |
| 3223 |
do{ \ |
| 3224 |
MOS_FreeMemory(ptr); \ |
| 3225 |
ptr = nullptr; \ |
| 3226 |
} while (0) |
| 3227 |
|
| 3228 |
#define MOS_SafeFreeMemory(ptr) \ |
| 3229 |
if (ptr) MOS_FreeMemory(ptr); \ |
| 3230 |
|
| 3231 |
#define MOS_ZeroMemory(pDestination, stLength) \ |
| 3232 |
MosUtilities::MosZeroMemory(pDestination, stLength) |
| 3233 |
|
| 3234 |
#define MOS_FillMemory(pDestination, stLength, bFill) \ |
| 3235 |
MosUtilities::MosFillMemory(pDestination, stLength, bFill) |
| 3236 |
|
| 3237 |
//------------------------------------------------------------------------------ |
| 3238 |
// string |
| 3239 |
//------------------------------------------------------------------------------ |
| 3240 |
#define MOS_SecureStrcat(strDestination, numberOfElements, strSource) \ |
| 3241 |
MosUtilities::MosSecureStrcat(strDestination, numberOfElements, strSource) |
| 3242 |
|
| 3243 |
#define MOS_SecureStrcpy(strDestination, numberOfElements, strSource) \ |
| 3244 |
MosUtilities::MosSecureStrcpy(strDestination, numberOfElements, strSource) |
| 3245 |
|
| 3246 |
#define MOS_SecureMemcpy(pDestination, dstLength, pSource, srcLength) \ |
| 3247 |
MosUtilities::MosSecureMemcpy(pDestination, dstLength, pSource, srcLength) |
| 3248 |
|
| 3249 |
#define MOS_SecureStringPrint(buffer, bufSize, length, format, ...) \ |
| 3250 |
MosUtilities::MosSecureStringPrint(buffer, bufSize, length, format, ##__VA_ARGS__) |
| 3251 |
|
| 3252 |
#define Mos_SwizzleData(pSrc, pDst, SrcTiling, DstTiling, iHeight, iPitch, extFlags) \ |
| 3253 |
MosUtilities::MosSwizzleData(pSrc, pDst, SrcTiling, DstTiling, iHeight, iPitch, extFlags) |
| 3254 |
|
| 3255 |
#define Mos_SwizzleOffsetWrapper(OffsetX, OffsetY, Pitch, TileFormat, CsxSwizzle, Flags) \ |
| 3256 |
MosUtilities::MosSwizzleOffsetWrapper(OffsetX, OffsetY, Pitch, TileFormat, CsxSwizzle, Flags) |
| 3257 |
//------------------------------------------------------------------------------ |
| 3258 |
// trace |
| 3259 |
//------------------------------------------------------------------------------ |
| 3260 |
|
| 3261 |
#define MOS_TraceKeyEnabled(key) MosUtilities::TraceKeyEnabled(key) |
| 3262 |
|
| 3263 |
inline void MOS_TraceEvent( |
| 3264 |
uint16_t usId, |
| 3265 |
uint8_t ucType, |
| 3266 |
const void *pArg1, |
| 3267 |
uint32_t dwSize1, |
| 3268 |
const void *pArg2 = nullptr, |
| 3269 |
uint32_t dwSize2 = 0) |
| 3270 |
{ |
| 3271 |
MosUtilities::MosTraceEvent(usId, ucType, pArg1, dwSize1, pArg2, dwSize2); |
| 3272 |
} |
| 3273 |
|
| 3274 |
inline void MOS_TraceEvent( |
| 3275 |
MEDIA_EVENT_FILTER_KEYID key, |
| 3276 |
uint16_t usId, |
| 3277 |
uint8_t ucType, |
| 3278 |
const void *pArg1, |
| 3279 |
uint32_t dwSize1, |
| 3280 |
const void *pArg2 = nullptr, |
| 3281 |
uint32_t dwSize2 = 0) |
| 3282 |
{ |
| 3283 |
if (MosUtilities::TraceKeyEnabled(key)) |
| 3284 |
{ |
| 3285 |
MosUtilities::MosTraceEvent(usId, ucType, pArg1, dwSize1, pArg2, dwSize2); |
| 3286 |
} |
| 3287 |
} |
| 3288 |
|
| 3289 |
inline void MOS_TraceEvent( |
| 3290 |
MEDIA_EVENT_FILTER_KEYID key, |
| 3291 |
MT_EVENT_LEVEL level, |
| 3292 |
uint16_t usId, |
| 3293 |
uint8_t ucType, |
| 3294 |
const void *pArg1, |
| 3295 |
uint32_t dwSize1, |
| 3296 |
const void *pArg2 = nullptr, |
| 3297 |
uint32_t dwSize2 = 0) |
| 3298 |
{ |
| 3299 |
if (MosUtilities::TraceKeyEnabled(key) && MosUtilities::TracelevelEnabled(level)) |
| 3300 |
{ |
| 3301 |
MosUtilities::MosTraceEvent(usId, ucType, pArg1, dwSize1, pArg2, dwSize2); |
| 3302 |
} |
| 3303 |
} |
| 3304 |
|
| 3305 |
inline void MOS_TraceDataDump( |
| 3306 |
const char *pcName, |
| 3307 |
uint32_t flags, |
| 3308 |
const void *pBuf, |
| 3309 |
uint32_t dwSize) |
| 3310 |
{ |
| 3311 |
if (MosUtilities::TraceKeyEnabled(TR_KEY_DATA_DUMP)) |
| 3312 |
{ |
| 3313 |
MosUtilities::MosTraceDataDump(pcName, flags, pBuf, dwSize); |
| 3314 |
} |
| 3315 |
} |
| 3316 |
|
| 3317 |
inline void MOS_TraceDataDump( |
| 3318 |
MEDIA_EVENT_FILTER_KEYID key, |
| 3319 |
const char *pcName, |
| 3320 |
uint32_t flags, |
| 3321 |
const void *pBuf, |
| 3322 |
uint32_t dwSize) |
| 3323 |
{ |
| 3324 |
if (MosUtilities::TraceKeyEnabled(TR_KEY_DATA_DUMP)) |
| 3325 |
{ |
| 3326 |
MosUtilities::MosTraceDataDump(pcName, flags, pBuf, dwSize); |
| 3327 |
} |
| 3328 |
} |
| 3329 |
|
| 3330 |
inline void MOS_TraceDataDump( |
| 3331 |
MEDIA_EVENT_FILTER_KEYID key, |
| 3332 |
MT_DATA_LEVEL level, |
| 3333 |
const char *pcName, |
| 3334 |
uint32_t flags, |
| 3335 |
const void *pBuf, |
| 3336 |
uint32_t dwSize) |
| 3337 |
{ |
| 3338 |
constexpr uint32_t LEVEL0_SIZE = 64; |
| 3339 |
|
| 3340 |
if (!(MosUtilities::TraceKeyEnabled(TR_KEY_DATA_DUMP) && MosUtilities::TraceKeyEnabled(key))) |
| 3341 |
{ |
| 3342 |
return; |
| 3343 |
} |
| 3344 |
|
| 3345 |
uint32_t size = dwSize; |
| 3346 |
if (size > LEVEL0_SIZE) |
| 3347 |
{ |
| 3348 |
switch (level) |
| 3349 |
{ |
| 3350 |
case MT_DATA_LEVEL::FIRST_64B: |
| 3351 |
size = LEVEL0_SIZE; |
| 3352 |
break; |
| 3353 |
case MT_DATA_LEVEL::QUARTER: |
| 3354 |
size >>= 2; |
| 3355 |
break; |
| 3356 |
case MT_DATA_LEVEL::HALF: |
| 3357 |
size >>= 1; |
| 3358 |
break; |
| 3359 |
case MT_DATA_LEVEL::FULL: |
| 3360 |
default: |
| 3361 |
break; |
| 3362 |
} |
| 3363 |
|
| 3364 |
size = size < LEVEL0_SIZE ? LEVEL0_SIZE : size; |
| 3365 |
} |
| 3366 |
|
| 3367 |
MosUtilities::MosTraceDataDump(pcName, flags, pBuf, size); |
| 3368 |
} |
| 3369 |
|
| 3370 |
//! |
| 3371 |
//! \def MOS_TraceData new trace interface, special interface for zero trace data |
| 3372 |
//! |
| 3373 |
#define MOS_TraceData0(usId, usType) \ |
| 3374 |
MosUtilities::MosTraceEvent(usId, usType, nullptr, 0, nullptr, 0); |
| 3375 |
|
| 3376 |
#define MOS_TraceData(usId, usType, ...) \ |
| 3377 |
{ \ |
| 3378 |
TR_FILL_PARAM(__VA_ARGS__); \ |
| 3379 |
TR_WRITE_PARAM(MosUtilities::MosTraceEvent, usId, usType); \ |
| 3380 |
} |
| 3381 |
|
| 3382 |
class PerfUtility |
| 3383 |
{ |
| 3384 |
public: |
| 3385 |
struct Tick |
| 3386 |
{ |
| 3387 |
double freq; |
| 3388 |
int64_t start; |
| 3389 |
int64_t stop; |
| 3390 |
double time; |
| 3391 |
}; |
| 3392 |
struct PerfInfo |
| 3393 |
{ |
| 3394 |
uint32_t count; |
| 3395 |
double avg; |
| 3396 |
double max; |
| 3397 |
double min; |
| 3398 |
}; |
| 3399 |
|
| 3400 |
public: |
| 3401 |
static PerfUtility *getInstance(); |
| 3402 |
virtual ~PerfUtility(); |
| 3403 |
PerfUtility(); |
| 3404 |
virtual void startTick(std::string tag); |
| 3405 |
virtual void stopTick(std::string tag); |
| 3406 |
virtual void savePerfData(); |
| 3407 |
virtual void setupFilePath(const char *perfFilePath); |
| 3408 |
virtual void setupFilePath(); |
| 3409 |
bool bPerfUtilityKey = false; |
| 3410 |
char sSummaryFileName[MOS_MAX_PERF_FILENAME_LEN + 1] = {'\0'}; |
| 3411 |
char sDetailsFileName[MOS_MAX_PERF_FILENAME_LEN + 1] = {'\0'}; |
| 3412 |
int32_t dwPerfUtilityIsEnabled = false; |
| 3413 |
|
| 3414 |
private: |
| 3415 |
void printPerfSummary(); |
| 3416 |
void printPerfDetails(); |
| 3417 |
void printHeader(std::ofstream& fout); |
| 3418 |
void printBody(std::ofstream& fout); |
| 3419 |
void printFooter(std::ofstream& fout); |
| 3420 |
std::string formatPerfData(std::string tag, std::vector<Tick>& record); |
| 3421 |
void getPerfInfo(std::vector<Tick>& record, PerfInfo* info); |
| 3422 |
std::string getDashString(uint32_t num); |
| 3423 |
|
| 3424 |
private: |
| 3425 |
static std::shared_ptr<PerfUtility> instance; |
| 3426 |
static std::mutex perfMutex; |
| 3427 |
std::map<std::string, std::vector<Tick>*> records {}; |
| 3428 |
MEDIA_CLASS_DEFINE_END(PerfUtility) |
| 3429 |
}; |
| 3430 |
|
| 3431 |
#endif // __MOS_UTILITIES_H__ |