Skip to content
This repository has been archived by the owner on May 17, 2023. It is now read-only.

Commit

Permalink
Readonly frame access when file dumping
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitry Ermilov <[email protected]>
  • Loading branch information
dmitryermilov committed Sep 23, 2021
1 parent 45b8812 commit b0eca48
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 88 deletions.
85 changes: 85 additions & 0 deletions samples/sample_common/include/base_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,90 @@ class MFXBufferAllocator : public mfxBufferAllocator
static mfxStatus MFX_CDECL Free_(mfxHDL pthis, mfxMemId mid);
};

//application can provide either generic mid from surface or this wrapper
//wrapper distinguishes from generic mid by highest 1 bit
//if it set then remained pointer points to extended structure of memid
//64 bits system layout
/*----+-----------------------------------------------------------+
|b63=1|63 bits remained for pointer to extended structure of memid|
|b63=0|63 bits from original mfxMemId |
+-----+----------------------------------------------------------*/
//32 bits system layout
/*--+---+--------------------------------------------+
|b31=1|31 bits remained for pointer to extended memid|
|b31=0|31 bits remained for surface pointer |
+---+---+-------------------------------------------*/
class MFXReadWriteMid
{
static const uintptr_t bits_offset = std::numeric_limits<uintptr_t>::digits - 1;
static const uintptr_t clear_mask = ~((uintptr_t)1 << bits_offset);
public:
enum
{
//if flag not set it means that read and write
not_set = 0,
reuse = 1,
read = 2,
write = 4,
};

//here mfxmemid might be as MFXReadWriteMid or mfxMemId memid
MFXReadWriteMid(mfxMemId mid, mfxU8 flag = not_set)
{
//setup mid
m_mid_to_report = (mfxMemId)((uintptr_t)&m_mid | ((uintptr_t)1 << bits_offset));
if (0 != ((uintptr_t)mid >> bits_offset))
{
//it points to extended structure
mfxMedIdEx* pMemIdExt = reinterpret_cast<mfxMedIdEx*>((uintptr_t)mid & clear_mask);
m_mid.pId = pMemIdExt->pId;
if (reuse == flag)
{
m_mid.read_write = pMemIdExt->read_write;
}
else
{
m_mid.read_write = flag;
}
}
else
{
m_mid.pId = mid;
if (reuse == flag)
m_mid.read_write = not_set;
else
m_mid.read_write = flag;
}

}
bool isRead() const
{
return 0 != (m_mid.read_write & read) || !m_mid.read_write;
}
bool isWrite() const
{
return 0 != (m_mid.read_write & write) || !m_mid.read_write;
}
/// returns original memid without read write flags
mfxMemId raw() const
{
return m_mid.pId;
}
operator mfxMemId() const
{
return m_mid_to_report;
}

private:
struct mfxMedIdEx
{
mfxMemId pId;
mfxU8 read_write;
};

mfxMedIdEx m_mid;
mfxMemId m_mid_to_report;
};


#endif // __BASE_ALLOCATOR_H__
85 changes: 0 additions & 85 deletions samples/sample_common/include/d3d11_allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,91 +27,6 @@ or https://software.intel.com/en-us/media-client-solutions-support.
#include <stdint.h> // for uintptr_t on Linux
#endif

//application can provide either generic mid from surface or this wrapper
//wrapper distinguishes from generic mid by highest 1 bit
//if it set then remained pointer points to extended structure of memid
//64 bits system layout
/*----+-----------------------------------------------------------+
|b63=1|63 bits remained for pointer to extended structure of memid|
|b63=0|63 bits from original mfxMemId |
+-----+----------------------------------------------------------*/
//32 bits system layout
/*--+---+--------------------------------------------+
|b31=1|31 bits remained for pointer to extended memid|
|b31=0|31 bits remained for surface pointer |
+---+---+-------------------------------------------*/
//#pragma warning (disable:4293)
class MFXReadWriteMid
{
static const uintptr_t bits_offset = std::numeric_limits<uintptr_t>::digits - 1;
static const uintptr_t clear_mask = ~((uintptr_t)1 << bits_offset);
public:
enum
{
//if flag not set it means that read and write
not_set = 0,
reuse = 1,
read = 2,
write = 4,
};
//here mfxmemid might be as MFXReadWriteMid or mfxMemId memid
MFXReadWriteMid(mfxMemId mid, mfxU8 flag = not_set)
{
//setup mid
m_mid_to_report = (mfxMemId)((uintptr_t)&m_mid | ((uintptr_t)1 << bits_offset));
if (0 != ((uintptr_t)mid >> bits_offset))
{
//it points to extended structure
mfxMedIdEx * pMemIdExt = reinterpret_cast<mfxMedIdEx *>((uintptr_t)mid & clear_mask);
m_mid.pId = pMemIdExt->pId;
if (reuse == flag)
{
m_mid.read_write = pMemIdExt->read_write;
}
else
{
m_mid.read_write = flag;
}
}
else
{
m_mid.pId = mid;
if (reuse == flag)
m_mid.read_write = not_set;
else
m_mid.read_write = flag;
}

}
bool isRead() const
{
return 0 != (m_mid.read_write & read) || !m_mid.read_write;
}
bool isWrite() const
{
return 0 != (m_mid.read_write & write) || !m_mid.read_write;
}
/// returns original memid without read write flags
mfxMemId raw() const
{
return m_mid.pId;
}
operator mfxMemId() const
{
return m_mid_to_report;
}

private:
struct mfxMedIdEx
{
mfxMemId pId;
mfxU8 read_write;
};

mfxMedIdEx m_mid;
mfxMemId m_mid_to_report;
};

#if (defined(_WIN32) || defined(_WIN64))

#include <d3d11.h>
Expand Down
2 changes: 1 addition & 1 deletion samples/sample_common/src/general_allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void GeneralAllocator::StoreFrameMids(bool isD3DFrames, mfxFrameAllocResponse
bool GeneralAllocator::isD3DMid(mfxHDL mid)
{
std::map<mfxHDL, bool>::iterator it;
it = m_Mids.find(mid);
it = m_Mids.find(MFXReadWriteMid(mid).raw());
if (it == m_Mids.end())
return false; // sys mem allocator will check validity of mid further
else
Expand Down
4 changes: 2 additions & 2 deletions samples/sample_decode/src/pipeline_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1614,11 +1614,11 @@ mfxStatus CDecodingPipeline::DeliverOutput(mfxFrameSurface1* frame)

if (m_bExternalAlloc) {
if (m_eWorkMode == MODE_FILE_DUMP) {
res = m_pGeneralAllocator->Lock(m_pGeneralAllocator->pthis, frame->Data.MemId, &(frame->Data));
res = m_pGeneralAllocator->Lock(m_pGeneralAllocator->pthis, MFXReadWriteMid(frame->Data.MemId, MFXReadWriteMid::read), &(frame->Data));
if (MFX_ERR_NONE == res) {
res = m_bOutI420 ? m_FileWriter.WriteNextFrameI420(frame)
: m_FileWriter.WriteNextFrame(frame);
sts = m_pGeneralAllocator->Unlock(m_pGeneralAllocator->pthis, frame->Data.MemId, &(frame->Data));
sts = m_pGeneralAllocator->Unlock(m_pGeneralAllocator->pthis, MFXReadWriteMid(frame->Data.MemId, MFXReadWriteMid::read), &(frame->Data));
}
if ((MFX_ERR_NONE == res) && (MFX_ERR_NONE != sts)) {
res = sts;
Expand Down

0 comments on commit b0eca48

Please sign in to comment.