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

Commit b0eca48

Browse files
committed
Readonly frame access when file dumping
Signed-off-by: Dmitry Ermilov <dmitry.ermilov@intel.com>
1 parent 45b8812 commit b0eca48

File tree

4 files changed

+88
-88
lines changed

4 files changed

+88
-88
lines changed

samples/sample_common/include/base_allocator.h

+85
Original file line numberDiff line numberDiff line change
@@ -197,5 +197,90 @@ class MFXBufferAllocator : public mfxBufferAllocator
197197
static mfxStatus MFX_CDECL Free_(mfxHDL pthis, mfxMemId mid);
198198
};
199199

200+
//application can provide either generic mid from surface or this wrapper
201+
//wrapper distinguishes from generic mid by highest 1 bit
202+
//if it set then remained pointer points to extended structure of memid
203+
//64 bits system layout
204+
/*----+-----------------------------------------------------------+
205+
|b63=1|63 bits remained for pointer to extended structure of memid|
206+
|b63=0|63 bits from original mfxMemId |
207+
+-----+----------------------------------------------------------*/
208+
//32 bits system layout
209+
/*--+---+--------------------------------------------+
210+
|b31=1|31 bits remained for pointer to extended memid|
211+
|b31=0|31 bits remained for surface pointer |
212+
+---+---+-------------------------------------------*/
213+
class MFXReadWriteMid
214+
{
215+
static const uintptr_t bits_offset = std::numeric_limits<uintptr_t>::digits - 1;
216+
static const uintptr_t clear_mask = ~((uintptr_t)1 << bits_offset);
217+
public:
218+
enum
219+
{
220+
//if flag not set it means that read and write
221+
not_set = 0,
222+
reuse = 1,
223+
read = 2,
224+
write = 4,
225+
};
226+
227+
//here mfxmemid might be as MFXReadWriteMid or mfxMemId memid
228+
MFXReadWriteMid(mfxMemId mid, mfxU8 flag = not_set)
229+
{
230+
//setup mid
231+
m_mid_to_report = (mfxMemId)((uintptr_t)&m_mid | ((uintptr_t)1 << bits_offset));
232+
if (0 != ((uintptr_t)mid >> bits_offset))
233+
{
234+
//it points to extended structure
235+
mfxMedIdEx* pMemIdExt = reinterpret_cast<mfxMedIdEx*>((uintptr_t)mid & clear_mask);
236+
m_mid.pId = pMemIdExt->pId;
237+
if (reuse == flag)
238+
{
239+
m_mid.read_write = pMemIdExt->read_write;
240+
}
241+
else
242+
{
243+
m_mid.read_write = flag;
244+
}
245+
}
246+
else
247+
{
248+
m_mid.pId = mid;
249+
if (reuse == flag)
250+
m_mid.read_write = not_set;
251+
else
252+
m_mid.read_write = flag;
253+
}
254+
255+
}
256+
bool isRead() const
257+
{
258+
return 0 != (m_mid.read_write & read) || !m_mid.read_write;
259+
}
260+
bool isWrite() const
261+
{
262+
return 0 != (m_mid.read_write & write) || !m_mid.read_write;
263+
}
264+
/// returns original memid without read write flags
265+
mfxMemId raw() const
266+
{
267+
return m_mid.pId;
268+
}
269+
operator mfxMemId() const
270+
{
271+
return m_mid_to_report;
272+
}
273+
274+
private:
275+
struct mfxMedIdEx
276+
{
277+
mfxMemId pId;
278+
mfxU8 read_write;
279+
};
280+
281+
mfxMedIdEx m_mid;
282+
mfxMemId m_mid_to_report;
283+
};
284+
200285

201286
#endif // __BASE_ALLOCATOR_H__

samples/sample_common/include/d3d11_allocator.h

-85
Original file line numberDiff line numberDiff line change
@@ -27,91 +27,6 @@ or https://software.intel.com/en-us/media-client-solutions-support.
2727
#include <stdint.h> // for uintptr_t on Linux
2828
#endif
2929

