| 1 |
/* |
| 2 |
* Copyright (c) 2007-2017, 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 cm_def_os.h |
| 24 |
//! \brief Contains CM definitions |
| 25 |
//! |
| 26 |
#pragma once |
| 27 |
|
| 28 |
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor" |
| 29 |
#pragma GCC diagnostic ignored "-Wnon-virtual-dtor" |
| 30 |
|
| 31 |
#include <assert.h> |
| 32 |
#include <stdarg.h> |
| 33 |
#include <stdio.h> |
| 34 |
#include <iostream> |
| 35 |
#include <exception> |
| 36 |
#include <string.h> |
| 37 |
#include <math.h> |
| 38 |
#include <errno.h> |
| 39 |
#include <cstring> |
| 40 |
#include "dlfcn.h" |
| 41 |
#include "media_libva_cm.h" |
| 42 |
|
| 43 |
#ifndef SUCCEEDED |
| 44 |
#define SUCCEEDED(hr) (hr == VA_STATUS_SUCCESS) |
| 45 |
#endif // !SUCCEEDED |
| 46 |
|
| 47 |
#ifndef FAILED |
| 48 |
#define FAILED(hr) (hr != VA_STATUS_SUCCESS) |
| 49 |
#endif // !FAILED |
| 50 |
|
| 51 |
#define CM_DRIVER_EXPOSED __attribute__ ((visibility ("default"))) |
| 52 |
|
| 53 |
#ifdef __cplusplus |
| 54 |
#define EXTERN_C extern "C" |
| 55 |
#else |
| 56 |
#define EXTERN_C |
| 57 |
#endif |
| 58 |
|
| 59 |
static inline char * |
| 60 |
strtok_s(char *strToken, const char *strDelimit, char **context) |
| 61 |
{ |
| 62 |
return strtok_r(strToken, strDelimit, context); |
| 63 |
} |
| 64 |
|
| 65 |
inline int memcpy_s(void *dst, size_t numberOfElements, const void *src, size_t count) |
| 66 |
{ |
| 67 |
if ((dst == nullptr) || (src == nullptr)) |
| 68 |
{ |
| 69 |
return EINVAL; |
| 70 |
} |
| 71 |
if (numberOfElements < count) |
| 72 |
{ |
| 73 |
return ERANGE; |
| 74 |
} |
| 75 |
std::memcpy(dst, src, count); |
| 76 |
return 0; |
| 77 |
} |
| 78 |
|
| 79 |
#define CM_CONTEXT_DATA CM_CONTEXT |
| 80 |
#define PCM_CONTEXT_DATA PCM_CONTEXT |
| 81 |
|
| 82 |
#define CM_MAX_SURFACE2D_FORMAT_COUNT 29 |
| 83 |
#define CM_MAX_SURFACE2D_FORMAT_COUNT_INTERNAL (CM_MAX_SURFACE2D_FORMAT_COUNT-1) |
| 84 |
|
| 85 |
// max resolution for surface 2D |
| 86 |
#define CM_MAX_2D_SURF_WIDTH 16384 |
| 87 |
#define CM_MAX_2D_SURF_HEIGHT 16384 |
| 88 |
|
| 89 |
typedef enum _CM_TEXTURE_ADDRESS_TYPE |
| 90 |
{ |
| 91 |
CM_TEXTURE_ADDRESS_WRAP = 1, |
| 92 |
CM_TEXTURE_ADDRESS_MIRROR = 2, |
| 93 |
CM_TEXTURE_ADDRESS_CLAMP = 3, |
| 94 |
CM_TEXTURE_ADDRESS_BORDER = 4, |
| 95 |
CM_TEXTURE_ADDRESS_MIRRORONCE = 5 |
| 96 |
} CM_TEXTURE_ADDRESS_TYPE; |
| 97 |
|
| 98 |
typedef enum _CM_TEXTURE_FILTER_TYPE |
| 99 |
{ |
| 100 |
CM_TEXTURE_FILTER_TYPE_NONE = 0, |
| 101 |
CM_TEXTURE_FILTER_TYPE_POINT = 1, |
| 102 |
CM_TEXTURE_FILTER_TYPE_LINEAR = 2, |
| 103 |
CM_TEXTURE_FILTER_TYPE_ANISOTROPIC = 3, |
| 104 |
CM_TEXTURE_FILTER_TYPE_FLATCUBIC = 4, |
| 105 |
CM_TEXTURE_FILTER_TYPE_GAUSSIANCUBIC = 5, |
| 106 |
CM_TEXTURE_FILTER_TYPE_PYRAMIDALQUAD = 6, |
| 107 |
CM_TEXTURE_FILTER_TYPE_GAUSSIANQUAD = 7 |
| 108 |
} CM_TEXTURE_FILTER_TYPE; |
| 109 |
|
| 110 |
// From Compiler |
| 111 |
#define CM_NOINLINE __attribute__((noinline)) |
| 112 |
|
| 113 |
namespace CMRT_UMD |
| 114 |
{ |
| 115 |
class SurfaceIndex |
| 116 |
{ |
| 117 |
public: |
| 118 |
CM_NOINLINE SurfaceIndex() { index = 0; extraByte = 0; }; |
| 119 |
CM_NOINLINE SurfaceIndex(const SurfaceIndex& src) { index = src.index; extraByte = src.extraByte; }; |
| 120 |
CM_NOINLINE SurfaceIndex(const unsigned int& n) { index = n; extraByte = 0; }; |
| 121 |
CM_NOINLINE SurfaceIndex& operator = (const unsigned int& n) { this->index = n; return *this; }; |
| 122 |
CM_NOINLINE SurfaceIndex& operator + (const unsigned int& n) { this->index += n; return *this; }; |
| 123 |
CM_NOINLINE SurfaceIndex& operator= (const SurfaceIndex& other) { this->index = other.index; return *this; }; |
| 124 |
virtual unsigned int get_data(void) { return index; }; |
| 125 |
|
| 126 |
//g++ warning: class has virtual functions but non-virtual destructor |
| 127 |
virtual ~SurfaceIndex() {}; |
| 128 |
|
| 129 |
private: |
| 130 |
unsigned int index; |
| 131 |
|
| 132 |
/* |
| 133 |
* Do not delete this line: |
| 134 |
* SurfaceIndex is commonly used as CM kernel function's parameter. |
| 135 |
* It has virutal table and has copy constructor, so GNU calling convention will pass the object's pointer to kernel function. |
| 136 |
* This is different from MSVC, which always copies the entire object transferred on the callee's stack. |
| 137 |
* |
| 138 |
* Depending on the special object size after adding below "extraByte", |
| 139 |
* SetKernelArg and SetThreadArg can recognize this object and follow GNU's convention to construct kernel function's stack. |
| 140 |
*/ |
| 141 |
unsigned char extraByte; |
| 142 |
}; |
| 143 |
|
| 144 |
class SamplerIndex |
| 145 |
{ |
| 146 |
public: |
| 147 |
CM_NOINLINE SamplerIndex() { index = 0; extraByte = 0;}; |
| 148 |
CM_NOINLINE SamplerIndex(SamplerIndex& src) { index = src.get_data(); extraByte = src.extraByte; }; |
| 149 |
CM_NOINLINE SamplerIndex(const unsigned int& n) { index = n; extraByte = 0; }; |
| 150 |
CM_NOINLINE SamplerIndex& operator = (const unsigned int& n) { this->index = n; return *this; }; |
| 151 |
virtual unsigned int get_data(void) { return index; }; |
| 152 |
virtual ~SamplerIndex(){}; |
| 153 |
|
| 154 |
private: |
| 155 |
unsigned int index; |
| 156 |
|
| 157 |
/* |
| 158 |
* Do not delete this line: |
| 159 |
* Same reason as SurfaceIndex. |
| 160 |
*/ |
| 161 |
unsigned char extraByte; |
| 162 |
SamplerIndex& operator= (const SamplerIndex& other); |
| 163 |
}; |
| 164 |
} |
| 165 |
|
| 166 |
#ifndef _SYSTEMTIME_DEFINE_PROTECTOR_ |
| 167 |
#define _SYSTEMTIME_DEFINE_PROTECTOR_ |
| 168 |
typedef struct _SYSTEMTIME |
| 169 |
{ |
| 170 |
uint16_t wYear; |
| 171 |
uint16_t wMonth; |
| 172 |
uint16_t wDayOfWeek; |
| 173 |
uint16_t wDay; |
| 174 |
uint16_t wHour; |
| 175 |
uint16_t wMinute; |
| 176 |
uint16_t wSecond; |
| 177 |
uint16_t wMilliseconds; |
| 178 |
} SYSTEMTIME, *PSYSTEMTIME; |
| 179 |
|
| 180 |
inline void GetLocalTime(PSYSTEMTIME sysTime) |
| 181 |
{ |
| 182 |
time_t temp; |
| 183 |
struct tm *localTime; |
| 184 |
time(&temp); |
| 185 |
localTime=localtime(&temp); |
| 186 |
sysTime->wYear = localTime->tm_year; |
| 187 |
sysTime->wMonth = localTime->tm_mon; |
| 188 |
sysTime->wDayOfWeek = localTime->tm_wday; |
| 189 |
sysTime->wDay = localTime->tm_mday; |
| 190 |
sysTime->wHour = localTime->tm_hour; |
| 191 |
sysTime->wMinute = localTime->tm_min; |
| 192 |
sysTime->wSecond = localTime->tm_sec; |
| 193 |
sysTime->wMilliseconds = 0; |
| 194 |
} |
| 195 |
#endif |
| 196 |
|