mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
init
This commit is contained in:
72
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/abstract_splitter.h
vendored
Normal file
72
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/abstract_splitter.h
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef _ABSTRACT_SPL_H__
|
||||
#define _ABSTRACT_SPL_H__
|
||||
|
||||
#include "mfxstructures.h"
|
||||
#include "vm/strings_defs.h"
|
||||
|
||||
enum SliceTypeCode {
|
||||
TYPE_I = 0,
|
||||
TYPE_P = 1,
|
||||
TYPE_B = 2,
|
||||
TYPE_SKIP=3,
|
||||
TYPE_UNKNOWN=4
|
||||
};
|
||||
|
||||
struct SliceSplitterInfo
|
||||
{
|
||||
mfxU32 DataOffset;
|
||||
mfxU32 DataLength;
|
||||
mfxU32 HeaderLength;
|
||||
SliceTypeCode SliceType;
|
||||
};
|
||||
|
||||
struct FrameSplitterInfo
|
||||
{
|
||||
SliceSplitterInfo * Slice; // array
|
||||
mfxU32 SliceNum;
|
||||
mfxU32 FirstFieldSliceNum;
|
||||
|
||||
mfxU8 * Data; // including data of slices
|
||||
mfxU32 DataLength;
|
||||
mfxU64 TimeStamp;
|
||||
};
|
||||
|
||||
class AbstractSplitter
|
||||
{
|
||||
public:
|
||||
|
||||
AbstractSplitter()
|
||||
{}
|
||||
|
||||
virtual ~AbstractSplitter()
|
||||
{}
|
||||
|
||||
virtual mfxStatus Reset() = 0;
|
||||
|
||||
virtual mfxStatus GetFrame(mfxBitstream * bs_in, FrameSplitterInfo ** frame) = 0;
|
||||
|
||||
virtual mfxStatus PostProcessing(FrameSplitterInfo *frame, mfxU32 sliceNum) = 0;
|
||||
|
||||
virtual void ResetCurrentState() = 0;
|
||||
};
|
||||
|
||||
#endif // _ABSTRACT_SPL_H__
|
||||
232
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_bitstream.h
vendored
Normal file
232
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_bitstream.h
vendored
Normal file
@@ -0,0 +1,232 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
#ifndef __AVC_BITSTREAM_H_
|
||||
#define __AVC_BITSTREAM_H_
|
||||
|
||||
#include "mfxstructures.h"
|
||||
#include "avc_structures.h"
|
||||
#include "avc_headers.h"
|
||||
|
||||
namespace ProtectedLibrary
|
||||
{
|
||||
|
||||
#define AVCPeek1Bit(current_data, offset) \
|
||||
((current_data[0] >> (offset)) & 1)
|
||||
|
||||
#define AVCDrop1Bit(current_data, offset) \
|
||||
{ \
|
||||
offset -= 1; \
|
||||
if (offset < 0) \
|
||||
{ \
|
||||
offset = 31; \
|
||||
current_data += 1; \
|
||||
} \
|
||||
}
|
||||
|
||||
// NAL unit definitions
|
||||
enum
|
||||
{
|
||||
NAL_STORAGE_IDC_BITS = 0x60,
|
||||
NAL_UNITTYPE_BITS = 0x1f
|
||||
};
|
||||
|
||||
class AVCBaseBitstream
|
||||
{
|
||||
public:
|
||||
|
||||
AVCBaseBitstream();
|
||||
AVCBaseBitstream(mfxU8 * const pb, const mfxU32 maxsize);
|
||||
virtual ~AVCBaseBitstream();
|
||||
|
||||
// Reset the bitstream with new data pointer
|
||||
void Reset(mfxU8 * const pb, mfxU32 maxsize);
|
||||
void Reset(mfxU8 * const pb, mfxI32 offset, mfxU32 maxsize);
|
||||
|
||||
inline mfxU32 GetBits(mfxU32 nbits);
|
||||
|
||||
// Read one VLC mfxI32 or mfxU32 value from bitstream
|
||||
mfxI32 GetVLCElement(bool bIsSigned);
|
||||
|
||||
// Reads one bit from the buffer.
|
||||
inline mfxU32 Get1Bit();
|
||||
|
||||
// Check amount of data
|
||||
bool More_RBSP_Data();
|
||||
|
||||
inline mfxU32 BytesDecoded();
|
||||
|
||||
inline mfxU32 BitsDecoded();
|
||||
|
||||
inline mfxU32 BytesLeft();
|
||||
|
||||
mfxStatus GetNALUnitType(NAL_Unit_Type &uNALUnitType, mfxU8 &uNALStorageIDC);
|
||||
void AlignPointerRight(void);
|
||||
|
||||
protected:
|
||||
mfxU32 *m_pbs; // pointer to the current position of the buffer.
|
||||
mfxI32 m_bitOffset; // the bit position (0 to 31) in the dword pointed by m_pbs.
|
||||
mfxU32 *m_pbsBase; // pointer to the first byte of the buffer.
|
||||
mfxU32 m_maxBsSize; // maximum buffer size in bytes.
|
||||
};
|
||||
|
||||
class AVCHeadersBitstream : public AVCBaseBitstream
|
||||
{
|
||||
public:
|
||||
|
||||
AVCHeadersBitstream();
|
||||
AVCHeadersBitstream(mfxU8 * const pb, const mfxU32 maxsize);
|
||||
|
||||
|
||||
// Decode sequence parameter set
|
||||
mfxStatus GetSequenceParamSet(AVCSeqParamSet *sps);
|
||||
// Decode sequence parameter set extension
|
||||
mfxStatus GetSequenceParamSetExtension(AVCSeqParamSetExtension *sps_ex);
|
||||
|
||||
// Decoding picture's parameter set functions
|
||||
mfxStatus GetPictureParamSetPart1(AVCPicParamSet *pps);
|
||||
mfxStatus GetPictureParamSetPart2(AVCPicParamSet *pps, const AVCSeqParamSet *sps);
|
||||
|
||||
mfxStatus GetSliceHeaderPart1(AVCSliceHeader *pSliceHeader);
|
||||
// Decoding slice header functions
|
||||
mfxStatus GetSliceHeaderPart2(AVCSliceHeader *hdr, // slice header read goes here
|
||||
const AVCPicParamSet *pps,
|
||||
const AVCSeqParamSet *sps); // from slice header NAL unit
|
||||
|
||||
mfxStatus GetSliceHeaderPart3(AVCSliceHeader *hdr, // slice header read goes here
|
||||
PredWeightTable *pPredWeight_L0, // L0 weight table goes here
|
||||
PredWeightTable *pPredWeight_L1, // L1 weight table goes here
|
||||
RefPicListReorderInfo *pReorderInfo_L0,
|
||||
RefPicListReorderInfo *pReorderInfo_L1,
|
||||
AdaptiveMarkingInfo *pAdaptiveMarkingInfo,
|
||||
const AVCPicParamSet *pps,
|
||||
const AVCSeqParamSet *sps,
|
||||
mfxU8 NALRef_idc); // from slice header NAL unit
|
||||
|
||||
|
||||
mfxStatus GetNalUnitPrefix(AVCNalExtension *pExt, mfxU32 NALRef_idc);
|
||||
|
||||
mfxI32 GetSEI(const HeaderSet<AVCSeqParamSet> & sps, mfxI32 current_sps, AVCSEIPayLoad *spl);
|
||||
|
||||
private:
|
||||
|
||||
mfxStatus GetNalUnitExtension(AVCNalExtension *pExt);
|
||||
|
||||
void GetScalingList4x4(AVCScalingList4x4 *scl, mfxU8 *def, mfxU8 *scl_type);
|
||||
void GetScalingList8x8(AVCScalingList8x8 *scl, mfxU8 *def, mfxU8 *scl_type);
|
||||
|
||||
mfxI32 GetSEIPayload(const HeaderSet<AVCSeqParamSet> & sps, mfxI32 current_sps, AVCSEIPayLoad *spl);
|
||||
mfxI32 recovery_point(const HeaderSet<AVCSeqParamSet> & sps, mfxI32 current_sps, AVCSEIPayLoad *spl);
|
||||
mfxI32 reserved_sei_message(const HeaderSet<AVCSeqParamSet> & sps, mfxI32 current_sps, AVCSEIPayLoad *spl);
|
||||
|
||||
mfxStatus GetVUIParam(AVCSeqParamSet *sps);
|
||||
mfxStatus GetHRDParam(AVCSeqParamSet *sps);
|
||||
};
|
||||
|
||||
|
||||
void SetDefaultScalingLists(AVCSeqParamSet * sps);
|
||||
|
||||
extern const mfxU32 bits_data[];
|
||||
|
||||
|
||||
#define _avcGetBits(current_data, offset, nbits, data) \
|
||||
{ \
|
||||
mfxU32 x; \
|
||||
\
|
||||
SAMPLE_ASSERT((nbits) > 0 && (nbits) <= 32); \
|
||||
SAMPLE_ASSERT(offset >= 0 && offset <= 31); \
|
||||
\
|
||||
offset -= (nbits); \
|
||||
\
|
||||
if (offset >= 0) \
|
||||
{ \
|
||||
x = current_data[0] >> (offset + 1); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
offset += 32; \
|
||||
\
|
||||
x = current_data[1] >> (offset); \
|
||||
x >>= 1; \
|
||||
x += current_data[0] << (31 - offset); \
|
||||
current_data++; \
|
||||
} \
|
||||
\
|
||||
SAMPLE_ASSERT(offset >= 0 && offset <= 31); \
|
||||
\
|
||||
(data) = x & bits_data[nbits]; \
|
||||
}
|
||||
|
||||
#define avcGetBits1(current_data, offset, data) \
|
||||
{ \
|
||||
data = ((current_data[0] >> (offset)) & 1); \
|
||||
offset -= 1; \
|
||||
if (offset < 0) \
|
||||
{ \
|
||||
offset = 31; \
|
||||
current_data += 1; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define avcUngetNBits(current_data, offset, nbits) \
|
||||
{ \
|
||||
SAMPLE_ASSERT(offset >= 0 && offset <= 31); \
|
||||
\
|
||||
offset += (nbits); \
|
||||
if (offset > 31) \
|
||||
{ \
|
||||
offset -= 32; \
|
||||
current_data--; \
|
||||
} \
|
||||
\
|
||||
SAMPLE_ASSERT(offset >= 0 && offset <= 31); \
|
||||
}
|
||||
|
||||
#define avcGetNBits( current_data, offset, nbits, data) \
|
||||
_avcGetBits(current_data, offset, nbits, data);
|
||||
|
||||
inline mfxU32 AVCBaseBitstream::GetBits(mfxU32 nbits)
|
||||
{
|
||||
mfxU32 w, n = nbits;
|
||||
|
||||
avcGetNBits(m_pbs, m_bitOffset, n, w);
|
||||
return w;
|
||||
}
|
||||
|
||||
inline mfxU32 AVCBaseBitstream::Get1Bit()
|
||||
{
|
||||
mfxU32 w;
|
||||
avcGetBits1(m_pbs, m_bitOffset, w);
|
||||
return w;
|
||||
|
||||
} // AVCBitstream::Get1Bit()
|
||||
|
||||
inline mfxU32 AVCBaseBitstream::BytesDecoded()
|
||||
{
|
||||
return static_cast<mfxU32>((mfxU8*)m_pbs - (mfxU8*)m_pbsBase) +
|
||||
((31 - m_bitOffset) >> 3);
|
||||
}
|
||||
|
||||
inline mfxU32 AVCBaseBitstream::BytesLeft()
|
||||
{
|
||||
return ((mfxI32)m_maxBsSize - (mfxI32) BytesDecoded());
|
||||
}
|
||||
|
||||
} // namespace ProtectedLibrary
|
||||
|
||||
#endif // __AVC_BITSTREAM_H_
|
||||
157
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_headers.h
vendored
Normal file
157
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_headers.h
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __AVC_HEADERS_H
|
||||
#define __AVC_HEADERS_H
|
||||
|
||||
#include "avc_structures.h"
|
||||
#include <vector>
|
||||
|
||||
namespace ProtectedLibrary
|
||||
{
|
||||
|
||||
template <typename T>
|
||||
class HeaderSet
|
||||
{
|
||||
public:
|
||||
|
||||
HeaderSet()
|
||||
: m_currentID(-1)
|
||||
{
|
||||
}
|
||||
|
||||
~HeaderSet()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void AddHeader(T* hdr)
|
||||
{
|
||||
mfxU32 id = hdr->GetID();
|
||||
if (id >= m_header.size())
|
||||
{
|
||||
m_header.resize(id + 1);
|
||||
}
|
||||
|
||||
delete m_header[id];
|
||||
|
||||
m_header[id] = new T();
|
||||
*(m_header[id]) = *hdr;
|
||||
}
|
||||
|
||||
T * GetHeader(mfxU32 id)
|
||||
{
|
||||
if (id >= m_header.size())
|
||||
return 0;
|
||||
|
||||
return m_header[id];
|
||||
}
|
||||
|
||||
void RemoveHeader(mfxU32 id)
|
||||
{
|
||||
if (id >= m_header.size())
|
||||
return;
|
||||
|
||||
delete m_header[id];
|
||||
m_header[id] = 0;
|
||||
}
|
||||
|
||||
void RemoveHeader(T * hdr)
|
||||
{
|
||||
if (!hdr)
|
||||
return;
|
||||
|
||||
RemoveHeader(hdr->GetID());
|
||||
}
|
||||
|
||||
const T * GetHeader(mfxU32 id) const
|
||||
{
|
||||
if (id >= m_header.size())
|
||||
return 0;
|
||||
|
||||
return m_header[id];
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
for (mfxU32 i = 0; i < m_header.size(); i++)
|
||||
{
|
||||
delete m_header[i];
|
||||
m_header[i]=0;
|
||||
}
|
||||
}
|
||||
|
||||
void SetCurrentID(mfxU32 id)
|
||||
{
|
||||
m_currentID = id;
|
||||
}
|
||||
|
||||
mfxI32 GetCurrrentID() const
|
||||
{
|
||||
return m_currentID;
|
||||
}
|
||||
|
||||
T * GetCurrentHeader()
|
||||
{
|
||||
if (m_currentID == -1)
|
||||
return 0;
|
||||
|
||||
return GetHeader(m_currentID);
|
||||
}
|
||||
|
||||
const T * GetCurrentHeader() const
|
||||
{
|
||||
if (m_currentID == -1)
|
||||
return 0;
|
||||
|
||||
return GetHeader(m_currentID);
|
||||
}
|
||||
|
||||
private:
|
||||
std::vector<T*> m_header;
|
||||
mfxI32 m_currentID;
|
||||
};
|
||||
|
||||
/****************************************************************************************************/
|
||||
// Headers stuff
|
||||
/****************************************************************************************************/
|
||||
class AVCHeaders
|
||||
{
|
||||
public:
|
||||
|
||||
void Reset()
|
||||
{
|
||||
m_SeqParams.Reset();
|
||||
m_SeqExParams.Reset();
|
||||
m_SeqParamsMvcExt.Reset();
|
||||
m_PicParams.Reset();
|
||||
m_SEIParams.Reset();
|
||||
}
|
||||
|
||||
HeaderSet<AVCSeqParamSet> m_SeqParams;
|
||||
HeaderSet<AVCSeqParamSetExtension> m_SeqExParams;
|
||||
HeaderSet<AVCSeqParamSet> m_SeqParamsMvcExt;
|
||||
HeaderSet<AVCPicParamSet> m_PicParams;
|
||||
HeaderSet<AVCSEIPayLoad> m_SEIParams;
|
||||
AVCNalExtension m_nalExtension;
|
||||
};
|
||||
|
||||
} //namespace ProtectedLibrary
|
||||
|
||||
#endif // __AVC_HEADERS_H
|
||||
101
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_nal_spl.h
vendored
Normal file
101
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_nal_spl.h
vendored
Normal file
@@ -0,0 +1,101 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
#ifndef __AVC_NAL_SPL_H
|
||||
#define __AVC_NAL_SPL_H
|
||||
|
||||
#include <vector>
|
||||
#include "mfxstructures.h"
|
||||
|
||||
namespace ProtectedLibrary
|
||||
{
|
||||
|
||||
class BytesSwapper
|
||||
{
|
||||
public:
|
||||
static void SwapMemory(mfxU8 *pDestination, mfxU32 &nDstSize, mfxU8 *pSource, mfxU32 nSrcSize);
|
||||
};
|
||||
|
||||
|
||||
class StartCodeIterator
|
||||
{
|
||||
public:
|
||||
|
||||
StartCodeIterator();
|
||||
|
||||
void Reset();
|
||||
|
||||
mfxI32 Init(mfxBitstream * source);
|
||||
|
||||
void SetSuggestedSize(mfxU32 size);
|
||||
|
||||
mfxI32 CheckNalUnitType(mfxBitstream * source);
|
||||
|
||||
mfxI32 GetNALUnit(mfxBitstream * source, mfxBitstream * destination);
|
||||
|
||||
mfxI32 EndOfStream(mfxBitstream * destination);
|
||||
|
||||
private:
|
||||
std::vector<mfxU8> m_prev;
|
||||
mfxU32 m_code;
|
||||
mfxU64 m_pts;
|
||||
|
||||
mfxU8 * m_pSource;
|
||||
mfxU32 m_nSourceSize;
|
||||
|
||||
mfxU8 * m_pSourceBase;
|
||||
mfxU32 m_nSourceBaseSize;
|
||||
|
||||
mfxU32 m_suggestedSize;
|
||||
|
||||
mfxI32 FindStartCode(mfxU8 * (&pb), mfxU32 & size, mfxI32 & startCodeSize);
|
||||
};
|
||||
|
||||
class NALUnitSplitter
|
||||
{
|
||||
public:
|
||||
|
||||
NALUnitSplitter();
|
||||
|
||||
virtual ~NALUnitSplitter();
|
||||
|
||||
virtual void Init();
|
||||
virtual void Release();
|
||||
|
||||
virtual mfxI32 CheckNalUnitType(mfxBitstream * source);
|
||||
virtual mfxI32 GetNalUnits(mfxBitstream * source, mfxBitstream * &destination);
|
||||
|
||||
virtual void Reset();
|
||||
|
||||
virtual void SetSuggestedSize(mfxU32 size)
|
||||
{
|
||||
m_pStartCodeIter.SetSuggestedSize(size);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
StartCodeIterator m_pStartCodeIter;
|
||||
|
||||
mfxBitstream m_bitstream;
|
||||
};
|
||||
|
||||
void SwapMemoryAndRemovePreventingBytes(mfxU8 *pDestination, mfxU32 &nDstSize, mfxU8 *pSource, mfxU32 nSrcSize);
|
||||
|
||||
} //namespace ProtectedLibrary
|
||||
|
||||
#endif // __AVC_NAL_SPL_H
|
||||
140
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_spl.h
vendored
Normal file
140
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_spl.h
vendored
Normal file
@@ -0,0 +1,140 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef _AVC_SPL_H__
|
||||
#define _AVC_SPL_H__
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
#include <memory>
|
||||
|
||||
#include "abstract_splitter.h"
|
||||
|
||||
#include "avc_bitstream.h"
|
||||
#include "avc_headers.h"
|
||||
#include "avc_nal_spl.h"
|
||||
|
||||
namespace ProtectedLibrary
|
||||
{
|
||||
|
||||
class AVCSlice : public SliceSplitterInfo
|
||||
{
|
||||
public:
|
||||
|
||||
AVCSlice();
|
||||
|
||||
AVCSliceHeader * GetSliceHeader();
|
||||
|
||||
bool IsField() const {return m_sliceHeader.field_pic_flag != 0;}
|
||||
|
||||
mfxI32 RetrievePicParamSetNumber(mfxU8 *pSource, mfxU32 nSourceSize);
|
||||
|
||||
bool DecodeHeader(mfxU8 *pSource, mfxU32 nSourceSize);
|
||||
|
||||
AVCHeadersBitstream *GetBitStream(void){return &m_bitStream;}
|
||||
|
||||
AVCPicParamSet* m_picParamSet;
|
||||
AVCSeqParamSet* m_seqParamSet;
|
||||
AVCSeqParamSet* m_seqParamSetMvcEx;
|
||||
AVCSeqParamSetExtension* m_seqParamSetEx;
|
||||
|
||||
mfxU64 m_dTime;
|
||||
|
||||
protected:
|
||||
AVCSliceHeader m_sliceHeader;
|
||||
AVCHeadersBitstream m_bitStream;
|
||||
|
||||
void Reset();
|
||||
};
|
||||
|
||||
class AVCFrameInfo
|
||||
{
|
||||
public:
|
||||
|
||||
AVCFrameInfo();
|
||||
|
||||
void Reset();
|
||||
|
||||
AVCSlice * m_slice;
|
||||
mfxU32 m_index;
|
||||
};
|
||||
|
||||
class AVC_Spl : public AbstractSplitter
|
||||
{
|
||||
public:
|
||||
|
||||
AVC_Spl();
|
||||
|
||||
virtual ~AVC_Spl();
|
||||
|
||||
virtual mfxStatus Reset();
|
||||
|
||||
virtual mfxStatus GetFrame(mfxBitstream * bs_in, FrameSplitterInfo ** frame);
|
||||
|
||||
virtual mfxStatus PostProcessing(FrameSplitterInfo *frame, mfxU32 sliceNum);
|
||||
|
||||
void ResetCurrentState();
|
||||
|
||||
protected:
|
||||
std::unique_ptr<NALUnitSplitter> m_pNALSplitter;
|
||||
|
||||
mfxStatus Init();
|
||||
|
||||
void Close();
|
||||
|
||||
mfxStatus ProcessNalUnit(mfxI32 nalType, mfxBitstream * destination);
|
||||
|
||||
mfxStatus DecodeHeader(mfxBitstream * nalUnit);
|
||||
mfxStatus DecodeSEI(mfxBitstream * nalUnit);
|
||||
AVCSlice * DecodeSliceHeader(mfxBitstream * nalUnit);
|
||||
mfxStatus AddSlice(AVCSlice * pSlice);
|
||||
|
||||
AVCFrameInfo * GetFreeFrame();
|
||||
|
||||
mfxU8 * GetMemoryForSwapping(mfxU32 size);
|
||||
|
||||
mfxStatus AddNalUnit(mfxBitstream * nalUnit);
|
||||
mfxStatus AddSliceNalUnit(mfxBitstream * nalUnit, AVCSlice * pSlice);
|
||||
bool IsFieldOfOneFrame(AVCFrameInfo * frame, const AVCSliceHeader * slice1, const AVCSliceHeader *slice2);
|
||||
|
||||
bool m_WaitForIDR;
|
||||
|
||||
AVCHeaders m_headers;
|
||||
std::unique_ptr<AVCFrameInfo> m_AUInfo;
|
||||
AVCFrameInfo * m_currentInfo;
|
||||
AVCSlice * m_pLastSlice;
|
||||
|
||||
mfxBitstream * m_lastNalUnit;
|
||||
|
||||
enum
|
||||
{
|
||||
BUFFER_SIZE = 1024 * 1024
|
||||
};
|
||||
|
||||
std::vector<mfxU8> m_currentFrame;
|
||||
std::vector<mfxU8> m_swappingMemory;
|
||||
std::list<AVCSlice> m_slicesStorage;
|
||||
|
||||
std::vector<SliceSplitterInfo> m_slices;
|
||||
FrameSplitterInfo m_frame;
|
||||
};
|
||||
|
||||
} // namespace ProtectedLibrary
|
||||
|
||||
#endif // _AVC_SPL_H__
|
||||
1107
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_structures.h
vendored
Normal file
1107
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/avc_structures.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
201
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/base_allocator.h
vendored
Normal file
201
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/base_allocator.h
vendored
Normal file
@@ -0,0 +1,201 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __BASE_ALLOCATOR_H__
|
||||
#define __BASE_ALLOCATOR_H__
|
||||
|
||||
#include <list>
|
||||
#include <string.h>
|
||||
#include <functional>
|
||||
#include "mfxvideo.h"
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
struct mfxAllocatorParams
|
||||
{
|
||||
virtual ~mfxAllocatorParams(){};
|
||||
};
|
||||
|
||||
// this class implements methods declared in mfxFrameAllocator structure
|
||||
// simply redirecting them to virtual methods which should be overridden in derived classes
|
||||
class MFXFrameAllocator : public mfxFrameAllocator
|
||||
{
|
||||
public:
|
||||
MFXFrameAllocator();
|
||||
virtual ~MFXFrameAllocator();
|
||||
|
||||
// optional method, override if need to pass some parameters to allocator from application
|
||||
virtual mfxStatus Init(mfxAllocatorParams *pParams) = 0;
|
||||
virtual mfxStatus Close() = 0;
|
||||
|
||||
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) = 0;
|
||||
virtual mfxStatus ReallocFrame(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut) = 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 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
|
||||
// Manages responses for different components according to allocation request type
|
||||
// External frames of a particular component-related type are allocated in one call
|
||||
// Further calls return previously allocated response.
|
||||
// Ex. Preallocated frame chain with type=FROM_ENCODE | FROM_VPPIN will be returned when
|
||||
// request type contains either FROM_ENCODE or FROM_VPPIN
|
||||
|
||||
// This class does not allocate any actual memory
|
||||
|
||||
class BaseFrameAllocator: public MFXFrameAllocator
|
||||
{
|
||||
public:
|
||||
BaseFrameAllocator();
|
||||
virtual ~BaseFrameAllocator();
|
||||
|
||||
virtual mfxStatus Init(mfxAllocatorParams *pParams) = 0;
|
||||
virtual mfxStatus Close();
|
||||
virtual mfxStatus AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus ReallocFrame(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut);
|
||||
virtual mfxStatus FreeFrames(mfxFrameAllocResponse *response);
|
||||
|
||||
protected:
|
||||
std::mutex mtx;
|
||||
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 | \
|
||||
MFX_MEMTYPE_FROM_ENC | MFX_MEMTYPE_FROM_PAK;
|
||||
|
||||
static const mfxU32 MEMTYPE_FROM_MASK_INT_EXT = MEMTYPE_FROM_MASK | MFX_MEMTYPE_INTERNAL_FRAME | MFX_MEMTYPE_EXTERNAL_FRAME;
|
||||
|
||||
struct UniqueResponse
|
||||
: mfxFrameAllocResponse
|
||||
{
|
||||
mfxU16 m_width;
|
||||
mfxU16 m_height;
|
||||
mfxU32 m_refCount;
|
||||
mfxU16 m_type;
|
||||
|
||||
UniqueResponse()
|
||||
: m_width(0)
|
||||
, m_height(0)
|
||||
, m_refCount(0)
|
||||
, m_type(0)
|
||||
{
|
||||
memset(static_cast<mfxFrameAllocResponse*>(this), 0, sizeof(mfxFrameAllocResponse));
|
||||
}
|
||||
|
||||
// compare responses by actual frame size, alignment (w and h) is up to application
|
||||
UniqueResponse(const mfxFrameAllocResponse & response, mfxU16 width, mfxU16 height, mfxU16 type)
|
||||
: mfxFrameAllocResponse(response)
|
||||
, m_width(width)
|
||||
, m_height(height)
|
||||
, m_refCount(1)
|
||||
, m_type(type)
|
||||
{
|
||||
}
|
||||
|
||||
//compare by resolution (and memory type for FEI ENC / PAK)
|
||||
bool operator () (const UniqueResponse &response)const
|
||||
{
|
||||
if (m_width <= response.m_width && m_height <= response.m_height)
|
||||
{
|
||||
// For FEI ENC and PAK we need to distinguish between INTERNAL and EXTERNAL frames
|
||||
|
||||
if (m_type & response.m_type & (MFX_MEMTYPE_FROM_ENC | MFX_MEMTYPE_FROM_PAK))
|
||||
{
|
||||
return !!((m_type & response.m_type) & 0x000f);
|
||||
}
|
||||
else
|
||||
{
|
||||
return !!(m_type & response.m_type & MFX_MEMTYPE_FROM_DECODE);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static mfxU16 CropMemoryTypeToStore(mfxU16 type)
|
||||
{
|
||||
// Remain INTERNAL / EXTERNAL flag for FEI ENC / PAK
|
||||
switch (type & 0xf000)
|
||||
{
|
||||
case MFX_MEMTYPE_FROM_ENC:
|
||||
case MFX_MEMTYPE_FROM_PAK:
|
||||
case (MFX_MEMTYPE_FROM_ENC | MFX_MEMTYPE_FROM_PAK):
|
||||
return type & MEMTYPE_FROM_MASK_INT_EXT;
|
||||
break;
|
||||
default:
|
||||
return type & MEMTYPE_FROM_MASK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
std::list<mfxFrameAllocResponse> m_responses;
|
||||
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);
|
||||
|
||||
// frees memory attached to response
|
||||
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response) = 0;
|
||||
// allocates memory
|
||||
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response) = 0;
|
||||
virtual mfxStatus ReallocImpl(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut) = 0;
|
||||
};
|
||||
|
||||
class MFXBufferAllocator : public mfxBufferAllocator
|
||||
{
|
||||
public:
|
||||
MFXBufferAllocator();
|
||||
virtual ~MFXBufferAllocator();
|
||||
|
||||
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 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);
|
||||
};
|
||||
|
||||
|
||||
#endif // __BASE_ALLOCATOR_H__
|
||||
425
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/brc_routines.h
vendored
Normal file
425
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/brc_routines.h
vendored
Normal file
@@ -0,0 +1,425 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
#include "sample_defs.h"
|
||||
#include "algorithm"
|
||||
|
||||
#ifndef MFX_VERSION
|
||||
#error MFX_VERSION not defined
|
||||
#endif
|
||||
|
||||
#if (MFX_VERSION >= 1024)
|
||||
#include "mfxbrc.h"
|
||||
|
||||
#ifndef __PIPELINE_ENCODE_BRC_H__
|
||||
#define __PIPELINE_ENCODE_BRC_H__
|
||||
|
||||
#define MFX_CHECK_NULL_PTR1(pointer) MSDK_CHECK_POINTER(pointer, MFX_ERR_NULL_PTR);
|
||||
|
||||
#define MFX_CHECK_NULL_PTR2(pointer1,pointer2 )\
|
||||
MFX_CHECK_NULL_PTR1(pointer1);\
|
||||
MFX_CHECK_NULL_PTR1(pointer2);
|
||||
|
||||
#define MFX_CHECK_NULL_PTR3(pointer1,pointer2, pointer3 )\
|
||||
MFX_CHECK_NULL_PTR2(pointer1,pointer2);\
|
||||
MFX_CHECK_NULL_PTR1(pointer3);
|
||||
|
||||
#define MFX_CHECK(cond, error) MSDK_CHECK_NOT_EQUAL(cond, true, error)
|
||||
#define MFX_CHECK_STS(sts) MFX_CHECK(sts == MFX_ERR_NONE, sts)
|
||||
|
||||
|
||||
/*
|
||||
NalHrdConformance | VuiNalHrdParameters | Result
|
||||
--------------------------------------------------------------
|
||||
off any => MFX_BRC_NO_HRD
|
||||
default off => MFX_BRC_NO_HRD
|
||||
on off => MFX_BRC_HRD_WEAK
|
||||
on (or default) on (or default) => MFX_BRC_HRD_STRONG
|
||||
--------------------------------------------------------------
|
||||
*/
|
||||
enum : mfxU16
|
||||
{
|
||||
MFX_BRC_NO_HRD = 0,
|
||||
MFX_BRC_HRD_WEAK, // IF HRD CALCULATION IS REQUIRED, BUT NOT WRITTEN TO THE STREAM
|
||||
MFX_BRC_HRD_STRONG
|
||||
};
|
||||
|
||||
class cBRCParams
|
||||
{
|
||||
public:
|
||||
mfxU16 rateControlMethod; // CBR or VBR
|
||||
|
||||
mfxU16 HRDConformance; // is HRD compliance needed
|
||||
mfxU16 bRec; // is Recoding possible
|
||||
mfxU16 bPanic; // is Panic mode possible
|
||||
|
||||
// HRD params
|
||||
mfxU32 bufferSizeInBytes;
|
||||
mfxU32 initialDelayInBytes;
|
||||
|
||||
// Sliding window parameters
|
||||
mfxU16 WinBRCMaxAvgKbps;
|
||||
mfxU16 WinBRCSize;
|
||||
|
||||
// RC params
|
||||
mfxU32 targetbps;
|
||||
mfxU32 maxbps;
|
||||
mfxF64 frameRate;
|
||||
mfxF64 inputBitsPerFrame;
|
||||
mfxF64 maxInputBitsPerFrame;
|
||||
mfxU32 maxFrameSizeInBits;
|
||||
|
||||
// Frame size params
|
||||
mfxU16 width;
|
||||
mfxU16 height;
|
||||
mfxU16 chromaFormat;
|
||||
mfxU16 bitDepthLuma;
|
||||
|
||||
// GOP params
|
||||
mfxU16 gopPicSize;
|
||||
mfxU16 gopRefDist;
|
||||
bool bPyr;
|
||||
|
||||
//BRC accurancy params
|
||||
mfxF64 fAbPeriodLong; // number on frames to calculate abberation from target frame
|
||||
mfxF64 fAbPeriodShort; // number on frames to calculate abberation from target frame
|
||||
mfxF64 dqAbPeriod; // number on frames to calculate abberation from dequant
|
||||
mfxF64 bAbPeriod; // number of frames to calculate abberation from target bitrate
|
||||
|
||||
//QP parameters
|
||||
mfxI32 quantOffset;
|
||||
mfxI32 quantMaxI;
|
||||
mfxI32 quantMinI;
|
||||
mfxI32 quantMaxP;
|
||||
mfxI32 quantMinP;
|
||||
mfxI32 quantMaxB;
|
||||
mfxI32 quantMinB;
|
||||
|
||||
public:
|
||||
cBRCParams():
|
||||
rateControlMethod(0),
|
||||
HRDConformance(MFX_BRC_NO_HRD),
|
||||
bRec(0),
|
||||
bPanic(0),
|
||||
bufferSizeInBytes(0),
|
||||
initialDelayInBytes(0),
|
||||
WinBRCMaxAvgKbps(0),
|
||||
WinBRCSize(0),
|
||||
targetbps(0),
|
||||
maxbps(0),
|
||||
frameRate(0),
|
||||
inputBitsPerFrame(0),
|
||||
maxInputBitsPerFrame(0),
|
||||
maxFrameSizeInBits(0),
|
||||
width(0),
|
||||
height(0),
|
||||
chromaFormat(0),
|
||||
bitDepthLuma(0),
|
||||
gopPicSize(0),
|
||||
gopRefDist(0),
|
||||
bPyr(0),
|
||||
fAbPeriodLong(0),
|
||||
fAbPeriodShort(0),
|
||||
dqAbPeriod(0),
|
||||
bAbPeriod(0),
|
||||
quantOffset(0),
|
||||
quantMaxI(0),
|
||||
quantMinI(0),
|
||||
quantMaxP(0),
|
||||
quantMinP(0),
|
||||
quantMaxB(0),
|
||||
quantMinB(0)
|
||||
{}
|
||||
|
||||
mfxStatus Init(mfxVideoParam* par, bool bFieldMode = false);
|
||||
mfxStatus GetBRCResetType(mfxVideoParam* par, bool bNewSequence, bool &bReset, bool &bSlidingWindowReset );
|
||||
};
|
||||
class cHRD
|
||||
{
|
||||
public:
|
||||
cHRD():
|
||||
m_bufFullness(0),
|
||||
m_prevBufFullness(0),
|
||||
m_frameNum(0),
|
||||
m_minFrameSize(0),
|
||||
m_maxFrameSize(0),
|
||||
m_underflowQuant(0),
|
||||
m_overflowQuant(0),
|
||||
m_buffSizeInBits(0),
|
||||
m_delayInBits(0),
|
||||
m_inputBitsPerFrame(0),
|
||||
m_bCBR (false)
|
||||
{}
|
||||
|
||||
void Init(mfxU32 buffSizeInBytes, mfxU32 delayInBytes, mfxF64 inputBitsPerFrame, bool cbr);
|
||||
mfxU16 UpdateAndCheckHRD(mfxI32 frameBits, mfxI32 recode, mfxI32 minQuant, mfxI32 maxQuant);
|
||||
mfxStatus UpdateMinMaxQPForRec(mfxU32 brcSts, mfxI32 qp);
|
||||
mfxI32 GetTargetSize(mfxU32 brcSts);
|
||||
mfxI32 GetMaxFrameSize() { return m_maxFrameSize;}
|
||||
mfxI32 GetMinFrameSize() { return m_minFrameSize;}
|
||||
mfxI32 GetMaxQuant() { return m_overflowQuant - 1;}
|
||||
mfxI32 GetMinQuant() { return m_underflowQuant + 1;}
|
||||
mfxF64 GetBufferDiviation(mfxU32 targetBitrate);
|
||||
|
||||
|
||||
|
||||
private:
|
||||
mfxF64 m_bufFullness;
|
||||
mfxF64 m_prevBufFullness;
|
||||
mfxI32 m_frameNum;
|
||||
mfxI32 m_minFrameSize;
|
||||
mfxI32 m_maxFrameSize;
|
||||
mfxI32 m_underflowQuant;
|
||||
mfxI32 m_overflowQuant;
|
||||
|
||||
private:
|
||||
mfxI32 m_buffSizeInBits;
|
||||
mfxI32 m_delayInBits;
|
||||
mfxF64 m_inputBitsPerFrame;
|
||||
bool m_bCBR;
|
||||
|
||||
};
|
||||
|
||||
struct BRC_Ctx
|
||||
{
|
||||
mfxI32 QuantI; //currect qp for intra frames
|
||||
mfxI32 QuantP; //currect qp for P frames
|
||||
mfxI32 QuantB; //currect qp for B frames
|
||||
|
||||
mfxI32 Quant; // qp for last encoded frame
|
||||
mfxI32 QuantMin; // qp Min for last encoded frame (is used for recoding)
|
||||
mfxI32 QuantMax; // qp Max for last encoded frame (is used for recoding)
|
||||
|
||||
bool bToRecode; // last frame is needed in recoding
|
||||
bool bPanic; // last frame is needed in panic
|
||||
mfxU32 encOrder; // encoding order of last encoded frame
|
||||
mfxU32 poc; // poc of last encoded frame
|
||||
mfxI32 SceneChange; // scene change parameter of last encoded frame
|
||||
mfxU32 SChPoc; // poc of frame with scene change
|
||||
mfxU32 LastIEncOrder; // encoded order if last intra frame
|
||||
mfxU32 LastNonBFrameSize; // encoded frame size of last non B frame (is used for sceneChange)
|
||||
|
||||
mfxF64 fAbLong; // avarage frame size (long period)
|
||||
mfxF64 fAbShort; // avarage frame size (short period)
|
||||
mfxF64 dQuantAb; // avarage dequant
|
||||
mfxF64 totalDiviation; // divation from target bitrate (total)
|
||||
|
||||
mfxF64 eRate; // eRate of last encoded frame, this parameter is used for scene change calculation
|
||||
mfxF64 eRateSH; // eRate of last encoded scene change frame, this parameter is used for scene change calculation
|
||||
};
|
||||
class AVGBitrate
|
||||
{
|
||||
public:
|
||||
AVGBitrate(mfxU32 windowSize, mfxU32 maxBitPerFrame, mfxU32 avgBitPerFrame) :
|
||||
m_maxWinBits(maxBitPerFrame*windowSize),
|
||||
m_maxWinBitsLim(0),
|
||||
m_avgBitPerFrame(std::min(avgBitPerFrame, maxBitPerFrame)),
|
||||
m_currPosInWindow(windowSize-1),
|
||||
m_lastFrameOrder(mfxU32(-1))
|
||||
|
||||
{
|
||||
windowSize = windowSize > 0 ? windowSize : 1; // kw
|
||||
m_slidingWindow.resize(windowSize);
|
||||
for (mfxU32 i = 0; i < windowSize; i++)
|
||||
{
|
||||
m_slidingWindow[i] = maxBitPerFrame / 3; //initial value to prevent big first frames
|
||||
}
|
||||
m_maxWinBitsLim = GetMaxWinBitsLim();
|
||||
}
|
||||
virtual ~AVGBitrate()
|
||||
{
|
||||
|
||||
}
|
||||
void UpdateSlidingWindow(mfxU32 sizeInBits, mfxU32 FrameOrder, bool bPanic, bool bSH, mfxU32 recode)
|
||||
{
|
||||
mfxU32 windowSize = (mfxU32)m_slidingWindow.size();
|
||||
bool bNextFrame = FrameOrder != m_lastFrameOrder;
|
||||
|
||||
if (bNextFrame)
|
||||
{
|
||||
m_lastFrameOrder = FrameOrder;
|
||||
m_currPosInWindow = (m_currPosInWindow + 1) % windowSize;
|
||||
}
|
||||
m_slidingWindow[m_currPosInWindow] = sizeInBits;
|
||||
|
||||
if (bNextFrame)
|
||||
{
|
||||
if (bPanic || bSH)
|
||||
{
|
||||
m_maxWinBitsLim = mfx::clamp((GetLastFrameBits(windowSize, false) + m_maxWinBits)/2, GetMaxWinBitsLim(), m_maxWinBits);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (recode)
|
||||
{
|
||||
m_maxWinBitsLim = mfx::clamp(GetLastFrameBits(windowSize, false) + GetStep()/2, m_maxWinBitsLim, m_maxWinBits);
|
||||
}
|
||||
else if ((m_maxWinBitsLim > GetMaxWinBitsLim() + GetStep()) &&
|
||||
(m_maxWinBitsLim - GetStep() > (GetLastFrameBits(windowSize - 1, false) + sizeInBits)))
|
||||
m_maxWinBitsLim -= GetStep();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
mfxU32 GetMaxFrameSize(bool bPanic, bool bSH, mfxU32 recode)
|
||||
{
|
||||
mfxU32 winBits = GetLastFrameBits(GetWindowSize() - 1, !bPanic);
|
||||
|
||||
mfxU32 maxWinBitsLim = m_maxWinBitsLim;
|
||||
if (bSH)
|
||||
maxWinBitsLim = (m_maxWinBits + m_maxWinBitsLim)/2;
|
||||
if (bPanic)
|
||||
maxWinBitsLim = m_maxWinBits;
|
||||
maxWinBitsLim = std::min(maxWinBitsLim + recode*GetStep()/2, m_maxWinBits);
|
||||
|
||||
mfxU32 maxFrameSize = winBits >= m_maxWinBitsLim ?
|
||||
mfxU32(std::max<mfxI32>((mfxI32)m_maxWinBits - (mfxI32)winBits, 1)):
|
||||
maxWinBitsLim - winBits;
|
||||
|
||||
|
||||
|
||||
return maxFrameSize;
|
||||
}
|
||||
mfxU32 GetWindowSize()
|
||||
{
|
||||
return (mfxU32)m_slidingWindow.size();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
mfxU32 m_maxWinBits;
|
||||
mfxU32 m_maxWinBitsLim;
|
||||
mfxU32 m_avgBitPerFrame;
|
||||
|
||||
mfxU32 m_currPosInWindow;
|
||||
mfxU32 m_lastFrameOrder;
|
||||
std::vector<mfxU32> m_slidingWindow;
|
||||
|
||||
|
||||
|
||||
mfxU32 GetLastFrameBits(mfxU32 numFrames, bool bCheckSkip)
|
||||
{
|
||||
mfxU32 size = 0;
|
||||
numFrames = numFrames < m_slidingWindow.size() ? numFrames : (mfxU32)m_slidingWindow.size();
|
||||
for (mfxU32 i = 0; i < numFrames; i++)
|
||||
{
|
||||
mfxU32 frame_size = m_slidingWindow[(m_currPosInWindow + m_slidingWindow.size() - i) % m_slidingWindow.size()];
|
||||
if (bCheckSkip && (frame_size < m_avgBitPerFrame / 3))
|
||||
frame_size = m_avgBitPerFrame / 3;
|
||||
size += frame_size;
|
||||
//printf("GetLastFrames: %d) %d sum %d\n",i,m_slidingWindow[(m_currPosInWindow + m_slidingWindow.size() - i) % m_slidingWindow.size() ], size);
|
||||
}
|
||||
return size;
|
||||
}
|
||||
mfxU32 GetStep()
|
||||
{
|
||||
return (m_maxWinBits / GetWindowSize() - m_avgBitPerFrame) / 2;
|
||||
}
|
||||
|
||||
mfxU32 GetMaxWinBitsLim()
|
||||
{
|
||||
return m_maxWinBits - GetStep() * GetWindowSize();
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
class ExtBRC
|
||||
{
|
||||
private:
|
||||
cBRCParams m_par;
|
||||
cHRD m_hrd;
|
||||
bool m_bInit;
|
||||
BRC_Ctx m_ctx;
|
||||
std::unique_ptr<AVGBitrate> m_avg;
|
||||
|
||||
public:
|
||||
ExtBRC():
|
||||
m_par(),
|
||||
m_hrd(),
|
||||
m_bInit(false)
|
||||
{
|
||||
memset(&m_ctx, 0, sizeof(m_ctx));
|
||||
|
||||
}
|
||||
mfxStatus Init (mfxVideoParam* par);
|
||||
mfxStatus Reset(mfxVideoParam* par);
|
||||
mfxStatus Close () {m_bInit = false; return MFX_ERR_NONE;}
|
||||
mfxStatus GetFrameCtrl (mfxBRCFrameParam* par, mfxBRCFrameCtrl* ctrl);
|
||||
mfxStatus Update (mfxBRCFrameParam* par, mfxBRCFrameCtrl* ctrl, mfxBRCFrameStatus* status);
|
||||
protected:
|
||||
mfxI32 GetCurQP (mfxU32 type, mfxI32 layer);
|
||||
};
|
||||
|
||||
namespace HEVCExtBRC
|
||||
{
|
||||
inline mfxStatus Init (mfxHDL pthis, mfxVideoParam* par)
|
||||
{
|
||||
MFX_CHECK_NULL_PTR1(pthis);
|
||||
return ((ExtBRC*)pthis)->Init(par) ;
|
||||
}
|
||||
inline mfxStatus Reset (mfxHDL pthis, mfxVideoParam* par)
|
||||
{
|
||||
MFX_CHECK_NULL_PTR1(pthis);
|
||||
return ((ExtBRC*)pthis)->Reset(par) ;
|
||||
}
|
||||
inline mfxStatus Close (mfxHDL pthis)
|
||||
{
|
||||
MFX_CHECK_NULL_PTR1(pthis);
|
||||
return ((ExtBRC*)pthis)->Close() ;
|
||||
}
|
||||
inline mfxStatus GetFrameCtrl (mfxHDL pthis, mfxBRCFrameParam* par, mfxBRCFrameCtrl* ctrl)
|
||||
{
|
||||
MFX_CHECK_NULL_PTR1(pthis);
|
||||
return ((ExtBRC*)pthis)->GetFrameCtrl(par,ctrl) ;
|
||||
}
|
||||
inline mfxStatus Update (mfxHDL pthis, mfxBRCFrameParam* par, mfxBRCFrameCtrl* ctrl, mfxBRCFrameStatus* status)
|
||||
{
|
||||
MFX_CHECK_NULL_PTR1(pthis);
|
||||
return ((ExtBRC*)pthis)->Update(par,ctrl, status) ;
|
||||
}
|
||||
inline mfxStatus Create(mfxExtBRC & m_BRC)
|
||||
{
|
||||
MFX_CHECK(m_BRC.pthis == NULL, MFX_ERR_UNDEFINED_BEHAVIOR);
|
||||
m_BRC.pthis = new ExtBRC;
|
||||
m_BRC.Init = Init;
|
||||
m_BRC.Reset = Reset;
|
||||
m_BRC.Close = Close;
|
||||
m_BRC.GetFrameCtrl = GetFrameCtrl;
|
||||
m_BRC.Update = Update;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
inline mfxStatus Destroy(mfxExtBRC & m_BRC)
|
||||
{
|
||||
if(m_BRC.pthis != NULL)
|
||||
{
|
||||
delete (ExtBRC*)m_BRC.pthis;
|
||||
m_BRC.pthis = 0;
|
||||
m_BRC.Init = 0;
|
||||
m_BRC.Reset = 0;
|
||||
m_BRC.Close = 0;
|
||||
m_BRC.GetFrameCtrl = 0;
|
||||
m_BRC.Update = 0;
|
||||
}
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
27
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/current_date.h
vendored
Normal file
27
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/current_date.h
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#define PRODUCT_NAME "Intel\xae Media SDK"
|
||||
#define FILE_VERSION 1,0,0,0
|
||||
#define FILE_VERSION_STRING "1,0,0,0"
|
||||
#define FILTER_NAME_PREFIX ""
|
||||
#define FILTER_NAME_SUFFIX ""
|
||||
#define PRODUCT_COPYRIGHT "Copyright\xa9 2003-2019 Intel Corporation"
|
||||
#define PRODUCT_VERSION 1,0,0,0
|
||||
#define PRODUCT_VERSION_STRING "1,0,0,0"
|
||||
263
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d11_allocator.h
vendored
Normal file
263
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d11_allocator.h
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __D3D11_ALLOCATOR_H__
|
||||
#define __D3D11_ALLOCATOR_H__
|
||||
|
||||
#include "base_allocator.h"
|
||||
#include <limits>
|
||||
|
||||
#ifdef __gnu_linux__
|
||||
#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>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
struct ID3D11VideoDevice;
|
||||
struct ID3D11VideoContext;
|
||||
|
||||
struct D3D11AllocatorParams : mfxAllocatorParams
|
||||
{
|
||||
ID3D11Device *pDevice;
|
||||
bool bUseSingleTexture;
|
||||
DWORD uncompressedResourceMiscFlags;
|
||||
|
||||
D3D11AllocatorParams()
|
||||
: pDevice()
|
||||
, bUseSingleTexture()
|
||||
, uncompressedResourceMiscFlags()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class D3D11FrameAllocator: public BaseFrameAllocator
|
||||
{
|
||||
public:
|
||||
|
||||
D3D11FrameAllocator();
|
||||
virtual ~D3D11FrameAllocator();
|
||||
|
||||
virtual mfxStatus Init(mfxAllocatorParams *pParams);
|
||||
virtual mfxStatus Close();
|
||||
virtual ID3D11Device * GetD3D11Device()
|
||||
{
|
||||
return m_initParams.pDevice;
|
||||
};
|
||||
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr);
|
||||
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr);
|
||||
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle);
|
||||
|
||||
protected:
|
||||
static DXGI_FORMAT ConverColortFormat(mfxU32 fourcc);
|
||||
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest *request);
|
||||
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus ReallocImpl(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut);
|
||||
|
||||
D3D11AllocatorParams m_initParams;
|
||||
ID3D11DeviceContext *m_pDeviceContext;
|
||||
|
||||
struct TextureResource
|
||||
{
|
||||
std::vector<mfxMemId> outerMids;
|
||||
std::vector<ID3D11Texture2D*> textures;
|
||||
std::vector<ID3D11Texture2D*> stagingTexture;
|
||||
bool bAlloc;
|
||||
|
||||
TextureResource()
|
||||
: bAlloc(true)
|
||||
{
|
||||
}
|
||||
|
||||
static bool isAllocated (TextureResource & that)
|
||||
{
|
||||
return that.bAlloc;
|
||||
}
|
||||
ID3D11Texture2D* GetTexture(mfxMemId id)
|
||||
{
|
||||
if (outerMids.empty())
|
||||
return NULL;
|
||||
|
||||
return textures[((uintptr_t)id - (uintptr_t)outerMids.front()) % textures.size()];
|
||||
}
|
||||
UINT GetSubResource(mfxMemId id)
|
||||
{
|
||||
if (outerMids.empty())
|
||||
return NULL;
|
||||
|
||||
return (UINT)(((uintptr_t)id - (uintptr_t)outerMids.front()) / textures.size());
|
||||
}
|
||||
void Release()
|
||||
{
|
||||
size_t i = 0;
|
||||
for(i = 0; i < textures.size(); i++)
|
||||
{
|
||||
textures[i]->Release();
|
||||
}
|
||||
textures.clear();
|
||||
|
||||
for(i = 0; i < stagingTexture.size(); i++)
|
||||
{
|
||||
stagingTexture[i]->Release();
|
||||
}
|
||||
stagingTexture.clear();
|
||||
|
||||
//marking texture as deallocated
|
||||
bAlloc = false;
|
||||
}
|
||||
};
|
||||
class TextureSubResource
|
||||
{
|
||||
TextureResource * m_pTarget;
|
||||
ID3D11Texture2D * m_pTexture;
|
||||
ID3D11Texture2D * m_pStaging;
|
||||
UINT m_subResource;
|
||||
public:
|
||||
TextureSubResource(TextureResource * pTarget = NULL, mfxMemId id = 0)
|
||||
: m_pTarget(pTarget)
|
||||
, m_pTexture()
|
||||
, m_subResource()
|
||||
, m_pStaging(NULL)
|
||||
{
|
||||
if (NULL != m_pTarget && !m_pTarget->outerMids.empty())
|
||||
{
|
||||
ptrdiff_t idx = (uintptr_t)MFXReadWriteMid(id).raw() - (uintptr_t)m_pTarget->outerMids.front();
|
||||
m_pTexture = m_pTarget->textures[idx % m_pTarget->textures.size()];
|
||||
m_subResource = (UINT)(idx / m_pTarget->textures.size());
|
||||
m_pStaging = m_pTarget->stagingTexture.empty() ? NULL : m_pTarget->stagingTexture[idx];
|
||||
}
|
||||
}
|
||||
ID3D11Texture2D* GetStaging()const
|
||||
{
|
||||
return m_pStaging;
|
||||
}
|
||||
ID3D11Texture2D* GetTexture()const
|
||||
{
|
||||
return m_pTexture;
|
||||
}
|
||||
UINT GetSubResource()const
|
||||
{
|
||||
return m_subResource;
|
||||
}
|
||||
void Release()
|
||||
{
|
||||
if (NULL != m_pTarget)
|
||||
m_pTarget->Release();
|
||||
}
|
||||
};
|
||||
|
||||
TextureSubResource GetResourceFromMid(mfxMemId);
|
||||
|
||||
std::list <TextureResource> m_resourcesByRequest;//each alloc request generates new item in list
|
||||
|
||||
typedef std::list <TextureResource>::iterator referenceType;
|
||||
std::vector<referenceType> m_memIdMap;
|
||||
};
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
#endif // __D3D11_ALLOCATOR_H__
|
||||
86
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d11_device.h
vendored
Normal file
86
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d11_device.h
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined( _WIN32 ) || defined ( _WIN64 )
|
||||
|
||||
#include "sample_defs.h" // defines MFX_D3D11_SUPPORT
|
||||
|
||||
#if MFX_D3D11_SUPPORT
|
||||
#include "hw_device.h"
|
||||
#include <windows.h>
|
||||
#include <d3d11.h>
|
||||
#include <atlbase.h>
|
||||
|
||||
#include <dxgi1_2.h>
|
||||
|
||||
class CD3D11Device: public CHWDevice
|
||||
{
|
||||
public:
|
||||
CD3D11Device();
|
||||
virtual ~CD3D11Device();
|
||||
virtual mfxStatus Init(
|
||||
mfxHDL hWindow,
|
||||
mfxU16 nViews,
|
||||
mfxU32 nAdapterNum);
|
||||
virtual mfxStatus Reset();
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl);
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl);
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc);
|
||||
virtual void UpdateTitle(double /*fps*/) { }
|
||||
virtual void Close();
|
||||
void DefineFormat(bool isA2rgb10) { m_bIsA2rgb10 = (isA2rgb10) ? TRUE : FALSE; }
|
||||
virtual void SetMondelloInput(bool /*isMondelloInputEnabled*/ ) { }
|
||||
protected:
|
||||
virtual mfxStatus FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd);
|
||||
virtual mfxStatus FillSCD1(DXGI_SWAP_CHAIN_DESC1& scd);
|
||||
mfxStatus CreateVideoProcessor(mfxFrameSurface1 * pSrf);
|
||||
|
||||
CComPtr<ID3D11Device> m_pD3D11Device;
|
||||
CComPtr<ID3D11DeviceContext> m_pD3D11Ctx;
|
||||
CComQIPtr<ID3D11VideoDevice> m_pDX11VideoDevice;
|
||||
CComQIPtr<ID3D11VideoContext> m_pVideoContext;
|
||||
CComPtr<ID3D11VideoProcessorEnumerator> m_VideoProcessorEnum;
|
||||
|
||||
CComQIPtr<IDXGIDevice1> m_pDXGIDev;
|
||||
CComQIPtr<IDXGIAdapter> m_pAdapter;
|
||||
|
||||
CComPtr<IDXGIFactory2> m_pDXGIFactory;
|
||||
|
||||
CComPtr<IDXGISwapChain1> m_pSwapChain;
|
||||
CComPtr<ID3D11VideoProcessor> m_pVideoProcessor;
|
||||
|
||||
private:
|
||||
CComPtr<ID3D11VideoProcessorInputView> m_pInputViewLeft;
|
||||
CComPtr<ID3D11VideoProcessorInputView> m_pInputViewRight;
|
||||
CComPtr<ID3D11VideoProcessorOutputView> m_pOutputView;
|
||||
|
||||
CComPtr<ID3D11Texture2D> m_pDXGIBackBuffer;
|
||||
CComPtr<ID3D11Texture2D> m_pTempTexture;
|
||||
CComPtr<IDXGIDisplayControl> m_pDisplayControl;
|
||||
CComPtr<IDXGIOutput> m_pDXGIOutput;
|
||||
mfxU16 m_nViews;
|
||||
BOOL m_bDefaultStereoEnabled;
|
||||
BOOL m_bIsA2rgb10;
|
||||
HWND m_HandleWindow;
|
||||
};
|
||||
|
||||
#endif //#if defined( _WIN32 ) || defined ( _WIN64 )
|
||||
#endif //#if MFX_D3D11_SUPPORT
|
||||
86
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d_allocator.h
vendored
Normal file
86
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d_allocator.h
vendored
Normal file
@@ -0,0 +1,86 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __D3D_ALLOCATOR_H__
|
||||
#define __D3D_ALLOCATOR_H__
|
||||
|
||||
#if defined( _WIN32 ) || defined ( _WIN64 )
|
||||
|
||||
#include <atlbase.h>
|
||||
#include <d3d9.h>
|
||||
#include <dxva2api.h>
|
||||
#include "base_allocator.h"
|
||||
#include <vector>
|
||||
|
||||
enum eTypeHandle
|
||||
{
|
||||
DXVA2_PROCESSOR = 0x00,
|
||||
DXVA2_DECODER = 0x01
|
||||
};
|
||||
|
||||
struct D3DAllocatorParams : mfxAllocatorParams
|
||||
{
|
||||
IDirect3DDeviceManager9 *pManager;
|
||||
DWORD surfaceUsage;
|
||||
|
||||
D3DAllocatorParams()
|
||||
: pManager()
|
||||
, surfaceUsage()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class D3DFrameAllocator: public BaseFrameAllocator
|
||||
{
|
||||
public:
|
||||
D3DFrameAllocator();
|
||||
virtual ~D3DFrameAllocator();
|
||||
|
||||
virtual mfxStatus Init(mfxAllocatorParams *pParams);
|
||||
virtual mfxStatus Close();
|
||||
|
||||
virtual IDirect3DDeviceManager9* GetDeviceManager()
|
||||
{
|
||||
return m_manager;
|
||||
};
|
||||
|
||||
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr);
|
||||
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr);
|
||||
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle);
|
||||
|
||||
protected:
|
||||
virtual mfxStatus CheckRequestType(mfxFrameAllocRequest *request);
|
||||
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus ReallocImpl(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut);
|
||||
|
||||
void DeallocateMids(mfxHDLPair** pairs, int n);
|
||||
|
||||
std::vector<mfxHDLPair**> m_midsAllocated;
|
||||
|
||||
CComPtr<IDirect3DDeviceManager9> m_manager;
|
||||
CComPtr<IDirectXVideoDecoderService> m_decoderService;
|
||||
CComPtr<IDirectXVideoProcessorService> m_processorService;
|
||||
HANDLE m_hDecoder;
|
||||
HANDLE m_hProcessor;
|
||||
DWORD m_surfaceUsage;
|
||||
};
|
||||
|
||||
#endif // #if defined( _WIN32 ) || defined ( _WIN64 )
|
||||
#endif // __D3D_ALLOCATOR_H__
|
||||
88
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d_device.h
vendored
Normal file
88
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/d3d_device.h
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined( _WIN32 ) || defined ( _WIN64 )
|
||||
|
||||
#include "hw_device.h"
|
||||
|
||||
#pragma warning(disable : 4201)
|
||||
#include <d3d9.h>
|
||||
#include <dxva2api.h>
|
||||
#include <dxva.h>
|
||||
#include <windows.h>
|
||||
|
||||
#define VIDEO_MAIN_FORMAT D3DFMT_YUY2
|
||||
|
||||
/** Direct3D 9 device implementation.
|
||||
@note Device always set D3DPRESENT_PARAMETERS::Windowed to TRUE.
|
||||
*/
|
||||
class CD3D9Device : public CHWDevice
|
||||
{
|
||||
public:
|
||||
CD3D9Device();
|
||||
virtual ~CD3D9Device();
|
||||
|
||||
virtual mfxStatus Init(
|
||||
mfxHDL hWindow,
|
||||
mfxU16 nViews,
|
||||
mfxU32 nAdapterNum);
|
||||
virtual mfxStatus Reset();
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl);
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl);
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc);
|
||||
virtual void UpdateTitle(double /*fps*/) { }
|
||||
virtual void Close() ;
|
||||
void DefineFormat(bool isA2rgb10) { m_bIsA2rgb10 = (isA2rgb10) ? TRUE : FALSE; }
|
||||
virtual void SetMondelloInput(bool /*isMondelloInputEnabled*/) { }
|
||||
protected:
|
||||
mfxStatus CreateVideoProcessors();
|
||||
bool CheckOverlaySupport();
|
||||
virtual mfxStatus FillD3DPP(mfxHDL hWindow, mfxU16 nViews, D3DPRESENT_PARAMETERS &D3DPP);
|
||||
private:
|
||||
IDirect3D9Ex* m_pD3D9;
|
||||
IDirect3DDevice9Ex* m_pD3DD9;
|
||||
IDirect3DDeviceManager9* m_pDeviceManager9;
|
||||
D3DPRESENT_PARAMETERS m_D3DPP;
|
||||
UINT m_resetToken;
|
||||
|
||||
mfxU16 m_nViews;
|
||||
|
||||
D3DSURFACE_DESC m_backBufferDesc;
|
||||
|
||||
// service required to create video processors
|
||||
IDirectXVideoProcessorService* m_pDXVAVPS;
|
||||
//left channel processor
|
||||
IDirectXVideoProcessor* m_pDXVAVP_Left;
|
||||
// right channel processor
|
||||
IDirectXVideoProcessor* m_pDXVAVP_Right;
|
||||
|
||||
// target rectangle
|
||||
RECT m_targetRect;
|
||||
|
||||
// various structures for DXVA2 calls
|
||||
DXVA2_VideoDesc m_VideoDesc;
|
||||
DXVA2_VideoProcessBltParams m_BltParams;
|
||||
DXVA2_VideoSample m_Sample;
|
||||
|
||||
BOOL m_bIsA2rgb10;
|
||||
};
|
||||
|
||||
#endif // #if defined( _WIN32 ) || defined ( _WIN64 )
|
||||
109
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/decode_render.h
vendored
Normal file
109
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/decode_render.h
vendored
Normal file
@@ -0,0 +1,109 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
|
||||
#ifndef __DECODE_D3D_RENDER_H__
|
||||
#define __DECODE_D3D_RENDER_H__
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#pragma warning(disable : 4201)
|
||||
#include <d3d9.h>
|
||||
#include <dxva2api.h>
|
||||
#include <dxva.h>
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "mfxstructures.h"
|
||||
#include "mfxvideo.h"
|
||||
|
||||
#include "hw_device.h"
|
||||
|
||||
typedef void* WindowHandle;
|
||||
typedef void* Handle;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
struct sWindowParams
|
||||
{
|
||||
LPCTSTR lpClassName;
|
||||
LPCTSTR lpWindowName;
|
||||
DWORD dwStyle;
|
||||
int nx;
|
||||
int ny;
|
||||
int ncell;
|
||||
int nAdapter;
|
||||
int nWidth;
|
||||
int nHeight;
|
||||
HWND hWndParent;
|
||||
HMENU hMenu;
|
||||
HINSTANCE hInstance;
|
||||
LPVOID lpParam;
|
||||
bool bFullScreen; // Stretch window to full screen
|
||||
};
|
||||
|
||||
class CDecodeD3DRender
|
||||
{
|
||||
public:
|
||||
|
||||
CDecodeD3DRender();
|
||||
virtual ~CDecodeD3DRender();
|
||||
|
||||
virtual mfxStatus Init(sWindowParams pWParams);
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 *pSurface, mfxFrameAllocator *pmfxAlloc);
|
||||
virtual VOID UpdateTitle(double fps);
|
||||
void Close();
|
||||
|
||||
HWND GetWindowHandle();
|
||||
|
||||
VOID OnDestroy(HWND hwnd);
|
||||
VOID OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags);
|
||||
VOID ChangeWindowSize(bool bFullScreen);
|
||||
|
||||
void SetHWDevice(CHWDevice *dev)
|
||||
{
|
||||
m_hwdev = dev;
|
||||
}
|
||||
protected:
|
||||
void AdjustWindowRect(RECT *rect);
|
||||
|
||||
mfxStatus AllocateShiftedSurfaceIfNeeded(const mfxFrameSurface1* refSurface,mfxFrameAllocator* allocator);
|
||||
mfxFrameAllocResponse shiftSurfaceResponse;
|
||||
mfxFrameSurface1 shiftedSurface;
|
||||
mfxFrameAllocator* pAllocator;
|
||||
|
||||
CHWDevice *m_hwdev;
|
||||
|
||||
|
||||
sWindowParams m_sWindowParams;
|
||||
HWND m_Hwnd;
|
||||
RECT m_rect;
|
||||
DWORD m_style;
|
||||
|
||||
bool EnableDwmQueuing();
|
||||
static BOOL CALLBACK MonitorEnumProc(HMONITOR ,HDC ,LPRECT lprcMonitor,LPARAM dwData);
|
||||
static bool m_bIsMonitorFound;
|
||||
|
||||
bool m_bDwmEnabled;
|
||||
int m_nMonitorCurrent;
|
||||
::RECT m_RectWindow;
|
||||
};
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#endif // __DECODE_D3D_RENDER_H__
|
||||
62
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/general_allocator.h
vendored
Normal file
62
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/general_allocator.h
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __GENERAL_ALLOCATOR_H__
|
||||
#define __GENERAL_ALLOCATOR_H__
|
||||
|
||||
#include "sample_utils.h"
|
||||
#include "base_allocator.h"
|
||||
|
||||
#include <memory>
|
||||
#include <map>
|
||||
|
||||
class SysMemFrameAllocator;
|
||||
|
||||
// Wrapper on standard allocator for concurrent allocation of
|
||||
// D3D and system surfaces
|
||||
class GeneralAllocator : public BaseFrameAllocator
|
||||
{
|
||||
public:
|
||||
GeneralAllocator();
|
||||
virtual ~GeneralAllocator();
|
||||
|
||||
virtual mfxStatus Init(mfxAllocatorParams *pParams);
|
||||
virtual mfxStatus Close();
|
||||
|
||||
protected:
|
||||
virtual mfxStatus LockFrame(mfxMemId mid, mfxFrameData *ptr);
|
||||
virtual mfxStatus UnlockFrame(mfxMemId mid, mfxFrameData *ptr);
|
||||
virtual mfxStatus GetFrameHDL(mfxMemId mid, mfxHDL *handle);
|
||||
|
||||
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus ReallocImpl(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut);
|
||||
|
||||
void StoreFrameMids(bool isD3DFrames, mfxFrameAllocResponse *response);
|
||||
bool isD3DMid(mfxHDL mid);
|
||||
|
||||
std::map<mfxHDL, bool> m_Mids;
|
||||
std::unique_ptr<BaseFrameAllocator> m_D3DAllocator;
|
||||
std::unique_ptr<SysMemFrameAllocator> m_SYSAllocator;
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(GeneralAllocator);
|
||||
|
||||
};
|
||||
|
||||
#endif //__GENERAL_ALLOCATOR_H__
|
||||
50
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/hw_device.h
vendored
Normal file
50
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/hw_device.h
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mfxvideo++.h"
|
||||
|
||||
/// Base class for hw device
|
||||
class CHWDevice
|
||||
{
|
||||
public:
|
||||
virtual ~CHWDevice(){}
|
||||
/** Initializes device for requested processing.
|
||||
@param[in] hWindow Window handle to bundle device to.
|
||||
@param[in] nViews Number of views to process.
|
||||
@param[in] nAdapterNum Number of adapter to use
|
||||
*/
|
||||
virtual mfxStatus Init(
|
||||
mfxHDL hWindow,
|
||||
mfxU16 nViews,
|
||||
mfxU32 nAdapterNum) = 0;
|
||||
/// Reset device.
|
||||
virtual mfxStatus Reset() = 0;
|
||||
/// Get handle can be used for MFX session SetHandle calls
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl) = 0;
|
||||
/** Set handle.
|
||||
Particular device implementation may require other objects to operate.
|
||||
*/
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl) = 0;
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc) = 0;
|
||||
virtual void UpdateTitle(double fps) = 0;
|
||||
virtual void SetMondelloInput(bool isMondelloInputEnabled) = 0;
|
||||
virtual void Close() = 0;
|
||||
};
|
||||
62
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/intrusive_ptr.h
vendored
Normal file
62
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/intrusive_ptr.h
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
//intrusive ptr concept
|
||||
//usage examples same as smart pointers except user has to define addref and release routine for that class
|
||||
|
||||
//inline void intrusive_ptr_addref(UserClassA * pResource);
|
||||
//inline void intrusive_ptr_release(UserClassA * pResource);
|
||||
|
||||
template <class T>
|
||||
class intrusive_ptr
|
||||
{
|
||||
T * m_pResource;
|
||||
public:
|
||||
intrusive_ptr(T* pResource = NULL)
|
||||
: m_pResource(pResource) {
|
||||
intrusive_ptr_addref(m_pResource);
|
||||
}
|
||||
intrusive_ptr(const intrusive_ptr<T> & rhs)
|
||||
: m_pResource(rhs.m_pResource) {
|
||||
intrusive_ptr_addref(m_pResource);
|
||||
}
|
||||
void reset(T* pResource) {
|
||||
if (m_pResource){
|
||||
intrusive_ptr_release(m_pResource);
|
||||
}
|
||||
m_pResource = pResource;
|
||||
intrusive_ptr_addref(m_pResource);
|
||||
}
|
||||
T* operator *() {
|
||||
return m_pResource;
|
||||
}
|
||||
T* operator ->() {
|
||||
return m_pResource;
|
||||
}
|
||||
T* get(){
|
||||
return m_pResource;
|
||||
}
|
||||
~intrusive_ptr(){
|
||||
if (m_pResource) {
|
||||
intrusive_ptr_release(m_pResource);
|
||||
}
|
||||
}
|
||||
};
|
||||
399
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_buffering.h
vendored
Normal file
399
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_buffering.h
vendored
Normal file
@@ -0,0 +1,399 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __MFX_BUFFERING_H__
|
||||
#define __MFX_BUFFERING_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <mutex>
|
||||
|
||||
#include "mfxstructures.h"
|
||||
|
||||
#include "vm/strings_defs.h"
|
||||
#include "vm/thread_defs.h"
|
||||
#include "vm/time_defs.h"
|
||||
#include "vm/atomic_defs.h"
|
||||
|
||||
struct msdkFrameSurface
|
||||
{
|
||||
mfxFrameSurface1 frame; // NOTE: this _should_ be the first item (see CBuffering::FindUsedSurface())
|
||||
msdk_tick submit; // tick when frame was submitted for processing
|
||||
mfxU16 render_lock; // signifies that frame is locked for rendering
|
||||
msdkFrameSurface* prev;
|
||||
msdkFrameSurface* next;
|
||||
};
|
||||
|
||||
struct msdkOutputSurface
|
||||
{
|
||||
msdkFrameSurface* surface;
|
||||
mfxSyncPoint syncp;
|
||||
msdkOutputSurface* next;
|
||||
};
|
||||
|
||||
/** \brief Debug purpose macro to terminate execution if buggy situation happenned.
|
||||
*
|
||||
* Use this macro to check impossible, buggy condition which should not occur under
|
||||
* normal circumstances. Macro should be used where check in release mode is not
|
||||
* desirable and atually needed.
|
||||
*/
|
||||
#define MSDK_SELF_CHECK(C)
|
||||
|
||||
class CBuffering;
|
||||
|
||||
// LIFO list of frame surfaces
|
||||
class msdkFreeSurfacesPool
|
||||
{
|
||||
friend class CBuffering;
|
||||
public:
|
||||
msdkFreeSurfacesPool(std::mutex & mutex):
|
||||
m_pSurfaces(NULL),
|
||||
m_rMutex(mutex) {}
|
||||
|
||||
~msdkFreeSurfacesPool() {
|
||||
m_pSurfaces = NULL;
|
||||
}
|
||||
/** \brief The function adds free surface to the free surfaces array.
|
||||
*
|
||||
* @note That's caller responsibility to pass valid surface.
|
||||
* @note We always add and get free surface from the array head. In case not all surfaces
|
||||
* will be actually used we have good chance to avoid actual allocation of the surface memory.
|
||||
*/
|
||||
inline void AddSurface(msdkFrameSurface* surface) {
|
||||
std::lock_guard<std::mutex> lock(m_rMutex);
|
||||
AddSurfaceUnsafe(surface);
|
||||
}
|
||||
/** \brief The function gets the next free surface from the free surfaces array.
|
||||
*
|
||||
* @note Surface is detached from the free surfaces array.
|
||||
*/
|
||||
inline msdkFrameSurface* GetSurface() {
|
||||
std::lock_guard<std::mutex> lock(m_rMutex);
|
||||
return GetSurfaceUnsafe();
|
||||
}
|
||||
|
||||
private:
|
||||
inline void AddSurfaceUnsafe(msdkFrameSurface* surface) {
|
||||
msdkFrameSurface* head;
|
||||
|
||||
MSDK_SELF_CHECK(surface);
|
||||
MSDK_SELF_CHECK(!surface->prev);
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
|
||||
head = m_pSurfaces;
|
||||
m_pSurfaces = surface;
|
||||
m_pSurfaces->next = head;
|
||||
}
|
||||
inline msdkFrameSurface* GetSurfaceUnsafe() {
|
||||
|
||||
msdkFrameSurface* surface = NULL;
|
||||
|
||||
if (m_pSurfaces) {
|
||||
surface = m_pSurfaces;
|
||||
m_pSurfaces = m_pSurfaces->next;
|
||||
surface->prev = surface->next = NULL;
|
||||
MSDK_SELF_CHECK(!surface->prev);
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
protected:
|
||||
msdkFrameSurface* m_pSurfaces;
|
||||
std::mutex & m_rMutex;
|
||||
|
||||
private:
|
||||
msdkFreeSurfacesPool(const msdkFreeSurfacesPool&);
|
||||
void operator=(const msdkFreeSurfacesPool&);
|
||||
};
|
||||
|
||||
// random access, predicted as FIFO
|
||||
class msdkUsedSurfacesPool
|
||||
{
|
||||
friend class CBuffering;
|
||||
public:
|
||||
msdkUsedSurfacesPool(std::mutex & mutex):
|
||||
m_pSurfacesHead(NULL),
|
||||
m_pSurfacesTail(NULL),
|
||||
m_rMutex(mutex) {}
|
||||
|
||||
~msdkUsedSurfacesPool() {
|
||||
m_pSurfacesHead = NULL;
|
||||
m_pSurfacesTail = NULL;
|
||||
}
|
||||
|
||||
/** \brief The function adds surface to the used surfaces array (m_pUsedSurfaces).
|
||||
*
|
||||
* @note That's caller responsibility to pass valid surface.
|
||||
* @note We can't actually know which surface will be returned by the decoder or unlocked. However,
|
||||
* we can make prediction that it will be the oldest surface. Thus, here the function adds new
|
||||
* surface (youngest) to the tail of the least. Check operations for the list will run starting from
|
||||
* head.
|
||||
*/
|
||||
inline void AddSurface(msdkFrameSurface* surface) {
|
||||
std::lock_guard<std::mutex> lock(m_rMutex);
|
||||
AddSurfaceUnsafe(surface);
|
||||
}
|
||||
|
||||
/** \brief The function detaches surface from the used surfaces array.
|
||||
*
|
||||
* @note That's caller responsibility to pass valid surface.
|
||||
*/
|
||||
|
||||
inline void DetachSurface(msdkFrameSurface* surface) {
|
||||
std::lock_guard<std::mutex> lock(m_rMutex);
|
||||
DetachSurfaceUnsafe(surface);
|
||||
}
|
||||
|
||||
private:
|
||||
inline void DetachSurfaceUnsafe(msdkFrameSurface* surface)
|
||||
{
|
||||
MSDK_SELF_CHECK(surface);
|
||||
|
||||
msdkFrameSurface *prev = surface->prev;
|
||||
msdkFrameSurface *next = surface->next;
|
||||
|
||||
if (prev) {
|
||||
prev->next = next;
|
||||
}
|
||||
else {
|
||||
MSDK_SELF_CHECK(surface == m_pSurfacesHead);
|
||||
m_pSurfacesHead = next;
|
||||
}
|
||||
if (next) {
|
||||
next->prev = prev;
|
||||
} else {
|
||||
MSDK_SELF_CHECK(surface == m_pSurfacesTail);
|
||||
m_pSurfacesTail = prev;
|
||||
}
|
||||
|
||||
surface->prev = surface->next = NULL;
|
||||
MSDK_SELF_CHECK(!surface->prev);
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
}
|
||||
inline void AddSurfaceUnsafe(msdkFrameSurface* surface)
|
||||
{
|
||||
MSDK_SELF_CHECK(surface);
|
||||
MSDK_SELF_CHECK(!surface->prev);
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
|
||||
surface->prev = m_pSurfacesTail;
|
||||
surface->next = NULL;
|
||||
if (m_pSurfacesTail) {
|
||||
m_pSurfacesTail->next = surface;
|
||||
m_pSurfacesTail = m_pSurfacesTail->next;
|
||||
} else {
|
||||
m_pSurfacesHead = m_pSurfacesTail = surface;
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
msdkFrameSurface* m_pSurfacesHead; // oldest surface
|
||||
msdkFrameSurface* m_pSurfacesTail; // youngest surface
|
||||
std::mutex & m_rMutex;
|
||||
|
||||
private:
|
||||
msdkUsedSurfacesPool(const msdkUsedSurfacesPool&);
|
||||
void operator=(const msdkUsedSurfacesPool&);
|
||||
};
|
||||
|
||||
// FIFO list of surfaces
|
||||
class msdkOutputSurfacesPool
|
||||
{
|
||||
friend class CBuffering;
|
||||
public:
|
||||
msdkOutputSurfacesPool(std::mutex & mutex):
|
||||
m_pSurfacesHead(NULL),
|
||||
m_pSurfacesTail(NULL),
|
||||
m_SurfacesCount(0),
|
||||
m_rMutex(mutex) {}
|
||||
|
||||
~msdkOutputSurfacesPool() {
|
||||
m_pSurfacesHead = NULL;
|
||||
m_pSurfacesTail = NULL;
|
||||
}
|
||||
|
||||
inline void AddSurface(msdkOutputSurface* surface) {
|
||||
std::lock_guard<std::mutex> lock(m_rMutex);
|
||||
AddSurfaceUnsafe(surface);
|
||||
}
|
||||
inline msdkOutputSurface* GetSurface() {
|
||||
std::lock_guard<std::mutex> lock(m_rMutex);
|
||||
return GetSurfaceUnsafe();
|
||||
}
|
||||
|
||||
inline mfxU32 GetSurfaceCount() {
|
||||
return m_SurfacesCount;
|
||||
}
|
||||
private:
|
||||
inline void AddSurfaceUnsafe(msdkOutputSurface* surface)
|
||||
{
|
||||
MSDK_SELF_CHECK(surface);
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
surface->next = NULL;
|
||||
|
||||
if (m_pSurfacesTail) {
|
||||
m_pSurfacesTail->next = surface;
|
||||
m_pSurfacesTail = m_pSurfacesTail->next;
|
||||
} else {
|
||||
m_pSurfacesHead = m_pSurfacesTail = surface;
|
||||
}
|
||||
++m_SurfacesCount;
|
||||
}
|
||||
inline msdkOutputSurface* GetSurfaceUnsafe()
|
||||
{
|
||||
msdkOutputSurface* surface = NULL;
|
||||
|
||||
if (m_pSurfacesHead) {
|
||||
surface = m_pSurfacesHead;
|
||||
m_pSurfacesHead = m_pSurfacesHead->next;
|
||||
if (!m_pSurfacesHead) {
|
||||
// there was only one surface in the array...
|
||||
m_pSurfacesTail = NULL;
|
||||
}
|
||||
--m_SurfacesCount;
|
||||
surface->next = NULL;
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
|
||||
protected:
|
||||
msdkOutputSurface* m_pSurfacesHead; // oldest surface
|
||||
msdkOutputSurface* m_pSurfacesTail; // youngest surface
|
||||
mfxU32 m_SurfacesCount;
|
||||
std::mutex & m_rMutex;
|
||||
|
||||
private:
|
||||
msdkOutputSurfacesPool(const msdkOutputSurfacesPool&);
|
||||
void operator=(const msdkOutputSurfacesPool&);
|
||||
};
|
||||
|
||||
/** \brief Helper class defining optimal buffering operations for the Media SDK decoder.
|
||||
*/
|
||||
class CBuffering
|
||||
{
|
||||
public:
|
||||
CBuffering();
|
||||
virtual ~CBuffering();
|
||||
|
||||
protected: // functions
|
||||
mfxStatus AllocBuffers(mfxU32 SurfaceNumber);
|
||||
mfxStatus AllocVppBuffers(mfxU32 VppSurfaceNumber);
|
||||
void AllocOutputBuffer();
|
||||
void FreeBuffers();
|
||||
void ResetBuffers();
|
||||
void ResetVppBuffers();
|
||||
|
||||
/** \brief The function syncs arrays of free and used surfaces.
|
||||
*
|
||||
* If Media SDK used surface for internal needs and unlocked it, the function moves such a surface
|
||||
* back to the free surfaces array.
|
||||
*/
|
||||
void SyncFrameSurfaces();
|
||||
void SyncVppFrameSurfaces();
|
||||
|
||||
/** \brief Returns surface which corresponds to the given one in Media SDK format (mfxFrameSurface1).
|
||||
*
|
||||
* @note This function will not detach the surface from the array, perform this explicitly.
|
||||
*/
|
||||
inline msdkFrameSurface* FindUsedSurface(mfxFrameSurface1* frame)
|
||||
{
|
||||
return (msdkFrameSurface*)(frame);
|
||||
}
|
||||
|
||||
inline void AddFreeOutputSurfaceUnsafe(msdkOutputSurface* surface)
|
||||
{
|
||||
msdkOutputSurface* head = m_pFreeOutputSurfaces;
|
||||
|
||||
MSDK_SELF_CHECK(surface);
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
m_pFreeOutputSurfaces = surface;
|
||||
m_pFreeOutputSurfaces->next = head;
|
||||
}
|
||||
inline void AddFreeOutputSurface(msdkOutputSurface* surface) {
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
AddFreeOutputSurfaceUnsafe(surface);
|
||||
}
|
||||
|
||||
inline msdkOutputSurface* GetFreeOutputSurfaceUnsafe(std::unique_lock<std::mutex> & lock)
|
||||
{
|
||||
msdkOutputSurface* surface = NULL;
|
||||
|
||||
if (!m_pFreeOutputSurfaces) {
|
||||
lock.unlock();
|
||||
AllocOutputBuffer();
|
||||
lock.lock();
|
||||
}
|
||||
if (m_pFreeOutputSurfaces) {
|
||||
surface = m_pFreeOutputSurfaces;
|
||||
m_pFreeOutputSurfaces = m_pFreeOutputSurfaces->next;
|
||||
surface->next = NULL;
|
||||
MSDK_SELF_CHECK(!surface->next);
|
||||
}
|
||||
return surface;
|
||||
}
|
||||
inline msdkOutputSurface* GetFreeOutputSurface() {
|
||||
std::unique_lock<std::mutex> lock(m_Mutex);
|
||||
return GetFreeOutputSurfaceUnsafe(lock);
|
||||
}
|
||||
|
||||
/** \brief Function returns surface data to the corresponding buffers.
|
||||
*/
|
||||
inline void ReturnSurfaceToBuffers(msdkOutputSurface* output_surface)
|
||||
{
|
||||
MSDK_SELF_CHECK(output_surface);
|
||||
MSDK_SELF_CHECK(output_surface->surface);
|
||||
MSDK_SELF_CHECK(output_surface->syncp);
|
||||
|
||||
msdk_atomic_dec16(&(output_surface->surface->render_lock));
|
||||
|
||||
output_surface->surface = NULL;
|
||||
output_surface->syncp = NULL;
|
||||
|
||||
AddFreeOutputSurface(output_surface);
|
||||
}
|
||||
|
||||
protected: // variables
|
||||
mfxU32 m_SurfacesNumber;
|
||||
mfxU32 m_OutputSurfacesNumber;
|
||||
msdkFrameSurface* m_pSurfaces;
|
||||
msdkFrameSurface* m_pVppSurfaces;
|
||||
std::mutex m_Mutex;
|
||||
|
||||
// LIFO list of frame surfaces
|
||||
msdkFreeSurfacesPool m_FreeSurfacesPool;
|
||||
msdkFreeSurfacesPool m_FreeVppSurfacesPool;
|
||||
|
||||
// random access, predicted as FIFO
|
||||
msdkUsedSurfacesPool m_UsedSurfacesPool;
|
||||
msdkUsedSurfacesPool m_UsedVppSurfacesPool;
|
||||
|
||||
// LIFO list of output surfaces
|
||||
msdkOutputSurface* m_pFreeOutputSurfaces;
|
||||
|
||||
// FIFO list of surfaces
|
||||
msdkOutputSurfacesPool m_OutputSurfacesPool;
|
||||
msdkOutputSurfacesPool m_DeliveredSurfacesPool;
|
||||
|
||||
private:
|
||||
CBuffering(const CBuffering&);
|
||||
void operator=(const CBuffering&);
|
||||
};
|
||||
|
||||
#endif // __MFX_BUFFERING_H__
|
||||
59
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_itt_trace.h
vendored
Normal file
59
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_itt_trace.h
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __MFX_ITT_TRACE_H__
|
||||
#define __MFX_ITT_TRACE_H__
|
||||
|
||||
#ifdef ITT_SUPPORT
|
||||
#include <ittnotify.h>
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef ITT_SUPPORT
|
||||
|
||||
static inline __itt_domain* mfx_itt_get_domain() {
|
||||
static __itt_domain *domain = NULL;
|
||||
|
||||
if (!domain) domain = __itt_domain_create("MFX_SAMPLES");
|
||||
return domain;
|
||||
}
|
||||
|
||||
class MFX_ITT_Tracer
|
||||
{
|
||||
public:
|
||||
MFX_ITT_Tracer(const char* trace_name)
|
||||
{
|
||||
m_domain = mfx_itt_get_domain();
|
||||
if (m_domain)
|
||||
__itt_task_begin(m_domain, __itt_null, __itt_null, __itt_string_handle_create(trace_name));
|
||||
}
|
||||
~MFX_ITT_Tracer()
|
||||
{
|
||||
if (m_domain) __itt_task_end(m_domain);
|
||||
}
|
||||
private:
|
||||
__itt_domain* m_domain;
|
||||
};
|
||||
#define MFX_ITT_TASK(x) MFX_ITT_Tracer __mfx_itt_tracer(x);
|
||||
|
||||
#else
|
||||
#define MFX_ITT_TASK(x)
|
||||
#endif
|
||||
|
||||
#endif //__MFX_ITT_TRACE_H__
|
||||
27
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_plugin_base.h
vendored
Normal file
27
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_plugin_base.h
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#include <mfxplugin++.h>
|
||||
|
||||
typedef MFXDecoderPlugin* (*mfxCreateDecoderPlugin)();
|
||||
typedef MFXEncoderPlugin* (*mfxCreateEncoderPlugin)();
|
||||
typedef MFXGenericPlugin* (*mfxCreateGenericPlugin)();
|
||||
40
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_plugin_module.h
vendored
Normal file
40
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_plugin_module.h
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mfxplugin++.h"
|
||||
|
||||
struct PluginModuleTemplate {
|
||||
typedef MFXDecoderPlugin* (*fncCreateDecoderPlugin)();
|
||||
typedef MFXEncoderPlugin* (*fncCreateEncoderPlugin)();
|
||||
typedef MFXAudioDecoderPlugin* (*fncCreateAudioDecoderPlugin)();
|
||||
typedef MFXAudioEncoderPlugin* (*fncCreateAudioEncoderPlugin)();
|
||||
typedef MFXGenericPlugin* (*fncCreateGenericPlugin)();
|
||||
typedef mfxStatus (MFX_CDECL *CreatePluginPtr_t)(mfxPluginUID uid, mfxPlugin* plugin);
|
||||
|
||||
fncCreateDecoderPlugin CreateDecoderPlugin;
|
||||
fncCreateEncoderPlugin CreateEncoderPlugin;
|
||||
fncCreateGenericPlugin CreateGenericPlugin;
|
||||
CreatePluginPtr_t CreatePlugin;
|
||||
fncCreateAudioDecoderPlugin CreateAudioDecoderPlugin;
|
||||
fncCreateAudioEncoderPlugin CreateAudioEncoderPlugin;
|
||||
};
|
||||
|
||||
extern PluginModuleTemplate g_PluginModule;
|
||||
23
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_samples_config.h
vendored
Normal file
23
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/mfx_samples_config.h
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __MFX_SAMPLES_CONFIG__
|
||||
#define __MFX_SAMPLES_CONFIG__
|
||||
|
||||
#endif //__MFX_SAMPLES_CONFIG__
|
||||
73
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/parameters_dumper.h
vendored
Normal file
73
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/parameters_dumper.h
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __PARAMETERS_DUMPER_H__
|
||||
#define __PARAMETERS_DUMPER_H__
|
||||
#include "sample_defs.h"
|
||||
|
||||
class CParametersDumper
|
||||
{
|
||||
protected:
|
||||
static void SerializeFrameInfoStruct(msdk_ostream& sstr,msdk_string prefix,mfxFrameInfo& info);
|
||||
static void SerializeMfxInfoMFXStruct(msdk_ostream& sstr,msdk_string prefix,mfxInfoMFX& info);
|
||||
static void SerializeExtensionBuffer(msdk_ostream& sstr,msdk_string prefix,mfxExtBuffer* pExtBuffer);
|
||||
static void SerializeVPPCompInputStream(msdk_ostream& sstr, msdk_string prefix, mfxVPPCompInputStream& info);
|
||||
|
||||
template <class T>
|
||||
static mfxStatus GetUnitParams(T* pMfxUnit, const mfxVideoParam* pPresetParams, mfxVideoParam* pOutParams)
|
||||
{
|
||||
memset(pOutParams,0, sizeof(mfxVideoParam));
|
||||
mfxExtBuffer** paramsArray = new mfxExtBuffer*[pPresetParams->NumExtParam];
|
||||
for (int paramNum = 0; paramNum < pPresetParams->NumExtParam; paramNum++)
|
||||
{
|
||||
mfxExtBuffer* buf = pPresetParams->ExtParam[paramNum];
|
||||
mfxExtBuffer* newBuf = (mfxExtBuffer*)new mfxU8[buf->BufferSz];
|
||||
memset(newBuf, 0, buf->BufferSz);
|
||||
newBuf->BufferId = buf->BufferId;
|
||||
newBuf->BufferSz = buf->BufferSz;
|
||||
paramsArray[paramNum]=newBuf;
|
||||
}
|
||||
pOutParams->NumExtParam = pPresetParams->NumExtParam;
|
||||
pOutParams->ExtParam = paramsArray;
|
||||
|
||||
mfxStatus sts = pMfxUnit->GetVideoParam(pOutParams);
|
||||
MSDK_CHECK_STATUS_SAFE(sts, "Cannot read configuration from encoder: GetVideoParam failed", ClearExtBuffs(pOutParams));
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
static void ClearExtBuffs(mfxVideoParam* params)
|
||||
{
|
||||
// Cleaning params array
|
||||
for (int paramNum = 0; paramNum < params->NumExtParam; paramNum++)
|
||||
{
|
||||
delete[] params->ExtParam[paramNum];
|
||||
}
|
||||
delete[] params->ExtParam;
|
||||
params->ExtParam = NULL;
|
||||
params->NumExtParam = 0;
|
||||
}
|
||||
|
||||
public:
|
||||
static void SerializeVideoParamStruct(msdk_ostream& sstr,msdk_string sectionName,mfxVideoParam& info,bool shouldUseVPPSection=false);
|
||||
static mfxStatus DumpLibraryConfiguration(msdk_string fileName, MFXVideoDECODE* pMfxDec, MFXVideoVPP* pMfxVPP, MFXVideoENCODE* pMfxEnc,
|
||||
const mfxVideoParam* pDecoderPresetParams, const mfxVideoParam* pVPPPresetParams, const mfxVideoParam* pEncoderPresetParams);
|
||||
static void ShowConfigurationDiff(msdk_ostream& sstr1, msdk_ostream& sstr2);
|
||||
};
|
||||
#endif
|
||||
261
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/plugin_loader.h
vendored
Normal file
261
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/plugin_loader.h
vendored
Normal file
@@ -0,0 +1,261 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifndef __PLUGIN_LOADER_H__
|
||||
#define __PLUGIN_LOADER_H__
|
||||
|
||||
#include "vm/so_defs.h"
|
||||
#include "sample_utils.h"
|
||||
#include "plugin_utils.h"
|
||||
//#include "mfx_plugin_module.h"
|
||||
#include <iostream>
|
||||
#include <iomanip> // for std::setfill, std::setw
|
||||
#include <memory> // for std::unique_ptr
|
||||
|
||||
class MsdkSoModule
|
||||
{
|
||||
protected:
|
||||
msdk_so_handle m_module;
|
||||
public:
|
||||
MsdkSoModule()
|
||||
: m_module(NULL)
|
||||
{
|
||||
}
|
||||
MsdkSoModule(const msdk_string & pluginName)
|
||||
: m_module(NULL)
|
||||
{
|
||||
m_module = msdk_so_load(pluginName.c_str());
|
||||
if (NULL == m_module)
|
||||
{
|
||||
MSDK_TRACE_ERROR(msdk_tstring(MSDK_CHAR("Failed to load shared module: ")) + pluginName);
|
||||
}
|
||||
}
|
||||
template <class T>
|
||||
T GetAddr(const std::string & fncName)
|
||||
{
|
||||
T pCreateFunc = reinterpret_cast<T>(msdk_so_get_addr(m_module, fncName.c_str()));
|
||||
if (NULL == pCreateFunc) {
|
||||
MSDK_TRACE_ERROR(msdk_tstring("Failed to get function addres: ") + fncName.c_str());
|
||||
}
|
||||
return pCreateFunc;
|
||||
}
|
||||
|
||||
virtual ~MsdkSoModule()
|
||||
{
|
||||
if (m_module)
|
||||
{
|
||||
msdk_so_free(m_module);
|
||||
m_module = NULL;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
* Rationale: class to load+register any mediasdk plugin decoder/encoder/generic by given name
|
||||
*/
|
||||
class PluginLoader : public MFXPlugin
|
||||
{
|
||||
protected:
|
||||
mfxPluginType ePluginType;
|
||||
|
||||
mfxSession m_session;
|
||||
mfxPluginUID m_uid;
|
||||
|
||||
private:
|
||||
const msdk_char* msdkGetPluginName(const mfxPluginUID& guid)
|
||||
{
|
||||
if (AreGuidsEqual(guid, MFX_PLUGINID_HEVCD_SW))
|
||||
return MSDK_STRING("Intel (R) Media SDK plugin for HEVC DECODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_HEVCD_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for HEVC DECODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_HEVCE_SW))
|
||||
return MSDK_STRING("Intel (R) Media SDK plugin for HEVC ENCODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_HEVCE_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for HEVC ENCODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_VP8E_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for VP8 ENCODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_VP8D_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for VP8 DECODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_VP9E_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for VP9 ENCODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_VP9D_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for VP9 DECODE");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_H264LA_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK plugin for LA ENC");
|
||||
else if(AreGuidsEqual(guid, MFX_PLUGINID_ITELECINE_HW))
|
||||
return MSDK_STRING("Intel (R) Media SDK PTIR plugin (HW)");
|
||||
else if (AreGuidsEqual(guid, MFX_PLUGINID_HEVCE_GACC))
|
||||
return MSDK_STRING("Intel (R) Media SDK GPU-Accelerated plugin for HEVC ENCODE");
|
||||
else
|
||||
#if (MFX_VERSION >= 1027) && !defined(_WIN32) && !defined(_WIN64)
|
||||
if (AreGuidsEqual(guid, MFX_PLUGINID_HEVC_FEI_ENCODE))
|
||||
return MSDK_STRING("Intel (R) Media SDK HW plugin for HEVC FEI ENCODE");
|
||||
else
|
||||
#endif
|
||||
return MSDK_STRING("Unknown plugin");
|
||||
}
|
||||
|
||||
public:
|
||||
PluginLoader(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version, const mfxChar *pluginName, mfxU32 len)
|
||||
: ePluginType(type)
|
||||
, m_session()
|
||||
, m_uid()
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
msdk_stringstream strStream;
|
||||
|
||||
MSDK_MEMCPY(&m_uid, &uid, sizeof(mfxPluginUID));
|
||||
for (size_t i = 0; i != sizeof(mfxPluginUID); i++)
|
||||
{
|
||||
strStream << MSDK_STRING("0x") << std::setfill(MSDK_CHAR('0')) << std::setw(2) << std::hex << (int)m_uid.Data[i];
|
||||
if (i != (sizeof(mfxPluginUID)-1)) strStream << MSDK_STRING(", ");
|
||||
}
|
||||
|
||||
if ((ePluginType == MFX_PLUGINTYPE_AUDIO_DECODE) ||
|
||||
(ePluginType == MFX_PLUGINTYPE_AUDIO_ENCODE))
|
||||
{
|
||||
// Audio plugins are not loaded by path
|
||||
sts = MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = MFXVideoUSER_LoadByPath(session, &m_uid, version, pluginName, len);
|
||||
}
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
{
|
||||
MSDK_TRACE_ERROR(MSDK_STRING("Failed to load plugin from GUID, sts=") << sts << MSDK_STRING(": { ") << strStream.str().c_str() << MSDK_STRING(" } (") << msdkGetPluginName(m_uid) << MSDK_STRING(")"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MSDK_TRACE_INFO(MSDK_STRING("Plugin was loaded from GUID"));
|
||||
m_session = session;
|
||||
}
|
||||
}
|
||||
|
||||
PluginLoader(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version)
|
||||
: ePluginType(type)
|
||||
, m_session()
|
||||
, m_uid()
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
msdk_stringstream strStream;
|
||||
|
||||
MSDK_MEMCPY(&m_uid, &uid, sizeof(mfxPluginUID));
|
||||
for (size_t i = 0; i != sizeof(mfxPluginUID); i++)
|
||||
{
|
||||
strStream << MSDK_STRING("0x") << std::setfill(MSDK_CHAR('0')) << std::setw(2) << std::hex << (int)m_uid.Data[i];
|
||||
if (i != (sizeof(mfxPluginUID)-1)) strStream << MSDK_STRING(", ");
|
||||
}
|
||||
|
||||
if ((ePluginType == MFX_PLUGINTYPE_AUDIO_DECODE) ||
|
||||
(ePluginType == MFX_PLUGINTYPE_AUDIO_ENCODE))
|
||||
{
|
||||
sts = MFXAudioUSER_Load(session, &m_uid, version);
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = MFXVideoUSER_Load(session, &m_uid, version);
|
||||
}
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
{
|
||||
MSDK_TRACE_ERROR(MSDK_STRING("Failed to load plugin from GUID, sts=") << sts << MSDK_STRING(": { ") << strStream.str().c_str() << MSDK_STRING(" } (") << msdkGetPluginName(m_uid) << MSDK_STRING(")"));
|
||||
}
|
||||
else
|
||||
{
|
||||
MSDK_TRACE_INFO(MSDK_STRING("Plugin was loaded from GUID")<< MSDK_STRING(": { ") << strStream.str().c_str() << MSDK_STRING(" } (") << msdkGetPluginName(m_uid) << MSDK_STRING(")"));
|
||||
m_session = session;
|
||||
}
|
||||
}
|
||||
|
||||
virtual ~PluginLoader()
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
if (m_session)
|
||||
{
|
||||
if ((ePluginType == MFX_PLUGINTYPE_AUDIO_DECODE) ||
|
||||
(ePluginType == MFX_PLUGINTYPE_AUDIO_ENCODE))
|
||||
{
|
||||
sts = MFXAudioUSER_UnLoad(m_session, &m_uid);
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = MFXVideoUSER_UnLoad(m_session, &m_uid);
|
||||
}
|
||||
|
||||
if (sts != MFX_ERR_NONE)
|
||||
{
|
||||
MSDK_TRACE_ERROR(MSDK_STRING("Failed to unload plugin from GUID, sts=") << sts);
|
||||
}
|
||||
else
|
||||
{
|
||||
MSDK_TRACE_INFO(MSDK_STRING("MFXBaseUSER_UnLoad(session=0x") << m_session << MSDK_STRING("), sts=") << sts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool IsOk() {
|
||||
return m_session != 0;
|
||||
}
|
||||
virtual mfxStatus PluginInit( mfxCoreInterface * /*core*/ ) {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
virtual mfxStatus PluginClose() {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
virtual mfxStatus GetPluginParam( mfxPluginParam * /*par*/ ) {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
virtual mfxStatus Execute( mfxThreadTask /*task*/, mfxU32 /*uid_p*/, mfxU32 /*uid_a*/ ) {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
virtual mfxStatus FreeResources( mfxThreadTask /*task*/, mfxStatus /*sts*/ ) {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
virtual void Release() {
|
||||
}
|
||||
virtual mfxStatus Close() {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
virtual mfxStatus SetAuxParams( void* /*auxParam*/, int /*auxParamSize*/ ) {
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
};
|
||||
|
||||
inline MFXPlugin * LoadPluginByType(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version, const mfxChar *pluginName, mfxU32 len) {
|
||||
std::unique_ptr<PluginLoader> plg(new PluginLoader (type, session, uid, version, pluginName, len));
|
||||
return plg->IsOk() ? plg.release() : NULL;
|
||||
}
|
||||
|
||||
inline MFXPlugin * LoadPluginByGUID(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version) {
|
||||
std::unique_ptr<PluginLoader> plg(new PluginLoader (type, session, uid, version));
|
||||
return plg->IsOk() ? plg.release() : NULL;
|
||||
}
|
||||
|
||||
inline MFXPlugin * LoadPlugin(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version, const mfxChar *pluginName, mfxU32 len) {
|
||||
return LoadPluginByType(type, session, uid, version, pluginName, len);
|
||||
}
|
||||
|
||||
inline MFXPlugin * LoadPlugin(mfxPluginType type, mfxSession session, const mfxPluginUID & uid, mfxU32 version) {
|
||||
return LoadPluginByGUID(type, session, uid, version);
|
||||
}
|
||||
#endif // PLUGIN_LOADER
|
||||
72
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/plugin_utils.h
vendored
Normal file
72
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/plugin_utils.h
vendored
Normal file
@@ -0,0 +1,72 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __PLUGIN_UTILS_H__
|
||||
#define __PLUGIN_UTILS_H__
|
||||
|
||||
#include "sample_defs.h"
|
||||
#include "sample_types.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#define MSDK_CPU_ROTATE_PLUGIN MSDK_STRING("sample_rotate_plugin.dll")
|
||||
#define MSDK_OCL_ROTATE_PLUGIN MSDK_STRING("sample_plugin_opencl.dll")
|
||||
#else
|
||||
#define MSDK_CPU_ROTATE_PLUGIN MSDK_STRING("libsample_rotate_plugin.so")
|
||||
#define MSDK_OCL_ROTATE_PLUGIN MSDK_STRING("libsample_plugin_opencl.so")
|
||||
#endif
|
||||
|
||||
typedef mfxI32 msdkComponentType;
|
||||
enum
|
||||
{
|
||||
MSDK_VDECODE = 0x0001,
|
||||
MSDK_VENCODE = 0x0002,
|
||||
MSDK_VPP = 0x0004,
|
||||
MSDK_VENC = 0x0008,
|
||||
#if (MFX_VERSION >= 1027)
|
||||
MSDK_FEI = 0x1000,
|
||||
#endif
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
MFX_PLUGINLOAD_TYPE_GUID = 1,
|
||||
MFX_PLUGINLOAD_TYPE_FILE = 2
|
||||
} MfxPluginLoadType;
|
||||
|
||||
struct sPluginParams
|
||||
{
|
||||
mfxPluginUID pluginGuid;
|
||||
mfxChar strPluginPath[MSDK_MAX_FILENAME_LEN];
|
||||
MfxPluginLoadType type;
|
||||
sPluginParams()
|
||||
{
|
||||
MSDK_ZERO_MEMORY(*this);
|
||||
}
|
||||
};
|
||||
|
||||
static const mfxPluginUID MSDK_PLUGINGUID_NULL = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
|
||||
bool AreGuidsEqual(const mfxPluginUID& guid1, const mfxPluginUID& guid2);
|
||||
|
||||
const mfxPluginUID & msdkGetPluginUID(mfxIMPL impl, msdkComponentType type, mfxU32 uCodecid);
|
||||
|
||||
sPluginParams ParsePluginGuid(msdk_char* );
|
||||
sPluginParams ParsePluginPath(msdk_char* );
|
||||
mfxStatus ConvertStringToGuid(const msdk_string & strGuid, mfxPluginUID & mfxGuid);
|
||||
|
||||
#endif //__PLUGIN_UTILS_H__
|
||||
127
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/preset_manager.h
vendored
Normal file
127
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/preset_manager.h
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "sample_defs.h"
|
||||
|
||||
#pragma once
|
||||
enum EPresetModes
|
||||
{
|
||||
PRESET_DEFAULT,
|
||||
PRESET_DSS,
|
||||
PRESET_CONF,
|
||||
PRESET_GAMING,
|
||||
PRESET_MAX_MODES
|
||||
};
|
||||
|
||||
enum EPresetCodecs
|
||||
{
|
||||
PRESET_AVC,
|
||||
PRESET_HEVC,
|
||||
PRESET_MAX_CODECS
|
||||
};
|
||||
|
||||
struct CPresetParameters
|
||||
{
|
||||
mfxU16 GopRefDist;
|
||||
|
||||
mfxU16 TargetUsage;
|
||||
|
||||
mfxU16 RateControlMethod;
|
||||
mfxU16 ExtBRCUsage;
|
||||
mfxU16 AsyncDepth;
|
||||
mfxU16 BRefType;
|
||||
mfxU16 AdaptiveMaxFrameSize;
|
||||
mfxU16 LowDelayBRC;
|
||||
|
||||
mfxU16 IntRefType;
|
||||
mfxU16 IntRefCycleSize;
|
||||
mfxU16 IntRefQPDelta;
|
||||
mfxU16 IntRefCycleDist;
|
||||
|
||||
mfxU16 WeightedPred;
|
||||
mfxU16 WeightedBiPred;
|
||||
|
||||
bool EnableBPyramid;
|
||||
bool EnablePPyramid;
|
||||
// bool EnableLTR;
|
||||
};
|
||||
|
||||
struct CDependentPresetParameters
|
||||
{
|
||||
mfxU16 TargetKbps;
|
||||
mfxU16 MaxKbps;
|
||||
mfxU16 GopPicSize;
|
||||
mfxU16 BufferSizeInKB;
|
||||
mfxU16 LookAheadDepth;
|
||||
mfxU32 MaxFrameSize;
|
||||
};
|
||||
|
||||
struct COutputPresetParameters : public CPresetParameters,CDependentPresetParameters
|
||||
{
|
||||
|
||||
msdk_string PresetName;
|
||||
|
||||
void Clear()
|
||||
{
|
||||
memset(dynamic_cast<CPresetParameters*>(this), 0, sizeof(CPresetParameters));
|
||||
memset(dynamic_cast<CDependentPresetParameters*>(this), 0, sizeof(CDependentPresetParameters));
|
||||
}
|
||||
|
||||
COutputPresetParameters()
|
||||
{
|
||||
Clear();
|
||||
}
|
||||
|
||||
COutputPresetParameters(CPresetParameters src)
|
||||
{
|
||||
Clear();
|
||||
*(CPresetParameters*)this = src;
|
||||
}
|
||||
};
|
||||
|
||||
class CPresetManager
|
||||
{
|
||||
public:
|
||||
~CPresetManager();
|
||||
COutputPresetParameters GetPreset(EPresetModes mode, mfxU32 codecFourCC, mfxF64 fps, mfxU32 width, mfxU32 height, bool isHWLib);
|
||||
COutputPresetParameters GetBasicPreset(EPresetModes mode, mfxU32 codecFourCC);
|
||||
CDependentPresetParameters GetDependentPresetParameters(EPresetModes mode, mfxU32 codecFourCC, mfxF64 fps, mfxU32 width, mfxU32 height, mfxU16 targetUsage);
|
||||
|
||||
static CPresetManager Inst;
|
||||
static EPresetModes PresetNameToMode(const msdk_char* name);
|
||||
protected:
|
||||
CPresetManager();
|
||||
static CPresetParameters presets[PRESET_MAX_MODES][PRESET_MAX_CODECS];
|
||||
static msdk_string modesName[PRESET_MAX_MODES];
|
||||
};
|
||||
|
||||
#define MODIFY_AND_PRINT_PARAM(paramName,presetName,shouldPrintPresetInfo) \
|
||||
if (!paramName){ \
|
||||
paramName = presetParams.presetName; \
|
||||
if(shouldPrintPresetInfo){msdk_printf(MSDK_STRING(#presetName) MSDK_STRING(": %d\n"), (int)paramName);} \
|
||||
}else{ \
|
||||
if(shouldPrintPresetInfo){msdk_printf(MSDK_STRING(#presetName) MSDK_STRING(": %d (original preset value: %d)\n"), (int)paramName, (int)presetParams.presetName);}}
|
||||
|
||||
#define MODIFY_AND_PRINT_PARAM_EXT(paramName,presetName,value,shouldPrintPresetInfo) \
|
||||
if (!paramName){ \
|
||||
paramName = (value); \
|
||||
if(shouldPrintPresetInfo){msdk_printf(MSDK_STRING(#presetName) MSDK_STRING(": %d\n"), (int)paramName);} \
|
||||
}else{ \
|
||||
if(shouldPrintPresetInfo){msdk_printf(MSDK_STRING(#presetName) MSDK_STRING(": %d (original preset value: %d)\n"), (int)paramName, (int)(value));}}
|
||||
|
||||
204
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sample_defs.h
vendored
Normal file
204
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sample_defs.h
vendored
Normal file
@@ -0,0 +1,204 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2020, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __SAMPLE_DEFS_H__
|
||||
#define __SAMPLE_DEFS_H__
|
||||
|
||||
#include <memory.h>
|
||||
#include <iostream>
|
||||
|
||||
#include "mfxdefs.h"
|
||||
#include "vm/strings_defs.h"
|
||||
#include "vm/file_defs.h"
|
||||
#include "vm/time_defs.h"
|
||||
|
||||
// Run-time HSBC
|
||||
// the condition below must be changed to MFX_VERSION >= 1027 after API is promoted to 1.27
|
||||
#if (MFX_VERSION >= MFX_VERSION_NEXT)
|
||||
#define ENABLE_VPP_RUNTIME_HSBC
|
||||
#endif
|
||||
|
||||
#if (MFX_VERSION >= 1026)
|
||||
#define ENABLE_MCTF
|
||||
#if defined(MFX_VERSION_NEXT) && (MFX_VERSION >= MFX_VERSION_NEXT)
|
||||
//---MCTF, extended interface
|
||||
#undef ENABLE_MCTF_EXT
|
||||
#endif
|
||||
enum {MCTF_BITRATE_MULTIPLIER = 100000};
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(WIN32) || defined(WIN64)
|
||||
|
||||
enum {
|
||||
MFX_HANDLE_DEVICEWINDOW = 0x101 /* A handle to the render window */
|
||||
}; //mfxHandleType
|
||||
|
||||
#ifndef D3D_SURFACES_SUPPORT
|
||||
#define D3D_SURFACES_SUPPORT 1
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) && !defined(MFX_D3D11_SUPPORT)
|
||||
#include <sdkddkver.h>
|
||||
#if (NTDDI_VERSION >= NTDDI_VERSION_FROM_WIN32_WINNT2(0x0602)) // >= _WIN32_WINNT_WIN8
|
||||
#define MFX_D3D11_SUPPORT 1 // Enable D3D11 support if SDK allows
|
||||
#else
|
||||
#define MFX_D3D11_SUPPORT 0
|
||||
#endif
|
||||
#endif // #if defined(WIN32) && !defined(MFX_D3D11_SUPPORT)
|
||||
#endif // #if defined(WIN32) || defined(WIN64)
|
||||
|
||||
enum
|
||||
{
|
||||
#define __DECLARE(type) MFX_MONITOR_ ## type
|
||||
__DECLARE(Unknown) = 0,
|
||||
__DECLARE(AUTO) = __DECLARE(Unknown),
|
||||
__DECLARE(VGA),
|
||||
__DECLARE(DVII),
|
||||
__DECLARE(DVID),
|
||||
__DECLARE(DVIA),
|
||||
__DECLARE(Composite),
|
||||
__DECLARE(SVIDEO),
|
||||
__DECLARE(LVDS),
|
||||
__DECLARE(Component),
|
||||
__DECLARE(9PinDIN),
|
||||
__DECLARE(HDMIA),
|
||||
__DECLARE(HDMIB),
|
||||
__DECLARE(eDP),
|
||||
__DECLARE(TV),
|
||||
__DECLARE(DisplayPort),
|
||||
#if defined(DRM_MODE_CONNECTOR_VIRTUAL) // from libdrm 2.4.59
|
||||
__DECLARE(VIRTUAL),
|
||||
#endif
|
||||
#if defined(DRM_MODE_CONNECTOR_DSI) // from libdrm 2.4.59
|
||||
__DECLARE(DSI),
|
||||
#endif
|
||||
__DECLARE(MAXNUMBER)
|
||||
#undef __DECLARE
|
||||
};
|
||||
|
||||
#if defined(LIBVA_SUPPORT)
|
||||
|
||||
enum LibVABackend
|
||||
{
|
||||
MFX_LIBVA_AUTO,
|
||||
MFX_LIBVA_DRM,
|
||||
MFX_LIBVA_DRM_RENDERNODE = MFX_LIBVA_DRM,
|
||||
MFX_LIBVA_DRM_MODESET,
|
||||
MFX_LIBVA_X11,
|
||||
MFX_LIBVA_WAYLAND
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//affects win32 winnt version macro
|
||||
#include "vm/time_defs.h"
|
||||
#include "sample_utils.h"
|
||||
|
||||
|
||||
#define MSDK_DEC_WAIT_INTERVAL 300000
|
||||
#define MSDK_ENC_WAIT_INTERVAL 300000
|
||||
#define MSDK_VPP_WAIT_INTERVAL 300000
|
||||
#define MSDK_SURFACE_WAIT_INTERVAL 300000
|
||||
#define MSDK_WAIT_INTERVAL (MSDK_DEC_WAIT_INTERVAL+3*MSDK_VPP_WAIT_INTERVAL+MSDK_ENC_WAIT_INTERVAL) // an estimate for the longest pipeline we have in samples
|
||||
|
||||
#define MSDK_INVALID_SURF_IDX 0xFFFF
|
||||
|
||||
#define MSDK_MAX_FILENAME_LEN 1024
|
||||
#define MSDK_MAX_USER_DATA_UNREG_SEI_LEN 80
|
||||
|
||||
#define MSDK_PRINT_RET_MSG(ERR,MSG) {msdk_stringstream tmpStr1;tmpStr1<<std::endl<<"[ERROR], sts=" \
|
||||
<<StatusToString(ERR)<<"("<<ERR<<")"<<", "<<__FUNCTION__<<", "<<MSG<<" at "<<__FILE__<<":"<<__LINE__<<std::endl;msdk_err<<tmpStr1.str();}
|
||||
|
||||
#define MSDK_PRINT_WRN_MSG(WRN,MSG) {msdk_stringstream tmpStr1;tmpStr1<<std::endl<<"[WARNING], sts=" \
|
||||
<<StatusToString(WRN)<<"("<<WRN<<")"<<", "<<__FUNCTION__<<", "<<MSG<<" at "<<__FILE__<<":"<<__LINE__<<std::endl;msdk_err<<tmpStr1.str();}
|
||||
|
||||
#define MSDK_TRACE_LEVEL(level, ERR) if (level <= msdk_trace_get_level()) {msdk_err<<NoFullPath(MSDK_STRING(__FILE__)) << MSDK_STRING(" :")<< __LINE__ <<MSDK_STRING(" [") \
|
||||
<<level<<MSDK_STRING("] ") << ERR << std::endl;}
|
||||
|
||||
#define MSDK_TRACE_CRITICAL(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_CRITICAL, ERR)
|
||||
#define MSDK_TRACE_ERROR(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_ERROR, ERR)
|
||||
#define MSDK_TRACE_WARNING(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_WARNING, ERR)
|
||||
#define MSDK_TRACE_INFO(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_INFO, ERR)
|
||||
#define MSDK_TRACE_DEBUG(ERR) MSDK_TRACE_LEVEL(MSDK_TRACE_LEVEL_DEBUG, ERR)
|
||||
|
||||
#define MSDK_CHECK_ERROR(P, X, ERR) {if ((X) == (P)) {msdk_stringstream tmpStr2;tmpStr2<<MSDK_STRING(#X)<<MSDK_STRING("==")<<MSDK_STRING(#P)<<MSDK_STRING(" error"); \
|
||||
MSDK_PRINT_RET_MSG(ERR, tmpStr2.str().c_str()); return ERR;}}
|
||||
|
||||
#define MSDK_CHECK_NOT_EQUAL(P, X, ERR) {if ((X) != (P)) {msdk_stringstream tmpStr3;tmpStr3<<MSDK_STRING(#X)<<MSDK_STRING("!=")<<MSDK_STRING(#P)<<MSDK_STRING(" error"); \
|
||||
MSDK_PRINT_RET_MSG(ERR, tmpStr3.str().c_str()); return ERR;}}
|
||||
|
||||
#define MSDK_CHECK_STATUS(X, MSG) {if ((X) < MFX_ERR_NONE) {MSDK_PRINT_RET_MSG(X, MSG); return X;}}
|
||||
#define MSDK_CHECK_STATUS_NO_RET(X, MSG) {if ((X) < MFX_ERR_NONE) {MSDK_PRINT_RET_MSG(X, MSG);}}
|
||||
#define MSDK_CHECK_WRN(X, MSG) {if ((X) > MFX_ERR_NONE) {MSDK_PRINT_WRN_MSG(X, MSG); }}
|
||||
#define MSDK_CHECK_ERR_NONE_STATUS(X, ERR, MSG) {if ((X) != MFX_ERR_NONE) {MSDK_PRINT_RET_MSG(X, MSG); return ERR;}}
|
||||
#define MSDK_CHECK_PARSE_RESULT(P, X, ERR) {if ((X) > (P)) {return ERR;}}
|
||||
|
||||
#define MSDK_CHECK_STATUS_SAFE(X, FUNC, ADD) {if ((X) < MFX_ERR_NONE) {ADD; MSDK_PRINT_RET_MSG(X, FUNC); return X;}}
|
||||
#define MSDK_IGNORE_MFX_STS(P, X) {if ((X) == (P)) {P = MFX_ERR_NONE;}}
|
||||
#define MSDK_CHECK_POINTER(P, ...) {if (!(P)) {msdk_stringstream tmpStr4;tmpStr4<<MSDK_STRING(#P)<<MSDK_STRING(" pointer is NULL");MSDK_PRINT_RET_MSG(MFX_ERR_NULL_PTR, tmpStr4.str().c_str());return __VA_ARGS__;}}
|
||||
#define MSDK_CHECK_POINTER_NO_RET(P) {if (!(P)) {msdk_stringstream tmpStr4;tmpStr4<<MSDK_STRING(#P)<<MSDK_STRING(" pointer is NULL");MSDK_PRINT_RET_MSG(MFX_ERR_NULL_PTR, tmpStr4.str().c_str());return;}}
|
||||
#define MSDK_CHECK_POINTER_SAFE(P, ERR, ADD) {if (!(P)) {ADD; return ERR;}}
|
||||
#define MSDK_BREAK_ON_ERROR(P) {if (MFX_ERR_NONE != (P)) break;}
|
||||
#define MSDK_SAFE_DELETE_ARRAY(P) {if (P) {delete[] P; P = NULL;}}
|
||||
#define MSDK_SAFE_RELEASE(X) {if (X) { X->Release(); X = NULL; }}
|
||||
#define MSDK_SAFE_FREE(X) {if (X) { free(X); X = NULL; }}
|
||||
|
||||
#ifndef MSDK_SAFE_DELETE
|
||||
#define MSDK_SAFE_DELETE(P) {if (P) {delete P; P = NULL;}}
|
||||
#endif // MSDK_SAFE_DELETE
|
||||
|
||||
#define MSDK_ZERO_MEMORY(VAR) {memset(&VAR, 0, sizeof(VAR));}
|
||||
#define MSDK_ALIGN16(value) (((value + 15) >> 4) << 4) // round up to a multiple of 16
|
||||
#define MSDK_ALIGN32(value) (((value + 31) >> 5) << 5) // round up to a multiple of 32
|
||||
#define MSDK_ALIGN(value, alignment) (alignment) * ( (value) / (alignment) + (((value) % (alignment)) ? 1 : 0))
|
||||
#define MSDK_ARRAY_LEN(value) (sizeof(value) / sizeof(value[0]))
|
||||
|
||||
#ifndef UNREFERENCED_PARAMETER
|
||||
#define UNREFERENCED_PARAMETER(par) (par)
|
||||
#endif
|
||||
|
||||
#define MFX_IMPL_VIA_MASK(x) (0x0f00 & (x))
|
||||
|
||||
// Deprecated
|
||||
#define MSDK_PRINT_RET_MSG_(ERR) {msdk_printf(MSDK_STRING("\nReturn on error: error code %d,\t%s\t%d\n\n"), (int)ERR, MSDK_STRING(__FILE__), __LINE__);}
|
||||
#define MSDK_CHECK_RESULT(P, X, ERR) {if ((X) > (P)) {MSDK_PRINT_RET_MSG_(ERR); return ERR;}}
|
||||
#define MSDK_CHECK_RESULT_SAFE(P, X, ERR, ADD) {if ((X) > (P)) {ADD; MSDK_PRINT_RET_MSG_(ERR); return ERR;}}
|
||||
|
||||
namespace mfx
|
||||
{
|
||||
// TODO: switch to std::clamp when C++17 support will be enabled
|
||||
|
||||
// Clip value v to range [lo, hi]
|
||||
template<class T>
|
||||
constexpr const T& clamp( const T& v, const T& lo, const T& hi )
|
||||
{
|
||||
return std::min(hi, std::max(v, lo));
|
||||
}
|
||||
|
||||
// Comp is comparison function object with meaning of 'less' operator (i.e. std::less<> or operator<)
|
||||
template<class T, class Compare>
|
||||
constexpr const T& clamp( const T& v, const T& lo, const T& hi, Compare comp )
|
||||
{
|
||||
return comp(v, lo) ? lo : comp(hi, v) ? hi : v;
|
||||
}
|
||||
}
|
||||
|
||||
#endif //__SAMPLE_DEFS_H__
|
||||
|
||||
52
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sample_types.h
vendored
Normal file
52
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sample_types.h
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __SAMPLE_TYPES_H__
|
||||
#define __SAMPLE_TYPES_H__
|
||||
|
||||
#ifdef UNICODE
|
||||
#define msdk_cout std::wcout
|
||||
#define msdk_err std::wcerr
|
||||
#else
|
||||
#define msdk_cout std::cout
|
||||
#define msdk_err std::cerr
|
||||
#endif
|
||||
|
||||
typedef std::basic_string<msdk_char> msdk_string;
|
||||
typedef std::basic_stringstream<msdk_char> msdk_stringstream;
|
||||
typedef std::basic_ostream<msdk_char, std::char_traits<msdk_char> > msdk_ostream;
|
||||
typedef std::basic_istream<msdk_char, std::char_traits<msdk_char> > msdk_istream;
|
||||
typedef std::basic_fstream<msdk_char, std::char_traits<msdk_char> > msdk_fstream;
|
||||
|
||||
#if defined(_UNICODE)
|
||||
#define MSDK_MAKE_BYTE_STRING(src,dest) \
|
||||
{\
|
||||
std::wstring wstr(src);\
|
||||
std::string str(wstr.length(), 0);\
|
||||
std::transform(wstr.begin(), wstr.end(), str.begin(), [](wchar_t c) {\
|
||||
return (char)c;\
|
||||
});\
|
||||
strcpy_s(dest, str.c_str());\
|
||||
}
|
||||
#else
|
||||
#define MSDK_MAKE_BYTE_STRING(src,dest) msdk_strcopy(dest, src);
|
||||
#endif
|
||||
|
||||
|
||||
#endif //__SAMPLE_TYPES_H__
|
||||
1495
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sample_utils.h
vendored
Normal file
1495
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sample_utils.h
vendored
Normal file
File diff suppressed because it is too large
Load Diff
69
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/surface_auto_lock.h
vendored
Normal file
69
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/surface_auto_lock.h
vendored
Normal file
@@ -0,0 +1,69 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mfxstructures.h"
|
||||
#include "sample_utils.h"
|
||||
|
||||
/*
|
||||
Rationale: locks allocator if necessary to get RAW pointers, unlock it at the end
|
||||
*/
|
||||
class SurfaceAutoLock : private no_copy
|
||||
{
|
||||
public:
|
||||
SurfaceAutoLock(mfxFrameAllocator & alloc, mfxFrameSurface1 &srf)
|
||||
: m_alloc(alloc) , m_srf(srf), m_lockRes(MFX_ERR_NONE), m_bLocked() {
|
||||
LockFrame();
|
||||
}
|
||||
operator mfxStatus () {
|
||||
return m_lockRes;
|
||||
}
|
||||
~SurfaceAutoLock() {
|
||||
UnlockFrame();
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
mfxFrameAllocator & m_alloc;
|
||||
mfxFrameSurface1 & m_srf;
|
||||
mfxStatus m_lockRes;
|
||||
bool m_bLocked;
|
||||
|
||||
void LockFrame()
|
||||
{
|
||||
//no allocator used, no need to do lock
|
||||
if (m_srf.Data.Y != 0)
|
||||
return ;
|
||||
//lock required
|
||||
m_lockRes = m_alloc.Lock(m_alloc.pthis, m_srf.Data.MemId, &m_srf.Data);
|
||||
if (m_lockRes == MFX_ERR_NONE) {
|
||||
m_bLocked = true;
|
||||
}
|
||||
}
|
||||
|
||||
void UnlockFrame()
|
||||
{
|
||||
if (m_lockRes != MFX_ERR_NONE || !m_bLocked) {
|
||||
return;
|
||||
}
|
||||
//unlock required
|
||||
m_alloc.Unlock(m_alloc.pthis, m_srf.Data.MemId, &m_srf.Data);
|
||||
}
|
||||
};
|
||||
84
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sysmem_allocator.h
vendored
Normal file
84
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/sysmem_allocator.h
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __SYSMEM_ALLOCATOR_H__
|
||||
#define __SYSMEM_ALLOCATOR_H__
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "base_allocator.h"
|
||||
#include <vector>
|
||||
|
||||
struct sBuffer
|
||||
{
|
||||
mfxU32 id;
|
||||
mfxU32 nbytes;
|
||||
mfxU16 type;
|
||||
};
|
||||
|
||||
struct sFrame
|
||||
{
|
||||
mfxU32 id;
|
||||
mfxFrameInfo info;
|
||||
};
|
||||
|
||||
struct SysMemAllocatorParams : mfxAllocatorParams
|
||||
{
|
||||
SysMemAllocatorParams()
|
||||
: mfxAllocatorParams(), pBufferAllocator(NULL) { }
|
||||
MFXBufferAllocator *pBufferAllocator;
|
||||
};
|
||||
|
||||
class SysMemFrameAllocator: public BaseFrameAllocator
|
||||
{
|
||||
public:
|
||||
SysMemFrameAllocator();
|
||||
virtual ~SysMemFrameAllocator();
|
||||
|
||||
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 CheckRequestType(mfxFrameAllocRequest *request);
|
||||
virtual mfxStatus ReleaseResponse(mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response);
|
||||
virtual mfxStatus ReallocImpl(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut);
|
||||
|
||||
MFXBufferAllocator *m_pBufferAllocator;
|
||||
bool m_bOwnBufferAllocator;
|
||||
|
||||
std::vector<mfxFrameAllocResponse *> m_vResp;
|
||||
|
||||
mfxMemId *GetMidHolder(mfxMemId mid);
|
||||
};
|
||||
|
||||
class SysMemBufferAllocator : public MFXBufferAllocator
|
||||
{
|
||||
public:
|
||||
SysMemBufferAllocator();
|
||||
virtual ~SysMemBufferAllocator();
|
||||
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);
|
||||
};
|
||||
|
||||
#endif // __SYSMEM_ALLOCATOR_H__
|
||||
263
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/time_statistics.h
vendored
Normal file
263
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/time_statistics.h
vendored
Normal file
@@ -0,0 +1,263 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "mfxstructures.h"
|
||||
#include "vm/time_defs.h"
|
||||
#include "vm/strings_defs.h"
|
||||
#include "math.h"
|
||||
#include <vector>
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
class CTimeStatisticsReal
|
||||
{
|
||||
public:
|
||||
CTimeStatisticsReal()
|
||||
{
|
||||
ResetStatistics();
|
||||
start=0;
|
||||
m_bNeedDumping = false;
|
||||
}
|
||||
|
||||
static msdk_tick GetFrequency()
|
||||
{
|
||||
if (!frequency)
|
||||
{
|
||||
frequency = msdk_time_get_frequency();
|
||||
}
|
||||
return frequency;
|
||||
}
|
||||
|
||||
static mfxF64 ConvertToSeconds(msdk_tick elapsed)
|
||||
{
|
||||
return MSDK_GET_TIME(elapsed, 0, GetFrequency());
|
||||
}
|
||||
|
||||
inline void StartTimeMeasurement()
|
||||
{
|
||||
start = msdk_time_get_tick();
|
||||
}
|
||||
|
||||
inline void StopTimeMeasurement()
|
||||
{
|
||||
mfxF64 delta=GetDeltaTime();
|
||||
totalTime+=delta;
|
||||
totalTimeSquares+=delta*delta;
|
||||
// dump in ms:
|
||||
if(m_bNeedDumping)
|
||||
m_time_deltas.push_back(delta * 1000);
|
||||
|
||||
if(delta<minTime)
|
||||
{
|
||||
minTime=delta;
|
||||
}
|
||||
|
||||
if(delta>maxTime)
|
||||
{
|
||||
maxTime=delta;
|
||||
}
|
||||
numMeasurements++;
|
||||
}
|
||||
|
||||
inline void StopTimeMeasurementWithCheck()
|
||||
{
|
||||
if(start)
|
||||
{
|
||||
StopTimeMeasurement();
|
||||
}
|
||||
}
|
||||
|
||||
inline mfxF64 GetDeltaTime()
|
||||
{
|
||||
return MSDK_GET_TIME(msdk_time_get_tick(), start, GetFrequency());
|
||||
}
|
||||
|
||||
inline mfxF64 GetDeltaTimeInMiliSeconds()
|
||||
{
|
||||
return GetDeltaTime() * 1000;
|
||||
}
|
||||
|
||||
inline void TurnOnDumping(){m_bNeedDumping = true; }
|
||||
|
||||
inline void TurnOffDumping(){m_bNeedDumping = false; }
|
||||
|
||||
inline void PrintStatistics(const msdk_char* prefix)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("%s Total:%.3lfms(%lld smpls),Avg %.3lfms,StdDev:%.3lfms,Min:%.3lfms,Max:%.3lfms\n"),
|
||||
prefix,totalTime,numMeasurements,
|
||||
GetAvgTime(false),GetTimeStdDev(false),
|
||||
GetMinTime(false),GetMaxTime(false));
|
||||
}
|
||||
|
||||
inline mfxU64 GetNumMeasurements()
|
||||
{
|
||||
return numMeasurements;
|
||||
}
|
||||
|
||||
inline mfxF64 GetAvgTime(bool inSeconds=true)
|
||||
{
|
||||
if (inSeconds)
|
||||
{
|
||||
return (numMeasurements ? totalTime / numMeasurements : 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
return (numMeasurements ? totalTime / numMeasurements : 0) * 1000;
|
||||
}
|
||||
}
|
||||
|
||||
inline mfxF64 GetTimeStdDev(bool inSeconds=true)
|
||||
{
|
||||
mfxF64 avg = GetAvgTime();
|
||||
mfxF64 ftmp = (numMeasurements ? sqrt(totalTimeSquares/numMeasurements-avg*avg) : 0.0);
|
||||
return inSeconds ? ftmp : ftmp * 1000;
|
||||
}
|
||||
|
||||
inline mfxF64 GetMinTime(bool inSeconds=true)
|
||||
{
|
||||
return inSeconds ? minTime : minTime * 1000;
|
||||
}
|
||||
|
||||
inline mfxF64 GetMaxTime(bool inSeconds=true)
|
||||
{
|
||||
return inSeconds ? maxTime : maxTime * 1000;
|
||||
}
|
||||
|
||||
inline mfxF64 GetTotalTime(bool inSeconds=true)
|
||||
{
|
||||
return inSeconds ? totalTime : totalTime * 1000;
|
||||
}
|
||||
|
||||
inline void ResetStatistics()
|
||||
{
|
||||
totalTime=0;
|
||||
totalTimeSquares=0;
|
||||
minTime=1E100;
|
||||
maxTime=-1;
|
||||
numMeasurements=0;
|
||||
m_time_deltas.clear();
|
||||
TurnOffDumping();
|
||||
}
|
||||
|
||||
protected:
|
||||
static msdk_tick frequency;
|
||||
|
||||
msdk_tick start;
|
||||
mfxF64 totalTime;
|
||||
mfxF64 totalTimeSquares;
|
||||
mfxF64 minTime;
|
||||
mfxF64 maxTime;
|
||||
mfxU64 numMeasurements;
|
||||
std::vector<mfxF64> m_time_deltas;
|
||||
bool m_bNeedDumping;
|
||||
|
||||
};
|
||||
|
||||
class CTimeStatisticsDummy
|
||||
{
|
||||
public:
|
||||
static msdk_tick GetFrequency()
|
||||
{
|
||||
if (!frequency)
|
||||
{
|
||||
frequency = msdk_time_get_frequency();
|
||||
}
|
||||
return frequency;
|
||||
}
|
||||
|
||||
static mfxF64 ConvertToSeconds(msdk_tick /*elapsed*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void StartTimeMeasurement()
|
||||
{
|
||||
}
|
||||
|
||||
inline void StopTimeMeasurement()
|
||||
{
|
||||
}
|
||||
|
||||
inline void StopTimeMeasurementWithCheck()
|
||||
{
|
||||
}
|
||||
|
||||
inline mfxF64 GetDeltaTime()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline mfxF64 GetDeltaTimeInMiliSeconds()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void TurnOnDumping() {}
|
||||
|
||||
inline void TurnOffDumping() {}
|
||||
|
||||
inline void PrintStatistics(const msdk_char* /*prefix*/)
|
||||
{
|
||||
}
|
||||
|
||||
inline mfxU64 GetNumMeasurements()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline mfxF64 GetAvgTime(bool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline mfxF64 GetTimeStdDev(bool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline mfxF64 GetMinTime(bool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline mfxF64 GetMaxTime(bool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline mfxF64 GetTotalTime(bool)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline void ResetStatistics()
|
||||
{
|
||||
}
|
||||
|
||||
protected:
|
||||
static msdk_tick frequency;
|
||||
};
|
||||
|
||||
#ifdef TIME_STATS
|
||||
typedef CTimeStatisticsReal CTimeStatistics;
|
||||
#else
|
||||
typedef CTimeStatisticsDummy CTimeStatistics;
|
||||
#endif
|
||||
120
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/v4l2_util.h
vendored
Normal file
120
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/v4l2_util.h
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __V4L2_UTIL_H__
|
||||
#define __V4L2_UTIL_H__
|
||||
|
||||
#include <pthread.h>
|
||||
#include <stdlib.h>
|
||||
#include <va/va.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include "sample_defs.h"
|
||||
|
||||
/* MIPI DRIVER Configurations*/
|
||||
#define _ISP_MODE_NONE 0x0000
|
||||
#define _ISP_MODE_CONTINUOUS 0x1000
|
||||
#define _ISP_MODE_STILL 0x2000
|
||||
#define _ISP_MODE_VIDEO 0x4000
|
||||
#define _ISP_MODE_PREVIEW 0x8000
|
||||
|
||||
#define CLEAR(x) memset(&(x), 0, sizeof(x))
|
||||
#define ERRSTR strerror(errno)
|
||||
|
||||
#define BYE_ON(cond, ...) \
|
||||
do { \
|
||||
if (cond) { \
|
||||
int errsv = errno; \
|
||||
fprintf(stderr, "ERROR(%s:%d) : ", \
|
||||
__FILE__, __LINE__); \
|
||||
errno = errsv; \
|
||||
fprintf(stderr, __VA_ARGS__); \
|
||||
abort(); \
|
||||
} \
|
||||
} while(0)
|
||||
|
||||
enum AtomISPMode
|
||||
{
|
||||
NONE = 0, PREVIEW, STILL, VIDEO, CONTINUOUS
|
||||
};
|
||||
|
||||
enum V4L2PixelFormat
|
||||
{
|
||||
NO_FORMAT = 0, UYVY, YUY2
|
||||
};
|
||||
|
||||
typedef struct _Buffer
|
||||
{
|
||||
int fd, index;
|
||||
} Buffer;
|
||||
|
||||
extern Buffer *buffers;
|
||||
void *PollingThread(void *data);
|
||||
|
||||
class v4l2Device
|
||||
{
|
||||
public:
|
||||
v4l2Device(const char *devname = "/dev/video0",
|
||||
uint32_t width = 1920,
|
||||
uint32_t height = 1080,
|
||||
uint32_t num_buffer = 4,
|
||||
enum AtomISPMode MipiMode = NONE,
|
||||
enum V4L2PixelFormat m_v4l2Format = NO_FORMAT);
|
||||
|
||||
~v4l2Device();
|
||||
|
||||
void Init(const char *devname,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t num_buffer,
|
||||
enum V4L2PixelFormat v4l2Format,
|
||||
enum AtomISPMode MipiMode,
|
||||
int m_MipiPort);
|
||||
|
||||
void V4L2Init();
|
||||
void V4L2Alloc();
|
||||
int blockIOCTL(int handle, int request, void *args);
|
||||
int GetAtomISPModes(enum AtomISPMode mode);
|
||||
void V4L2QueueBuffer(Buffer *buffer);
|
||||
Buffer *V4L2DeQueueBuffer(Buffer *buffer);
|
||||
void V4L2StartCapture();
|
||||
void V4L2StopCapture();
|
||||
int GetV4L2TerminationSignal();
|
||||
void PutOnQ(int x);
|
||||
int GetOffQ();
|
||||
int ConvertToMFXFourCC(enum V4L2PixelFormat v4l2Format);
|
||||
int ConvertToV4L2FourCC();
|
||||
int GetV4L2DisplayID() { return m_fd; }
|
||||
bool ISV4L2Enabled() { return (m_fd > 0)? true : false; }
|
||||
|
||||
protected:
|
||||
const char *m_devname;
|
||||
uint32_t m_height;
|
||||
uint32_t m_width;
|
||||
uint32_t m_num_buffers;
|
||||
struct v4l2_pix_format m_format;
|
||||
int m_MipiPort;
|
||||
enum AtomISPMode m_MipiMode;
|
||||
enum V4L2PixelFormat m_v4l2Format;
|
||||
int m_fd;
|
||||
};
|
||||
|
||||
#endif // ifdef __V4L2_UTIL_H__
|
||||
111
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_allocator.h
vendored
Normal file
111
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_allocator.h
vendored
Normal file
@@ -0,0 +1,111 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __VAAPI_ALLOCATOR_H__
|
||||
#define __VAAPI_ALLOCATOR_H__
|
||||
|
||||
#if defined(LIBVA_SUPPORT)
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <va/va.h>
|
||||
#include <va/va_drmcommon.h>
|
||||
|
||||
#include "base_allocator.h"
|
||||
#include "vaapi_utils.h"
|
||||
|
||||
// VAAPI Allocator internal Mem ID
|
||||
struct vaapiMemId
|
||||
{
|
||||
VASurfaceID* m_surface;
|
||||
VAImage m_image;
|
||||
// variables for VAAPI Allocator internal color conversion
|
||||
unsigned int m_fourcc;
|
||||
mfxU8* m_sys_buffer;
|
||||
mfxU8* m_va_buffer;
|
||||
// buffer info to support surface export
|
||||
VABufferInfo m_buffer_info;
|
||||
// pointer to private export data
|
||||
void* m_custom;
|
||||
};
|
||||
|
||||
namespace MfxLoader
|
||||
{
|
||||
class VA_Proxy;
|
||||
}
|
||||
|
||||
struct vaapiAllocatorParams : mfxAllocatorParams
|
||||
{
|
||||
enum {
|
||||
DONOT_EXPORT = 0,
|
||||
FLINK = 0x01,
|
||||
PRIME = 0x02,
|
||||
NATIVE_EXPORT_MASK = FLINK | PRIME,
|
||||
CUSTOM = 0x100,
|
||||
CUSTOM_FLINK = CUSTOM | FLINK,
|
||||
CUSTOM_PRIME = CUSTOM | PRIME
|
||||
};
|
||||
class Exporter
|
||||
{
|
||||
public:
|
||||
virtual ~Exporter(){}
|
||||
virtual void* acquire(mfxMemId mid) = 0;
|
||||
virtual void release(mfxMemId mid, void * hdl) = 0;
|
||||
};
|
||||
|
||||
vaapiAllocatorParams()
|
||||
: m_dpy(NULL)
|
||||
, m_export_mode(DONOT_EXPORT)
|
||||
, m_exporter(NULL)
|
||||
{}
|
||||
|
||||
VADisplay m_dpy;
|
||||
mfxU32 m_export_mode;
|
||||
Exporter* m_exporter;
|
||||
};
|
||||
|
||||
class vaapiFrameAllocator: public BaseFrameAllocator
|
||||
{
|
||||
public:
|
||||
vaapiFrameAllocator();
|
||||
virtual ~vaapiFrameAllocator();
|
||||
|
||||
virtual mfxStatus Init(mfxAllocatorParams *pParams);
|
||||
virtual mfxStatus Close();
|
||||
|
||||
protected:
|
||||
DISALLOW_COPY_AND_ASSIGN(vaapiFrameAllocator);
|
||||
|
||||
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 ReallocImpl(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut);
|
||||
|
||||
VADisplay m_dpy;
|
||||
MfxLoader::VA_Proxy * m_libva;
|
||||
mfxU32 m_export_mode;
|
||||
vaapiAllocatorParams::Exporter* m_exporter;
|
||||
};
|
||||
|
||||
#endif //#if defined(LIBVA_SUPPORT)
|
||||
|
||||
#endif // __VAAPI_ALLOCATOR_H__
|
||||
231
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_device.h
vendored
Normal file
231
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_device.h
vendored
Normal file
@@ -0,0 +1,231 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined(LIBVA_ANDROID_SUPPORT) || defined(LIBVA_WAYLAND_SUPPORT)
|
||||
|
||||
#include "hw_device.h"
|
||||
#include "vaapi_utils_drm.h"
|
||||
#include "vaapi_utils_x11.h"
|
||||
#if defined(LIBVA_ANDROID_SUPPORT)
|
||||
#include "vaapi_utils_android.h"
|
||||
#endif
|
||||
|
||||
CHWDevice* CreateVAAPIDevice(const std::string& devicePath = "", int type = MFX_LIBVA_DRM);
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
/** VAAPI DRM implementation. */
|
||||
class CVAAPIDeviceDRM : public CHWDevice
|
||||
{
|
||||
public:
|
||||
CVAAPIDeviceDRM(const std::string& devicePath, int type);
|
||||
virtual ~CVAAPIDeviceDRM(void);
|
||||
|
||||
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
|
||||
virtual mfxStatus Reset(void) { return MFX_ERR_NONE; }
|
||||
virtual void Close(void) { }
|
||||
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl) { return MFX_ERR_UNSUPPORTED; }
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl)
|
||||
{
|
||||
if ((MFX_HANDLE_VA_DISPLAY == type) && (NULL != pHdl))
|
||||
{
|
||||
*pHdl = m_DRMLibVA.GetVADisplay();
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc);
|
||||
virtual void UpdateTitle(double fps) { }
|
||||
virtual void SetMondelloInput(bool isMondelloInputEnabled) { }
|
||||
|
||||
inline drmRenderer* getRenderer() { return m_rndr; }
|
||||
protected:
|
||||
DRMLibVA m_DRMLibVA;
|
||||
drmRenderer * m_rndr;
|
||||
private:
|
||||
// no copies allowed
|
||||
CVAAPIDeviceDRM(const CVAAPIDeviceDRM &);
|
||||
void operator=(const CVAAPIDeviceDRM &);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
/** VAAPI X11 implementation. */
|
||||
class CVAAPIDeviceX11 : public CHWDevice
|
||||
{
|
||||
public:
|
||||
CVAAPIDeviceX11()
|
||||
{
|
||||
m_window = NULL;
|
||||
m_nRenderWinX=0;
|
||||
m_nRenderWinY=0;
|
||||
m_nRenderWinW=0;
|
||||
m_nRenderWinH=0;
|
||||
m_bRenderWin=false;
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
m_dri_fd = 0;
|
||||
m_bufmgr = NULL;
|
||||
m_xcbconn = NULL;
|
||||
#endif
|
||||
}
|
||||
virtual ~CVAAPIDeviceX11(void);
|
||||
|
||||
virtual mfxStatus Init(
|
||||
mfxHDL hWindow,
|
||||
mfxU16 nViews,
|
||||
mfxU32 nAdapterNum);
|
||||
virtual mfxStatus Reset(void);
|
||||
virtual void Close(void);
|
||||
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl);
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl);
|
||||
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc);
|
||||
virtual void UpdateTitle(double fps) { }
|
||||
virtual void SetMondelloInput(bool isMondelloInputEnabled) { }
|
||||
|
||||
protected:
|
||||
mfxHDL m_window;
|
||||
X11LibVA m_X11LibVA;
|
||||
private:
|
||||
|
||||
bool m_bRenderWin;
|
||||
mfxU32 m_nRenderWinX;
|
||||
mfxU32 m_nRenderWinY;
|
||||
mfxU32 m_nRenderWinW;
|
||||
mfxU32 m_nRenderWinH;
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
int m_dri_fd;
|
||||
drm_intel_bufmgr* m_bufmgr;
|
||||
xcb_connection_t *m_xcbconn;
|
||||
#endif
|
||||
// no copies allowed
|
||||
CVAAPIDeviceX11(const CVAAPIDeviceX11 &);
|
||||
void operator=(const CVAAPIDeviceX11 &);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_WAYLAND_SUPPORT)
|
||||
|
||||
class Wayland;
|
||||
|
||||
class CVAAPIDeviceWayland : public CHWDevice
|
||||
{
|
||||
public:
|
||||
CVAAPIDeviceWayland(){
|
||||
m_nRenderWinX = 0;
|
||||
m_nRenderWinY = 0;
|
||||
m_nRenderWinW = 0;
|
||||
m_nRenderWinH = 0;
|
||||
m_isMondelloInputEnabled = false;
|
||||
m_Wayland = NULL;
|
||||
}
|
||||
virtual ~CVAAPIDeviceWayland(void);
|
||||
|
||||
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum);
|
||||
virtual mfxStatus Reset(void) { return MFX_ERR_NONE; }
|
||||
virtual void Close(void);
|
||||
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl) { return MFX_ERR_UNSUPPORTED; }
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl)
|
||||
{
|
||||
if((MFX_HANDLE_VA_DISPLAY == type) && (NULL != pHdl)) {
|
||||
*pHdl = m_DRMLibVA.GetVADisplay();
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc);
|
||||
virtual void UpdateTitle(double fps) { }
|
||||
|
||||
virtual void SetMondelloInput(bool isMondelloInputEnabled)
|
||||
{
|
||||
m_isMondelloInputEnabled = isMondelloInputEnabled;
|
||||
}
|
||||
|
||||
Wayland * GetWaylandHandle()
|
||||
{
|
||||
return m_Wayland;
|
||||
}
|
||||
protected:
|
||||
DRMLibVA m_DRMLibVA;
|
||||
MfxLoader::VA_WaylandClientProxy m_WaylandClient;
|
||||
Wayland *m_Wayland;
|
||||
private:
|
||||
mfxU32 m_nRenderWinX;
|
||||
mfxU32 m_nRenderWinY;
|
||||
mfxU32 m_nRenderWinW;
|
||||
mfxU32 m_nRenderWinH;
|
||||
|
||||
bool m_isMondelloInputEnabled;
|
||||
|
||||
// no copies allowed
|
||||
CVAAPIDeviceWayland(const CVAAPIDeviceWayland &);
|
||||
void operator=(const CVAAPIDeviceWayland &);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_ANDROID_SUPPORT)
|
||||
|
||||
/** VAAPI Android implementation. */
|
||||
class CVAAPIDeviceAndroid : public CHWDevice
|
||||
{
|
||||
public:
|
||||
CVAAPIDeviceAndroid(AndroidLibVA *pAndroidLibVA):
|
||||
m_pAndroidLibVA(pAndroidLibVA)
|
||||
{
|
||||
if (!m_pAndroidLibVA)
|
||||
{
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
};
|
||||
virtual ~CVAAPIDeviceAndroid(void) { Close();}
|
||||
|
||||
virtual mfxStatus Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum) { return MFX_ERR_NONE;}
|
||||
virtual mfxStatus Reset(void) { return MFX_ERR_NONE; }
|
||||
virtual void Close(void) { }
|
||||
|
||||
virtual mfxStatus SetHandle(mfxHandleType type, mfxHDL hdl) { return MFX_ERR_UNSUPPORTED; }
|
||||
virtual mfxStatus GetHandle(mfxHandleType type, mfxHDL *pHdl)
|
||||
{
|
||||
if ((MFX_HANDLE_VA_DISPLAY == type) && (NULL != pHdl))
|
||||
{
|
||||
if(m_pAndroidLibVA)*pHdl = m_pAndroidLibVA->GetVADisplay();
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
virtual mfxStatus RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc) { return MFX_ERR_NONE; }
|
||||
virtual void UpdateTitle(double fps) { }
|
||||
virtual void SetMondelloInput(bool isMondelloInputEnabled) { }
|
||||
|
||||
protected:
|
||||
AndroidLibVA* m_pAndroidLibVA;
|
||||
};
|
||||
#endif
|
||||
#endif //#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined(LIBVA_ANDROID_SUPPORT)
|
||||
481
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils.h
vendored
Normal file
481
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils.h
vendored
Normal file
@@ -0,0 +1,481 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __VAAPI_UTILS_H__
|
||||
#define __VAAPI_UTILS_H__
|
||||
|
||||
#ifdef LIBVA_SUPPORT
|
||||
|
||||
#include <va/va.h>
|
||||
#include <va/va_drmcommon.h>
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
#include <xf86drm.h>
|
||||
#include <xf86drmMode.h>
|
||||
#include <libdrm/intel_bufmgr.h>
|
||||
#include <va/va_drm.h>
|
||||
#endif
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
#include <va/va_x11.h>
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
#include <xcb/dri3.h>
|
||||
#include <xcb/present.h>
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
#endif
|
||||
#include "sample_defs.h"
|
||||
#include "sample_utils.h"
|
||||
#include "vm/thread_defs.h"
|
||||
|
||||
namespace MfxLoader
|
||||
{
|
||||
|
||||
class SimpleLoader
|
||||
{
|
||||
public:
|
||||
SimpleLoader(const char * name);
|
||||
|
||||
void * GetFunction(const char * name);
|
||||
|
||||
~SimpleLoader();
|
||||
|
||||
private:
|
||||
SimpleLoader(SimpleLoader&);
|
||||
void operator=(SimpleLoader&);
|
||||
|
||||
void * so_handle;
|
||||
};
|
||||
|
||||
#ifdef LIBVA_SUPPORT
|
||||
class VA_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef VAStatus (*vaInitialize_type)(VADisplay, int *, int *);
|
||||
typedef VAStatus (*vaTerminate_type)(VADisplay);
|
||||
typedef VAStatus (*vaCreateSurfaces_type)(VADisplay, unsigned int,
|
||||
unsigned int, unsigned int, VASurfaceID *, unsigned int,
|
||||
VASurfaceAttrib *, unsigned int);
|
||||
typedef VAStatus (*vaDestroySurfaces_type)(VADisplay, VASurfaceID *, int);
|
||||
typedef VAStatus (*vaCreateBuffer_type)(VADisplay, VAContextID,
|
||||
VABufferType, unsigned int, unsigned int, void *, VABufferID *);
|
||||
typedef VAStatus (*vaDestroyBuffer_type)(VADisplay, VABufferID);
|
||||
typedef VAStatus (*vaMapBuffer_type)(VADisplay, VABufferID, void **pbuf);
|
||||
typedef VAStatus (*vaUnmapBuffer_type)(VADisplay, VABufferID);
|
||||
typedef VAStatus (*vaSyncSurface_type)(VADisplay, VASurfaceID);
|
||||
typedef VAStatus (*vaDeriveImage_type)(VADisplay, VASurfaceID, VAImage *);
|
||||
typedef VAStatus (*vaDestroyImage_type)(VADisplay, VAImageID);
|
||||
typedef VAStatus (*vaGetLibFunc_type)(VADisplay, const char *func);
|
||||
typedef VAStatus (*vaAcquireBufferHandle_type)(VADisplay, VABufferID, VABufferInfo *);
|
||||
typedef VAStatus (*vaReleaseBufferHandle_type)(VADisplay, VABufferID);
|
||||
typedef VAStatus (*vaMaxNumEntrypoints_type)(VADisplay dpy);
|
||||
typedef VAStatus (*vaQueryConfigEntrypoints_type)(VADisplay dpy,
|
||||
VAProfile profile,
|
||||
VAEntrypoint *entrypoint_list,
|
||||
int *num_entrypoints);
|
||||
typedef VAStatus (*vaGetConfigAttributes_type)(VADisplay dpy,
|
||||
VAProfile profile,
|
||||
VAEntrypoint entrypoint,
|
||||
VAConfigAttrib *attrib_list,
|
||||
int num_attribs);
|
||||
typedef VAStatus (*vaCreateConfig_type)(VADisplay dpy,
|
||||
VAProfile profile,
|
||||
VAEntrypoint entrypoint,
|
||||
VAConfigAttrib *attrib_list,
|
||||
int num_attribs,
|
||||
VAConfigID *config_id);
|
||||
|
||||
typedef VAStatus (*vaCreateContext_type)(VADisplay dpy,
|
||||
VAConfigID config_id,
|
||||
int picture_width,
|
||||
int picture_height,
|
||||
int flag,
|
||||
VASurfaceID *render_targets,
|
||||
int num_render_targets,
|
||||
VAContextID *context);
|
||||
typedef VAStatus (*vaDestroyConfig_type) (VADisplay dpy,
|
||||
VAConfigID config_id);
|
||||
typedef VAStatus (*vaDestroyContext_type) (VADisplay dpy,
|
||||
VAContextID context);
|
||||
|
||||
VA_Proxy();
|
||||
~VA_Proxy();
|
||||
|
||||
const vaInitialize_type vaInitialize;
|
||||
const vaTerminate_type vaTerminate;
|
||||
const vaCreateSurfaces_type vaCreateSurfaces;
|
||||
const vaDestroySurfaces_type vaDestroySurfaces;
|
||||
const vaCreateBuffer_type vaCreateBuffer;
|
||||
const vaDestroyBuffer_type vaDestroyBuffer;
|
||||
const vaMapBuffer_type vaMapBuffer;
|
||||
const vaUnmapBuffer_type vaUnmapBuffer;
|
||||
const vaSyncSurface_type vaSyncSurface;
|
||||
const vaDeriveImage_type vaDeriveImage;
|
||||
const vaDestroyImage_type vaDestroyImage;
|
||||
const vaGetLibFunc_type vaGetLibFunc;
|
||||
const vaAcquireBufferHandle_type vaAcquireBufferHandle;
|
||||
const vaReleaseBufferHandle_type vaReleaseBufferHandle;
|
||||
const vaMaxNumEntrypoints_type vaMaxNumEntrypoints;
|
||||
const vaQueryConfigEntrypoints_type vaQueryConfigEntrypoints;
|
||||
const vaGetConfigAttributes_type vaGetConfigAttributes;
|
||||
const vaCreateConfig_type vaCreateConfig;
|
||||
const vaCreateContext_type vaCreateContext;
|
||||
const vaDestroyConfig_type vaDestroyConfig;
|
||||
const vaDestroyContext_type vaDestroyContext;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
class DRM_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef int (*drmIoctl_type)(int fd, unsigned long request, void *arg);
|
||||
typedef int (*drmModeAddFB_type)(
|
||||
int fd, uint32_t width, uint32_t height, uint8_t depth,
|
||||
uint8_t bpp, uint32_t pitch, uint32_t bo_handle,
|
||||
uint32_t *buf_id);
|
||||
typedef int (*drmModeAddFB2WithModifiers_type)(int fd, uint32_t width, uint32_t height, uint32_t pixel_format,
|
||||
uint32_t bo_handles[4], uint32_t pitches[4], uint32_t offsets[4], uint64_t modifier[4],
|
||||
uint32_t *buf_id, uint32_t flags);
|
||||
typedef void (*drmModeFreeConnector_type)( drmModeConnectorPtr ptr );
|
||||
typedef void (*drmModeFreeCrtc_type)( drmModeCrtcPtr ptr );
|
||||
typedef void (*drmModeFreeEncoder_type)( drmModeEncoderPtr ptr );
|
||||
typedef void (*drmModeFreePlane_type)( drmModePlanePtr ptr );
|
||||
typedef void (*drmModeFreePlaneResources_type)(drmModePlaneResPtr ptr);
|
||||
typedef void (*drmModeFreeResources_type)( drmModeResPtr ptr );
|
||||
typedef drmModeConnectorPtr (*drmModeGetConnector_type)(
|
||||
int fd, uint32_t connectorId);
|
||||
typedef drmModeCrtcPtr (*drmModeGetCrtc_type)(int fd, uint32_t crtcId);
|
||||
typedef drmModeEncoderPtr (*drmModeGetEncoder_type)(int fd, uint32_t encoder_id);
|
||||
typedef drmModePlanePtr (*drmModeGetPlane_type)(int fd, uint32_t plane_id);
|
||||
typedef drmModePlaneResPtr (*drmModeGetPlaneResources_type)(int fd);
|
||||
typedef drmModeResPtr (*drmModeGetResources_type)(int fd);
|
||||
typedef int (*drmModeRmFB_type)(int fd, uint32_t bufferId);
|
||||
typedef int (*drmModeSetCrtc_type)(
|
||||
int fd, uint32_t crtcId, uint32_t bufferId,
|
||||
uint32_t x, uint32_t y, uint32_t *connectors, int count,
|
||||
drmModeModeInfoPtr mode);
|
||||
typedef int (*drmSetMaster_type)(int fd);
|
||||
typedef int (*drmDropMaster_type)(int fd);
|
||||
typedef int (*drmModeSetPlane_type)(
|
||||
int fd, uint32_t plane_id, uint32_t crtc_id,
|
||||
uint32_t fb_id, uint32_t flags,
|
||||
int32_t crtc_x, int32_t crtc_y,
|
||||
uint32_t crtc_w, uint32_t crtc_h,
|
||||
uint32_t src_x, uint32_t src_y,
|
||||
uint32_t src_w, uint32_t src_h);
|
||||
|
||||
DRM_Proxy();
|
||||
~DRM_Proxy();
|
||||
|
||||
#define __DECLARE(name) const name ## _type name
|
||||
__DECLARE(drmIoctl);
|
||||
__DECLARE(drmModeAddFB);
|
||||
__DECLARE(drmModeAddFB2WithModifiers);
|
||||
__DECLARE(drmModeFreeConnector);
|
||||
__DECLARE(drmModeFreeCrtc);
|
||||
__DECLARE(drmModeFreeEncoder);
|
||||
__DECLARE(drmModeFreePlane);
|
||||
__DECLARE(drmModeFreePlaneResources);
|
||||
__DECLARE(drmModeFreeResources);
|
||||
__DECLARE(drmModeGetConnector);
|
||||
__DECLARE(drmModeGetCrtc);
|
||||
__DECLARE(drmModeGetEncoder);
|
||||
__DECLARE(drmModeGetPlane);
|
||||
__DECLARE(drmModeGetPlaneResources);
|
||||
__DECLARE(drmModeGetResources);
|
||||
__DECLARE(drmModeRmFB);
|
||||
__DECLARE(drmModeSetCrtc);
|
||||
__DECLARE(drmSetMaster);
|
||||
__DECLARE(drmDropMaster);
|
||||
__DECLARE(drmModeSetPlane);
|
||||
#undef __DECLARE
|
||||
};
|
||||
|
||||
class DrmIntel_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef drm_intel_bo* (*drm_intel_bo_gem_create_from_prime_type)(
|
||||
drm_intel_bufmgr *bufmgr, int prime_fd, int size);
|
||||
typedef void (*drm_intel_bo_unreference_type)(drm_intel_bo *bo);
|
||||
typedef drm_intel_bufmgr* (*drm_intel_bufmgr_gem_init_type)(int fd, int batch_size);
|
||||
typedef int (*drm_intel_bo_gem_export_to_prime_type) (drm_intel_bo *, int *);
|
||||
typedef void (*drm_intel_bufmgr_destroy_type)(drm_intel_bufmgr*);
|
||||
|
||||
DrmIntel_Proxy();
|
||||
~DrmIntel_Proxy();
|
||||
|
||||
#define __DECLARE(name) const name ## _type name
|
||||
__DECLARE(drm_intel_bo_gem_create_from_prime);
|
||||
__DECLARE(drm_intel_bo_unreference);
|
||||
__DECLARE(drm_intel_bufmgr_gem_init);
|
||||
__DECLARE(drm_intel_bufmgr_destroy);
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
__DECLARE(drm_intel_bo_gem_export_to_prime);
|
||||
#endif
|
||||
|
||||
#undef __DECLARE
|
||||
};
|
||||
|
||||
class VA_DRMProxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef VADisplay (*vaGetDisplayDRM_type)(int);
|
||||
|
||||
|
||||
VA_DRMProxy();
|
||||
~VA_DRMProxy();
|
||||
|
||||
const vaGetDisplayDRM_type vaGetDisplayDRM;
|
||||
};
|
||||
#endif
|
||||
|
||||
#if defined (LIBVA_WAYLAND_SUPPORT)
|
||||
|
||||
class Wayland;
|
||||
|
||||
class VA_WaylandClientProxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef Wayland* (*WaylandCreate_type)(void);
|
||||
|
||||
VA_WaylandClientProxy();
|
||||
~VA_WaylandClientProxy();
|
||||
|
||||
const WaylandCreate_type WaylandCreate;
|
||||
};
|
||||
|
||||
#endif // LIBVA_WAYLAND_SUPPORT
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
class VA_X11Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef VADisplay (*vaGetDisplay_type)(Display*);
|
||||
typedef VAStatus (*vaPutSurface_type)(
|
||||
VADisplay, VASurfaceID,
|
||||
Drawable,
|
||||
short, short,
|
||||
unsigned short, unsigned short,
|
||||
short, short,
|
||||
unsigned short, unsigned short,
|
||||
VARectangle *,
|
||||
unsigned int, unsigned int);
|
||||
|
||||
VA_X11Proxy();
|
||||
~VA_X11Proxy();
|
||||
|
||||
const vaGetDisplay_type vaGetDisplay;
|
||||
const vaPutSurface_type vaPutSurface;
|
||||
};
|
||||
|
||||
class XLib_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef Display* (*XOpenDisplay_type) (const char*);
|
||||
typedef int (*XCloseDisplay_type)(Display*);
|
||||
typedef Window (*XCreateSimpleWindow_type)(Display *,
|
||||
Window, int, int,
|
||||
unsigned int, unsigned int,
|
||||
unsigned int, unsigned long,
|
||||
unsigned long);
|
||||
typedef int (*XMapWindow_type)(Display*, Window);
|
||||
typedef int (*XSync_type)(Display*, Bool);
|
||||
typedef int (*XDestroyWindow_type)(Display*, Window);
|
||||
typedef int (*XResizeWindow_type)(Display *, Window, unsigned int, unsigned int);
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
typedef Status (*XGetGeometry_type)(Display *, Drawable, Window *,
|
||||
int *, int *, unsigned int *, unsigned int *,
|
||||
unsigned int *, unsigned int *);
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
XLib_Proxy();
|
||||
~XLib_Proxy();
|
||||
|
||||
const XOpenDisplay_type XOpenDisplay;
|
||||
const XCloseDisplay_type XCloseDisplay;
|
||||
const XCreateSimpleWindow_type XCreateSimpleWindow;
|
||||
const XMapWindow_type XMapWindow;
|
||||
const XSync_type XSync;
|
||||
const XDestroyWindow_type XDestroyWindow;
|
||||
const XResizeWindow_type XResizeWindow;
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
const XGetGeometry_type XGetGeometry;
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
};
|
||||
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
|
||||
class XCB_Dri3_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef xcb_void_cookie_t (*xcb_dri3_pixmap_from_buffer_type) (xcb_connection_t *,
|
||||
xcb_pixmap_t,
|
||||
xcb_drawable_t,
|
||||
uint32_t,
|
||||
uint16_t,
|
||||
uint16_t,
|
||||
uint16_t,
|
||||
uint8_t,
|
||||
uint8_t,
|
||||
int32_t);
|
||||
typedef xcb_dri3_pixmap_from_buffer_type xcb_dri3_pixmap_from_buffer_checked_type;
|
||||
|
||||
XCB_Dri3_Proxy();
|
||||
~XCB_Dri3_Proxy();
|
||||
|
||||
const xcb_dri3_pixmap_from_buffer_checked_type xcb_dri3_pixmap_from_buffer_checked;
|
||||
};
|
||||
|
||||
class Xcb_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef uint32_t (*xcb_generate_id_type) (xcb_connection_t *);
|
||||
typedef xcb_void_cookie_t (*xcb_free_pixmap_type) (xcb_connection_t *, xcb_pixmap_t);
|
||||
typedef int (*xcb_flush_type)(xcb_connection_t *);
|
||||
typedef xcb_generic_error_t* (*xcb_request_check_type)(xcb_connection_t *c, xcb_void_cookie_t cookie);
|
||||
|
||||
Xcb_Proxy();
|
||||
~Xcb_Proxy();
|
||||
|
||||
const xcb_generate_id_type xcb_generate_id;
|
||||
const xcb_free_pixmap_type xcb_free_pixmap;
|
||||
const xcb_flush_type xcb_flush;
|
||||
const xcb_request_check_type xcb_request_check;
|
||||
};
|
||||
|
||||
class X11_Xcb_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib; // should appear first in member list
|
||||
|
||||
public:
|
||||
typedef xcb_connection_t * (*XGetXCBConnection_type) (Display *dpy);
|
||||
|
||||
X11_Xcb_Proxy();
|
||||
~X11_Xcb_Proxy();
|
||||
|
||||
const XGetXCBConnection_type XGetXCBConnection;
|
||||
};
|
||||
|
||||
class Xcbpresent_Proxy
|
||||
{
|
||||
private:
|
||||
SimpleLoader lib;
|
||||
|
||||
public:
|
||||
typedef xcb_void_cookie_t (*xcb_present_pixmap_type) (xcb_connection_t *,
|
||||
xcb_window_t,
|
||||
xcb_pixmap_t,
|
||||
uint32_t,
|
||||
xcb_xfixes_region_t,
|
||||
xcb_xfixes_region_t,
|
||||
int16_t,
|
||||
int16_t,
|
||||
xcb_randr_crtc_t,
|
||||
xcb_sync_fence_t,
|
||||
xcb_sync_fence_t,
|
||||
uint32_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint64_t,
|
||||
uint32_t,
|
||||
const xcb_present_notify_t *);
|
||||
typedef xcb_present_pixmap_type xcb_present_pixmap_checked_type;
|
||||
|
||||
Xcbpresent_Proxy();
|
||||
~Xcbpresent_Proxy();
|
||||
|
||||
const xcb_present_pixmap_checked_type xcb_present_pixmap_checked;
|
||||
};
|
||||
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
#endif
|
||||
|
||||
} // namespace MfxLoader
|
||||
|
||||
|
||||
class CLibVA
|
||||
{
|
||||
public:
|
||||
virtual ~CLibVA(void) {};
|
||||
|
||||
VAStatus AcquireVASurface(
|
||||
void** pctx,
|
||||
VADisplay dpy1,
|
||||
VASurfaceID srf1,
|
||||
VADisplay dpy2,
|
||||
VASurfaceID* srf2);
|
||||
void ReleaseVASurface(
|
||||
void* actx,
|
||||
VADisplay dpy1,
|
||||
VASurfaceID /*srf1*/,
|
||||
VADisplay dpy2,
|
||||
VASurfaceID srf2);
|
||||
|
||||
inline int getBackendType() { return m_type; }
|
||||
VADisplay GetVADisplay() { return m_va_dpy; }
|
||||
const MfxLoader::VA_Proxy m_libva;
|
||||
|
||||
protected:
|
||||
CLibVA(int type)
|
||||
: m_type(type)
|
||||
, m_va_dpy(NULL)
|
||||
{}
|
||||
int m_type;
|
||||
VADisplay m_va_dpy;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(CLibVA);
|
||||
};
|
||||
|
||||
CLibVA* CreateLibVA(const std::string& devicePath = "", int type = MFX_LIBVA_DRM);
|
||||
|
||||
VAStatus AcquireVASurface(void** ctx, VADisplay dpy1, VASurfaceID srf1, VADisplay dpy2, VASurfaceID* srf2);
|
||||
void ReleaseVASurface(void* actx, VADisplay dpy1, VASurfaceID srf1, VADisplay dpy2, VASurfaceID srf2);
|
||||
|
||||
mfxStatus va_to_mfx_status(VAStatus va_res);
|
||||
|
||||
#endif // #ifdef LIBVA_SUPPORT
|
||||
|
||||
#endif // #ifndef __VAAPI_UTILS_H__
|
||||
43
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils_android.h
vendored
Normal file
43
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils_android.h
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __VAAPI_UTILS_ANDROID_H__
|
||||
#define __VAAPI_UTILS_ANDROID_H__
|
||||
|
||||
#if defined(LIBVA_ANDROID_SUPPORT)
|
||||
|
||||
#include <va/va_android.h>
|
||||
#include "vaapi_utils.h"
|
||||
|
||||
class AndroidLibVA : public CLibVA
|
||||
{
|
||||
public:
|
||||
AndroidLibVA(void);
|
||||
virtual ~AndroidLibVA(void);
|
||||
|
||||
protected:
|
||||
void *m_display;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(AndroidLibVA);
|
||||
};
|
||||
|
||||
#endif // #if defined(LIBVA_ANDROID_SUPPORT)
|
||||
|
||||
#endif // #ifndef __VAAPI_UTILS_ANDROID_H__
|
||||
94
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils_drm.h
vendored
Normal file
94
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils_drm.h
vendored
Normal file
@@ -0,0 +1,94 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __VAAPI_UTILS_DRM_H__
|
||||
#define __VAAPI_UTILS_DRM_H__
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
|
||||
#include <va/va_drm.h>
|
||||
#include <va/va_drmcommon.h>
|
||||
#include "vaapi_utils.h"
|
||||
#include "vaapi_allocator.h"
|
||||
|
||||
class drmRenderer;
|
||||
|
||||
class DRMLibVA : public CLibVA
|
||||
{
|
||||
public:
|
||||
DRMLibVA(const std::string& devicePath = "", int type = MFX_LIBVA_DRM);
|
||||
virtual ~DRMLibVA(void);
|
||||
|
||||
inline int getFD() { return m_fd; }
|
||||
|
||||
protected:
|
||||
int m_fd;
|
||||
MfxLoader::VA_DRMProxy m_vadrmlib;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(DRMLibVA);
|
||||
};
|
||||
|
||||
class drmRenderer : public vaapiAllocatorParams::Exporter
|
||||
{
|
||||
public:
|
||||
drmRenderer(int fd, mfxI32 monitorType);
|
||||
virtual ~drmRenderer();
|
||||
|
||||
virtual mfxStatus render(mfxFrameSurface1 * pSurface);
|
||||
|
||||
// vaapiAllocatorParams::Exporter methods
|
||||
virtual void* acquire(mfxMemId mid);
|
||||
virtual void release(mfxMemId mid, void * mem);
|
||||
|
||||
static uint32_t getConnectorType(mfxI32 monitor_type);
|
||||
static const msdk_char* getConnectorName(uint32_t connector_type);
|
||||
|
||||
private:
|
||||
bool getConnector(drmModeRes *resource, uint32_t connector_type);
|
||||
bool setupConnection(drmModeRes *resource, drmModeConnector* connector);
|
||||
bool getPlane();
|
||||
|
||||
bool setMaster();
|
||||
void dropMaster();
|
||||
bool restore();
|
||||
|
||||
const MfxLoader::DRM_Proxy m_drmlib;
|
||||
const MfxLoader::DrmIntel_Proxy m_drmintellib;
|
||||
|
||||
int m_fd;
|
||||
uint32_t m_connector_type;
|
||||
uint32_t m_connectorID;
|
||||
uint32_t m_encoderID;
|
||||
uint32_t m_crtcID;
|
||||
uint32_t m_crtcIndex;
|
||||
uint32_t m_planeID;
|
||||
drmModeModeInfo m_mode;
|
||||
drmModeCrtcPtr m_crtc;
|
||||
drm_intel_bufmgr* m_bufmgr;
|
||||
bool m_overlay_wrn;
|
||||
mfxFrameSurface1 * m_pCurrentRenderTargetSurface;
|
||||
|
||||
private:
|
||||
DISALLOW_COPY_AND_ASSIGN(drmRenderer);
|
||||
};
|
||||
|
||||
#endif // #if defined(LIBVA_DRM_SUPPORT)
|
||||
|
||||
#endif // #ifndef __VAAPI_UTILS_DRM_H__
|
||||
70
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils_x11.h
vendored
Normal file
70
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vaapi_utils_x11.h
vendored
Normal file
@@ -0,0 +1,70 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __VAAPI_UTILS_X11_H__
|
||||
#define __VAAPI_UTILS_X11_H__
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
#include <va/va_x11.h>
|
||||
#include "vaapi_utils.h"
|
||||
|
||||
class X11LibVA : public CLibVA
|
||||
{
|
||||
public:
|
||||
X11LibVA(void);
|
||||
virtual ~X11LibVA(void);
|
||||
|
||||
void *GetXDisplay(void) { return m_display;}
|
||||
|
||||
|
||||
MfxLoader::XLib_Proxy & GetX11() { return m_x11lib; }
|
||||
MfxLoader::VA_X11Proxy & GetVAX11() { return m_vax11lib; }
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
MfxLoader::Xcb_Proxy & GetXcbX11() { return m_xcblib; }
|
||||
MfxLoader::X11_Xcb_Proxy & GetX11XcbX11() { return m_x11xcblib; }
|
||||
MfxLoader::XCB_Dri3_Proxy & GetXCBDri3X11() { return m_xcbdri3lib; }
|
||||
MfxLoader::Xcbpresent_Proxy & GetXcbpresentX11() { return m_xcbpresentlib; }
|
||||
MfxLoader::DrmIntel_Proxy & GetDrmIntelX11() { return m_drmintellib; }
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
|
||||
protected:
|
||||
Display* m_display;
|
||||
VAConfigID m_configID;
|
||||
VAContextID m_contextID;
|
||||
MfxLoader::XLib_Proxy m_x11lib;
|
||||
MfxLoader::VA_X11Proxy m_vax11lib;
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
MfxLoader::VA_DRMProxy m_vadrmlib;
|
||||
MfxLoader::Xcb_Proxy m_xcblib;
|
||||
MfxLoader::X11_Xcb_Proxy m_x11xcblib;
|
||||
MfxLoader::XCB_Dri3_Proxy m_xcbdri3lib;
|
||||
MfxLoader::Xcbpresent_Proxy m_xcbpresentlib;
|
||||
MfxLoader::DrmIntel_Proxy m_drmintellib;
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
|
||||
private:
|
||||
void Close();
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(X11LibVA);
|
||||
};
|
||||
|
||||
#endif // #if defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
#endif // #ifndef __VAAPI_UTILS_X11_H__
|
||||
45
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/version.h
vendored
Normal file
45
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/version.h
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sample_defs.h"
|
||||
|
||||
#ifndef MSDK_MAJOR
|
||||
#define MSDK_MAJOR 8
|
||||
#endif
|
||||
|
||||
#ifndef MSDK_MINOR
|
||||
#define MSDK_MINOR 4
|
||||
#endif
|
||||
|
||||
#ifndef MSDK_RELEASE
|
||||
#define MSDK_TARGETAPIMINOR 27
|
||||
#endif
|
||||
|
||||
#ifndef MSDK_BUILD
|
||||
#define MSDK_BUILD 0
|
||||
#endif
|
||||
|
||||
static msdk_string GetMSDKSampleVersion()
|
||||
{
|
||||
msdk_stringstream ss;
|
||||
ss << MSDK_MAJOR << "." << MSDK_MINOR << "." << MSDK_TARGETAPIMINOR << "." << MSDK_BUILD;
|
||||
return ss.str();
|
||||
}
|
||||
37
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/atomic_defs.h
vendored
Normal file
37
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/atomic_defs.h
vendored
Normal file
@@ -0,0 +1,37 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __ATOMIC_DEFS_H__
|
||||
#define __ATOMIC_DEFS_H__
|
||||
|
||||
#include "mfxdefs.h"
|
||||
|
||||
/* Thread-safe 16-bit variable incrementing */
|
||||
mfxU16 msdk_atomic_inc16(volatile mfxU16 *pVariable);
|
||||
|
||||
/* Thread-safe 16-bit variable decrementing */
|
||||
mfxU16 msdk_atomic_dec16(volatile mfxU16 *pVariable);
|
||||
|
||||
/* Thread-safe 32-bit variable incrementing */
|
||||
mfxU32 msdk_atomic_inc32(volatile mfxU32 *pVariable);
|
||||
|
||||
/* Thread-safe 32-bit variable decrementing */
|
||||
mfxU32 msdk_atomic_dec32(volatile mfxU32 *pVariable);
|
||||
|
||||
#endif // #ifndef __ATOMIC_DEFS_H__
|
||||
40
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/file_defs.h
vendored
Normal file
40
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/file_defs.h
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __FILE_DEFS_H__
|
||||
#define __FILE_DEFS_H__
|
||||
|
||||
#include "mfxdefs.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#define MSDK_FOPEN(file, name, mode) _tfopen_s(&file, name, mode)
|
||||
|
||||
#define msdk_fgets _fgetts
|
||||
#else // #if defined(_WIN32) || defined(_WIN64)
|
||||
#include <unistd.h>
|
||||
|
||||
#define MSDK_FOPEN(file, name, mode) !(file = fopen(name, mode))
|
||||
|
||||
#define msdk_fgets fgets
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#endif // #ifndef __FILE_DEFS_H__
|
||||
34
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/so_defs.h
vendored
Normal file
34
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/so_defs.h
vendored
Normal file
@@ -0,0 +1,34 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __SO_DEFS_H__
|
||||
#define __SO_DEFS_H__
|
||||
|
||||
#include "mfxdefs.h"
|
||||
#include "strings_defs.h"
|
||||
|
||||
/* Declare shared object handle */
|
||||
typedef void * msdk_so_handle;
|
||||
typedef void (*msdk_func_pointer)(void);
|
||||
|
||||
msdk_so_handle msdk_so_load(const msdk_char *file_name);
|
||||
msdk_func_pointer msdk_so_get_addr(msdk_so_handle handle, const char *func_name);
|
||||
void msdk_so_free(msdk_so_handle handle);
|
||||
|
||||
#endif // #ifndef __SO_DEFS_H__
|
||||
117
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/strings_defs.h
vendored
Normal file
117
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/strings_defs.h
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __STRING_DEFS_H__
|
||||
#define __STRING_DEFS_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
#include <string>
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <tchar.h>
|
||||
|
||||
#define MSDK_STRING(x) _T(x)
|
||||
#define MSDK_CHAR(x) _T(x)
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef std::basic_string<TCHAR> msdk_tstring;
|
||||
#endif
|
||||
typedef TCHAR msdk_char;
|
||||
|
||||
#define msdk_printf _tprintf
|
||||
#define msdk_fprintf _ftprintf
|
||||
#define msdk_sprintf _stprintf_s // to be removed
|
||||
#define msdk_vprintf _vtprintf
|
||||
#define msdk_strlen _tcslen
|
||||
#define msdk_strcmp _tcscmp
|
||||
#define msdk_stricmp _tcsicmp
|
||||
#define msdk_strncmp _tcsnicmp
|
||||
#define msdk_strstr _tcsstr
|
||||
#define msdk_atoi _ttoi
|
||||
#define msdk_strtol _tcstol
|
||||
#define msdk_strtod _tcstod
|
||||
#define msdk_strchr _tcschr
|
||||
#define msdk_strnlen(str,lenmax) strnlen_s(str,lenmax)
|
||||
#define msdk_sscanf _stscanf_s
|
||||
#define msdk_itoa_decimal(value, str) _itot_s(value,str,10)
|
||||
|
||||
// msdk_strcopy is intended to be used with 2 parmeters, i.e. msdk_strcopy(dst, src)
|
||||
// for _tcscpy_s that's possible if DST is declared as: TCHAR DST[n];
|
||||
#define msdk_strcopy _tcscpy_s
|
||||
#define msdk_strncopy_s _tcsncpy_s
|
||||
|
||||
#define MSDK_MEMCPY_BITSTREAM(bitstream, offset, src, count) memcpy_s((bitstream).Data + (offset), (bitstream).MaxLength - (offset), (src), (count))
|
||||
|
||||
#define MSDK_MEMCPY_BUF(bufptr, offset, maxsize, src, count) memcpy_s((bufptr)+ (offset), (maxsize) - (offset), (src), (count))
|
||||
|
||||
#define MSDK_MEMCPY_VAR(dstVarName, src, count) memcpy_s(&(dstVarName), sizeof(dstVarName), (src), (count))
|
||||
|
||||
#define MSDK_MEMCPY(dst, src, count) memcpy_s(dst, (count), (src), (count))
|
||||
|
||||
|
||||
|
||||
#else // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#define MSDK_STRING(x) x
|
||||
#define MSDK_CHAR(x) x
|
||||
|
||||
#ifdef __cplusplus
|
||||
typedef std::string msdk_tstring;
|
||||
#endif
|
||||
typedef char msdk_char;
|
||||
|
||||
#define msdk_printf printf
|
||||
#define msdk_sprintf sprintf
|
||||
#define msdk_vprintf vprintf
|
||||
#define msdk_fprintf fprintf
|
||||
#define msdk_strlen strlen
|
||||
#define msdk_strcmp strcmp
|
||||
#define msdk_stricmp strcasecmp
|
||||
#define msdk_strncmp strncmp
|
||||
#define msdk_strstr strstr
|
||||
#define msdk_atoi atoi
|
||||
#define msdk_atoll atoll
|
||||
#define msdk_strtol strtol
|
||||
#define msdk_strtod strtod
|
||||
#define msdk_itoa_decimal(value, str) \
|
||||
snprintf(str, sizeof(str)/sizeof(str[0])-1, "%d", value)
|
||||
#define msdk_strnlen(str,maxlen) strlen(str)
|
||||
#define msdk_sscanf sscanf
|
||||
|
||||
#define msdk_strcopy strcpy
|
||||
|
||||
#define msdk_strncopy_s(dst, num_dst, src, count) strncpy(dst, src, count)
|
||||
|
||||
#define MSDK_MEMCPY_BITSTREAM(bitstream, offset, src, count) memcpy((bitstream).Data + (offset), (src), (count))
|
||||
|
||||
#define MSDK_MEMCPY_BUF(bufptr, offset, maxsize, src, count) memcpy((bufptr)+ (offset), (src), (count))
|
||||
|
||||
#define MSDK_MEMCPY_VAR(dstVarName, src, count) memcpy(&(dstVarName), (src), (count))
|
||||
|
||||
#define MSDK_MEMCPY(dst, src, count) memcpy(dst, (src), (count))
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#endif //__STRING_DEFS_H__
|
||||
154
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/thread_defs.h
vendored
Normal file
154
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/thread_defs.h
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __THREAD_DEFS_H__
|
||||
#define __THREAD_DEFS_H__
|
||||
|
||||
#include "mfxdefs.h"
|
||||
#include "vm/strings_defs.h"
|
||||
|
||||
typedef unsigned int (MFX_STDCALL * msdk_thread_callback)(void*);
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
|
||||
struct msdkSemaphoreHandle
|
||||
{
|
||||
void* m_semaphore;
|
||||
};
|
||||
|
||||
struct msdkEventHandle
|
||||
{
|
||||
void* m_event;
|
||||
};
|
||||
|
||||
struct msdkThreadHandle
|
||||
{
|
||||
void* m_thread;
|
||||
};
|
||||
|
||||
#else // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <pthread.h>
|
||||
#include <errno.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/resource.h>
|
||||
|
||||
struct msdkSemaphoreHandle
|
||||
{
|
||||
msdkSemaphoreHandle(mfxU32 count):
|
||||
m_count(count)
|
||||
{}
|
||||
|
||||
mfxU32 m_count;
|
||||
pthread_cond_t m_semaphore;
|
||||
pthread_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
struct msdkEventHandle
|
||||
{
|
||||
msdkEventHandle(bool manual, bool state):
|
||||
m_manual(manual),
|
||||
m_state(state)
|
||||
{}
|
||||
|
||||
bool m_manual;
|
||||
bool m_state;
|
||||
pthread_cond_t m_event;
|
||||
pthread_mutex_t m_mutex;
|
||||
};
|
||||
|
||||
class MSDKEvent;
|
||||
|
||||
struct msdkThreadHandle
|
||||
{
|
||||
msdkThreadHandle(
|
||||
msdk_thread_callback func,
|
||||
void* arg):
|
||||
m_func(func),
|
||||
m_arg(arg),
|
||||
m_event(0),
|
||||
m_thread(0)
|
||||
{}
|
||||
|
||||
msdk_thread_callback m_func;
|
||||
void* m_arg;
|
||||
MSDKEvent* m_event;
|
||||
pthread_t m_thread;
|
||||
};
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
class MSDKSemaphore: public msdkSemaphoreHandle
|
||||
{
|
||||
public:
|
||||
MSDKSemaphore(mfxStatus &sts, mfxU32 count = 0);
|
||||
~MSDKSemaphore(void);
|
||||
|
||||
mfxStatus Post(void);
|
||||
mfxStatus Wait(void);
|
||||
|
||||
private:
|
||||
MSDKSemaphore(const MSDKSemaphore&);
|
||||
void operator=(const MSDKSemaphore&);
|
||||
};
|
||||
|
||||
class MSDKEvent: public msdkEventHandle
|
||||
{
|
||||
public:
|
||||
MSDKEvent(mfxStatus &sts, bool manual, bool state);
|
||||
~MSDKEvent(void);
|
||||
|
||||
mfxStatus Signal(void);
|
||||
mfxStatus Reset(void);
|
||||
mfxStatus Wait(void);
|
||||
mfxStatus TimedWait(mfxU32 msec);
|
||||
|
||||
private:
|
||||
MSDKEvent(const MSDKEvent&);
|
||||
void operator=(const MSDKEvent&);
|
||||
};
|
||||
|
||||
class MSDKThread: public msdkThreadHandle
|
||||
{
|
||||
public:
|
||||
MSDKThread(mfxStatus &sts, msdk_thread_callback func, void* arg);
|
||||
~MSDKThread(void);
|
||||
|
||||
mfxStatus Wait(void);
|
||||
mfxStatus TimedWait(mfxU32 msec);
|
||||
mfxStatus GetExitCode();
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
friend void* msdk_thread_start(void* arg);
|
||||
#endif
|
||||
|
||||
private:
|
||||
MSDKThread(const MSDKThread&);
|
||||
void operator=(const MSDKThread&);
|
||||
};
|
||||
|
||||
mfxU32 msdk_get_current_pid();
|
||||
mfxStatus msdk_setrlimit_vmem(mfxU64 size);
|
||||
mfxStatus msdk_thread_get_schedtype(const msdk_char*, mfxI32 &type);
|
||||
void msdk_thread_printf_scheduling_help();
|
||||
|
||||
#endif //__THREAD_DEFS_H__
|
||||
68
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/time_defs.h
vendored
Normal file
68
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vm/time_defs.h
vendored
Normal file
@@ -0,0 +1,68 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __TIME_DEFS_H__
|
||||
#define __TIME_DEFS_H__
|
||||
|
||||
#include "mfxdefs.h"
|
||||
#include "mfx_itt_trace.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#define MSDK_SLEEP(msec) Sleep(msec)
|
||||
|
||||
#define MSDK_USLEEP(usec) \
|
||||
{ \
|
||||
LARGE_INTEGER due; \
|
||||
due.QuadPart = -(10*(int)usec); \
|
||||
HANDLE t = CreateWaitableTimer(NULL, TRUE, NULL); \
|
||||
SetWaitableTimer(t, &due, 0, NULL, NULL, 0); \
|
||||
WaitForSingleObject(t, INFINITE); \
|
||||
CloseHandle(t); \
|
||||
}
|
||||
|
||||
#else // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <unistd.h>
|
||||
|
||||
#define MSDK_SLEEP(msec) \
|
||||
do { \
|
||||
MFX_ITT_TASK("MSDK_SLEEP"); \
|
||||
usleep(1000*msec); \
|
||||
} while(0)
|
||||
|
||||
#define MSDK_USLEEP(usec) \
|
||||
do { \
|
||||
MFX_ITT_TASK("MSDK_USLEEP"); \
|
||||
usleep(usec); \
|
||||
} while(0)
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#define MSDK_GET_TIME(T,S,F) ((mfxF64)((T)-(S))/(mfxF64)(F))
|
||||
|
||||
typedef mfxI64 msdk_tick;
|
||||
|
||||
msdk_tick msdk_time_get_tick(void);
|
||||
msdk_tick msdk_time_get_frequency(void);
|
||||
mfxU64 rdtsc(void);
|
||||
|
||||
#endif // #ifndef __TIME_DEFS_H__
|
||||
59
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vpp_ex.h
vendored
Normal file
59
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/include/vpp_ex.h
vendored
Normal file
@@ -0,0 +1,59 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifndef __VPP_EX_H__
|
||||
#define __VPP_EX_H__
|
||||
|
||||
#include "sample_utils.h"
|
||||
#include "mfxvideo++.h"
|
||||
#include <vector>
|
||||
|
||||
/* #define USE_VPP_EX */
|
||||
|
||||
class MFXVideoVPPEx : public MFXVideoVPP
|
||||
{
|
||||
|
||||
public:
|
||||
MFXVideoVPPEx(mfxSession session);
|
||||
|
||||
#if defined USE_VPP_EX
|
||||
|
||||
mfxStatus QueryIOSurf(mfxVideoParam *par, mfxFrameAllocRequest request[2]);
|
||||
mfxStatus Query(mfxVideoParam *in, mfxVideoParam *out);
|
||||
mfxStatus Init(mfxVideoParam *par);
|
||||
mfxStatus RunFrameVPPAsync(mfxFrameSurface1 *in, mfxFrameSurface1 *out, mfxExtVppAuxData *aux, mfxSyncPoint *syncp);
|
||||
mfxStatus GetVideoParam(mfxVideoParam *par);
|
||||
mfxStatus Close(void);
|
||||
|
||||
protected:
|
||||
|
||||
std::vector<mfxFrameSurface1*> m_LockedSurfacesList;
|
||||
mfxVideoParam m_VideoParams;
|
||||
|
||||
mfxU64 m_nCurrentPTS;
|
||||
|
||||
mfxU64 m_nIncreaseTime;
|
||||
mfxU64 m_nArraySize;
|
||||
mfxU64 m_nInputTimeStamp;
|
||||
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif //__VPP_EX_H__
|
||||
2098
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/avc_bitstream.cpp
vendored
Normal file
2098
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/avc_bitstream.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
533
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/avc_nal_spl.cpp
vendored
Normal file
533
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/avc_nal_spl.cpp
vendored
Normal file
@@ -0,0 +1,533 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "sample_defs.h"
|
||||
#include "avc_structures.h"
|
||||
#include "avc_nal_spl.h"
|
||||
|
||||
namespace ProtectedLibrary
|
||||
{
|
||||
|
||||
static const mfxU32 MFX_TIME_STAMP_FREQUENCY = 90000; // will go to mfxdefs.h
|
||||
static const mfxU64 MFX_TIME_STAMP_INVALID = (mfxU64)-1; // will go to mfxdefs.h
|
||||
|
||||
inline
|
||||
mfxF64 GetUmcTimeStamp(mfxU64 ts)
|
||||
{
|
||||
return ts == MFX_TIME_STAMP_INVALID ? -1.0 : ts / (mfxF64)MFX_TIME_STAMP_FREQUENCY;
|
||||
}
|
||||
|
||||
inline
|
||||
mfxU64 GetMfxTimeStamp(mfxF64 ts)
|
||||
{
|
||||
return ts < 0.0 ? MFX_TIME_STAMP_INVALID : (mfxU64)(ts * MFX_TIME_STAMP_FREQUENCY + .5);
|
||||
}
|
||||
|
||||
enum
|
||||
{
|
||||
AVC_NAL_UNITTYPE_BITS_MASK = 0x1f
|
||||
};
|
||||
|
||||
|
||||
inline bool IsHeaderCode(mfxI32 iCode)
|
||||
{
|
||||
return (NAL_UT_SPS == (iCode & AVC_NAL_UNITTYPE_BITS_MASK)) ||
|
||||
(NAL_UT_SPS_EX == (iCode & AVC_NAL_UNITTYPE_BITS_MASK)) ||
|
||||
(NAL_UT_PPS == (iCode & AVC_NAL_UNITTYPE_BITS_MASK));
|
||||
}
|
||||
|
||||
inline bool IsVLCCode(mfxI32 iCode)
|
||||
{
|
||||
return ((NAL_UT_SLICE <= (iCode & AVC_NAL_UNITTYPE_BITS_MASK)) &&
|
||||
(NAL_UT_IDR_SLICE >= (iCode & AVC_NAL_UNITTYPE_BITS_MASK))) ||
|
||||
(NAL_UT_AUXILIARY == (iCode & AVC_NAL_UNITTYPE_BITS_MASK));
|
||||
}
|
||||
|
||||
static mfxI32 FindStartCode(mfxU8 * (&pb), mfxU32 &nSize)
|
||||
{
|
||||
// there is no data
|
||||
if (nSize < 4)
|
||||
return 0;
|
||||
|
||||
// find start code
|
||||
while ((4 <= nSize) && ((0 != pb[0]) ||
|
||||
(0 != pb[1]) ||
|
||||
(1 != pb[2])))
|
||||
{
|
||||
pb += 1;
|
||||
nSize -= 1;
|
||||
}
|
||||
|
||||
if (4 <= nSize)
|
||||
return ((pb[0] << 24) | (pb[1] << 16) | (pb[2] << 8) | (pb[3]));
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
mfxStatus MoveBitstream(mfxBitstream * source, mfxI32 moveSize)
|
||||
{
|
||||
if (!source)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
if (moveSize < 0 && (mfxI32)source->DataOffset + moveSize < 0)
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
if (moveSize > 0 && source->DataLength < (mfxU32)moveSize)
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
source->DataOffset += moveSize;
|
||||
source->DataLength -= moveSize;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
StartCodeIterator::StartCodeIterator()
|
||||
: m_code(0)
|
||||
, m_pts(MFX_TIME_STAMP_INVALID)
|
||||
, m_pSource(0)
|
||||
, m_nSourceSize(0)
|
||||
, m_pSourceBase(0)
|
||||
, m_nSourceBaseSize(0)
|
||||
, m_suggestedSize(10 * 1024)
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void StartCodeIterator::Reset()
|
||||
{
|
||||
m_code = 0;
|
||||
m_pts = MFX_TIME_STAMP_INVALID;
|
||||
m_prev.clear();
|
||||
}
|
||||
|
||||
mfxI32 StartCodeIterator::Init(mfxBitstream * source)
|
||||
{
|
||||
Reset();
|
||||
|
||||
m_pSourceBase = m_pSource = source->Data + source->DataOffset;
|
||||
m_nSourceBaseSize = m_nSourceSize = source->DataLength;
|
||||
|
||||
mfxI32 iCode = ProtectedLibrary::FindStartCode(m_pSource, m_nSourceSize);
|
||||
return iCode;
|
||||
}
|
||||
|
||||
void StartCodeIterator::SetSuggestedSize(mfxU32 size)
|
||||
{
|
||||
if (size > m_suggestedSize)
|
||||
m_suggestedSize = size;
|
||||
}
|
||||
|
||||
mfxI32 StartCodeIterator::CheckNalUnitType(mfxBitstream * source)
|
||||
{
|
||||
if (!source)
|
||||
return 0;
|
||||
|
||||
if (!m_code)
|
||||
m_prev.clear();
|
||||
|
||||
mfxU8 * src = source->Data + source->DataOffset;
|
||||
mfxU32 size = source->DataLength;
|
||||
|
||||
mfxI32 startCodeSize;
|
||||
mfxI32 iCodeNext = FindStartCode(src, size, startCodeSize);
|
||||
return iCodeNext;
|
||||
}
|
||||
|
||||
mfxI32 StartCodeIterator::GetNALUnit(mfxBitstream * src, mfxBitstream * dst)
|
||||
{
|
||||
if (!src)
|
||||
return EndOfStream(dst);
|
||||
|
||||
if (!m_code)
|
||||
m_prev.clear();
|
||||
|
||||
mfxU8 * source = src->Data + src->DataOffset;
|
||||
mfxU32 size = src->DataLength;
|
||||
|
||||
if (!size)
|
||||
return 0;
|
||||
|
||||
mfxI32 startCodeSize;
|
||||
|
||||
mfxI32 iCodeNext = FindStartCode(source, size, startCodeSize);
|
||||
|
||||
if (m_prev.size())
|
||||
{
|
||||
if (!iCodeNext)
|
||||
{
|
||||
size_t sz = source - (src->Data + src->DataOffset);
|
||||
if (m_prev.size() + sz > m_suggestedSize)
|
||||
{
|
||||
m_prev.clear();
|
||||
sz = std::min<size_t>(sz, m_suggestedSize);
|
||||
}
|
||||
|
||||
m_prev.insert(m_prev.end(), src->Data + src->DataOffset, src->Data + src->DataOffset + sz);
|
||||
MoveBitstream(src, (mfxI32)sz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
source -= startCodeSize;
|
||||
m_prev.insert(m_prev.end(), src->Data + src->DataOffset, source);
|
||||
MoveBitstream(src, (mfxI32)(source - (src->Data + src->DataOffset)));
|
||||
|
||||
dst->Data = &(m_prev[0]);
|
||||
dst->DataLength = (mfxU32)m_prev.size();
|
||||
dst->DataOffset = 0;
|
||||
dst->TimeStamp = m_pts;
|
||||
mfxI32 code = m_code;
|
||||
m_code = 0;
|
||||
m_pts = MFX_TIME_STAMP_INVALID;
|
||||
return code;
|
||||
}
|
||||
|
||||
if (!iCodeNext)
|
||||
{
|
||||
MoveBitstream(src, (mfxI32)(source - (src->Data + src->DataOffset)));
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_pts = src->TimeStamp;
|
||||
m_code = iCodeNext;
|
||||
|
||||
// move before start code
|
||||
MoveBitstream(src, (mfxI32)(source - (src->Data + src->DataOffset) - startCodeSize));
|
||||
|
||||
mfxI32 startCodeSize1;
|
||||
iCodeNext = FindStartCode(source, size, startCodeSize1);
|
||||
|
||||
MoveBitstream(src, startCodeSize);
|
||||
|
||||
if (!iCodeNext && (src->DataFlag & MFX_BITSTREAM_COMPLETE_FRAME))
|
||||
{
|
||||
iCodeNext = 1;
|
||||
startCodeSize1 = 0;
|
||||
}
|
||||
|
||||
if (!iCodeNext)
|
||||
{
|
||||
if (m_prev.size()) // assertion: it should be
|
||||
return 0;
|
||||
|
||||
size_t sz = source - (src->Data + src->DataOffset);
|
||||
if (sz > m_suggestedSize)
|
||||
{
|
||||
sz = m_suggestedSize;
|
||||
}
|
||||
|
||||
m_prev.insert(m_prev.end(), src->Data + src->DataOffset, src->Data + src->DataOffset + sz);
|
||||
MoveBitstream(src, (mfxI32)sz);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// fill
|
||||
size_t nal_size = source - (src->Data + src->DataOffset) - startCodeSize1;
|
||||
|
||||
dst->Data = src->Data + src->DataOffset;
|
||||
dst->DataLength = (mfxU32)nal_size;
|
||||
dst->DataOffset = 0;
|
||||
dst->TimeStamp = m_pts;
|
||||
|
||||
MoveBitstream(src, (mfxI32)nal_size);
|
||||
|
||||
mfxI32 code = m_code;
|
||||
m_code = 0;
|
||||
|
||||
m_pts = MFX_TIME_STAMP_INVALID;
|
||||
return code;
|
||||
}
|
||||
|
||||
mfxI32 StartCodeIterator::EndOfStream(mfxBitstream * dst)
|
||||
{
|
||||
if (!m_code)
|
||||
{
|
||||
m_prev.clear();
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (m_prev.size())
|
||||
{
|
||||
dst->Data = &(m_prev[0]);
|
||||
dst->DataLength = (mfxU32)m_prev.size();
|
||||
dst->DataOffset = 0;
|
||||
dst->TimeStamp = m_pts;
|
||||
mfxI32 code = m_code;
|
||||
m_code = 0;
|
||||
m_pts = MFX_TIME_STAMP_INVALID;
|
||||
return code;
|
||||
}
|
||||
|
||||
m_code = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
mfxI32 StartCodeIterator::FindStartCode(mfxU8 * (&pb), mfxU32 & size, mfxI32 & startCodeSize)
|
||||
{
|
||||
mfxU32 zeroCount = 0;
|
||||
|
||||
for (mfxU32 i = 0 ; i < (mfxU32)size; i++, pb++)
|
||||
{
|
||||
switch(pb[0])
|
||||
{
|
||||
case 0x00:
|
||||
zeroCount++;
|
||||
break;
|
||||
case 0x01:
|
||||
if (zeroCount >= 2)
|
||||
{
|
||||
startCodeSize = std::min(zeroCount + 1, 4u);
|
||||
size -= i + 1;
|
||||
pb++; // remove 0x01 symbol
|
||||
zeroCount = 0;
|
||||
if (size >= 1)
|
||||
{
|
||||
return pb[0] & AVC_NAL_UNITTYPE_BITS_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
pb -= startCodeSize;
|
||||
size += startCodeSize;
|
||||
startCodeSize = 0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
zeroCount = 0;
|
||||
break;
|
||||
default:
|
||||
zeroCount = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
zeroCount = std::min(zeroCount, 3u);
|
||||
pb -= zeroCount;
|
||||
size += zeroCount;
|
||||
zeroCount = 0;
|
||||
startCodeSize = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
void BytesSwapper::SwapMemory(mfxU8 *pDestination, mfxU32 &nDstSize, mfxU8 *pSource, mfxU32 nSrcSize)
|
||||
{
|
||||
SwapMemoryAndRemovePreventingBytes(pDestination, nDstSize, pSource, nSrcSize);
|
||||
}
|
||||
|
||||
NALUnitSplitter::NALUnitSplitter()
|
||||
{
|
||||
memset(&m_bitstream, 0, sizeof(m_bitstream));
|
||||
}
|
||||
|
||||
NALUnitSplitter::~NALUnitSplitter()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
void NALUnitSplitter::Init()
|
||||
{
|
||||
Release();
|
||||
}
|
||||
|
||||
void NALUnitSplitter::Reset()
|
||||
{
|
||||
m_pStartCodeIter.Reset();
|
||||
}
|
||||
|
||||
void NALUnitSplitter::Release()
|
||||
{
|
||||
}
|
||||
|
||||
mfxI32 NALUnitSplitter::CheckNalUnitType(mfxBitstream * source)
|
||||
{
|
||||
return m_pStartCodeIter.CheckNalUnitType(source);
|
||||
}
|
||||
|
||||
mfxI32 NALUnitSplitter::GetNalUnits(mfxBitstream * source, mfxBitstream * &destination)
|
||||
{
|
||||
mfxI32 iCode = m_pStartCodeIter.GetNALUnit(source, &m_bitstream);
|
||||
|
||||
if (iCode == 0)
|
||||
{
|
||||
destination = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
destination = &m_bitstream;
|
||||
return iCode;
|
||||
}
|
||||
|
||||
/* temporal class definition */
|
||||
class H264DwordPointer_
|
||||
{
|
||||
public:
|
||||
// Default constructor
|
||||
H264DwordPointer_(void)
|
||||
{
|
||||
m_pDest = NULL;
|
||||
m_nByteNum = 0;
|
||||
m_iCur = 0;
|
||||
}
|
||||
|
||||
H264DwordPointer_ operator = (void *pDest)
|
||||
{
|
||||
m_pDest = (mfxU32 *) pDest;
|
||||
m_nByteNum = 0;
|
||||
m_iCur = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
// Increment operator
|
||||
H264DwordPointer_ &operator ++ (void)
|
||||
{
|
||||
if (4 == ++m_nByteNum)
|
||||
{
|
||||
*m_pDest = m_iCur;
|
||||
m_pDest += 1;
|
||||
m_nByteNum = 0;
|
||||
m_iCur = 0;
|
||||
}
|
||||
else
|
||||
m_iCur <<= 8;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
mfxU8 operator = (mfxU8 nByte)
|
||||
{
|
||||
m_iCur = (m_iCur & ~0x0ff) | ((mfxU32) nByte);
|
||||
|
||||
return nByte;
|
||||
}
|
||||
|
||||
protected:
|
||||
mfxU32 *m_pDest; // pointer to destination buffer
|
||||
mfxU32 m_nByteNum; // number of current byte in dword
|
||||
mfxU32 m_iCur; // current dword
|
||||
};
|
||||
|
||||
class H264SourcePointer_
|
||||
{
|
||||
public:
|
||||
// Default constructor
|
||||
H264SourcePointer_(void)
|
||||
{
|
||||
m_pSource = NULL;
|
||||
m_nRemovedBytes=0;
|
||||
m_nZeros=0;
|
||||
}
|
||||
|
||||
H264SourcePointer_ &operator = (mfxU8 *pSource)
|
||||
{
|
||||
m_pSource = (mfxU8 *) pSource;
|
||||
|
||||
m_nZeros = 0;
|
||||
m_nRemovedBytes = 0;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
H264SourcePointer_ &operator ++ (void)
|
||||
{
|
||||
mfxU8 bCurByte = m_pSource[0];
|
||||
|
||||
if (0 == bCurByte)
|
||||
m_nZeros += 1;
|
||||
else
|
||||
{
|
||||
if ((3 == bCurByte) && (2 <= m_nZeros))
|
||||
m_nRemovedBytes += 1;
|
||||
m_nZeros = 0;
|
||||
}
|
||||
|
||||
m_pSource += 1;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool IsPrevent(void)
|
||||
{
|
||||
if ((3 == m_pSource[0]) && (2 <= m_nZeros))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
operator mfxU8 (void)
|
||||
{
|
||||
return m_pSource[0];
|
||||
}
|
||||
|
||||
mfxU32 GetRemovedBytes(void)
|
||||
{
|
||||
return m_nRemovedBytes;
|
||||
}
|
||||
|
||||
protected:
|
||||
mfxU8 *m_pSource; // pointer to destination buffer
|
||||
mfxU32 m_nZeros; // number of preceding zeros
|
||||
mfxU32 m_nRemovedBytes; // number of removed bytes
|
||||
};
|
||||
|
||||
void SwapMemoryAndRemovePreventingBytes(mfxU8 *pDestination, mfxU32 &nDstSize, mfxU8 *pSource, mfxU32 nSrcSize)
|
||||
{
|
||||
H264DwordPointer_ pDst;
|
||||
H264SourcePointer_ pSrc;
|
||||
size_t i;
|
||||
|
||||
// DwordPointer object is swapping written bytes
|
||||
// H264SourcePointer_ removes preventing start-code bytes
|
||||
|
||||
// reset pointer(s)
|
||||
pSrc = pSource;
|
||||
pDst = pDestination;
|
||||
|
||||
// first two bytes
|
||||
i = 0;
|
||||
while (i < std::min(2u, nSrcSize))
|
||||
{
|
||||
pDst = (mfxU8) pSrc;
|
||||
++pDst;
|
||||
++pSrc;
|
||||
++i;
|
||||
}
|
||||
|
||||
// do swapping
|
||||
while (i < (mfxU32) nSrcSize)
|
||||
{
|
||||
if (false == pSrc.IsPrevent())
|
||||
{
|
||||
pDst = (mfxU8) pSrc;
|
||||
++pDst;
|
||||
}
|
||||
++pSrc;
|
||||
++i;
|
||||
}
|
||||
|
||||
// write padding bytes
|
||||
nDstSize = nSrcSize - pSrc.GetRemovedBytes();
|
||||
while (nDstSize & 3)
|
||||
{
|
||||
pDst = (mfxU8) (0);
|
||||
++nDstSize;
|
||||
++pDst;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ProtectedLibrary
|
||||
815
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/avc_spl.cpp
vendored
Normal file
815
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/avc_spl.cpp
vendored
Normal file
@@ -0,0 +1,815 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
|
||||
#include <exception>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "avc_spl.h"
|
||||
#include "sample_defs.h"
|
||||
|
||||
namespace ProtectedLibrary
|
||||
{
|
||||
|
||||
AVCFrameInfo::AVCFrameInfo()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void AVCFrameInfo::Reset()
|
||||
{
|
||||
m_slice = 0;
|
||||
m_index = 0;
|
||||
}
|
||||
|
||||
AVC_Spl::AVC_Spl()
|
||||
: m_WaitForIDR(true)
|
||||
, m_currentInfo(0)
|
||||
, m_pLastSlice(0)
|
||||
, m_lastNalUnit(0)
|
||||
{
|
||||
Init();
|
||||
}
|
||||
|
||||
AVC_Spl::~AVC_Spl()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::Init()
|
||||
{
|
||||
Close();
|
||||
|
||||
m_pNALSplitter.reset(new NALUnitSplitter());
|
||||
m_pNALSplitter->Init();
|
||||
|
||||
m_WaitForIDR = true;
|
||||
|
||||
m_AUInfo.reset(new AVCFrameInfo());
|
||||
|
||||
m_currentFrame.resize(BUFFER_SIZE);
|
||||
|
||||
m_pLastSlice = 0;
|
||||
m_lastNalUnit = 0;
|
||||
m_currentInfo = 0;
|
||||
|
||||
m_slices.resize(128);
|
||||
memset(&m_frame, 0, sizeof(m_frame));
|
||||
m_frame.Data = &m_currentFrame[0];
|
||||
m_frame.Slice = &m_slices[0];
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void AVC_Spl::Close()
|
||||
{
|
||||
m_pLastSlice = 0;
|
||||
m_lastNalUnit = 0;
|
||||
m_currentInfo = 0;
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::Reset()
|
||||
{
|
||||
m_pNALSplitter->Reset();
|
||||
m_WaitForIDR = true;
|
||||
m_lastNalUnit = 0;
|
||||
m_pLastSlice = 0;
|
||||
m_currentInfo = 0;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxU8 * AVC_Spl::GetMemoryForSwapping(mfxU32 size)
|
||||
{
|
||||
if (m_swappingMemory.size() <= size + 8)
|
||||
m_swappingMemory.resize(size + 8);
|
||||
|
||||
return &(m_swappingMemory[0]);
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::DecodeHeader(mfxBitstream * nalUnit)
|
||||
{
|
||||
mfxStatus umcRes = MFX_ERR_NONE;
|
||||
|
||||
AVCHeadersBitstream bitStream;
|
||||
|
||||
try
|
||||
{
|
||||
mfxU32 swappingSize = nalUnit->DataLength;
|
||||
mfxU8 * swappingMemory = GetMemoryForSwapping(swappingSize);
|
||||
|
||||
BytesSwapper::SwapMemory(swappingMemory, swappingSize, nalUnit->Data + nalUnit->DataOffset, nalUnit->DataLength);
|
||||
|
||||
bitStream.Reset(swappingMemory, swappingSize);
|
||||
|
||||
NAL_Unit_Type uNALUnitType;
|
||||
mfxU8 uNALStorageIDC;
|
||||
|
||||
bitStream.GetNALUnitType(uNALUnitType, uNALStorageIDC);
|
||||
|
||||
switch(uNALUnitType)
|
||||
{
|
||||
// sequence parameter set
|
||||
case NAL_UT_SPS:
|
||||
{
|
||||
AVCSeqParamSet sps;
|
||||
umcRes = bitStream.GetSequenceParamSet(&sps);
|
||||
if (umcRes == MFX_ERR_NONE)
|
||||
{
|
||||
m_headers.m_SeqParams.GetHeader(sps.seq_parameter_set_id);
|
||||
m_headers.m_SeqParams.AddHeader(&sps);
|
||||
|
||||
// Validate the incoming bitstream's image dimensions.
|
||||
m_headers.m_SeqParams.GetHeader(sps.seq_parameter_set_id);
|
||||
|
||||
m_pNALSplitter->SetSuggestedSize(CalculateSuggestedSize(&sps));
|
||||
|
||||
if (umcRes != MFX_ERR_NONE)
|
||||
return umcRes;
|
||||
}
|
||||
else
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
break;
|
||||
|
||||
case NAL_UT_SPS_EX:
|
||||
{
|
||||
AVCSeqParamSetExtension sps_ex;
|
||||
umcRes = bitStream.GetSequenceParamSetExtension(&sps_ex);
|
||||
|
||||
if (umcRes == MFX_ERR_NONE)
|
||||
{
|
||||
m_headers.m_SeqExParams.AddHeader(&sps_ex);
|
||||
}
|
||||
else
|
||||
return umcRes;
|
||||
}
|
||||
break;
|
||||
|
||||
// picture parameter set
|
||||
case NAL_UT_PPS:
|
||||
{
|
||||
AVCPicParamSet pps;
|
||||
// set illegal id
|
||||
pps.pic_parameter_set_id = MAX_NUM_PIC_PARAM_SETS;
|
||||
|
||||
// Get id
|
||||
umcRes = bitStream.GetPictureParamSetPart1(&pps);
|
||||
if (MFX_ERR_NONE == umcRes)
|
||||
{
|
||||
AVCSeqParamSet *pRefsps = m_headers.m_SeqParams.GetHeader(pps.seq_parameter_set_id);
|
||||
|
||||
if (!pRefsps || pRefsps ->seq_parameter_set_id >= MAX_NUM_SEQ_PARAM_SETS)
|
||||
{
|
||||
pRefsps = m_headers.m_SeqParamsMvcExt.GetHeader(pps.seq_parameter_set_id);
|
||||
if (!pRefsps || pRefsps->seq_parameter_set_id >= MAX_NUM_SEQ_PARAM_SETS)
|
||||
{
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
}
|
||||
|
||||
// Get rest of pic param set
|
||||
umcRes = bitStream.GetPictureParamSetPart2(&pps, pRefsps);
|
||||
if (MFX_ERR_NONE == umcRes)
|
||||
{
|
||||
m_headers.m_PicParams.AddHeader(&pps);
|
||||
}
|
||||
|
||||
m_headers.m_SeqParams.SetCurrentID(pps.seq_parameter_set_id);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// subset sequence parameter set
|
||||
case NAL_UNIT_SUBSET_SPS:
|
||||
{
|
||||
AVCSeqParamSet sps;
|
||||
umcRes = bitStream.GetSequenceParamSet(&sps);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
{
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
|
||||
// decode additional parameters
|
||||
if ((AVC_PROFILE_MULTIVIEW_HIGH == sps.profile_idc) ||
|
||||
(AVC_PROFILE_STEREO_HIGH == sps.profile_idc))
|
||||
{
|
||||
AVCSeqParamSet spsMvcExt;
|
||||
AVCSeqParamSet * sps_temp = &spsMvcExt;
|
||||
|
||||
*sps_temp = sps;
|
||||
|
||||
m_headers.m_SeqParamsMvcExt.AddHeader(&spsMvcExt);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
// decode a prefix nal unit
|
||||
case NAL_UNIT_PREFIX:
|
||||
{
|
||||
umcRes = bitStream.GetNalUnitPrefix(&m_headers.m_nalExtension, uNALStorageIDC);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
{
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(const AVC_exception & )
|
||||
{
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::DecodeSEI(mfxBitstream * nalUnit)
|
||||
{
|
||||
if (m_headers.m_SeqParams.GetCurrrentID() == -1)
|
||||
return MFX_ERR_NONE;
|
||||
|
||||
AVCHeadersBitstream bitStream;
|
||||
|
||||
try
|
||||
{
|
||||
mfxU32 swappingSize = nalUnit->DataLength;
|
||||
mfxU8 * swappingMemory = GetMemoryForSwapping(swappingSize);
|
||||
|
||||
BytesSwapper::SwapMemory(swappingMemory, swappingSize, nalUnit->Data + nalUnit->DataOffset, nalUnit->DataLength);
|
||||
|
||||
bitStream.Reset(swappingMemory, swappingSize);
|
||||
|
||||
NAL_Unit_Type uNALUnitType;
|
||||
mfxU8 uNALStorageIDC;
|
||||
|
||||
bitStream.GetNALUnitType(uNALUnitType, uNALStorageIDC);
|
||||
|
||||
do
|
||||
{
|
||||
AVCSEIPayLoad m_SEIPayLoads;
|
||||
|
||||
bitStream.GetSEI(m_headers.m_SeqParams,
|
||||
m_headers.m_SeqParams.GetCurrrentID(), &m_SEIPayLoads);
|
||||
|
||||
if (m_SEIPayLoads.payLoadType == SEI_RESERVED)
|
||||
continue;
|
||||
|
||||
m_headers.m_SEIParams.AddHeader(&m_SEIPayLoads);
|
||||
} while (bitStream.More_RBSP_Data());
|
||||
|
||||
} catch(...)
|
||||
{
|
||||
// nothing to do just catch it
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
AVCSlice * AVC_Spl::DecodeSliceHeader(mfxBitstream * nalUnit)
|
||||
{
|
||||
m_slicesStorage.push_back(AVCSlice());
|
||||
AVCSlice *pSlice = &m_slicesStorage.back();
|
||||
|
||||
mfxU32 swappingSize = nalUnit->DataLength;
|
||||
mfxU8 * swappingMemory = GetMemoryForSwapping(swappingSize);
|
||||
|
||||
BytesSwapper::SwapMemory(swappingMemory, swappingSize, nalUnit->Data + nalUnit->DataOffset, nalUnit->DataLength);
|
||||
|
||||
mfxI32 pps_pid = pSlice->RetrievePicParamSetNumber(swappingMemory, swappingSize);
|
||||
if (pps_pid == -1)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
AVCSEIPayLoad * spl = m_headers.m_SEIParams.GetHeader(SEI_RECOVERY_POINT_TYPE);
|
||||
|
||||
if (m_WaitForIDR)
|
||||
{
|
||||
if (pSlice->GetSliceHeader()->slice_type != INTRASLICE && !spl)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
pSlice->m_picParamSet = m_headers.m_PicParams.GetHeader(pps_pid);
|
||||
if (!pSlice->m_picParamSet)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
mfxI32 seq_parameter_set_id = pSlice->m_picParamSet->seq_parameter_set_id;
|
||||
|
||||
if (NAL_UT_CODED_SLICE_EXTENSION == pSlice->GetSliceHeader()->nal_unit_type)
|
||||
{
|
||||
pSlice->m_seqParamSet = pSlice->m_seqParamSetMvcEx = m_headers.m_SeqParamsMvcExt.GetHeader(seq_parameter_set_id);
|
||||
|
||||
if (NULL == pSlice->m_seqParamSetMvcEx)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
m_headers.m_SeqParamsMvcExt.SetCurrentID(pSlice->m_seqParamSetMvcEx->seq_parameter_set_id);
|
||||
m_headers.m_PicParams.SetCurrentID(pSlice->m_picParamSet->pic_parameter_set_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
pSlice->m_seqParamSetMvcEx = m_headers.m_SeqParamsMvcExt.GetCurrentHeader();
|
||||
pSlice->m_seqParamSet = m_headers.m_SeqParams.GetHeader(seq_parameter_set_id);
|
||||
|
||||
m_headers.m_SeqParams.SetCurrentID(pSlice->m_picParamSet->seq_parameter_set_id);
|
||||
m_headers.m_PicParams.SetCurrentID(pSlice->m_picParamSet->pic_parameter_set_id);
|
||||
}
|
||||
|
||||
pSlice->m_seqParamSetEx = m_headers.m_SeqExParams.GetHeader(seq_parameter_set_id);
|
||||
pSlice->m_dTime = nalUnit->TimeStamp;
|
||||
|
||||
if (!pSlice->DecodeHeader(swappingMemory, swappingSize))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (spl && (pSlice->GetSliceHeader()->slice_type != INTRASLICE))
|
||||
{
|
||||
m_headers.m_SEIParams.RemoveHeader(spl->GetID());
|
||||
}
|
||||
|
||||
m_WaitForIDR = false;
|
||||
|
||||
return pSlice;
|
||||
}
|
||||
|
||||
|
||||
AVCFrameInfo * AVC_Spl::GetFreeFrame()
|
||||
{
|
||||
return m_AUInfo.get();
|
||||
}
|
||||
|
||||
void AVC_Spl::ResetCurrentState()
|
||||
{
|
||||
m_frame.DataLength = 0;
|
||||
m_frame.SliceNum = 0;
|
||||
m_frame.FirstFieldSliceNum = 0;
|
||||
m_AUInfo->Reset();
|
||||
if (m_slicesStorage.size() > 1)
|
||||
{
|
||||
m_slicesStorage.erase(m_slicesStorage.begin(), --m_slicesStorage.end());
|
||||
}
|
||||
}
|
||||
|
||||
bool AVC_Spl::IsFieldOfOneFrame(AVCFrameInfo * frame, const AVCSliceHeader * slice1, const AVCSliceHeader *slice2)
|
||||
{
|
||||
if (frame && frame->m_index)
|
||||
return false;
|
||||
|
||||
if ((slice1->nal_ref_idc && !slice2->nal_ref_idc) ||
|
||||
(!slice1->nal_ref_idc && slice2->nal_ref_idc))
|
||||
return false;
|
||||
|
||||
if (slice1->field_pic_flag != slice2->field_pic_flag)
|
||||
return false;
|
||||
|
||||
if (slice1->bottom_field_flag == slice2->bottom_field_flag)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool IsSlicesOfOneAU(const AVCSliceHeader *pOne, const AVCSliceHeader *pTwo)
|
||||
{
|
||||
if (!pOne || !pTwo)
|
||||
return true;
|
||||
|
||||
if (pOne->view_id != pTwo->view_id)
|
||||
{
|
||||
if (pOne->view_id < pTwo->view_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// this function checks two slices are from same picture or not
|
||||
// 7.4.1.2.4 part of AVC standart
|
||||
|
||||
if ((pOne->frame_num != pTwo->frame_num) ||
|
||||
(pOne->first_mb_in_slice == pTwo->first_mb_in_slice) ||
|
||||
(pOne->pic_parameter_set_id != pTwo->pic_parameter_set_id) ||
|
||||
(pOne->field_pic_flag != pTwo->field_pic_flag) ||
|
||||
(pOne->bottom_field_flag != pTwo->bottom_field_flag))
|
||||
return false;
|
||||
|
||||
if ((pOne->nal_ref_idc != pTwo->nal_ref_idc) &&
|
||||
(0 == std::min(pOne->nal_ref_idc, pTwo->nal_ref_idc)))
|
||||
return false;
|
||||
|
||||
if ((pOne->pic_order_cnt_lsb != pTwo->pic_order_cnt_lsb) ||
|
||||
(pOne->delta_pic_order_cnt_bottom != pTwo->delta_pic_order_cnt_bottom))
|
||||
return false;
|
||||
|
||||
if ((pOne->delta_pic_order_cnt[0] != pTwo->delta_pic_order_cnt[0]) ||
|
||||
(pOne->delta_pic_order_cnt[1] != pTwo->delta_pic_order_cnt[1]))
|
||||
return false;
|
||||
|
||||
if (pOne->nal_unit_type != pTwo->nal_unit_type)
|
||||
{
|
||||
if ((NAL_UT_IDR_SLICE == pOne->nal_unit_type) ||
|
||||
(NAL_UT_IDR_SLICE == pTwo->nal_unit_type))
|
||||
return false;
|
||||
}
|
||||
else if (NAL_UT_IDR_SLICE == pOne->nal_unit_type)
|
||||
{
|
||||
if (pOne->idr_pic_id != pTwo->idr_pic_id)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
mfxStatus AVC_Spl::AddSlice(AVCSlice * pSlice)
|
||||
{
|
||||
m_pLastSlice = 0;
|
||||
|
||||
if (!pSlice)
|
||||
{
|
||||
// complete current frame info
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
if (m_currentInfo)
|
||||
{
|
||||
AVCSlice * pFirstFrameSlice = m_currentInfo->m_slice;
|
||||
|
||||
if (pFirstFrameSlice && (false == IsSlicesOfOneAU(pFirstFrameSlice->GetSliceHeader(), pSlice->GetSliceHeader())))
|
||||
{
|
||||
// complete frame
|
||||
if (pSlice->IsField())
|
||||
{
|
||||
if (IsFieldOfOneFrame(m_currentInfo, pFirstFrameSlice->GetSliceHeader(), pSlice->GetSliceHeader()))
|
||||
{
|
||||
m_currentInfo->m_index = 1;
|
||||
m_currentInfo->m_slice = pSlice;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentInfo->m_index = 0;
|
||||
m_pLastSlice = pSlice;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentInfo->m_index = 0;
|
||||
m_pLastSlice = pSlice;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_currentInfo = GetFreeFrame();
|
||||
if (!m_currentInfo)
|
||||
{
|
||||
m_pLastSlice = pSlice;
|
||||
return MFX_ERR_NOT_ENOUGH_BUFFER;
|
||||
}
|
||||
m_currentInfo->m_index = 0;
|
||||
}
|
||||
|
||||
if (!m_currentInfo->m_slice)
|
||||
m_currentInfo->m_slice = pSlice;
|
||||
|
||||
return MFX_ERR_MORE_DATA;
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::AddNalUnit(mfxBitstream * nalUnit)
|
||||
{
|
||||
static mfxU8 start_code_prefix[] = {0, 0, 1};
|
||||
|
||||
if (m_frame.DataLength + nalUnit->DataLength + sizeof(start_code_prefix) >= BUFFER_SIZE)
|
||||
return MFX_ERR_NOT_ENOUGH_BUFFER;
|
||||
|
||||
MSDK_MEMCPY_BUF(m_frame.Data, m_frame.DataLength, BUFFER_SIZE, start_code_prefix, sizeof(start_code_prefix));
|
||||
MSDK_MEMCPY_BUF(m_frame.Data, m_frame.DataLength + sizeof(start_code_prefix), BUFFER_SIZE, nalUnit->Data + nalUnit->DataOffset, nalUnit->DataLength);
|
||||
|
||||
m_frame.DataLength += (mfxU32)(nalUnit->DataLength + sizeof(start_code_prefix));
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::AddSliceNalUnit(mfxBitstream * nalUnit, AVCSlice * slice)
|
||||
{
|
||||
static mfxU8 start_code_prefix[] = {0, 0, 1};
|
||||
|
||||
mfxU32 sliceLength = (mfxU32)(nalUnit->DataLength + sizeof(start_code_prefix));
|
||||
|
||||
if (m_frame.DataLength + sliceLength >= BUFFER_SIZE)
|
||||
return MFX_ERR_NOT_ENOUGH_BUFFER;
|
||||
|
||||
MSDK_MEMCPY_BUF(m_frame.Data, m_frame.DataLength, BUFFER_SIZE, start_code_prefix, sizeof(start_code_prefix));
|
||||
MSDK_MEMCPY_BUF(m_frame.Data, m_frame.DataLength + sizeof(start_code_prefix), BUFFER_SIZE, nalUnit->Data + nalUnit->DataOffset, nalUnit->DataLength);
|
||||
|
||||
if (!m_frame.SliceNum)
|
||||
{
|
||||
m_frame.TimeStamp = nalUnit->TimeStamp;
|
||||
}
|
||||
|
||||
m_frame.SliceNum++;
|
||||
|
||||
if (m_slices.size() <= m_frame.SliceNum)
|
||||
{
|
||||
m_slices.resize(m_frame.SliceNum + 10);
|
||||
m_frame.Slice = &m_slices[0];
|
||||
}
|
||||
|
||||
SliceSplitterInfo & newSlice = m_slices[m_frame.SliceNum - 1];
|
||||
|
||||
AVCHeadersBitstream * bs = slice->GetBitStream();
|
||||
|
||||
newSlice.HeaderLength = (mfxU32)bs->BytesDecoded();
|
||||
|
||||
// add number of 003 sequence to HeaderLength
|
||||
for(mfxU8 *ptr = nalUnit->Data + sizeof(start_code_prefix); ptr < nalUnit->Data + sizeof(start_code_prefix) + newSlice.HeaderLength; ptr++)
|
||||
{
|
||||
if (ptr[0]==0 && ptr[1]==0 && ptr[2]==3)
|
||||
{
|
||||
newSlice.HeaderLength++;
|
||||
}
|
||||
}
|
||||
|
||||
newSlice.HeaderLength += sizeof(start_code_prefix) + 1;
|
||||
|
||||
newSlice.DataLength = sliceLength;
|
||||
newSlice.DataOffset = m_frame.DataLength;
|
||||
if(IS_I_SLICE(slice->GetSliceHeader()->slice_type))
|
||||
newSlice.SliceType = TYPE_I;
|
||||
else if(IS_P_SLICE(slice->GetSliceHeader()->slice_type))
|
||||
newSlice.SliceType = TYPE_P;
|
||||
else if(IS_B_SLICE(slice->GetSliceHeader()->slice_type))
|
||||
newSlice.SliceType = TYPE_B;
|
||||
|
||||
m_frame.DataLength += sliceLength;
|
||||
|
||||
if (!m_currentInfo->m_index)
|
||||
m_frame.FirstFieldSliceNum++;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::ProcessNalUnit(mfxI32 nalType, mfxBitstream * nalUnit)
|
||||
{
|
||||
if (!nalUnit)
|
||||
return MFX_ERR_MORE_DATA;
|
||||
|
||||
switch (nalType)
|
||||
{
|
||||
case NAL_UT_IDR_SLICE:
|
||||
case NAL_UT_SLICE:
|
||||
case NAL_UT_CODED_SLICE_EXTENSION:
|
||||
{
|
||||
AVCSlice * pSlice = DecodeSliceHeader(nalUnit);
|
||||
if (pSlice)
|
||||
{
|
||||
mfxStatus sts = AddSlice(pSlice);
|
||||
if (sts == MFX_ERR_NOT_ENOUGH_BUFFER)
|
||||
{
|
||||
return sts;
|
||||
}
|
||||
|
||||
if (!m_pLastSlice)
|
||||
{
|
||||
AddSliceNalUnit(nalUnit, pSlice);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_lastNalUnit = nalUnit;
|
||||
}
|
||||
|
||||
if (sts == MFX_ERR_NONE)
|
||||
{
|
||||
return sts;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case NAL_UT_SPS:
|
||||
case NAL_UT_PPS:
|
||||
case NAL_UT_SPS_EX:
|
||||
case NAL_UNIT_SUBSET_SPS:
|
||||
case NAL_UNIT_PREFIX:
|
||||
DecodeHeader(nalUnit);
|
||||
AddNalUnit(nalUnit);
|
||||
break;
|
||||
|
||||
case NAL_UT_SEI:
|
||||
DecodeSEI(nalUnit);
|
||||
AddNalUnit(nalUnit);
|
||||
break;
|
||||
case NAL_UT_AUD:
|
||||
AddNalUnit(nalUnit);
|
||||
break;
|
||||
|
||||
case NAL_UT_DPA:
|
||||
case NAL_UT_DPB:
|
||||
case NAL_UT_DPC:
|
||||
case NAL_UT_FD:
|
||||
case NAL_UT_UNSPECIFIED:
|
||||
break;
|
||||
|
||||
case NAL_END_OF_STREAM:
|
||||
case NAL_END_OF_SEQ:
|
||||
{
|
||||
AddNalUnit(nalUnit);
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
||||
return MFX_ERR_MORE_DATA;
|
||||
}
|
||||
|
||||
mfxStatus AVC_Spl::GetFrame(mfxBitstream * bs_in, FrameSplitterInfo ** frame)
|
||||
{
|
||||
*frame = 0;
|
||||
|
||||
do
|
||||
{
|
||||
if (m_pLastSlice)
|
||||
{
|
||||
AVCSlice * pSlice = m_pLastSlice;
|
||||
mfxStatus sts = AddSlice(pSlice);
|
||||
if(!m_lastNalUnit)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("ERROR: m_lastNalUnit=NULL\n"));
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
AddSliceNalUnit(m_lastNalUnit, pSlice);
|
||||
m_lastNalUnit = 0;
|
||||
if (sts == MFX_ERR_NONE)
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxBitstream * destination=NULL;
|
||||
mfxI32 nalType = m_pNALSplitter->GetNalUnits(bs_in, destination);
|
||||
mfxStatus sts = ProcessNalUnit(nalType, destination);
|
||||
|
||||
if (sts == MFX_ERR_NONE || (!bs_in && m_frame.SliceNum))
|
||||
{
|
||||
m_currentInfo = 0;
|
||||
*frame = &m_frame;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
} while (bs_in && bs_in->DataLength > MINIMAL_DATA_SIZE);
|
||||
|
||||
return MFX_ERR_MORE_DATA;
|
||||
}
|
||||
|
||||
AVCSlice::AVCSlice()
|
||||
{
|
||||
Reset();
|
||||
}
|
||||
|
||||
void AVCSlice::Reset()
|
||||
{
|
||||
m_picParamSet = 0;
|
||||
m_seqParamSet = 0;
|
||||
m_seqParamSetMvcEx = 0;
|
||||
m_seqParamSetEx = 0;
|
||||
m_dTime=0;
|
||||
memset(&m_sliceHeader, 0, sizeof(m_sliceHeader));
|
||||
}
|
||||
|
||||
AVCSliceHeader * AVCSlice::GetSliceHeader()
|
||||
{
|
||||
return &m_sliceHeader;
|
||||
}
|
||||
|
||||
mfxI32 AVCSlice::RetrievePicParamSetNumber(mfxU8 *pSource, mfxU32 nSourceSize)
|
||||
{
|
||||
if (!nSourceSize)
|
||||
return -1;
|
||||
|
||||
m_bitStream.Reset(pSource, nSourceSize);
|
||||
|
||||
mfxStatus umcRes = MFX_ERR_NONE;
|
||||
|
||||
try
|
||||
{
|
||||
umcRes = m_bitStream.GetNALUnitType(m_sliceHeader.nal_unit_type, m_sliceHeader.nal_ref_idc);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
return false;
|
||||
|
||||
// decode first part of slice header
|
||||
umcRes = m_bitStream.GetSliceHeaderPart1(&m_sliceHeader);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
return -1;
|
||||
} catch (...)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return m_sliceHeader.pic_parameter_set_id;
|
||||
}
|
||||
|
||||
bool AVCSlice::DecodeHeader(mfxU8 *pSource, mfxU32 nSourceSize)
|
||||
{
|
||||
m_bitStream.Reset(pSource, nSourceSize);
|
||||
|
||||
if (!nSourceSize)
|
||||
return false;
|
||||
|
||||
mfxStatus umcRes = MFX_ERR_NONE;
|
||||
// Locals for additional slice data to be read into, the data
|
||||
// was read and saved from the first slice header of the picture,
|
||||
// is not supposed to change within the picture, so can be
|
||||
// discarded when read again here.
|
||||
try
|
||||
{
|
||||
memset(&m_sliceHeader, 0, sizeof(m_sliceHeader));
|
||||
|
||||
umcRes = m_bitStream.GetNALUnitType(m_sliceHeader.nal_unit_type, m_sliceHeader.nal_ref_idc);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
return false;
|
||||
|
||||
// decode first part of slice header
|
||||
umcRes = m_bitStream.GetSliceHeaderPart1(&m_sliceHeader);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
return false;
|
||||
|
||||
// decode second part of slice header
|
||||
umcRes = m_bitStream.GetSliceHeaderPart2(&m_sliceHeader,
|
||||
m_picParamSet,
|
||||
m_seqParamSet);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
return false;
|
||||
|
||||
PredWeightTable m_PredWeight[2][MAX_NUM_REF_FRAMES];
|
||||
RefPicListReorderInfo ReorderInfoL0;
|
||||
RefPicListReorderInfo ReorderInfoL1;
|
||||
AdaptiveMarkingInfo m_AdaptiveMarkingInfo;
|
||||
|
||||
// decode second part of slice header
|
||||
umcRes = m_bitStream.GetSliceHeaderPart3(&m_sliceHeader,
|
||||
m_PredWeight[0],
|
||||
m_PredWeight[1],
|
||||
&ReorderInfoL0,
|
||||
&ReorderInfoL1,
|
||||
&m_AdaptiveMarkingInfo,
|
||||
m_picParamSet,
|
||||
m_seqParamSet,
|
||||
m_sliceHeader.nal_ref_idc);
|
||||
if (MFX_ERR_NONE != umcRes)
|
||||
return false;
|
||||
|
||||
if (m_picParamSet->entropy_coding_mode)
|
||||
m_bitStream.AlignPointerRight();
|
||||
}
|
||||
catch(const AVC_exception & )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (MFX_ERR_NONE == umcRes);
|
||||
}
|
||||
|
||||
|
||||
mfxStatus AVC_Spl::PostProcessing(FrameSplitterInfo *frame, mfxU32 sliceNum)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(frame);
|
||||
UNREFERENCED_PARAMETER(sliceNum);
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
} // namespace ProtectedLibrary
|
||||
296
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/base_allocator.cpp
vendored
Normal file
296
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/base_allocator.cpp
vendored
Normal file
@@ -0,0 +1,296 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include "base_allocator.h"
|
||||
#include "vm/thread_defs.h"
|
||||
|
||||
MFXFrameAllocator::MFXFrameAllocator()
|
||||
{
|
||||
pthis = this;
|
||||
Alloc = Alloc_;
|
||||
Lock = Lock_;
|
||||
Free = Free_;
|
||||
Unlock = Unlock_;
|
||||
GetHDL = GetHDL_;
|
||||
}
|
||||
|
||||
MFXFrameAllocator::~MFXFrameAllocator()
|
||||
{
|
||||
}
|
||||
|
||||
mfxStatus MFXFrameAllocator::Alloc_(mfxHDL pthis, mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
if (0 == pthis)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
|
||||
|
||||
return self.AllocFrames(request, response);
|
||||
}
|
||||
|
||||
mfxStatus MFXFrameAllocator::Lock_(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (0 == pthis)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
|
||||
|
||||
return self.LockFrame(mid, ptr);
|
||||
}
|
||||
|
||||
mfxStatus MFXFrameAllocator::Unlock_(mfxHDL pthis, mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (0 == pthis)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
MFXFrameAllocator& self = *(MFXFrameAllocator *)pthis;
|
||||
|
||||
return self.UnlockFrame(mid, ptr);
|
||||
}
|
||||
|
||||
mfxStatus MFXFrameAllocator::Free_(mfxHDL pthis, mfxFrameAllocResponse *response)
|
||||
{
|
||||
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::BaseFrameAllocator()
|
||||
{
|
||||
}
|
||||
|
||||
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::ReallocFrame(mfxMemId midIn, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut)
|
||||
{
|
||||
return ReallocImpl(midIn, info, memType, midOut);
|
||||
}
|
||||
|
||||
mfxStatus BaseFrameAllocator::AllocFrames(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
if (0 == request || 0 == response || 0 == request->NumFrameSuggested)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
if (MFX_ERR_NONE != CheckRequestType(request))
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
if ( // External Frames
|
||||
((request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) &&
|
||||
(request->Type & (MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_FROM_ENC | MFX_MEMTYPE_FROM_PAK)))
|
||||
// Exception: Internal Frames for FEI ENC / PAK reconstructs
|
||||
||
|
||||
((request->Type & MFX_MEMTYPE_INTERNAL_FRAME) &&
|
||||
(request->Type & (MFX_MEMTYPE_FROM_ENC | MFX_MEMTYPE_FROM_PAK)))
|
||||
)
|
||||
{
|
||||
bool foundInCache = false;
|
||||
// external decoder allocations
|
||||
std::list<UniqueResponse>::iterator
|
||||
it = m_ExtResponses.begin(),
|
||||
et = m_ExtResponses.end();
|
||||
UniqueResponse checker(*response, request->Info.Width, request->Info.Height, request->Type);
|
||||
for (; it != et; ++it)
|
||||
{
|
||||
// same decoder and same size
|
||||
if (request->AllocId == it->AllocId && checker(*it))
|
||||
{
|
||||
// check if enough frames were allocated
|
||||
if (request->NumFrameSuggested > it->NumFrameActual)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
it->m_refCount++;
|
||||
// return existing response
|
||||
*response = (mfxFrameAllocResponse&)*it;
|
||||
foundInCache = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!foundInCache)
|
||||
{
|
||||
sts = AllocImpl(request, response);
|
||||
if (sts == MFX_ERR_NONE)
|
||||
{
|
||||
response->AllocId = request->AllocId;
|
||||
m_ExtResponses.push_back(UniqueResponse(*response, request->Info.Width, request->Info.Height, UniqueResponse::CropMemoryTypeToStore(request->Type)));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// internal allocations
|
||||
|
||||
// reserve space before allocation to avoid memory leak
|
||||
m_responses.push_back(mfxFrameAllocResponse());
|
||||
|
||||
sts = AllocImpl(request, response);
|
||||
if (sts == MFX_ERR_NONE)
|
||||
{
|
||||
m_responses.back() = *response;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_responses.pop_back();
|
||||
}
|
||||
}
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus BaseFrameAllocator::FreeFrames(mfxFrameAllocResponse *response)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
if (response == 0)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
// check whether response is an external decoder response
|
||||
std::list<UniqueResponse>::iterator i =
|
||||
std::find_if( m_ExtResponses.begin(), m_ExtResponses.end(), std::bind(IsSame(), *response, std::placeholders::_1));
|
||||
|
||||
if (i != m_ExtResponses.end())
|
||||
{
|
||||
if ((--i->m_refCount) == 0)
|
||||
{
|
||||
sts = ReleaseResponse(response);
|
||||
m_ExtResponses.erase(i);
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
|
||||
// if not found so far, then search in internal responses
|
||||
std::list<mfxFrameAllocResponse>::iterator i2 =
|
||||
std::find_if(m_responses.begin(), m_responses.end(), std::bind(IsSame(), *response, std::placeholders::_1));
|
||||
|
||||
if (i2 != m_responses.end())
|
||||
{
|
||||
sts = ReleaseResponse(response);
|
||||
m_responses.erase(i2);
|
||||
return sts;
|
||||
}
|
||||
|
||||
// not found anywhere, report an error
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
mfxStatus BaseFrameAllocator::Close()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(mtx);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
MFXBufferAllocator::MFXBufferAllocator()
|
||||
{
|
||||
pthis = this;
|
||||
Alloc = Alloc_;
|
||||
Lock = Lock_;
|
||||
Free = Free_;
|
||||
Unlock = Unlock_;
|
||||
}
|
||||
|
||||
MFXBufferAllocator::~MFXBufferAllocator()
|
||||
{
|
||||
}
|
||||
|
||||
mfxStatus MFXBufferAllocator::Alloc_(mfxHDL pthis, mfxU32 nbytes, mfxU16 type, mfxMemId *mid)
|
||||
{
|
||||
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)
|
||||
{
|
||||
if (0 == pthis)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
MFXBufferAllocator& self = *(MFXBufferAllocator *)pthis;
|
||||
|
||||
return self.UnlockBuffer(mid);
|
||||
}
|
||||
|
||||
mfxStatus MFXBufferAllocator::Free_(mfxHDL pthis, mfxMemId mid)
|
||||
{
|
||||
if (0 == pthis)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
MFXBufferAllocator& self = *(MFXBufferAllocator *)pthis;
|
||||
|
||||
return self.FreeBuffer(mid);
|
||||
}
|
||||
|
||||
1000
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/brc_routines.cpp
vendored
Normal file
1000
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/brc_routines.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
600
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d11_allocator.cpp
vendored
Normal file
600
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d11_allocator.cpp
vendored
Normal file
@@ -0,0 +1,600 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include "sample_defs.h"
|
||||
|
||||
#if MFX_D3D11_SUPPORT
|
||||
|
||||
#include <objbase.h>
|
||||
#include <initguid.h>
|
||||
#include <assert.h>
|
||||
#include <algorithm>
|
||||
#include <functional>
|
||||
#include <iterator>
|
||||
#include "d3d11_allocator.h"
|
||||
|
||||
#define D3DFMT_NV12 (DXGI_FORMAT)MAKEFOURCC('N','V','1','2')
|
||||
#define D3DFMT_YV12 (DXGI_FORMAT)MAKEFOURCC('Y','V','1','2')
|
||||
|
||||
//for generating sequence of mfx handles
|
||||
template <typename T>
|
||||
struct sequence {
|
||||
T x;
|
||||
sequence(T seed) : x(seed) { }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct sequence<mfxHDL> {
|
||||
mfxHDL x;
|
||||
sequence(mfxHDL seed) : x(seed) { }
|
||||
|
||||
mfxHDL operator ()()
|
||||
{
|
||||
mfxHDL y = x;
|
||||
x = (mfxHDL)(1 + (size_t)(x));
|
||||
return y;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
D3D11FrameAllocator::D3D11FrameAllocator()
|
||||
{
|
||||
m_pDeviceContext = NULL;
|
||||
}
|
||||
|
||||
D3D11FrameAllocator::~D3D11FrameAllocator()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
D3D11FrameAllocator::TextureSubResource D3D11FrameAllocator::GetResourceFromMid(mfxMemId mid)
|
||||
{
|
||||
size_t index = (size_t)MFXReadWriteMid(mid).raw() - 1;
|
||||
|
||||
if(m_memIdMap.size() <= index)
|
||||
return TextureSubResource();
|
||||
|
||||
//reverse iterator dereferencing
|
||||
TextureResource * p = &(*m_memIdMap[index]);
|
||||
if (!p->bAlloc)
|
||||
return TextureSubResource();
|
||||
|
||||
return TextureSubResource(p, mid);
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::Init(mfxAllocatorParams *pParams)
|
||||
{
|
||||
D3D11AllocatorParams *pd3d11Params = 0;
|
||||
pd3d11Params = dynamic_cast<D3D11AllocatorParams *>(pParams);
|
||||
|
||||
if (NULL == pd3d11Params ||
|
||||
NULL == pd3d11Params->pDevice)
|
||||
{
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
m_initParams = *pd3d11Params;
|
||||
MSDK_SAFE_RELEASE(m_pDeviceContext);
|
||||
pd3d11Params->pDevice->GetImmediateContext(&m_pDeviceContext);
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::Close()
|
||||
{
|
||||
mfxStatus sts = BaseFrameAllocator::Close();
|
||||
for(referenceType i = m_resourcesByRequest.begin(); i != m_resourcesByRequest.end(); i++)
|
||||
{
|
||||
i->Release();
|
||||
}
|
||||
m_resourcesByRequest.clear();
|
||||
m_memIdMap.clear();
|
||||
MSDK_SAFE_RELEASE(m_pDeviceContext);
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
HRESULT hRes = S_OK;
|
||||
|
||||
D3D11_TEXTURE2D_DESC desc = {0};
|
||||
D3D11_MAPPED_SUBRESOURCE lockedRect = {0};
|
||||
|
||||
|
||||
//check that texture exists
|
||||
TextureSubResource sr = GetResourceFromMid(mid);
|
||||
if (!sr.GetTexture())
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
D3D11_MAP mapType = D3D11_MAP_READ;
|
||||
UINT mapFlags = D3D11_MAP_FLAG_DO_NOT_WAIT;
|
||||
{
|
||||
if (NULL == sr.GetStaging())
|
||||
{
|
||||
hRes = m_pDeviceContext->Map(sr.GetTexture(), sr.GetSubResource(), D3D11_MAP_READ, D3D11_MAP_FLAG_DO_NOT_WAIT, &lockedRect);
|
||||
desc.Format = DXGI_FORMAT_P8;
|
||||
}
|
||||
else
|
||||
{
|
||||
sr.GetTexture()->GetDesc(&desc);
|
||||
|
||||
if (DXGI_FORMAT_NV12 != desc.Format &&
|
||||
DXGI_FORMAT_420_OPAQUE != desc.Format &&
|
||||
DXGI_FORMAT_YUY2 != desc.Format &&
|
||||
DXGI_FORMAT_P8 != desc.Format &&
|
||||
DXGI_FORMAT_B8G8R8A8_UNORM != desc.Format &&
|
||||
DXGI_FORMAT_R16_UINT != desc.Format &&
|
||||
DXGI_FORMAT_R16_UNORM != desc.Format &&
|
||||
DXGI_FORMAT_R10G10B10A2_UNORM != desc.Format &&
|
||||
DXGI_FORMAT_R16G16B16A16_UNORM != desc.Format &&
|
||||
DXGI_FORMAT_P010 != desc.Format &&
|
||||
DXGI_FORMAT_AYUV != desc.Format
|
||||
#if (MFX_VERSION >= 1027)
|
||||
&& DXGI_FORMAT_Y210 != desc.Format
|
||||
&& DXGI_FORMAT_Y410 != desc.Format
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
&& DXGI_FORMAT_P016 != desc.Format
|
||||
&& DXGI_FORMAT_Y216 != desc.Format
|
||||
&& DXGI_FORMAT_Y416 != desc.Format
|
||||
#endif
|
||||
)
|
||||
{
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
}
|
||||
|
||||
//coping data only in case user wants to read from stored surface
|
||||
{
|
||||
|
||||
if (MFXReadWriteMid(mid, MFXReadWriteMid::reuse).isRead())
|
||||
{
|
||||
m_pDeviceContext->CopySubresourceRegion(sr.GetStaging(), 0, 0, 0, 0, sr.GetTexture(), sr.GetSubResource(), NULL);
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
hRes = m_pDeviceContext->Map(sr.GetStaging(), 0, mapType, mapFlags, &lockedRect);
|
||||
if (S_OK != hRes && DXGI_ERROR_WAS_STILL_DRAWING != hRes)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("ERROR: m_pDeviceContext->Map = 0x%08lx\n"), hRes);
|
||||
}
|
||||
}
|
||||
while (DXGI_ERROR_WAS_STILL_DRAWING == hRes);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if (FAILED(hRes))
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
switch (desc.Format)
|
||||
{
|
||||
case DXGI_FORMAT_P010:
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case DXGI_FORMAT_P016:
|
||||
#endif
|
||||
case DXGI_FORMAT_NV12:
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = (mfxU8 *)lockedRect.pData + desc.Height * lockedRect.RowPitch;
|
||||
ptr->V = (desc.Format == DXGI_FORMAT_P010) ? ptr->U + 2 : ptr->U + 1;
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_420_OPAQUE: // can be unsupported by standard ms guid
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->V = ptr->Y + desc.Height * lockedRect.RowPitch;
|
||||
ptr->U = ptr->V + (desc.Height * lockedRect.RowPitch) / 4;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_YUY2:
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = ptr->Y + 1;
|
||||
ptr->V = ptr->Y + 3;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_P8 :
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = 0;
|
||||
ptr->V = 0;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_AYUV:
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->V = (mfxU8 *)lockedRect.pData;
|
||||
ptr->U = ptr->V + 1;
|
||||
ptr->Y = ptr->V + 2;
|
||||
ptr->A = ptr->V + 3;
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_B8G8R8A8_UNORM:
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->B = (mfxU8 *)lockedRect.pData;
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
ptr->A = ptr->B + 3;
|
||||
|
||||
break;
|
||||
case DXGI_FORMAT_R10G10B10A2_UNORM :
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->B = (mfxU8 *)lockedRect.pData;
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
ptr->A = ptr->B + 3;
|
||||
|
||||
break;
|
||||
case DXGI_FORMAT_R16G16B16A16_UNORM:
|
||||
ptr->V16 = (mfxU16*)lockedRect.pData;
|
||||
ptr->U16 = ptr->V16 + 1;
|
||||
ptr->Y16 = ptr->V16 + 2;
|
||||
ptr->A = (mfxU8*)(ptr->V16 + 3);
|
||||
ptr->PitchHigh = (mfxU16)((mfxU32)lockedRect.RowPitch / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((mfxU32)lockedRect.RowPitch % (1 << 16));
|
||||
break;
|
||||
case DXGI_FORMAT_R16_UNORM :
|
||||
case DXGI_FORMAT_R16_UINT :
|
||||
ptr->Pitch = (mfxU16)lockedRect.RowPitch;
|
||||
ptr->Y16 = (mfxU16 *)lockedRect.pData;
|
||||
ptr->U16 = 0;
|
||||
ptr->V16 = 0;
|
||||
|
||||
break;
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case DXGI_FORMAT_Y416:
|
||||
ptr->PitchHigh = (mfxU16)(lockedRect.RowPitch / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)(lockedRect.RowPitch % (1 << 16));
|
||||
ptr->U16 = (mfxU16*)lockedRect.pData;
|
||||
ptr->Y16 = ptr->U16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 1;
|
||||
ptr->A = (mfxU8 *)(ptr->V16 + 1);
|
||||
break;
|
||||
case DXGI_FORMAT_Y216:
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case DXGI_FORMAT_Y210:
|
||||
ptr->PitchHigh = (mfxU16)(lockedRect.RowPitch / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)(lockedRect.RowPitch % (1 << 16));
|
||||
ptr->Y16 = (mfxU16 *)lockedRect.pData;
|
||||
ptr->U16 = ptr->Y16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 3;
|
||||
|
||||
break;
|
||||
|
||||
case DXGI_FORMAT_Y410:
|
||||
ptr->PitchHigh = (mfxU16)(lockedRect.RowPitch / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)(lockedRect.RowPitch % (1 << 16));
|
||||
ptr->Y410 = (mfxY410 *)lockedRect.pData;
|
||||
ptr->Y = 0;
|
||||
ptr->V = 0;
|
||||
ptr->A = 0;
|
||||
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
//check that texture exists
|
||||
TextureSubResource sr = GetResourceFromMid(mid);
|
||||
if (!sr.GetTexture())
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
if (NULL == sr.GetStaging())
|
||||
{
|
||||
m_pDeviceContext->Unmap(sr.GetTexture(), sr.GetSubResource());
|
||||
}
|
||||
else
|
||||
{
|
||||
m_pDeviceContext->Unmap(sr.GetStaging(), 0);
|
||||
//only if user wrote something to texture
|
||||
if (MFXReadWriteMid(mid, MFXReadWriteMid::reuse).isWrite())
|
||||
{
|
||||
m_pDeviceContext->CopySubresourceRegion(sr.GetTexture(), sr.GetSubResource(), 0, 0, 0, sr.GetStaging(), 0, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if (ptr)
|
||||
{
|
||||
ptr->Pitch=0;
|
||||
ptr->U=ptr->V=ptr->Y=0;
|
||||
ptr->A=ptr->R=ptr->G=ptr->B=0;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
|
||||
mfxStatus D3D11FrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
|
||||
{
|
||||
if (NULL == handle)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
TextureSubResource sr = GetResourceFromMid(mid);
|
||||
|
||||
if (!sr.GetTexture())
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
mfxHDLPair *pPair = (mfxHDLPair*)handle;
|
||||
|
||||
pPair->first = sr.GetTexture();
|
||||
pPair->second = (mfxHDL)(UINT_PTR)sr.GetSubResource();
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
|
||||
{
|
||||
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
if ((request->Type & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) != 0)
|
||||
return MFX_ERR_NONE;
|
||||
else
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
|
||||
{
|
||||
if (NULL == response)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
if (response->mids && 0 != response->NumFrameActual)
|
||||
{
|
||||
//check whether texture exsist
|
||||
TextureSubResource sr = GetResourceFromMid(response->mids[0]);
|
||||
|
||||
if (!sr.GetTexture())
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
sr.Release();
|
||||
|
||||
//if texture is last it is possible to remove also all handles from map to reduce fragmentation
|
||||
//search for allocated chunk
|
||||
if (m_resourcesByRequest.end() == std::find_if(m_resourcesByRequest.begin(), m_resourcesByRequest.end(), TextureResource::isAllocated))
|
||||
{
|
||||
m_resourcesByRequest.clear();
|
||||
m_memIdMap.clear();
|
||||
}
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::ReallocImpl(mfxMemId /*mid*/, const mfxFrameInfo *info, mfxU16 /*memType*/, mfxMemId *midOut)
|
||||
{
|
||||
if (!info || !midOut)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
//TODO: Need add implementation in the future.
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus D3D11FrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
HRESULT hRes;
|
||||
|
||||
DXGI_FORMAT colorFormat = ConverColortFormat(request->Info.FourCC);
|
||||
|
||||
if (DXGI_FORMAT_UNKNOWN == colorFormat)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("D3D11 Allocator: invalid fourcc is provided (%#X), exitting\n"),request->Info.FourCC);
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
TextureResource newTexture;
|
||||
|
||||
if (request->Info.FourCC == MFX_FOURCC_P8)
|
||||
{
|
||||
D3D11_BUFFER_DESC desc = { 0 };
|
||||
|
||||
desc.ByteWidth = request->Info.Width * request->Info.Height;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.BindFlags = 0;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.MiscFlags = 0;
|
||||
desc.StructureByteStride = 0;
|
||||
|
||||
ID3D11Buffer * buffer = 0;
|
||||
hRes = m_initParams.pDevice->CreateBuffer(&desc, 0, &buffer);
|
||||
if (FAILED(hRes))
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
newTexture.textures.push_back(reinterpret_cast<ID3D11Texture2D *>(buffer));
|
||||
}
|
||||
else
|
||||
{
|
||||
D3D11_TEXTURE2D_DESC desc = {0};
|
||||
|
||||
desc.Width = request->Info.Width;
|
||||
desc.Height = request->Info.Height;
|
||||
|
||||
desc.MipLevels = 1;
|
||||
//number of subresources is 1 in case of not single texture
|
||||
desc.ArraySize = m_initParams.bUseSingleTexture ? request->NumFrameSuggested : 1;
|
||||
desc.Format = ConverColortFormat(request->Info.FourCC);
|
||||
desc.SampleDesc.Count = 1;
|
||||
desc.Usage = D3D11_USAGE_DEFAULT;
|
||||
desc.MiscFlags = m_initParams.uncompressedResourceMiscFlags | D3D11_RESOURCE_MISC_SHARED;
|
||||
#if (MFX_VERSION >= 1025)
|
||||
if ((request->Type&MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET) && (request->Type & MFX_MEMTYPE_INTERNAL_FRAME))
|
||||
{
|
||||
desc.BindFlags = D3D11_BIND_DECODER | D3D11_BIND_VIDEO_ENCODER;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
desc.BindFlags = D3D11_BIND_DECODER;
|
||||
|
||||
if ( (MFX_MEMTYPE_FROM_VPPIN & request->Type) && (DXGI_FORMAT_YUY2 == desc.Format) ||
|
||||
(DXGI_FORMAT_B8G8R8A8_UNORM == desc.Format) ||
|
||||
(DXGI_FORMAT_R10G10B10A2_UNORM == desc.Format) ||
|
||||
(DXGI_FORMAT_R16G16B16A16_UNORM == desc.Format) )
|
||||
{
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
if (desc.ArraySize > 2)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
if ( (MFX_MEMTYPE_FROM_VPPOUT & request->Type) ||
|
||||
(MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET & request->Type))
|
||||
{
|
||||
desc.BindFlags = D3D11_BIND_RENDER_TARGET;
|
||||
if (desc.ArraySize > 2)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
if(request->Type&MFX_MEMTYPE_SHARED_RESOURCE)
|
||||
{
|
||||
desc.BindFlags |= D3D11_BIND_SHADER_RESOURCE;
|
||||
desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED;
|
||||
}
|
||||
|
||||
if( DXGI_FORMAT_P8 == desc.Format )
|
||||
{
|
||||
desc.BindFlags = 0;
|
||||
}
|
||||
|
||||
ID3D11Texture2D* pTexture2D;
|
||||
|
||||
for(size_t i = 0; i < request->NumFrameSuggested / desc.ArraySize; i++)
|
||||
{
|
||||
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
|
||||
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
msdk_printf(MSDK_STRING("CreateTexture2D(%lld) failed, hr = 0x%08lx\n"), (long long)i, hRes);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
newTexture.textures.push_back(pTexture2D);
|
||||
}
|
||||
|
||||
desc.ArraySize = 1;
|
||||
desc.Usage = D3D11_USAGE_STAGING;
|
||||
desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
|
||||
desc.BindFlags = 0;
|
||||
desc.MiscFlags = 0;
|
||||
|
||||
for(size_t i = 0; i < request->NumFrameSuggested; i++)
|
||||
{
|
||||
hRes = m_initParams.pDevice->CreateTexture2D(&desc, NULL, &pTexture2D);
|
||||
|
||||
if (FAILED(hRes))
|
||||
{
|
||||
msdk_printf(MSDK_STRING("Create staging texture(%lld) failed hr = 0x%X\n"), (long long)i, (unsigned int)hRes);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
newTexture.stagingTexture.push_back(pTexture2D);
|
||||
}
|
||||
}
|
||||
|
||||
// mapping to self created handles array, starting from zero or from last assigned handle + 1
|
||||
sequence<mfxHDL> seq_initializer(m_resourcesByRequest.empty() ? 0 : m_resourcesByRequest.back().outerMids.back());
|
||||
|
||||
//incrementing starting index
|
||||
//1. 0(NULL) is invalid memid
|
||||
//2. back is last index not new one
|
||||
seq_initializer();
|
||||
|
||||
std::generate_n(std::back_inserter(newTexture.outerMids), request->NumFrameSuggested, seq_initializer);
|
||||
|
||||
//saving texture resources
|
||||
m_resourcesByRequest.push_back(newTexture);
|
||||
|
||||
//providing pointer to mids externally
|
||||
response->mids = &m_resourcesByRequest.back().outerMids.front();
|
||||
response->NumFrameActual = request->NumFrameSuggested;
|
||||
|
||||
//iterator prior end()
|
||||
std::list <TextureResource>::iterator it_last = m_resourcesByRequest.end();
|
||||
//fill map
|
||||
std::fill_n(std::back_inserter(m_memIdMap), request->NumFrameSuggested, --it_last);
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
DXGI_FORMAT D3D11FrameAllocator::ConverColortFormat(mfxU32 fourcc)
|
||||
{
|
||||
switch (fourcc)
|
||||
{
|
||||
case MFX_FOURCC_NV12:
|
||||
return DXGI_FORMAT_NV12;
|
||||
|
||||
case MFX_FOURCC_YUY2:
|
||||
return DXGI_FORMAT_YUY2;
|
||||
|
||||
case MFX_FOURCC_RGB4:
|
||||
return DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
|
||||
case MFX_FOURCC_P8:
|
||||
case MFX_FOURCC_P8_TEXTURE:
|
||||
return DXGI_FORMAT_P8;
|
||||
|
||||
case MFX_FOURCC_ARGB16:
|
||||
case MFX_FOURCC_ABGR16:
|
||||
return DXGI_FORMAT_R16G16B16A16_UNORM;
|
||||
|
||||
case MFX_FOURCC_P010:
|
||||
return DXGI_FORMAT_P010;
|
||||
|
||||
case MFX_FOURCC_A2RGB10:
|
||||
return DXGI_FORMAT_R10G10B10A2_UNORM;
|
||||
|
||||
case DXGI_FORMAT_AYUV:
|
||||
case MFX_FOURCC_AYUV:
|
||||
return DXGI_FORMAT_AYUV;
|
||||
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case MFX_FOURCC_Y210:
|
||||
return DXGI_FORMAT_Y210;
|
||||
case MFX_FOURCC_Y410:
|
||||
return DXGI_FORMAT_Y410;
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_P016:
|
||||
return DXGI_FORMAT_P016;
|
||||
case MFX_FOURCC_Y216:
|
||||
return DXGI_FORMAT_Y216;
|
||||
case MFX_FOURCC_Y416:
|
||||
return DXGI_FORMAT_Y416;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return DXGI_FORMAT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #if MFX_D3D11_SUPPORT
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
395
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d11_device.cpp
vendored
Normal file
395
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d11_device.cpp
vendored
Normal file
@@ -0,0 +1,395 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include "sample_defs.h"
|
||||
|
||||
#if MFX_D3D11_SUPPORT
|
||||
|
||||
#include "d3d11_device.h"
|
||||
|
||||
CD3D11Device::CD3D11Device():
|
||||
m_nViews(0),
|
||||
m_bDefaultStereoEnabled(FALSE),
|
||||
m_bIsA2rgb10(FALSE),
|
||||
m_HandleWindow(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CD3D11Device::~CD3D11Device()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::FillSCD(mfxHDL hWindow, DXGI_SWAP_CHAIN_DESC& scd)
|
||||
{
|
||||
scd.Windowed = TRUE;
|
||||
scd.OutputWindow = (HWND)hWindow;
|
||||
scd.SampleDesc.Count = 1;
|
||||
scd.BufferDesc.Format = (m_bIsA2rgb10) ? DXGI_FORMAT_R10G10B10A2_UNORM : DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
scd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
scd.BufferCount = 1;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::FillSCD1(DXGI_SWAP_CHAIN_DESC1& scd1)
|
||||
{
|
||||
scd1.Width = 0; // Use automatic sizing.
|
||||
scd1.Height = 0;
|
||||
scd1.Format = (m_bIsA2rgb10) ? DXGI_FORMAT_R10G10B10A2_UNORM : DXGI_FORMAT_B8G8R8A8_UNORM;
|
||||
scd1.Stereo = m_nViews == 2 ? TRUE : FALSE;
|
||||
scd1.SampleDesc.Count = 1; // Don't use multi-sampling.
|
||||
scd1.SampleDesc.Quality = 0;
|
||||
scd1.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
|
||||
scd1.BufferCount = 2; // Use double buffering to minimize latency.
|
||||
scd1.Scaling = DXGI_SCALING_STRETCH;
|
||||
scd1.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
|
||||
scd1.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::Init(
|
||||
mfxHDL hWindow,
|
||||
mfxU16 nViews,
|
||||
mfxU32 nAdapterNum)
|
||||
{
|
||||
m_HandleWindow = (HWND)hWindow;
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
HRESULT hres = S_OK;
|
||||
m_nViews = nViews;
|
||||
if (2 < nViews)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
m_bDefaultStereoEnabled = FALSE;
|
||||
|
||||
static D3D_FEATURE_LEVEL FeatureLevels[] = {
|
||||
D3D_FEATURE_LEVEL_11_1,
|
||||
D3D_FEATURE_LEVEL_11_0,
|
||||
D3D_FEATURE_LEVEL_10_1,
|
||||
D3D_FEATURE_LEVEL_10_0
|
||||
};
|
||||
D3D_FEATURE_LEVEL pFeatureLevelsOut;
|
||||
|
||||
hres = CreateDXGIFactory(__uuidof(IDXGIFactory2), (void**)(&m_pDXGIFactory) );
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
if (m_nViews == 2)
|
||||
{
|
||||
hres = m_pDXGIFactory->QueryInterface(__uuidof(IDXGIDisplayControl), (void **)&m_pDisplayControl);
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
m_bDefaultStereoEnabled = m_pDisplayControl->IsStereoEnabled();
|
||||
if (!m_bDefaultStereoEnabled)
|
||||
m_pDisplayControl->SetStereoEnabled(TRUE);
|
||||
}
|
||||
|
||||
hres = m_pDXGIFactory->EnumAdapters(nAdapterNum,&m_pAdapter);
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
hres = D3D11CreateDevice(m_pAdapter ,
|
||||
D3D_DRIVER_TYPE_UNKNOWN,
|
||||
NULL,
|
||||
0,
|
||||
FeatureLevels,
|
||||
MSDK_ARRAY_LEN(FeatureLevels),
|
||||
D3D11_SDK_VERSION,
|
||||
&m_pD3D11Device,
|
||||
&pFeatureLevelsOut,
|
||||
&m_pD3D11Ctx);
|
||||
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
m_pDXGIDev = m_pD3D11Device;
|
||||
m_pDX11VideoDevice = m_pD3D11Device;
|
||||
m_pVideoContext = m_pD3D11Ctx;
|
||||
|
||||
MSDK_CHECK_POINTER(m_pDXGIDev.p, MFX_ERR_NULL_PTR);
|
||||
MSDK_CHECK_POINTER(m_pDX11VideoDevice.p, MFX_ERR_NULL_PTR);
|
||||
MSDK_CHECK_POINTER(m_pVideoContext.p, MFX_ERR_NULL_PTR);
|
||||
|
||||
// turn on multithreading for the Context
|
||||
CComQIPtr<ID3D10Multithread> p_mt(m_pVideoContext);
|
||||
|
||||
if (p_mt)
|
||||
p_mt->SetMultithreadProtected(true);
|
||||
else
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
// create swap chain only for rendering use case (hWindow != 0)
|
||||
if (hWindow)
|
||||
{
|
||||
MSDK_CHECK_POINTER(m_pDXGIFactory.p, MFX_ERR_NULL_PTR);
|
||||
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
|
||||
|
||||
sts = FillSCD1(swapChainDesc);
|
||||
MSDK_CHECK_STATUS(sts, "FillSCD1 failed");
|
||||
|
||||
hres = m_pDXGIFactory->CreateSwapChainForHwnd(m_pD3D11Device,
|
||||
(HWND)hWindow,
|
||||
&swapChainDesc,
|
||||
NULL,
|
||||
NULL,
|
||||
reinterpret_cast<IDXGISwapChain1**>(&m_pSwapChain));
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::CreateVideoProcessor(mfxFrameSurface1 * pSrf)
|
||||
{
|
||||
HRESULT hres = S_OK;
|
||||
|
||||
if (m_VideoProcessorEnum.p || NULL == pSrf)
|
||||
return MFX_ERR_NONE;
|
||||
|
||||
//create video processor
|
||||
D3D11_VIDEO_PROCESSOR_CONTENT_DESC ContentDesc;
|
||||
MSDK_ZERO_MEMORY( ContentDesc );
|
||||
|
||||
ContentDesc.InputFrameFormat = D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE;
|
||||
ContentDesc.InputFrameRate.Numerator = 30000;
|
||||
ContentDesc.InputFrameRate.Denominator = 1000;
|
||||
ContentDesc.InputWidth = pSrf->Info.CropW;
|
||||
ContentDesc.InputHeight = pSrf->Info.CropH;
|
||||
ContentDesc.OutputWidth = pSrf->Info.CropW;
|
||||
ContentDesc.OutputHeight = pSrf->Info.CropH;
|
||||
ContentDesc.OutputFrameRate.Numerator = 30000;
|
||||
ContentDesc.OutputFrameRate.Denominator = 1000;
|
||||
|
||||
ContentDesc.Usage = D3D11_VIDEO_USAGE_PLAYBACK_NORMAL;
|
||||
|
||||
hres = m_pDX11VideoDevice->CreateVideoProcessorEnumerator( &ContentDesc, &m_VideoProcessorEnum );
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
hres = m_pDX11VideoDevice->CreateVideoProcessor( m_VideoProcessorEnum, 0, &m_pVideoProcessor );
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::Reset()
|
||||
{
|
||||
// Changing video mode back to the original state
|
||||
if (2 == m_nViews && !m_bDefaultStereoEnabled)
|
||||
m_pDisplayControl->SetStereoEnabled(FALSE);
|
||||
|
||||
MSDK_CHECK_POINTER (m_pDXGIFactory.p, MFX_ERR_NULL_PTR);
|
||||
DXGI_SWAP_CHAIN_DESC1 swapChainDesc = {0};
|
||||
|
||||
mfxStatus sts = FillSCD1(swapChainDesc);
|
||||
MSDK_CHECK_STATUS(sts, "FillSCD1 failed");
|
||||
|
||||
HRESULT hres = S_OK;
|
||||
hres = m_pDXGIFactory->CreateSwapChainForHwnd(m_pD3D11Device,
|
||||
(HWND)m_HandleWindow,
|
||||
&swapChainDesc,
|
||||
NULL,
|
||||
NULL,
|
||||
reinterpret_cast<IDXGISwapChain1**>(&m_pSwapChain));
|
||||
|
||||
if (FAILED(hres))
|
||||
{
|
||||
if (swapChainDesc.Stereo)
|
||||
{
|
||||
MSDK_PRINT_RET_MSG(MFX_ERR_DEVICE_FAILED,"Cannot create swap chain required for rendering. Possibly stereo mode is not supported.");
|
||||
}
|
||||
else
|
||||
{
|
||||
MSDK_PRINT_RET_MSG(MFX_ERR_DEVICE_FAILED, "Cannot create swap chain required for rendering.");
|
||||
}
|
||||
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::GetHandle(mfxHandleType type, mfxHDL *pHdl)
|
||||
{
|
||||
if (MFX_HANDLE_D3D11_DEVICE == type)
|
||||
{
|
||||
*pHdl = m_pD3D11Device.p;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::SetHandle(mfxHandleType type, mfxHDL hdl)
|
||||
{
|
||||
if (MFX_HANDLE_DEVICEWINDOW == type && hdl != NULL) //for render window handle
|
||||
{
|
||||
m_HandleWindow = (HWND)hdl;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CD3D11Device::RenderFrame(mfxFrameSurface1 * pSrf, mfxFrameAllocator * pAlloc)
|
||||
{
|
||||
HRESULT hres = S_OK;
|
||||
mfxStatus sts;
|
||||
|
||||
sts = CreateVideoProcessor(pSrf);
|
||||
MSDK_CHECK_STATUS(sts, "CreateVideoProcessor failed");
|
||||
|
||||
hres = m_pSwapChain->GetBuffer(0, __uuidof( ID3D11Texture2D ), (void**)&m_pDXGIBackBuffer.p);
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
D3D11_VIDEO_PROCESSOR_OUTPUT_VIEW_DESC OutputViewDesc;
|
||||
if (2 == m_nViews)
|
||||
{
|
||||
m_pVideoContext->VideoProcessorSetStreamStereoFormat(m_pVideoProcessor, 0, TRUE,D3D11_VIDEO_PROCESSOR_STEREO_FORMAT_SEPARATE,
|
||||
TRUE, TRUE, D3D11_VIDEO_PROCESSOR_STEREO_FLIP_NONE, NULL);
|
||||
m_pVideoContext->VideoProcessorSetOutputStereoMode(m_pVideoProcessor,TRUE);
|
||||
|
||||
OutputViewDesc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2DARRAY;
|
||||
OutputViewDesc.Texture2DArray.ArraySize = 2;
|
||||
OutputViewDesc.Texture2DArray.MipSlice = 0;
|
||||
OutputViewDesc.Texture2DArray.FirstArraySlice = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
OutputViewDesc.ViewDimension = D3D11_VPOV_DIMENSION_TEXTURE2D;
|
||||
OutputViewDesc.Texture2D.MipSlice = 0;
|
||||
}
|
||||
|
||||
if (1 == m_nViews || 0 == pSrf->Info.FrameId.ViewId)
|
||||
{
|
||||
hres = m_pDX11VideoDevice->CreateVideoProcessorOutputView(
|
||||
m_pDXGIBackBuffer,
|
||||
m_VideoProcessorEnum,
|
||||
&OutputViewDesc,
|
||||
&m_pOutputView.p );
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
D3D11_VIDEO_PROCESSOR_INPUT_VIEW_DESC InputViewDesc;
|
||||
InputViewDesc.FourCC = 0;
|
||||
InputViewDesc.ViewDimension = D3D11_VPIV_DIMENSION_TEXTURE2D;
|
||||
InputViewDesc.Texture2D.MipSlice = 0;
|
||||
InputViewDesc.Texture2D.ArraySlice = 0;
|
||||
|
||||
mfxHDLPair pair = {NULL};
|
||||
sts = pAlloc->GetHDL(pAlloc->pthis, pSrf->Data.MemId, (mfxHDL*)&pair);
|
||||
MSDK_CHECK_STATUS(sts, "pAlloc->GetHDL failed");
|
||||
|
||||
ID3D11Texture2D *pRTTexture2D = reinterpret_cast<ID3D11Texture2D*>(pair.first);
|
||||
D3D11_TEXTURE2D_DESC RTTexture2DDesc;
|
||||
|
||||
if(!m_pTempTexture && m_nViews == 2)
|
||||
{
|
||||
pRTTexture2D->GetDesc(&RTTexture2DDesc);
|
||||
hres = m_pD3D11Device->CreateTexture2D(&RTTexture2DDesc,NULL,&m_pTempTexture.p);
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
// Creating input views for left and righ eyes
|
||||
if (1 == m_nViews)
|
||||
{
|
||||
hres = m_pDX11VideoDevice->CreateVideoProcessorInputView(
|
||||
pRTTexture2D,
|
||||
m_VideoProcessorEnum,
|
||||
&InputViewDesc,
|
||||
&m_pInputViewLeft.p );
|
||||
|
||||
}
|
||||
else if (2 == m_nViews && 0 == pSrf->Info.FrameId.ViewId)
|
||||
{
|
||||
m_pD3D11Ctx->CopyResource(m_pTempTexture,pRTTexture2D);
|
||||
hres = m_pDX11VideoDevice->CreateVideoProcessorInputView(
|
||||
m_pTempTexture,
|
||||
m_VideoProcessorEnum,
|
||||
&InputViewDesc,
|
||||
&m_pInputViewLeft.p );
|
||||
}
|
||||
else
|
||||
{
|
||||
hres = m_pDX11VideoDevice->CreateVideoProcessorInputView(
|
||||
pRTTexture2D,
|
||||
m_VideoProcessorEnum,
|
||||
&InputViewDesc,
|
||||
&m_pInputViewRight.p );
|
||||
}
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
// NV12 surface to RGB backbuffer
|
||||
RECT rect = {0};
|
||||
rect.right = pSrf->Info.CropW;
|
||||
rect.bottom = pSrf->Info.CropH;
|
||||
|
||||
D3D11_VIDEO_PROCESSOR_STREAM StreamData;
|
||||
|
||||
if (1 == m_nViews || pSrf->Info.FrameId.ViewId == 1)
|
||||
{
|
||||
StreamData.Enable = TRUE;
|
||||
StreamData.OutputIndex = 0;
|
||||
StreamData.InputFrameOrField = 0;
|
||||
StreamData.PastFrames = 0;
|
||||
StreamData.FutureFrames = 0;
|
||||
StreamData.ppPastSurfaces = NULL;
|
||||
StreamData.ppFutureSurfaces = NULL;
|
||||
StreamData.pInputSurface = m_pInputViewLeft;
|
||||
StreamData.ppPastSurfacesRight = NULL;
|
||||
StreamData.ppFutureSurfacesRight = NULL;
|
||||
StreamData.pInputSurfaceRight = m_nViews == 2 ? m_pInputViewRight : NULL;
|
||||
|
||||
m_pVideoContext->VideoProcessorSetStreamSourceRect(m_pVideoProcessor, 0, true, &rect);
|
||||
m_pVideoContext->VideoProcessorSetStreamFrameFormat( m_pVideoProcessor, 0, D3D11_VIDEO_FRAME_FORMAT_PROGRESSIVE);
|
||||
hres = m_pVideoContext->VideoProcessorBlt( m_pVideoProcessor, m_pOutputView, 0, 1, &StreamData );
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
if (1 == m_nViews || 1 == pSrf->Info.FrameId.ViewId)
|
||||
{
|
||||
DXGI_PRESENT_PARAMETERS parameters = {0};
|
||||
hres = m_pSwapChain->Present1(0, 0, ¶meters);
|
||||
if (FAILED(hres))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void CD3D11Device::Close()
|
||||
{
|
||||
// Changing video mode back to the original state
|
||||
if (2 == m_nViews && !m_bDefaultStereoEnabled)
|
||||
m_pDisplayControl->SetStereoEnabled(FALSE);
|
||||
|
||||
m_HandleWindow = NULL;
|
||||
}
|
||||
|
||||
#endif // #if MFX_D3D11_SUPPORT
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
475
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d_allocator.cpp
vendored
Normal file
475
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d_allocator.cpp
vendored
Normal file
@@ -0,0 +1,475 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
#include "sample_defs.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <objbase.h>
|
||||
#include <initguid.h>
|
||||
#include <assert.h>
|
||||
#include <d3d9.h>
|
||||
|
||||
#include "d3d_allocator.h"
|
||||
|
||||
#define D3DFMT_NV12 (D3DFORMAT)MAKEFOURCC('N','V','1','2')
|
||||
#define D3DFMT_YV12 (D3DFORMAT)MAKEFOURCC('Y','V','1','2')
|
||||
#define D3DFMT_NV16 (D3DFORMAT)MAKEFOURCC('N','V','1','6')
|
||||
#define D3DFMT_P010 (D3DFORMAT)MAKEFOURCC('P','0','1','0')
|
||||
#define D3DFMT_P210 (D3DFORMAT)MAKEFOURCC('P','2','1','0')
|
||||
#define D3DFMT_IMC3 (D3DFORMAT)MAKEFOURCC('I','M','C','3')
|
||||
#define D3DFMT_AYUV (D3DFORMAT)MAKEFOURCC('A','Y','U','V')
|
||||
#if (MFX_VERSION >= 1027)
|
||||
#define D3DFMT_Y210 (D3DFORMAT)MAKEFOURCC('Y','2','1','0')
|
||||
#define D3DFMT_Y410 (D3DFORMAT)MAKEFOURCC('Y','4','1','0')
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
#define D3DFMT_P016 (D3DFORMAT)MAKEFOURCC('P','0','1','6')
|
||||
#define D3DFMT_Y216 (D3DFORMAT)MAKEFOURCC('Y','2','1','6')
|
||||
#define D3DFMT_Y416 (D3DFORMAT)MAKEFOURCC('Y','4','1','6')
|
||||
#endif
|
||||
|
||||
#define MFX_FOURCC_IMC3 (MFX_MAKEFOURCC('I','M','C','3')) // This line should be moved into mfxstructures.h in new API version
|
||||
|
||||
D3DFORMAT ConvertMfxFourccToD3dFormat(mfxU32 fourcc)
|
||||
{
|
||||
switch (fourcc)
|
||||
{
|
||||
case MFX_FOURCC_NV12:
|
||||
return D3DFMT_NV12;
|
||||
case MFX_FOURCC_YV12:
|
||||
return D3DFMT_YV12;
|
||||
case MFX_FOURCC_NV16:
|
||||
return D3DFMT_NV16;
|
||||
case MFX_FOURCC_YUY2:
|
||||
return D3DFMT_YUY2;
|
||||
case MFX_FOURCC_RGB3:
|
||||
return D3DFMT_R8G8B8;
|
||||
case MFX_FOURCC_RGB4:
|
||||
return D3DFMT_A8R8G8B8;
|
||||
case MFX_FOURCC_P8:
|
||||
return D3DFMT_P8;
|
||||
case MFX_FOURCC_P010:
|
||||
return D3DFMT_P010;
|
||||
case MFX_FOURCC_AYUV:
|
||||
return D3DFMT_AYUV;
|
||||
case MFX_FOURCC_P210:
|
||||
return D3DFMT_P210;
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case MFX_FOURCC_Y210:
|
||||
return D3DFMT_Y210;
|
||||
case MFX_FOURCC_Y410:
|
||||
return D3DFMT_Y410;
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_P016:
|
||||
return D3DFMT_P016;
|
||||
case MFX_FOURCC_Y216:
|
||||
return D3DFMT_Y216;
|
||||
case MFX_FOURCC_Y416:
|
||||
return D3DFMT_Y416;
|
||||
#endif
|
||||
case MFX_FOURCC_A2RGB10:
|
||||
return D3DFMT_A2R10G10B10;
|
||||
case MFX_FOURCC_ABGR16:
|
||||
case MFX_FOURCC_ARGB16:
|
||||
return D3DFMT_A16B16G16R16;
|
||||
case MFX_FOURCC_IMC3:
|
||||
return D3DFMT_IMC3;
|
||||
default:
|
||||
return D3DFMT_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
D3DFrameAllocator::D3DFrameAllocator()
|
||||
: m_decoderService(0), m_processorService(0), m_hDecoder(0), m_hProcessor(0), m_manager(0), m_surfaceUsage(0)
|
||||
{
|
||||
}
|
||||
|
||||
D3DFrameAllocator::~D3DFrameAllocator()
|
||||
{
|
||||
Close();
|
||||
for (unsigned i = 0; i < m_midsAllocated.size(); i++)
|
||||
MSDK_SAFE_FREE(m_midsAllocated[i]);
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::Init(mfxAllocatorParams *pParams)
|
||||
{
|
||||
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)
|
||||
{
|
||||
m_manager->CloseDeviceHandle(m_hDecoder);
|
||||
m_manager = 0;
|
||||
m_hDecoder = 0;
|
||||
}
|
||||
|
||||
if (m_manager && m_hProcessor)
|
||||
{
|
||||
m_manager->CloseDeviceHandle(m_hProcessor);
|
||||
m_manager = 0;
|
||||
m_hProcessor = 0;
|
||||
}
|
||||
|
||||
return BaseFrameAllocator::Close();
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (!ptr || !mid)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
mfxHDLPair *dxmid = (mfxHDLPair*)mid;
|
||||
IDirect3DSurface9 *pSurface = static_cast<IDirect3DSurface9*>(dxmid->first);
|
||||
if (pSurface == 0)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
D3DSURFACE_DESC desc;
|
||||
HRESULT hr = pSurface->GetDesc(&desc);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
if (desc.Format != D3DFMT_NV12 &&
|
||||
desc.Format != D3DFMT_YV12 &&
|
||||
desc.Format != D3DFMT_YUY2 &&
|
||||
desc.Format != D3DFMT_R8G8B8 &&
|
||||
desc.Format != D3DFMT_A8R8G8B8 &&
|
||||
desc.Format != D3DFMT_P8 &&
|
||||
desc.Format != D3DFMT_P010 &&
|
||||
desc.Format != D3DFMT_A2R10G10B10 &&
|
||||
desc.Format != D3DFMT_A16B16G16R16 &&
|
||||
desc.Format != D3DFMT_IMC3 &&
|
||||
desc.Format != D3DFMT_AYUV
|
||||
#if (MFX_VERSION >= 1027)
|
||||
&& desc.Format != D3DFMT_Y210
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
&& desc.Format != D3DFMT_P016
|
||||
&& desc.Format != D3DFMT_Y216
|
||||
&& desc.Format != D3DFMT_Y410
|
||||
&& desc.Format != D3DFMT_Y416
|
||||
#endif
|
||||
)
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
D3DLOCKED_RECT locked;
|
||||
|
||||
hr = pSurface->LockRect(&locked, 0, D3DLOCK_NOSYSLOCK);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
switch ((DWORD)desc.Format)
|
||||
{
|
||||
case D3DFMT_NV12:
|
||||
case D3DFMT_P010:
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case D3DFMT_P016:
|
||||
#endif
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->Y = (mfxU8 *)locked.pBits;
|
||||
ptr->U = (mfxU8 *)locked.pBits + desc.Height * locked.Pitch;
|
||||
ptr->V = (desc.Format == D3DFMT_P010) ? ptr->U + 2 : ptr->U + 1;
|
||||
break;
|
||||
case D3DFMT_YV12:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
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->U = ptr->Y + 1;
|
||||
ptr->V = ptr->Y + 3;
|
||||
break;
|
||||
case D3DFMT_R8G8B8:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->B = (mfxU8 *)locked.pBits;
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
break;
|
||||
case D3DFMT_A8R8G8B8:
|
||||
case D3DFMT_A2R10G10B10:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
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->U = 0;
|
||||
ptr->V = 0;
|
||||
break;
|
||||
case D3DFMT_A16B16G16R16:
|
||||
ptr->V16 = (mfxU16*)locked.pBits;
|
||||
ptr->U16 = ptr->V16 + 1;
|
||||
ptr->Y16 = ptr->V16 + 2;
|
||||
ptr->A = (mfxU8*)(ptr->V16 + 3);
|
||||
ptr->PitchHigh = (mfxU16)((mfxU32)locked.Pitch / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((mfxU32)locked.Pitch % (1 << 16));
|
||||
break;
|
||||
case D3DFMT_IMC3:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->Y = (mfxU8 *)locked.pBits;
|
||||
ptr->V = ptr->Y + desc.Height * locked.Pitch;
|
||||
ptr->U = ptr->Y + desc.Height * locked.Pitch *2;
|
||||
break;
|
||||
case D3DFMT_AYUV:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->V = (mfxU8 *)locked.pBits;
|
||||
ptr->U = ptr->V + 1;
|
||||
ptr->Y = ptr->V + 2;
|
||||
ptr->A = ptr->V + 3;
|
||||
break;
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case D3DFMT_Y416:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->U16 = (mfxU16*)locked.pBits;
|
||||
ptr->Y16 = ptr->U16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 1;
|
||||
ptr->A = (mfxU8 *)(ptr->V16 + 1);
|
||||
break;
|
||||
case D3DFMT_Y216:
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case D3DFMT_Y210:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->Y16 = (mfxU16 *)locked.pBits;
|
||||
ptr->U16 = ptr->Y16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 3;
|
||||
break;
|
||||
case D3DFMT_Y410:
|
||||
ptr->Pitch = (mfxU16)locked.Pitch;
|
||||
ptr->Y410 = (mfxY410 *)locked.pBits;
|
||||
ptr->Y = 0;
|
||||
ptr->V = 0;
|
||||
ptr->A = 0;
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (!mid)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
mfxHDLPair *dxmid = (mfxHDLPair*)mid;
|
||||
IDirect3DSurface9 *pSurface = static_cast<IDirect3DSurface9*>(dxmid->first);
|
||||
if (pSurface == 0)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
pSurface->UnlockRect();
|
||||
|
||||
if (NULL != ptr)
|
||||
{
|
||||
ptr->Pitch = 0;
|
||||
ptr->Y = 0;
|
||||
ptr->U = 0;
|
||||
ptr->V = 0;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL * handle)
|
||||
{
|
||||
if (!mid || !handle)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
mfxHDLPair *dxMid = (mfxHDLPair*)mid;
|
||||
*handle = dxMid->first;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
|
||||
{
|
||||
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
if ((request->Type & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) != 0)
|
||||
return MFX_ERR_NONE;
|
||||
else
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
|
||||
{
|
||||
if (!response)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
if (response->mids) {
|
||||
for (mfxU32 i = 0; i < response->NumFrameActual; i++) {
|
||||
if (response->mids[i]) {
|
||||
mfxHDLPair *dxMids = (mfxHDLPair*)response->mids[i];
|
||||
if (dxMids->first)
|
||||
{
|
||||
static_cast<IDirect3DSurface9*>(dxMids->first)->Release();
|
||||
}
|
||||
MSDK_SAFE_FREE(dxMids);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::ReallocImpl(mfxMemId /*mid*/, const mfxFrameInfo *info, mfxU16 /*memType*/, mfxMemId *midOut)
|
||||
{
|
||||
if (!info || !midOut)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
//TODO: Need add implementation in the future.
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus D3DFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
HRESULT hr;
|
||||
|
||||
MSDK_CHECK_POINTER(request, MFX_ERR_NULL_PTR);
|
||||
if (request->NumFrameSuggested == 0)
|
||||
return MFX_ERR_UNKNOWN;
|
||||
|
||||
D3DFORMAT format = ConvertMfxFourccToD3dFormat(request->Info.FourCC);
|
||||
|
||||
if (format == D3DFMT_UNKNOWN)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("D3D Allocator: invalid fourcc is provided (%#X), exitting\n"),request->Info.FourCC);
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
IDirectXVideoAccelerationService* videoService = NULL;
|
||||
|
||||
if (target == DXVA2_VideoProcessorRenderTarget) {
|
||||
if (!m_hProcessor) {
|
||||
hr = m_manager->OpenDeviceHandle(&m_hProcessor);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
hr = m_manager->GetVideoService(m_hProcessor, IID_IDirectXVideoProcessorService, (void**)&m_processorService);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
videoService = m_processorService;
|
||||
}
|
||||
else {
|
||||
if (!m_hDecoder)
|
||||
{
|
||||
hr = m_manager->OpenDeviceHandle(&m_hDecoder);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
hr = m_manager->GetVideoService(m_hDecoder, IID_IDirectXVideoDecoderService, (void**)&m_decoderService);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
videoService = m_decoderService;
|
||||
}
|
||||
|
||||
mfxHDLPair **dxMidPtrs = (mfxHDLPair**)calloc(request->NumFrameSuggested, sizeof(mfxHDLPair*));
|
||||
if (!dxMidPtrs)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
for (int i = 0; i < request->NumFrameSuggested; i++)
|
||||
{
|
||||
dxMidPtrs[i] = (mfxHDLPair*)calloc(1, sizeof(mfxHDLPair));
|
||||
if (!dxMidPtrs[i])
|
||||
{
|
||||
DeallocateMids(dxMidPtrs, i);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
}
|
||||
|
||||
response->mids = (mfxMemId*)dxMidPtrs;
|
||||
response->NumFrameActual = request->NumFrameSuggested;
|
||||
|
||||
if (request->Type & MFX_MEMTYPE_EXTERNAL_FRAME) {
|
||||
for (int i = 0; i < request->NumFrameSuggested; i++) {
|
||||
hr = videoService->CreateSurface(request->Info.Width, request->Info.Height, 0, format,
|
||||
D3DPOOL_DEFAULT, m_surfaceUsage, target, (IDirect3DSurface9**)&dxMidPtrs[i]->first, &dxMidPtrs[i]->second);
|
||||
if (FAILED(hr)) {
|
||||
ReleaseResponse(response);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
std::unique_ptr<IDirect3DSurface9*[]> dxSrf(new (std::nothrow) IDirect3DSurface9*[request->NumFrameSuggested]);
|
||||
if (!dxSrf.get())
|
||||
{
|
||||
DeallocateMids(dxMidPtrs, request->NumFrameSuggested);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
hr = videoService->CreateSurface(request->Info.Width, request->Info.Height, request->NumFrameSuggested - 1, format,
|
||||
D3DPOOL_DEFAULT, m_surfaceUsage, target, dxSrf.get(), NULL);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
DeallocateMids(dxMidPtrs, request->NumFrameSuggested);
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
for (int i = 0; i < request->NumFrameSuggested; i++) {
|
||||
dxMidPtrs[i]->first = dxSrf[i];
|
||||
}
|
||||
}
|
||||
m_midsAllocated.push_back(dxMidPtrs);
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void D3DFrameAllocator::DeallocateMids(mfxHDLPair** pair, int n)
|
||||
{
|
||||
for (int i = 0; i < n; i++)
|
||||
{
|
||||
MSDK_SAFE_FREE(pair[i]);
|
||||
}
|
||||
MSDK_SAFE_FREE(pair);
|
||||
}
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
408
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d_device.cpp
vendored
Normal file
408
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/d3d_device.cpp
vendored
Normal file
@@ -0,0 +1,408 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
#include <algorithm>
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
//prefast singnature used in combaseapi.h
|
||||
#ifndef _PREFAST_
|
||||
#pragma warning(disable:4068)
|
||||
#endif
|
||||
|
||||
#include "d3d_device.h"
|
||||
#include "d3d_allocator.h"
|
||||
#include "sample_defs.h"
|
||||
|
||||
#include "atlbase.h"
|
||||
|
||||
CD3D9Device::CD3D9Device()
|
||||
{
|
||||
m_pD3D9 = NULL;
|
||||
m_pD3DD9 = NULL;
|
||||
m_pDeviceManager9 = NULL;
|
||||
MSDK_ZERO_MEMORY(m_D3DPP);
|
||||
m_resetToken = 0;
|
||||
|
||||
m_nViews = 0;
|
||||
|
||||
MSDK_ZERO_MEMORY(m_backBufferDesc);
|
||||
m_pDXVAVPS = NULL;
|
||||
m_pDXVAVP_Left = NULL;
|
||||
m_pDXVAVP_Right = NULL;
|
||||
|
||||
MSDK_ZERO_MEMORY(m_targetRect);
|
||||
|
||||
MSDK_ZERO_MEMORY(m_VideoDesc);
|
||||
MSDK_ZERO_MEMORY(m_BltParams);
|
||||
MSDK_ZERO_MEMORY(m_Sample);
|
||||
|
||||
// Initialize DXVA structures
|
||||
|
||||
DXVA2_AYUVSample16 color = {
|
||||
0x8000, // Cr
|
||||
0x8000, // Cb
|
||||
0x1000, // Y
|
||||
0xffff // Alpha
|
||||
};
|
||||
|
||||
DXVA2_ExtendedFormat format = { // DestFormat
|
||||
DXVA2_SampleProgressiveFrame, // SampleFormat
|
||||
DXVA2_VideoChromaSubsampling_MPEG2, // VideoChromaSubsampling
|
||||
DXVA_NominalRange_0_255, // NominalRange
|
||||
DXVA2_VideoTransferMatrix_BT709, // VideoTransferMatrix
|
||||
DXVA2_VideoLighting_bright, // VideoLighting
|
||||
DXVA2_VideoPrimaries_BT709, // VideoPrimaries
|
||||
DXVA2_VideoTransFunc_709 // VideoTransferFunction
|
||||
};
|
||||
|
||||
// init m_VideoDesc structure
|
||||
MSDK_MEMCPY_VAR(m_VideoDesc.SampleFormat, &format, sizeof(DXVA2_ExtendedFormat));
|
||||
m_VideoDesc.SampleWidth = 0;
|
||||
m_VideoDesc.SampleHeight = 0;
|
||||
m_VideoDesc.InputSampleFreq.Numerator = 60;
|
||||
m_VideoDesc.InputSampleFreq.Denominator = 1;
|
||||
m_VideoDesc.OutputFrameFreq.Numerator = 60;
|
||||
m_VideoDesc.OutputFrameFreq.Denominator = 1;
|
||||
|
||||
// init m_BltParams structure
|
||||
MSDK_MEMCPY_VAR(m_BltParams.DestFormat, &format, sizeof(DXVA2_ExtendedFormat));
|
||||
MSDK_MEMCPY_VAR(m_BltParams.BackgroundColor, &color, sizeof(DXVA2_AYUVSample16));
|
||||
|
||||
// init m_Sample structure
|
||||
m_Sample.Start = 0;
|
||||
m_Sample.End = 1;
|
||||
m_Sample.SampleFormat = format;
|
||||
m_Sample.PlanarAlpha.Fraction = 0;
|
||||
m_Sample.PlanarAlpha.Value = 1;
|
||||
|
||||
m_bIsA2rgb10 = FALSE;
|
||||
}
|
||||
|
||||
bool CD3D9Device::CheckOverlaySupport()
|
||||
{
|
||||
D3DCAPS9 d3d9caps;
|
||||
D3DOVERLAYCAPS d3doverlaycaps = {0};
|
||||
IDirect3D9ExOverlayExtension *d3d9overlay = NULL;
|
||||
bool overlaySupported = false;
|
||||
|
||||
memset(&d3d9caps, 0, sizeof(d3d9caps));
|
||||
HRESULT hr = m_pD3D9->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &d3d9caps);
|
||||
if (FAILED(hr) || !(d3d9caps.Caps & D3DCAPS_OVERLAY))
|
||||
{
|
||||
overlaySupported = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = m_pD3D9->QueryInterface(IID_PPV_ARGS(&d3d9overlay));
|
||||
if (FAILED(hr) || (d3d9overlay == NULL))
|
||||
{
|
||||
overlaySupported = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
hr = d3d9overlay->CheckDeviceOverlayType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL,
|
||||
m_D3DPP.BackBufferWidth,
|
||||
m_D3DPP.BackBufferHeight,
|
||||
m_D3DPP.BackBufferFormat, NULL,
|
||||
D3DDISPLAYROTATION_IDENTITY, &d3doverlaycaps);
|
||||
MSDK_SAFE_RELEASE(d3d9overlay);
|
||||
|
||||
if (FAILED(hr))
|
||||
{
|
||||
overlaySupported = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlaySupported = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return overlaySupported;
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::FillD3DPP(mfxHDL hWindow, mfxU16 nViews, D3DPRESENT_PARAMETERS &D3DPP)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
D3DPP.Windowed = true;
|
||||
D3DPP.hDeviceWindow = (HWND)hWindow;
|
||||
|
||||
D3DPP.Flags = D3DPRESENTFLAG_VIDEO;
|
||||
D3DPP.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;
|
||||
D3DPP.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE; // note that this setting leads to an implicit timeBeginPeriod call
|
||||
D3DPP.BackBufferCount = 1;
|
||||
D3DPP.BackBufferFormat = (m_bIsA2rgb10) ? D3DFMT_A2R10G10B10 : D3DFMT_X8R8G8B8;
|
||||
|
||||
if (hWindow)
|
||||
{
|
||||
RECT r;
|
||||
GetClientRect((HWND)hWindow, &r);
|
||||
int x = GetSystemMetrics(SM_CXSCREEN);
|
||||
int y = GetSystemMetrics(SM_CYSCREEN);
|
||||
D3DPP.BackBufferWidth = std::min<LONG>(r.right - r.left, x);
|
||||
D3DPP.BackBufferHeight = std::min<LONG>(r.bottom - r.top, y);
|
||||
}
|
||||
else
|
||||
{
|
||||
D3DPP.BackBufferWidth = GetSystemMetrics(SM_CYSCREEN);
|
||||
D3DPP.BackBufferHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
//
|
||||
// Mark the back buffer lockable if software DXVA2 could be used.
|
||||
// This is because software DXVA2 device requires a lockable render target
|
||||
// for the optimal performance.
|
||||
//
|
||||
{
|
||||
D3DPP.Flags |= D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;
|
||||
}
|
||||
|
||||
bool isOverlaySupported = CheckOverlaySupport();
|
||||
if (2 == nViews && !isOverlaySupported)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
bool needOverlay = (2 == nViews) ? true : false;
|
||||
|
||||
D3DPP.SwapEffect = needOverlay ? D3DSWAPEFFECT_OVERLAY : D3DSWAPEFFECT_DISCARD;
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::Init(
|
||||
mfxHDL hWindow,
|
||||
mfxU16 nViews,
|
||||
mfxU32 nAdapterNum)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
if (2 < nViews)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
m_nViews = nViews;
|
||||
|
||||
HRESULT hr = Direct3DCreate9Ex(D3D_SDK_VERSION, &m_pD3D9);
|
||||
if (!m_pD3D9 || FAILED(hr))
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
|
||||
ZeroMemory(&m_D3DPP, sizeof(m_D3DPP));
|
||||
sts = FillD3DPP(hWindow, nViews, m_D3DPP);
|
||||
MSDK_CHECK_STATUS(sts, "FillD3DPP failed");
|
||||
|
||||
hr = m_pD3D9->CreateDeviceEx(
|
||||
nAdapterNum,
|
||||
D3DDEVTYPE_HAL,
|
||||
(HWND)hWindow,
|
||||
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
|
||||
&m_D3DPP,
|
||||
NULL,
|
||||
&m_pD3DD9);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
if(hWindow)
|
||||
{
|
||||
hr = m_pD3DD9->ResetEx(&m_D3DPP, NULL);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
hr = m_pD3DD9->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, 0), 1.0f, 0);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
UINT resetToken = 0;
|
||||
|
||||
hr = DXVA2CreateDirect3DDeviceManager9(&resetToken, &m_pDeviceManager9);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
hr = m_pDeviceManager9->ResetDevice(m_pD3DD9, resetToken);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
m_resetToken = resetToken;
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::Reset()
|
||||
{
|
||||
HRESULT hr = NO_ERROR;
|
||||
MSDK_CHECK_POINTER(m_pD3DD9, MFX_ERR_NULL_PTR);
|
||||
|
||||
if (m_D3DPP.hDeviceWindow)
|
||||
{
|
||||
RECT r;
|
||||
hr = GetClientRect((HWND)m_D3DPP.hDeviceWindow, &r);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
int x = GetSystemMetrics(SM_CXSCREEN);
|
||||
int y = GetSystemMetrics(SM_CYSCREEN);
|
||||
m_D3DPP.BackBufferWidth = std::min<LONG>(r.right - r.left, x);
|
||||
m_D3DPP.BackBufferHeight = std::min<LONG>(r.bottom - r.top, y);
|
||||
|
||||
// Reset will change the parameters, so use a copy instead.
|
||||
D3DPRESENT_PARAMETERS d3dpp = m_D3DPP;
|
||||
hr = m_pD3DD9->ResetEx(&d3dpp, NULL);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_D3DPP.BackBufferWidth = GetSystemMetrics(SM_CXSCREEN);
|
||||
m_D3DPP.BackBufferHeight = GetSystemMetrics(SM_CYSCREEN);
|
||||
}
|
||||
|
||||
hr = m_pDeviceManager9->ResetDevice(m_pD3DD9, m_resetToken);
|
||||
if (FAILED(hr))
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void CD3D9Device::Close()
|
||||
{
|
||||
MSDK_SAFE_RELEASE(m_pDXVAVP_Left);
|
||||
MSDK_SAFE_RELEASE(m_pDXVAVP_Right);
|
||||
MSDK_SAFE_RELEASE(m_pDXVAVPS);
|
||||
|
||||
MSDK_SAFE_RELEASE(m_pDeviceManager9);
|
||||
MSDK_SAFE_RELEASE(m_pD3DD9);
|
||||
MSDK_SAFE_RELEASE(m_pD3D9);
|
||||
}
|
||||
|
||||
CD3D9Device::~CD3D9Device()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::GetHandle(mfxHandleType type, mfxHDL *pHdl)
|
||||
{
|
||||
if (MFX_HANDLE_DIRECT3D_DEVICE_MANAGER9 == type && pHdl != NULL)
|
||||
{
|
||||
*pHdl = m_pDeviceManager9;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::SetHandle(mfxHandleType type, mfxHDL hdl)
|
||||
{
|
||||
if (MFX_HANDLE_DEVICEWINDOW == type && hdl != NULL) //for render window handle
|
||||
{
|
||||
m_D3DPP.hDeviceWindow = (HWND)hdl;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc)
|
||||
{
|
||||
HRESULT hr = S_OK;
|
||||
|
||||
// Rendering of MVC is not supported
|
||||
if (2 == m_nViews)
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
MSDK_CHECK_POINTER(pSurface, MFX_ERR_NULL_PTR);
|
||||
MSDK_CHECK_POINTER(m_pDeviceManager9, MFX_ERR_NOT_INITIALIZED);
|
||||
MSDK_CHECK_POINTER(pmfxAlloc, MFX_ERR_NULL_PTR);
|
||||
|
||||
hr = m_pD3DD9->TestCooperativeLevel();
|
||||
|
||||
switch (hr)
|
||||
{
|
||||
case D3D_OK :
|
||||
break;
|
||||
|
||||
case D3DERR_DEVICELOST :
|
||||
{
|
||||
return MFX_ERR_DEVICE_LOST;
|
||||
}
|
||||
|
||||
case D3DERR_DEVICENOTRESET :
|
||||
{
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
default :
|
||||
{
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
CComPtr<IDirect3DSurface9> pBackBuffer;
|
||||
hr = m_pD3DD9->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &pBackBuffer);
|
||||
|
||||
mfxHDLPair* dxMemId = (mfxHDLPair*)pSurface->Data.MemId;
|
||||
|
||||
hr = m_pD3DD9->StretchRect((IDirect3DSurface9*)dxMemId->first, NULL, pBackBuffer, NULL, D3DTEXF_LINEAR);
|
||||
if (FAILED(hr))
|
||||
{
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = m_pD3DD9->Present(NULL, NULL, NULL, NULL);
|
||||
}
|
||||
|
||||
return SUCCEEDED(hr) ? MFX_ERR_NONE : MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
mfxStatus CD3D9Device::CreateVideoProcessors()
|
||||
{
|
||||
if (2 == m_nViews)
|
||||
return MFX_ERR_UNDEFINED_BEHAVIOR;
|
||||
|
||||
MSDK_SAFE_RELEASE(m_pDXVAVP_Left);
|
||||
MSDK_SAFE_RELEASE(m_pDXVAVP_Right);
|
||||
|
||||
HRESULT hr ;
|
||||
|
||||
ZeroMemory(&m_backBufferDesc, sizeof(m_backBufferDesc));
|
||||
IDirect3DSurface9 *backBufferTmp = NULL;
|
||||
hr = m_pD3DD9->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backBufferTmp);
|
||||
if (NULL != backBufferTmp)
|
||||
backBufferTmp->GetDesc(&m_backBufferDesc);
|
||||
MSDK_SAFE_RELEASE(backBufferTmp);
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
// Create DXVA2 Video Processor Service.
|
||||
hr = DXVA2CreateVideoService(m_pD3DD9,
|
||||
IID_IDirectXVideoProcessorService,
|
||||
(void**)&m_pDXVAVPS);
|
||||
}
|
||||
|
||||
if (SUCCEEDED(hr))
|
||||
{
|
||||
hr = m_pDXVAVPS->CreateVideoProcessor(DXVA2_VideoProcProgressiveDevice,
|
||||
&m_VideoDesc,
|
||||
m_D3DPP.BackBufferFormat,
|
||||
1,
|
||||
&m_pDXVAVP_Right);
|
||||
}
|
||||
|
||||
return SUCCEEDED(hr) ? MFX_ERR_NONE : MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
#endif // #if defined(WIN32) || defined(WIN64)
|
||||
362
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/decode_render.cpp
vendored
Normal file
362
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/decode_render.cpp
vendored
Normal file
@@ -0,0 +1,362 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include <windowsx.h>
|
||||
#include <dwmapi.h>
|
||||
#include <mmsystem.h>
|
||||
|
||||
#include "sample_defs.h"
|
||||
#include "decode_render.h"
|
||||
#include "winUser.h"
|
||||
#pragma warning(disable : 4100)
|
||||
|
||||
bool CDecodeD3DRender::m_bIsMonitorFound = false;
|
||||
|
||||
LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
#ifdef _WIN64
|
||||
CDecodeD3DRender* pRender = (CDecodeD3DRender*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
|
||||
#else
|
||||
CDecodeD3DRender* pRender = (CDecodeD3DRender*)LongToPtr(GetWindowLongPtr(hWnd, GWL_USERDATA));
|
||||
#endif
|
||||
if (pRender)
|
||||
{
|
||||
switch(message)
|
||||
{
|
||||
HANDLE_MSG(hWnd, WM_DESTROY, pRender->OnDestroy);
|
||||
HANDLE_MSG(hWnd, WM_KEYUP, pRender->OnKey);
|
||||
}
|
||||
}
|
||||
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
CDecodeD3DRender::CDecodeD3DRender()
|
||||
{
|
||||
m_bDwmEnabled = false;
|
||||
m_nMonitorCurrent = 0;
|
||||
|
||||
m_hwdev = NULL;
|
||||
MSDK_ZERO_MEMORY(m_sWindowParams);
|
||||
m_Hwnd = 0;
|
||||
MSDK_ZERO_MEMORY(m_rect);
|
||||
m_style = 0;
|
||||
|
||||
MSDK_ZERO_MEMORY(shiftedSurface);
|
||||
MSDK_ZERO_MEMORY(shiftSurfaceResponse);
|
||||
pAllocator=NULL;
|
||||
}
|
||||
|
||||
BOOL CALLBACK CDecodeD3DRender::MonitorEnumProc(HMONITOR /*hMonitor*/,
|
||||
HDC /*hdcMonitor*/,
|
||||
LPRECT lprcMonitor,
|
||||
LPARAM dwData)
|
||||
{
|
||||
CDecodeD3DRender * pRender = reinterpret_cast<CDecodeD3DRender *>(dwData);
|
||||
RECT r = {0};
|
||||
if (NULL == lprcMonitor)
|
||||
lprcMonitor = &r;
|
||||
|
||||
if (pRender->m_nMonitorCurrent++ == pRender->m_sWindowParams.nAdapter)
|
||||
{
|
||||
pRender->m_RectWindow = *lprcMonitor;
|
||||
m_bIsMonitorFound = true;
|
||||
}
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
CDecodeD3DRender::~CDecodeD3DRender()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void CDecodeD3DRender::Close()
|
||||
{
|
||||
if (m_Hwnd)
|
||||
{
|
||||
DestroyWindow(m_Hwnd);
|
||||
m_Hwnd=NULL;
|
||||
}
|
||||
|
||||
if(pAllocator)
|
||||
{
|
||||
pAllocator->Free(pAllocator->pthis,&shiftSurfaceResponse);
|
||||
pAllocator=NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
mfxStatus CDecodeD3DRender::Init(sWindowParams pWParams)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
// window part
|
||||
m_sWindowParams = pWParams;
|
||||
|
||||
WNDCLASS window;
|
||||
MSDK_ZERO_MEMORY(window);
|
||||
|
||||
window.lpfnWndProc= (WNDPROC)WindowProc;
|
||||
window.hInstance= GetModuleHandle(NULL);
|
||||
window.hCursor= LoadCursor(NULL, IDC_ARROW);
|
||||
window.lpszClassName= m_sWindowParams.lpClassName;
|
||||
|
||||
if (!RegisterClass(&window))
|
||||
return MFX_ERR_UNKNOWN;
|
||||
|
||||
EnumDisplayMonitors(NULL, NULL, &CDecodeD3DRender::MonitorEnumProc, (LPARAM)this);
|
||||
if(!m_bIsMonitorFound)
|
||||
return MFX_ERR_NOT_FOUND;
|
||||
|
||||
::RECT displayRegion = {CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT};
|
||||
|
||||
//right and bottom fields consist of width and height values of displayed reqion
|
||||
if (0 != m_sWindowParams.nx )
|
||||
{
|
||||
displayRegion.right = (m_RectWindow.right - m_RectWindow.left) / m_sWindowParams.nx;
|
||||
displayRegion.bottom = (m_RectWindow.bottom - m_RectWindow.top) / m_sWindowParams.ny;
|
||||
displayRegion.left = displayRegion.right * (m_sWindowParams.ncell % m_sWindowParams.nx) + m_RectWindow.left;
|
||||
displayRegion.top = displayRegion.bottom * (m_sWindowParams.ncell / m_sWindowParams.nx) + m_RectWindow.top;
|
||||
}
|
||||
else
|
||||
{
|
||||
displayRegion.right = pWParams.nWidth;
|
||||
displayRegion.bottom = pWParams.nHeight;
|
||||
displayRegion.left = m_RectWindow.left;
|
||||
displayRegion.top= m_RectWindow.top;
|
||||
}
|
||||
|
||||
//no title window style if required
|
||||
DWORD dwStyle = NULL == m_sWindowParams.lpWindowName ? WS_POPUP|WS_BORDER|WS_MAXIMIZE : WS_OVERLAPPEDWINDOW;
|
||||
|
||||
m_Hwnd = CreateWindowEx(NULL,
|
||||
m_sWindowParams.lpClassName,
|
||||
m_sWindowParams.lpWindowName,
|
||||
!m_sWindowParams.bFullScreen ? dwStyle : (WS_POPUP),
|
||||
!m_sWindowParams.bFullScreen ? displayRegion.left : 0,
|
||||
!m_sWindowParams.bFullScreen ? displayRegion.top : 0,
|
||||
!m_sWindowParams.bFullScreen ? displayRegion.right : GetSystemMetrics(SM_CXSCREEN),
|
||||
!m_sWindowParams.bFullScreen ? displayRegion.bottom : GetSystemMetrics(SM_CYSCREEN),
|
||||
m_sWindowParams.hWndParent,
|
||||
m_sWindowParams.hMenu,
|
||||
m_sWindowParams.hInstance,
|
||||
m_sWindowParams.lpParam);
|
||||
|
||||
if (!m_Hwnd)
|
||||
return MFX_ERR_UNKNOWN;
|
||||
|
||||
ShowWindow(m_Hwnd, SW_SHOWDEFAULT);
|
||||
UpdateWindow(m_Hwnd);
|
||||
|
||||
#ifdef _WIN64
|
||||
SetWindowLongPtr(m_Hwnd, GWLP_USERDATA, (LONG_PTR)this);
|
||||
#else
|
||||
SetWindowLong(m_Hwnd, GWL_USERDATA, PtrToLong(this));
|
||||
#endif
|
||||
|
||||
m_hwdev->SetHandle((mfxHandleType)MFX_HANDLE_DEVICEWINDOW, m_Hwnd);
|
||||
sts = m_hwdev->Reset();
|
||||
MSDK_CHECK_STATUS(sts, "m_hwdev->Reset failed");
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus CDecodeD3DRender::RenderFrame(mfxFrameSurface1 *pSurface, mfxFrameAllocator *pmfxAlloc)
|
||||
{
|
||||
RECT rect;
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
GetClientRect(m_Hwnd, &rect);
|
||||
|
||||
if (IsRectEmpty(&rect))
|
||||
return MFX_ERR_UNKNOWN;
|
||||
|
||||
//--- In case of 10 bit surfaces and SW library we have to copy it and shift its data
|
||||
if(pSurface->Info.FourCC == MFX_FOURCC_P010 && !pSurface->Info.Shift)
|
||||
{
|
||||
sts = AllocateShiftedSurfaceIfNeeded(pSurface,pmfxAlloc);
|
||||
MSDK_CHECK_STATUS(sts, "AllocateShiftedSurfaceIfNeeded failed");
|
||||
|
||||
sts = pAllocator->Lock(pAllocator->pthis,shiftedSurface.Data.MemId,&shiftedSurface.Data);
|
||||
MSDK_CHECK_STATUS(sts, "pAllocator->Lock of shiftedSurface failed");
|
||||
sts = pAllocator->Lock(pAllocator->pthis,pSurface->Data.MemId,&pSurface->Data);
|
||||
MSDK_CHECK_STATUS(sts, "pAllocator->Lock of pSurface failed");
|
||||
|
||||
int wordsNum = pSurface->Data.Pitch*pSurface->Info.Height*3/16; // Number of 8-byte words
|
||||
mfxU64* pBuf = (mfxU64*)pSurface->Data.Y16;
|
||||
mfxU64* pDestBuf = (mfxU64*)shiftedSurface.Data.Y16;
|
||||
for(int i=0;i<wordsNum;i++)
|
||||
{
|
||||
pDestBuf[i] = (pBuf[i]<<6)&0xFFC0FFC0FFC0FFC0;
|
||||
}
|
||||
sts = pAllocator->Unlock(pAllocator->pthis,shiftedSurface.Data.MemId,&shiftedSurface.Data);
|
||||
MSDK_CHECK_STATUS(sts, "pAllocator->Unlock of shiftedSurface failed");
|
||||
sts = pAllocator->Unlock(pAllocator->pthis,pSurface->Data.MemId,&pSurface->Data);
|
||||
MSDK_CHECK_STATUS(sts, "pAllocator->Unlock of pSurface failed");
|
||||
|
||||
sts = m_hwdev->RenderFrame(&shiftedSurface, pmfxAlloc);
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = m_hwdev->RenderFrame(pSurface, pmfxAlloc);
|
||||
}
|
||||
MSDK_CHECK_STATUS(sts, "m_hwdev->RenderFrame failed");
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
HWND CDecodeD3DRender::GetWindowHandle()
|
||||
{
|
||||
if (!m_Hwnd)
|
||||
{
|
||||
EnumDisplayMonitors(NULL, NULL, &CDecodeD3DRender::MonitorEnumProc, (LPARAM)this);
|
||||
POINT point = {m_RectWindow.left, m_RectWindow.top};
|
||||
m_Hwnd = WindowFromPoint(point);
|
||||
m_nMonitorCurrent = 0;
|
||||
m_bIsMonitorFound = false;
|
||||
}
|
||||
return m_Hwnd;
|
||||
}
|
||||
|
||||
VOID CDecodeD3DRender::UpdateTitle(double fps)
|
||||
{
|
||||
if (m_Hwnd)
|
||||
{
|
||||
MSG msg;
|
||||
MSDK_ZERO_MEMORY(msg);
|
||||
while (msg.message != WM_QUIT && PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
|
||||
if (NULL != m_sWindowParams.lpWindowName) {
|
||||
TCHAR str[20];
|
||||
_stprintf_s(str, 20, MSDK_STRING("fps=%.2lf"), fps );
|
||||
|
||||
SetWindowText(m_Hwnd, str);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
VOID CDecodeD3DRender::OnDestroy(HWND /*hwnd*/)
|
||||
{
|
||||
PostQuitMessage(0);
|
||||
}
|
||||
|
||||
VOID CDecodeD3DRender::OnKey(HWND hwnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
|
||||
{
|
||||
if (TRUE == fDown)
|
||||
return;
|
||||
|
||||
if ('1' == vk && false == m_sWindowParams.bFullScreen)
|
||||
ChangeWindowSize(true);
|
||||
else if (true == m_sWindowParams.bFullScreen)
|
||||
ChangeWindowSize(false);
|
||||
}
|
||||
|
||||
void CDecodeD3DRender::AdjustWindowRect(RECT *rect)
|
||||
{
|
||||
int cxmax = GetSystemMetrics(SM_CXMAXIMIZED);
|
||||
int cymax = GetSystemMetrics(SM_CYMAXIMIZED);
|
||||
int cxmin = GetSystemMetrics(SM_CXMINTRACK);
|
||||
int cymin = GetSystemMetrics(SM_CYMINTRACK);
|
||||
int leftmax = cxmax - cxmin;
|
||||
int topmax = cymax - cxmin;
|
||||
if (rect->left < 0)
|
||||
rect->left = 0;
|
||||
if (rect->left > leftmax)
|
||||
rect->left = leftmax;
|
||||
if (rect->top < 0)
|
||||
rect->top = 0;
|
||||
if (rect->top > topmax)
|
||||
rect->top = topmax;
|
||||
|
||||
if (rect->right < rect->left + cxmin)
|
||||
rect->right = rect->left + cxmin;
|
||||
if (rect->right - rect->left > cxmax)
|
||||
rect->right = rect->left + cxmax;
|
||||
|
||||
if (rect->bottom < rect->top + cymin)
|
||||
rect->bottom = rect->top + cymin;
|
||||
if (rect->bottom - rect->top > cymax)
|
||||
rect->bottom = rect->top + cymax;
|
||||
}
|
||||
|
||||
VOID CDecodeD3DRender::ChangeWindowSize(bool bFullScreen)
|
||||
{
|
||||
HMONITOR hMonitor = MonitorFromWindow(m_Hwnd, MONITOR_DEFAULTTONEAREST);
|
||||
MONITORINFOEX mi;
|
||||
mi.cbSize = sizeof(mi);
|
||||
GetMonitorInfo(hMonitor, &mi);
|
||||
|
||||
WINDOWINFO wndInfo;
|
||||
wndInfo.cbSize = sizeof(WINDOWINFO);
|
||||
GetWindowInfo(m_Hwnd, &wndInfo);
|
||||
|
||||
if(!m_sWindowParams.bFullScreen)
|
||||
{
|
||||
m_rect = wndInfo.rcWindow;
|
||||
m_style = wndInfo.dwStyle;
|
||||
}
|
||||
|
||||
m_sWindowParams.bFullScreen = bFullScreen;
|
||||
|
||||
if(!bFullScreen)
|
||||
{
|
||||
AdjustWindowRectEx(&m_rect,0,0,0);
|
||||
SetWindowLong(m_Hwnd, GWL_STYLE, m_style);
|
||||
SetWindowPos(m_Hwnd, HWND_NOTOPMOST,
|
||||
m_rect.left , m_rect.top ,
|
||||
abs(m_rect.right - m_rect.left), abs(m_rect.bottom - m_rect.top),
|
||||
SWP_SHOWWINDOW);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetWindowLong(m_Hwnd, GWL_STYLE, WS_POPUP);
|
||||
SetWindowPos(m_Hwnd, HWND_NOTOPMOST,mi.rcMonitor.left , mi.rcMonitor.top,
|
||||
abs(mi.rcMonitor.left - mi.rcMonitor.right), abs(mi.rcMonitor.top - mi.rcMonitor.bottom), SWP_SHOWWINDOW);
|
||||
}
|
||||
}
|
||||
|
||||
mfxStatus CDecodeD3DRender::AllocateShiftedSurfaceIfNeeded(const mfxFrameSurface1* refSurface,mfxFrameAllocator* allocator)
|
||||
{
|
||||
if(!pAllocator)
|
||||
{
|
||||
mfxFrameAllocRequest request={};
|
||||
request.AllocId = 0xF000; // Unique alloc ID
|
||||
request.NumFrameMin=request.NumFrameSuggested=1;
|
||||
request.Info = refSurface->Info;
|
||||
request.Type = MFX_MEMTYPE_EXTERNAL_FRAME | MFX_MEMTYPE_FROM_DECODE | MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET;
|
||||
|
||||
pAllocator = allocator;
|
||||
mfxStatus sts = allocator->Alloc(allocator->pthis, &request, &shiftSurfaceResponse);
|
||||
MSDK_CHECK_STATUS(sts, "Renderer: Shifted Surface allocation failed");
|
||||
|
||||
shiftedSurface.Data.MemId=shiftSurfaceResponse.mids[0];
|
||||
shiftedSurface.Info = request.Info;
|
||||
}
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
172
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/general_allocator.cpp
vendored
Normal file
172
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/general_allocator.cpp
vendored
Normal file
@@ -0,0 +1,172 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#include "general_allocator.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
#include "d3d_allocator.h"
|
||||
#include "d3d11_allocator.h"
|
||||
#else
|
||||
#include <stdarg.h>
|
||||
#include "vaapi_allocator.h"
|
||||
#endif
|
||||
|
||||
#include "sysmem_allocator.h"
|
||||
|
||||
#include "sample_defs.h"
|
||||
|
||||
// Wrapper on standard allocator for concurrent allocation of
|
||||
// D3D and system surfaces
|
||||
GeneralAllocator::GeneralAllocator()
|
||||
{
|
||||
};
|
||||
GeneralAllocator::~GeneralAllocator()
|
||||
{
|
||||
};
|
||||
mfxStatus GeneralAllocator::Init(mfxAllocatorParams *pParams)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
D3DAllocatorParams *d3dAllocParams = dynamic_cast<D3DAllocatorParams*>(pParams);
|
||||
if (d3dAllocParams)
|
||||
m_D3DAllocator.reset(new D3DFrameAllocator);
|
||||
#if MFX_D3D11_SUPPORT
|
||||
D3D11AllocatorParams *d3d11AllocParams = dynamic_cast<D3D11AllocatorParams*>(pParams);
|
||||
if (d3d11AllocParams)
|
||||
m_D3DAllocator.reset(new D3D11FrameAllocator);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef LIBVA_SUPPORT
|
||||
vaapiAllocatorParams *vaapiAllocParams = dynamic_cast<vaapiAllocatorParams*>(pParams);
|
||||
if (vaapiAllocParams)
|
||||
m_D3DAllocator.reset(new vaapiFrameAllocator);
|
||||
#endif
|
||||
|
||||
if (m_D3DAllocator.get())
|
||||
{
|
||||
sts = m_D3DAllocator.get()->Init(pParams);
|
||||
MSDK_CHECK_STATUS(sts, "m_D3DAllocator.get failed");
|
||||
}
|
||||
|
||||
m_SYSAllocator.reset(new SysMemFrameAllocator);
|
||||
sts = m_SYSAllocator.get()->Init(0);
|
||||
MSDK_CHECK_STATUS(sts, "m_SYSAllocator.get failed");
|
||||
|
||||
return sts;
|
||||
}
|
||||
mfxStatus GeneralAllocator::Close()
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
if (m_D3DAllocator.get())
|
||||
{
|
||||
sts = m_D3DAllocator.get()->Close();
|
||||
MSDK_CHECK_STATUS(sts, "m_D3DAllocator.get failed");
|
||||
}
|
||||
|
||||
sts = m_SYSAllocator.get()->Close();
|
||||
MSDK_CHECK_STATUS(sts, "m_SYSAllocator.get failed");
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus GeneralAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (isD3DMid(mid) && m_D3DAllocator.get())
|
||||
return m_D3DAllocator.get()->Lock(m_D3DAllocator.get(), mid, ptr);
|
||||
else
|
||||
return m_SYSAllocator.get()->Lock(m_SYSAllocator.get(),mid, ptr);
|
||||
}
|
||||
mfxStatus GeneralAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (isD3DMid(mid) && m_D3DAllocator.get())
|
||||
return m_D3DAllocator.get()->Unlock(m_D3DAllocator.get(), mid, ptr);
|
||||
else
|
||||
return m_SYSAllocator.get()->Unlock(m_SYSAllocator.get(),mid, ptr);
|
||||
}
|
||||
|
||||
mfxStatus GeneralAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
|
||||
{
|
||||
if (isD3DMid(mid) && m_D3DAllocator.get())
|
||||
return m_D3DAllocator.get()->GetHDL(m_D3DAllocator.get(), mid, handle);
|
||||
else
|
||||
return m_SYSAllocator.get()->GetHDL(m_SYSAllocator.get(), mid, handle);
|
||||
}
|
||||
|
||||
mfxStatus GeneralAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
|
||||
{
|
||||
// try to ReleaseResponse via D3D allocator
|
||||
if (isD3DMid(response->mids[0]) && m_D3DAllocator.get())
|
||||
return m_D3DAllocator.get()->Free(m_D3DAllocator.get(),response);
|
||||
else
|
||||
return m_SYSAllocator.get()->Free(m_SYSAllocator.get(), response);
|
||||
}
|
||||
|
||||
mfxStatus GeneralAllocator::ReallocImpl(mfxMemId mid, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut)
|
||||
{
|
||||
if (!info || !midOut) return MFX_ERR_NULL_PTR;
|
||||
|
||||
mfxStatus sts;
|
||||
if ((memType & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET || memType & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) && m_D3DAllocator.get())
|
||||
{
|
||||
sts = m_D3DAllocator.get()->ReallocFrame(mid, info, memType, midOut);
|
||||
MSDK_CHECK_NOT_EQUAL(MFX_ERR_NONE, sts, sts);
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = m_SYSAllocator.get()->ReallocFrame(mid, info, memType, midOut);
|
||||
MSDK_CHECK_NOT_EQUAL(MFX_ERR_NONE, sts, sts);
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus GeneralAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
mfxStatus sts;
|
||||
if ((request->Type & MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET || request->Type & MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET) && m_D3DAllocator.get())
|
||||
{
|
||||
sts = m_D3DAllocator.get()->Alloc(m_D3DAllocator.get(), request, response);
|
||||
MSDK_CHECK_NOT_EQUAL(MFX_ERR_NONE, sts, sts);
|
||||
StoreFrameMids(true, response);
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = m_SYSAllocator.get()->Alloc(m_SYSAllocator.get(), request, response);
|
||||
MSDK_CHECK_NOT_EQUAL(MFX_ERR_NONE, sts, sts);
|
||||
StoreFrameMids(false, response);
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
void GeneralAllocator::StoreFrameMids(bool isD3DFrames, mfxFrameAllocResponse *response)
|
||||
{
|
||||
for (mfxU32 i = 0; i < response->NumFrameActual; i++)
|
||||
m_Mids.insert(std::pair<mfxHDL, bool>(response->mids[i], isD3DFrames));
|
||||
}
|
||||
bool GeneralAllocator::isD3DMid(mfxHDL mid)
|
||||
{
|
||||
std::map<mfxHDL, bool>::iterator it;
|
||||
it = m_Mids.find(mid);
|
||||
if (it == m_Mids.end())
|
||||
return false; // sys mem allocator will check validity of mid further
|
||||
else
|
||||
return it->second;
|
||||
}
|
||||
202
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/mfx_buffering.cpp
vendored
Normal file
202
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/mfx_buffering.cpp
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <mfx_buffering.h>
|
||||
|
||||
CBuffering::CBuffering():
|
||||
m_SurfacesNumber(0),
|
||||
m_OutputSurfacesNumber(0),
|
||||
m_pSurfaces(NULL),
|
||||
m_pVppSurfaces(NULL),
|
||||
m_FreeSurfacesPool(m_Mutex),
|
||||
m_FreeVppSurfacesPool(m_Mutex),
|
||||
m_UsedSurfacesPool(m_Mutex),
|
||||
m_UsedVppSurfacesPool(m_Mutex),
|
||||
m_pFreeOutputSurfaces(NULL),
|
||||
m_OutputSurfacesPool(m_Mutex),
|
||||
m_DeliveredSurfacesPool(m_Mutex)
|
||||
{
|
||||
}
|
||||
|
||||
CBuffering::~CBuffering()
|
||||
{
|
||||
}
|
||||
|
||||
mfxStatus
|
||||
CBuffering::AllocBuffers(mfxU32 SurfaceNumber)
|
||||
{
|
||||
if (!SurfaceNumber) return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
if (!m_OutputSurfacesNumber) { // true - if Vpp isn't enabled
|
||||
m_OutputSurfacesNumber = SurfaceNumber;
|
||||
}
|
||||
m_SurfacesNumber = SurfaceNumber;
|
||||
|
||||
m_pSurfaces = (msdkFrameSurface*)calloc(m_SurfacesNumber, sizeof(msdkFrameSurface));
|
||||
if (!m_pSurfaces) return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
msdkOutputSurface* p = NULL;
|
||||
msdkOutputSurface* tail = NULL;
|
||||
|
||||
m_pFreeOutputSurfaces = (msdkOutputSurface*)calloc(1, sizeof(msdkOutputSurface));
|
||||
if (!m_pFreeOutputSurfaces) return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
tail = m_pFreeOutputSurfaces;
|
||||
|
||||
for (mfxU32 i = 1; i < m_OutputSurfacesNumber; ++i) {
|
||||
p = (msdkOutputSurface*)calloc(1, sizeof(msdkOutputSurface));
|
||||
if (!p) return MFX_ERR_MEMORY_ALLOC;
|
||||
tail->next = p;
|
||||
tail = p;
|
||||
}
|
||||
|
||||
ResetBuffers();
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus
|
||||
CBuffering::AllocVppBuffers(mfxU32 VppSurfaceNumber)
|
||||
{
|
||||
m_OutputSurfacesNumber = VppSurfaceNumber;
|
||||
m_pVppSurfaces = (msdkFrameSurface*)calloc(m_OutputSurfacesNumber, sizeof(msdkFrameSurface));
|
||||
if (!m_pVppSurfaces) return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
ResetVppBuffers();
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void
|
||||
CBuffering::AllocOutputBuffer()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
|
||||
m_pFreeOutputSurfaces = (msdkOutputSurface*)calloc(1, sizeof(msdkOutputSurface));
|
||||
}
|
||||
|
||||
static void
|
||||
FreeList(msdkOutputSurface*& head) {
|
||||
msdkOutputSurface* next;
|
||||
while (head) {
|
||||
next = head->next;
|
||||
free(head);
|
||||
head = next;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CBuffering::FreeBuffers()
|
||||
{
|
||||
if (m_pSurfaces) {
|
||||
free(m_pSurfaces);
|
||||
m_pSurfaces = NULL;
|
||||
}
|
||||
|
||||
if (m_pVppSurfaces) {
|
||||
free(m_pVppSurfaces);
|
||||
m_pVppSurfaces = NULL;
|
||||
}
|
||||
|
||||
FreeList(m_pFreeOutputSurfaces);
|
||||
FreeList(m_OutputSurfacesPool.m_pSurfacesHead);
|
||||
FreeList(m_DeliveredSurfacesPool.m_pSurfacesHead);
|
||||
|
||||
m_UsedSurfacesPool.m_pSurfacesHead = NULL;
|
||||
m_UsedSurfacesPool.m_pSurfacesTail = NULL;
|
||||
m_UsedVppSurfacesPool.m_pSurfacesHead = NULL;
|
||||
m_UsedVppSurfacesPool.m_pSurfacesTail = NULL;
|
||||
m_OutputSurfacesPool.m_pSurfacesHead = NULL;
|
||||
m_OutputSurfacesPool.m_pSurfacesTail = NULL;
|
||||
|
||||
m_FreeSurfacesPool.m_pSurfaces = NULL;
|
||||
m_FreeVppSurfacesPool.m_pSurfaces = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
CBuffering::ResetBuffers()
|
||||
{
|
||||
mfxU32 i;
|
||||
msdkFrameSurface* pFreeSurf = m_FreeSurfacesPool.m_pSurfaces = m_pSurfaces;
|
||||
|
||||
for (i = 0; i < m_SurfacesNumber; ++i) {
|
||||
if (i < (m_SurfacesNumber-1)) {
|
||||
pFreeSurf[i].next = &(pFreeSurf[i+1]);
|
||||
pFreeSurf[i+1].prev = &(pFreeSurf[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CBuffering::ResetVppBuffers()
|
||||
{
|
||||
mfxU32 i;
|
||||
msdkFrameSurface* pFreeVppSurf = m_FreeVppSurfacesPool.m_pSurfaces = m_pVppSurfaces;
|
||||
|
||||
for (i = 0; i < m_OutputSurfacesNumber; ++i) {
|
||||
if (i < (m_OutputSurfacesNumber-1)) {
|
||||
pFreeVppSurf[i].next = &(pFreeVppSurf[i+1]);
|
||||
pFreeVppSurf[i+1].prev = &(pFreeVppSurf[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CBuffering::SyncFrameSurfaces()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
msdkFrameSurface *next = NULL;
|
||||
msdkFrameSurface *cur = m_UsedSurfacesPool.m_pSurfacesHead;
|
||||
|
||||
while (cur) {
|
||||
if (cur->frame.Data.Locked || cur->render_lock) {
|
||||
// frame is still locked: just moving to the next one
|
||||
cur = cur->next;
|
||||
} else {
|
||||
// frame was unlocked: moving it to the free surfaces array
|
||||
m_UsedSurfacesPool.DetachSurfaceUnsafe(cur);
|
||||
m_FreeSurfacesPool.AddSurfaceUnsafe(cur);
|
||||
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
CBuffering::SyncVppFrameSurfaces()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(m_Mutex);
|
||||
msdkFrameSurface *next = NULL;
|
||||
msdkFrameSurface *cur = m_UsedVppSurfacesPool.m_pSurfacesHead;
|
||||
|
||||
while (cur) {
|
||||
if (cur->frame.Data.Locked || cur->render_lock) {
|
||||
// frame is still locked: just moving to the next one
|
||||
cur = cur->next;
|
||||
} else {
|
||||
// frame was unlocked: moving it to the free surfaces array
|
||||
m_UsedVppSurfacesPool.DetachSurfaceUnsafe(cur);
|
||||
m_FreeVppSurfacesPool.AddSurfaceUnsafe(cur);
|
||||
|
||||
cur = next;
|
||||
}
|
||||
}
|
||||
}
|
||||
1044
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/parameters_dumper.cpp
vendored
Normal file
1044
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/parameters_dumper.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
182
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/plugin_utils.cpp
vendored
Normal file
182
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/plugin_utils.cpp
vendored
Normal file
@@ -0,0 +1,182 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#include "plugin_utils.h"
|
||||
#include "mfxvp8.h"
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
|
||||
bool AreGuidsEqual(const mfxPluginUID& guid1, const mfxPluginUID& guid2)
|
||||
{
|
||||
for(size_t i = 0; i != sizeof(mfxPluginUID); i++)
|
||||
{
|
||||
if (guid1.Data[i] != guid2.Data[i])
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
mfxStatus ConvertStringToGuid(const msdk_string & strGuid, mfxPluginUID & mfxGuid)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
// Check if symbolic GUID value
|
||||
std::map<msdk_string, mfxPluginUID> uid;
|
||||
uid[MSDK_STRING("hevcd_sw")] = MFX_PLUGINID_HEVCD_SW;
|
||||
uid[MSDK_STRING("hevcd_hw")] = MFX_PLUGINID_HEVCD_HW;
|
||||
|
||||
uid[MSDK_STRING("hevce_sw")] = MFX_PLUGINID_HEVCE_SW;
|
||||
uid[MSDK_STRING("hevce_gacc")] = MFX_PLUGINID_HEVCE_GACC;
|
||||
uid[MSDK_STRING("hevce_hw")] = MFX_PLUGINID_HEVCE_HW;
|
||||
|
||||
uid[MSDK_STRING("vp8d_hw")] = MFX_PLUGINID_VP8D_HW;
|
||||
uid[MSDK_STRING("vp8e_hw")] = MFX_PLUGINID_VP8E_HW;
|
||||
|
||||
uid[MSDK_STRING("vp9d_hw")] = MFX_PLUGINID_VP9D_HW;
|
||||
uid[MSDK_STRING("vp9e_hw")] = MFX_PLUGINID_VP9E_HW;
|
||||
|
||||
uid[MSDK_STRING("camera_hw")] = MFX_PLUGINID_CAMERA_HW;
|
||||
|
||||
uid[MSDK_STRING("capture_hw")] = MFX_PLUGINID_CAPTURE_HW;
|
||||
|
||||
uid[MSDK_STRING("ptir_hw")] = MFX_PLUGINID_ITELECINE_HW;
|
||||
uid[MSDK_STRING("h264_la_hw")] = MFX_PLUGINID_H264LA_HW;
|
||||
uid[MSDK_STRING("aacd")] = MFX_PLUGINID_AACD;
|
||||
uid[MSDK_STRING("aace")] = MFX_PLUGINID_AACE;
|
||||
|
||||
uid[MSDK_STRING("hevce_fei_hw")] = MFX_PLUGINID_HEVCE_FEI_HW;
|
||||
|
||||
if (uid.find(strGuid) == uid.end())
|
||||
{
|
||||
mfxGuid = MSDK_PLUGINGUID_NULL;
|
||||
sts = MFX_ERR_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
mfxGuid = uid[strGuid];
|
||||
sts = MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
// Check if plain GUID value
|
||||
if (sts)
|
||||
{
|
||||
if (strGuid.size() != 32)
|
||||
{
|
||||
sts = MFX_ERR_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (size_t i = 0; i < 16; i++)
|
||||
{
|
||||
unsigned int xx = 0;
|
||||
msdk_stringstream ss;
|
||||
ss << std::hex << strGuid.substr(i * 2, 2);
|
||||
ss >> xx;
|
||||
mfxGuid.Data[i] = (mfxU8)xx;
|
||||
}
|
||||
sts = MFX_ERR_NONE;
|
||||
}
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
|
||||
const mfxPluginUID & msdkGetPluginUID(mfxIMPL impl, msdkComponentType type, mfxU32 uCodecid)
|
||||
{
|
||||
if (impl == MFX_IMPL_SOFTWARE)
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case MSDK_VDECODE:
|
||||
switch(uCodecid)
|
||||
{
|
||||
case MFX_CODEC_HEVC:
|
||||
return MFX_PLUGINID_HEVCD_SW;
|
||||
}
|
||||
break;
|
||||
case MSDK_VENCODE:
|
||||
switch(uCodecid)
|
||||
{
|
||||
case MFX_CODEC_HEVC:
|
||||
return MFX_PLUGINID_HEVCE_SW;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
switch(type)
|
||||
{
|
||||
case MSDK_VENCODE:
|
||||
switch(uCodecid)
|
||||
{
|
||||
case MFX_CODEC_VP8:
|
||||
return MFX_PLUGINID_VP8E_HW;
|
||||
}
|
||||
break;
|
||||
#if MFX_VERSION >= 1027
|
||||
case (MSDK_VENCODE | MSDK_FEI):
|
||||
switch (uCodecid)
|
||||
{
|
||||
case MFX_CODEC_HEVC:
|
||||
return MFX_PLUGINID_HEVC_FEI_ENCODE;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
case MSDK_VENC:
|
||||
switch(uCodecid)
|
||||
{
|
||||
case MFX_CODEC_HEVC:
|
||||
return MFX_PLUGINID_HEVCE_FEI_HW; // HEVC FEI uses ENC interface
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return MSDK_PLUGINGUID_NULL;
|
||||
}
|
||||
|
||||
sPluginParams ParsePluginGuid(msdk_char* strPluginGuid)
|
||||
{
|
||||
sPluginParams pluginParams;
|
||||
mfxPluginUID uid;
|
||||
mfxStatus sts = ConvertStringToGuid(strPluginGuid, uid);
|
||||
|
||||
if (sts == MFX_ERR_NONE)
|
||||
{
|
||||
pluginParams.type = MFX_PLUGINLOAD_TYPE_GUID;
|
||||
pluginParams.pluginGuid = uid;
|
||||
}
|
||||
|
||||
return pluginParams;
|
||||
}
|
||||
|
||||
sPluginParams ParsePluginPath(msdk_char* strPluginGuid)
|
||||
{
|
||||
sPluginParams pluginParams;
|
||||
|
||||
msdk_char tmpVal[MSDK_MAX_FILENAME_LEN];
|
||||
msdk_opt_read(strPluginGuid, tmpVal);
|
||||
|
||||
MSDK_MAKE_BYTE_STRING(tmpVal, pluginParams.strPluginPath);
|
||||
pluginParams.type = MFX_PLUGINLOAD_TYPE_FILE;
|
||||
|
||||
return pluginParams;
|
||||
}
|
||||
157
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/preset_manager.cpp
vendored
Normal file
157
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/preset_manager.cpp
vendored
Normal file
@@ -0,0 +1,157 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "preset_manager.h"
|
||||
#include "mfxvideo.h"
|
||||
#include "brc_routines.h"
|
||||
|
||||
CPresetManager CPresetManager::Inst;
|
||||
|
||||
msdk_string CPresetManager::modesName[PRESET_MAX_MODES] =
|
||||
{
|
||||
MSDK_STRING("Default"),
|
||||
MSDK_STRING("DSS"),
|
||||
MSDK_STRING("Conference"),
|
||||
MSDK_STRING("Gaming"),
|
||||
};
|
||||
|
||||
//GopRefDist, TargetUsage, RateControlMethod, ExtBRCType, AsyncDepth, BRefType
|
||||
// AdaptiveMaxFrameSize, LowDelayBRC, IntRefType, IntRefCycleSize, IntRefQPDelta, IntRefCycleDist, WeightedPred, WeightedBiPred, EnableBPyramid, EnablePPyramid
|
||||
|
||||
CPresetParameters CPresetManager::presets[PRESET_MAX_MODES][PRESET_MAX_CODECS] =
|
||||
{
|
||||
// Default
|
||||
{
|
||||
{4, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_VBR, EXTBRC_DEFAULT, 4, MFX_B_REF_PYRAMID,
|
||||
0, 0, 0, 0, 0, 0, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0},
|
||||
{0, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_VBR, EXTBRC_DEFAULT, 4, 0,
|
||||
0, 0, 0, 0, 0, 0, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0 }
|
||||
},
|
||||
// DSS
|
||||
{
|
||||
{1, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_QVBR, EXTBRC_DEFAULT, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0 },
|
||||
{1, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_QVBR, EXTBRC_DEFAULT, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 1, 1 },
|
||||
},
|
||||
// Conference
|
||||
{
|
||||
{1, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_VCM, EXTBRC_DEFAULT, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0 },
|
||||
{1, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_VBR, EXTBRC_ON, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0 },
|
||||
},
|
||||
// Gaming
|
||||
{
|
||||
{1, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_QVBR, EXTBRC_DEFAULT, 1, 0,
|
||||
MFX_CODINGOPTION_ON, MFX_CODINGOPTION_ON, MFX_REFRESH_HORIZONTAL, 8, 0, 4, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0 },
|
||||
{1, MFX_TARGETUSAGE_BALANCED, MFX_RATECONTROL_VBR, EXTBRC_ON, 1, 0,
|
||||
MFX_CODINGOPTION_ON, MFX_CODINGOPTION_ON, MFX_REFRESH_HORIZONTAL, 8, 0, 4, MFX_WEIGHTED_PRED_UNKNOWN, MFX_WEIGHTED_PRED_UNKNOWN, 0, 0 },
|
||||
}
|
||||
};
|
||||
|
||||
CPresetManager::CPresetManager()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
CPresetManager::~CPresetManager()
|
||||
{
|
||||
}
|
||||
|
||||
COutputPresetParameters CPresetManager::GetPreset(EPresetModes mode, mfxU32 codecFourCC, mfxF64 fps, mfxU32 width, mfxU32 height, bool isHWLib)
|
||||
{
|
||||
COutputPresetParameters retVal = GetBasicPreset(mode, codecFourCC);
|
||||
*(dynamic_cast<CDependentPresetParameters*>(&retVal)) = GetDependentPresetParameters(mode, codecFourCC, fps, width, height,retVal.TargetUsage);
|
||||
|
||||
if (!isHWLib)
|
||||
{
|
||||
// These features are unsupported in SW library
|
||||
retVal.WeightedBiPred = 0;
|
||||
retVal.WeightedPred = 0;
|
||||
}
|
||||
|
||||
return retVal;
|
||||
}
|
||||
|
||||
COutputPresetParameters CPresetManager::GetBasicPreset(EPresetModes mode, mfxU32 codecFourCC)
|
||||
{
|
||||
COutputPresetParameters retVal;
|
||||
|
||||
if (mode < 0 || mode >= PRESET_MAX_MODES)
|
||||
{
|
||||
mode = PRESET_DEFAULT;
|
||||
}
|
||||
|
||||
// Reading basic preset values
|
||||
switch (codecFourCC)
|
||||
{
|
||||
case MFX_CODEC_AVC:
|
||||
retVal = presets[mode][PRESET_AVC];
|
||||
break;
|
||||
case MFX_CODEC_HEVC:
|
||||
retVal = presets[mode][PRESET_HEVC];
|
||||
break;
|
||||
default:
|
||||
if (mode != PRESET_DEFAULT)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("WARNING: Presets are available for h.264 or h.265 codecs only. Request for particular preset is ignored.\n"));
|
||||
}
|
||||
|
||||
if (codecFourCC != MFX_CODEC_JPEG)
|
||||
{
|
||||
retVal.TargetUsage = MFX_TARGETUSAGE_BALANCED;
|
||||
retVal.RateControlMethod = MFX_RATECONTROL_CBR;
|
||||
}
|
||||
retVal.AsyncDepth = 4;
|
||||
return retVal;
|
||||
}
|
||||
|
||||
retVal.PresetName = modesName[mode];
|
||||
return retVal;
|
||||
}
|
||||
|
||||
CDependentPresetParameters CPresetManager::GetDependentPresetParameters(EPresetModes mode, mfxU32 codecFourCC, mfxF64 fps, mfxU32 width, mfxU32 height,mfxU16 targetUsage)
|
||||
{
|
||||
CDependentPresetParameters retVal = {};
|
||||
retVal.TargetKbps = codecFourCC != MFX_CODEC_JPEG ? CalculateDefaultBitrate(codecFourCC, targetUsage, width, height, fps) : 0;
|
||||
|
||||
if (codecFourCC == MFX_CODEC_AVC || codecFourCC == MFX_CODEC_HEVC)
|
||||
{
|
||||
// Calculating dependent preset values
|
||||
retVal.MaxKbps = (mode == PRESET_GAMING ? (mfxU16)(1.2*retVal.TargetKbps) : 0);
|
||||
retVal.GopPicSize = (mode == PRESET_GAMING || mode == PRESET_DEFAULT ? 0 : (mfxU16)(2 * fps));
|
||||
retVal.BufferSizeInKB = (mode == PRESET_DEFAULT ? 0 : retVal.TargetKbps); // 1 second buffers
|
||||
retVal.LookAheadDepth = 0; // Enable this setting if LA BRC will be enabled
|
||||
retVal.MaxFrameSize = (mode == PRESET_GAMING ? (mfxU32)(retVal.TargetKbps*0.166) : 0);
|
||||
}
|
||||
return retVal;
|
||||
}
|
||||
|
||||
EPresetModes CPresetManager::PresetNameToMode(const msdk_char* name)
|
||||
{
|
||||
for (int i = 0; i < PRESET_MAX_MODES; i++)
|
||||
{
|
||||
if (!msdk_stricmp(modesName[i].c_str(), name))
|
||||
{
|
||||
return (EPresetModes)i;
|
||||
}
|
||||
}
|
||||
return PRESET_MAX_MODES;
|
||||
}
|
||||
2779
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/sample_utils.cpp
vendored
Normal file
2779
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/sample_utils.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
538
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/sysmem_allocator.cpp
vendored
Normal file
538
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/sysmem_allocator.cpp
vendored
Normal file
@@ -0,0 +1,538 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "sysmem_allocator.h"
|
||||
#include "sample_utils.h"
|
||||
|
||||
#define MSDK_ALIGN32(X) (((mfxU32)((X)+31)) & (~ (mfxU32)31))
|
||||
#define ID_BUFFER MFX_MAKEFOURCC('B','U','F','F')
|
||||
#define ID_FRAME MFX_MAKEFOURCC('F','R','M','E')
|
||||
|
||||
|
||||
SysMemFrameAllocator::SysMemFrameAllocator()
|
||||
: m_pBufferAllocator(0), m_bOwnBufferAllocator(false)
|
||||
{
|
||||
}
|
||||
|
||||
SysMemFrameAllocator::~SysMemFrameAllocator()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::Init(mfxAllocatorParams *pParams)
|
||||
{
|
||||
// check if any params passed from application
|
||||
if (pParams)
|
||||
{
|
||||
SysMemAllocatorParams *pSysMemParams = 0;
|
||||
pSysMemParams = dynamic_cast<SysMemAllocatorParams *>(pParams);
|
||||
if (!pSysMemParams)
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
m_pBufferAllocator = pSysMemParams->pBufferAllocator;
|
||||
m_bOwnBufferAllocator = false;
|
||||
}
|
||||
|
||||
// if buffer allocator wasn't passed from application create own
|
||||
if (!m_pBufferAllocator)
|
||||
{
|
||||
m_pBufferAllocator = new SysMemBufferAllocator;
|
||||
if (!m_pBufferAllocator)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
m_bOwnBufferAllocator = true;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::Close()
|
||||
{
|
||||
mfxStatus sts = BaseFrameAllocator::Close();
|
||||
|
||||
if (m_bOwnBufferAllocator)
|
||||
{
|
||||
delete m_pBufferAllocator;
|
||||
m_pBufferAllocator = 0;
|
||||
}
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (!m_pBufferAllocator)
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
if (!ptr)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
// If allocator uses pointers instead of mids, no further action is required
|
||||
if (!mid && ptr->Y)
|
||||
return MFX_ERR_NONE;
|
||||
|
||||
sFrame *fs = 0;
|
||||
mfxStatus sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, mid,(mfxU8 **)&fs);
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
if (ID_FRAME != fs->id)
|
||||
{
|
||||
m_pBufferAllocator->Unlock(m_pBufferAllocator->pthis, mid);
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
case MFX_FOURCC_NV12:
|
||||
ptr->U = ptr->Y + Width2 * Height2;
|
||||
ptr->V = ptr->U + 1;
|
||||
ptr->PitchHigh = 0;
|
||||
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width);
|
||||
break;
|
||||
case MFX_FOURCC_NV16:
|
||||
ptr->U = ptr->Y + Width2 * Height2;
|
||||
ptr->V = ptr->U + 1;
|
||||
ptr->PitchHigh = 0;
|
||||
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width);
|
||||
break;
|
||||
case MFX_FOURCC_YV12:
|
||||
ptr->V = ptr->Y + Width2 * Height2;
|
||||
ptr->U = ptr->V + (Width2 >> 1) * (Height2 >> 1);
|
||||
ptr->PitchHigh = 0;
|
||||
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width);
|
||||
break;
|
||||
case MFX_FOURCC_UYVY:
|
||||
ptr->U = ptr->Y;
|
||||
ptr->Y = ptr->U + 1;
|
||||
ptr->V = ptr->U + 2;
|
||||
ptr->PitchHigh = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
case MFX_FOURCC_YUY2:
|
||||
ptr->U = ptr->Y + 1;
|
||||
ptr->V = ptr->Y + 3;
|
||||
ptr->PitchHigh = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#if (MFX_VERSION >= 1028)
|
||||
case MFX_FOURCC_RGB565:
|
||||
ptr->G = ptr->B;
|
||||
ptr->R = ptr->B;
|
||||
ptr->PitchHigh = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#endif
|
||||
case MFX_FOURCC_RGB3:
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
ptr->PitchHigh = (mfxU16)((3 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((3 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#if !(defined(_WIN32) || defined(_WIN64))
|
||||
case MFX_FOURCC_RGBP:
|
||||
ptr->G = ptr->R + Width2 * Height2;
|
||||
ptr->B = ptr->G + Width2 * Height2;
|
||||
ptr->PitchHigh = (mfxU16)((MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#endif
|
||||
case MFX_FOURCC_RGB4:
|
||||
case MFX_FOURCC_A2RGB10:
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
ptr->A = ptr->B + 3;
|
||||
ptr->PitchHigh = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
case MFX_FOURCC_R16:
|
||||
ptr->Y16 = (mfxU16 *)ptr->B;
|
||||
ptr->PitchHigh = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((2 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_P016:
|
||||
#endif
|
||||
case MFX_FOURCC_P010:
|
||||
ptr->U = ptr->Y + Width2 * Height2 * 2;
|
||||
ptr->V = ptr->U + 2;
|
||||
ptr->PitchHigh = 0;
|
||||
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width * 2);
|
||||
break;
|
||||
case MFX_FOURCC_P210:
|
||||
ptr->U = ptr->Y + Width2 * Height2 * 2;
|
||||
ptr->V = ptr->U + 2;
|
||||
ptr->PitchHigh = 0;
|
||||
ptr->PitchLow = (mfxU16)MSDK_ALIGN32(fs->info.Width * 2);
|
||||
break;
|
||||
case MFX_FOURCC_AYUV:
|
||||
ptr->V = ptr->B;
|
||||
ptr->U = ptr->V + 1;
|
||||
ptr->Y = ptr->V + 2;
|
||||
ptr->A = ptr->V + 3;
|
||||
ptr->PitchHigh = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_Y416:
|
||||
ptr->U16 = (mfxU16*)ptr->B;
|
||||
ptr->Y16 = ptr->U16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 1;
|
||||
ptr->A = (mfxU8 *)(ptr->V16 + 1);
|
||||
ptr->PitchHigh = (mfxU16)(8 * MSDK_ALIGN32(fs->info.Width) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)(8 * MSDK_ALIGN32(fs->info.Width) % (1 << 16));
|
||||
break;
|
||||
case MFX_FOURCC_Y216:
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case MFX_FOURCC_Y210:
|
||||
ptr->Y16 = (mfxU16 *)ptr->B;
|
||||
ptr->U16 = ptr->Y16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 3;
|
||||
//4 words per macropixel -> 2 words per pixel -> 4 bytes per pixel
|
||||
ptr->PitchHigh = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
case MFX_FOURCC_Y410:
|
||||
ptr->U = ptr->V = ptr->A = ptr->Y;
|
||||
ptr->PitchHigh = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)((4 * MSDK_ALIGN32(fs->info.Width)) % (1 << 16));
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
if (!m_pBufferAllocator)
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
// If allocator uses pointers instead of mids, no further action is required
|
||||
if (!mid && ptr->Y)
|
||||
return MFX_ERR_NONE;
|
||||
|
||||
mfxStatus sts = m_pBufferAllocator->Unlock(m_pBufferAllocator->pthis, mid);
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
if (NULL != ptr)
|
||||
{
|
||||
ptr->Pitch = 0;
|
||||
ptr->Y = 0;
|
||||
ptr->U = 0;
|
||||
ptr->V = 0;
|
||||
ptr->A = 0;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::GetFrameHDL(mfxMemId /*mid*/, mfxHDL* /*handle*/)
|
||||
{
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
|
||||
{
|
||||
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
if ((request->Type & MFX_MEMTYPE_SYSTEM_MEMORY) != 0)
|
||||
return MFX_ERR_NONE;
|
||||
else
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxMemId *SysMemFrameAllocator::GetMidHolder(mfxMemId mid)
|
||||
{
|
||||
for (auto resp : m_vResp)
|
||||
{
|
||||
mfxMemId *it = std::find(resp->mids, resp->mids + resp->NumFrameActual, mid);
|
||||
if (it != resp->mids + resp->NumFrameActual)
|
||||
return it;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static mfxU32 GetSurfaceSize(mfxU32 FourCC, mfxU32 Width2, mfxU32 Height2)
|
||||
{
|
||||
mfxU32 nbytes = 0;
|
||||
|
||||
switch (FourCC)
|
||||
{
|
||||
case MFX_FOURCC_YV12:
|
||||
case MFX_FOURCC_NV12:
|
||||
nbytes = Width2*Height2 + (Width2>>1)*(Height2>>1) + (Width2>>1)*(Height2>>1);
|
||||
break;
|
||||
case MFX_FOURCC_NV16:
|
||||
nbytes = Width2*Height2 + (Width2>>1)*(Height2) + (Width2>>1)*(Height2);
|
||||
break;
|
||||
#if (MFX_VERSION >= 1028)
|
||||
case MFX_FOURCC_RGB565:
|
||||
nbytes = 2*Width2*Height2;
|
||||
break;
|
||||
#endif
|
||||
#if !(defined(_WIN32) || defined(_WIN64))
|
||||
case MFX_FOURCC_RGBP:
|
||||
#endif
|
||||
case MFX_FOURCC_RGB3:
|
||||
nbytes = Width2*Height2 + Width2*Height2 + Width2*Height2;
|
||||
break;
|
||||
case MFX_FOURCC_RGB4:
|
||||
case MFX_FOURCC_AYUV:
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case MFX_FOURCC_Y410:
|
||||
#endif
|
||||
nbytes = Width2*Height2 + Width2*Height2 + Width2*Height2 + Width2*Height2;
|
||||
break;
|
||||
case MFX_FOURCC_UYVY:
|
||||
case MFX_FOURCC_YUY2:
|
||||
nbytes = Width2*Height2 + (Width2>>1)*(Height2) + (Width2>>1)*(Height2);
|
||||
break;
|
||||
case MFX_FOURCC_R16:
|
||||
nbytes = 2*Width2*Height2;
|
||||
break;
|
||||
case MFX_FOURCC_P010:
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_P016:
|
||||
#endif
|
||||
nbytes = Width2*Height2 + (Width2>>1)*(Height2>>1) + (Width2>>1)*(Height2>>1);
|
||||
nbytes *= 2;
|
||||
break;
|
||||
case MFX_FOURCC_A2RGB10:
|
||||
nbytes = Width2*Height2*4; // 4 bytes per pixel
|
||||
break;
|
||||
case MFX_FOURCC_P210:
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case MFX_FOURCC_Y210:
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_Y216:
|
||||
nbytes = Width2*Height2 + (Width2>>1)*(Height2) + (Width2>>1)*(Height2);
|
||||
nbytes *= 2; // 16bits
|
||||
break;
|
||||
case MFX_FOURCC_Y416:
|
||||
nbytes = (Width2*Height2 + Width2*Height2 + Width2*Height2 + Width2*Height2) * 2;
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return nbytes;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::ReallocImpl(mfxMemId mid, const mfxFrameInfo *info, mfxU16 /*memType*/, mfxMemId *midOut)
|
||||
{
|
||||
if (!info || !midOut)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
if (!m_pBufferAllocator)
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
mfxU32 nbytes = GetSurfaceSize(info->FourCC, MSDK_ALIGN32(info->Width), MSDK_ALIGN32(info->Height));
|
||||
if(!nbytes)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
// pointer to the record in m_mids structure
|
||||
mfxMemId *pmid = GetMidHolder(mid);
|
||||
if (!pmid)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
mfxStatus sts = m_pBufferAllocator->Free(m_pBufferAllocator->pthis, *pmid);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
sts = m_pBufferAllocator->Alloc(m_pBufferAllocator->pthis,
|
||||
MSDK_ALIGN32(nbytes) + MSDK_ALIGN32(sizeof(sFrame)), MFX_MEMTYPE_SYSTEM_MEMORY, pmid);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
sFrame *fs;
|
||||
sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, *pmid, (mfxU8 **)&fs);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
fs->id = ID_FRAME;
|
||||
fs->info = *info;
|
||||
m_pBufferAllocator->Unlock(m_pBufferAllocator->pthis, *pmid);
|
||||
|
||||
*midOut = *pmid;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
if (!m_pBufferAllocator)
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
mfxU32 numAllocated = 0;
|
||||
|
||||
mfxU32 nbytes = GetSurfaceSize(request->Info.FourCC, MSDK_ALIGN32(request->Info.Width), MSDK_ALIGN32(request->Info.Height));
|
||||
if(!nbytes)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
std::unique_ptr<mfxMemId[]> mids(new mfxMemId[request->NumFrameSuggested]);
|
||||
|
||||
// allocate frames
|
||||
for (numAllocated = 0; numAllocated < request->NumFrameSuggested; numAllocated ++)
|
||||
{
|
||||
mfxStatus sts = m_pBufferAllocator->Alloc(m_pBufferAllocator->pthis,
|
||||
nbytes + MSDK_ALIGN32(sizeof(sFrame)), request->Type, &(mids[numAllocated]));
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
break;
|
||||
|
||||
sFrame *fs;
|
||||
sts = m_pBufferAllocator->Lock(m_pBufferAllocator->pthis, mids[numAllocated], (mfxU8 **)&fs);
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
break;
|
||||
|
||||
fs->id = ID_FRAME;
|
||||
fs->info = request->Info;
|
||||
sts = m_pBufferAllocator->Unlock(m_pBufferAllocator->pthis, mids[numAllocated]);
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
break;
|
||||
}
|
||||
|
||||
// check the number of allocated frames
|
||||
if (numAllocated < request->NumFrameSuggested)
|
||||
{
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
response->NumFrameActual = (mfxU16) numAllocated;
|
||||
response->mids = mids.release();
|
||||
|
||||
m_vResp.push_back(response);
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemFrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
|
||||
{
|
||||
if (!response)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
if (!m_pBufferAllocator)
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
if (response->mids)
|
||||
{
|
||||
for (mfxU32 i = 0; i < response->NumFrameActual; i++)
|
||||
{
|
||||
if (response->mids[i])
|
||||
{
|
||||
sts = m_pBufferAllocator->Free(m_pBufferAllocator->pthis, response->mids[i]);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_vResp.erase(std::remove(m_vResp.begin(), m_vResp.end(), response), m_vResp.end());
|
||||
delete [] response->mids;
|
||||
response->mids = 0;
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
SysMemBufferAllocator::SysMemBufferAllocator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
SysMemBufferAllocator::~SysMemBufferAllocator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
mfxStatus SysMemBufferAllocator::AllocBuffer(mfxU32 nbytes, mfxU16 type, mfxMemId *mid)
|
||||
{
|
||||
if (!mid)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
if (0 == (type & MFX_MEMTYPE_SYSTEM_MEMORY))
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
mfxU32 header_size = MSDK_ALIGN32(sizeof(sBuffer));
|
||||
mfxU8 *buffer_ptr = (mfxU8 *)calloc(header_size + nbytes + 32, 1);
|
||||
|
||||
if (!buffer_ptr)
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
|
||||
sBuffer *bs = (sBuffer *)buffer_ptr;
|
||||
bs->id = ID_BUFFER;
|
||||
bs->type = type;
|
||||
bs->nbytes = nbytes;
|
||||
*mid = (mfxHDL) bs;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemBufferAllocator::LockBuffer(mfxMemId mid, mfxU8 **ptr)
|
||||
{
|
||||
if (!ptr)
|
||||
return MFX_ERR_NULL_PTR;
|
||||
|
||||
sBuffer *bs = (sBuffer *)mid;
|
||||
|
||||
if (!bs)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
if (ID_BUFFER != bs->id)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
*ptr = (mfxU8*)((size_t)((mfxU8 *)bs+MSDK_ALIGN32(sizeof(sBuffer))+31)&(~((size_t)31)));
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemBufferAllocator::UnlockBuffer(mfxMemId mid)
|
||||
{
|
||||
sBuffer *bs = (sBuffer *)mid;
|
||||
|
||||
if (!bs || ID_BUFFER != bs->id)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus SysMemBufferAllocator::FreeBuffer(mfxMemId mid)
|
||||
{
|
||||
sBuffer *bs = (sBuffer *)mid;
|
||||
if (!bs || ID_BUFFER != bs->id)
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
free(bs);
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
357
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/v4l2_util.cpp
vendored
Normal file
357
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/v4l2_util.cpp
vendored
Normal file
@@ -0,0 +1,357 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined (ENABLE_V4L2_SUPPORT)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread.h>
|
||||
#include <poll.h>
|
||||
#include <signal.h>
|
||||
#include <assert.h>
|
||||
#include <linux/videodev2.h>
|
||||
#include "v4l2_util.h"
|
||||
|
||||
/* Global Declaration */
|
||||
Buffer *buffers, *CurBuffers;
|
||||
bool CtrlFlag = false;
|
||||
int m_q[5], m_first = 0, m_last = 0, m_numInQ = 0;
|
||||
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
pthread_mutex_t empty = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
v4l2Device::v4l2Device( const char *devname,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t num_buffers,
|
||||
enum AtomISPMode MipiMode,
|
||||
enum V4L2PixelFormat v4l2Format):
|
||||
m_devname(devname),
|
||||
m_height(height),
|
||||
m_width(width),
|
||||
m_num_buffers(num_buffers),
|
||||
m_MipiPort(0),
|
||||
m_MipiMode(MipiMode),
|
||||
m_v4l2Format(v4l2Format),
|
||||
m_fd(-1)
|
||||
{
|
||||
}
|
||||
|
||||
v4l2Device::~v4l2Device()
|
||||
{
|
||||
if (m_fd > -1)
|
||||
{
|
||||
BYE_ON(close(m_fd) < 0, "V4L2 device close failed: %s\n", ERRSTR);
|
||||
}
|
||||
}
|
||||
|
||||
int v4l2Device::blockIOCTL(int handle, int request, void *args)
|
||||
{
|
||||
int ioctlStatus;
|
||||
do
|
||||
{
|
||||
ioctlStatus = ioctl(handle, request, args);
|
||||
} while (-1 == ioctlStatus && EINTR == errno);
|
||||
return ioctlStatus;
|
||||
}
|
||||
|
||||
int v4l2Device::GetAtomISPModes(enum AtomISPMode mode)
|
||||
{
|
||||
switch(mode)
|
||||
{
|
||||
case VIDEO: return _ISP_MODE_VIDEO;
|
||||
case PREVIEW: return _ISP_MODE_PREVIEW;
|
||||
case CONTINUOUS: return _ISP_MODE_CONTINUOUS;
|
||||
case STILL: return _ISP_MODE_STILL;
|
||||
case NONE:
|
||||
|
||||
default:
|
||||
return _ISP_MODE_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
int v4l2Device::ConvertToMFXFourCC(enum V4L2PixelFormat v4l2Format)
|
||||
{
|
||||
switch (v4l2Format)
|
||||
{
|
||||
case UYVY: return MFX_FOURCC_UYVY;
|
||||
case YUY2: return MFX_FOURCC_YUY2;
|
||||
case NO_FORMAT:
|
||||
|
||||
default:
|
||||
assert( !"Unsupported mfx fourcc");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
int v4l2Device::ConvertToV4L2FourCC()
|
||||
{
|
||||
switch (m_v4l2Format)
|
||||
{
|
||||
case UYVY: return V4L2_PIX_FMT_UYVY;
|
||||
case YUY2: return V4L2_PIX_FMT_YUYV;
|
||||
case NO_FORMAT:
|
||||
|
||||
default:
|
||||
assert( !"Unsupported v4l2 fourcc");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void v4l2Device::Init( const char *devname,
|
||||
uint32_t width,
|
||||
uint32_t height,
|
||||
uint32_t num_buffers,
|
||||
enum V4L2PixelFormat v4l2Format,
|
||||
enum AtomISPMode MipiMode,
|
||||
int MipiPort)
|
||||
{
|
||||
|
||||
(devname != NULL)? m_devname = devname : m_devname;
|
||||
(m_width != width )? m_width = width : m_width;
|
||||
(m_height != height)? m_height = height : m_height;
|
||||
(m_num_buffers != num_buffers)? m_num_buffers = num_buffers : m_num_buffers;
|
||||
(m_v4l2Format != v4l2Format )? m_v4l2Format = v4l2Format : m_v4l2Format;
|
||||
(m_MipiMode != MipiMode )? m_MipiMode = MipiMode : m_MipiMode;
|
||||
(m_MipiPort != MipiPort )? m_MipiPort = MipiPort : m_MipiPort;
|
||||
|
||||
memset(&m_format, 0, sizeof m_format);
|
||||
m_format.width = m_width;
|
||||
m_format.height = m_height;
|
||||
m_format.pixelformat = ConvertToV4L2FourCC();
|
||||
|
||||
V4L2Init();
|
||||
}
|
||||
|
||||
void v4l2Device::V4L2Init()
|
||||
{
|
||||
int ret;
|
||||
struct v4l2_format fmt;
|
||||
struct v4l2_capability caps;
|
||||
struct v4l2_streamparm parm;
|
||||
struct v4l2_requestbuffers rqbufs;
|
||||
CLEAR(parm);
|
||||
|
||||
m_fd = open(m_devname, O_RDWR);
|
||||
BYE_ON(m_fd < 0, "failed to open %s: %s\n", m_devname, ERRSTR);
|
||||
CLEAR(caps);
|
||||
|
||||
/* Specifically for setting up mipi configuration. DMABUFF is
|
||||
* also enable by default here.
|
||||
*/
|
||||
if (m_MipiPort > -1 && m_MipiMode != NONE) {
|
||||
parm.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
parm.parm.capture.capturemode = GetAtomISPModes(m_MipiMode);
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_S_INPUT, &m_MipiPort);
|
||||
BYE_ON(ret < 0, "VIDIOC_S_INPUT failed: %s\n", ERRSTR);
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_S_PARM, &parm);
|
||||
BYE_ON(ret < 0, "VIDIOC_S_PARAM failed: %s\n", ERRSTR);
|
||||
}
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_QUERYCAP, &caps);
|
||||
msdk_printf( "Driver Caps:\n"
|
||||
" Driver: \"%s\"\n"
|
||||
" Card: \"%s\"\n"
|
||||
" Bus: \"%s\"\n"
|
||||
" Version: %d.%d\n"
|
||||
" Capabilities: %08x\n",
|
||||
caps.driver,
|
||||
caps.card,
|
||||
caps.bus_info,
|
||||
(caps.version>>16)&&0xff,
|
||||
(caps.version>>24)&&0xff,
|
||||
caps.capabilities);
|
||||
|
||||
BYE_ON(ret, "VIDIOC_QUERYCAP failed: %s\n", ERRSTR);
|
||||
BYE_ON(~caps.capabilities & V4L2_CAP_VIDEO_CAPTURE,
|
||||
"video: singleplanar capture is not supported\n");
|
||||
|
||||
CLEAR(fmt);
|
||||
fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
ret = blockIOCTL(m_fd, VIDIOC_G_FMT, &fmt);
|
||||
|
||||
BYE_ON(ret < 0, "VIDIOC_G_FMT failed: %s\n", ERRSTR);
|
||||
|
||||
msdk_printf("G_FMT(start): width = %u, height = %u, 4cc = %.4s, BPP = %u sizeimage = %d field = %d\n",
|
||||
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
||||
(char*)&fmt.fmt.pix.pixelformat,
|
||||
fmt.fmt.pix.bytesperline,
|
||||
fmt.fmt.pix.sizeimage,
|
||||
fmt.fmt.pix.field);
|
||||
|
||||
fmt.fmt.pix = m_format;
|
||||
|
||||
msdk_printf("G_FMT(pre): width = %u, height = %u, 4cc = %.4s, BPP = %u sizeimage = %d field = %d\n",
|
||||
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
||||
(char*)&fmt.fmt.pix.pixelformat,
|
||||
fmt.fmt.pix.bytesperline,
|
||||
fmt.fmt.pix.sizeimage,
|
||||
fmt.fmt.pix.field);
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_S_FMT, &fmt);
|
||||
BYE_ON(ret < 0, "VIDIOC_S_FMT failed: %s\n", ERRSTR);
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_G_FMT, &fmt);
|
||||
BYE_ON(ret < 0, "VIDIOC_G_FMT failed: %s\n", ERRSTR);
|
||||
msdk_printf("G_FMT(final): width = %u, height = %u, 4cc = %.4s, BPP = %u\n",
|
||||
fmt.fmt.pix.width, fmt.fmt.pix.height,
|
||||
(char*)&fmt.fmt.pix.pixelformat,
|
||||
fmt.fmt.pix.bytesperline);
|
||||
|
||||
CLEAR(rqbufs);
|
||||
rqbufs.count = m_num_buffers;
|
||||
rqbufs.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
rqbufs.memory = V4L2_MEMORY_DMABUF;
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_REQBUFS, &rqbufs);
|
||||
BYE_ON(ret < 0, "VIDIOC_REQBUFS failed: %s\n", ERRSTR);
|
||||
BYE_ON(rqbufs.count < m_num_buffers, "video node allocated only "
|
||||
"%u of %u buffers\n", rqbufs.count, m_num_buffers);
|
||||
|
||||
m_format = fmt.fmt.pix;
|
||||
}
|
||||
|
||||
void v4l2Device::V4L2Alloc()
|
||||
{
|
||||
buffers = (Buffer *)malloc(sizeof(Buffer) * (int) m_num_buffers);
|
||||
}
|
||||
|
||||
void v4l2Device::V4L2QueueBuffer(Buffer *buffer)
|
||||
{
|
||||
struct v4l2_buffer buf;
|
||||
int ret;
|
||||
|
||||
memset(&buf, 0, sizeof buf);
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_DMABUF;
|
||||
buf.index = buffer->index;
|
||||
buf.m.fd = buffer->fd;
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_QBUF, &buf);
|
||||
BYE_ON(ret < 0, "VIDIOC_QBUF for buffer %d failed: %s (fd %u) (i %u)\n",
|
||||
buf.index, ERRSTR, buffer->fd, buffer->index);
|
||||
}
|
||||
|
||||
Buffer *v4l2Device::V4L2DeQueueBuffer(Buffer *buffer)
|
||||
{
|
||||
struct v4l2_buffer buf;
|
||||
int ret;
|
||||
|
||||
memset(&buf, 0, sizeof buf);
|
||||
|
||||
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
buf.memory = V4L2_MEMORY_DMABUF;
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_DQBUF, &buf);
|
||||
BYE_ON(ret, "VIDIOC_DQBUF failed: %s\n", ERRSTR);
|
||||
|
||||
return &buffer[buf.index];
|
||||
}
|
||||
|
||||
void v4l2Device::V4L2StartCapture()
|
||||
{
|
||||
int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
int ret = 0;
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_STREAMON, &type);
|
||||
BYE_ON(ret < 0, "STREAMON failed: %s\n", ERRSTR);
|
||||
}
|
||||
|
||||
void v4l2Device::V4L2StopCapture()
|
||||
{
|
||||
int type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
|
||||
int ret = 0;
|
||||
|
||||
ret = blockIOCTL(m_fd, VIDIOC_STREAMOFF, &type);
|
||||
BYE_ON(ret < 0, "STREAMOFF failed: %s\n", ERRSTR);
|
||||
}
|
||||
|
||||
void v4l2Device::PutOnQ(int x)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
m_q[m_first] = x;
|
||||
m_first = (m_first+1) % 5;
|
||||
m_numInQ++;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
pthread_mutex_unlock(&empty);
|
||||
}
|
||||
|
||||
int v4l2Device::GetOffQ()
|
||||
{
|
||||
int thing;
|
||||
|
||||
/* wait if the queue is empty. */
|
||||
while (m_numInQ == 0)
|
||||
pthread_mutex_lock(&empty);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
thing = m_q[m_last];
|
||||
m_last = (m_last+1) % 5;
|
||||
m_numInQ--;
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
return thing;
|
||||
}
|
||||
|
||||
int v4l2Device::GetV4L2TerminationSignal()
|
||||
{
|
||||
return (CtrlFlag && m_numInQ == 0)? 1 : 0;
|
||||
}
|
||||
|
||||
static void CtrlCTerminationHandler(int s) { CtrlFlag = true; }
|
||||
|
||||
void *PollingThread(void *data)
|
||||
{
|
||||
|
||||
v4l2Device *v4l2 = (v4l2Device *)data;
|
||||
|
||||
struct sigaction sigIntHandler;
|
||||
sigIntHandler.sa_handler = CtrlCTerminationHandler;
|
||||
sigemptyset(&sigIntHandler.sa_mask);
|
||||
sigIntHandler.sa_flags = 0;
|
||||
sigaction(SIGINT, &sigIntHandler, NULL);
|
||||
|
||||
struct pollfd fd;
|
||||
fd.fd = v4l2->GetV4L2DisplayID();
|
||||
fd.events = POLLIN;
|
||||
|
||||
while(1)
|
||||
{
|
||||
if (poll(&fd, 1, 5000) > 0)
|
||||
{
|
||||
if (fd.revents & POLLIN)
|
||||
{
|
||||
CurBuffers = v4l2->V4L2DeQueueBuffer(buffers);
|
||||
v4l2->PutOnQ(CurBuffers->index);
|
||||
|
||||
if (CtrlFlag)
|
||||
break;
|
||||
|
||||
if (CurBuffers)
|
||||
v4l2->V4L2QueueBuffer(&buffers[CurBuffers->index]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif // ifdef ENABLE_V4L2_SUPPORT
|
||||
747
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_allocator.cpp
vendored
Normal file
747
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_allocator.cpp
vendored
Normal file
@@ -0,0 +1,747 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined(LIBVA_SUPPORT)
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "vaapi_allocator.h"
|
||||
#include "vaapi_utils.h"
|
||||
|
||||
enum {
|
||||
MFX_FOURCC_VP8_NV12 = MFX_MAKEFOURCC('V','P','8','N'),
|
||||
MFX_FOURCC_VP8_MBDATA = MFX_MAKEFOURCC('V','P','8','M'),
|
||||
MFX_FOURCC_VP8_SEGMAP = MFX_MAKEFOURCC('V','P','8','S'),
|
||||
};
|
||||
|
||||
unsigned int ConvertMfxFourccToVAFormat(mfxU32 fourcc)
|
||||
{
|
||||
switch (fourcc)
|
||||
{
|
||||
case MFX_FOURCC_NV12:
|
||||
return VA_FOURCC_NV12;
|
||||
case MFX_FOURCC_YUY2:
|
||||
return VA_FOURCC_YUY2;
|
||||
case MFX_FOURCC_UYVY:
|
||||
return VA_FOURCC_UYVY;
|
||||
case MFX_FOURCC_YV12:
|
||||
return VA_FOURCC_YV12;
|
||||
#if (MFX_VERSION >= 1028)
|
||||
case MFX_FOURCC_RGB565:
|
||||
return VA_FOURCC_RGB565;
|
||||
#endif
|
||||
case MFX_FOURCC_RGB4:
|
||||
return VA_FOURCC_ARGB;
|
||||
case MFX_FOURCC_BGR4:
|
||||
return VA_FOURCC_ABGR;
|
||||
case MFX_FOURCC_RGBP:
|
||||
return VA_FOURCC_RGBP;
|
||||
case MFX_FOURCC_P8:
|
||||
return VA_FOURCC_P208;
|
||||
case MFX_FOURCC_P010:
|
||||
return VA_FOURCC_P010;
|
||||
case MFX_FOURCC_A2RGB10:
|
||||
return VA_FOURCC_ARGB; // rt format will be VA_RT_FORMAT_RGB32_10BPP
|
||||
case MFX_FOURCC_AYUV:
|
||||
return VA_FOURCC_AYUV;
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case MFX_FOURCC_Y210:
|
||||
return VA_FOURCC_Y210;
|
||||
case MFX_FOURCC_Y410:
|
||||
return VA_FOURCC_Y410;
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case MFX_FOURCC_P016:
|
||||
return VA_FOURCC_P016;
|
||||
case MFX_FOURCC_Y216:
|
||||
return VA_FOURCC_Y216;
|
||||
case MFX_FOURCC_Y416:
|
||||
return VA_FOURCC_Y416;
|
||||
#endif
|
||||
default:
|
||||
assert(!"unsupported fourcc");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
unsigned int ConvertVP8FourccToMfxFourcc(mfxU32 fourcc)
|
||||
{
|
||||
switch (fourcc)
|
||||
{
|
||||
case MFX_FOURCC_VP8_NV12:
|
||||
case MFX_FOURCC_VP8_MBDATA:
|
||||
return MFX_FOURCC_NV12;
|
||||
case MFX_FOURCC_VP8_SEGMAP:
|
||||
return MFX_FOURCC_P8;
|
||||
|
||||
default:
|
||||
return fourcc;
|
||||
}
|
||||
}
|
||||
|
||||
vaapiFrameAllocator::vaapiFrameAllocator()
|
||||
: m_dpy(0)
|
||||
, m_libva(new MfxLoader::VA_Proxy)
|
||||
, m_export_mode(vaapiAllocatorParams::DONOT_EXPORT)
|
||||
, m_exporter(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
vaapiFrameAllocator::~vaapiFrameAllocator()
|
||||
{
|
||||
Close();
|
||||
delete m_libva;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::Init(mfxAllocatorParams *pParams)
|
||||
{
|
||||
vaapiAllocatorParams* p_vaapiParams = dynamic_cast<vaapiAllocatorParams*>(pParams);
|
||||
|
||||
if ((NULL == p_vaapiParams) || (NULL == p_vaapiParams->m_dpy))
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
if ((p_vaapiParams->m_export_mode != vaapiAllocatorParams::DONOT_EXPORT) &&
|
||||
!(p_vaapiParams->m_export_mode & vaapiAllocatorParams::FLINK) &&
|
||||
!(p_vaapiParams->m_export_mode & vaapiAllocatorParams::PRIME) &&
|
||||
!(p_vaapiParams->m_export_mode & vaapiAllocatorParams::CUSTOM))
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
if ((p_vaapiParams->m_export_mode & vaapiAllocatorParams::CUSTOM) &&
|
||||
!p_vaapiParams->m_exporter)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
m_dpy = p_vaapiParams->m_dpy;
|
||||
m_export_mode = p_vaapiParams->m_export_mode;
|
||||
m_exporter = p_vaapiParams->m_exporter;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::CheckRequestType(mfxFrameAllocRequest *request)
|
||||
{
|
||||
mfxStatus sts = BaseFrameAllocator::CheckRequestType(request);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
return sts;
|
||||
|
||||
if ((request->Type & (MFX_MEMTYPE_VIDEO_MEMORY_DECODER_TARGET | MFX_MEMTYPE_VIDEO_MEMORY_PROCESSOR_TARGET)) != 0)
|
||||
return MFX_ERR_NONE;
|
||||
else
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::Close()
|
||||
{
|
||||
return BaseFrameAllocator::Close();
|
||||
}
|
||||
|
||||
static mfxStatus GetVAFourcc(mfxU32 fourcc, unsigned int &va_fourcc)
|
||||
{
|
||||
// VP8 hybrid driver has weird requirements for allocation of surfaces/buffers for VP8 encoding
|
||||
// to comply with them additional logic is required to support regular and VP8 hybrid allocation pathes
|
||||
mfxU32 mfx_fourcc = ConvertVP8FourccToMfxFourcc(fourcc);
|
||||
va_fourcc = ConvertMfxFourccToVAFormat(mfx_fourcc);
|
||||
if (!va_fourcc || ((VA_FOURCC_NV12 != va_fourcc) &&
|
||||
(VA_FOURCC_YV12 != va_fourcc) &&
|
||||
(VA_FOURCC_YUY2 != va_fourcc) &&
|
||||
(VA_FOURCC_ARGB != va_fourcc) &&
|
||||
(VA_FOURCC_ABGR != va_fourcc) &&
|
||||
(VA_FOURCC_RGBP != va_fourcc) &&
|
||||
(VA_FOURCC_P208 != va_fourcc) &&
|
||||
(VA_FOURCC_P010 != va_fourcc) &&
|
||||
(VA_FOURCC_YUY2 != va_fourcc) &&
|
||||
#if (MFX_VERSION >= 1027)
|
||||
(VA_FOURCC_Y210 != va_fourcc) &&
|
||||
(VA_FOURCC_Y410 != va_fourcc) &&
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1028)
|
||||
(VA_FOURCC_RGB565 != va_fourcc) &&
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
(VA_FOURCC_P016 != va_fourcc) &&
|
||||
(VA_FOURCC_Y216 != va_fourcc) &&
|
||||
(VA_FOURCC_Y416 != va_fourcc) &&
|
||||
#endif
|
||||
(VA_FOURCC_AYUV != va_fourcc)))
|
||||
{
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::ReallocImpl(mfxMemId mid, const mfxFrameInfo *info, mfxU16 memType, mfxMemId *midOut)
|
||||
{
|
||||
if (!info || !midOut) return MFX_ERR_NULL_PTR;
|
||||
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
VAStatus va_res = VA_STATUS_SUCCESS;
|
||||
unsigned int va_fourcc = 0;
|
||||
mfxU32 fourcc = info->FourCC;
|
||||
|
||||
mfx_res = GetVAFourcc(fourcc, va_fourcc);
|
||||
if (MFX_ERR_NONE != mfx_res)
|
||||
return mfx_res;
|
||||
|
||||
mfxU32 Width = info->Width;
|
||||
mfxU32 Height = info->Height;
|
||||
|
||||
if (VA_FOURCC_P208 == va_fourcc)
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
VASurfaceID surfaces[1];
|
||||
VASurfaceAttrib attrib[2];
|
||||
vaapiMemId *vaapiMid = (vaapiMemId *)mid;
|
||||
surfaces[0] = *vaapiMid->m_surface;
|
||||
m_libva->vaDestroySurfaces(m_dpy, surfaces, 1);
|
||||
|
||||
unsigned int format;
|
||||
int attrCnt = 0;
|
||||
|
||||
attrib[attrCnt].type = VASurfaceAttribPixelFormat;
|
||||
attrib[attrCnt].flags = VA_SURFACE_ATTRIB_SETTABLE;
|
||||
attrib[attrCnt].value.type = VAGenericValueTypeInteger;
|
||||
attrib[attrCnt++].value.value.i = va_fourcc;
|
||||
format = va_fourcc;
|
||||
|
||||
if ((fourcc == MFX_FOURCC_VP8_NV12) ||
|
||||
((MFX_MEMTYPE_VIDEO_MEMORY_ENCODER_TARGET & memType)
|
||||
&& ((fourcc == MFX_FOURCC_RGB4) || (fourcc == MFX_FOURCC_BGR4))))
|
||||
{
|
||||
/*
|
||||
* special configuration for NV12 surf allocation for VP8 hybrid encoder and
|
||||
* RGB32 for JPEG is required
|
||||
*/
|
||||
attrib[attrCnt].type = (VASurfaceAttribType)VASurfaceAttribUsageHint;
|
||||
attrib[attrCnt].flags = VA_SURFACE_ATTRIB_SETTABLE;
|
||||
attrib[attrCnt].value.type = VAGenericValueTypeInteger;
|
||||
attrib[attrCnt++].value.value.i = VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER;
|
||||
}
|
||||
else if (fourcc == MFX_FOURCC_VP8_MBDATA)
|
||||
{
|
||||
// special configuration for MB data surf allocation for VP8 hybrid encoder is required
|
||||
attrib[0].value.value.i = VA_FOURCC_P208;
|
||||
format = VA_FOURCC_P208;
|
||||
}
|
||||
else if (va_fourcc == VA_FOURCC_NV12)
|
||||
{
|
||||
format = VA_RT_FORMAT_YUV420;
|
||||
}
|
||||
|
||||
va_res = m_libva->vaCreateSurfaces(m_dpy,
|
||||
format,
|
||||
Width, Height,
|
||||
surfaces,
|
||||
1,
|
||||
&attrib[0], attrCnt);
|
||||
|
||||
*vaapiMid->m_surface = surfaces[0];
|
||||
vaapiMid->m_fourcc = fourcc;
|
||||
*midOut = mid;
|
||||
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::AllocImpl(mfxFrameAllocRequest *request, mfxFrameAllocResponse *response)
|
||||
{
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
VAStatus va_res = VA_STATUS_SUCCESS;
|
||||
unsigned int va_fourcc = 0;
|
||||
VASurfaceID* surfaces = NULL;
|
||||
vaapiMemId *vaapi_mids = NULL, *vaapi_mid = NULL;
|
||||
mfxMemId* mids = NULL;
|
||||
mfxU32 fourcc = request->Info.FourCC;
|
||||
mfxU16 surfaces_num = request->NumFrameSuggested, numAllocated = 0, i = 0;
|
||||
bool bCreateSrfSucceeded = false;
|
||||
|
||||
memset(response, 0, sizeof(mfxFrameAllocResponse));
|
||||
|
||||
mfx_res = GetVAFourcc(fourcc, va_fourcc);
|
||||
if (MFX_ERR_NONE != mfx_res)
|
||||
return mfx_res;
|
||||
|
||||
if (!surfaces_num)
|
||||
{
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
surfaces = (VASurfaceID*)calloc(surfaces_num, sizeof(VASurfaceID));
|
||||
vaapi_mids = (vaapiMemId*)calloc(surfaces_num, sizeof(vaapiMemId));
|
||||
mids = (mfxMemId*)calloc(surfaces_num, sizeof(mfxMemId));
|
||||
if ((NULL == surfaces) || (NULL == vaapi_mids) || (NULL == mids)) mfx_res = MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
if( VA_FOURCC_P208 != va_fourcc )
|
||||
{
|
||||
unsigned int format;
|
||||
VASurfaceAttrib attrib[2];
|
||||
int attrCnt = 0;
|
||||
|
||||
attrib[attrCnt].type = VASurfaceAttribPixelFormat;
|
||||
attrib[attrCnt].flags = VA_SURFACE_ATTRIB_SETTABLE;
|
||||
attrib[attrCnt].value.type = VAGenericValueTypeInteger;
|
||||
attrib[attrCnt++].value.value.i = va_fourcc;
|
||||
format = va_fourcc;
|
||||
|
||||
if (fourcc == MFX_FOURCC_VP8_NV12)
|
||||
{
|
||||
// special configuration for NV12 surf allocation for VP8 hybrid encoder is required
|
||||
attrib[attrCnt].type = (VASurfaceAttribType)VASurfaceAttribUsageHint;
|
||||
attrib[attrCnt].flags = VA_SURFACE_ATTRIB_SETTABLE;
|
||||
attrib[attrCnt].value.type = VAGenericValueTypeInteger;
|
||||
attrib[attrCnt++].value.value.i = VA_SURFACE_ATTRIB_USAGE_HINT_ENCODER;
|
||||
}
|
||||
else if (fourcc == MFX_FOURCC_VP8_MBDATA)
|
||||
{
|
||||
// special configuration for MB data surf allocation for VP8 hybrid encoder is required
|
||||
attrib[0].value.value.i = VA_FOURCC_P208;
|
||||
format = VA_FOURCC_P208;
|
||||
}
|
||||
else if (va_fourcc == VA_FOURCC_NV12)
|
||||
{
|
||||
format = VA_RT_FORMAT_YUV420;
|
||||
}
|
||||
else if ((va_fourcc == VA_FOURCC_UYVY) || (va_fourcc == VA_FOURCC_YUY2))
|
||||
{
|
||||
format = VA_RT_FORMAT_YUV422;
|
||||
}
|
||||
else if (fourcc == MFX_FOURCC_A2RGB10)
|
||||
{
|
||||
format = VA_RT_FORMAT_RGB32_10BPP;
|
||||
}
|
||||
else if (fourcc == MFX_FOURCC_RGBP)
|
||||
{
|
||||
format = VA_RT_FORMAT_RGBP;
|
||||
}
|
||||
|
||||
va_res = m_libva->vaCreateSurfaces(m_dpy,
|
||||
format,
|
||||
request->Info.Width, request->Info.Height,
|
||||
surfaces,
|
||||
surfaces_num,
|
||||
&attrib[0], attrCnt);
|
||||
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
bCreateSrfSucceeded = (MFX_ERR_NONE == mfx_res);
|
||||
}
|
||||
else
|
||||
{
|
||||
VAContextID context_id = request->AllocId;
|
||||
int codedbuf_size, codedbuf_num;
|
||||
|
||||
VABufferType codedbuf_type;
|
||||
if (fourcc == MFX_FOURCC_VP8_SEGMAP)
|
||||
{
|
||||
codedbuf_size = request->Info.Width;
|
||||
codedbuf_num = request->Info.Height;
|
||||
codedbuf_type = VAEncMacroblockMapBufferType;
|
||||
}
|
||||
else
|
||||
{
|
||||
int width32 = 32 * ((request->Info.Width + 31) >> 5);
|
||||
int height32 = 32 * ((request->Info.Height + 31) >> 5);
|
||||
codedbuf_size = static_cast<int>((width32 * height32) * 400LL / (16 * 16));
|
||||
codedbuf_num = 1;
|
||||
codedbuf_type = VAEncCodedBufferType;
|
||||
}
|
||||
|
||||
for (numAllocated = 0; numAllocated < surfaces_num; numAllocated++)
|
||||
{
|
||||
VABufferID coded_buf;
|
||||
|
||||
va_res = m_libva->vaCreateBuffer(m_dpy,
|
||||
context_id,
|
||||
codedbuf_type,
|
||||
codedbuf_size,
|
||||
codedbuf_num,
|
||||
NULL,
|
||||
&coded_buf);
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
if (MFX_ERR_NONE != mfx_res) break;
|
||||
surfaces[numAllocated] = coded_buf;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((MFX_ERR_NONE == mfx_res) &&
|
||||
(request->Type & MFX_MEMTYPE_EXPORT_FRAME))
|
||||
{
|
||||
if (m_export_mode == vaapiAllocatorParams::DONOT_EXPORT) {
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
}
|
||||
for (i=0; i < surfaces_num; ++i)
|
||||
{
|
||||
if (m_export_mode & vaapiAllocatorParams::NATIVE_EXPORT_MASK) {
|
||||
vaapi_mids[i].m_buffer_info.mem_type = (m_export_mode & vaapiAllocatorParams::PRIME)?
|
||||
VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME: VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM;
|
||||
va_res = m_libva->vaDeriveImage(m_dpy, surfaces[i], &(vaapi_mids[i].m_image));
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
|
||||
if (MFX_ERR_NONE != mfx_res) break;
|
||||
|
||||
va_res = m_libva->vaAcquireBufferHandle(m_dpy, vaapi_mids[i].m_image.buf, &(vaapi_mids[i].m_buffer_info));
|
||||
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
|
||||
if (MFX_ERR_NONE != mfx_res) {
|
||||
m_libva->vaDestroyImage(m_dpy, vaapi_mids[i].m_image.image_id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (m_exporter) {
|
||||
vaapi_mids[i].m_fourcc = va_fourcc;
|
||||
vaapi_mids[i].m_custom = m_exporter->acquire(&vaapi_mids[i]);
|
||||
if (!vaapi_mids[i].m_custom) {
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
for (i = 0; i < surfaces_num; ++i)
|
||||
{
|
||||
vaapi_mid = &(vaapi_mids[i]);
|
||||
vaapi_mid->m_fourcc = fourcc;
|
||||
vaapi_mid->m_surface = &(surfaces[i]);
|
||||
mids[i] = vaapi_mid;
|
||||
}
|
||||
}
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
response->mids = mids;
|
||||
response->NumFrameActual = surfaces_num;
|
||||
}
|
||||
else // i.e. MFX_ERR_NONE != mfx_res
|
||||
{
|
||||
response->mids = NULL;
|
||||
response->NumFrameActual = 0;
|
||||
if (VA_FOURCC_P208 != va_fourcc
|
||||
|| fourcc == MFX_FOURCC_VP8_MBDATA )
|
||||
{
|
||||
if (bCreateSrfSucceeded)
|
||||
m_libva->vaDestroySurfaces(m_dpy, surfaces, surfaces_num);
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i = 0; i < numAllocated; i++)
|
||||
m_libva->vaDestroyBuffer(m_dpy, surfaces[i]);
|
||||
}
|
||||
if (mids)
|
||||
{
|
||||
free(mids);
|
||||
mids = NULL;
|
||||
}
|
||||
if (vaapi_mids) { free(vaapi_mids); vaapi_mids = NULL; }
|
||||
if (surfaces) { free(surfaces); surfaces = NULL; }
|
||||
}
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::ReleaseResponse(mfxFrameAllocResponse *response)
|
||||
{
|
||||
vaapiMemId *vaapi_mids = NULL;
|
||||
VASurfaceID* surfaces = NULL;
|
||||
mfxU32 i = 0;
|
||||
bool isBitstreamMemory=false;
|
||||
|
||||
if (!response) return MFX_ERR_NULL_PTR;
|
||||
|
||||
if (response->mids)
|
||||
{
|
||||
vaapi_mids = (vaapiMemId*)(response->mids[0]);
|
||||
mfxU32 mfx_fourcc = ConvertVP8FourccToMfxFourcc(vaapi_mids->m_fourcc);
|
||||
isBitstreamMemory = (MFX_FOURCC_P8 == mfx_fourcc)?true:false;
|
||||
surfaces = vaapi_mids->m_surface;
|
||||
for (i = 0; i < response->NumFrameActual; ++i)
|
||||
{
|
||||
if (MFX_FOURCC_P8 == vaapi_mids[i].m_fourcc) m_libva->vaDestroyBuffer(m_dpy, surfaces[i]);
|
||||
else if (vaapi_mids[i].m_sys_buffer) free(vaapi_mids[i].m_sys_buffer);
|
||||
if (m_export_mode != vaapiAllocatorParams::DONOT_EXPORT) {
|
||||
if (m_exporter && vaapi_mids[i].m_custom) {
|
||||
m_exporter->release(&vaapi_mids[i], vaapi_mids[i].m_custom);
|
||||
}
|
||||
if (m_export_mode & vaapiAllocatorParams::NATIVE_EXPORT_MASK) {
|
||||
m_libva->vaReleaseBufferHandle(m_dpy, vaapi_mids[i].m_image.buf);
|
||||
m_libva->vaDestroyImage(m_dpy, vaapi_mids[i].m_image.image_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
free(vaapi_mids);
|
||||
free(response->mids);
|
||||
response->mids = NULL;
|
||||
|
||||
if (!isBitstreamMemory) m_libva->vaDestroySurfaces(m_dpy, surfaces, response->NumFrameActual);
|
||||
free(surfaces);
|
||||
}
|
||||
response->NumFrameActual = 0;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::LockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
VAStatus va_res = VA_STATUS_SUCCESS;
|
||||
vaapiMemId* vaapi_mid = (vaapiMemId*)mid;
|
||||
mfxU8* pBuffer = 0;
|
||||
|
||||
if (!vaapi_mid || !(vaapi_mid->m_surface)) return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
mfxU32 mfx_fourcc = ConvertVP8FourccToMfxFourcc(vaapi_mid->m_fourcc);
|
||||
|
||||
if (MFX_FOURCC_P8 == mfx_fourcc) // bitstream processing
|
||||
{
|
||||
VACodedBufferSegment *coded_buffer_segment;
|
||||
if (vaapi_mid->m_fourcc == MFX_FOURCC_VP8_SEGMAP)
|
||||
va_res = m_libva->vaMapBuffer(m_dpy, *(vaapi_mid->m_surface), (void **)(&pBuffer));
|
||||
else
|
||||
va_res = m_libva->vaMapBuffer(m_dpy, *(vaapi_mid->m_surface), (void **)(&coded_buffer_segment));
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
if (vaapi_mid->m_fourcc == MFX_FOURCC_VP8_SEGMAP)
|
||||
ptr->Y = pBuffer;
|
||||
else
|
||||
ptr->Y = (mfxU8*)coded_buffer_segment->buf;
|
||||
|
||||
}
|
||||
}
|
||||
else // Image processing
|
||||
{
|
||||
va_res = m_libva->vaDeriveImage(m_dpy, *(vaapi_mid->m_surface), &(vaapi_mid->m_image));
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
va_res = m_libva->vaMapBuffer(m_dpy, vaapi_mid->m_image.buf, (void **)&pBuffer);
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
}
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
switch (vaapi_mid->m_image.format.fourcc)
|
||||
{
|
||||
case VA_FOURCC_NV12:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->Y = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->U = pBuffer + vaapi_mid->m_image.offsets[1];
|
||||
ptr->V = ptr->U + 1;
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_YV12:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->Y = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->V = pBuffer + vaapi_mid->m_image.offsets[1];
|
||||
ptr->U = pBuffer + vaapi_mid->m_image.offsets[2];
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_YUY2:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->Y = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->U = ptr->Y + 1;
|
||||
ptr->V = ptr->Y + 3;
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_UYVY:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->U = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->Y = ptr->U + 1;
|
||||
ptr->V = ptr->U + 2;
|
||||
}
|
||||
break;
|
||||
#if (MFX_VERSION >= 1028)
|
||||
case VA_FOURCC_RGB565:
|
||||
if (mfx_fourcc == MFX_FOURCC_RGB565)
|
||||
{
|
||||
ptr->B = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->G = ptr->B;
|
||||
ptr->R = ptr->B;
|
||||
}
|
||||
else return MFX_ERR_LOCK_MEMORY;
|
||||
break;
|
||||
#endif
|
||||
case VA_FOURCC_ARGB:
|
||||
if (mfx_fourcc == MFX_FOURCC_RGB4)
|
||||
{
|
||||
ptr->B = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->G = ptr->B + 1;
|
||||
ptr->R = ptr->B + 2;
|
||||
ptr->A = ptr->B + 3;
|
||||
}
|
||||
else return MFX_ERR_LOCK_MEMORY;
|
||||
break;
|
||||
#ifndef ANDROID
|
||||
case VA_FOURCC_A2R10G10B10:
|
||||
if (mfx_fourcc == MFX_FOURCC_A2RGB10)
|
||||
{
|
||||
ptr->B = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->G = ptr->B;
|
||||
ptr->R = ptr->B;
|
||||
ptr->A = ptr->B;
|
||||
}
|
||||
else return MFX_ERR_LOCK_MEMORY;
|
||||
break;
|
||||
#endif
|
||||
case VA_FOURCC_ABGR:
|
||||
if (mfx_fourcc == MFX_FOURCC_BGR4)
|
||||
{
|
||||
ptr->R = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->G = pBuffer + vaapi_mid->m_image.offsets[1];
|
||||
ptr->B = pBuffer + vaapi_mid->m_image.offsets[2];
|
||||
ptr->A = ptr->R + 3;
|
||||
}
|
||||
else return MFX_ERR_LOCK_MEMORY;
|
||||
break;
|
||||
case VA_FOURCC_RGBP:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->B = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->G = pBuffer + vaapi_mid->m_image.offsets[1];
|
||||
ptr->R = pBuffer + vaapi_mid->m_image.offsets[2];
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_P208:
|
||||
if (mfx_fourcc == MFX_FOURCC_NV12)
|
||||
{
|
||||
ptr->Y = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
}
|
||||
else return MFX_ERR_LOCK_MEMORY;
|
||||
break;
|
||||
case VA_FOURCC_P010:
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case VA_FOURCC_P016:
|
||||
#endif
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->Y16 = (mfxU16 *) (pBuffer + vaapi_mid->m_image.offsets[0]);
|
||||
ptr->U16 = (mfxU16 *) (pBuffer + vaapi_mid->m_image.offsets[1]);
|
||||
ptr->V16 = ptr->U16 + 1;
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_AYUV:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->V = pBuffer + vaapi_mid->m_image.offsets[0];
|
||||
ptr->U = ptr->V + 1;
|
||||
ptr->Y = ptr->V + 2;
|
||||
ptr->A = ptr->V + 3;
|
||||
}
|
||||
break;
|
||||
#if (MFX_VERSION >= 1027)
|
||||
case VA_FOURCC_Y210:
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case VA_FOURCC_Y216:
|
||||
#endif
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->Y16 = (mfxU16 *) (pBuffer + vaapi_mid->m_image.offsets[0]);
|
||||
ptr->U16 = ptr->Y16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 3;
|
||||
}
|
||||
break;
|
||||
case VA_FOURCC_Y410:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->Y410 = (mfxY410 *)(pBuffer + vaapi_mid->m_image.offsets[0]);
|
||||
ptr->Y = 0;
|
||||
ptr->V = 0;
|
||||
ptr->A = 0;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
#if (MFX_VERSION >= 1031)
|
||||
case VA_FOURCC_Y416:
|
||||
if (mfx_fourcc != vaapi_mid->m_image.format.fourcc) return MFX_ERR_LOCK_MEMORY;
|
||||
|
||||
{
|
||||
ptr->U16 = (mfxU16 *) (pBuffer + vaapi_mid->m_image.offsets[0]);
|
||||
ptr->Y16 = ptr->U16 + 1;
|
||||
ptr->V16 = ptr->Y16 + 1;
|
||||
ptr->A = (mfxU8 *)(ptr->V16 + 1);
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
return MFX_ERR_LOCK_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
ptr->PitchHigh = (mfxU16)(vaapi_mid->m_image.pitches[0] / (1 << 16));
|
||||
ptr->PitchLow = (mfxU16)(vaapi_mid->m_image.pitches[0] % (1 << 16));
|
||||
}
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::UnlockFrame(mfxMemId mid, mfxFrameData *ptr)
|
||||
{
|
||||
vaapiMemId* vaapi_mid = (vaapiMemId*)mid;
|
||||
|
||||
if (!vaapi_mid || !(vaapi_mid->m_surface)) return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
mfxU32 mfx_fourcc = ConvertVP8FourccToMfxFourcc(vaapi_mid->m_fourcc);
|
||||
|
||||
if (MFX_FOURCC_P8 == mfx_fourcc) // bitstream processing
|
||||
{
|
||||
m_libva->vaUnmapBuffer(m_dpy, *(vaapi_mid->m_surface));
|
||||
}
|
||||
else // Image processing
|
||||
{
|
||||
m_libva->vaUnmapBuffer(m_dpy, vaapi_mid->m_image.buf);
|
||||
m_libva->vaDestroyImage(m_dpy, vaapi_mid->m_image.image_id);
|
||||
|
||||
if (NULL != ptr)
|
||||
{
|
||||
ptr->PitchLow = 0;
|
||||
ptr->PitchHigh = 0;
|
||||
ptr->Y = NULL;
|
||||
ptr->U = NULL;
|
||||
ptr->V = NULL;
|
||||
ptr->A = NULL;
|
||||
}
|
||||
}
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus vaapiFrameAllocator::GetFrameHDL(mfxMemId mid, mfxHDL *handle)
|
||||
{
|
||||
vaapiMemId* vaapi_mid = (vaapiMemId*)mid;
|
||||
|
||||
if (!handle || !vaapi_mid || !(vaapi_mid->m_surface)) return MFX_ERR_INVALID_HANDLE;
|
||||
|
||||
*handle = vaapi_mid->m_surface; //VASurfaceID* <-> mfxHDL
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
#endif // #if defined(LIBVA_SUPPORT)
|
||||
538
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_device.cpp
vendored
Normal file
538
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_device.cpp
vendored
Normal file
@@ -0,0 +1,538 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined(LIBVA_ANDROID_SUPPORT)
|
||||
|
||||
#include "vaapi_device.h"
|
||||
|
||||
#if defined(LIBVA_WAYLAND_SUPPORT)
|
||||
#include "class_wayland.h"
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
#include <va/va_x11.h>
|
||||
#include <X11/Xlib.h>
|
||||
|
||||
#include "vaapi_allocator.h"
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
#include <fcntl.h>
|
||||
|
||||
#define ALIGN(x, y) (((x) + (y) - 1) & -(y))
|
||||
#define PAGE_ALIGN(x) ALIGN(x, 4096)
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
|
||||
#define VAAPI_GET_X_DISPLAY(_display) (Display*)(_display)
|
||||
#define VAAPI_GET_X_WINDOW(_window) (Window*)(_window)
|
||||
|
||||
CVAAPIDeviceX11::~CVAAPIDeviceX11(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceX11::Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum)
|
||||
{
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
Window* window = NULL;
|
||||
|
||||
if (nViews)
|
||||
{
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
m_window = window = (Window*)malloc(sizeof(Window));
|
||||
if (!m_window) mfx_res = MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
Display* display = VAAPI_GET_X_DISPLAY(m_X11LibVA.GetXDisplay());
|
||||
MfxLoader::XLib_Proxy & x11lib = m_X11LibVA.GetX11();
|
||||
mfxU32 screen_number = DefaultScreen(display);
|
||||
|
||||
*window = x11lib.XCreateSimpleWindow(
|
||||
display,
|
||||
RootWindow(display, screen_number),
|
||||
m_bRenderWin ? m_nRenderWinX : 0,
|
||||
m_bRenderWin ? m_nRenderWinY : 0,
|
||||
100,
|
||||
100,
|
||||
0,
|
||||
0,
|
||||
BlackPixel(display, screen_number));
|
||||
|
||||
if (!(*window)) mfx_res = MFX_ERR_UNKNOWN;
|
||||
else
|
||||
{
|
||||
x11lib.XMapWindow(display, *window);
|
||||
x11lib.XSync(display, False);
|
||||
}
|
||||
}
|
||||
}
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
MfxLoader::DrmIntel_Proxy & drmintellib = m_X11LibVA.GetDrmIntelX11();
|
||||
MfxLoader::X11_Xcb_Proxy & x11xcblib = m_X11LibVA.GetX11XcbX11();
|
||||
|
||||
m_xcbconn = x11xcblib.XGetXCBConnection(VAAPI_GET_X_DISPLAY(m_X11LibVA.GetXDisplay()));
|
||||
|
||||
// it's enough to pass render node, because we only request
|
||||
// information from kernel via m_dri_fd
|
||||
m_dri_fd = open("/dev/dri/renderD128", O_RDWR);
|
||||
if (m_dri_fd < 0) {
|
||||
msdk_printf(MSDK_STRING("Failed to open dri device\n"));
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
m_bufmgr = drmintellib.drm_intel_bufmgr_gem_init(m_dri_fd, 4096);
|
||||
if (!m_bufmgr){
|
||||
msdk_printf(MSDK_STRING("Failed to get buffer manager\n"));
|
||||
return MFX_ERR_NOT_INITIALIZED;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
void CVAAPIDeviceX11::Close(void)
|
||||
{
|
||||
if (m_window)
|
||||
{
|
||||
Display* display = VAAPI_GET_X_DISPLAY(m_X11LibVA.GetXDisplay());
|
||||
Window* window = VAAPI_GET_X_WINDOW(m_window);
|
||||
|
||||
MfxLoader::XLib_Proxy & x11lib = m_X11LibVA.GetX11();
|
||||
x11lib.XDestroyWindow(display, *window);
|
||||
|
||||
free(m_window);
|
||||
m_window = NULL;
|
||||
}
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
if (m_dri_fd)
|
||||
{
|
||||
close(m_dri_fd);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceX11::Reset(void)
|
||||
{
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceX11::GetHandle(mfxHandleType type, mfxHDL *pHdl)
|
||||
{
|
||||
if ((MFX_HANDLE_VA_DISPLAY == type) && (NULL != pHdl))
|
||||
{
|
||||
*pHdl = m_X11LibVA.GetVADisplay();
|
||||
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceX11::SetHandle(mfxHandleType type, mfxHDL hdl)
|
||||
{
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceX11::RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * /*pmfxAlloc*/)
|
||||
{
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
vaapiMemId * memId = NULL;
|
||||
|
||||
#if !defined(X11_DRI3_SUPPORT)
|
||||
VAStatus va_res = VA_STATUS_SUCCESS;
|
||||
VASurfaceID surface;
|
||||
Display* display = VAAPI_GET_X_DISPLAY(m_X11LibVA.GetXDisplay());
|
||||
Window* window = VAAPI_GET_X_WINDOW(m_window);
|
||||
|
||||
if(!window || !(*window)) mfx_res = MFX_ERR_NOT_INITIALIZED;
|
||||
// should MFX_ERR_NONE be returned below considering situation as EOS?
|
||||
if ((MFX_ERR_NONE == mfx_res) && NULL == pSurface) mfx_res = MFX_ERR_NULL_PTR;
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
memId = (vaapiMemId*)(pSurface->Data.MemId);
|
||||
if (!memId || !memId->m_surface) mfx_res = MFX_ERR_NULL_PTR;
|
||||
}
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
VADisplay dpy = m_X11LibVA.GetVADisplay();
|
||||
VADisplay rnddpy = m_X11LibVA.GetVADisplay();
|
||||
VASurfaceID rndsrf;
|
||||
void* ctx;
|
||||
|
||||
surface = *memId->m_surface;
|
||||
|
||||
va_res = m_X11LibVA.AcquireVASurface(&ctx, dpy, surface, rnddpy, &rndsrf);
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
if (MFX_ERR_NONE != mfx_res) return mfx_res;
|
||||
|
||||
MfxLoader::XLib_Proxy & x11lib = m_X11LibVA.GetX11();
|
||||
x11lib.XResizeWindow(display, *window, pSurface->Info.CropW, pSurface->Info.CropH);
|
||||
|
||||
|
||||
MfxLoader::VA_X11Proxy & vax11lib = m_X11LibVA.GetVAX11();
|
||||
va_res = vax11lib.vaPutSurface(rnddpy,
|
||||
rndsrf,
|
||||
*window,
|
||||
pSurface->Info.CropX,
|
||||
pSurface->Info.CropY,
|
||||
pSurface->Info.CropX + pSurface->Info.CropW,
|
||||
pSurface->Info.CropY + pSurface->Info.CropH,
|
||||
pSurface->Info.CropX,
|
||||
pSurface->Info.CropY,
|
||||
pSurface->Info.CropX + pSurface->Info.CropW,
|
||||
pSurface->Info.CropY + pSurface->Info.CropH,
|
||||
NULL,
|
||||
0,
|
||||
VA_FRAME_PICTURE);
|
||||
|
||||
mfx_res = va_to_mfx_status(va_res);
|
||||
x11lib.XSync(display, False);
|
||||
|
||||
m_X11LibVA.ReleaseVASurface(ctx, dpy, surface, rnddpy, rndsrf);
|
||||
|
||||
}
|
||||
return mfx_res;
|
||||
#else //\/ X11_DRI3_SUPPORT
|
||||
Window* window = VAAPI_GET_X_WINDOW(m_window);
|
||||
Window root;
|
||||
drm_intel_bo *bo = NULL;
|
||||
unsigned int border, depth, stride, size,
|
||||
width, height;
|
||||
int fd = 0, bpp = 0, x, y;
|
||||
|
||||
MfxLoader::Xcb_Proxy & xcblib = m_X11LibVA.GetXcbX11();
|
||||
MfxLoader::XLib_Proxy & x11lib = m_X11LibVA.GetX11();
|
||||
MfxLoader::DrmIntel_Proxy & drmintellib = m_X11LibVA.GetDrmIntelX11();
|
||||
MfxLoader::Xcbpresent_Proxy & xcbpresentlib = m_X11LibVA.GetXcbpresentX11();
|
||||
MfxLoader::XCB_Dri3_Proxy & dri3lib= m_X11LibVA.GetXCBDri3X11();
|
||||
|
||||
if(!window || !(*window)) mfx_res = MFX_ERR_NOT_INITIALIZED;
|
||||
// should MFX_ERR_NONE be returned below considering situation as EOS?
|
||||
if ((MFX_ERR_NONE == mfx_res) && NULL == pSurface) mfx_res = MFX_ERR_NULL_PTR;
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
memId = (vaapiMemId*)(pSurface->Data.MemId);
|
||||
if (!memId || !memId->m_surface) mfx_res = MFX_ERR_NULL_PTR;
|
||||
}
|
||||
|
||||
if(memId && memId->m_buffer_info.mem_type != VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME){
|
||||
msdk_printf(MSDK_STRING("Memory type invalid!\n"));
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
if (MFX_ERR_NONE == mfx_res)
|
||||
{
|
||||
x11lib.XResizeWindow(VAAPI_GET_X_DISPLAY(m_X11LibVA.GetXDisplay()),
|
||||
*window, pSurface->Info.CropW, pSurface->Info.CropH);
|
||||
x11lib.XGetGeometry(VAAPI_GET_X_DISPLAY(m_X11LibVA.GetXDisplay()),
|
||||
*window, &root, &x, &y, &width, &height, &border, &depth);
|
||||
|
||||
switch (depth) {
|
||||
case 8: bpp = 8; break;
|
||||
case 15: case 16: bpp = 16; break;
|
||||
case 24: case 32: bpp = 32; break;
|
||||
default: msdk_printf(MSDK_STRING("Invalid depth\n"));
|
||||
}
|
||||
|
||||
width = pSurface->Info.CropX + pSurface->Info.CropW;
|
||||
height = pSurface->Info.CropY + pSurface->Info.CropH;
|
||||
|
||||
stride = width * bpp/8;
|
||||
size = PAGE_ALIGN(stride * height);
|
||||
|
||||
bo = drmintellib.drm_intel_bo_gem_create_from_prime(m_bufmgr, memId->m_buffer_info.handle, size);
|
||||
if (!bo) {
|
||||
msdk_printf(MSDK_STRING("Failed to create buffer object\n"));
|
||||
return MFX_ERR_MEMORY_ALLOC;
|
||||
}
|
||||
|
||||
drmintellib.drm_intel_bo_gem_export_to_prime(bo, &fd);
|
||||
if (!fd) {
|
||||
msdk_printf(MSDK_STRING("Invalid fd\n"));
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
xcb_pixmap_t pixmap = xcblib.xcb_generate_id(m_xcbconn);
|
||||
xcb_void_cookie_t cookie;
|
||||
xcb_generic_error_t *error;
|
||||
|
||||
cookie = dri3lib.xcb_dri3_pixmap_from_buffer_checked(m_xcbconn, pixmap, root, size, width, height, stride, depth, bpp, fd);
|
||||
if ((error = xcblib.xcb_request_check(m_xcbconn, cookie))) {
|
||||
msdk_printf(MSDK_STRING("Failed to create xcb pixmap from the %s surface: try another color format (e.g. RGB4)\n"),
|
||||
ColorFormatToStr(pSurface->Info.FourCC));
|
||||
free(error);
|
||||
return MFX_ERR_INVALID_HANDLE;
|
||||
}
|
||||
|
||||
cookie = xcbpresentlib.xcb_present_pixmap_checked(m_xcbconn,
|
||||
*window, pixmap,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
None,
|
||||
None,
|
||||
None,
|
||||
XCB_PRESENT_OPTION_NONE,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0, NULL);
|
||||
if ((error = xcblib.xcb_request_check(m_xcbconn, cookie))) {
|
||||
msdk_printf(MSDK_STRING("Failed to present pixmap\n"));
|
||||
free(error);
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
|
||||
xcblib.xcb_free_pixmap(m_xcbconn, pixmap);
|
||||
xcblib.xcb_flush(m_xcbconn);
|
||||
}
|
||||
|
||||
return mfx_res;
|
||||
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_WAYLAND_SUPPORT)
|
||||
#include "wayland-drm-client-protocol.h"
|
||||
|
||||
CVAAPIDeviceWayland::~CVAAPIDeviceWayland(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceWayland::Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum)
|
||||
{
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
|
||||
if(nViews)
|
||||
{
|
||||
m_Wayland = (Wayland*)m_WaylandClient.WaylandCreate();
|
||||
if(!m_Wayland->InitDisplay()) {
|
||||
return MFX_ERR_DEVICE_FAILED;
|
||||
}
|
||||
|
||||
if(NULL == m_Wayland->GetDisplay())
|
||||
{
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
return mfx_res;
|
||||
}
|
||||
if(-1 == m_Wayland->DisplayRoundtrip())
|
||||
{
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
return mfx_res;
|
||||
}
|
||||
if(!m_Wayland->CreateSurface())
|
||||
{
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
return mfx_res;
|
||||
}
|
||||
}
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceWayland::RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * /*pmfxAlloc*/)
|
||||
{
|
||||
uint32_t drm_format = 0;
|
||||
int offsets[3], pitches[3];
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
vaapiMemId * memId = NULL;
|
||||
struct wl_buffer *m_wl_buffer = NULL;
|
||||
if(NULL==pSurface) {
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
return mfx_res;
|
||||
}
|
||||
m_Wayland->Sync();
|
||||
memId = (vaapiMemId*)(pSurface->Data.MemId);
|
||||
|
||||
if (pSurface->Info.FourCC == MFX_FOURCC_NV12)
|
||||
{
|
||||
drm_format = WL_DRM_FORMAT_NV12;
|
||||
} else if(pSurface->Info.FourCC == MFX_FOURCC_RGB4)
|
||||
{
|
||||
drm_format = WL_DRM_FORMAT_ARGB8888;
|
||||
|
||||
if (m_isMondelloInputEnabled)
|
||||
{
|
||||
drm_format = WL_DRM_FORMAT_XBGR8888;
|
||||
}
|
||||
}
|
||||
|
||||
offsets[0] = memId->m_image.offsets[0];
|
||||
offsets[1] = memId->m_image.offsets[1];
|
||||
offsets[2] = memId->m_image.offsets[2];
|
||||
pitches[0] = memId->m_image.pitches[0];
|
||||
pitches[1] = memId->m_image.pitches[1];
|
||||
pitches[2] = memId->m_image.pitches[2];
|
||||
m_wl_buffer = m_Wayland->CreatePrimeBuffer(memId->m_buffer_info.handle
|
||||
, pSurface->Info.CropW
|
||||
, pSurface->Info.CropH
|
||||
, drm_format
|
||||
, offsets
|
||||
, pitches);
|
||||
if(NULL == m_wl_buffer)
|
||||
{
|
||||
msdk_printf("\nCan't wrap flink to wl_buffer\n");
|
||||
mfx_res = MFX_ERR_UNKNOWN;
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
m_Wayland->RenderBuffer(m_wl_buffer, pSurface);
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
void CVAAPIDeviceWayland::Close(void)
|
||||
{
|
||||
m_Wayland->FreeSurface();
|
||||
}
|
||||
|
||||
CHWDevice* CreateVAAPIDevice(void)
|
||||
{
|
||||
return new CVAAPIDeviceWayland();
|
||||
}
|
||||
|
||||
#endif // LIBVA_WAYLAND_SUPPORT
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
|
||||
CVAAPIDeviceDRM::CVAAPIDeviceDRM(const std::string& devicePath, int type)
|
||||
: m_DRMLibVA(devicePath, type)
|
||||
, m_rndr(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CVAAPIDeviceDRM::~CVAAPIDeviceDRM(void)
|
||||
{
|
||||
MSDK_SAFE_DELETE(m_rndr);
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceDRM::Init(mfxHDL hWindow, mfxU16 nViews, mfxU32 nAdapterNum)
|
||||
{
|
||||
if (0 == nViews) {
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
if (1 == nViews) {
|
||||
if (m_DRMLibVA.getBackendType() == MFX_LIBVA_DRM_RENDERNODE) {
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
mfxI32 * monitorType = (mfxI32*)hWindow;
|
||||
if (!monitorType) return MFX_ERR_INVALID_VIDEO_PARAM;
|
||||
try {
|
||||
m_rndr = new drmRenderer(m_DRMLibVA.getFD(), *monitorType);
|
||||
} catch(...) {
|
||||
msdk_printf(MSDK_STRING("vaapi_device: failed to initialize drmrender\n"));
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
|
||||
mfxStatus CVAAPIDeviceDRM::RenderFrame(mfxFrameSurface1 * pSurface, mfxFrameAllocator * pmfxAlloc)
|
||||
{
|
||||
return (m_rndr)? m_rndr->render(pSurface): MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined (LIBVA_WAYLAND_SUPPORT)
|
||||
|
||||
CHWDevice* CreateVAAPIDevice(const std::string& devicePath, int type)
|
||||
{
|
||||
CHWDevice * device = NULL;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case MFX_LIBVA_DRM_RENDERNODE:
|
||||
case MFX_LIBVA_DRM_MODESET:
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
try
|
||||
{
|
||||
device = new CVAAPIDeviceDRM(devicePath, type);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
device = NULL;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case MFX_LIBVA_X11:
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
try
|
||||
{
|
||||
device = new CVAAPIDeviceX11;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
device = NULL;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
case MFX_LIBVA_WAYLAND:
|
||||
#if defined(LIBVA_WAYLAND_SUPPORT)
|
||||
device = new CVAAPIDeviceWayland;
|
||||
#endif
|
||||
break;
|
||||
case MFX_LIBVA_AUTO:
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
try
|
||||
{
|
||||
device = new CVAAPIDeviceX11;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
device = NULL;
|
||||
}
|
||||
#endif
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
if (!device)
|
||||
{
|
||||
try
|
||||
{
|
||||
device = new CVAAPIDeviceDRM(devicePath, type);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
device = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
} // switch(type)
|
||||
|
||||
return device;
|
||||
}
|
||||
|
||||
#elif defined(LIBVA_ANDROID_SUPPORT)
|
||||
|
||||
static AndroidLibVA g_LibVA;
|
||||
CHWDevice* CreateVAAPIDevice(const std::string& devicePath, int type)
|
||||
{
|
||||
return new CVAAPIDeviceAndroid(&g_LibVA);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif //#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT) || defined(LIBVA_ANDROID_SUPPORT)
|
||||
462
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils.cpp
vendored
Normal file
462
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils.cpp
vendored
Normal file
@@ -0,0 +1,462 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifdef LIBVA_SUPPORT
|
||||
|
||||
#include "vaapi_utils.h"
|
||||
#include <dlfcn.h>
|
||||
#include <stdexcept>
|
||||
|
||||
//#if defined(LIBVA_DRM_SUPPORT)
|
||||
#include "vaapi_utils_drm.h"
|
||||
//#elif defined(LIBVA_X11_SUPPORT)
|
||||
#include "vaapi_utils_x11.h"
|
||||
//#endif
|
||||
|
||||
#if defined(LIBVA_WAYLAND_SUPPORT)
|
||||
#include "class_wayland.h"
|
||||
#endif
|
||||
|
||||
namespace MfxLoader
|
||||
{
|
||||
|
||||
SimpleLoader::SimpleLoader(const char * name)
|
||||
{
|
||||
dlerror();
|
||||
so_handle = dlopen(name, RTLD_GLOBAL | RTLD_NOW);
|
||||
if (NULL == so_handle)
|
||||
{
|
||||
std::cerr << dlerror() << std::endl;
|
||||
throw std::runtime_error("Can't load library");
|
||||
}
|
||||
}
|
||||
|
||||
void * SimpleLoader::GetFunction(const char * name)
|
||||
{
|
||||
void * fn_ptr = dlsym(so_handle, name);
|
||||
if (!fn_ptr)
|
||||
throw std::runtime_error("Can't find function");
|
||||
return fn_ptr;
|
||||
}
|
||||
|
||||
SimpleLoader::~SimpleLoader()
|
||||
{
|
||||
dlclose(so_handle);
|
||||
}
|
||||
|
||||
#define SIMPLE_LOADER_STRINGIFY1( x) #x
|
||||
#define SIMPLE_LOADER_STRINGIFY(x) SIMPLE_LOADER_STRINGIFY1(x)
|
||||
#define SIMPLE_LOADER_DECORATOR1(fun,suffix) fun ## _ ## suffix
|
||||
#define SIMPLE_LOADER_DECORATOR(fun,suffix) SIMPLE_LOADER_DECORATOR1(fun,suffix)
|
||||
|
||||
|
||||
// Following macro applied on vaInitialize will give: vaInitialize((vaInitialize_type)lib.GetFunction("vaInitialize"))
|
||||
#define SIMPLE_LOADER_FUNCTION(name) name( (SIMPLE_LOADER_DECORATOR(name, type)) lib.GetFunction(SIMPLE_LOADER_STRINGIFY(name)) )
|
||||
|
||||
|
||||
#if defined(LIBVA_SUPPORT)
|
||||
VA_Proxy::VA_Proxy()
|
||||
#ifdef ANDROID
|
||||
: lib("libva-android.so")
|
||||
#else
|
||||
: lib("libva.so.2")
|
||||
#endif
|
||||
, SIMPLE_LOADER_FUNCTION(vaInitialize)
|
||||
, SIMPLE_LOADER_FUNCTION(vaTerminate)
|
||||
, SIMPLE_LOADER_FUNCTION(vaCreateSurfaces)
|
||||
, SIMPLE_LOADER_FUNCTION(vaDestroySurfaces)
|
||||
, SIMPLE_LOADER_FUNCTION(vaCreateBuffer)
|
||||
, SIMPLE_LOADER_FUNCTION(vaDestroyBuffer)
|
||||
, SIMPLE_LOADER_FUNCTION(vaMapBuffer)
|
||||
, SIMPLE_LOADER_FUNCTION(vaUnmapBuffer)
|
||||
, SIMPLE_LOADER_FUNCTION(vaSyncSurface)
|
||||
, SIMPLE_LOADER_FUNCTION(vaDeriveImage)
|
||||
, SIMPLE_LOADER_FUNCTION(vaDestroyImage)
|
||||
, SIMPLE_LOADER_FUNCTION(vaGetLibFunc)
|
||||
, SIMPLE_LOADER_FUNCTION(vaAcquireBufferHandle)
|
||||
, SIMPLE_LOADER_FUNCTION(vaReleaseBufferHandle)
|
||||
, SIMPLE_LOADER_FUNCTION(vaMaxNumEntrypoints)
|
||||
, SIMPLE_LOADER_FUNCTION(vaQueryConfigEntrypoints)
|
||||
, SIMPLE_LOADER_FUNCTION(vaGetConfigAttributes)
|
||||
, SIMPLE_LOADER_FUNCTION(vaCreateConfig)
|
||||
, SIMPLE_LOADER_FUNCTION(vaCreateContext)
|
||||
, SIMPLE_LOADER_FUNCTION(vaDestroyConfig)
|
||||
, SIMPLE_LOADER_FUNCTION(vaDestroyContext)
|
||||
{
|
||||
}
|
||||
|
||||
VA_Proxy::~VA_Proxy()
|
||||
{}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
DRM_Proxy::DRM_Proxy()
|
||||
: lib("libdrm.so.2")
|
||||
, SIMPLE_LOADER_FUNCTION(drmIoctl)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeAddFB)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeAddFB2WithModifiers)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeFreeConnector)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeFreeCrtc)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeFreeEncoder)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeFreePlane)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeFreePlaneResources)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeFreeResources)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeGetConnector)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeGetCrtc)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeGetEncoder)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeGetPlane)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeGetPlaneResources)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeGetResources)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeRmFB)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeSetCrtc)
|
||||
, SIMPLE_LOADER_FUNCTION(drmSetMaster)
|
||||
, SIMPLE_LOADER_FUNCTION(drmDropMaster)
|
||||
, SIMPLE_LOADER_FUNCTION(drmModeSetPlane)
|
||||
{
|
||||
}
|
||||
|
||||
DrmIntel_Proxy::~DrmIntel_Proxy()
|
||||
{}
|
||||
|
||||
DrmIntel_Proxy::DrmIntel_Proxy()
|
||||
: lib("libdrm_intel.so.1")
|
||||
, SIMPLE_LOADER_FUNCTION(drm_intel_bo_gem_create_from_prime)
|
||||
, SIMPLE_LOADER_FUNCTION(drm_intel_bo_unreference)
|
||||
, SIMPLE_LOADER_FUNCTION(drm_intel_bufmgr_gem_init)
|
||||
, SIMPLE_LOADER_FUNCTION(drm_intel_bufmgr_destroy)
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
, SIMPLE_LOADER_FUNCTION(drm_intel_bo_gem_export_to_prime)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
|
||||
DRM_Proxy::~DRM_Proxy()
|
||||
{}
|
||||
|
||||
VA_DRMProxy::VA_DRMProxy()
|
||||
: lib("libva-drm.so.2")
|
||||
, SIMPLE_LOADER_FUNCTION(vaGetDisplayDRM)
|
||||
{
|
||||
}
|
||||
|
||||
VA_DRMProxy::~VA_DRMProxy()
|
||||
{}
|
||||
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
XCB_Dri3_Proxy::XCB_Dri3_Proxy()
|
||||
: lib("libxcb-dri3.so.0")
|
||||
, SIMPLE_LOADER_FUNCTION(xcb_dri3_pixmap_from_buffer_checked)
|
||||
{
|
||||
}
|
||||
|
||||
XCB_Dri3_Proxy::~XCB_Dri3_Proxy()
|
||||
{}
|
||||
|
||||
Xcb_Proxy::Xcb_Proxy()
|
||||
: lib("libxcb.so.1")
|
||||
, SIMPLE_LOADER_FUNCTION(xcb_generate_id)
|
||||
, SIMPLE_LOADER_FUNCTION(xcb_free_pixmap)
|
||||
, SIMPLE_LOADER_FUNCTION(xcb_flush)
|
||||
, SIMPLE_LOADER_FUNCTION(xcb_request_check)
|
||||
{
|
||||
}
|
||||
|
||||
Xcb_Proxy::~Xcb_Proxy()
|
||||
{}
|
||||
|
||||
X11_Xcb_Proxy::X11_Xcb_Proxy()
|
||||
: lib("libX11-xcb.so.1")
|
||||
, SIMPLE_LOADER_FUNCTION(XGetXCBConnection)
|
||||
{
|
||||
}
|
||||
|
||||
X11_Xcb_Proxy::~X11_Xcb_Proxy()
|
||||
{}
|
||||
|
||||
Xcbpresent_Proxy::Xcbpresent_Proxy()
|
||||
: lib("libxcb-present.so.0")
|
||||
, SIMPLE_LOADER_FUNCTION(xcb_present_pixmap_checked)
|
||||
{
|
||||
}
|
||||
|
||||
Xcbpresent_Proxy::~Xcbpresent_Proxy()
|
||||
{}
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
#endif
|
||||
|
||||
#if defined(LIBVA_WAYLAND_SUPPORT)
|
||||
|
||||
VA_WaylandClientProxy::VA_WaylandClientProxy()
|
||||
: lib("libmfx_wayland.so")
|
||||
, SIMPLE_LOADER_FUNCTION(WaylandCreate)
|
||||
{
|
||||
}
|
||||
|
||||
VA_WaylandClientProxy::~VA_WaylandClientProxy()
|
||||
{}
|
||||
|
||||
#endif // LIBVA_WAYLAND_SUPPORT
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
VA_X11Proxy::VA_X11Proxy()
|
||||
: lib("libva-x11.so.2")
|
||||
, SIMPLE_LOADER_FUNCTION(vaGetDisplay)
|
||||
, SIMPLE_LOADER_FUNCTION(vaPutSurface)
|
||||
{
|
||||
}
|
||||
|
||||
VA_X11Proxy::~VA_X11Proxy()
|
||||
{}
|
||||
|
||||
XLib_Proxy::XLib_Proxy()
|
||||
: lib("libX11.so.6")
|
||||
, SIMPLE_LOADER_FUNCTION(XOpenDisplay)
|
||||
, SIMPLE_LOADER_FUNCTION(XCloseDisplay)
|
||||
, SIMPLE_LOADER_FUNCTION(XCreateSimpleWindow)
|
||||
, SIMPLE_LOADER_FUNCTION(XMapWindow)
|
||||
, SIMPLE_LOADER_FUNCTION(XSync)
|
||||
, SIMPLE_LOADER_FUNCTION(XDestroyWindow)
|
||||
, SIMPLE_LOADER_FUNCTION(XResizeWindow)
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
, SIMPLE_LOADER_FUNCTION(XGetGeometry)
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
{}
|
||||
|
||||
XLib_Proxy::~XLib_Proxy()
|
||||
{}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#undef SIMPLE_LOADER_FUNCTION
|
||||
|
||||
} // MfxLoader
|
||||
|
||||
mfxStatus va_to_mfx_status(VAStatus va_res)
|
||||
{
|
||||
mfxStatus mfxRes = MFX_ERR_NONE;
|
||||
|
||||
switch (va_res)
|
||||
{
|
||||
case VA_STATUS_SUCCESS:
|
||||
mfxRes = MFX_ERR_NONE;
|
||||
break;
|
||||
case VA_STATUS_ERROR_ALLOCATION_FAILED:
|
||||
mfxRes = MFX_ERR_MEMORY_ALLOC;
|
||||
break;
|
||||
case VA_STATUS_ERROR_ATTR_NOT_SUPPORTED:
|
||||
case VA_STATUS_ERROR_UNSUPPORTED_PROFILE:
|
||||
case VA_STATUS_ERROR_UNSUPPORTED_ENTRYPOINT:
|
||||
case VA_STATUS_ERROR_UNSUPPORTED_RT_FORMAT:
|
||||
case VA_STATUS_ERROR_UNSUPPORTED_BUFFERTYPE:
|
||||
case VA_STATUS_ERROR_FLAG_NOT_SUPPORTED:
|
||||
case VA_STATUS_ERROR_RESOLUTION_NOT_SUPPORTED:
|
||||
mfxRes = MFX_ERR_UNSUPPORTED;
|
||||
break;
|
||||
case VA_STATUS_ERROR_INVALID_DISPLAY:
|
||||
case VA_STATUS_ERROR_INVALID_CONFIG:
|
||||
case VA_STATUS_ERROR_INVALID_CONTEXT:
|
||||
case VA_STATUS_ERROR_INVALID_SURFACE:
|
||||
case VA_STATUS_ERROR_INVALID_BUFFER:
|
||||
case VA_STATUS_ERROR_INVALID_IMAGE:
|
||||
case VA_STATUS_ERROR_INVALID_SUBPICTURE:
|
||||
mfxRes = MFX_ERR_NOT_INITIALIZED;
|
||||
break;
|
||||
case VA_STATUS_ERROR_INVALID_PARAMETER:
|
||||
mfxRes = MFX_ERR_INVALID_VIDEO_PARAM;
|
||||
default:
|
||||
mfxRes = MFX_ERR_UNKNOWN;
|
||||
break;
|
||||
}
|
||||
return mfxRes;
|
||||
}
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT)
|
||||
CLibVA* CreateLibVA(const std::string& devicePath, int type)
|
||||
{
|
||||
CLibVA * libva = NULL;
|
||||
switch (type)
|
||||
{
|
||||
case MFX_LIBVA_DRM:
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
try
|
||||
{
|
||||
libva = new DRMLibVA(devicePath, type);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
libva = 0;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case MFX_LIBVA_X11:
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
try
|
||||
{
|
||||
libva = new X11LibVA;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
libva = NULL;
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
|
||||
case MFX_LIBVA_AUTO:
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
try
|
||||
{
|
||||
libva = new X11LibVA;
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
libva = NULL;
|
||||
}
|
||||
#endif
|
||||
#if defined(LIBVA_DRM_SUPPORT)
|
||||
if (!libva)
|
||||
{
|
||||
try
|
||||
{
|
||||
libva = new DRMLibVA(devicePath, type);
|
||||
}
|
||||
catch (std::exception&)
|
||||
{
|
||||
libva = NULL;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
break;
|
||||
} // switch(type)
|
||||
|
||||
return libva;
|
||||
}
|
||||
#endif // #if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
struct AcquireCtx
|
||||
{
|
||||
VAImage image;
|
||||
};
|
||||
|
||||
VAStatus CLibVA::AcquireVASurface(
|
||||
void** pctx,
|
||||
VADisplay dpy1,
|
||||
VASurfaceID srf1,
|
||||
VADisplay dpy2,
|
||||
VASurfaceID* srf2)
|
||||
{
|
||||
if (!pctx || !srf2) return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||
|
||||
if (dpy1 == dpy2) {
|
||||
*srf2 = srf1;
|
||||
return VA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
AcquireCtx* ctx;
|
||||
uintptr_t handle=0;
|
||||
VAStatus va_res;
|
||||
VASurfaceAttrib attribs[2];
|
||||
VASurfaceAttribExternalBuffers extsrf;
|
||||
VABufferInfo bufferInfo;
|
||||
uint32_t memtype = VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME;
|
||||
|
||||
MSDK_ZERO_MEMORY(attribs);
|
||||
MSDK_ZERO_MEMORY(extsrf);
|
||||
MSDK_ZERO_MEMORY(bufferInfo);
|
||||
extsrf.num_buffers = 1;
|
||||
extsrf.buffers = &handle;
|
||||
|
||||
attribs[0].type = (VASurfaceAttribType)VASurfaceAttribMemoryType;
|
||||
attribs[0].flags = VA_SURFACE_ATTRIB_SETTABLE;
|
||||
attribs[0].value.type = VAGenericValueTypeInteger;
|
||||
attribs[0].value.value.i = memtype;
|
||||
|
||||
attribs[1].type = (VASurfaceAttribType)VASurfaceAttribExternalBufferDescriptor;
|
||||
attribs[1].flags = VA_SURFACE_ATTRIB_SETTABLE;
|
||||
attribs[1].value.type = VAGenericValueTypePointer;
|
||||
attribs[1].value.value.p = &extsrf;
|
||||
|
||||
ctx = (AcquireCtx*)calloc(1, sizeof(AcquireCtx));
|
||||
if (!ctx) return VA_STATUS_ERROR_OPERATION_FAILED;
|
||||
|
||||
va_res = m_libva.vaDeriveImage(dpy1, srf1, &ctx->image);
|
||||
if (VA_STATUS_SUCCESS != va_res) {
|
||||
free(ctx);
|
||||
return va_res;
|
||||
}
|
||||
|
||||
va_res = m_libva.vaAcquireBufferHandle(dpy1, ctx->image.buf, &bufferInfo);
|
||||
if (VA_STATUS_SUCCESS != va_res) {
|
||||
m_libva.vaDestroyImage(dpy1, ctx->image.image_id);
|
||||
free(ctx);
|
||||
return va_res;
|
||||
}
|
||||
|
||||
extsrf.width = ctx->image.width;
|
||||
extsrf.height = ctx->image.height;
|
||||
extsrf.num_planes = ctx->image.num_planes;
|
||||
extsrf.pixel_format = ctx->image.format.fourcc;
|
||||
for (int i=0; i < 3; ++i) {
|
||||
extsrf.pitches[i] = ctx->image.pitches[i];
|
||||
extsrf.offsets[i] = ctx->image.offsets[i];
|
||||
}
|
||||
extsrf.data_size = ctx->image.data_size;
|
||||
extsrf.flags = memtype;
|
||||
extsrf.buffers[0] = bufferInfo.handle;
|
||||
|
||||
va_res = m_libva.vaCreateSurfaces(dpy2,
|
||||
VA_RT_FORMAT_YUV420,
|
||||
extsrf.width, extsrf.height,
|
||||
srf2, 1, attribs, 2);
|
||||
if (VA_STATUS_SUCCESS != va_res) {
|
||||
m_libva.vaDestroyImage(dpy1, ctx->image.image_id);
|
||||
free(ctx);
|
||||
return va_res;
|
||||
}
|
||||
|
||||
*pctx = ctx;
|
||||
|
||||
return VA_STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
void CLibVA::ReleaseVASurface(
|
||||
void* actx,
|
||||
VADisplay dpy1,
|
||||
VASurfaceID /*srf1*/,
|
||||
VADisplay dpy2,
|
||||
VASurfaceID srf2)
|
||||
{
|
||||
if (dpy1 != dpy2) {
|
||||
AcquireCtx* ctx = (AcquireCtx*)actx;
|
||||
if (ctx) {
|
||||
m_libva.vaDestroySurfaces(dpy2, &srf2, 1);
|
||||
m_libva.vaReleaseBufferHandle(dpy1, ctx->image.buf);
|
||||
m_libva.vaDestroyImage(dpy1, ctx->image.image_id);
|
||||
free(ctx);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //LIBVA_X11_SUPPORT
|
||||
|
||||
#endif // #ifdef LIBVA_SUPPORT
|
||||
84
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils_android.cpp
vendored
Normal file
84
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils_android.cpp
vendored
Normal file
@@ -0,0 +1,84 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#ifdef LIBVA_ANDROID_SUPPORT
|
||||
#ifdef ANDROID
|
||||
|
||||
#include "vaapi_utils_android.h"
|
||||
|
||||
CLibVA* CreateLibVA(int)
|
||||
{
|
||||
return new AndroidLibVA;
|
||||
}
|
||||
|
||||
/*------------------------------------------------------------------------------*/
|
||||
|
||||
typedef unsigned int vaapiAndroidDisplay;
|
||||
|
||||
#define VAAPI_ANDROID_DEFAULT_DISPLAY 0x18c34078
|
||||
|
||||
AndroidLibVA::AndroidLibVA(void)
|
||||
: CLibVA(MFX_LIBVA_AUTO)
|
||||
, m_display(NULL)
|
||||
{
|
||||
VAStatus va_res = VA_STATUS_SUCCESS;
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
int major_version = 0, minor_version = 0;
|
||||
vaapiAndroidDisplay* display = NULL;
|
||||
|
||||
m_display = display = (vaapiAndroidDisplay*)malloc(sizeof(vaapiAndroidDisplay));
|
||||
if (NULL == m_display) sts = MFX_ERR_NOT_INITIALIZED;
|
||||
else *display = VAAPI_ANDROID_DEFAULT_DISPLAY;
|
||||
|
||||
if (MFX_ERR_NONE == sts)
|
||||
{
|
||||
m_va_dpy = vaGetDisplay(m_display);
|
||||
if (!m_va_dpy)
|
||||
{
|
||||
free(m_display);
|
||||
sts = MFX_ERR_NULL_PTR;
|
||||
}
|
||||
}
|
||||
if (MFX_ERR_NONE == sts)
|
||||
{
|
||||
va_res = vaInitialize(m_va_dpy, &major_version, &minor_version);
|
||||
sts = va_to_mfx_status(va_res);
|
||||
if (MFX_ERR_NONE != sts)
|
||||
{
|
||||
free(display);
|
||||
m_display = NULL;
|
||||
}
|
||||
}
|
||||
if (MFX_ERR_NONE != sts) throw std::bad_alloc();
|
||||
}
|
||||
|
||||
AndroidLibVA::~AndroidLibVA(void)
|
||||
{
|
||||
if (m_va_dpy)
|
||||
{
|
||||
vaTerminate(m_va_dpy);
|
||||
}
|
||||
if (m_display)
|
||||
{
|
||||
free(m_display);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // #ifdef ANDROID
|
||||
#endif // #ifdef LIBVA_ANDROID_SUPPORT
|
||||
542
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils_drm.cpp
vendored
Normal file
542
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils_drm.cpp
vendored
Normal file
@@ -0,0 +1,542 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined(LIBVA_DRM_SUPPORT) || defined(LIBVA_WAYLAND_SUPPORT)
|
||||
|
||||
#include "vaapi_utils_drm.h"
|
||||
#include "vaapi_allocator.h"
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
#include <stdexcept>
|
||||
|
||||
#include "vaapi_utils_drm.h"
|
||||
#include <drm_fourcc.h>
|
||||
#include "i915_drm.h"
|
||||
|
||||
constexpr mfxU32 MFX_DRI_MAX_NODES_NUM = 16;
|
||||
constexpr mfxU32 MFX_DRI_RENDER_START_INDEX = 128;
|
||||
constexpr mfxU32 MFX_DRI_CARD_START_INDEX = 0;
|
||||
constexpr mfxU32 MFX_DRM_DRIVER_NAME_LEN = 4;
|
||||
const char* MFX_DRM_INTEL_DRIVER_NAME = "i915";
|
||||
const char* MFX_DRI_PATH = "/dev/dri/";
|
||||
const char* MFX_DRI_NODE_RENDER = "renderD";
|
||||
const char* MFX_DRI_NODE_CARD = "card";
|
||||
|
||||
int get_drm_driver_name(int fd, char *name, int name_size)
|
||||
{
|
||||
drm_version_t version = {};
|
||||
version.name_len = name_size;
|
||||
version.name = name;
|
||||
return ioctl(fd, DRM_IOWR(0, drm_version), &version);
|
||||
}
|
||||
|
||||
int open_first_intel_adapter(int type)
|
||||
{
|
||||
std::string adapterPath = MFX_DRI_PATH;
|
||||
char driverName[MFX_DRM_DRIVER_NAME_LEN + 1] = {};
|
||||
mfxU32 nodeIndex;
|
||||
|
||||
switch (type) {
|
||||
case MFX_LIBVA_DRM:
|
||||
case MFX_LIBVA_AUTO:
|
||||
adapterPath += MFX_DRI_NODE_RENDER;
|
||||
nodeIndex = MFX_DRI_RENDER_START_INDEX;
|
||||
break;
|
||||
case MFX_LIBVA_DRM_MODESET:
|
||||
adapterPath += MFX_DRI_NODE_CARD;
|
||||
nodeIndex = MFX_DRI_CARD_START_INDEX;
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("Wrong libVA backend type");
|
||||
}
|
||||
|
||||
for (mfxU32 i = 0; i < MFX_DRI_MAX_NODES_NUM; ++i) {
|
||||
std::string curAdapterPath = adapterPath + std::to_string(nodeIndex + i);
|
||||
|
||||
int fd = open(curAdapterPath.c_str(), O_RDWR);
|
||||
if (fd < 0) continue;
|
||||
|
||||
if (!get_drm_driver_name(fd, driverName, MFX_DRM_DRIVER_NAME_LEN) &&
|
||||
!strcmp(driverName, MFX_DRM_INTEL_DRIVER_NAME)) {
|
||||
return fd;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
int open_intel_adapter(const std::string& devicePath, int type)
|
||||
{
|
||||
if(devicePath.empty())
|
||||
return open_first_intel_adapter(type);
|
||||
|
||||
int fd = open(devicePath.c_str(), O_RDWR);
|
||||
|
||||
if (fd < 0) {
|
||||
msdk_printf(MSDK_STRING("Failed to open specified device\n"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
char driverName[MFX_DRM_DRIVER_NAME_LEN + 1] = {};
|
||||
if (!get_drm_driver_name(fd, driverName, MFX_DRM_DRIVER_NAME_LEN) &&
|
||||
!strcmp(driverName, MFX_DRM_INTEL_DRIVER_NAME)) {
|
||||
return fd;
|
||||
}
|
||||
else {
|
||||
close(fd);
|
||||
msdk_printf(MSDK_STRING("Specified device is not Intel one\n"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
DRMLibVA::DRMLibVA(const std::string& devicePath, int type)
|
||||
: CLibVA(type)
|
||||
, m_fd(-1)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
m_fd = open_intel_adapter(devicePath, type);
|
||||
if (m_fd < 0) throw std::range_error("Intel GPU was not found");
|
||||
|
||||
m_va_dpy = m_vadrmlib.vaGetDisplayDRM(m_fd);
|
||||
if (m_va_dpy)
|
||||
{
|
||||
int major_version = 0, minor_version = 0;
|
||||
VAStatus va_res = m_libva.vaInitialize(m_va_dpy, &major_version, &minor_version);
|
||||
sts = va_to_mfx_status(va_res);
|
||||
}
|
||||
else {
|
||||
sts = MFX_ERR_NULL_PTR;
|
||||
}
|
||||
|
||||
if (MFX_ERR_NONE != sts)
|
||||
{
|
||||
if (m_va_dpy) m_libva.vaTerminate(m_va_dpy);
|
||||
close(m_fd);
|
||||
throw std::runtime_error("Loading of VA display was failed");
|
||||
}
|
||||
}
|
||||
|
||||
DRMLibVA::~DRMLibVA(void)
|
||||
{
|
||||
if (m_va_dpy)
|
||||
{
|
||||
m_libva.vaTerminate(m_va_dpy);
|
||||
}
|
||||
if (m_fd >= 0)
|
||||
{
|
||||
close(m_fd);
|
||||
}
|
||||
}
|
||||
|
||||
struct drmMonitorsTable {
|
||||
mfxI32 mfx_type;
|
||||
uint32_t drm_type;
|
||||
const msdk_char * type_name;
|
||||
};
|
||||
|
||||
drmMonitorsTable g_drmMonitorsTable[] = {
|
||||
#define __DECLARE(type) { MFX_MONITOR_ ## type, DRM_MODE_CONNECTOR_ ## type, MSDK_STRING(#type) }
|
||||
__DECLARE(Unknown),
|
||||
__DECLARE(VGA),
|
||||
__DECLARE(DVII),
|
||||
__DECLARE(DVID),
|
||||
__DECLARE(DVIA),
|
||||
__DECLARE(Composite),
|
||||
__DECLARE(SVIDEO),
|
||||
__DECLARE(LVDS),
|
||||
__DECLARE(Component),
|
||||
__DECLARE(9PinDIN),
|
||||
__DECLARE(HDMIA),
|
||||
__DECLARE(HDMIB),
|
||||
__DECLARE(eDP),
|
||||
__DECLARE(TV),
|
||||
__DECLARE(DisplayPort),
|
||||
#if defined(DRM_MODE_CONNECTOR_VIRTUAL) // from libdrm 2.4.59
|
||||
__DECLARE(VIRTUAL),
|
||||
#endif
|
||||
#if defined(DRM_MODE_CONNECTOR_DSI) // from libdrm 2.4.59
|
||||
__DECLARE(DSI)
|
||||
#endif
|
||||
#undef __DECLARE
|
||||
};
|
||||
|
||||
uint32_t drmRenderer::getConnectorType(mfxI32 monitor_type)
|
||||
{
|
||||
for (size_t i=0; i < sizeof(g_drmMonitorsTable)/sizeof(g_drmMonitorsTable[0]); ++i) {
|
||||
if (g_drmMonitorsTable[i].mfx_type == monitor_type) {
|
||||
return g_drmMonitorsTable[i].drm_type;
|
||||
}
|
||||
}
|
||||
return DRM_MODE_CONNECTOR_Unknown;
|
||||
}
|
||||
|
||||
const msdk_char* drmRenderer::getConnectorName(uint32_t connector_type)
|
||||
{
|
||||
for (size_t i=0; i < sizeof(g_drmMonitorsTable)/sizeof(g_drmMonitorsTable[0]); ++i) {
|
||||
if (g_drmMonitorsTable[i].drm_type == connector_type) {
|
||||
return g_drmMonitorsTable[i].type_name;
|
||||
}
|
||||
}
|
||||
return MSDK_STRING("Unknown");
|
||||
}
|
||||
|
||||
drmRenderer::drmRenderer(int fd, mfxI32 monitorType)
|
||||
: m_fd(fd)
|
||||
, m_bufmgr(NULL)
|
||||
, m_overlay_wrn(true)
|
||||
, m_pCurrentRenderTargetSurface(NULL)
|
||||
{
|
||||
bool res = false;
|
||||
uint32_t connectorType = getConnectorType(monitorType);
|
||||
|
||||
if (monitorType == MFX_MONITOR_AUTO) {
|
||||
connectorType = DRM_MODE_CONNECTOR_Unknown;
|
||||
} else if (connectorType == DRM_MODE_CONNECTOR_Unknown) {
|
||||
throw std::invalid_argument("Unsupported monitor type");
|
||||
}
|
||||
drmModeRes *resource = m_drmlib.drmModeGetResources(m_fd);
|
||||
if (resource) {
|
||||
if (getConnector(resource, connectorType) &&
|
||||
getPlane()) {
|
||||
res = true;
|
||||
}
|
||||
m_drmlib.drmModeFreeResources(resource);
|
||||
}
|
||||
if (!res) {
|
||||
throw std::invalid_argument("Failed to allocate renderer");
|
||||
}
|
||||
msdk_printf(MSDK_STRING("drmrender: connected via %s to %dx%d@%d capable display\n"),
|
||||
getConnectorName(m_connector_type), m_mode.hdisplay, m_mode.vdisplay, m_mode.vrefresh);
|
||||
}
|
||||
|
||||
drmRenderer::~drmRenderer()
|
||||
{
|
||||
m_drmlib.drmModeFreeCrtc(m_crtc);
|
||||
if (m_bufmgr)
|
||||
{
|
||||
m_drmintellib.drm_intel_bufmgr_destroy(m_bufmgr);
|
||||
m_bufmgr = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
bool drmRenderer::getConnector(drmModeRes *resource, uint32_t connector_type)
|
||||
{
|
||||
bool found = false;
|
||||
drmModeConnectorPtr connector = NULL;
|
||||
|
||||
for (int i = 0; i < resource->count_connectors; ++i) {
|
||||
connector = m_drmlib.drmModeGetConnector(m_fd, resource->connectors[i]);
|
||||
if (connector) {
|
||||
if ((connector->connector_type == connector_type) ||
|
||||
(connector_type == DRM_MODE_CONNECTOR_Unknown)) {
|
||||
if (connector->connection == DRM_MODE_CONNECTED) {
|
||||
msdk_printf(MSDK_STRING("drmrender: trying connection: %s\n"), getConnectorName(connector->connector_type));
|
||||
m_connector_type = connector->connector_type;
|
||||
m_connectorID = connector->connector_id;
|
||||
found = setupConnection(resource, connector);
|
||||
if (found) msdk_printf(MSDK_STRING("drmrender: succeeded...\n"));
|
||||
else msdk_printf(MSDK_STRING("drmrender: failed...\n"));
|
||||
} else if ((connector_type != DRM_MODE_CONNECTOR_Unknown)) {
|
||||
msdk_printf(MSDK_STRING("drmrender: error: requested monitor not connected\n"));
|
||||
}
|
||||
}
|
||||
m_drmlib.drmModeFreeConnector(connector);
|
||||
if (found) return true;
|
||||
}
|
||||
}
|
||||
msdk_printf(MSDK_STRING("drmrender: error: requested monitor not available\n"));
|
||||
return false;
|
||||
}
|
||||
|
||||
bool drmRenderer::setupConnection(drmModeRes *resource, drmModeConnector* connector)
|
||||
{
|
||||
bool ret = false;
|
||||
drmModeEncoderPtr encoder;
|
||||
|
||||
if (!connector->count_modes) {
|
||||
msdk_printf(MSDK_STRING("drmrender: error: no valid modes for %s connector\n"),
|
||||
getConnectorName(connector->connector_type));
|
||||
return false;
|
||||
}
|
||||
// we will use the first available mode - that's always mode with the highest resolution
|
||||
m_mode = connector->modes[0];
|
||||
|
||||
// trying encoder+crtc which are currently attached to connector
|
||||
m_encoderID = connector->encoder_id;
|
||||
encoder = m_drmlib.drmModeGetEncoder(m_fd, m_encoderID);
|
||||
if (encoder) {
|
||||
m_crtcID = encoder->crtc_id;
|
||||
for (int j = 0; j < resource->count_crtcs; ++j)
|
||||
{
|
||||
if (m_crtcID == resource->crtcs[j])
|
||||
{
|
||||
m_crtcIndex = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
ret = true;
|
||||
msdk_printf(MSDK_STRING("drmrender: selected crtc already attached to connector\n"));
|
||||
m_drmlib.drmModeFreeEncoder(encoder);
|
||||
}
|
||||
|
||||
// if previous attempt to get crtc failed, let performs global search
|
||||
// searching matching encoder+crtc globally
|
||||
if (!ret) {
|
||||
for (int i = 0; i < connector->count_encoders; ++i) {
|
||||
encoder = m_drmlib.drmModeGetEncoder(m_fd, connector->encoders[i]);
|
||||
if (encoder) {
|
||||
for (int j = 0; j < resource->count_crtcs; ++j) {
|
||||
// check whether this CRTC works with the encoder
|
||||
if ( !((encoder->possible_crtcs & (1 << j)) &&
|
||||
(encoder->crtc_id == resource->crtcs[j])) )
|
||||
continue;
|
||||
|
||||
m_encoderID = connector->encoders[i];
|
||||
m_crtcIndex = j;
|
||||
m_crtcID = resource->crtcs[j];
|
||||
ret = true;
|
||||
msdk_printf(MSDK_STRING("drmrender: found crtc with global search\n"));
|
||||
break;
|
||||
}
|
||||
m_drmlib.drmModeFreeEncoder(encoder);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ret) {
|
||||
m_crtc = m_drmlib.drmModeGetCrtc(m_fd, m_crtcID);
|
||||
if (!m_crtc)
|
||||
ret = false;
|
||||
} else {
|
||||
msdk_printf(MSDK_STRING("drmrender: failed to select crtc\n"));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
bool drmRenderer::getPlane()
|
||||
{
|
||||
drmModePlaneResPtr planes = m_drmlib.drmModeGetPlaneResources(m_fd);
|
||||
if (!planes) {
|
||||
return false;
|
||||
}
|
||||
for (uint32_t i = 0; i < planes->count_planes; ++i) {
|
||||
drmModePlanePtr plane = m_drmlib.drmModeGetPlane(m_fd, planes->planes[i]);
|
||||
if (plane) {
|
||||
if (plane->possible_crtcs & (1 << m_crtcIndex)) {
|
||||
for (uint32_t j = 0; j < plane->count_formats; ++j) {
|
||||
if ((plane->formats[j] == DRM_FORMAT_XRGB8888)
|
||||
|| (plane->formats[j] == DRM_FORMAT_NV12)) {
|
||||
m_planeID = plane->plane_id;
|
||||
m_drmlib.drmModeFreePlane(plane);
|
||||
m_drmlib.drmModeFreePlaneResources(planes);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
m_drmlib.drmModeFreePlane(plane);
|
||||
}
|
||||
}
|
||||
m_drmlib.drmModeFreePlaneResources(planes);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool drmRenderer::setMaster()
|
||||
{
|
||||
int wait_count = 0;
|
||||
do {
|
||||
if (!m_drmlib.drmSetMaster(m_fd)) return true;
|
||||
usleep(100);
|
||||
++wait_count;
|
||||
} while(wait_count < 30000);
|
||||
msdk_printf(MSDK_STRING("drmrender: error: failed to get drm mastership during 3 seconds - aborting\n"));
|
||||
return false;
|
||||
}
|
||||
|
||||
void drmRenderer::dropMaster()
|
||||
{
|
||||
m_drmlib.drmDropMaster(m_fd);
|
||||
}
|
||||
|
||||
bool drmRenderer::restore()
|
||||
{
|
||||
if (!setMaster()) return false;
|
||||
|
||||
int ret = m_drmlib.drmModeSetCrtc(m_fd, m_crtcID, m_crtc->buffer_id, m_crtc->x, m_crtc->y, &m_connectorID, 1, &m_mode);
|
||||
if (ret) {
|
||||
msdk_printf(MSDK_STRING("drmrender: failed to restore original mode\n"));
|
||||
return false;
|
||||
}
|
||||
dropMaster();
|
||||
return true;
|
||||
}
|
||||
|
||||
void* drmRenderer::acquire(mfxMemId mid)
|
||||
{
|
||||
vaapiMemId* vmid = (vaapiMemId*)mid;
|
||||
uint32_t fbhandle=0;
|
||||
|
||||
if (vmid->m_buffer_info.mem_type == VA_SURFACE_ATTRIB_MEM_TYPE_DRM_PRIME) {
|
||||
if (!m_bufmgr) {
|
||||
m_bufmgr = m_drmintellib.drm_intel_bufmgr_gem_init(m_fd, 4096);
|
||||
if (!m_bufmgr) return NULL;
|
||||
}
|
||||
|
||||
drm_intel_bo* bo = m_drmintellib.drm_intel_bo_gem_create_from_prime(
|
||||
m_bufmgr, (int)vmid->m_buffer_info.handle, vmid->m_buffer_info.mem_size);
|
||||
if (!bo) return NULL;
|
||||
|
||||
int ret = m_drmlib.drmModeAddFB(m_fd,
|
||||
vmid->m_image.width, vmid->m_image.height,
|
||||
24, 32, vmid->m_image.pitches[0],
|
||||
bo->handle, &fbhandle);
|
||||
if (ret) {
|
||||
return NULL;
|
||||
}
|
||||
m_drmintellib.drm_intel_bo_unreference(bo);
|
||||
} else if (vmid->m_buffer_info.mem_type == VA_SURFACE_ATTRIB_MEM_TYPE_KERNEL_DRM) {
|
||||
struct drm_gem_open flink_open;
|
||||
struct drm_gem_close flink_close;
|
||||
|
||||
MSDK_ZERO_MEMORY(flink_open);
|
||||
flink_open.name = vmid->m_buffer_info.handle;
|
||||
int ret = m_drmlib.drmIoctl(m_fd, DRM_IOCTL_GEM_OPEN, &flink_open);
|
||||
if (ret) return NULL;
|
||||
|
||||
uint32_t handles[4], pitches[4], offsets[4], pixel_format, flags = 0;
|
||||
uint64_t modifiers[4];
|
||||
|
||||
memset(&handles, 0, sizeof(handles));
|
||||
memset(&pitches, 0, sizeof(pitches));
|
||||
memset(&offsets, 0, sizeof(offsets));
|
||||
memset(&modifiers, 0, sizeof(modifiers));
|
||||
|
||||
handles[0] = flink_open.handle;
|
||||
pitches[0] = vmid->m_image.pitches[0];
|
||||
offsets[0] = vmid->m_image.offsets[0];
|
||||
|
||||
if (VA_FOURCC_NV12 == vmid->m_fourcc) {
|
||||
struct drm_i915_gem_set_tiling set_tiling;
|
||||
|
||||
pixel_format = DRM_FORMAT_NV12;
|
||||
memset(&set_tiling, 0, sizeof(set_tiling));
|
||||
set_tiling.handle = flink_open.handle;
|
||||
set_tiling.tiling_mode = I915_TILING_Y;
|
||||
set_tiling.stride = vmid->m_image.pitches[0];
|
||||
ret = m_drmlib.drmIoctl(m_fd, DRM_IOCTL_I915_GEM_SET_TILING, &set_tiling);
|
||||
if (ret) {
|
||||
msdk_printf(MSDK_STRING("DRM_IOCTL_I915_GEM_SET_TILING Failed ret = %d\n"),ret);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
handles[1] = flink_open.handle;
|
||||
pitches[1] = vmid->m_image.pitches[1];
|
||||
offsets[1] = vmid->m_image.offsets[1];
|
||||
modifiers[0] = modifiers[1] = I915_FORMAT_MOD_Y_TILED;
|
||||
flags = 2; // DRM_MODE_FB_MODIFIERS (1<<1) /* enables ->modifer[]
|
||||
}
|
||||
else {
|
||||
pixel_format = DRM_FORMAT_XRGB8888;
|
||||
}
|
||||
|
||||
ret = m_drmlib.drmModeAddFB2WithModifiers(m_fd, vmid->m_image.width, vmid->m_image.height,
|
||||
pixel_format, handles, pitches, offsets, modifiers, &fbhandle, flags);
|
||||
if (ret) return NULL;
|
||||
|
||||
MSDK_ZERO_MEMORY(flink_close);
|
||||
flink_close.handle = flink_open.handle;
|
||||
ret = m_drmlib.drmIoctl(m_fd, DRM_IOCTL_GEM_CLOSE, &flink_close);
|
||||
if (ret) return NULL;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
try {
|
||||
uint32_t* hdl = new uint32_t;
|
||||
*hdl = fbhandle;
|
||||
return hdl;
|
||||
} catch(...) {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void drmRenderer::release(mfxMemId mid, void * mem)
|
||||
{
|
||||
uint32_t* hdl = (uint32_t*)mem;
|
||||
if (!hdl) return;
|
||||
if (!restore()) {
|
||||
msdk_printf(MSDK_STRING("drmrender: warning: failure to restore original mode may lead to application segfault!\n"));
|
||||
}
|
||||
m_drmlib.drmModeRmFB(m_fd, *hdl);
|
||||
delete(hdl);
|
||||
}
|
||||
|
||||
mfxStatus drmRenderer::render(mfxFrameSurface1 * pSurface)
|
||||
{
|
||||
int ret;
|
||||
vaapiMemId * memid;
|
||||
uint32_t fbhandle;
|
||||
|
||||
if (!pSurface || !pSurface->Data.MemId) return MFX_ERR_INVALID_HANDLE;
|
||||
memid = (vaapiMemId*)(pSurface->Data.MemId);
|
||||
if (!memid->m_custom) return MFX_ERR_INVALID_HANDLE;
|
||||
fbhandle = *(uint32_t*)memid->m_custom;
|
||||
|
||||
// rendering on the screen
|
||||
if (!setMaster()) {
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
if ((m_mode.hdisplay == memid->m_image.width) &&
|
||||
(m_mode.vdisplay == memid->m_image.height)) {
|
||||
// surface in the framebuffer exactly matches crtc scanout port, so we
|
||||
// can scanout from this framebuffer for the whole crtc
|
||||
ret = m_drmlib.drmModeSetCrtc(m_fd, m_crtcID, fbhandle, 0, 0, &m_connectorID, 1, &m_mode);
|
||||
if (ret) {
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
} else {
|
||||
if (m_overlay_wrn) {
|
||||
m_overlay_wrn = false;
|
||||
msdk_printf(MSDK_STRING("drmrender: warning: rendering via OVERLAY plane\n"));
|
||||
}
|
||||
// surface in the framebuffer exactly does NOT match crtc scanout port,
|
||||
// and we can only use overlay technique with possible resize (depending on the driver))
|
||||
ret = m_drmlib.drmModeSetPlane(m_fd, m_planeID, m_crtcID, fbhandle, 0,
|
||||
0, 0, m_crtc->width, m_crtc->height,
|
||||
pSurface->Info.CropX << 16, pSurface->Info.CropY << 16, pSurface->Info.CropW << 16, pSurface->Info.CropH << 16);
|
||||
if (ret) {
|
||||
return MFX_ERR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
dropMaster();
|
||||
|
||||
/* Unlock previous Render Target Surface (if exists) */
|
||||
if (NULL != m_pCurrentRenderTargetSurface)
|
||||
msdk_atomic_dec16((volatile mfxU16*)&m_pCurrentRenderTargetSurface->Data.Locked);
|
||||
|
||||
/* new Render target */
|
||||
m_pCurrentRenderTargetSurface = pSurface;
|
||||
/* And lock it */
|
||||
msdk_atomic_inc16((volatile mfxU16*)&m_pCurrentRenderTargetSurface->Data.Locked);
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
#endif // #if defined(LIBVA_DRM_SUPPORT)
|
||||
130
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils_x11.cpp
vendored
Normal file
130
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vaapi_utils_x11.cpp
vendored
Normal file
@@ -0,0 +1,130 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined(LIBVA_X11_SUPPORT)
|
||||
|
||||
#include "sample_defs.h"
|
||||
#include "vaapi_utils_x11.h"
|
||||
|
||||
#include <dlfcn.h>
|
||||
#if defined(X11_DRI3_SUPPORT)
|
||||
#include <fcntl.h>
|
||||
#endif
|
||||
|
||||
#define VAAPI_X_DEFAULT_DISPLAY ":0.0"
|
||||
|
||||
X11LibVA::X11LibVA(void)
|
||||
: CLibVA(MFX_LIBVA_X11)
|
||||
, m_display(0)
|
||||
, m_configID(VA_INVALID_ID)
|
||||
, m_contextID(VA_INVALID_ID)
|
||||
{
|
||||
char* currentDisplay = getenv("DISPLAY");
|
||||
|
||||
m_display = (currentDisplay)?
|
||||
m_x11lib.XOpenDisplay(currentDisplay) :
|
||||
m_x11lib.XOpenDisplay(VAAPI_X_DEFAULT_DISPLAY);
|
||||
|
||||
if (!m_display)
|
||||
{
|
||||
msdk_printf(MSDK_STRING("Failed to open X Display: try to check/set DISPLAY environment variable.\n"));
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
m_va_dpy = m_vax11lib.vaGetDisplay(m_display);
|
||||
if (!m_va_dpy)
|
||||
{
|
||||
m_x11lib.XCloseDisplay(m_display);
|
||||
msdk_printf(MSDK_STRING("Failed to get VA Display\n"));
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
int major_version = 0, minor_version = 0;
|
||||
VAStatus sts = m_libva.vaInitialize(m_va_dpy, &major_version, &minor_version);
|
||||
|
||||
if (VA_STATUS_SUCCESS != sts)
|
||||
{
|
||||
m_x11lib.XCloseDisplay(m_display);
|
||||
msdk_printf(MSDK_STRING("Failed to initialize VAAPI: %d\n"), sts);
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
#if !defined(X11_DRI3_SUPPORT)
|
||||
VAConfigAttrib cfgAttrib{};
|
||||
if (VA_STATUS_SUCCESS == sts)
|
||||
{
|
||||
cfgAttrib.type = VAConfigAttribRTFormat;
|
||||
sts = m_libva.vaGetConfigAttributes(
|
||||
m_va_dpy,
|
||||
VAProfileNone, VAEntrypointVideoProc,
|
||||
&cfgAttrib, 1);
|
||||
}
|
||||
if (VA_STATUS_SUCCESS == sts)
|
||||
{
|
||||
sts = m_libva.vaCreateConfig(
|
||||
m_va_dpy,
|
||||
VAProfileNone, VAEntrypointVideoProc,
|
||||
&cfgAttrib, 1,
|
||||
&m_configID);
|
||||
}
|
||||
if (VA_STATUS_SUCCESS == sts)
|
||||
{
|
||||
sts = m_libva.vaCreateContext(
|
||||
m_va_dpy,
|
||||
m_configID, 0, 0, VA_PROGRESSIVE, 0, 0,
|
||||
&m_contextID);
|
||||
}
|
||||
if (VA_STATUS_SUCCESS != sts)
|
||||
{
|
||||
Close();
|
||||
msdk_printf(MSDK_STRING("Failed to initialize VP: %d\n"), sts);
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
#endif // X11_DRI3_SUPPORT
|
||||
}
|
||||
|
||||
X11LibVA::~X11LibVA(void)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
|
||||
void X11LibVA::Close()
|
||||
{
|
||||
VAStatus sts;
|
||||
|
||||
if (m_contextID != VA_INVALID_ID)
|
||||
{
|
||||
sts = m_libva.vaDestroyContext(m_va_dpy, m_contextID);
|
||||
if (sts != VA_STATUS_SUCCESS)
|
||||
msdk_printf(MSDK_STRING("Failed to destroy VA context: %d\n"), sts);
|
||||
}
|
||||
if (m_configID != VA_INVALID_ID)
|
||||
{
|
||||
sts = m_libva.vaDestroyConfig(m_va_dpy, m_configID);
|
||||
if (sts != VA_STATUS_SUCCESS)
|
||||
msdk_printf(MSDK_STRING("Failed to destroy VA config: %d\n"), sts);
|
||||
}
|
||||
sts = m_libva.vaTerminate(m_va_dpy);
|
||||
if (sts != VA_STATUS_SUCCESS)
|
||||
msdk_printf(MSDK_STRING("Failed to close VAAPI library: %d\n"), sts);
|
||||
|
||||
m_x11lib.XCloseDisplay(m_display);
|
||||
}
|
||||
|
||||
#endif // #if defined(LIBVA_X11_SUPPORT)
|
||||
60
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/atomic.cpp
vendored
Normal file
60
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/atomic.cpp
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include "vm/atomic_defs.h"
|
||||
|
||||
//#define _interlockedbittestandset fake_set
|
||||
//#define _interlockedbittestandreset fake_reset
|
||||
//#define _interlockedbittestandset64 fake_set64
|
||||
//#define _interlockedbittestandreset64 fake_reset64
|
||||
#include <intrin.h>
|
||||
//#undef _interlockedbittestandset
|
||||
//#undef _interlockedbittestandreset
|
||||
//#undef _interlockedbittestandset64
|
||||
//#undef _interlockedbittestandreset64
|
||||
#pragma intrinsic (_InterlockedIncrement16)
|
||||
#pragma intrinsic (_InterlockedDecrement16)
|
||||
#pragma intrinsic (_InterlockedIncrement)
|
||||
#pragma intrinsic (_InterlockedDecrement)
|
||||
|
||||
mfxU16 msdk_atomic_inc16(volatile mfxU16 *pVariable)
|
||||
{
|
||||
return _InterlockedIncrement16((volatile short*)pVariable);
|
||||
}
|
||||
|
||||
/* Thread-safe 16-bit variable decrementing */
|
||||
mfxU16 msdk_atomic_dec16(volatile mfxU16 *pVariable)
|
||||
{
|
||||
return _InterlockedDecrement16((volatile short*)pVariable);
|
||||
}
|
||||
|
||||
mfxU32 msdk_atomic_inc32(volatile mfxU32 *pVariable)
|
||||
{
|
||||
return _InterlockedIncrement((volatile long*)pVariable);
|
||||
}
|
||||
|
||||
/* Thread-safe 16-bit variable decrementing */
|
||||
mfxU32 msdk_atomic_dec32(volatile mfxU32 *pVariable)
|
||||
{
|
||||
return _InterlockedDecrement((volatile long*)pVariable);
|
||||
}
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
64
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/atomic_linux.cpp
vendored
Normal file
64
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/atomic_linux.cpp
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
|
||||
#include "vm/atomic_defs.h"
|
||||
|
||||
static mfxU16 msdk_atomic_add16(volatile mfxU16 *mem, mfxU16 val)
|
||||
{
|
||||
asm volatile ("lock; xaddw %0,%1"
|
||||
: "=r" (val), "=m" (*mem)
|
||||
: "0" (val), "m" (*mem)
|
||||
: "memory", "cc");
|
||||
return val;
|
||||
}
|
||||
|
||||
static mfxU32 msdk_atomic_add32(volatile mfxU32 *mem, mfxU32 val)
|
||||
{
|
||||
asm volatile ("lock; xaddl %0,%1"
|
||||
: "=r" (val), "=m" (*mem)
|
||||
: "0" (val), "m" (*mem)
|
||||
: "memory", "cc");
|
||||
return val;
|
||||
}
|
||||
|
||||
mfxU16 msdk_atomic_inc16(volatile mfxU16 *pVariable)
|
||||
{
|
||||
return msdk_atomic_add16(pVariable, 1) + 1;
|
||||
}
|
||||
|
||||
/* Thread-safe 16-bit variable decrementing */
|
||||
mfxU16 msdk_atomic_dec16(volatile mfxU16 *pVariable)
|
||||
{
|
||||
return msdk_atomic_add16(pVariable, (mfxU16)-1) + 1;
|
||||
}
|
||||
|
||||
mfxU32 msdk_atomic_inc32(volatile mfxU32 *pVariable)
|
||||
{
|
||||
return msdk_atomic_add32(pVariable, 1) + 1;
|
||||
}
|
||||
|
||||
/* Thread-safe 16-bit variable decrementing */
|
||||
mfxU32 msdk_atomic_dec32(volatile mfxU32 *pVariable)
|
||||
{
|
||||
return msdk_atomic_add32(pVariable, (mfxU32)-1) + 1;
|
||||
}
|
||||
|
||||
#endif // #if !defined(_WIN32) && !defined(_WIN64)
|
||||
46
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/shared_object.cpp
vendored
Normal file
46
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/shared_object.cpp
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include "vm/so_defs.h"
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
msdk_so_handle msdk_so_load(const msdk_char *file_name)
|
||||
{
|
||||
if (!file_name) return NULL;
|
||||
return (msdk_so_handle) LoadLibrary((LPCTSTR)file_name);
|
||||
}
|
||||
|
||||
msdk_func_pointer msdk_so_get_addr(msdk_so_handle handle, const char *func_name)
|
||||
{
|
||||
if (!handle) return NULL;
|
||||
return (msdk_func_pointer)GetProcAddress((HMODULE)handle, /*(LPCSTR)*/func_name);
|
||||
}
|
||||
|
||||
void msdk_so_free(msdk_so_handle handle)
|
||||
{
|
||||
if (!handle) return;
|
||||
FreeLibrary((HMODULE)handle);
|
||||
}
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
43
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/shared_object_linux.cpp
vendored
Normal file
43
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/shared_object_linux.cpp
vendored
Normal file
@@ -0,0 +1,43 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
|
||||
#include "vm/so_defs.h"
|
||||
#include <dlfcn.h>
|
||||
|
||||
msdk_so_handle msdk_so_load(const msdk_char *file_name)
|
||||
{
|
||||
if (!file_name) return NULL;
|
||||
return (msdk_so_handle) dlopen(file_name, RTLD_LAZY);
|
||||
}
|
||||
|
||||
msdk_func_pointer msdk_so_get_addr(msdk_so_handle handle, const char *func_name)
|
||||
{
|
||||
if (!handle) return NULL;
|
||||
return (msdk_func_pointer)dlsym(handle, func_name);
|
||||
}
|
||||
|
||||
void msdk_so_free(msdk_so_handle handle)
|
||||
{
|
||||
if (!handle) return;
|
||||
dlclose(handle);
|
||||
}
|
||||
|
||||
#endif // #if !defined(_WIN32) && !defined(_WIN64)
|
||||
293
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/thread_linux.cpp
vendored
Normal file
293
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/thread_linux.cpp
vendored
Normal file
@@ -0,0 +1,293 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
|
||||
#include <new> // std::bad_alloc
|
||||
#include <stdio.h> // setrlimit
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/syscall.h>
|
||||
|
||||
#include "vm/thread_defs.h"
|
||||
#include "sample_utils.h"
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
MSDKSemaphore::MSDKSemaphore(mfxStatus &sts, mfxU32 count):
|
||||
msdkSemaphoreHandle(count)
|
||||
{
|
||||
sts = MFX_ERR_NONE;
|
||||
int res = pthread_cond_init(&m_semaphore, NULL);
|
||||
if (!res) {
|
||||
res = pthread_mutex_init(&m_mutex, NULL);
|
||||
if (res) {
|
||||
pthread_cond_destroy(&m_semaphore);
|
||||
}
|
||||
}
|
||||
if (res) throw std::bad_alloc();
|
||||
}
|
||||
|
||||
MSDKSemaphore::~MSDKSemaphore(void)
|
||||
{
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
pthread_cond_destroy(&m_semaphore);
|
||||
}
|
||||
|
||||
mfxStatus MSDKSemaphore::Post(void)
|
||||
{
|
||||
int res = pthread_mutex_lock(&m_mutex);
|
||||
if (!res) {
|
||||
if (0 == m_count++) res = pthread_cond_signal(&m_semaphore);
|
||||
}
|
||||
int sts = pthread_mutex_unlock(&m_mutex);
|
||||
if (!res) res = sts;
|
||||
return (res)? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKSemaphore::Wait(void)
|
||||
{
|
||||
int res = pthread_mutex_lock(&m_mutex);
|
||||
if (!res) {
|
||||
while(!m_count) {
|
||||
res = pthread_cond_wait(&m_semaphore, &m_mutex);
|
||||
}
|
||||
if (!res) --m_count;
|
||||
int sts = pthread_mutex_unlock(&m_mutex);
|
||||
if (!res) res = sts;
|
||||
}
|
||||
return (res)? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
MSDKEvent::MSDKEvent(mfxStatus &sts, bool manual, bool state):
|
||||
msdkEventHandle(manual, state)
|
||||
{
|
||||
sts = MFX_ERR_NONE;
|
||||
|
||||
int res = pthread_cond_init(&m_event, NULL);
|
||||
if (!res) {
|
||||
res = pthread_mutex_init(&m_mutex, NULL);
|
||||
if (res) {
|
||||
pthread_cond_destroy(&m_event);
|
||||
}
|
||||
}
|
||||
if (res) throw std::bad_alloc();
|
||||
}
|
||||
|
||||
MSDKEvent::~MSDKEvent(void)
|
||||
{
|
||||
pthread_mutex_destroy(&m_mutex);
|
||||
pthread_cond_destroy(&m_event);
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::Signal(void)
|
||||
{
|
||||
int res = pthread_mutex_lock(&m_mutex);
|
||||
if (!res) {
|
||||
if (!m_state) {
|
||||
m_state = true;
|
||||
if (m_manual) res = pthread_cond_broadcast(&m_event);
|
||||
else res = pthread_cond_signal(&m_event);
|
||||
}
|
||||
int sts = pthread_mutex_unlock(&m_mutex);
|
||||
if (!res) res = sts;
|
||||
}
|
||||
return (res)? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::Reset(void)
|
||||
{
|
||||
int res = pthread_mutex_lock(&m_mutex);
|
||||
if (!res)
|
||||
{
|
||||
if (m_state) m_state = false;
|
||||
res = pthread_mutex_unlock(&m_mutex);
|
||||
}
|
||||
return (res)? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::Wait(void)
|
||||
{
|
||||
int res = pthread_mutex_lock(&m_mutex);
|
||||
if (!res)
|
||||
{
|
||||
while(!m_state) res = pthread_cond_wait(&m_event, &m_mutex);
|
||||
if (!m_manual) m_state = false;
|
||||
int sts = pthread_mutex_unlock(&m_mutex);
|
||||
if (!res) res = sts;
|
||||
}
|
||||
return (res)? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::TimedWait(mfxU32 msec)
|
||||
{
|
||||
if (MFX_INFINITE == msec) return MFX_ERR_UNSUPPORTED;
|
||||
mfxStatus mfx_res = MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
int res = pthread_mutex_lock(&m_mutex);
|
||||
if (!res)
|
||||
{
|
||||
if (!m_state)
|
||||
{
|
||||
struct timeval tval;
|
||||
struct timespec tspec;
|
||||
mfxI32 res;
|
||||
|
||||
gettimeofday(&tval, NULL);
|
||||
msec = 1000 * msec + tval.tv_usec;
|
||||
tspec.tv_sec = tval.tv_sec + msec / 1000000;
|
||||
tspec.tv_nsec = (msec % 1000000) * 1000;
|
||||
res = pthread_cond_timedwait(&m_event,
|
||||
&m_mutex,
|
||||
&tspec);
|
||||
if (!res) mfx_res = MFX_ERR_NONE;
|
||||
else if (ETIMEDOUT == res) mfx_res = MFX_TASK_WORKING;
|
||||
else mfx_res = MFX_ERR_UNKNOWN;
|
||||
}
|
||||
else mfx_res = MFX_ERR_NONE;
|
||||
if (!m_manual)
|
||||
m_state = false;
|
||||
|
||||
res = pthread_mutex_unlock(&m_mutex);
|
||||
if (res) mfx_res = MFX_ERR_UNKNOWN;
|
||||
}
|
||||
else mfx_res = MFX_ERR_UNKNOWN;
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
void* msdk_thread_start(void* arg)
|
||||
{
|
||||
if (arg) {
|
||||
MSDKThread* thread = (MSDKThread*)arg;
|
||||
|
||||
if (thread->m_func) thread->m_func(thread->m_arg);
|
||||
thread->m_event->Signal();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
MSDKThread::MSDKThread(mfxStatus &sts, msdk_thread_callback func, void* arg):
|
||||
msdkThreadHandle(func, arg)
|
||||
{
|
||||
m_event = new MSDKEvent(sts, false, false);
|
||||
if (pthread_create(&(m_thread), NULL, msdk_thread_start, this)) {
|
||||
delete(m_event);
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
}
|
||||
|
||||
MSDKThread::~MSDKThread(void)
|
||||
{
|
||||
delete m_event;
|
||||
}
|
||||
|
||||
mfxStatus MSDKThread::Wait(void)
|
||||
{
|
||||
int res = pthread_join(m_thread, NULL);
|
||||
return (res)? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKThread::TimedWait(mfxU32 msec)
|
||||
{
|
||||
if (MFX_INFINITE == msec) return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
mfxStatus mfx_res = m_event->TimedWait(msec);
|
||||
|
||||
if (MFX_ERR_NONE == mfx_res) {
|
||||
return (pthread_join(m_thread, NULL))? MFX_ERR_UNKNOWN: MFX_ERR_NONE;
|
||||
}
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxStatus MSDKThread::GetExitCode()
|
||||
{
|
||||
if (!m_event) return MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
/** @todo: Need to add implementation. */
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
mfxStatus msdk_setrlimit_vmem(mfxU64 size)
|
||||
{
|
||||
struct rlimit limit;
|
||||
|
||||
limit.rlim_cur = size;
|
||||
limit.rlim_max = size;
|
||||
if (setrlimit(RLIMIT_AS, &limit)) return MFX_ERR_UNKNOWN;
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus msdk_thread_get_schedtype(const msdk_char* str, mfxI32 &type)
|
||||
{
|
||||
if (!msdk_strcmp(str, MSDK_STRING("fifo"))) {
|
||||
type = SCHED_FIFO;
|
||||
}
|
||||
else if (!msdk_strcmp(str, MSDK_STRING("rr"))) {
|
||||
type = SCHED_RR;
|
||||
}
|
||||
else if (!msdk_strcmp(str, MSDK_STRING("other"))) {
|
||||
type = SCHED_OTHER;
|
||||
}
|
||||
else if (!msdk_strcmp(str, MSDK_STRING("batch"))) {
|
||||
type = SCHED_BATCH;
|
||||
}
|
||||
else if (!msdk_strcmp(str, MSDK_STRING("idle"))) {
|
||||
type = SCHED_IDLE;
|
||||
}
|
||||
// else if (!msdk_strcmp(str, MSDK_STRING("deadline"))) {
|
||||
// type = SCHED_DEADLINE;
|
||||
// }
|
||||
else {
|
||||
return MFX_ERR_UNSUPPORTED;
|
||||
}
|
||||
return MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
void msdk_thread_printf_scheduling_help()
|
||||
{
|
||||
msdk_printf(MSDK_STRING("Note on the scheduling types and priorities:\n"));
|
||||
msdk_printf(MSDK_STRING(" - <sched_type>: <priority_min> .. <priority_max> (notes)\n"));
|
||||
msdk_printf(MSDK_STRING("The following scheduling types requires root privileges:\n"));
|
||||
msdk_printf(MSDK_STRING(" - fifo: %d .. %d (static priority: low .. high)\n"), sched_get_priority_min(SCHED_FIFO), sched_get_priority_max(SCHED_FIFO));
|
||||
msdk_printf(MSDK_STRING(" - rr: %d .. %d (static priority: low .. high)\n"), sched_get_priority_min(SCHED_RR), sched_get_priority_max(SCHED_RR));
|
||||
msdk_printf(MSDK_STRING("The following scheduling types can be used by non-privileged users:\n"));
|
||||
msdk_printf(MSDK_STRING(" - other: 0 .. 0 (static priority always 0)\n"));
|
||||
msdk_printf(MSDK_STRING(" - batch: 0 .. 0 (static priority always 0)\n"));
|
||||
msdk_printf(MSDK_STRING(" - idle: n/a\n"));
|
||||
msdk_printf(MSDK_STRING("If you want to adjust priority for the other or batch scheduling type,\n"));
|
||||
msdk_printf(MSDK_STRING("you can do that process-wise using dynamic priority - so called nice value.\n"));
|
||||
msdk_printf(MSDK_STRING("Range for the nice value is: %d .. %d (high .. low)\n"), PRIO_MIN, PRIO_MAX);
|
||||
msdk_printf(MSDK_STRING("Please, see 'man(1) nice' for details.\n"));
|
||||
}
|
||||
|
||||
mfxU32 msdk_get_current_pid()
|
||||
{
|
||||
return syscall(SYS_getpid);
|
||||
}
|
||||
|
||||
#endif // #if !defined(_WIN32) && !defined(_WIN64)
|
||||
142
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/thread_windows.cpp
vendored
Normal file
142
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/thread_windows.cpp
vendored
Normal file
@@ -0,0 +1,142 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include "vm/thread_defs.h"
|
||||
#include <new>
|
||||
|
||||
MSDKSemaphore::MSDKSemaphore(mfxStatus &sts, mfxU32 count)
|
||||
{
|
||||
sts = MFX_ERR_NONE;
|
||||
m_semaphore = CreateSemaphore(NULL, count, LONG_MAX, 0);
|
||||
if (!m_semaphore) throw std::bad_alloc();
|
||||
}
|
||||
|
||||
MSDKSemaphore::~MSDKSemaphore(void)
|
||||
{
|
||||
CloseHandle(m_semaphore);
|
||||
}
|
||||
|
||||
mfxStatus MSDKSemaphore::Post(void)
|
||||
{
|
||||
return (ReleaseSemaphore(m_semaphore, 1, NULL) == false) ? MFX_ERR_UNKNOWN : MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKSemaphore::Wait(void)
|
||||
{
|
||||
return (WaitForSingleObject(m_semaphore, INFINITE) != WAIT_OBJECT_0) ? MFX_ERR_UNKNOWN : MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
/* ****************************************************************************** */
|
||||
|
||||
MSDKEvent::MSDKEvent(mfxStatus &sts, bool manual, bool state)
|
||||
{
|
||||
sts = MFX_ERR_NONE;
|
||||
m_event = CreateEvent(NULL, manual, state, NULL);
|
||||
if (!m_event) throw std::bad_alloc();
|
||||
}
|
||||
|
||||
MSDKEvent::~MSDKEvent(void)
|
||||
{
|
||||
CloseHandle(m_event);
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::Signal(void)
|
||||
{
|
||||
return (SetEvent(m_event) == false) ? MFX_ERR_UNKNOWN : MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::Reset(void)
|
||||
{
|
||||
return (ResetEvent(m_event) == false) ? MFX_ERR_UNKNOWN : MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::Wait(void)
|
||||
{
|
||||
return (WaitForSingleObject(m_event, INFINITE) != WAIT_OBJECT_0) ? MFX_ERR_UNKNOWN : MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKEvent::TimedWait(mfxU32 msec)
|
||||
{
|
||||
if(MFX_INFINITE == msec) return MFX_ERR_UNSUPPORTED;
|
||||
mfxStatus mfx_res = MFX_ERR_NOT_INITIALIZED;
|
||||
DWORD res = WaitForSingleObject(m_event, msec);
|
||||
|
||||
if(WAIT_OBJECT_0 == res) mfx_res = MFX_ERR_NONE;
|
||||
else if (WAIT_TIMEOUT == res) mfx_res = MFX_TASK_WORKING;
|
||||
else mfx_res = MFX_ERR_UNKNOWN;
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
MSDKThread::MSDKThread(mfxStatus &sts, msdk_thread_callback func, void* arg)
|
||||
{
|
||||
sts = MFX_ERR_NONE;
|
||||
m_thread = (void*)_beginthreadex(NULL, 0, func, arg, 0, NULL);
|
||||
if (!m_thread) throw std::bad_alloc();
|
||||
}
|
||||
|
||||
MSDKThread::~MSDKThread(void)
|
||||
{
|
||||
CloseHandle(m_thread);
|
||||
}
|
||||
|
||||
mfxStatus MSDKThread::Wait(void)
|
||||
{
|
||||
return (WaitForSingleObject(m_thread, INFINITE) != WAIT_OBJECT_0) ? MFX_ERR_UNKNOWN : MFX_ERR_NONE;
|
||||
}
|
||||
|
||||
mfxStatus MSDKThread::TimedWait(mfxU32 msec)
|
||||
{
|
||||
if(MFX_INFINITE == msec) return MFX_ERR_UNSUPPORTED;
|
||||
|
||||
mfxStatus mfx_res = MFX_ERR_NONE;
|
||||
DWORD res = WaitForSingleObject(m_thread, msec);
|
||||
|
||||
if(WAIT_OBJECT_0 == res) mfx_res = MFX_ERR_NONE;
|
||||
else if (WAIT_TIMEOUT == res) mfx_res = MFX_TASK_WORKING;
|
||||
else mfx_res = MFX_ERR_UNKNOWN;
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxStatus MSDKThread::GetExitCode()
|
||||
{
|
||||
mfxStatus mfx_res = MFX_ERR_NOT_INITIALIZED;
|
||||
|
||||
DWORD code = 0;
|
||||
int sts = 0;
|
||||
sts = GetExitCodeThread(m_thread, &code);
|
||||
|
||||
if (sts == 0) mfx_res = MFX_ERR_UNKNOWN;
|
||||
else if (STILL_ACTIVE == code) mfx_res = MFX_TASK_WORKING;
|
||||
else mfx_res = MFX_ERR_NONE;
|
||||
|
||||
return mfx_res;
|
||||
}
|
||||
|
||||
mfxU32 msdk_get_current_pid()
|
||||
{
|
||||
return GetCurrentProcessId();
|
||||
}
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
46
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/time.cpp
vendored
Normal file
46
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/time.cpp
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
|
||||
#include "vm/time_defs.h"
|
||||
|
||||
msdk_tick msdk_time_get_tick(void)
|
||||
{
|
||||
LARGE_INTEGER t1;
|
||||
|
||||
QueryPerformanceCounter(&t1);
|
||||
return t1.QuadPart;
|
||||
}
|
||||
|
||||
msdk_tick msdk_time_get_frequency(void)
|
||||
{
|
||||
LARGE_INTEGER t1;
|
||||
|
||||
QueryPerformanceFrequency(&t1);
|
||||
return t1.QuadPart;
|
||||
}
|
||||
|
||||
mfxU64 rdtsc(){
|
||||
return __rdtsc();
|
||||
}
|
||||
|
||||
#endif // #if defined(_WIN32) || defined(_WIN64)
|
||||
47
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/time_linux.cpp
vendored
Normal file
47
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vm/time_linux.cpp
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#if !defined(_WIN32) && !defined(_WIN64)
|
||||
|
||||
#include "vm/time_defs.h"
|
||||
#include <sys/time.h>
|
||||
|
||||
#define MSDK_TIME_MHZ 1000000
|
||||
|
||||
msdk_tick msdk_time_get_tick(void)
|
||||
{
|
||||
struct timeval tv;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
return (msdk_tick)tv.tv_sec * (msdk_tick)MSDK_TIME_MHZ + (msdk_tick)tv.tv_usec;
|
||||
}
|
||||
|
||||
msdk_tick msdk_time_get_frequency(void)
|
||||
{
|
||||
return (msdk_tick)MSDK_TIME_MHZ;
|
||||
}
|
||||
|
||||
mfxU64 rdtsc(void){
|
||||
unsigned int lo,hi;
|
||||
__asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
|
||||
return ((mfxU64)hi << 32) | lo;
|
||||
}
|
||||
|
||||
|
||||
#endif // #if !defined(_WIN32) && !defined(_WIN64)
|
||||
275
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vpp_ex.cpp
vendored
Normal file
275
libs/hwcodec/externals/MediaSDK_22.5.4/samples/sample_common/src/vpp_ex.cpp
vendored
Normal file
@@ -0,0 +1,275 @@
|
||||
/******************************************************************************\
|
||||
Copyright (c) 2005-2019, Intel Corporation
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
This sample was distributed or derived from the Intel's Media Samples package.
|
||||
The original version of this sample may be obtained from https://software.intel.com/en-us/intel-media-server-studio
|
||||
or https://software.intel.com/en-us/media-client-solutions-support.
|
||||
\**********************************************************************************/
|
||||
|
||||
#include "mfx_samples_config.h"
|
||||
|
||||
#include "sample_defs.h"
|
||||
|
||||
#include "vpp_ex.h"
|
||||
#include "vm/atomic_defs.h"
|
||||
|
||||
|
||||
MFXVideoVPPEx::MFXVideoVPPEx(mfxSession session) :
|
||||
MFXVideoVPP(session)
|
||||
#if !defined (USE_VPP_EX)
|
||||
{};
|
||||
#else
|
||||
, m_nCurrentPTS(0)
|
||||
, m_nIncreaseTime(0)
|
||||
, m_nInputTimeStamp(0)
|
||||
, m_nArraySize(0)
|
||||
{
|
||||
memset(&m_VideoParams, 0, sizeof(m_VideoParams));
|
||||
};
|
||||
|
||||
mfxStatus MFXVideoVPPEx::Close(void)
|
||||
{
|
||||
for(std::vector<mfxFrameSurface1*>::iterator it = m_LockedSurfacesList.begin(); it != m_LockedSurfacesList.end(); ++it)
|
||||
{
|
||||
try {
|
||||
msdk_atomic_dec16((volatile mfxU16*)(&(*it)->Data.Locked));
|
||||
} catch (...) { // improve robustness by try/catch
|
||||
}
|
||||
}
|
||||
|
||||
m_LockedSurfacesList.clear();
|
||||
|
||||
return MFXVideoVPP::Close();
|
||||
};
|
||||
|
||||
mfxStatus MFXVideoVPPEx::QueryIOSurf(mfxVideoParam *par, mfxFrameAllocRequest request[2])
|
||||
{
|
||||
mfxVideoParam params;
|
||||
|
||||
if (NULL == par)
|
||||
{
|
||||
return MFX_ERR_NULL_PTR;
|
||||
};
|
||||
|
||||
MSDK_MEMCPY_VAR(params, par, sizeof(mfxVideoParam));
|
||||
|
||||
params.vpp.In.FrameRateExtD = params.vpp.Out.FrameRateExtD;
|
||||
params.vpp.In.FrameRateExtN = params.vpp.Out.FrameRateExtN;
|
||||
|
||||
return MFXVideoVPP::QueryIOSurf(¶ms, request);
|
||||
};
|
||||
|
||||
mfxStatus MFXVideoVPPEx::Query(mfxVideoParam *in, mfxVideoParam *out)
|
||||
{
|
||||
mfxVideoParam params;
|
||||
|
||||
if (NULL == out)
|
||||
{
|
||||
return MFX_ERR_NULL_PTR;
|
||||
}
|
||||
|
||||
if (in)
|
||||
{
|
||||
MSDK_MEMCPY_VAR(params, in, sizeof(mfxVideoParam));
|
||||
|
||||
params.vpp.In.FrameRateExtD = params.vpp.Out.FrameRateExtD;
|
||||
params.vpp.In.FrameRateExtN = params.vpp.Out.FrameRateExtN;
|
||||
}
|
||||
|
||||
return MFXVideoVPP::Query((in) ? ¶ms : NULL, out);
|
||||
};
|
||||
|
||||
mfxStatus MFXVideoVPPEx::Init(mfxVideoParam *par)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
if (NULL == par)
|
||||
{
|
||||
return MFX_ERR_NULL_PTR;
|
||||
};
|
||||
|
||||
m_nCurrentPTS = 0;
|
||||
m_nArraySize = 0;
|
||||
m_nInputTimeStamp = 0;
|
||||
|
||||
for(std::vector<mfxFrameSurface1*>::iterator it = m_LockedSurfacesList.begin(); it != m_LockedSurfacesList.end(); ++it)
|
||||
{
|
||||
msdk_atomic_dec16((volatile mfxU16*)(&(*it)->Data.Locked));
|
||||
}
|
||||
|
||||
m_LockedSurfacesList.clear();
|
||||
|
||||
m_nIncreaseTime = (mfxU64)((mfxF64)MFX_TIME_STAMP_FREQUENCY * par->vpp.Out.FrameRateExtD / par->vpp.Out.FrameRateExtN);
|
||||
|
||||
MSDK_MEMCPY_VAR(m_VideoParams, par, sizeof(mfxVideoParam));
|
||||
|
||||
m_VideoParams.vpp.In.FrameRateExtD = m_VideoParams.vpp.Out.FrameRateExtD;
|
||||
m_VideoParams.vpp.In.FrameRateExtN = m_VideoParams.vpp.Out.FrameRateExtN;
|
||||
|
||||
sts = MFXVideoVPP::Init(&m_VideoParams);
|
||||
|
||||
m_VideoParams.vpp.In.FrameRateExtD = par->vpp.In.FrameRateExtD;
|
||||
m_VideoParams.vpp.In.FrameRateExtN = par->vpp.In.FrameRateExtN;
|
||||
|
||||
return sts;
|
||||
}
|
||||
|
||||
mfxStatus MFXVideoVPPEx::GetVideoParam(mfxVideoParam *par)
|
||||
{
|
||||
mfxStatus sts = MFXVideoVPP::GetVideoParam(par);
|
||||
|
||||
if (MFX_ERR_NONE == sts)
|
||||
{
|
||||
par->vpp.In.FrameRateExtD = m_VideoParams.vpp.In.FrameRateExtD;
|
||||
par->vpp.In.FrameRateExtN = m_VideoParams.vpp.In.FrameRateExtN;
|
||||
|
||||
par->vpp.Out.FrameRateExtD = m_VideoParams.vpp.Out.FrameRateExtD;
|
||||
par->vpp.Out.FrameRateExtN = m_VideoParams.vpp.Out.FrameRateExtN;
|
||||
};
|
||||
|
||||
return sts;
|
||||
};
|
||||
|
||||
mfxStatus MFXVideoVPPEx::RunFrameVPPAsync(mfxFrameSurface1 *in, mfxFrameSurface1 *out, mfxExtVppAuxData *aux, mfxSyncPoint *syncp)
|
||||
{
|
||||
mfxStatus sts = MFX_ERR_NONE;
|
||||
|
||||
if (NULL == out || NULL == syncp)
|
||||
{
|
||||
return MFX_ERR_NULL_PTR;
|
||||
};
|
||||
|
||||
if (!in)
|
||||
{
|
||||
if (!m_LockedSurfacesList.empty())
|
||||
{
|
||||
// subtract 1 to handle minimal difference between input and expected timestamps
|
||||
if (m_nCurrentPTS - 1 <= m_LockedSurfacesList[0]->Data.TimeStamp)
|
||||
{
|
||||
mfxU64 nPTS = m_LockedSurfacesList[0]->Data.TimeStamp;
|
||||
m_LockedSurfacesList[0]->Data.TimeStamp = m_nCurrentPTS;
|
||||
|
||||
sts = MFXVideoVPP::RunFrameVPPAsync(m_LockedSurfacesList[0], out, aux, syncp);
|
||||
|
||||
m_LockedSurfacesList[0]->Data.TimeStamp = nPTS;
|
||||
|
||||
if (MFX_WRN_DEVICE_BUSY != sts)
|
||||
{
|
||||
m_nCurrentPTS += m_nIncreaseTime;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(std::vector<mfxFrameSurface1*>::iterator it = m_LockedSurfacesList.begin(); it != m_LockedSurfacesList.end(); ++it)
|
||||
{
|
||||
msdk_atomic_dec16((volatile mfxU16*)(&(*it)->Data.Locked));
|
||||
}
|
||||
|
||||
m_LockedSurfacesList.clear();
|
||||
|
||||
return MFXVideoVPP::RunFrameVPPAsync(in, out, aux, syncp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return MFXVideoVPP::RunFrameVPPAsync(in, out, aux, syncp);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nArraySize = m_LockedSurfacesList.size();
|
||||
|
||||
if (!m_nArraySize)
|
||||
{
|
||||
m_nCurrentPTS = (mfxU64)in->Data.TimeStamp;
|
||||
|
||||
msdk_atomic_inc16((volatile mfxU16*)&in->Data.Locked);
|
||||
m_LockedSurfacesList.push_back(in);
|
||||
|
||||
return MFX_ERR_MORE_DATA;
|
||||
}
|
||||
|
||||
if (1 == m_nArraySize)
|
||||
{
|
||||
if (in->Data.TimeStamp < m_nCurrentPTS)
|
||||
{
|
||||
return MFX_ERR_MORE_DATA;
|
||||
}
|
||||
|
||||
if (in->Data.TimeStamp > m_LockedSurfacesList[0]->Data.TimeStamp && (in->Data.TimeStamp < m_nCurrentPTS + m_nIncreaseTime/2))
|
||||
{
|
||||
return MFX_ERR_MORE_DATA;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
mfxStatus stsRunFrame = MFX_ERR_NONE;
|
||||
|
||||
m_nInputTimeStamp = m_LockedSurfacesList[0]->Data.TimeStamp;
|
||||
|
||||
if (m_nCurrentPTS <= m_LockedSurfacesList[0]->Data.TimeStamp ||
|
||||
m_nCurrentPTS < (in->Data.TimeStamp - (mfxF64)m_nIncreaseTime/2))
|
||||
{
|
||||
m_nInputTimeStamp = m_LockedSurfacesList[0]->Data.TimeStamp;
|
||||
m_LockedSurfacesList[0]->Data.TimeStamp = m_nCurrentPTS;
|
||||
|
||||
stsRunFrame = sts = MFXVideoVPP::RunFrameVPPAsync(m_LockedSurfacesList[0], out, aux, syncp);
|
||||
|
||||
m_LockedSurfacesList[0]->Data.TimeStamp = m_nInputTimeStamp;
|
||||
|
||||
if (MFX_WRN_DEVICE_BUSY != stsRunFrame)
|
||||
{
|
||||
m_nCurrentPTS += m_nIncreaseTime;
|
||||
}
|
||||
|
||||
if (MFX_ERR_NONE == stsRunFrame)
|
||||
{
|
||||
sts = MFX_ERR_MORE_SURFACE;
|
||||
}
|
||||
}
|
||||
|
||||
if (MFX_WRN_DEVICE_BUSY != stsRunFrame)
|
||||
{
|
||||
if (1 == m_nArraySize)
|
||||
{
|
||||
msdk_atomic_inc16((volatile mfxU16*)&in->Data.Locked);
|
||||
m_LockedSurfacesList.push_back(in);
|
||||
}
|
||||
|
||||
if (m_nCurrentPTS > m_LockedSurfacesList[0]->Data.TimeStamp &&
|
||||
m_nCurrentPTS >= (m_LockedSurfacesList[1]->Data.TimeStamp - (mfxF64)m_nIncreaseTime/2))
|
||||
{
|
||||
msdk_atomic_dec16((volatile mfxU16*)&m_LockedSurfacesList[0]->Data.Locked);
|
||||
m_LockedSurfacesList.erase(m_LockedSurfacesList.begin());
|
||||
|
||||
if (MFX_ERR_NONE == stsRunFrame)
|
||||
{
|
||||
if (stsRunFrame != sts)
|
||||
{
|
||||
sts = MFX_ERR_NONE;
|
||||
}
|
||||
else
|
||||
{
|
||||
sts = MFX_ERR_MORE_DATA;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return sts;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user