| 1 |
/* |
| 2 |
* Copyright (c) 2018-2025, 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 |
#ifndef __DECODE_UTILS_H__ |
| 23 |
#define __DECODE_UTILS_H__ |
| 24 |
#include <mutex> |
| 25 |
#include "mos_util_debug.h" |
| 26 |
#include "mos_utilities.h" |
| 27 |
#include "media_class_trace.h" |
| 28 |
#include "media_user_setting.h" |
| 29 |
|
| 30 |
//------------------------------------------------------------------------------ |
| 31 |
// Macros specific to MOS_CODEC_SUBCOMP_DECODE sub-comp |
| 32 |
//------------------------------------------------------------------------------ |
| 33 |
#define DECODE_ASSERT(_expr) \ |
| 34 |
MOS_ASSERT(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _expr) |
| 35 |
|
| 36 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 37 |
#define DECODE_ASSERTMESSAGE(_message, ...) \ |
| 38 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _message, ##__VA_ARGS__) |
| 39 |
#else |
| 40 |
#define DECODE_ASSERTMESSAGE(_message, ...) \ |
| 41 |
OcaOnMosCriticalMessage(MOS_FUNCTION, __LINE__); |
| 42 |
#endif |
| 43 |
|
| 44 |
#define DECODE_WARNINGMESSAGE(_message, ...) \ |
| 45 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _message, ##__VA_ARGS__) |
| 46 |
|
| 47 |
#define DECODE_NORMALMESSAGE(_message, ...) \ |
| 48 |
MOS_NORMALMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _message, ##__VA_ARGS__) |
| 49 |
|
| 50 |
#define DECODE_VERBOSEMESSAGE(_message, ...) \ |
| 51 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _message, ##__VA_ARGS__) |
| 52 |
|
| 53 |
#define DECODE_CHK_NULL(_ptr) \ |
| 54 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _ptr) |
| 55 |
|
| 56 |
#define DECODE_CHK_STATUS(_stmt) \ |
| 57 |
MOS_CHK_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _stmt) |
| 58 |
|
| 59 |
#define DECODE_CHK_STATUS_MESSAGE(_stmt, _message, ...) \ |
| 60 |
MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _stmt, _message, ##__VA_ARGS__) |
| 61 |
|
| 62 |
#define DECODE_CHK_COND(_expr, _message, ...) \ |
| 63 |
MOS_CHK_COND_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE,_expr,_message, ##__VA_ARGS__) |
| 64 |
|
| 65 |
#define DECODE_CHK_NULL_NO_STATUS_RETURN(_ptr) \ |
| 66 |
MOS_CHK_NULL_NO_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_DECODE, _ptr) |
| 67 |
|
| 68 |
namespace decode { |
| 69 |
|
| 70 |
class Trace |
| 71 |
{ |
| 72 |
public: |
| 73 |
Trace(const char* name) : m_name(name) |
| 74 |
{ |
| 75 |
DECODE_VERBOSEMESSAGE("Enter function:%s\r\n", name); |
| 76 |
} |
| 77 |
|
| 78 |
~Trace() |
| 79 |
{ |
| 80 |
DECODE_VERBOSEMESSAGE("Exit function:%s\r\n", m_name); |
| 81 |
} |
| 82 |
|
| 83 |
protected: |
| 84 |
const char* m_name; |
| 85 |
}; |
| 86 |
|
| 87 |
class Mutex |
| 88 |
{ |
| 89 |
public: |
| 90 |
Mutex() |
| 91 |
{ |
| 92 |
m_mutex = MosUtilities::MosCreateMutex(); |
| 93 |
DECODE_ASSERT(m_mutex != nullptr); |
| 94 |
} |
| 95 |
~Mutex() |
| 96 |
{ |
| 97 |
MosUtilities::MosDestroyMutex(m_mutex); |
| 98 |
} |
| 99 |
PMOS_MUTEX Get() |
| 100 |
{ |
| 101 |
return m_mutex; |
| 102 |
} |
| 103 |
|
| 104 |
//forbidden mutex transfer |
| 105 |
Mutex(const Mutex&) = delete; |
| 106 |
Mutex& operator=(const Mutex&) = delete; |
| 107 |
|
| 108 |
protected: |
| 109 |
PMOS_MUTEX m_mutex; |
| 110 |
MEDIA_CLASS_DEFINE_END(decode__Mutex) |
| 111 |
}; |
| 112 |
|
| 113 |
class AutoLock |
| 114 |
{ |
| 115 |
public: |
| 116 |
AutoLock(Mutex &mutex) : m_mutex(mutex) { MosUtilities::MosLockMutex(m_mutex.Get()); } |
| 117 |
~AutoLock() { MosUtilities::MosUnlockMutex(m_mutex.Get()); } |
| 118 |
protected: |
| 119 |
Mutex &m_mutex; |
| 120 |
MEDIA_CLASS_DEFINE_END(decode__AutoLock) |
| 121 |
}; |
| 122 |
|
| 123 |
class Condition |
| 124 |
{ |
| 125 |
public: |
| 126 |
Condition() |
| 127 |
{ |
| 128 |
m_sem = MosUtilities::MosCreateSemaphore(0, 1); |
| 129 |
} |
| 130 |
|
| 131 |
~Condition() |
| 132 |
{ |
| 133 |
MosUtilities::MosDestroySemaphore(m_sem); |
| 134 |
} |
| 135 |
MOS_STATUS Wait(PMOS_MUTEX mutex) |
| 136 |
{ |
| 137 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 138 |
MosUtilities::MosUnlockMutex(mutex); |
| 139 |
status = MosUtilities::MosWaitSemaphore(m_sem, 5000); |
| 140 |
MosUtilities::MosLockMutex(mutex); |
| 141 |
return status; |
| 142 |
} |
| 143 |
MOS_STATUS Signal() |
| 144 |
{ |
| 145 |
MosUtilities::MosPostSemaphore(m_sem, 1); |
| 146 |
return MOS_STATUS_SUCCESS; |
| 147 |
} |
| 148 |
|
| 149 |
protected: |
| 150 |
PMOS_SEMAPHORE m_sem; |
| 151 |
MEDIA_CLASS_DEFINE_END(decode__Condition) |
| 152 |
}; |
| 153 |
|
| 154 |
//! |
| 155 |
//! \brief Allocate data list with specific type and length |
| 156 |
//! |
| 157 |
//! \param [in,out] dataList |
| 158 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 159 |
//! \param [in] length |
| 160 |
//! Specify the number of data members |
| 161 |
//! |
| 162 |
//! \return MOS_STATUS |
| 163 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 164 |
//! |
| 165 |
template <class type> |
| 166 |
MOS_STATUS AllocateDataList(type **dataList, uint32_t length) |
| 167 |
{ |
| 168 |
type *ptr; |
| 169 |
ptr = (type *)MOS_AllocAndZeroMemory(sizeof(type) * length); |
| 170 |
if (ptr == nullptr) |
| 171 |
{ |
| 172 |
DECODE_ASSERTMESSAGE("No memory to allocate CodecHal data list."); |
| 173 |
return MOS_STATUS_NO_SPACE; |
| 174 |
} |
| 175 |
for (uint32_t i = 0; i < length; i++) |
| 176 |
{ |
| 177 |
dataList[i] = &(ptr[i]); |
| 178 |
} |
| 179 |
return MOS_STATUS_SUCCESS; |
| 180 |
} |
| 181 |
|
| 182 |
//! |
| 183 |
//! \brief Free data list |
| 184 |
//! |
| 185 |
//! \param [in,out] dataList |
| 186 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 187 |
//! \param [in] length |
| 188 |
//! Specify the number of data members |
| 189 |
//! |
| 190 |
//! \return MOS_STATUS |
| 191 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 192 |
//! |
| 193 |
template <class type> |
| 194 |
MOS_STATUS FreeDataList(type **dataList, uint32_t length) |
| 195 |
{ |
| 196 |
type* ptr; |
| 197 |
ptr = dataList[0]; |
| 198 |
if (ptr) |
| 199 |
{ |
| 200 |
MOS_FreeMemory(ptr); |
| 201 |
} |
| 202 |
for (uint32_t i = 0; i < length; i++) |
| 203 |
{ |
| 204 |
dataList[i] = nullptr; |
| 205 |
} |
| 206 |
|
| 207 |
return MOS_STATUS_SUCCESS; |
| 208 |
} |
| 209 |
|
| 210 |
inline MediaUserSetting::Value ReadUserFeature(MediaUserSettingSharedPtr m_userSettingPtr, std::string name, MediaUserSetting::Group userSettingGroup) |
| 211 |
{ |
| 212 |
MediaUserSetting::Value outValue; |
| 213 |
MOS_STATUS s_status = ReadUserSetting( |
| 214 |
m_userSettingPtr, |
| 215 |
outValue, |
| 216 |
name, |
| 217 |
userSettingGroup); |
| 218 |
return outValue; //open: how to check read user setting results. |
| 219 |
} |
| 220 |
|
| 221 |
} |
| 222 |
|
| 223 |
#define DECODE_FUNC_CALL() decode::Trace trace(__FUNCTION__); |
| 224 |
|
| 225 |
#endif // !__DECODE_UTILS_H__ |