diff options
author | Hendrik Leppkes <h.leppkes@gmail.com> | 2017-03-07 13:18:17 +0300 |
---|---|---|
committer | Hendrik Leppkes <h.leppkes@gmail.com> | 2017-03-07 13:18:17 +0300 |
commit | 2aac58f37cde3352dccaf5331edf4e6332c31aa6 (patch) | |
tree | de3f64a4d845e2e9dd0475574be290ce21492245 /common | |
parent | e43997a98af24b5d336ab51cedc62ee9ada03c49 (diff) |
msdk_mvc: Unescape SEI NALs before parsing them
Diffstat (limited to 'common')
-rw-r--r-- | common/DSUtilLite/H264Nalu.cpp | 38 | ||||
-rw-r--r-- | common/DSUtilLite/H264Nalu.h | 13 |
2 files changed, 51 insertions, 0 deletions
diff --git a/common/DSUtilLite/H264Nalu.cpp b/common/DSUtilLite/H264Nalu.cpp index 4ee5e20a..578b86f1 100644 --- a/common/DSUtilLite/H264Nalu.cpp +++ b/common/DSUtilLite/H264Nalu.cpp @@ -114,3 +114,41 @@ bool CH265Nalu::ReadNext() return false; } + + +CH264NALUnescape::CH264NALUnescape(const BYTE *src, size_t nSize) +{ + m_pBuffer = (BYTE *)_aligned_malloc(nSize + 16, 16); + memset(m_pBuffer, 0, nSize + 16); + + unsigned si = 0, di = 0; + BYTE *dst = m_pBuffer; + while (si + 2 < nSize) { + // detect and remove escapes + if (src[si + 2] > 3) { + dst[di++] = src[si++]; + dst[di++] = src[si++]; + } + else if (src[si] == 0 && src[si + 1] == 0 && src[si + 2] != 0) { + if (src[si + 2] == 3) { // escape + dst[di++] = 0; + dst[di++] = 0; + si += 3; + + continue; + } + } + + dst[di++] = src[si++]; + } + + while (si < nSize) + dst[di++] = src[si++]; + + m_nSize = di; +} + +CH264NALUnescape::~CH264NALUnescape() +{ + _aligned_free(m_pBuffer); +} diff --git a/common/DSUtilLite/H264Nalu.h b/common/DSUtilLite/H264Nalu.h index cb68425f..d7f947f6 100644 --- a/common/DSUtilLite/H264Nalu.h +++ b/common/DSUtilLite/H264Nalu.h @@ -87,3 +87,16 @@ public: CH265Nalu() : CH264Nalu() {}; bool ReadNext(); }; + +class CH264NALUnescape +{ +public: + CH264NALUnescape(const BYTE *pBuffer, size_t nSize); + ~CH264NALUnescape(); + const BYTE *GetBuffer() const { return m_pBuffer; } + size_t GetSize() const { return m_nSize; } + +private: + BYTE *m_pBuffer = nullptr; + size_t m_nSize = 0; +}; |