[x265-commits] [x265] bitstream: unify resetBits() and clear() methods
Steve Borho
steve at borho.org
Fri Jun 20 06:27:43 CEST 2014
details: http://hg.videolan.org/x265/rev/0d77026a11ac
branches:
changeset: 7139:0d77026a11ac
user: Steve Borho <steve at borho.org>
date: Thu Jun 19 21:09:56 2014 -0500
description:
bitstream: unify resetBits() and clear() methods
There's no point in having a virtual resetBits() method in the abstract class
and then not implemeent in the derived class but make a second method with
identical semantics. What the heck?
Subject: [x265] move bitstream implementations into common
details: http://hg.videolan.org/x265/rev/5091ffc86a42
branches:
changeset: 7140:5091ffc86a42
user: Steve Borho <steve at borho.org>
date: Thu Jun 19 22:17:38 2014 -0500
description:
move bitstream implementations into common
diffstat:
source/Lib/TLibCommon/TComBitStream.cpp | 136 ---------------------------
source/Lib/TLibCommon/TComBitStream.h | 108 ---------------------
source/Lib/TLibEncoder/SyntaxElementWriter.h | 6 +-
source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp | 8 +-
source/Lib/TLibEncoder/TEncBinCoderCABAC.h | 7 +-
source/Lib/TLibEncoder/TEncCu.cpp | 6 +-
source/Lib/TLibEncoder/TEncCu.h | 4 +-
source/Lib/TLibEncoder/TEncEntropy.h | 7 +-
source/Lib/TLibEncoder/TEncSbac.cpp | 2 +-
source/Lib/TLibEncoder/TEncSbac.h | 5 +-
source/common/CMakeLists.txt | 5 +-
source/common/bitstream.cpp | 103 ++++++++++++++++++++
source/common/bitstream.h | 67 +++++++++++++
source/encoder/cturow.cpp | 10 +-
source/encoder/cturow.h | 1 -
source/encoder/encoder.cpp | 2 +-
source/encoder/frameencoder.cpp | 28 ++--
source/encoder/frameencoder.h | 10 +-
source/encoder/framefilter.h | 2 +-
source/encoder/nal.cpp | 8 +-
source/encoder/nal.h | 6 +-
source/encoder/sei.cpp | 6 +-
source/encoder/sei.h | 6 +-
23 files changed, 237 insertions(+), 306 deletions(-)
diffs (truncated from 1020 to 300 lines):
diff -r 0b4a50730f21 -r 5091ffc86a42 source/Lib/TLibCommon/TComBitStream.cpp
--- a/source/Lib/TLibCommon/TComBitStream.cpp Thu Jun 19 20:46:10 2014 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,136 +0,0 @@
-/* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * 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.
- * * Neither the name of the ITU/ISO/IEC 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.
- */
-
-#include "common.h"
-#include "TComBitStream.h"
-
-using namespace x265;
-
-#define MIN_FIFO_SIZE 1000
-
-TComOutputBitstream::TComOutputBitstream()
-{
- m_fifo = X265_MALLOC(uint8_t, MIN_FIFO_SIZE);
- m_byteAlloc = MIN_FIFO_SIZE;
- clear();
-}
-
-void TComOutputBitstream::push_back(uint8_t val)
-{
- if (!m_fifo)
- return;
-
- if (m_byteOccupancy >= m_byteAlloc)
- {
- /** reallocate buffer with doubled size */
- uint8_t *temp = X265_MALLOC(uint8_t, m_byteAlloc * 2);
- if (temp)
- {
- ::memcpy(temp, m_fifo, m_byteOccupancy);
- X265_FREE(m_fifo);
- m_fifo = temp;
- m_byteAlloc *= 2;
- }
- else
- {
- x265_log(NULL, X265_LOG_ERROR, "Unable to realloc bitstream buffer");
- return;
- }
- }
- m_fifo[m_byteOccupancy++] = val;
-}
-
-void TComOutputBitstream::write(uint32_t val, uint32_t numBits)
-{
- X265_CHECK(numBits <= 32, "numBits out of range\n");
- X265_CHECK(numBits == 32 || (val & (~0 << numBits)) == 0, "numBits & val out of range\n");
-
- uint32_t totalPartialBits = m_partialByteBits + numBits;
- uint32_t nextPartialBits = totalPartialBits & 7;
- uint8_t nextHeldByte = val << (8 - nextPartialBits);
- uint32_t writeBytes = totalPartialBits >> 3;
-
- if (writeBytes)
- {
- /* topword aligns m_partialByte with the msb of val */
- uint32_t topword = (numBits - nextPartialBits) & ~7;
- uint32_t write_bits = (m_partialByte << topword) | (val >> nextPartialBits);
-
- switch (writeBytes)
- {
- case 4: push_back(write_bits >> 24);
- case 3: push_back(write_bits >> 16);
- case 2: push_back(write_bits >> 8);
- case 1: push_back(write_bits);
- }
-
- m_partialByte = nextHeldByte;
- m_partialByteBits = nextPartialBits;
- }
- else
- {
- m_partialByte |= nextHeldByte;
- m_partialByteBits = nextPartialBits;
- }
-}
-
-void TComOutputBitstream::writeByte(uint32_t val)
-{
- // Only CABAC will call writeByte, the fifo must be byte aligned
- X265_CHECK(!m_partialByteBits, "expecting m_partialByteBits = 0\n");
-
- push_back(val);
-}
-
-void TComOutputBitstream::writeAlignOne()
-{
- uint32_t numBits = (8 - m_partialByteBits) & 0x7;
-
- write((1 << numBits) - 1, numBits);
-}
-
-void TComOutputBitstream::writeAlignZero()
-{
- if (m_partialByteBits)
- {
- push_back(m_partialByte);
- m_partialByte = 0;
- m_partialByteBits = 0;
- }
-}
-
-void TComOutputBitstream::writeByteAlignment()
-{
- write(1, 1);
- writeAlignZero();
-}
diff -r 0b4a50730f21 -r 5091ffc86a42 source/Lib/TLibCommon/TComBitStream.h
--- a/source/Lib/TLibCommon/TComBitStream.h Thu Jun 19 20:46:10 2014 -0500
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,108 +0,0 @@
-/* The copyright in this software is being made available under the BSD
- * License, included below. This software may be subject to other third party
- * and contributor rights, including patent rights, and no such rights are
- * granted under this license.
- *
- * Copyright (c) 2010-2013, ITU/ISO/IEC
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- *
- * * Redistributions of source code must retain the above copyright notice,
- * this list of conditions and the following disclaimer.
- * * 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.
- * * Neither the name of the ITU/ISO/IEC 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.
- */
-
-/** \file TComBitStream.h
- \brief class for handling bitstream (header)
-*/
-
-#ifndef X265_COMBITSTREAM_H
-#define X265_COMBITSTREAM_H
-
-#include "common.h"
-
-namespace x265 {
-// private namespace
-
-class TComBitIf
-{
-public:
-
- virtual void writeAlignOne() {}
- virtual void writeAlignZero() {}
- virtual void write(uint32_t val, uint32_t numBits) = 0;
- virtual void writeByte(uint32_t val) = 0;
- virtual void resetBits() = 0;
- virtual uint32_t getNumberOfWrittenBits() const = 0;
- virtual ~TComBitIf() {}
-};
-
-class TComBitCounter : public TComBitIf
-{
-protected:
-
- uint32_t m_bitCounter;
-
-public:
-
- TComBitCounter() : m_bitCounter(0) {}
-
- void write(uint32_t, uint32_t num) { m_bitCounter += num; }
- void writeByte(uint32_t) { m_bitCounter += 8; }
- void resetBits() { m_bitCounter = 0; }
- uint32_t getNumberOfWrittenBits() const { return m_bitCounter; }
-};
-
-
-class TComOutputBitstream : public TComBitIf
-{
-public:
-
- TComOutputBitstream();
- ~TComOutputBitstream() { X265_FREE(m_fifo); }
-
- void clear() { m_partialByteBits = m_byteOccupancy = 0; m_partialByte = 0; }
- uint32_t getNumberOfWrittenBytes() const { return m_byteOccupancy; }
- uint32_t getNumberOfWrittenBits() const { return m_byteOccupancy * 8 + m_partialByteBits; }
- const uint8_t* getFIFO() const { return m_fifo; }
-
- void write(uint32_t val, uint32_t numBits);
- void writeByte(uint32_t val);
-
- void writeAlignOne(); // insert one bits until the bitstream is byte-aligned
- void writeAlignZero(); // insert zero bits until the bitstream is byte-aligned
- void writeByteAlignment(); // insert 1 bit, then pad to byte-align with zero
-
-private:
-
- uint8_t *m_fifo;
- uint32_t m_byteAlloc;
- uint32_t m_byteOccupancy;
- uint32_t m_partialByteBits;
- uint8_t m_partialByte;
-
- void resetBits() { X265_CHECK(0, "resetBits called on base class\n"); }
- void push_back(uint8_t val);
-};
-}
-
-#endif // ifndef X265_COMBITSTREAM_H
diff -r 0b4a50730f21 -r 5091ffc86a42 source/Lib/TLibEncoder/SyntaxElementWriter.h
--- a/source/Lib/TLibEncoder/SyntaxElementWriter.h Thu Jun 19 20:46:10 2014 -0500
+++ b/source/Lib/TLibEncoder/SyntaxElementWriter.h Thu Jun 19 22:17:38 2014 -0500
@@ -39,7 +39,7 @@
#define X265_SYNTAXELEMENTWRITER_H
#include "common.h"
-#include "TLibCommon/TComBitStream.h"
+#include "bitstream.h"
#include "TLibCommon/TComRom.h"
//! \ingroup TLibEncoder
@@ -68,13 +68,13 @@ class SyntaxElementWriter
{
protected:
- TComBitIf* m_bitIf;
+ BitInterface* m_bitIf;
SyntaxElementWriter()
: m_bitIf(NULL)
{}
- void setBitstream(TComBitIf* p) { m_bitIf = p; }
+ void setBitstream(BitInterface* p) { m_bitIf = p; }
void xWriteCode(uint32_t code, uint32_t len);
void xWriteUvlc(uint32_t code);
diff -r 0b4a50730f21 -r 5091ffc86a42 source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp
--- a/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp Thu Jun 19 20:46:10 2014 -0500
+++ b/source/Lib/TLibEncoder/TEncBinCoderCABAC.cpp Thu Jun 19 22:17:38 2014 -0500
@@ -35,9 +35,11 @@
\brief binary entropy encoder of CABAC
*/
+#include "common.h"
+#include "bitstream.h"
+#include "threading.h" // CLZ32
+#include "TLibCommon/TComRom.h"
#include "TEncBinCoderCABAC.h"
-#include "TLibCommon/TComRom.h"
-#include "threading.h" // CLZ32
using namespace x265;
@@ -53,7 +55,7 @@ TEncBinCABAC::TEncBinCABAC(bool isCounte
TEncBinCABAC::~TEncBinCABAC()
{}
More information about the x265-commits
mailing list