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
|
// Copyright (c) 2017-2020 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 __LIBMFX_CORE_H__
#define __LIBMFX_CORE_H__
#include <map>
#include "umc_mutex.h"
#include "libmfx_allocator.h"
#include "mfxvideo.h"
#include "mfxvideo++int.h"
#include "mfx_ext_buffers.h"
#include "fast_copy.h"
#include "libmfx_core_interface.h"
#include <memory>
class mfx_UMC_FrameAllocator;
// Virtual table size for CommonCORE should be considered fixed.
// Otherwise binary compatibility with already released plugins would be broken.
class CommonCORE : public VideoCORE
{
public:
friend class FactoryCORE;
virtual ~CommonCORE() override { Close(); }
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *handle) override;
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL handle) override;
virtual mfxStatus SetBufferAllocator(mfxBufferAllocator *) override;
virtual mfxStatus SetFrameAllocator(mfxFrameAllocator *allocator) override;
// Utility functions for memory access
virtual mfxStatus AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId *mid) override;
virtual mfxStatus LockBuffer(mfxMemId mid, mfxU8 **ptr) override;
virtual mfxStatus UnlockBuffer(mfxMemId mid) override;
virtual mfxStatus FreeBuffer(mfxMemId mid) override;
// DEPRECATED
virtual mfxStatus CheckHandle() override { return MFX_ERR_NONE; }
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle, bool ExtendedSearch = true) override;
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request,
mfxFrameAllocResponse *response, bool isNeedCopy = true) override;
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request,
mfxFrameAllocResponse *response,
mfxFrameSurface1 **pOpaqueSurface,
mfxU32 NumOpaqueSurface) override;
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr) override;
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr = nullptr) override;
virtual mfxStatus FreeFrames(mfxFrameAllocResponse *response, bool ExtendedSearch = true) override;
virtual mfxStatus LockExternalFrame(mfxMemId mid, mfxFrameData *ptr, bool ExtendedSearch = true) override;
virtual mfxStatus GetExternalFrameHDL(mfxMemId mid, mfxHDL *handle, bool ExtendedSearch = true) override;
virtual mfxStatus UnlockExternalFrame(mfxMemId mid, mfxFrameData *ptr=0, bool ExtendedSearch = true) override;
virtual mfxMemId MapIdx(mfxMemId mid) override;
// Get original Surface corresponding to OpaqueSurface
virtual mfxFrameSurface1* GetNativeSurface(mfxFrameSurface1 *pOpqSurface, bool ExtendedSearch = true) override;
// Get OpaqueSurface corresponding to Original
virtual mfxFrameSurface1* GetOpaqSurface(mfxMemId mid, bool ExtendedSearch = true) override;
// Increment Surface lock caring about opaq
virtual mfxStatus IncreaseReference(mfxFrameData *ptr, bool ExtendedSearch = true) override;
// Decrement Surface lock caring about opaq
virtual mfxStatus DecreaseReference(mfxFrameData *ptr, bool ExtendedSearch = true) override;
// no care about surface, opaq and all round. Just increasing reference
virtual mfxStatus IncreasePureReference(mfxU16 &Locked) override;
// no care about surface, opaq and all round. Just decreasing reference
virtual mfxStatus DecreasePureReference(mfxU16 &Locked) override;
// Get Video Accelerator.
virtual void GetVA(mfxHDL* phdl, mfxU16) override { *phdl = nullptr; }
virtual mfxStatus CreateVA(mfxVideoParam *, mfxFrameAllocRequest *, mfxFrameAllocResponse *, UMC::FrameAllocator *) override { MFX_RETURN(MFX_ERR_UNSUPPORTED); }
// Get the current working adapter's number
virtual mfxU32 GetAdapterNumber() override { return 0; }
//
virtual eMFXPlatform GetPlatformType() override { return MFX_PLATFORM_SOFTWARE; }
// Get Video Processing
virtual void GetVideoProcessing(mfxHDL* phdl) override { *phdl = 0; }
virtual mfxStatus CreateVideoProcessing(mfxVideoParam *) override { MFX_RETURN(MFX_ERR_UNSUPPORTED); }
// Get the current number of working threads
virtual mfxU32 GetNumWorkingThreads() override { return m_numThreadsAvailable; }
virtual void INeedMoreThreadsInside(const void *pComponent) override;
virtual mfxStatus DoFastCopy(mfxFrameSurface1 *pDst, mfxFrameSurface1 *pSrc) override;
virtual mfxStatus DoFastCopyExtended(mfxFrameSurface1 *pDst, mfxFrameSurface1 *pSrc) override;
virtual mfxStatus DoFastCopyWrapper(mfxFrameSurface1 *pDst, mfxU16 dstMemType, mfxFrameSurface1 *pSrc, mfxU16 srcMemType) override;
// DEPRECATED
virtual bool IsFastCopyEnabled() override { return true; }
virtual bool IsExternalFrameAllocator() const override;
virtual eMFXHWType GetHWType() override { return MFX_HW_UNKNOWN; }
virtual mfxStatus CopyFrame(mfxFrameSurface1 *dst, mfxFrameSurface1 *src) override;
virtual mfxStatus CopyBuffer(mfxU8 *, mfxU32, mfxFrameSurface1 *) override { MFX_RETURN(MFX_ERR_UNKNOWN); }
virtual mfxStatus CopyFrameEx(mfxFrameSurface1 *pDst, mfxU16 dstMemType, mfxFrameSurface1 *pSrc, mfxU16 srcMemType) override
{
return DoFastCopyWrapper(pDst, dstMemType, pSrc, srcMemType);
}
virtual mfxStatus IsGuidSupported(const GUID, mfxVideoParam *, bool) override { return MFX_ERR_NONE; }
virtual bool CheckOpaqueRequest(mfxFrameAllocRequest *request, mfxFrameSurface1 **pOpaqueSurface, mfxU32 NumOpaqueSurface, bool ExtendedSearch = true) override;
virtual eMFXVAType GetVAType() const override { return MFX_HW_NO; }
virtual bool SetCoreId(mfxU32 Id) override;
virtual void* QueryCoreInterface(const MFX_GUID &guid) override;
virtual mfxSession GetSession() override { return m_session; }
virtual void SetWrapper(void* pWrp) override;
virtual mfxU16 GetAutoAsyncDepth() override;
virtual bool IsCompatibleForOpaq() override { return true; }
// keep frame response structure describing plug-in memory surfaces
void AddPluginAllocResponse(mfxFrameAllocResponse& response);
// get response which corresponds required conditions: same mids and number
mfxFrameAllocResponse* GetPluginAllocResponse(mfxFrameAllocResponse& temp_response);
// non-virtual QueryPlatform, as we should not change vtable
mfxStatus QueryPlatform(mfxPlatform* platform);
protected:
CommonCORE(const mfxU32 numThreadsAvailable, const mfxSession session = nullptr);
class API_1_19_Adapter : public IVideoCore_API_1_19
{
public:
API_1_19_Adapter(CommonCORE * core) : m_core(core) {}
virtual mfxStatus QueryPlatform(mfxPlatform* platform);
private:
CommonCORE *m_core;
};
virtual mfxStatus DefaultAllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
mfxFrameAllocator* GetAllocatorAndMid(mfxMemId& mid);
mfxBaseWideFrameAllocator* GetAllocatorByReq(mfxU16 type) const;
virtual void Close();
mfxStatus FreeMidArray(mfxFrameAllocator* pAlloc, mfxFrameAllocResponse *response);
mfxStatus RegisterMids(mfxFrameAllocResponse *response, mfxU16 memType, bool IsDefaultAlloc, mfxBaseWideFrameAllocator* pAlloc = 0);
mfxStatus CheckTimingLog();
bool GetUniqID(mfxMemId& mId);
virtual mfxStatus InternalFreeFrames(mfxFrameAllocResponse *response);
bool IsEqual (const mfxFrameAllocResponse &resp1, const mfxFrameAllocResponse &resp2) const
{
if (resp1.NumFrameActual != resp2.NumFrameActual)
return false;
for (mfxU32 i=0; i < resp1.NumFrameActual; i++)
{
if (resp1.mids[i] != resp2.mids[i])
return false;
}
return true;
};
//function checks if surfaces already allocated and mapped and request is consistent. Fill response if surfaces are correct
virtual bool IsOpaqSurfacesAlreadyMapped(mfxFrameSurface1 **pOpaqueSurface, mfxU32 NumOpaqueSurface, mfxFrameAllocResponse *response, bool ExtendedSearch = true) override;
typedef struct
{
mfxMemId InternalMid;
bool isDefaultMem;
mfxU16 memType;
} MemDesc;
typedef std::map<mfxMemId, MemDesc> CorrespTbl;
typedef std::map<mfxMemId, mfxBaseWideFrameAllocator*> AllocQueue;
typedef std::map<mfxMemId*, mfxMemId*> MemIDMap;
typedef std::map<mfxFrameSurface1*, mfxFrameSurface1> OpqTbl;
typedef std::map<mfxMemId, mfxFrameSurface1*> OpqTbl_MemId;
typedef std::map<mfxFrameData*, mfxFrameSurface1*> OpqTbl_FrameData;
typedef std::map<mfxFrameAllocResponse*, mfxU32> RefCtrTbl;
CorrespTbl m_CTbl;
AllocQueue m_AllocatorQueue;
MemIDMap m_RespMidQ;
OpqTbl m_OpqTbl;
OpqTbl_MemId m_OpqTbl_MemId;
OpqTbl_FrameData m_OpqTbl_FrameData;
RefCtrTbl m_RefCtrTbl;
// Number of available threads
const
mfxU32 m_numThreadsAvailable;
// Handler to the owning session
const
mfxSession m_session;
// Common I/F
mfxWideBufferAllocator m_bufferAllocator;
mfxBaseWideFrameAllocator m_FrameAllocator;
mfxU32 m_NumAllocators;
mfxHDL m_hdl;
mfxHDL m_DXVA2DecodeHandle;
mfxHDL m_D3DDecodeHandle;
mfxHDL m_D3DEncodeHandle;
mfxHDL m_D3DVPPHandle;
bool m_bSetExtBufAlloc;
bool m_bSetExtFrameAlloc;
std::unique_ptr<mfxMemId[]> m_pMemId;
std::unique_ptr<mfxBaseWideFrameAllocator> m_pcAlloc;
std::unique_ptr<FastCopy> m_pFastCopy;
bool m_bUseExtManager;
UMC::Mutex m_guard;
bool m_bIsOpaqMode;
mfxU32 m_CoreId;
mfx_UMC_FrameAllocator* m_pWrp;
EncodeHWCaps m_encode_caps;
EncodeHWCaps m_encode_mbprocrate;
std::vector<mfxFrameAllocResponse> m_PlugInMids;
API_1_19_Adapter m_API_1_19;
mfxU16 m_deviceId;
CommonCORE & operator = (const CommonCORE &) = delete;
};
mfxStatus CoreDoSWFastCopy(mfxFrameSurface1 & dst, const mfxFrameSurface1 & src, int copyFlag);
#endif
|