| 1 |
/* |
| 2 |
* Copyright (c) 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 codec_utilities_next.h |
| 24 |
//! \brief Defines the common functions for codec. |
| 25 |
//! \details This modules implements utilities which are shared by encoder and decoder |
| 26 |
//! |
| 27 |
|
| 28 |
#ifndef __CODEC_UTILITIES_NEXT_H__ |
| 29 |
#define __CODEC_UTILITIES_NEXT_H__ |
| 30 |
#include "mos_defs.h" |
| 31 |
#include "mos_os_specific.h" |
| 32 |
#include "codec_hw_next.h" |
| 33 |
|
| 34 |
#define CODECHAL_SURFACE_PITCH_ALIGNMENT 128 |
| 35 |
class CodecUtilities |
| 36 |
{ |
| 37 |
public: |
| 38 |
//! |
| 39 |
//! \brief Allocate data list with specific type and length |
| 40 |
//! |
| 41 |
//! \param [in,out] dataList |
| 42 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 43 |
//! \param [in] length |
| 44 |
//! Specify the number of data members |
| 45 |
//! |
| 46 |
//! \return MOS_STATUS |
| 47 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 48 |
//! |
| 49 |
template <class type> |
| 50 |
static MOS_STATUS CodecHalAllocateDataList(type **dataList, uint32_t length) |
| 51 |
{ |
| 52 |
type *ptr; |
| 53 |
ptr = (type *)MOS_AllocAndZeroMemory(sizeof(type) * length); |
| 54 |
if (ptr == nullptr) |
| 55 |
{ |
| 56 |
CODECHAL_PUBLIC_ASSERTMESSAGE("No memory to allocate CodecHal data list."); |
| 57 |
return MOS_STATUS_NO_SPACE; |
| 58 |
} |
| 59 |
for (uint32_t i = 0; i < length; i++) |
| 60 |
{ |
| 61 |
dataList[i] = &(ptr[i]); |
| 62 |
} |
| 63 |
return MOS_STATUS_SUCCESS; |
| 64 |
} |
| 65 |
|
| 66 |
//! |
| 67 |
//! \brief Free data list |
| 68 |
//! |
| 69 |
//! \param [in,out] dataList |
| 70 |
//! Pointer to a type * pointer. Specify the address of the memory handles |
| 71 |
//! \param [in] length |
| 72 |
//! Specify the number of data members |
| 73 |
//! |
| 74 |
//! \return MOS_STATUS |
| 75 |
//! MOS_STATUS_SUCCESS if success, else fail reason |
| 76 |
//! |
| 77 |
template <class type> |
| 78 |
static MOS_STATUS CodecHalFreeDataList(type **dataList, uint32_t length) |
| 79 |
{ |
| 80 |
type *ptr; |
| 81 |
ptr = dataList[0]; |
| 82 |
if (ptr) |
| 83 |
{ |
| 84 |
MOS_FreeMemory(ptr); |
| 85 |
} |
| 86 |
for (uint32_t i = 0; i < length; i++) |
| 87 |
{ |
| 88 |
dataList[i] = nullptr; |
| 89 |
} |
| 90 |
|
| 91 |
return MOS_STATUS_SUCCESS; |
| 92 |
} |
| 93 |
|
| 94 |
static MOS_STATUS CodecHalGetResourceInfo( |
| 95 |
PMOS_INTERFACE osInterface, |
| 96 |
PMOS_SURFACE surface) |
| 97 |
{ |
| 98 |
CODECHAL_PUBLIC_CHK_NULL_RETURN(surface); |
| 99 |
|
| 100 |
MOS_SURFACE details; |
| 101 |
MOS_ZeroMemory(&details, sizeof(details)); |
| 102 |
details.Format = Format_Invalid; |
| 103 |
|
| 104 |
CODECHAL_PUBLIC_CHK_STATUS_RETURN(osInterface->pfnGetResourceInfo(osInterface, &surface->OsResource, &details)); |
| 105 |
|
| 106 |
surface->Format = details.Format; |
| 107 |
surface->dwWidth = details.dwWidth; |
| 108 |
surface->dwHeight = details.dwHeight; |
| 109 |
surface->dwPitch = details.dwPitch; |
| 110 |
surface->dwDepth = details.dwDepth; |
| 111 |
surface->dwQPitch = details.dwQPitch; |
| 112 |
surface->bArraySpacing = details.bArraySpacing; |
| 113 |
surface->TileType = details.TileType; |
| 114 |
surface->TileModeGMM = details.TileModeGMM; |
| 115 |
surface->bGMMTileEnabled = details.bGMMTileEnabled; |
| 116 |
surface->dwOffset = details.RenderOffset.YUV.Y.BaseOffset; |
| 117 |
surface->YPlaneOffset.iSurfaceOffset = details.RenderOffset.YUV.Y.BaseOffset; |
| 118 |
surface->YPlaneOffset.iXOffset = details.RenderOffset.YUV.Y.XOffset; |
| 119 |
surface->YPlaneOffset.iYOffset = |
| 120 |
(surface->YPlaneOffset.iSurfaceOffset - surface->dwOffset) / surface->dwPitch + |
| 121 |
details.RenderOffset.YUV.Y.YOffset; |
| 122 |
surface->UPlaneOffset.iSurfaceOffset = details.RenderOffset.YUV.U.BaseOffset; |
| 123 |
surface->UPlaneOffset.iXOffset = details.RenderOffset.YUV.U.XOffset; |
| 124 |
surface->UPlaneOffset.iYOffset = |
| 125 |
(surface->UPlaneOffset.iSurfaceOffset - surface->dwOffset) / surface->dwPitch + |
| 126 |
details.RenderOffset.YUV.U.YOffset; |
| 127 |
surface->UPlaneOffset.iLockSurfaceOffset = details.LockOffset.YUV.U; |
| 128 |
surface->VPlaneOffset.iSurfaceOffset = details.RenderOffset.YUV.V.BaseOffset; |
| 129 |
surface->VPlaneOffset.iXOffset = details.RenderOffset.YUV.V.XOffset; |
| 130 |
surface->VPlaneOffset.iYOffset = |
| 131 |
(surface->VPlaneOffset.iSurfaceOffset - surface->dwOffset) / surface->dwPitch + |
| 132 |
details.RenderOffset.YUV.V.YOffset; |
| 133 |
surface->VPlaneOffset.iLockSurfaceOffset = details.LockOffset.YUV.V; |
| 134 |
surface->bCompressible = details.bCompressible; |
| 135 |
surface->CompressionMode = details.CompressionMode; |
| 136 |
surface->bIsCompressed = details.bIsCompressed; |
| 137 |
|
| 138 |
return MOS_STATUS_SUCCESS; |
| 139 |
} |
| 140 |
MEDIA_CLASS_DEFINE_END(CodecUtilities) |
| 141 |
}; |
| 142 |
|
| 143 |
#endif |