1
0
* Updated MSDK headers and dispatch library to Intel Media SDK 2013.
* Strip unknown/invalid NALUs from all H264 packets, not just headers.
* Fixed handling of special case of broken H264 header.
* Avoid crash (but not failure) when switching display resolutions during HW init.
* Sync shared code from Media SDK 2013 (allocators, etc).
* Added IQuickSyncDecoder::GetCodecName() - returns name of decoder + active codec.
* Added IQuickSyncDecoder::IsHwAccelerated() - returns true/false when HW is used.

git-svn-id: svn://svn.code.sf.net/p/qsdecoder/code/trunk/IntelQuickSyncDecoder@80 dfccccb7-dd81-40b7-a334-5a7ba89c2b1d
This commit is contained in:
egur 2013-01-31 19:55:47 +00:00
parent 7ebf555c26
commit e8a111d96a
11 changed files with 430 additions and 304 deletions

View File

@ -29,7 +29,7 @@
#pragma once
#define QS_DEC_DLL_NAME "IntelQuickSyncDecoder.dll"
#define QS_DEC_VERSION "v0.40"
#define QS_DEC_VERSION "v0.41"
// Forward declarations
struct IDirect3DDeviceManager9;
@ -246,6 +246,8 @@ struct IQuickSyncDecoder
// Change output surface type dynamically
virtual void SetOutputSurfaceType(QsOutputSurfaceType surfaceType) = 0;
virtual const char* GetCodecName() const = 0;
virtual bool IsHwAccelerated() const = 0;
protected:
// Ban copying!
IQuickSyncDecoder& operator=(const IQuickSyncDecoder&);

View File

@ -14,8 +14,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//
VS_VERSION_INFO VERSIONINFO
FILEVERSION 0,40,0,0
PRODUCTVERSION 0,40,0,0
FILEVERSION 0,41,0,0
PRODUCTVERSION 0,41,0,0
FILEFLAGSMASK 0x17L
#ifdef _DEBUG
FILEFLAGS 0x1L
@ -32,13 +32,13 @@ BEGIN
BEGIN
VALUE "CompanyName", "Intel Corp."
VALUE "FileDescription", "IntelQuickSyncDecoder DLL"
VALUE "FileVersion", "0.40"
VALUE "FileVersion", "0.41.0.0"
VALUE "InternalName", "IntelQuickSyncDecoder"
VALUE "LegalCopyright", "BSD lisence. © 2012 Intel ® Corp. By Eric Gur"
VALUE "LegalTrademarks", "Intel QuickSync"
VALUE "LegalCopyright", "BSD lisence. © 2013 Intel ® Corp. By Eric Gur"
VALUE "LegalTrademarks", "Intel QuickSync Decoder"
VALUE "OriginalFilename", "IntelQuickSyncDecoder.dll"
VALUE "ProductName", "IntelQuickSyncDecoder"
VALUE "ProductVersion", "0.40"
VALUE "ProductName", "Intel QuickSync Decoder"
VALUE "ProductVersion", "0.41.0.0"
END
END
BLOCK "VarFileInfo"

View File

@ -61,9 +61,11 @@ CQuickSync::CQuickSync() :
m_bDvdDecoding(false),
m_PicStruct(0),
m_SurfaceType(QS_SURFACE_SYSTEM),
m_ProcessedFrame(new QsFrameData, new CQsAlignedBuffer(0))
m_ProcessedFrame(new QsFrameData, new CQsAlignedBuffer(0)
)
{
MSDK_TRACE("QsDecoder: Constructor\n");
strcpy(m_CodecName, "Intel\xae QuickSync Decoder");
mfxStatus sts = MFX_ERR_NONE;
m_pDecoder = new CQuickSyncDecoder(sts);
@ -105,7 +107,7 @@ CQuickSync::CQuickSync() :
// m_Config.nVppDenoiseStrength = 16; // 0-64
// m_Config.bDropDuplicateFrames = true;
m_OK = (sts == MFX_ERR_NONE);
}
@ -191,18 +193,18 @@ HRESULT CQuickSync::HandleSubType(const AM_MEDIA_TYPE* mtIn, FOURCC fourCC, mfxV
if (hr != S_OK)
{
MSDK_TRACE("QsDecoder::InitDecoder - failed due to unsupported codec (%s), profile (%s), level (%i) combination\n",
GetCodecName(mfx.CodecId), GetProfileName(mfx.CodecId, mp2->dwProfile), mp2->dwLevel);
::GetCodecName(mfx.CodecId), GetProfileName(mfx.CodecId, mp2->dwProfile), mp2->dwLevel);
return E_NOTIMPL;
}
else
{
MSDK_TRACE("QsDecoder::InitDecoder - codec (%s), profile (%s), level (%i)\n",
GetCodecName(mfx.CodecId), GetProfileName(mfx.CodecId, mp2->dwProfile), mp2->dwLevel);
::GetCodecName(mfx.CodecId), GetProfileName(mfx.CodecId, mp2->dwProfile), mp2->dwLevel);
}
}
else
{
MSDK_TRACE("QsDecoder::InitDecoder - codec (%s)\n", GetCodecName(mfx.CodecId));
MSDK_TRACE("QsDecoder::InitDecoder - codec (%s)\n", ::GetCodecName(mfx.CodecId));
}
return S_OK;
@ -527,6 +529,9 @@ HRESULT CQuickSync::InitDecoder(const AM_MEDIA_TYPE* mtIn, FOURCC fourCC)
m_pDecoder->SetAuxFramesCount(surfaceCount);
}
_snprintf_s(m_CodecName, MSDK_ARRAY_LEN(m_CodecName), MSDK_ARRAY_LEN(m_CodecName)-1,
"Intel\xae QuickSync Decoder (%s)" , ::GetCodecName(m_DecVideoParams.mfx.CodecId));
delete[] (mfxU8*)vih2;
m_OK = (sts == MFX_ERR_NONE);
return (m_OK) ? S_OK : E_FAIL;

View File

@ -101,6 +101,8 @@ protected:
CQsAutoLock cObjectLock(&m_csLock);
m_SurfaceType = surfaceType;
}
const char* GetCodecName() const { return m_CodecName; }
bool IsHwAccelerated() const { return (m_pDecoder) ? m_pDecoder->IsHwAccelerated() : false; }
bool SetTimeStamp(mfxFrameSurface1* pSurface, REFERENCE_TIME& rtStart);
void SetAspectRatio(VIDEOINFOHEADER2& vih2, mfxFrameInfo& FrameInfo);
@ -136,6 +138,7 @@ protected:
CQsConfig m_Config; // Global config
mfxU32 m_PicStruct;
QsOutputSurfaceType m_SurfaceType;
char m_CodecName[256];
typedef std::pair<QsFrameData*, CQsAlignedBuffer*> TQsQueueItem;
TQsQueueItem m_ProcessedFrame;

