| 1 |
/* |
| 2 |
* Copyright (c) 2018-2021, Intel Corporation |
| 3 |
* |
| 4 |
* Permission is hereby granted, free of charge, to any person obtaining a |
| 5 |
* copy of this software and associated documentation files (the "Software"), |
| 6 |
* to deal in the Software without restriction, including without limitation |
| 7 |
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 |
* and/or sell copies of the Software, and to permit persons to whom the |
| 9 |
* Software is furnished to do so, subject to the following conditions: |
| 10 |
* |
| 11 |
* The above copyright notice and this permission notice shall be included |
| 12 |
* in all copies or substantial portions of the Software. |
| 13 |
* |
| 14 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 15 |
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 |
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 |
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 21 |
*/ |
| 22 |
#ifndef __ENCODE_UTILS_H__ |
| 23 |
#define __ENCODE_UTILS_H__ |
| 24 |
#include <mutex> |
| 25 |
#include "mos_util_debug.h" |
| 26 |
#include "mos_utilities.h" |
| 27 |
|
| 28 |
#define _SW_BRC _MEDIA_RESERVED && (_DEBUG || _RELEASE_INTERNAL) |
| 29 |
#define _SW_HUC _MEDIA_RESERVED && (_DEBUG || _RELEASE_INTERNAL) |
| 30 |
#define _KERNEL_RESERVED _MEDIA_RESERVED && ENABLE_KERNELS |
| 31 |
|
| 32 |
enum HuCFunction |
| 33 |
{ |
| 34 |
NONE_BRC = 0, |
| 35 |
BRC_INIT, |
| 36 |
BRC_RESET, |
| 37 |
BRC_UPDATE, |
| 38 |
LA_INIT, |
| 39 |
LA_RESET, |
| 40 |
LA_UPDATE, |
| 41 |
PAK_INTEGRATE, |
| 42 |
HPU_VP9, |
| 43 |
SLBB_UPDATE |
| 44 |
}; |
| 45 |
|
| 46 |
//------------------------------------------------------------------------------ |
| 47 |
// Macros specific to MOS_CODEC_SUBCOMP_ENCODE sub-comp |
| 48 |
//------------------------------------------------------------------------------ |
| 49 |
#define ENCODE_ASSERT(_expr) \ |
| 50 |
MOS_ASSERT(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _expr) |
| 51 |
|
| 52 |
#if (_DEBUG || _RELEASE_INTERNAL) |
| 53 |
#define ENCODE_ASSERTMESSAGE(_message, ...) \ |
| 54 |
MOS_ASSERTMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__) |
| 55 |
#else |
| 56 |
#define ENCODE_ASSERTMESSAGE(_message, ...) \ |
| 57 |
OcaOnMosCriticalMessage(MOS_FUNCTION, __LINE__); |
| 58 |
#endif |
| 59 |
|
| 60 |
#define ENCODE_WARNINGMESSAGE(_message, ...) \ |
| 61 |
MOS_WARNINGMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__) |
| 62 |
|
| 63 |
#define ENCODE_NORMALMESSAGE(_message, ...) \ |
| 64 |
MOS_NORMALMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__) |
| 65 |
|
| 66 |
#define ENCODE_VERBOSEMESSAGE(_message, ...) \ |
| 67 |
MOS_VERBOSEMESSAGE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _message, ##__VA_ARGS__) |
| 68 |
|
| 69 |
#define ENCODE_CHK_NULL_RETURN(_ptr) \ |
| 70 |
MOS_CHK_NULL_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _ptr) |
| 71 |
|
| 72 |
#define ENCODE_CHK_NULL_NO_STATUS_RETURN(_ptr) \ |
| 73 |
MOS_CHK_NULL_NO_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _ptr) |
| 74 |
|
| 75 |
#define ENCODE_CHK_STATUS_RETURN(_stmt) \ |
| 76 |
MOS_CHK_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt) |
| 77 |
|
| 78 |
#define ENCODE_CHK_STATUS_NO_STATUS_RETURN(_stmt) \ |
| 79 |
MOS_CHK_STATUS_NO_STATUS_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt) |
| 80 |
|
| 81 |
#define ENCODE_CHK_COND_RETURN(_stmt, _message, ...) \ |
| 82 |
MOS_CHK_COND_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt, _message, ##__VA_ARGS__) |
| 83 |
|
| 84 |
#define ENCODE_CHK_STATUS_MESSAGE_RETURN(_stmt, _message, ...) \ |
| 85 |
MOS_CHK_STATUS_MESSAGE_RETURN(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, _stmt, _message, ##__VA_ARGS__) |
| 86 |
|
| 87 |
#define ENCODE_CHK_NULL_WITH_DESTROY_RETURN_VALUE(_ptr, destroyFunction) \ |
| 88 |
MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, (nullptr == _ptr), destroyFunction, MOS_STATUS_NULL_POINTER, "error nullptr!") |
| 89 |
|
| 90 |
#define ENCODE_CHK_STATUS_WITH_DESTROY_RETURN_VALUE(_stmt, destroyFunction) \ |
| 91 |
{ \ |
| 92 |
MOS_STATUS sts = (MOS_STATUS)(_stmt); \ |
| 93 |
MOS_CHK_COND_WITH_DESTROY_RETURN_VALUE(MOS_COMPONENT_CODEC, MOS_CODEC_SUBCOMP_ENCODE, (MOS_STATUS_SUCCESS != sts), destroyFunction, sts, "error status!") \ |
| 94 |
} |
| 95 |
|
| 96 |
namespace encode { |
| 97 |
|
| 98 |
class Trace |
| 99 |
{ |
| 100 |
public: |
| 101 |
Trace(const char* name) : m_name(name) |
| 102 |
{ |
| 103 |
ENCODE_VERBOSEMESSAGE("Enter function:%s\r\n", name); |
| 104 |
} |
| 105 |
|
| 106 |
~Trace() |
| 107 |
{ |
| 108 |
ENCODE_VERBOSEMESSAGE("Exit function:%s\r\n", m_name); |
| 109 |
} |
| 110 |
|
| 111 |
protected: |
| 112 |
const char* m_name; |
| 113 |
}; |
| 114 |
|
| 115 |
class AutoLock |
| 116 |
{ |
| 117 |
public: |
| 118 |
AutoLock(PMOS_MUTEX mutex) : m_mutex(mutex) { MosUtilities::MosLockMutex(mutex); } |
| 119 |
~AutoLock() { MosUtilities::MosUnlockMutex(m_mutex); } |
| 120 |
protected: |
| 121 |
PMOS_MUTEX m_mutex; |
| 122 |
MEDIA_CLASS_DEFINE_END(encode__AutoLock) |
| 123 |
}; |
| 124 |
|
| 125 |
class Condition |
| 126 |
{ |
| 127 |
public: |
| 128 |
Condition() |
| 129 |
{ |
| 130 |
m_sem = MosUtilities::MosCreateSemaphore(0, 1); |
| 131 |
} |
| 132 |
|
| 133 |
~Condition() |
| 134 |
{ |
| 135 |
MosUtilities::MosDestroySemaphore(m_sem); |
| 136 |
} |
| 137 |
MOS_STATUS Wait(PMOS_MUTEX mutex) |
| 138 |
{ |
| 139 |
MOS_STATUS status = MOS_STATUS_SUCCESS; |
| 140 |
MosUtilities::MosUnlockMutex(mutex); |
| 141 |
status = MosUtilities::MosWaitSemaphore(m_sem, 5000); |
| 142 |
MosUtilities::MosLockMutex(mutex); |
| 143 |
return status; |
| 144 |
} |
| 145 |
MOS_STATUS Signal() |
| 146 |
{ |
| 147 |
MosUtilities::MosPostSemaphore(m_sem, 1); |
| 148 |
return MOS_STATUS_SUCCESS; |
| 149 |
} |
| 150 |
|
| 151 |
protected: |
| 152 |
PMOS_SEMAPHORE m_sem; |
| 153 |
MEDIA_CLASS_DEFINE_END(encode__Condition) |
| 154 |
}; |
| 155 |
|
| 156 |
//! |
| 157 |
//! \brief Allocate data list with specific type and length |
| 158 |
//! |
| 159 |
//! \param [in,out] dataList |
| 160 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 161 |
//! \param [in] length |
| 162 |
//! Specify the number of data members |
| 163 |
//! |
| 164 |
//! \return MOS_STATUS |
| 165 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 166 |
//! |
| 167 |
template <class type> |
| 168 |
MOS_STATUS EncodeAllocateDataList(type **dataList, uint32_t length) |
| 169 |
{ |
| 170 |
type *ptr; |
| 171 |
ptr = (type *)MOS_AllocAndZeroMemory(sizeof(type) * length); |
| 172 |
if (ptr == nullptr) |
| 173 |
{ |
| 174 |
ENCODE_ASSERTMESSAGE("No memory to allocate CodecHal data list."); |
| 175 |
return MOS_STATUS_NO_SPACE; |
| 176 |
} |
| 177 |
for (uint32_t i = 0; i < length; i++) |
| 178 |
{ |
| 179 |
dataList[i] = &(ptr[i]); |
| 180 |
} |
| 181 |
return MOS_STATUS_SUCCESS; |
| 182 |
} |
| 183 |
|
| 184 |
//! |
| 185 |
//! \brief Free data list |
| 186 |
//! |
| 187 |
//! \param [in,out] dataList |
| 188 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 189 |
//! \param [in] length |
| 190 |
//! Specify the number of data members |
| 191 |
//! |
| 192 |
//! \return MOS_STATUS |
| 193 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 194 |
//! |
| 195 |
template <class type> |
| 196 |
MOS_STATUS EncodeFreeDataList(type **dataList, uint32_t length) |
| 197 |
{ |
| 198 |
type* ptr; |
| 199 |
ptr = dataList[0]; |
| 200 |
if (ptr) |
| 201 |
{ |
| 202 |
MOS_FreeMemory(ptr); |
| 203 |
} |
| 204 |
for (uint32_t i = 0; i < length; i++) |
| 205 |
{ |
| 206 |
dataList[i] = nullptr; |
| 207 |
} |
| 208 |
|
| 209 |
return MOS_STATUS_SUCCESS; |
| 210 |
} |
| 211 |
|
| 212 |
} |
| 213 |
|
| 214 |
#define ENCODE_FUNC_CALL() encode::Trace trace(__FUNCTION__); |
| 215 |
|
| 216 |
#endif // !__ENCODE_UTILS_H__ |