30-
//application can provide either generic mid from surface or this wrapper
31-
//wrapper distinguishes from generic mid by highest 1 bit
32-
//if it set then remained pointer points to extended structure of memid
33-
//64 bits system layout
34-
/*----+-----------------------------------------------------------+
35-
|b63=1|63 bits remained for pointer to extended structure of memid|
36-
|b63=0|63 bits from original mfxMemId |
37-
+-----+----------------------------------------------------------*/
38-
//32 bits system layout
39-
/*--+---+--------------------------------------------+
40-
|b31=1|31 bits remained for pointer to extended memid|
41-
|b31=0|31 bits remained for surface pointer |
42-
+---+---+-------------------------------------------*/
43-
//#pragma warning (disable:4293)
44-
class MFXReadWriteMid
45-
{
46-
static const uintptr_t bits_offset = std::numeric_limits<uintptr_t>::digits - 1;
47-
static const uintptr_t clear_mask = ~((uintptr_t)1 << bits_offset);
48-
public:
49-
enum
50-
{
51-
//if flag not set it means that read and write
52-
not_set = 0,
53-
reuse = 1,
54-
read = 2,
55-
write = 4,
56-
};
57-
//here mfxmemid might be as MFXReadWriteMid or mfxMemId memid
58-
MFXReadWriteMid(mfxMemId mid, mfxU8 flag = not_set)
59-
{
60-
//setup mid
61-
m_mid_to_report = (mfxMemId)((uintptr_t)&m_mid | ((uintptr_t)1 << bits_offset));
62-
if (0 != ((uintptr_t)mid >> bits_offset))
63-
{
64-
//it points to extended structure
65-
mfxMedIdEx * pMemIdExt = reinterpret_cast<mfxMedIdEx *>((uintptr_t)mid & clear_mask);
66-
m_mid.pId = pMemIdExt->pId;
67-
if (reuse == flag)
68-
{
69-
m_mid.read_write = pMemIdExt->read_write;
70-
}
71-
else
72-
{
73-
m_mid.read_write = flag;
74-
}
75-
}
76-
else
77-
{
78-
m_mid.pId = mid;
79-
if (reuse == flag)
80-
m_mid.read_write = not_set;
81-
else
82-
m_mid.read_write = flag;
83-
}
84-
85-
}
86-
bool isRead() const
87-
{
88-
return 0 != (m_mid.read_write & read) || !m_mid.read_write;
89-
}
90-
bool isWrite() const
91-
{
92-
return 0 != (m_mid.read_write & write) || !m_mid.read_write;
93-
}
94-
/// returns original memid without read write flags
95-
mfxMemId raw() const
96-
{
97-
return m_mid.pId;
98-
}
99-
operator mfxMemId() const
100-
{
101-
return m_mid_to_report;
102-
}
103-
104-
private:
105-
struct mfxMedIdEx
106-
{
107-
mfxMemId pId;
108-
mfxU8 read_write;
109-
};
110-
111-
mfxMedIdEx m_mid;
112-
mfxMemId m_mid_to_report;
113-
};
114-
11530
#if (defined(_WIN32) || defined(_WIN64))
11631

11732
#include <d3d11.h>

samples/sample_common/src/general_allocator.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ void GeneralAllocator::StoreFrameMids(bool isD3DFrames, mfxFrameAllocResponse
164164
bool GeneralAllocator::isD3DMid(mfxHDL mid)
165165
{
166166
std::map<mfxHDL, bool>::iterator it;
167-
it = m_Mids.find(mid);
167+
it = m_Mids.find(MFXReadWriteMid(mid).raw());
168168
if (it == m_Mids.end())
169169
return false; // sys mem allocator will check validity of mid further
170170
else

samples/sample_decode/src/pipeline_decode.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1614,11 +1614,11 @@ mfxStatus CDecodingPipeline::DeliverOutput(mfxFrameSurface1* frame)
16141614

16151615
if (m_bExternalAlloc) {
16161616
if (m_eWorkMode == MODE_FILE_DUMP) {
1617-
res = m_pGeneralAllocator->Lock(m_pGeneralAllocator->pthis, frame->Data.MemId, &(frame->Data));
1617+
res = m_pGeneralAllocator->Lock(m_pGeneralAllocator->pthis, MFXReadWriteMid(frame->Data.MemId, MFXReadWriteMid::read), &(frame->Data));
16181618
if (MFX_ERR_NONE == res) {
16191619
res = m_bOutI420 ? m_FileWriter.WriteNextFrameI420(frame)
16201620
: m_FileWriter.WriteNextFrame(frame);
1621-
sts = m_pGeneralAllocator->Unlock(m_pGeneralAllocator->pthis, frame->Data.MemId, &(frame->Data));
1621+
sts = m_pGeneralAllocator->Unlock(m_pGeneralAllocator->pthis, MFXReadWriteMid(frame->Data.MemId, MFXReadWriteMid::read), &(frame->Data));
16221622
}
16231623
if ((MFX_ERR_NONE == res) && (MFX_ERR_NONE != sts)) {
16241624
res = sts;

0 commit comments

Comments
 (0)