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
|
// Copyright (c) 2017-2019 Intel Corporation
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
#ifndef _MFX_ALLOC_WRAPPER_H_
#define _MFX_ALLOC_WRAPPER_H_
#include <vector>
#include <memory> // unique_ptr
#include "mfx_common.h"
#include "umc_memory_allocator.h"
#include "umc_frame_allocator.h"
#include "umc_frame_data.h"
#include "mfxvideo++int.h"
#define MFX_UMC_MAX_ALLOC_SIZE 128
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// mfx_UMC_MemAllocator - buffer allocator
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class mfx_UMC_MemAllocator : public UMC::MemoryAllocator
{
DYNAMIC_CAST_DECL(mfx_UMC_MemAllocator, MemoryAllocator)
public:
mfx_UMC_MemAllocator(void);
virtual ~mfx_UMC_MemAllocator(void);
// Initiates object
virtual UMC::Status InitMem(UMC::MemoryAllocatorParams *pParams, VideoCORE* mfxCore);
// Closes object and releases all allocated memory
virtual UMC::Status Close();
// Allocates or reserves physical memory and return unique ID
// Sets lock counter to 0
virtual UMC::Status Alloc(UMC::MemID *pNewMemID, size_t Size, uint32_t Flags, uint32_t Align = 16);
// Lock() provides pointer from ID. If data is not in memory (swapped)
// prepares (restores) it. Increases lock counter
virtual void *Lock(UMC::MemID MID);
// Unlock() decreases lock counter
virtual UMC::Status Unlock(UMC::MemID MID);
// Notifies that the data wont be used anymore. Memory can be free
virtual UMC::Status Free(UMC::MemID MID);
// Immediately deallocates memory regardless of whether it is in use (locked) or no
virtual UMC::Status DeallocateMem(UMC::MemID MID);
protected:
VideoCORE* m_pCore;
};
enum {
mfx_UMC_ReallocAllowed = 1,
} mfx_UMC_FrameAllocator_Flags;
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// mfx_UMC_FrameAllocator
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class mfx_UMC_FrameAllocator : public UMC::FrameAllocator
{
DYNAMIC_CAST_DECL(mfx_UMC_FrameAllocator, UMC::FrameAllocator)
public:
mfx_UMC_FrameAllocator(void);
virtual ~mfx_UMC_FrameAllocator(void);
// Initiates object
virtual UMC::Status InitMfx(UMC::FrameAllocatorParams *pParams,
VideoCORE* mfxCore,
const mfxVideoParam *params,
const mfxFrameAllocRequest *request,
mfxFrameAllocResponse *response,
bool isUseExternalFrames,
bool isSWplatform);
// Closes object and releases all allocated memory
virtual UMC::Status Close();
// Allocates or reserves physical memory and returns unique ID
// Sets lock counter to 0
virtual UMC::Status Alloc(UMC::FrameMemID *pNewMemID, const UMC::VideoDataInfo * info, uint32_t flags);
virtual UMC::Status GetFrameHandle(UMC::FrameMemID memId, void * handle);
// Lock() provides pointer from ID. If data is not in memory (swapped)
// prepares (restores) it. Increases lock counter
virtual const UMC::FrameData* Lock(UMC::FrameMemID mid);
// Unlock() decreases lock counter
virtual UMC::Status Unlock(UMC::FrameMemID mid);
// Notifies that the data won't be used anymore. Memory can be freed.
virtual UMC::Status IncreaseReference(UMC::FrameMemID mid);
// Notifies that the data won't be used anymore. Memory can be freed.
virtual UMC::Status DecreaseReference(UMC::FrameMemID mid);
virtual UMC::Status Reset();
virtual mfxStatus SetCurrentMFXSurface(mfxFrameSurface1 *srf, bool isOpaq);
virtual mfxFrameSurface1* GetSurface(UMC::FrameMemID index, mfxFrameSurface1 *surface_work, const mfxVideoParam * videoPar);
virtual mfxStatus PrepareToOutput(mfxFrameSurface1 *surface_work, UMC::FrameMemID index, const mfxVideoParam * videoPar, bool isOpaq);
mfxI32 FindSurface(mfxFrameSurface1 *surf, bool isOpaq);
mfxI32 FindFreeSurface();
void SetSfcPostProcessingFlag(bool flagToSet);
void SetExternalFramesResponse(mfxFrameAllocResponse *response);
mfxFrameSurface1 * GetInternalSurface(UMC::FrameMemID index);
mfxFrameSurface1 * GetSurfaceByIndex(UMC::FrameMemID index);
mfxMemId ConvertMemId(UMC::FrameMemID index)
{
return m_frameDataInternal.GetSurface(index).Data.MemId;
};
protected:
struct surf_descr
{
surf_descr(mfxFrameSurface1* FrameSurface, bool isUsed):FrameSurface(FrameSurface),
isUsed(isUsed)
{
};
surf_descr():FrameSurface(0),
isUsed(false)
{
};
mfxFrameSurface1* FrameSurface;
bool isUsed;
};
virtual UMC::Status Free(UMC::FrameMemID mid);
virtual mfxI32 AddSurface(mfxFrameSurface1 *surface);
class InternalFrameData
{
class FrameRefInfo
{
public:
FrameRefInfo();
void Reset();
mfxU32 m_referenceCounter;
};
typedef std::pair<mfxFrameSurface1, UMC::FrameData> FrameInfo;
public:
mfxFrameSurface1 & GetSurface(mfxU32 index);
UMC::FrameData & GetFrameData(mfxU32 index);
void ResetFrameData(mfxU32 index);
mfxU32 IncreaseRef(mfxU32 index);
mfxU32 DecreaseRef(mfxU32 index);
bool IsValidMID(mfxU32 index) const;
void AddNewFrame(mfx_UMC_FrameAllocator * alloc, mfxFrameSurface1 *surface, UMC::VideoDataInfo * info);
mfxU32 GetSize() const;
void Close();
void Reset();
void Resize(mfxU32 size);
private:
std::vector<FrameInfo> m_frameData;
std::vector<FrameRefInfo> m_frameDataRefs;
};
InternalFrameData m_frameDataInternal;
std::vector<surf_descr> m_extSurfaces;
mfxI32 m_curIndex;
bool m_IsUseExternalFrames;
bool m_sfcVideoPostProcessing;
mfxFrameInfo m_surface_info; // for copying
UMC::VideoDataInfo m_info;
VideoCORE* m_pCore;
mfxFrameAllocResponse *m_externalFramesResponse;
bool m_isSWDecode;
mfxU16 m_IOPattern;
};
class mfx_UMC_FrameAllocator_D3D : public mfx_UMC_FrameAllocator
{
public:
virtual mfxStatus PrepareToOutput(mfxFrameSurface1 *surface_work, UMC::FrameMemID index, const mfxVideoParam * videoPar, bool isOpaq);
};
#if defined (MFX_ENABLE_MJPEG_VIDEO_DECODE)
class VideoVppJpegD3D9;
class mfx_UMC_FrameAllocator_D3D_Converter : public mfx_UMC_FrameAllocator_D3D
{
std::unique_ptr<VideoVppJpegD3D9> m_pCc;
mfxStatus InitVideoVppJpegD3D9(const mfxVideoParam *params);
mfxStatus FindSurfaceByMemId(const UMC::FrameData* in, bool isOpaq, const mfxHDLPair &hdlPair,
// output param
mfxFrameSurface1 &surface);
public:
virtual UMC::Status InitMfx(UMC::FrameAllocatorParams *pParams,
VideoCORE* mfxCore,
const mfxVideoParam *params,
const mfxFrameAllocRequest *request,
mfxFrameAllocResponse *response,
bool isUseExternalFrames,
bool isSWplatform) override;
// suppose that Close() calls Reset(), so override only Reset()
virtual UMC::Status Reset() override;
typedef struct
{
int32_t colorFormat;
size_t UOffset;
size_t VOffset;
} JPEG_Info;
void SetJPEGInfo(JPEG_Info * jpegInfo);
mfxStatus StartPreparingToOutput(mfxFrameSurface1 *surface_work, UMC::FrameData* in, const mfxVideoParam * par, mfxU16 *taskId, bool isOpaq);
mfxStatus CheckPreparingToOutput(mfxFrameSurface1 *surface_work, UMC::FrameData* in, const mfxVideoParam * par, mfxU16 taskId);
protected:
mfxStatus ConvertToNV12(UMC::FrameMemID index, mfxFrameSurface1 *dst);
JPEG_Info m_jpegInfo;
};
#endif // #if defined (MFX_ENABLE_MJPEG_VIDEO_DECODE) && defined (MFX_VA_WIN)
#endif //_MFX_ALLOC_WRAPPER_H_
|