View File

@ -144,8 +144,8 @@ public:
return (i < m_nRequiredFramesNum) ? (m_LockedSurfaces[i] > 0 || pSurface->Data.Locked > 0) : true;
}
__forceinline bool IsD3DAlloc() { return m_bUseD3DAlloc; }
__forceinline bool IsHwAccelerated() { return m_bHwAcceleration; }
__forceinline bool IsD3DAlloc() const { return m_bUseD3DAlloc; }
__forceinline bool IsHwAccelerated() const { return m_bHwAcceleration; }
mfxStatus LockFrame(mfxFrameSurface1* pSurface, mfxFrameData* pFrameData);
mfxStatus UnlockFrame(mfxFrameSurface1* pSurface, mfxFrameData* pFrameData);

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, INTEL CORPORATION
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -44,48 +44,84 @@ MFXFrameAllocator::MFXFrameAllocator()
GetHDL = GetHDL_;
}
mfxStatus MFXFrameAllocator::Alloc_(mfxHDL pthis, mfxFrameAllocRequest* request, mfxFrameAllocResponse* response)
MFXFrameAllocator::~MFXFrameAllocator()
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXFrameAllocator*)(pthis))->AllocFrames(request, response);
}
mfxStatus MFXFrameAllocator::Lock_(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr)
mfxStatus MFXFrameAllocator::Alloc_(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXFrameAllocator*)(pthis))->LockFrame(mid, ptr);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
return self.AllocFrames(request, response);
}
mfxStatus MFXFrameAllocator::Unlock_(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr)
mfxStatus MFXFrameAllocator::Lock_(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXFrameAllocator*)(pthis))->UnlockFrame(mid, ptr);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
return self.LockFrame(mid, ptr);
}
mfxStatus MFXFrameAllocator::Free_(mfxHDL pthis, mfxFrameAllocResponse* response)
mfxStatus MFXFrameAllocator::Unlock_(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXFrameAllocator*)(pthis))->FreeFrames(response);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
return self.UnlockFrame(mid, ptr);
}
mfxStatus MFXFrameAllocator::GetHDL_(mfxHDL pthis, mfxMemId mid, mfxHDL* handle)
mfxStatus MFXFrameAllocator::Free_(mfxHDL pthis, mfxFrameAllocResponse *response)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXFrameAllocator*)(pthis))->GetFrameHDL(mid, handle);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
return self.FreeFrames(response);
}
mfxStatus MFXFrameAllocator::GetHDL_(mfxHDL pthis, mfxMemId mid, mfxHDL *handle)
{
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
return self.GetFrameHDL(mid, handle);
}
/////////////////////////////////////////////////////////////////////////////////////////////
// BaseFrameAllocator
/////////////////////////////////////////////////////////////////////////////////////////////
mfxStatus BaseFrameAllocator::CheckRequestType(mfxFrameAllocRequest* request)
BaseFrameAllocator::BaseFrameAllocator()
{
MSDK_CHECK_POINTER(request, MFX_ERR_NULL_PTR);
// check that Media SDK component is specified in request
return ((request->Type & MEMTYPE_FROM_MASK) != 0) ? MFX_ERR_NONE : MFX_ERR_UNSUPPORTED;
}
mfxStatus BaseFrameAllocator::AllocFrames(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response)
BaseFrameAllocator::~BaseFrameAllocator()
{
}
mfxStatus BaseFrameAllocator::CheckRequestType(mfxFrameAllocRequest* request)
{
if (0 == request)
return MFX_ERR_NULL_PTR;
// check that Media SDK component is specified in request
if ((request->Type & MEMTYPE_FROM_MASK) != 0)
return MFX_ERR_NONE;
else
return MFX_ERR_UNSUPPORTED;
}
mfxStatus BaseFrameAllocator::AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
{
if (0 == request || 0 == response || 0 == request->NumFrameSuggested)
return MFX_ERR_MEMORY_ALLOC;
@ -95,29 +131,31 @@ mfxStatus BaseFrameAllocator::AllocFrames(mfxFrameAllocRequest* request, mfxFram
mfxStatus sts = MFX_ERR_NONE;
if ((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) && (request->Type & MFX_MEMTYPE_FROM_DECODE))
if ( (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) && (request->Type & MFX_MEMTYPE_FROM_DECODE) )
{
// external decoder allocations
if (m_externalDecoderResponse.m_refCount > 0)
{
std::list<UniqueResponse>::iterator it =
std::find_if( m_ExtResponses.begin()
, m_ExtResponses.end()
, UniqueResponse (*response, request->Info.CropW, request->Info.CropH, 0));
if (it != m_ExtResponses.end())
{
// check if enough frames were allocated
if (request->NumFrameMin > m_externalDecoderResponse.m_response.NumFrameActual)
if (request->NumFrameMin > it->NumFrameActual)
return MFX_ERR_MEMORY_ALLOC;
m_externalDecoderResponse.m_refCount++;
it->m_refCount++;
// return existing response
*response = m_externalDecoderResponse.m_response;
*response = (mfxFrameAllocResponse&)*it;
}
else
else
{
sts = AllocImpl(request, response);
if (sts == MFX_ERR_NONE)
{
m_externalDecoderResponse.m_response = *response;
m_externalDecoderResponse.m_refCount = 1;
m_externalDecoderResponse.m_type = request->Type & MEMTYPE_FROM_MASK;
}
m_ExtResponses.push_back(UniqueResponse(*response, request->Info.CropW, request->Info.CropH, request->Type & MEMTYPE_FROM_MASK));
}
}
}
else
@ -141,38 +179,36 @@ mfxStatus BaseFrameAllocator::AllocFrames(mfxFrameAllocRequest* request, mfxFram
return sts;
}
bool BaseFrameAllocator::IsSame(const mfxFrameAllocResponse& l, const mfxFrameAllocResponse& r)
{
return l.mids != 0 && r.mids != 0 && l.mids[0] == r.mids[0] && l.NumFrameActual == r.NumFrameActual;
}
mfxStatus BaseFrameAllocator::FreeFrames(mfxFrameAllocResponse* response)
mfxStatus BaseFrameAllocator::FreeFrames(mfxFrameAllocResponse *response)
{
if (response == 0)
return MFX_ERR_INVALID_HANDLE;
mfxStatus sts = MFX_ERR_NONE;
// check whether response is m_externalDecoderResponse
if (m_externalDecoderResponse.m_refCount > 0 && IsSame(*response, m_externalDecoderResponse.m_response))
// check whether response is an external decoder response
std::list<UniqueResponse>::iterator i =
std::find_if( m_ExtResponses.begin(), m_ExtResponses.end(), std::bind1st(IsSame(), *response));
if (i != m_ExtResponses.end())
{
if (--m_externalDecoderResponse.m_refCount == 0)
if ((--i->m_refCount) == 0)
{
sts = ReleaseResponse(response);
m_externalDecoderResponse.Reset();
m_ExtResponses.erase(i);
}
return sts;
}
// if not found so far, then search in internal responses
for (Iter i = m_responses.begin(); i != m_responses.end(); ++i)
std::list<mfxFrameAllocResponse>::iterator i2 =
std::find_if(m_responses.begin(), m_responses.end(), std::bind1st(IsSame(), *response));
if (i2 != m_responses.end())
{
if (IsSame(*response, *i))
{
sts = ReleaseResponse(response);
m_responses.erase(i);
return sts;
}
sts = ReleaseResponse(response);
m_responses.erase(i2);
return sts;
}
// not found anywhere, report an error
@ -181,15 +217,19 @@ mfxStatus BaseFrameAllocator::FreeFrames(mfxFrameAllocResponse* response)
mfxStatus BaseFrameAllocator::Close()
{
ReleaseResponse(&(m_externalDecoderResponse.m_response));
m_externalDecoderResponse.Reset();
while (!m_responses.empty())
{
ReleaseResponse(&(*m_responses.begin()));
m_responses.pop_front();
std::list<UniqueResponse> ::iterator i;
for (i = m_ExtResponses.begin(); i!= m_ExtResponses.end(); i++)
{
ReleaseResponse(&*i);
}
m_ExtResponses.clear();
std::list<mfxFrameAllocResponse> ::iterator i2;
for (i2 = m_responses.begin(); i2!= m_responses.end(); i2++)
{
ReleaseResponse(&*i2);
}
return MFX_ERR_NONE;
}
@ -205,26 +245,47 @@ MFXBufferAllocator::MFXBufferAllocator()
Unlock = Unlock_;
}
mfxStatus MFXBufferAllocator::Alloc_(mfxHDL pthis, mfxU32 nbytes, mfxU16 type, mfxMemId* mid)
MFXBufferAllocator::~MFXBufferAllocator()
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXBufferAllocator*)pthis)->AllocBuffer(nbytes, type, mid);
}
mfxStatus MFXBufferAllocator::Lock_(mfxHDL pthis, mfxMemId mid, mfxU8** ptr)
mfxStatus MFXBufferAllocator::Alloc_(mfxHDL pthis, mfxU32 nbytes, mfxU16 type, mfxMemId *mid)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXBufferAllocator*)pthis)->LockBuffer(mid, ptr);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXBufferAllocator& self = *(MFXBufferAllocator *)pthis;
return self.AllocBuffer(nbytes, type, mid);
}
mfxStatus MFXBufferAllocator::Lock_(mfxHDL pthis, mfxMemId mid, mfxU8 **ptr)
{
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXBufferAllocator& self = *(MFXBufferAllocator *)pthis;
return self.LockBuffer(mid, ptr);
}
mfxStatus MFXBufferAllocator::Unlock_(mfxHDL pthis, mfxMemId mid)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXBufferAllocator*)pthis)->UnlockBuffer(mid);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXBufferAllocator& self = *(MFXBufferAllocator *)pthis;
return self.UnlockBuffer(mid);
}
mfxStatus MFXBufferAllocator::Free_(mfxHDL pthis, mfxMemId mid)
{
MSDK_CHECK_POINTER(pthis, MFX_ERR_MEMORY_ALLOC);
return ((MFXBufferAllocator*)pthis)->FreeBuffer(mid);
if (0 == pthis)
return MFX_ERR_MEMORY_ALLOC;
MFXBufferAllocator& self = *(MFXBufferAllocator *)pthis;
return self.FreeBuffer(mid);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, INTEL CORPORATION
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -39,25 +39,24 @@ class MFXFrameAllocator : public mfxFrameAllocator
{
public:
MFXFrameAllocator();
virtual ~MFXFrameAllocator() {}
virtual ~MFXFrameAllocator();
// optional method, override if need to pass some parameters to allocator from application
virtual mfxStatus Init(mfxAllocatorParams* pParams) = 0;
virtual mfxStatus Init(mfxAllocatorParams *pParams) = 0;
virtual mfxStatus Close() = 0;
protected:
virtual mfxStatus AllocFrames(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response) = 0;
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData* ptr) = 0;
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData* ptr) = 0;
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL* handle) = 0;
virtual mfxStatus FreeFrames(mfxFrameAllocResponse* response) = 0;
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) = 0;
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr) = 0;
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr) = 0;
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle) = 0;
virtual mfxStatus FreeFrames(mfxFrameAllocResponse *response) = 0;
private:
static mfxStatus Alloc_(mfxHDL pthis, mfxFrameAllocRequest* request, mfxFrameAllocResponse* response);
static mfxStatus Lock_(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr);
static mfxStatus Unlock_(mfxHDL pthis, mfxMemId mid, mfxFrameData* ptr);
static mfxStatus GetHDL_(mfxHDL pthis, mfxMemId mid, mfxHDL* handle);
static mfxStatus Free_(mfxHDL pthis, mfxFrameAllocResponse* response);
static mfxStatus MFX_CDECL Alloc_(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
static mfxStatus MFX_CDECL Lock_(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr);
static mfxStatus MFX_CDECL Unlock_(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr);
static mfxStatus MFX_CDECL GetHDL_(mfxHDL pthis, mfxMemId mid, mfxHDL *handle);
static mfxStatus MFX_CDECL Free_(mfxHDL pthis, mfxFrameAllocResponse *response);
};
// This class implements basic logic of memory allocator
@ -71,66 +70,91 @@ private:
class BaseFrameAllocator: public MFXFrameAllocator
{
public:
BaseFrameAllocator() {}
virtual ~BaseFrameAllocator() {}
BaseFrameAllocator();
virtual ~BaseFrameAllocator();
virtual mfxStatus Init(mfxAllocatorParams* pParams) = 0;
virtual mfxStatus Init(mfxAllocatorParams *pParams) = 0;
virtual mfxStatus Close();
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
virtual mfxStatus FreeFrames(mfxFrameAllocResponse *response);
protected:
virtual mfxStatus AllocFrames(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response);
virtual mfxStatus FreeFrames(mfxFrameAllocResponse* response);
typedef std::list<mfxFrameAllocResponse>::iterator Iter;
static const mfxU32 MEMTYPE_FROM_MASK = MFX_MEMTYPE_FROM_ENCODE | MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT;
struct UniqueResponse
: mfxFrameAllocResponse
{
mfxU16 m_cropw;
mfxU16 m_croph;
mfxU32 m_refCount;
mfxFrameAllocResponse m_response;
mfxU16 m_type;
UniqueResponse() { Reset(); }
void Reset() { memset(this, 0, sizeof(*this)); }
UniqueResponse()
{
memset(this, 0, sizeof(*this));
}
// compare responses by actual frame size, alignment (w and h) is up to application
UniqueResponse(const mfxFrameAllocResponse & response, mfxU16 cropw, mfxU16 croph, mfxU16 type)
: mfxFrameAllocResponse(response)
, m_type(type)
, m_refCount(1)
, m_cropw(cropw)
, m_croph(croph)
{
}
//compare by resolution
bool operator () (const UniqueResponse &response)const
{
return m_cropw == response.m_cropw && m_croph == response.m_croph;
}
};
std::list<mfxFrameAllocResponse> m_responses;
UniqueResponse m_externalDecoderResponse;
// checks responses for identity
virtual bool IsSame(const mfxFrameAllocResponse& l, const mfxFrameAllocResponse& r);
std::list<UniqueResponse> m_ExtResponses;
struct IsSame
: public std::binary_function<mfxFrameAllocResponse, mfxFrameAllocResponse, bool>
{
bool operator () (const mfxFrameAllocResponse & l, const mfxFrameAllocResponse &r)const
{
return r.mids != 0 && l.mids != 0 &&
r.mids[0] == l.mids[0] &&
r.NumFrameActual == l.NumFrameActual;
}
};
// checks if request is supported
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest* request);
// memory type specific methods, must be overridden in derived classes
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData* ptr) = 0;
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData* ptr) = 0;
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL* handle) = 0;
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest *request);
// frees memory attached to response
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse* response) = 0;
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response) = 0;
// allocates memory
virtual mfxStatus AllocImpl(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response) = 0;
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) = 0;
template <class T>
class safe_array
{
public:
safe_array(T* ptr = 0) : m_ptr(ptr) {} // construct from object pointer
~safe_array() { reset(0); }
inline T* get()
safe_array(T *ptr = 0):m_ptr(ptr)
{ // construct from object pointer
};
~safe_array()
{
reset(0);
}
T* get()
{ // return wrapped pointer
return m_ptr;
}
inline T* release()
T* release()
{ // return wrapped pointer and give up ownership
T* ptr = m_ptr;
m_ptr = 0;
return ptr;
}
inline void reset(T* ptr)
void reset(T* ptr)
{ // destroy designated object and store new pointer
if (m_ptr)
{
@ -147,17 +171,16 @@ class MFXBufferAllocator : public mfxBufferAllocator
{
public:
MFXBufferAllocator();
virtual ~MFXBufferAllocator() {}
virtual ~MFXBufferAllocator();
protected:
virtual mfxStatus AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId* mid) = 0;
virtual mfxStatus LockBuffer(mfxMemId mid, mfxU8** ptr) = 0;
virtual mfxStatus AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId *mid) = 0;
virtual mfxStatus LockBuffer(mfxMemId mid, mfxU8 **ptr) = 0;
virtual mfxStatus UnlockBuffer(mfxMemId mid) = 0;
virtual mfxStatus FreeBuffer(mfxMemId mid) = 0;
private:
static mfxStatus Alloc_(mfxHDL pthis, mfxU32 nbytes, mfxU16 type, mfxMemId* mid);
static mfxStatus Lock_(mfxHDL pthis, mfxMemId mid, mfxU8** ptr);
static mfxStatus Unlock_(mfxHDL pthis, mfxMemId mid);
static mfxStatus Free_(mfxHDL pthis, mfxMemId mid);
static mfxStatus MFX_CDECL Alloc_(mfxHDL pthis, mfxU32 nbytes, mfxU16 type, mfxMemId *mid);
static mfxStatus MFX_CDECL Lock_(mfxHDL pthis, mfxMemId mid, mfxU8 **ptr);
static mfxStatus MFX_CDECL Unlock_(mfxHDL pthis, mfxMemId mid);
static mfxStatus MFX_CDECL Free_(mfxHDL pthis, mfxMemId mid);
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, INTEL CORPORATION
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -47,7 +47,7 @@ D3DFORMAT ConvertMfxFourccToD3dFormat(mfxU32 fourcc)
return D3DFMT_R8G8B8;
case MFX_FOURCC_RGB4:
return D3DFMT_A8R8G8B8;
case mfxU32(D3DFMT_P8):
case MFX_FOURCC_P8:
return D3DFMT_P8;
default:
return D3DFMT_UNKNOWN;
@ -57,47 +57,49 @@ D3DFORMAT ConvertMfxFourccToD3dFormat(mfxU32 fourcc)
class DeviceHandle
{
public:
DeviceHandle(IDirect3DDeviceManager9* manager) :
m_Manager(manager),
m_Handle(0)
DeviceHandle(IDirect3DDeviceManager9* manager)
: m_manager(manager)
, m_handle(0)
{
MSDK_CHECK_POINTER_NO_RET(manager);
HRESULT hr = manager->OpenDeviceHandle(&m_Handle);
if (FAILED(hr))
m_Manager = 0;
if (manager)
{
HRESULT hr = manager->OpenDeviceHandle(&m_handle);
if (FAILED(hr))
m_manager = 0;
}
}
~DeviceHandle()
{
if (m_Manager && m_Handle)
m_Manager->CloseDeviceHandle(m_Handle);
if (m_manager && m_handle)
m_manager->CloseDeviceHandle(m_handle);
}
HANDLE Detach()
{
HANDLE tmp = m_Handle;
m_Manager = 0;
m_Handle = 0;
HANDLE tmp = m_handle;
m_manager = 0;
m_handle = 0;
return tmp;
}
inline operator HANDLE()
operator HANDLE()
{
return m_Handle;
return m_handle;
}
inline bool operator!() const
bool operator !() const
{
return m_Handle == 0;
return m_handle == 0;
}
protected:
CComPtr<IDirect3DDeviceManager9> m_Manager;
HANDLE m_Handle;
CComPtr<IDirect3DDeviceManager9> m_manager;
HANDLE m_handle;
};
D3DFrameAllocator::D3DFrameAllocator() :
m_Manager(0), m_DecoderService(0), m_ProcessorService(0), m_hDecoder(0), m_hProcessor(0)
D3DFrameAllocator::D3DFrameAllocator()
: m_decoderService(0), m_processorService(0), m_hDecoder(0), m_hProcessor(0), m_manager(0), m_surfaceUsage(0)
{
}
@ -106,39 +108,46 @@ D3DFrameAllocator::~D3DFrameAllocator()
Close();
}
mfxStatus D3DFrameAllocator::Init(mfxAllocatorParams* pParams)
mfxStatus D3DFrameAllocator::Init(mfxAllocatorParams *pParams)
{
D3DAllocatorParams* pd3dParams = 0;
pd3dParams = dynamic_cast<D3DAllocatorParams* >(pParams);
MSDK_CHECK_POINTER(pd3dParams, MFX_ERR_NOT_INITIALIZED);
m_Manager = pd3dParams->pManager;
D3DAllocatorParams *pd3dParams = 0;
pd3dParams = dynamic_cast<D3DAllocatorParams *>(pParams);
if (!pd3dParams)
return MFX_ERR_NOT_INITIALIZED;
m_manager = pd3dParams->pManager;
m_surfaceUsage = pd3dParams->surfaceUsage;
return MFX_ERR_NONE;
}
mfxStatus D3DFrameAllocator::Close()
{
if (m_Manager && m_hDecoder)
if (m_manager && m_hDecoder)
{
m_Manager->CloseDeviceHandle(m_hDecoder);
m_Manager = 0;
m_manager->CloseDeviceHandle(m_hDecoder);
m_manager = 0;
m_hDecoder = 0;
}
if (m_Manager && m_hProcessor)
if (m_manager && m_hProcessor)
{
m_Manager->CloseDeviceHandle(m_hProcessor);
m_Manager = 0;
m_manager->CloseDeviceHandle(m_hProcessor);
m_manager = 0;
m_hProcessor = 0;
}
return BaseFrameAllocator::Close();
}
mfxStatus D3DFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
mfxStatus D3DFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
{
IDirect3DSurface9* pSurface = (IDirect3DSurface9*)mid;
MSDK_CHECK_POINTER(pSurface, MFX_ERR_INVALID_HANDLE);
MSDK_CHECK_POINTER(ptr, MFX_ERR_LOCK_MEMORY);
IDirect3DSurface9 *pSurface = (IDirect3DSurface9 *)mid;
if (pSurface == 0)
return MFX_ERR_INVALID_HANDLE;
if (ptr == 0)
return MFX_ERR_LOCK_MEMORY;
D3DSURFACE_DESC desc;
HRESULT hr = pSurface->GetDesc(&desc);
@ -155,7 +164,7 @@ mfxStatus D3DFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
D3DLOCKED_RECT locked;
hr = pSurface->LockRect(&locked, NULL, D3DLOCK_READONLY | D3DLOCK_NOSYSLOCK);
hr = pSurface->LockRect(&locked, 0, D3DLOCK_NOSYSLOCK);
if (FAILED(hr))
return MFX_ERR_LOCK_MEMORY;
@ -163,38 +172,38 @@ mfxStatus D3DFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
{
case D3DFMT_NV12:
ptr->Pitch = (mfxU16)locked.Pitch;
ptr->Y = (mfxU8*)locked.pBits;
ptr->U = (mfxU8*)locked.pBits + desc.Height * locked.Pitch;
ptr->Y = (mfxU8 *)locked.pBits;
ptr->U = (mfxU8 *)locked.pBits + desc.Height * locked.Pitch;
ptr->V = ptr->U + 1;
break;
case D3DFMT_YV12:
ptr->Pitch = (mfxU16)locked.Pitch;
ptr->Y = (mfxU8*)locked.pBits;
ptr->Y = (mfxU8 *)locked.pBits;
ptr->V = ptr->Y + desc.Height * locked.Pitch;
ptr->U = ptr->V + (desc.Height * locked.Pitch) / 4;
break;
case D3DFMT_YUY2:
ptr->Pitch = (mfxU16)locked.Pitch;
ptr->Y = (mfxU8*)locked.pBits;
ptr->Y = (mfxU8 *)locked.pBits;
ptr->U = ptr->Y + 1;
ptr->V = ptr->Y + 3;
break;
case D3DFMT_R8G8B8:
ptr->Pitch = (mfxU16)locked.Pitch;
ptr->B = (mfxU8*)locked.pBits;
ptr->B = (mfxU8 *)locked.pBits;
ptr->G = ptr->B + 1;
ptr->R = ptr->B + 2;
break;
case D3DFMT_A8R8G8B8:
ptr->Pitch = (mfxU16)locked.Pitch;
ptr->B = (mfxU8* )locked.pBits;
ptr->B = (mfxU8 *)locked.pBits;
ptr->G = ptr->B + 1;
ptr->R = ptr->B + 2;
ptr->A = ptr->B + 3;
break;
case D3DFMT_P8:
ptr->Pitch = (mfxU16)locked.Pitch;
ptr->Y = (mfxU8*)locked.pBits;
ptr->Y = (mfxU8 *)locked.pBits;
ptr->U = 0;
ptr->V = 0;
break;
@ -203,9 +212,9 @@ mfxStatus D3DFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
return MFX_ERR_NONE;
}
mfxStatus D3DFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData* ptr)
mfxStatus D3DFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
{
IDirect3DSurface9* pSurface = (IDirect3DSurface9*)mid;
IDirect3DSurface9 *pSurface = (IDirect3DSurface9 *)mid;
if (pSurface == 0)
return MFX_ERR_INVALID_HANDLE;
@ -222,7 +231,7 @@ mfxStatus D3DFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData* ptr)
return MFX_ERR_NONE;
}
mfxStatus D3DFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL* handle)
mfxStatus D3DFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
{
if (handle == 0)
return MFX_ERR_INVALID_HANDLE;
@ -231,7 +240,7 @@ mfxStatus D3DFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL* handle)
return MFX_ERR_NONE;
}
mfxStatus D3DFrameAllocator::CheckRequestType(mfxFrameAllocRequest* request)
mfxStatus D3DFrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
{
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
if (MFX_ERR_NONE != sts)
@ -243,33 +252,33 @@ mfxStatus D3DFrameAllocator::CheckRequestType(mfxFrameAllocRequest* request)
return MFX_ERR_UNSUPPORTED;
}
mfxStatus D3DFrameAllocator::ReleaseResponse(mfxFrameAllocResponse* response)
mfxStatus D3DFrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
{
if (!response)
return MFX_ERR_NULL_PTR;
if (NULL == response->mids)
return MFX_ERR_NONE;
mfxStatus sts = MFX_ERR_NONE;
for (mfxU32 i = 0; i < response->NumFrameActual; i++)
if (response->mids)
{
if (response->mids[i])
for (mfxU32 i = 0; i < response->NumFrameActual; i++)
{
IDirect3DSurface9* handle = 0;
sts = GetFrameHDL(response->mids[i], (mfxHDL*)&handle);
if (MFX_ERR_NONE != sts)
return sts;
handle->Release();
}
}
if (response->mids[i])
{
IDirect3DSurface9* handle = 0;
sts = GetFrameHDL(response->mids[i], (mfxHDL *)&handle);
if (MFX_ERR_NONE != sts)
return sts;
handle->Release();
}
}
}
MSDK_SAFE_DELETE_ARRAY(response->mids);
return sts;
}
mfxStatus D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response)
mfxStatus D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
{
HRESULT hr;
D3DFORMAT format = ConvertMfxFourccToD3dFormat(request->Info.FourCC);
@ -281,69 +290,81 @@ mfxStatus D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest* request, mfxFrameAl
if (!mids.get())
return MFX_ERR_MEMORY_ALLOC;
DWORD target;
if (MFX_MEMTYPE_DXVA2_DECODER_TARGET & request->Type)
{
target = DXVA2_VideoDecoderRenderTarget;
}
else if (MFX_MEMTYPE_DXVA2_PROCESSOR_TARGET & request->Type)
{
target = DXVA2_VideoProcessorRenderTarget;
}
else
return MFX_ERR_UNSUPPORTED;
// VPP may require at input/output surfaces with color format other than NV12 (in case of color conversion)
// VideoProcessorService must be used to create such surfaces
if (((request->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) && (MFX_FOURCC_NV12 != request->Info.FourCC))||
(request->Type & (MFX_MEMTYPE_FROM_VPPIN | MFX_MEMTYPE_FROM_VPPOUT)) && (request->Type & MFX_MEMTYPE_INTERNAL_FRAME ))
if (target == DXVA2_VideoProcessorRenderTarget)
{
if (!m_hProcessor)
{
DeviceHandle device(m_Manager);
DeviceHandle device = DeviceHandle(m_manager);
if (!device)
return MFX_ERR_MEMORY_ALLOC;
CComPtr<IDirectXVideoProcessorService> service = 0;
hr = m_Manager->GetVideoService(device, IID_IDirectXVideoProcessorService, (void**)&service);
hr = m_manager->GetVideoService(device, IID_IDirectXVideoProcessorService, (void**)&service);
if (FAILED(hr))
return MFX_ERR_MEMORY_ALLOC;
m_ProcessorService = service;
m_processorService = service;
m_hProcessor = device.Detach();
}
hr = m_ProcessorService->CreateSurface(
hr = m_processorService->CreateSurface(
request->Info.Width,
request->Info.Height,
request->NumFrameSuggested - 1,
format,
D3DPOOL_DEFAULT,
0,
DXVA2_VideoProcessorRenderTarget,
(IDirect3DSurface9**)mids.get(),
m_surfaceUsage,
target,
(IDirect3DSurface9 **)mids.get(),
NULL);
}
else
{
if (!m_hDecoder)
{
DeviceHandle device(m_Manager);
DeviceHandle device = DeviceHandle(m_manager);
if (!device)
return MFX_ERR_MEMORY_ALLOC;
CComPtr<IDirectXVideoDecoderService> service = 0;
hr = m_Manager->GetVideoService(device, IID_IDirectXVideoDecoderService, (void**)&service);
hr = m_manager->GetVideoService(device, IID_IDirectXVideoDecoderService, (void**)&service);
if (FAILED(hr))
return MFX_ERR_MEMORY_ALLOC;
m_DecoderService = service;
m_decoderService = service;
m_hDecoder = device.Detach();
}
hr = m_DecoderService->CreateSurface(
hr = m_decoderService->CreateSurface(
request->Info.Width,
request->Info.Height,
request->NumFrameSuggested - 1,
format,
D3DPOOL_DEFAULT,
0,
DXVA2_VideoDecoderRenderTarget,
(IDirect3DSurface9**)mids.get(),
m_surfaceUsage,
target,
(IDirect3DSurface9 **)mids.get(),
NULL);
}
@ -352,6 +373,23 @@ mfxStatus D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest* request, mfxFrameAl
return MFX_ERR_MEMORY_ALLOC;
}
#if 0 // optional, may be done on application level if needed
//zeroing created surfaces
for (mfxU32 i = 0; i < request->NumFrameSuggested; i++)
{
mfxFrameData pData;
if (MFX_ERR_NONE == LockFrame(mids.get()[i], &pData))
{
if (format == D3DFMT_NV12 ||
format == D3DFMT_YV12)
{
memset(pData.Y, 0, (pData.Pitch * request->Info.Height * 3)/2 );
}
UnlockFrame(mids.get()[i], &pData);
}
}
#endif
response->mids = mids.release();
response->NumFrameActual = request->NumFrameSuggested;
return MFX_ERR_NONE;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, INTEL CORPORATION
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -38,9 +38,17 @@ enum eTypeHandle
DXVA2_DECODER = 0x01
};
struct D3DAllocatorParams : public mfxAllocatorParams
struct D3DAllocatorParams : mfxAllocatorParams
{
IDirect3DDeviceManager9* pManager;
IDirect3DDeviceManager9 *pManager;
DWORD surfaceUsage;
D3DAllocatorParams()
: pManager()
, surfaceUsage()
{
}
};
class D3DFrameAllocator : public BaseFrameAllocator
@ -49,26 +57,27 @@ public:
D3DFrameAllocator();
virtual ~D3DFrameAllocator();
virtual mfxStatus Init(mfxAllocatorParams* pParams);
virtual mfxStatus Init(mfxAllocatorParams *pParams);
virtual mfxStatus Close();
virtual IDirect3DDeviceManager9* GetDeviceManager()
{
return m_Manager;
return m_manager;
}
protected:
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData* ptr);
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData* ptr);
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL* handle);
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr);
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr);
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle);
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest* request);
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse* response);
virtual mfxStatus AllocImpl(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response);
protected:
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest *request);
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
CComPtr<IDirect3DDeviceManager9> m_Manager;
CComPtr<IDirectXVideoDecoderService> m_DecoderService;
CComPtr<IDirectXVideoProcessorService> m_ProcessorService;
CComPtr<IDirect3DDeviceManager9> m_manager;
CComPtr<IDirectXVideoDecoderService> m_decoderService;
CComPtr<IDirectXVideoProcessorService> m_processorService;
HANDLE m_hDecoder;
HANDLE m_hProcessor;
DWORD m_surfaceUsage;
};

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, INTEL CORPORATION
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -48,13 +48,13 @@ SysMemFrameAllocator::~SysMemFrameAllocator()
Close();
}
mfxStatus SysMemFrameAllocator::Init(mfxAllocatorParams* pParams)
mfxStatus SysMemFrameAllocator::Init(mfxAllocatorParams *pParams)
{
// check if any params passed from application
if (pParams)
{
SysMemAllocatorParams* pSysMemParams = 0;
pSysMemParams = dynamic_cast<SysMemAllocatorParams*>(pParams);
SysMemAllocatorParams *pSysMemParams = 0;
pSysMemParams = dynamic_cast<SysMemAllocatorParams *>(pParams);
if (!pSysMemParams)
return MFX_ERR_NOT_INITIALIZED;
@ -86,7 +86,7 @@ mfxStatus SysMemFrameAllocator::Close()
return BaseFrameAllocator::Close();
}
mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
{
if (!m_pBufferAllocator)
return MFX_ERR_NOT_INITIALIZED;
@ -94,8 +94,8 @@ mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
if (!ptr)
return MFX_ERR_NULL_PTR;
sFrame* fs = 0;
mfxStatus sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, mid,(mfxU8**)&fs);
sFrame *fs = 0;
mfxStatus sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, mid,(mfxU8 **)&fs);
if (MFX_ERR_NONE != sts)
return sts;
@ -106,9 +106,9 @@ mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
return MFX_ERR_INVALID_HANDLE;
}
mfxU16 Width2 = (mfxU16)MSDK_ALIGN16(fs->info.Width);
mfxU16 Height2 = (mfxU16)MSDK_ALIGN16(fs->info.Height);
ptr->R = ptr->Y = (mfxU8*)fs + MSDK_ALIGN16(sizeof(sFrame));
mfxU16 Width2 = (mfxU16)MSDK_ALIGN32(fs->info.Width);
mfxU16 Height2 = (mfxU16)MSDK_ALIGN32(fs->info.Height);
ptr->B = ptr->Y = (mfxU8 *)fs + MSDK_ALIGN32(sizeof(sFrame));
switch (fs->info.FourCC)
{
@ -128,14 +128,14 @@ mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
ptr->Pitch = 2 * Width2;
break;
case MFX_FOURCC_RGB3:
ptr->G = ptr->R + 1;
ptr->B = ptr->R + 2;
ptr->G = ptr->B + 1;
ptr->R = ptr->B + 2;
ptr->Pitch = 3 * Width2;
break;
case MFX_FOURCC_RGB4:
ptr->G = ptr->R + 1;
ptr->B = ptr->R + 2;
ptr->A = ptr->R + 3;
ptr->G = ptr->B + 1;
ptr->R = ptr->B + 2;
ptr->A = ptr->B + 3;
ptr->Pitch = 4 * Width2;
break;
default:
@ -145,7 +145,7 @@ mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData* ptr)
return MFX_ERR_NONE;
}
mfxStatus SysMemFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData* ptr)
mfxStatus SysMemFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
{
if (!m_pBufferAllocator)
return MFX_ERR_NOT_INITIALIZED;
@ -166,12 +166,12 @@ mfxStatus SysMemFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData* ptr)
return MFX_ERR_NONE;
}
mfxStatus SysMemFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL* handle)
mfxStatus SysMemFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
{
return MFX_ERR_UNSUPPORTED;
}
mfxStatus SysMemFrameAllocator::CheckRequestType(mfxFrameAllocRequest* request)
mfxStatus SysMemFrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
{
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
if (MFX_ERR_NONE != sts)
@ -183,54 +183,51 @@ mfxStatus SysMemFrameAllocator::CheckRequestType(mfxFrameAllocRequest* request)
return MFX_ERR_UNSUPPORTED;
}
mfxStatus SysMemFrameAllocator::AllocImpl(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response)
mfxStatus SysMemFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
{
if (!m_pBufferAllocator)
return MFX_ERR_NOT_INITIALIZED;
mfxU32 numAllocated = 0;
mfxU32 Width2 = MSDK_ALIGN16(request->Info.Width);
mfxU32 Height2 = MSDK_ALIGN16(request->Info.Height);
mfxU32 Width2 = MSDK_ALIGN32(request->Info.Width);
mfxU32 Height2 = MSDK_ALIGN32(request->Info.Height);
mfxU32 nbytes;
mfxU8 nBitsPerPixel;
switch (request->Info.FourCC)
{
case MFX_FOURCC_YV12:
case MFX_FOURCC_NV12:
nBitsPerPixel = 12;
break;
nbytes = Width2*Height2 + (Width2>>1)*(Height2>>1) + (Width2>>1)*(Height2>>1);
break;
case MFX_FOURCC_RGB3:
nBitsPerPixel = 24;
break;
nbytes = Width2*Height2 + Width2*Height2 + Width2*Height2;
break;
case MFX_FOURCC_RGB4:
nBitsPerPixel = 32;
break;
nbytes = Width2*Height2 + Width2*Height2 + Width2*Height2 + Width2*Height2;
break;
case MFX_FOURCC_YUY2:
nBitsPerPixel = 16;
nbytes = Width2*Height2 + (Width2>>1)*(Height2) + (Width2>>1)*(Height2);
break;
default:
return MFX_ERR_UNSUPPORTED;
}
nbytes = Width2 * Height2 * nBitsPerPixel / 8;
}
safe_array<mfxMemId> mids(new mfxMemId[request->NumFrameSuggested]);
if (!mids.get())
return MFX_ERR_MEMORY_ALLOC;
// allocate frames
for (numAllocated = 0; numAllocated < request->NumFrameSuggested; ++numAllocated)
for (numAllocated = 0; numAllocated < request->NumFrameSuggested; numAllocated ++)
{
mfxStatus sts = m_pBufferAllocator->Alloc(m_pBufferAllocator->pthis,
nbytes + MSDK_ALIGN16(sizeof(sFrame)), request->Type, &(mids.get()[numAllocated]));
nbytes + MSDK_ALIGN32(sizeof(sFrame)), request->Type, &(mids.get()[numAllocated]));
if (MFX_ERR_NONE != sts)
break;
sFrame* fs;
sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, mids.get()[numAllocated], (mfxU8**)&fs);
sFrame *fs;
sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, mids.get()[numAllocated], (mfxU8 **)&fs);
if (MFX_ERR_NONE != sts)
break;
@ -252,7 +249,7 @@ mfxStatus SysMemFrameAllocator::AllocImpl(mfxFrameAllocRequest* request, mfxFram
return MFX_ERR_NONE;
}
mfxStatus SysMemFrameAllocator::ReleaseResponse(mfxFrameAllocResponse* response)
mfxStatus SysMemFrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
{
if (!response)
return MFX_ERR_NULL_PTR;
@ -275,8 +272,7 @@ mfxStatus SysMemFrameAllocator::ReleaseResponse(mfxFrameAllocResponse* response)
}
}
delete[] response->mids;
response->mids = 0;
MSDK_SAFE_DELETE_ARRAY(response->mids);
return sts;
}
@ -292,7 +288,7 @@ SysMemBufferAllocator::~SysMemBufferAllocator()
{
}
mfxStatus SysMemBufferAllocator::AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId* mid)
mfxStatus SysMemBufferAllocator::AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId *mid)
{
if (!mid)
return MFX_ERR_NULL_PTR;
@ -300,14 +296,13 @@ mfxStatus SysMemBufferAllocator::AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemI
if (0 == (type & MFX_MEMTYPE_SYSTEM_MEMORY))
return MFX_ERR_UNSUPPORTED;
size_t allocSize = MSDK_ALIGN16(sizeof(sBuffer)) + nbytes;
mfxU8* buffer_ptr = (mfxU8*)_aligned_malloc(allocSize, 16);
MSDK_ZERO_MEMORY(buffer_ptr, allocSize);
mfxU32 header_size = MSDK_ALIGN32(sizeof(sBuffer));
mfxU8 *buffer_ptr = (mfxU8 *)calloc(header_size + nbytes, 1);
if (!buffer_ptr)
return MFX_ERR_MEMORY_ALLOC;
sBuffer* bs = (sBuffer*)buffer_ptr;
sBuffer *bs = (sBuffer *)buffer_ptr;
bs->id = ID_BUFFER;
bs->type = type;
bs->nbytes = nbytes;
@ -315,25 +310,25 @@ mfxStatus SysMemBufferAllocator::AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemI
return MFX_ERR_NONE;
}
mfxStatus SysMemBufferAllocator::LockBuffer(mfxMemId mid, mfxU8** ptr)
mfxStatus SysMemBufferAllocator::LockBuffer(mfxMemId mid, mfxU8 **ptr)
{
if (!ptr)
return MFX_ERR_NULL_PTR;
sBuffer* bs = (sBuffer*)mid;
sBuffer *bs = (sBuffer *)mid;
if (!bs)
return MFX_ERR_INVALID_HANDLE;
if (ID_BUFFER != bs->id)
return MFX_ERR_INVALID_HANDLE;
*ptr = (mfxU8*)bs + MSDK_ALIGN16(sizeof(sBuffer));
*ptr = (mfxU8 *)bs + MSDK_ALIGN32(sizeof(sBuffer));
return MFX_ERR_NONE;
}
mfxStatus SysMemBufferAllocator::UnlockBuffer(mfxMemId mid)
{
sBuffer* bs = (sBuffer*)mid;
sBuffer *bs = (sBuffer *)mid;
if (!bs || ID_BUFFER != bs->id)
return MFX_ERR_INVALID_HANDLE;
@ -343,10 +338,10 @@ mfxStatus SysMemBufferAllocator::UnlockBuffer(mfxMemId mid)
mfxStatus SysMemBufferAllocator::FreeBuffer(mfxMemId mid)
{
sBuffer* bs = (sBuffer*)mid;
sBuffer *bs = (sBuffer *)mid;
if (!bs || ID_BUFFER != bs->id)
return MFX_ERR_INVALID_HANDLE;
_aligned_free (bs);
free(bs);
return MFX_ERR_NONE;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2011, INTEL CORPORATION
* Copyright (c) 2013, INTEL CORPORATION
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
@ -32,28 +32,20 @@
struct sBuffer
{
union
{
mfxU32 id;
char idName[4];
};
mfxU32 nbytes;
mfxU16 type;
mfxU32 id;
mfxU32 nbytes;
mfxU16 type;
};
struct sFrame
{
union
{
mfxU32 id;
char idName[4];
};
mfxU32 id;
mfxFrameInfo info;
};
struct SysMemAllocatorParams : mfxAllocatorParams
{
MFXBufferAllocator* pBufferAllocator;
MFXBufferAllocator *pBufferAllocator;
};
class SysMemFrameAllocator: public BaseFrameAllocator
@ -62,18 +54,18 @@ public:
SysMemFrameAllocator();
virtual ~SysMemFrameAllocator();
virtual mfxStatus Init(mfxAllocatorParams* pParams);
virtual mfxStatus Init(mfxAllocatorParams *pParams);
virtual mfxStatus Close();
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr);
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr);
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle);
protected:
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData* ptr);
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData* ptr);
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL* handle);
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest* request);
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse* response);
virtual mfxStatus AllocImpl(mfxFrameAllocRequest* request, mfxFrameAllocResponse* response);
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest *request);
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
MFXBufferAllocator* m_pBufferAllocator;
MFXBufferAllocator *m_pBufferAllocator;
bool m_bOwnBufferAllocator;
};
@ -82,10 +74,8 @@ class SysMemBufferAllocator : public MFXBufferAllocator
public:
SysMemBufferAllocator();
virtual ~SysMemBufferAllocator();
protected:
virtual mfxStatus AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId* mid);
virtual mfxStatus LockBuffer(mfxMemId mid, mfxU8** ptr);
virtual mfxStatus AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId *mid);
virtual mfxStatus LockBuffer(mfxMemId mid, mfxU8 **ptr);
virtual mfxStatus UnlockBuffer(mfxMemId mid);
virtual mfxStatus FreeBuffer(mfxMemId mid);
};