1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344
|
/*############################################################################
# Copyright (C) 2005 Intel Corporation
#
# SPDX-License-Identifier: MIT
############################################################################*/
#ifndef __SAMPLE_DEFS_H__
#define __SAMPLE_DEFS_H__
#include <memory.h>
#include <algorithm>
#include <iostream>
#include "vm/file_defs.h"
#include "vm/strings_defs.h"
#include "vm/time_defs.h"
#include "vpl/mfxdefs.h"
inline const char* path_to_name(const char* path, char delim) {
const char* last_delim = strrchr(path, '\\');
if (last_delim && *last_delim) {
return last_delim + 1;
}
else {
return path;
}
}
#if defined(WIN32) || defined(WIN64)
#define __FILENAME__ path_to_name(__FILE__, '\\')
#else
#define __FILENAME__ path_to_name(__FILE__, '/')
#endif
// Run-time HSBC
#if (MFX_VERSION >= MFX_VERSION_NEXT)
#define ENABLE_VPP_RUNTIME_HSBC
#endif
#define ENABLE_MCTF
enum { MCTF_BITRATE_MULTIPLIER = 100000 };
#if defined(_WIN32) || defined(_WIN64)
enum {
MFX_HANDLE_DEVICEWINDOW = 0x101 /* A handle to the render window */
}; //mfxHandleType
#ifndef D3D_SURFACES_SUPPORT
#define D3D_SURFACES_SUPPORT 1
#endif
#if defined(_WIN32) && !defined(MFX_D3D11_SUPPORT)
#include <sdkddkver.h>
#if (NTDDI_VERSION >= NTDDI_VERSION_FROM_WIN32_WINNT2(0x0602)) // >= _WIN32_WINNT_WIN8
#define MFX_D3D11_SUPPORT 1 // Enable D3D11 support if SDK allows
#else
#define MFX_D3D11_SUPPORT 0
#endif
#endif // #if defined(_WIN32) && !defined(MFX_D3D11_SUPPORT)
#endif // #if defined(_WIN32) || defined(_WIN64)
enum {
#define __DECLARE(type) MFX_MONITOR_##type
__DECLARE(Unknown) = 0,
__DECLARE(AUTO) = __DECLARE(Unknown),
__DECLARE(VGA),
__DECLARE(DVII),
__DECLARE(DVID),
__DECLARE(DVIA),
__DECLARE(Composite),
__DECLARE(SVIDEO),
__DECLARE(LVDS),
__DECLARE(Component),
__DECLARE(9PinDIN),
__DECLARE(HDMIA),
__DECLARE(HDMIB),
__DECLARE(eDP),
__DECLARE(TV),
__DECLARE(DisplayPort),
#if defined(DRM_MODE_CONNECTOR_VIRTUAL) // from libdrm 2.4.59
__DECLARE(VIRTUAL),
#endif
#if defined(DRM_MODE_CONNECTOR_DSI) // from libdrm 2.4.59
__DECLARE(DSI),
#endif
__DECLARE(MAXNUMBER)
#undef __DECLARE
};
#if defined(LIBVA_SUPPORT)
enum LibVABackend {
MFX_LIBVA_AUTO,
MFX_LIBVA_DRM,
MFX_LIBVA_DRM_RENDERNODE = MFX_LIBVA_DRM,
MFX_LIBVA_DRM_MODESET,
MFX_LIBVA_X11,
MFX_LIBVA_WAYLAND,
MFX_LIBVA_GTK
};
#endif
//affects win32 winnt version macro
#include "sample_utils.h"
#include "vm/time_defs.h"
#define MSDK_DEC_WAIT_INTERVAL 300000
#define MSDK_ENC_WAIT_INTERVAL 300000
#define MSDK_VPP_WAIT_INTERVAL 300000
#define MSDK_SURFACE_WAIT_INTERVAL 300000
#define MSDK_WAIT_INTERVAL \
(MSDK_DEC_WAIT_INTERVAL + 3 * MSDK_VPP_WAIT_INTERVAL + \
MSDK_ENC_WAIT_INTERVAL) // an estimate for the longest pipeline we have in samples
#define MSDK_INVALID_SURF_IDX 0xFFFF
#define MSDK_MAX_FILENAME_LEN 1024
#define MSDK_MAX_USER_DATA_UNREG_SEI_LEN 80
#define MSDK_PRINT_RET_MSG(ERR, MSG) \
{ \
std::stringstream tmpStr1; \
tmpStr1 << std::endl \
<< "[ERROR], sts=" << StatusToString(ERR) << "(" << ERR << ")" \
<< ", " << __FUNCTION__ << ", " << MSG << " at " << __FILENAME__ << ":" \
<< __LINE__ << std::endl; \
std::cerr << tmpStr1.str(); \
}
#define MSDK_PRINT_WRN_MSG(WRN, MSG) \
{ \
std::stringstream tmpStr1; \
tmpStr1 << std::endl \
<< "[WARNING], sts=" << StatusToString(WRN) << "(" << WRN << ")" \
<< ", " << __FUNCTION__ << ", " << MSG << " at " << __FILENAME__ << ":" \
<< __LINE__ << std::endl; \
std::cerr << tmpStr1.str(); \
}
#define MSDK_TRACE_LEVEL(level, ERR) \
if (level <= msdk_trace_get_level()) { \
std::cerr << __FILENAME__ << " :" << __LINE__ << " [" << level << "] " << ERR \
<< std::endl; \
}
#define MSDK_TRACE_CRITICAL(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_CRITICAL, ERR)
#define MSDK_TRACE_ERROR(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_ERROR, ERR)
#define MSDK_TRACE_WARNING(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_WARNING, ERR)
#define MSDK_TRACE_INFO(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_INFO, ERR)
#define MSDK_TRACE_DEBUG(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_DEBUG, ERR)
#define MSDK_CHECK_ERROR(P, X, ERR) \
{ \
if ((X) == (P)) { \
std::stringstream tmpStr2; \
tmpStr2 << #X << "==" << #P << " error"; \
MSDK_PRINT_RET_MSG(ERR, tmpStr2.str().c_str()); \
return ERR; \
} \
}
#define MSDK_CHECK_NOT_EQUAL(P, X, ERR) \
{ \
if ((X) != (P)) { \
std::stringstream tmpStr3; \
tmpStr3 << #X << "!=" << #P << " error"; \
MSDK_PRINT_RET_MSG(ERR, tmpStr3.str().c_str()); \
return ERR; \
} \
}
#define MSDK_CHECK_STATUS(X, MSG) \
{ \
if ((X) < MFX_ERR_NONE) { \
MSDK_PRINT_RET_MSG(X, MSG); \
return X; \
} \
}
#define MSDK_CHECK_STATUS_NO_RET(X, MSG) \
{ \
if ((X) < MFX_ERR_NONE) { \
MSDK_PRINT_RET_MSG(X, MSG); \
} \
}
#define MSDK_CHECK_WRN(X, MSG) \
{ \
if ((X) > MFX_ERR_NONE) { \
MSDK_PRINT_WRN_MSG(X, MSG); \
} \
}
#define MSDK_CHECK_ERR_NONE_STATUS(X, ERR, MSG) \
{ \
if ((X) != MFX_ERR_NONE) { \
MSDK_PRINT_RET_MSG(X, MSG); \
return ERR; \
} \
}
#define MSDK_CHECK_ERR_NONE_STATUS_NO_RET(X, MSG) \
{ \
if ((X) != MFX_ERR_NONE) { \
MSDK_PRINT_RET_MSG(X, MSG); \
} \
}
#define MSDK_CHECK_NOERROR_STATUS_NO_RET(X, MSG) \
{ \
if ((X) != MFX_ERR_NONE && (X) != MFX_ERR_NONE_PARTIAL_OUTPUT) { \
MSDK_PRINT_RET_MSG(X, MSG); \
} \
}
#define MSDK_CHECK_PARSE_RESULT(P, X, ERR) \
{ \
if ((X) > (P)) { \
return ERR; \
} \
}
#define MSDK_CHECK_STATUS_SAFE(X, FUNC, ADD) \
{ \
if ((X) < MFX_ERR_NONE) { \
ADD; \
MSDK_PRINT_RET_MSG(X, FUNC); \
return X; \
} \
}
#define MSDK_IGNORE_MFX_STS(P, X) \
{ \
if ((X) == (P)) { \
P = MFX_ERR_NONE; \
} \
}
#define MSDK_CHECK_POINTER(P, ...) \
{ \
if (!(P)) { \
std::stringstream tmpStr4; \
tmpStr4 << #P << " pointer is NULL"; \
MSDK_PRINT_RET_MSG(MFX_ERR_NULL_PTR, tmpStr4.str().c_str()); \
return __VA_ARGS__; \
} \
}
#define MSDK_CHECK_POINTER_NO_RET(P) \
{ \
if (!(P)) { \
std::stringstream tmpStr4; \
tmpStr4 << #P << " pointer is NULL"; \
MSDK_PRINT_RET_MSG(MFX_ERR_NULL_PTR, tmpStr4.str().c_str()); \
return; \
} \
}
#define MSDK_CHECK_POINTER_SAFE(P, ERR, ADD) \
{ \
if (!(P)) { \
ADD; \
return ERR; \
} \
}
#define MSDK_BREAK_ON_ERROR(P) \
{ \
if (MFX_ERR_NONE != (P)) \
break; \
}
#define MSDK_SAFE_DELETE_ARRAY(P) \
{ \
if (P) { \
delete[] P; \
P = NULL; \
} \
}
#define MSDK_SAFE_RELEASE(X) \
{ \
if (X) { \
X->Release(); \
X = NULL; \
} \
}
#define MSDK_SAFE_FREE(X) \
{ \
if (X) { \
free(X); \
X = NULL; \
} \
}
#ifndef MSDK_SAFE_DELETE
#define MSDK_SAFE_DELETE(P) \
{ \
if (P) { \
delete P; \
P = NULL; \
} \
}
#endif // MSDK_SAFE_DELETE
#define MSDK_ZERO_MEMORY(VAR) \
{ memset(&VAR, 0, sizeof(VAR)); }
#define MSDK_ALIGN16(value) (((value + 15) >> 4) << 4) // round up to a multiple of 16
#define MSDK_ALIGN32(value) (((value + 31) >> 5) << 5) // round up to a multiple of 32
#define MSDK_ALIGN(value, alignment) \
(alignment) * ((value) / (alignment) + (((value) % (alignment)) ? 1 : 0))
#define MSDK_ARRAY_LEN(value) (sizeof(value) / sizeof(value[0]))
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(par) std::ignore = par;
#endif
#define MFX_IMPL_VIA_MASK(x) (0x0f00 & (x))
// Deprecated
#define MSDK_PRINT_RET_MSG_(ERR) \
{ printf("\nReturn on error: error code %d,\t%s\t%d\n\n", (int)ERR, __FILENAME__, __LINE__); }
#define MSDK_CHECK_RESULT(P, X, ERR) \
{ \
if ((X) > (P)) { \
MSDK_PRINT_RET_MSG_(ERR); \
return ERR; \
} \
}
#define MSDK_CHECK_RESULT_SAFE(P, X, ERR, ADD) \
{ \
if ((X) > (P)) { \
ADD; \
MSDK_PRINT_RET_MSG_(ERR); \
return ERR; \
} \
}
namespace mfx {
// TODO: switch to std::clamp when C++17 support will be enabled
// Clip value v to range [lo, hi]
template <class T>
constexpr const T& clamp(const T& v, const T& lo, const T& hi) {
return std::min(hi, std::max(v, lo));
}
// Comp is comparison function object with meaning of 'less' operator (i.e. std::less<> or operator<)
template <class T, class Compare>
constexpr const T& clamp(const T& v, const T& lo, const T& hi, Compare comp) {
return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
}
} // namespace mfx
#endif //__SAMPLE_DEFS_H__
|