From cd2222cba3f97f0e660e534a8c9d9214492fdd58 Mon Sep 17 00:00:00 2001 From: Hendrik Leppkes Date: Sat, 23 Jul 2011 18:27:02 +0200 Subject: Moved ByteParser helper class into DSUtilLite --- demuxer/Demuxers/ByteParser.cpp | 93 ------------------------------- demuxer/Demuxers/ByteParser.h | 76 ------------------------- demuxer/Demuxers/Demuxers.vcxproj | 2 - demuxer/Demuxers/Demuxers.vcxproj.filters | 6 -- 4 files changed, 177 deletions(-) delete mode 100644 demuxer/Demuxers/ByteParser.cpp delete mode 100644 demuxer/Demuxers/ByteParser.h (limited to 'demuxer/Demuxers') diff --git a/demuxer/Demuxers/ByteParser.cpp b/demuxer/Demuxers/ByteParser.cpp deleted file mode 100644 index 8597edd9..00000000 --- a/demuxer/Demuxers/ByteParser.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2011 Hendrik Leppkes - * http://www.1f0.de - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * Initial design and concept by Gabest and the MPC-HC Team, copyright under GPLv2 - */ - -#include "stdafx.h" -#include "ByteParser.h" - -CByteParser::CByteParser(const BYTE *pData, uint32_t length) - : m_pData(pData), m_pCurrent(pData), m_pEnd(pData+length), m_dwLen(length), m_bitBuffer(0), m_bitLen(0) -{ -} - -CByteParser::~CByteParser() -{ -} - -uint32_t CByteParser::BitRead(uint8_t numBits, bool peek) -{ - ASSERT(numBits <= 32); - ASSERT(numBits <= (m_bitLen + (8 * (m_pEnd - m_pCurrent)))); - - if (numBits == 0) { return 0; } - - bool atEnd = false; - // Read more data in the buffer - while(m_bitLen < numBits) { - m_bitBuffer <<= 8; - m_bitBuffer += !atEnd ? *m_pCurrent : 0; - // Just a safety check so we don't cross the array boundary - if (m_pCurrent < m_pEnd) { m_pCurrent++; } else { atEnd = true; } - m_bitLen += 8; - } - - // Number of superfluous bits in the buffer - int bitlen = m_bitLen - numBits; - - // Compose the return value - // Shift the value so the superfluous bits fall off, and then crop the result with an AND - uint32_t ret = (m_bitBuffer >> bitlen) & ((1ui64 << numBits) - 1); - - // If we're not peeking, then update the buffer and remove the data we just read - if(!peek) { - m_bitBuffer &= ((1ui64 << bitlen) - 1); - m_bitLen = bitlen; - } - - return ret; -} - -// Exponential Golomb Coding (with k = 0) -// As used in H.264/MPEG-4 AVC -// http://en.wikipedia.org/wiki/Exponential-Golomb_coding - -uint64_t CByteParser::UExpGolombRead() { - int n = -1; - for(BYTE b = 0; !b; n++) { - b = BitRead(1); - } - return (1ui64 << n) - 1 + BitRead(n); -} - -int64_t CByteParser::SExpGolombRead() { - uint64_t k = UExpGolombRead(); - // Negative numbers are interleaved in the series - // k: 0, 1, 2, 3, 4, 5, 6, ... - // Actual: 0, 1, -1, 2, -2, 3, -3, .... - // So all even numbers are negative (last bit = 0) - return ((k&1) ? 1 : -1) * ((k + 1) >> 1); -} - -void CByteParser::Seek(DWORD pos) -{ - m_pCurrent = m_pData + min(m_dwLen, pos); - BitFlush(); -} diff --git a/demuxer/Demuxers/ByteParser.h b/demuxer/Demuxers/ByteParser.h deleted file mode 100644 index 695a7acd..00000000 --- a/demuxer/Demuxers/ByteParser.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (C) 2011 Hendrik Leppkes - * http://www.1f0.de - * - * This Program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This Program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; see the file COPYING. If not, write to - * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. - * http://www.gnu.org/copyleft/gpl.html - * - * Initial design and concept by Gabest and the MPC-HC Team, copyright under GPLv2 - */ - -#pragma once - -/** -* Byte Parser Utility Class -*/ -class CByteParser -{ -public: - /** Construct a Byte Parser to parse the given BYTE array with the given length */ - CByteParser(const BYTE *pData, uint32_t length); - virtual ~CByteParser(); - - /** Read 1 to 32 Bits from the Byte Array. If peek is set, the data will just be returned, and the buffer not advanced. */ - uint32_t BitRead(uint8_t numBits, bool peek = false); - - /** Read a unsigned number in Exponential Golomb encoding (with k = 0) */ - uint64_t UExpGolombRead(); - /** Read a signed number in Exponential Golomb encoding (with k = 0) */ - int64_t SExpGolombRead(); - - /** Seek to the position (in bytes) in the byte array */ - void Seek(DWORD pos); - - /** Pointer to the start of the byte array */ - const BYTE *Start() const { return m_pData; } - /** Pointer to the end of the byte array */ - const BYTE *End() const { return m_pEnd; } - - /** Overall length (in bytes) of the byte array */ - uint32_t Length() const { return m_dwLen; } - /** Current byte position in the array. Any incomplete bytes ( buffer < 8 bits ) will not be counted */ - uint32_t Pos() const { return uint32_t(m_pCurrent - m_pData) - (m_bitLen>>3); } - /** Number of bytes remaining in the array */ - uint32_t Remaining() const { return Length() - Pos(); } - - /** Flush any bits currently in the buffer */ - void BitFlush() { m_bitLen = 0; m_bitBuffer = 0; } - /** Skip bits until the next byte border */ - void BitByteAlign() { BitRead(m_bitLen & 7); } - -private: - // Pointer to the start of the data buffer - const BYTE * const m_pData; - - // Pointer to the current position in the data buffer - const BYTE *m_pCurrent; - // Pointer to the end in the data buffer - const BYTE * const m_pEnd; - - const uint32_t m_dwLen; - - uint64_t m_bitBuffer; - uint8_t m_bitLen; -}; diff --git a/demuxer/Demuxers/Demuxers.vcxproj b/demuxer/Demuxers/Demuxers.vcxproj index d14cb4cd..60b0ff31 100644 --- a/demuxer/Demuxers/Demuxers.vcxproj +++ b/demuxer/Demuxers/Demuxers.vcxproj @@ -122,7 +122,6 @@ - @@ -135,7 +134,6 @@ - diff --git a/demuxer/Demuxers/Demuxers.vcxproj.filters b/demuxer/Demuxers/Demuxers.vcxproj.filters index d2a6da50..9440bb3b 100644 --- a/demuxer/Demuxers/Demuxers.vcxproj.filters +++ b/demuxer/Demuxers/Demuxers.vcxproj.filters @@ -33,9 +33,6 @@ Header Files - - Header Files - Header Files @@ -68,9 +65,6 @@ Source Files - - Source Files - Source Files -- cgit v1.2.3