diff options
author | povaddict <povaddict@users.sourceforge.net> | 2010-02-10 02:16:44 +0300 |
---|---|---|
committer | povaddict <povaddict@users.sourceforge.net> | 2010-02-10 02:16:44 +0300 |
commit | 726a91b12a7524e45e7a901c9e4883af5b1bffe6 (patch) | |
tree | f5d25e3b2e84c92f4901280c73d5d3d7e6c3cd19 /src/filters/parser/DiracSplitter/libdirac/libdirac_byteio | |
parent | 02183f6e47ad4ea1057de9950482f291f2ae4290 (diff) |
Rename several directories to use MixedCase instead of lowercase.
They now mostly match the case used in #includes,
and they're consistent with the names of the .h files they contain.
git-svn-id: https://mpc-hc.svn.sourceforge.net/svnroot/mpc-hc/trunk@1648 10f7b99b-c216-0410-bff0-8a66a9350fd8
Diffstat (limited to 'src/filters/parser/DiracSplitter/libdirac/libdirac_byteio')
30 files changed, 5830 insertions, 0 deletions
diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp new file mode 100644 index 000000000..33bb8ff9f --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.cpp @@ -0,0 +1,192 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: accessunit_byteio.cpp,v 1.7 2008/08/14 00:51:08 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_common/dirac_exception.h> +#include <libdirac_byteio/accessunit_byteio.h> + +using namespace dirac; + +// Constructor for encoding +SequenceHeaderByteIO::SequenceHeaderByteIO( SourceParams& src_params, + EncoderParams& enc_params): +ParseUnitByteIO(), +m_parseparams_byteio(*this, m_parse_params, enc_params), +// create default source parameters for comparisions +m_default_src_params(src_params.GetVideoFormat()), +m_src_params(src_params), +m_sourceparams_byteio( m_src_params, + m_default_src_params, + *this), +m_codec_params(enc_params), +m_codingparams_byteio(m_src_params, + m_codec_params, + m_default_src_params, + *this) +{ +} + +// Constructor for decoding +SequenceHeaderByteIO::SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, + ParseParams& parse_params, + SourceParams& src_params, + CodecParams& codec_params) : +ParseUnitByteIO(parseunit_byteio), +m_parseparams_byteio( parseunit_byteio, parse_params), +m_src_params(src_params), +m_sourceparams_byteio( m_src_params, + m_default_src_params, + parseunit_byteio), +m_codec_params(codec_params), +m_codingparams_byteio( m_src_params, + m_codec_params, + m_default_src_params, + parseunit_byteio) +{ +} + +SequenceHeaderByteIO::~SequenceHeaderByteIO() +{ +} + +//-----public------------------------------------------------------ +bool SequenceHeaderByteIO::Input() +{ + //int o=mp_stream->tellg(); + InputParseParams(); + + // Inout Video format + SetByteParams(m_parseparams_byteio); + VideoFormat vf = IntToVideoFormat(ReadUint()); + if(vf==VIDEO_FORMAT_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_VIDEO_FORMAT, + "Dirac does not recognise the specified video-format", + SEVERITY_ACCESSUNIT_ERROR); + + SourceParams src_params(vf, true); + m_src_params = src_params; + + InputSourceParams(); + + CodecParams codec_params(vf); + m_codec_params = codec_params; + + InputCodingParams(); + + return true; +} + +void SequenceHeaderByteIO::Output() +{ + OutputParseParams(); + + // Output the video format + SetByteParams(m_parseparams_byteio); + WriteUint(static_cast<int>(m_src_params.GetVideoFormat())); + + OutputSourceParams(); + + OutputCodingParams(); + +} + +int SequenceHeaderByteIO::GetSize() const +{ + return ParseUnitByteIO::GetSize()+ + m_parseparams_byteio.GetSize()+ + ByteIO::GetSize() + + m_sourceparams_byteio.GetSize()+ + m_codingparams_byteio.GetSize(); +} + + + +//-------private------------------------------------------------------- + +unsigned char SequenceHeaderByteIO::CalcParseCode() const +{ + unsigned char code = 0; + + // no further mods required + + return code; +} + + +void SequenceHeaderByteIO::InputSourceParams() +{ + // copy current input params + m_sourceparams_byteio.SetByteParams(*this); + + m_sourceparams_byteio.Input(); +} + +void SequenceHeaderByteIO::InputParseParams() +{ + m_parseparams_byteio.Input(); +} + +void SequenceHeaderByteIO::InputCodingParams() +{ + // copy current input params + m_codingparams_byteio.SetByteParams(m_sourceparams_byteio); + + m_codingparams_byteio.Input(); +} + +void SequenceHeaderByteIO::OutputSourceParams() +{ + // copy current output params + m_sourceparams_byteio.SetByteParams(*this); + + m_sourceparams_byteio.Output(); +} + +void SequenceHeaderByteIO::OutputParseParams() +{ + m_parseparams_byteio.Output(); +} + +void SequenceHeaderByteIO::OutputCodingParams() +{ + // copy current output params + m_codingparams_byteio.SetByteParams(m_sourceparams_byteio); + + m_codingparams_byteio.Output(); +} + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h new file mode 100644 index 000000000..2c2966ed8 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/accessunit_byteio.h @@ -0,0 +1,182 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: accessunit_byteio.h,v 1.7 2008/08/14 00:51:08 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy(Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class SequenceHeaderByteIO +*/ +#ifndef accessunit_byteio_h +#define accessunit_byteio_h + +//LOCAL INCLUDES +#include <libdirac_byteio/parseunit_byteio.h> // Parent class +#include <libdirac_byteio/parseparams_byteio.h> // ParseParamsByteIO class +#include <libdirac_byteio/displayparams_byteio.h> // SourceParamsByteIO class +#include <libdirac_byteio/codingparams_byteio.h> // CodingParamsByteIO class + +namespace dirac +{ + /** + * A random access point within a Dirac bytestream + */ + class SequenceHeaderByteIO : public ParseUnitByteIO + { + public: + + /** + * Constructor (encoding) + *@param src_params Source parameters for current AccessUnit + *@param enc_params Encoder parameters for current AccessUnit + */ + SequenceHeaderByteIO( SourceParams& src_params, + EncoderParams& enc_params); + + /** + * Constructor (decoding) + *@param parseunit_byteio Source of data + *@param parse_params Destination of parse paramters data + *@param src_params Destination of source paramters data + *@param codec_params Destination of coding paramters data + */ + SequenceHeaderByteIO(const ParseUnitByteIO& parseunit_byteio, + ParseParams& parse_params, + SourceParams& src_params, + CodecParams& codec_params); + + /** + * Destructor + */ + ~SequenceHeaderByteIO(); + + /** + * Parses data in Dirac-stream format (decoding) + */ + bool Input(); + + /** + * Writes access-unit info to Dirac stream-format (encoding) + */ + void Output(); + + /* + * Gets size of access-unit (in bytes) + */ + int GetSize() const; + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_SEQ_HEADER;} + + private: + + /** + * Calculates parse-code based on access-unit parameters (encoding) + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + /** + * Parse source attributes from bytestream-compatible input (decoding) + */ + void InputSourceParams(); + + /** + * Parse parse attributes from bytestream-compatible input (decoding) + */ + void InputParseParams(); + + /** + * Parse Coding attributes from bytestream-compatible input (decoding) + */ + void InputCodingParams(); + + /** + * Output source attributes for bytestream-compatible output (encoding) + */ + void OutputSourceParams(); + + /** + * Output parse attributes for bytestream-compatible output (encoding) + */ + void OutputParseParams(); + + /** + * Output coding attributes for bytestream-compatible output (encoding) + */ + void OutputCodingParams(); + + /** + * Current parse parameters + */ + ParseParams m_parse_params; + + + /** + * Parse-params byte input/output + */ + ParseParamsByteIO m_parseparams_byteio; + + /** + * Default source parameters + */ + SourceParams m_default_src_params; + + /** + * Current source parameters + */ + SourceParams& m_src_params; + + /** + * Source-params byte input/output + */ + SourceParamsByteIO m_sourceparams_byteio; + + /** + * Current codec parameters + */ + CodecParams& m_codec_params; + + /** + * Coding-params byte input/output + */ + CodingParamsByteIO m_codingparams_byteio; + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp new file mode 100644 index 000000000..12b129953 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.cpp @@ -0,0 +1,299 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: byteio.cpp,v 1.4 2008/03/14 08:17:36 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author), +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <cmath> +#include <libdirac_byteio/byteio.h> +using namespace dirac; +using namespace std; + +ByteIO::ByteIO(bool new_stream): +m_current_byte(0), +m_current_pos(0), +m_num_bytes(0), +m_new_stream(true), +m_bits_left(0) +{ + if(new_stream) + mp_stream = new stringstream(stringstream::in | stringstream::out | + stringstream::binary); + + +} + +ByteIO::ByteIO(const ByteIO& stream_data): +m_current_byte(0), +m_current_pos(0), +m_num_bytes(0), +m_new_stream(false), +m_bits_left(0) +{ + mp_stream=stream_data.mp_stream; +} + + +ByteIO::~ByteIO() +{ + if (m_new_stream) + delete mp_stream; +} + +const string ByteIO::GetBytes() +{ + return mp_stream->str(); +} + +int ByteIO::GetSize() const +{ + return m_num_bytes; +} + +void ByteIO::SetByteParams(const ByteIO& byte_io) +{ + mp_stream=byte_io.mp_stream; + m_current_byte=byte_io.m_current_byte; + m_current_pos=byte_io.m_current_pos; +} + +//----------protected--------------------------------------------------------------- + +void ByteIO::ByteAlignInput() +{ + m_current_pos=0; + m_current_byte=0; +} + +void ByteIO::ByteAlignOutput() +{ + if(m_current_pos!=0) + OutputCurrentByte(); +} + +int ByteIO::ReadBit() +{ + if(m_current_pos == CHAR_BIT) + m_current_pos=0; + + if (m_current_pos == 0) + m_current_byte = InputUnByte(); +#if 1 + // MSB to LSB + return GetBit(m_current_byte, (CHAR_BIT-1-m_current_pos++)); +#else + // LSB to MSB + return GetBit(m_current_byte, m_current_pos++); +#endif +} + +int ByteIO::ReadBitB() +{ + if (m_bits_left) + { + --m_bits_left; + return ReadBit(); + } + else + return 1; +} + +bool ByteIO::ReadBool() +{ + return ReadBit(); +} + +bool ByteIO::ReadBoolB() +{ + return ReadBitB(); +} + +unsigned int ByteIO::ReadNBits(int count) +{ + unsigned int val = 0; + for (int i = 0; i < count; ++i) + { + val <<= 1; + val += ReadBit(); + } + return val; +} + +void ByteIO::FlushInputB() +{ + while(m_bits_left) + { + ReadBit(); + --m_bits_left; + } +} + +int ByteIO::ReadSint() +{ + + int val = ReadUint(); + bool bit; + + //get the sign + if (val != 0) + { + bit = ReadBit(); + if (bit ) + val = -val; + } + return val; +} + +int ByteIO::ReadSintB() +{ + + int val = ReadUintB(); + bool bit; + + //get the sign + if (val != 0) + { + bit = ReadBitB(); + if (bit ) + val = -val; + } + return val; +} + +unsigned int ByteIO::ReadUint() +{ + unsigned int value = 1; + while (!ReadBit()) + { + value <<= 1; + if (ReadBit()) + value +=1; + } + --value; + return value; +} + +unsigned int ByteIO::ReadUintB() +{ + unsigned int value = 1; + while (!ReadBitB()) + { + value <<= 1; + if (ReadBitB()) + value +=1; + } + --value; + return value; +} + +void ByteIO::WriteBit(const bool& bit) +{ + if(bit) +#if 1 + // MSB to LSB + SetBit(m_current_byte, CHAR_BIT-1-m_current_pos); +#else + // LSB to MSB + SetBit(m_current_byte, m_current_pos); +#endif + + if ( m_current_pos == CHAR_BIT-1) + { + // If a whole byte has been written, output to stream + OutputCurrentByte(); + m_current_byte = 0; + m_current_pos = 0; + } + else + // Shift mask to next bit in the output byte + ++m_current_pos; +} + +void ByteIO::WriteNBits(unsigned int val, int count) +{ + do + { + WriteBit(val & ( 1 << (count-1))); + count--; + } + while(count > 0); +} + +int ByteIO::WriteNBits(unsigned int val) +{ + int nbits = static_cast<int>(log(static_cast<double>(val))/log(2.0)) + 1; + WriteNBits(val, nbits); + return nbits; +} + +void ByteIO::WriteSint(int val) +{ + unsigned int value = (val >= 0 ? val : -val); + //output magnitude + WriteUint(value); + + //do sign + if (val<0) WriteBit(1); + else if (val>0) WriteBit(0); +} + +void ByteIO::WriteUint(unsigned int value) +{ + unsigned int val = value+1; + + int num_follow_zeroes = 0; + + while (val >= (1U <<num_follow_zeroes)) + ++num_follow_zeroes; + --num_follow_zeroes; + + for (int i=num_follow_zeroes-1; i>=0; --i) + { + WriteBit(BIT_ZERO); + WriteBit(val&(1<<i)); + } + WriteBit(BIT_ONE); +} + +void ByteIO::RemoveRedundantBytes(const int size) +{ + int prev_pos = mp_stream->tellg(); + string data=mp_stream->str(); + data.erase(0, size); + mp_stream->str(data); + m_num_bytes=data.size(); + if(data.size()) + SeekGet(max(prev_pos-size, 0), ios_base::beg); +} diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h new file mode 100644 index 000000000..db885d658 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/byteio.h @@ -0,0 +1,397 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: byteio.h,v 1.11 2009/01/21 05:18:09 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author), +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class ByteIO. +*/ +#ifndef byteio_h +#define byteio_h + +// SYSTEM INCLUDES +#include <iostream> // IO classes +#include <sstream> // IO classes +#include <iomanip> // setw +#include <climits> // CHAR_BIT + +//LOCAL INCLUDEs +#include <libdirac_byteio/dirac_byte_stats.h> // stores stats + +namespace dirac +{ + + // BIT DEFS + #define BIT_ZERO 0 + #define BIT_ONE 1 + + // most significant bit in a character + #define MS_BIT (1 << (CHAR_BIT - 1)) + + /* array index for character containing bit */ + //#define BIT_IN_CHAR(bit) (1 << (CHAR_BIT-1-bit)) + #define BIT_IN_CHAR(bit) (1 << bit) + + + /** + * Class ByteIO - top-level class for reading/writing bytes to a stream + */ + class ByteIO + { + public: + + /** + * Default constructor + *@param new_stream <B>Has Creates & owns data buffer </B> + */ + ByteIO(bool new_stream=true); + + /** + * Constructor + *@param stream_data Copies data buffer details + */ + ByteIO(const ByteIO& stream_data); + + /** + * Destructor + */ + virtual ~ByteIO(); + + /** + * Gathers byte-stream statistics + *@param dirac_byte_stats Collates byte information + */ + virtual void CollateByteStats(DiracByteStats& dirac_byte_stats) + { dirac_byte_stats.Clear(); } + + /** + * Get bytes in Dirac-bytestream format + */ + virtual const std::string GetBytes(); + + /** + * Get position of read stream pointer + */ + int GetReadBytePosition() const { return mp_stream->tellg();}; + + + /** + *Gets size (in bytes) + */ + virtual int GetSize() const; + + /** + * Copies stream source/destination info + *@param byte_io Byte source/destination + */ + void SetByteParams(const ByteIO& byte_io); + + /** + * Sync input for byte-alignment + */ + void ByteAlignOutput(); + + /** + * Ouputs an unsigned integer in interleaved exp Golomb format + *@param value Integer to be output + */ + //void OutputVarLengthUint(const unsigned int& value); + void WriteUint(unsigned int value); + + /** + * Sets input size in bits. Read is limited by this + */ + void SetBitsLeft(int left_bits) { m_bits_left = left_bits; } + + /** + * Sets input size in bits. Read is limited by this + */ + int BitsLeft(void) { return m_bits_left; } + + protected: + + inline bool CanRead() const { return(!mp_stream->eof()); } + + inline bool GetBit(unsigned char& c, int pos) const { return (c & BIT_IN_CHAR(pos)); } + + inline void SetBit(unsigned char& c, int pos) const { c |= BIT_IN_CHAR(pos); } + + inline void SetBits(unsigned char& c, unsigned char bits) const { c |= bits; } + + /** + * Sync input for byte-alignment + */ + void ByteAlignInput(); + + + /** + * Reads boolean value + */ + bool ReadBool(); + + /** + * Reads boolean value - bounded i/o + */ + bool ReadBoolB(); + + /** + * Reads next bit + */ + int ReadBit(); + + /** + * Reads next bit - bounded i/o + */ + int ReadBitB(); + + /** + * Reads next 'count' bits + *@param count number of bits to be read + *@return unsigned interger read + */ + unsigned int ReadNBits(int count); + + /** + * Reads from stream + *@param data Start of char buffer + *@param count Number of bytes to read + */ + void InputBytes(char* data, int count) + { + //int j=mp_stream->tellg(); + mp_stream->read(data, count); + + //int h=mp_stream->tellg(); + } + + /** + * Flushes the bounde input + */ + void FlushInputB(); + + /** + * Reads a signed integer in interleaved exp-Golomb format + *return Signed integer read + */ + //int InputVarLengthInt(); + int ReadSint(); + + /** + * Reads a signed integer in interleaved exp-Golomb format from bounded input + *return Signed integer read + */ + int ReadSintB(); + + /** + * Reads an unsigned integer in interleaved exp Golomb format + *@return Unsigned Integer read + */ + //unsigned int InputVarLengthUint(); + unsigned int ReadUint(); + + /** + * Reads an unsigned integer in interleaved exp Golomb format from bounded input + *@return Unsigned Integer read + */ + //unsigned int InputVarLengthUint(); + unsigned int ReadUintB(); + + /** + * Reads a fixed length unsigned integer from the stream in big endian + *@param byte_size Number of bytes in fixed length integer + *@return Unsigned Integer read + */ + //inline unsigned int InputFixedLengthUint(const int byte_size) { + inline unsigned int ReadUintLit(const int byte_size) { + unsigned int val=0; + for(int i=0; i < byte_size; ++i) + { + val <<= 8; + val += (unsigned char)mp_stream->get(); + } + m_num_bytes+=byte_size; + return val; + } + + /** + * Reads a byte from the stream + */ + inline unsigned char InputUnByte() {m_num_bytes++ ; return mp_stream->get(); } + + /** + * Reads a series of bytes from a stream + */ + inline std::string InputUnString(const int count) + { + std::string str; + for(int index=0; index < count; ++index) + str.push_back(InputUnByte()); + return str; + } + + /** + * Outputs a bit + *@param bit 1/0 Output + */ + void WriteBit(const bool& bit); + + /** + * Outputs an unsigned integer + *@param val Integer to be output + *@return number of bits written + */ + int WriteNBits(unsigned int val); + + /** + * Outputs an n bit integer + *@param val Unsigned Integer to be output + *@param count number of bits to be written + */ + void WriteNBits(unsigned int val, int count); + + + + /** + * Outputs a series of bytes + */ + void OutputBytes(const std::string& bytes) { + int cur_pos = mp_stream->tellg(); + mp_stream->str(mp_stream->str()+bytes); + m_num_bytes+=bytes.size(); + // *mp_stream << bytes; + mp_stream->seekg(std::max(cur_pos,0), std::ios_base::beg); + } + + /** + * Outputs current byte contents + */ + inline void OutputCurrentByte() + { + if (m_current_pos) + { + *mp_stream << (m_current_byte); + ++m_num_bytes; + m_current_pos = 0; + m_current_byte = 0; + } + }; + + /** + * Outputs an integer in Golomb signed integer format + *@param val Integer to be output + */ + //void OutputVarLengthInt(const int val); + void WriteSint(int val); + + /** + * Output unsigned int value in big endian format + * @param value Integer to be output + * @param length number of bytes in val to output + */ + //inline void OutputFixedLengthUint(const unsigned int& value, const int& length) + inline void WriteUintLit(const unsigned int& value, const int& length) + { + for(int i=length-1; i >=0 ; --i) + { + unsigned char cp = (value>>(i*8))&0xff; + *mp_stream << cp; + } + m_num_bytes+=length; + } + + /** + * Removes portion of byte-stream no longer required + *@param count Number of bytes to be removed from beginning of stream + */ + void RemoveRedundantBytes(const int count); + + inline void SeekGet(const int offset, std::ios_base::seekdir dir) + { + mp_stream->seekg(offset, dir); + } + + /** + * Input/output steam + */ + std::stringstream* mp_stream; + + + private: + + /** + * ArithCodec can see internals for getting/setting bits + */ + friend class ArithCodecBase; + + /** + * VLC entropy coder can see internals for getting/setting bits + */ + friend class ArithCodecToVLCAdapter; + + /** + * Char used for temporary storage of op data bits + */ + unsigned char m_current_byte; + + /** + * Used to set individual bit within the current header byte + */ + int m_current_pos; + + /** + * Number of bytes processed + */ + int m_num_bytes; + + /** + * stream alloc flag + */ + bool m_new_stream; + + /** + * num bits left to read + */ + int m_bits_left; + protected: + + + }; + + + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp new file mode 100644 index 000000000..7326b4562 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.cpp @@ -0,0 +1,134 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: codingparams_byteio.cpp,v 1.9 2008/04/29 08:51:52 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/codingparams_byteio.h> +#include <libdirac_common/common.h> +#include <libdirac_common/dirac_exception.h> + +using namespace dirac; + +CodingParamsByteIO::CodingParamsByteIO(const SourceParams& src_params, + CodecParams& codec_params, + const SourceParams& default_source_params, + const ByteIO& stream_data): +ByteIO(stream_data), +m_src_params(src_params), +m_codec_params(codec_params), +m_default_source_params(default_source_params) +{ + +} + +CodingParamsByteIO::~CodingParamsByteIO() +{ +} + +//---------public--------------------------------------------------- + +void CodingParamsByteIO::Input() +{ + // input picture coding mode + InputPictureCodingMode(); + + m_codec_params.SetTopFieldFirst(m_src_params.TopFieldFirst()); + + // Set the dimensions to frame dimensions + m_codec_params.SetXl(m_src_params.Xl()); + m_codec_params.SetYl(m_src_params.Yl()); + + m_codec_params.SetChromaXl(m_src_params.ChromaWidth()); + m_codec_params.SetChromaYl(m_src_params.ChromaHeight()); + + // If source was coded as fields, halve the vertical dimensions + // to set them to field dimensions + if (m_codec_params.FieldCoding()) + { + m_codec_params.SetYl(m_codec_params.Yl()>>1); + m_codec_params.SetChromaYl(m_codec_params.ChromaYl()>>1); + } + + unsigned int luma_depth = static_cast<unsigned int> + ( + std::log((double)m_src_params.LumaExcursion())/std::log(2.0) + 1 + ); + m_codec_params.SetLumaDepth(luma_depth); + + unsigned int chroma_depth = static_cast<unsigned int> + ( + std::log((double)m_src_params.ChromaExcursion())/std::log(2.0) + 1 + ); + m_codec_params.SetChromaDepth(chroma_depth); + + // byte align + ByteAlignInput(); +} + + +void CodingParamsByteIO::Output() +{ + // output picture coding mode flag + OutputPictureCodingMode(); + + // byte align + ByteAlignOutput(); +} + +//-------------private--------------------------------------------------------------- + +void CodingParamsByteIO::InputPictureCodingMode() +{ + unsigned int coding_mode = ReadUint(); + if (coding_mode > 1) + { + std::ostringstream errstr; + errstr << "Picture coding mode " << coding_mode + << " out of range [0-1]"; + DIRAC_THROW_EXCEPTION( + ERR_UNSUPPORTED_STREAM_DATA, + errstr.str(), + SEVERITY_ACCESSUNIT_ERROR); + } + m_codec_params.SetPictureCodingMode(coding_mode); +} + + +void CodingParamsByteIO::OutputPictureCodingMode() +{ + WriteUint(m_codec_params.FieldCoding() ? 1 : 0); +} + + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h new file mode 100644 index 000000000..b96b037a0 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/codingparams_byteio.h @@ -0,0 +1,135 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: codingparams_byteio.h,v 1.3 2007/12/05 01:42:40 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class CodingParamsByteIO +*/ +#ifndef codingparams_byteio_h +#define codingparams_byteio_h + + +// DIRAC INCLUDES +#include <libdirac_common/common.h> // CodecParams, SourceParams + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class + + +namespace dirac +{ + + /** + * Represents compressed sequence-parameter data used in an AccessUnit + */ + class CodingParamsByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param src_params Source parameters + *@param codec_params Coding parameters + *@param default_source_params Default source parameters + *@param stream_data Source/Destination of data + */ + CodingParamsByteIO(const SourceParams& src_params, + CodecParams& codec_params, + const SourceParams& default_source_params, + const ByteIO& stream_data); + + + /** + * Destructor + */ + ~CodingParamsByteIO(); + + /** + * Reads sequence information from Dirac byte-format + */ + void Input(); + + /** + * Outputs sequence information to Dirac byte-format + */ + void Output(); + + protected: + + + private: + + /** + * Reads number of bits used to compress input signal + */ + void InputVideoDepth(); + + /** + * Reads picture coding mode - 0 - frames, 1 - fields + */ + void InputPictureCodingMode(); + + /** + * Outputs number of bits used to compress input signal + */ + void OutputVideoDepth(); + + /** + * Outputs how input was coded - i.e. frames or fields + */ + void OutputPictureCodingMode(); + + /** + * Source paramters for intput/output + */ + const SourceParams& m_src_params; + + /** + * Coding paramters for intput/output + */ + CodecParams& m_codec_params; + + /** + * Default source parameters + */ + const SourceParams& m_default_source_params; + + }; + + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp new file mode 100644 index 000000000..07f5433d1 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.cpp @@ -0,0 +1,98 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: component_byteio.cpp,v 1.2 2008/04/29 08:51:52 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/component_byteio.h> + +using namespace dirac; +using namespace std; + +ComponentByteIO::ComponentByteIO(CompSort cs, + const ByteIO& byteio): +ByteIO(byteio), +m_compsort(cs) +{} + +ComponentByteIO::ComponentByteIO(CompSort cs): +ByteIO(), +m_compsort(cs) +{} + +ComponentByteIO::~ComponentByteIO() +{} + +//--------------public---------------------------------------------- + +void ComponentByteIO::AddSubband(SubbandByteIO* p_subband_byteio) +{ + OutputBytes(p_subband_byteio->GetBytes()); +} + +void ComponentByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) +{ + // set number of component bytes + switch(m_compsort) + { + case Y_COMP: + dirac_byte_stats.SetByteCount(STAT_YCOMP_BYTE_COUNT, + GetSize()); + break; + case U_COMP: + dirac_byte_stats.SetByteCount(STAT_UCOMP_BYTE_COUNT, + GetSize()); + break; + case V_COMP: + dirac_byte_stats.SetByteCount(STAT_VCOMP_BYTE_COUNT, + GetSize()); + break; + } +} + +bool ComponentByteIO::Input() +{ + + return true; +} + +void ComponentByteIO::Output() +{ + + +} + + +//-------------private------------------------------------------------------- + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h new file mode 100644 index 000000000..e80b0877a --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/component_byteio.h @@ -0,0 +1,125 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class ComponentByteIO +*/ +#ifndef component_byteio_h +#define component_byteio_h + + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class +#include <libdirac_byteio/subband_byteio.h> // child-type + +// DIRAC includes + +// SYSTEM INCLUDES +#include <vector> + +namespace dirac +{ + /** + * Picture component in Dirac bytestream format + */ + class ComponentByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param cs Picture-component type + *@param byteIO Input/output Byte stream + */ + ComponentByteIO(CompSort cs, + const ByteIO& byteIO); + + /** + * Constructor + *@param cs Picture-component type + */ + ComponentByteIO(CompSort cs); + + /** + * Destructor + */ + ~ComponentByteIO(); + + /** + * Gathers byte stats on the component data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Add a subband byte-stream to this component + *@param p_subband_byteio Subband to be added + */ + void AddSubband(SubbandByteIO *p_subband_byteio); + + /** + * Inputs data from Dirac stream-format + */ + bool Input(); + + /** + * Outputs picture values to Dirac stream-format + */ + void Output(); + + + + protected: + + + private: + + /** + * Picture component type + */ + CompSort m_compsort; + + /** + * List of subbands in output/input order + */ + std::vector<ByteIO*> m_subband_list; + + + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp new file mode 100644 index 000000000..9c697bc3d --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.cpp @@ -0,0 +1,84 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: dirac_byte_stats.cpp,v 1.3 2008/04/29 12:27:49 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/dirac_byte_stats.h> + +using namespace dirac; +using namespace std; + + +DiracByteStats::DiracByteStats() +{ +} + +DiracByteStats::DiracByteStats(const DiracByteStats& dirac_byte_stats): +m_byte_count(dirac_byte_stats.m_byte_count) +{ +} + +DiracByteStats::~DiracByteStats() +{ +} + + +void DiracByteStats::Clear() +{ + m_byte_count.clear(); +} + +int64_t DiracByteStats::GetBitCount(const StatType& stat_type) const +{ + return GetByteCount(stat_type) * CHAR_BIT; +} + +int64_t DiracByteStats::GetByteCount(const StatType& stat_type) const +{ + std::map<StatType, int64_t>::const_iterator it; + it = m_byte_count.find(stat_type); + if(it==m_byte_count.end()) + return 0; + + return it->second; +} + +void DiracByteStats::SetByteCount(const StatType& stat_type, int64_t count) +{ + if(m_byte_count.find(stat_type)==m_byte_count.end()) + m_byte_count[stat_type]=0; + + m_byte_count[stat_type]+=count; + } diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h new file mode 100644 index 000000000..0da273f0a --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stats.h @@ -0,0 +1,120 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: dirac_byte_stats.h,v 1.5 2008/05/06 09:35:51 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class DiracByteStats +*/ +#ifndef dirac_byte_stats_h +#define dirac_byte_stats_h + +// SYSTEM INCLUDES +#include <map> // for byte-counts +#include <climits> + +#include <libdirac_common/dirac_inttypes.h> + +namespace dirac +{ + + #ifdef _MSC_VER + // char length + #define CHAR_BIT 8 +#endif + + typedef enum { + STAT_TOTAL_BYTE_COUNT=0, + STAT_MV_BYTE_COUNT, + STAT_YCOMP_BYTE_COUNT, + STAT_UCOMP_BYTE_COUNT, + STAT_VCOMP_BYTE_COUNT + } StatType; + + + /** + * Class DiracByteStats - for collecting statistics on aspects of the Dirac byte-stream + */ + class DiracByteStats + { + public: + /** + * Constructor + */ + DiracByteStats(); + + /** + * Copy constructor + */ + DiracByteStats(const DiracByteStats& dirac_byte_stats); + + /** + * Destructor + */ + ~DiracByteStats(); + + /** + * Clears data + */ + void Clear(); + + /** + * Gets number of bits for a particular stat-type + */ + int64_t GetBitCount(const StatType& stat_type) const; + + /** + * Gets number of bytes for a particular stat-type + */ + int64_t GetByteCount(const StatType& stat_type) const; + + /** + * Sets number of bytes for a particular stat-type + */ + void SetByteCount(const StatType& stat_type, int64_t count); + + + private: + + /** + * Map of byte-counts + */ + std::map<StatType, int64_t> m_byte_count; + + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp new file mode 100644 index 000000000..a45e54706 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.cpp @@ -0,0 +1,264 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: dirac_byte_stream.cpp,v 1.8 2008/08/14 00:51:08 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/dirac_byte_stream.h> +#include <libdirac_byteio/endofsequence_byteio.h> +#include <libdirac_common/dirac_exception.h> + +using namespace dirac; +using namespace std; + +DiracByteStream::DiracByteStream(): +ByteIO(), +mp_prev_parse_unit(NULL) +{ +} + +DiracByteStream::~DiracByteStream() +{ + delete mp_prev_parse_unit; +} + +//---------------decoding---------------------------------------------------- + +void DiracByteStream::AddBytes(char* start, + int count) +{ + // add to input stream + string str(start, count); + ByteIO::OutputBytes(str); + +} + +DiracByteStats DiracByteStream::GetLastUnitStats() +{ + DiracByteStats dirac_byte_stats; + + if(m_parse_unit_list.empty()) + return dirac_byte_stats; + + ParseUnitByteIO* p_parse_unit = m_parse_unit_list.back().second; + p_parse_unit->CollateByteStats(dirac_byte_stats); + + return dirac_byte_stats; +} + +void DiracByteStream::Reset(ParseUnitByteIO* p_curr_unit, int pos) +{ + delete p_curr_unit; + SeekGet(pos, ios_base::beg); +} + +ParseUnitByteIO* DiracByteStream::GetNextParseUnit() +{ + if(GetSize()==0) + return NULL; + + int pos=0; + if(mp_prev_parse_unit) + { + // remove the unwanted bytes associated with the previous parse-unit + int prev_offset = mp_prev_parse_unit->GetNextParseOffset(); + RemoveRedundantBytes(prev_offset ? prev_offset : mp_prev_parse_unit->GetSize()); + delete mp_prev_parse_unit; + mp_prev_parse_unit=NULL; + if(!GetSize()) + return NULL; + } + + ParseUnitByteIO* p_curr_unit=NULL; + + while(true) + { + pos = GetReadBytePosition(); + + p_curr_unit = new ParseUnitByteIO(*this); + if (!p_curr_unit->Input()) + { + Reset(p_curr_unit, pos); + return NULL; + } + + // skip past current unit + if(!p_curr_unit->CanSkip()) + { + Reset(p_curr_unit, pos); + return NULL; + } + + if (p_curr_unit->IsEndOfSequence()) + { + break; + } + + // look to see if next unit validates the current one + if(!p_curr_unit->IsValid()) + { + // delete the unit - it's invalid + delete p_curr_unit; + // remove unwanted portion of bytes + RemoveRedundantBytes(pos); + // look for next potential parse-unit + continue; + } + break; + } // while + + // Remove all redundant bytes that are not part of a parse unit + int remove_size = std::max (0, GetReadBytePosition()-p_curr_unit->GetSize()); + if (remove_size) + { + //std::cerr << "Size="<<GetSize() << " Un-useful bytes=" << remove_size << std::endl; + RemoveRedundantBytes(remove_size); + } + + mp_prev_parse_unit=p_curr_unit; + return p_curr_unit; +} + +DiracByteStats DiracByteStream::GetSequenceStats() const +{ + return m_sequence_stats; +} + +//---------------encoding----------------------------------------------------- + +void DiracByteStream::AddSequenceHeader(SequenceHeaderByteIO *p_seqheader_byteio) +{ + // set previous parse-unit details + ParseUnitByteIO *mp_previous_parse_unit=mp_prev_parse_unit; + + if(!m_parse_unit_list.empty()) + mp_previous_parse_unit = m_parse_unit_list.back().second; + + // set adjacent parse-unit + p_seqheader_byteio->SetAdjacentParseUnits(mp_previous_parse_unit); + + // push onto to pending list + m_parse_unit_list.push(std::make_pair (PU_SEQ_HEADER, p_seqheader_byteio) ); + + // set previous parse-unit + mp_previous_parse_unit = p_seqheader_byteio; + + // save stats + p_seqheader_byteio->CollateByteStats(m_sequence_stats); +} + +void DiracByteStream::AddPicture(PictureByteIO *p_frame_byteio) +{ + // set previous parse-unit details + ParseUnitByteIO *mp_previous_parse_unit=mp_prev_parse_unit; + + if(!m_parse_unit_list.empty()) + mp_previous_parse_unit = m_parse_unit_list.back().second; + + // set adjacent parse-unit + p_frame_byteio->SetAdjacentParseUnits(mp_previous_parse_unit); + + // push onto to pending list + m_parse_unit_list.push(std::make_pair(PU_PICTURE, p_frame_byteio ) ); + + // set previous parse-unit + mp_previous_parse_unit = p_frame_byteio; + + // save stats + p_frame_byteio->CollateByteStats(m_sequence_stats); +} + +void DiracByteStream::Clear() +{ + while(!m_parse_unit_list.empty()) + { + ParseUnitByteIO* p_parse_unit=m_parse_unit_list.front().second; + m_parse_unit_list.pop(); + if(m_parse_unit_list.empty()) + { + delete mp_prev_parse_unit; + mp_prev_parse_unit=p_parse_unit; + } + else + delete p_parse_unit; + } +} + +DiracByteStats DiracByteStream::EndSequence() +{ + // create + EndOfSequenceByteIO *p_endofsequence_byteio = new EndOfSequenceByteIO(*this); + + // set previous parse-unit details + ParseUnitByteIO *mp_previous_parse_unit=mp_prev_parse_unit; + + if(!m_parse_unit_list.empty()) + mp_previous_parse_unit = m_parse_unit_list.back().second; + + // set adjacent parse-unit + p_endofsequence_byteio->SetAdjacentParseUnits(mp_previous_parse_unit); + + // push onto to pending list + m_parse_unit_list.push(std::make_pair(PU_END_OF_SEQUENCE, p_endofsequence_byteio) ); + + p_endofsequence_byteio->CollateByteStats(m_sequence_stats); + + // clear stats + DiracByteStats seq_stats(m_sequence_stats); + m_sequence_stats.Clear(); + + // return seq stats + return seq_stats; +} + +const string DiracByteStream::GetBytes() +{ + // take copy + ParseUnitList parse_list = m_parse_unit_list; + mp_stream->str(""); + + while(!parse_list.empty()) + { + *mp_stream << parse_list.front().second->GetBytes(); + parse_list.pop(); + } + + return mp_stream->str(); +} + +bool DiracByteStream::IsUnitAvailable() const +{ + return !m_parse_unit_list.empty(); +} diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.h new file mode 100644 index 000000000..d448b5fca --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/dirac_byte_stream.h @@ -0,0 +1,158 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: dirac_byte_stream.h,v 1.4 2008/08/14 00:51:08 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class DiracByteStream +*/ +#ifndef dirac_byte_stream_h +#define dirac_byte_stream_h + +//SYSTEM INCLUDES +#include <queue> + +//LOCAL INCLUDES +#include "byteio.h" // Parent class +#include "accessunit_byteio.h" // manages parse-unit types +#include "picture_byteio.h" // manages parse-unit types + +namespace dirac +{ + + /** + * Represents a series of bytes in the Dirac bytestream specfication format. + * These bytes are grouped into more managable parse units by this class. + */ + class DiracByteStream : public ByteIO + { + public: + + /** + * Constructor + */ + DiracByteStream(); + + /** + * Destructor + */ + ~DiracByteStream(); + + /** + * Adds Dirac-formatted bytes to internal-byte-stream for processing + *@param start Start of char list + *@param count Number of chars + */ + void AddBytes(char* start, int count); + + /** + * Gets the statistics of the most recent parse-unit to be processed + *@return Byte-statistics + */ + DiracByteStats GetLastUnitStats(); + + /** + * Gets the next parse-unit in the current byte-stream + */ + ParseUnitByteIO* GetNextParseUnit(); + + + /** + * Gets stats for current sequence + */ + DiracByteStats GetSequenceStats() const; + + /** + * Adds a random access point to the current Dirac byte stream + *@param p_seqheader_byteio Sequence header data. + */ + void AddSequenceHeader(SequenceHeaderByteIO *p_seqheader_byteio); + + /** + * Adds a picture to the current Dirac byte stream + *@param p_frame_byteio Picture stream. This class is now responsible for deleting. + */ + void AddPicture(PictureByteIO *p_frame_byteio); + + /** + * Clear parse-units + */ + void Clear(); + + /** + * Insert end-of-sequence data + *@return Sequence stats + */ + DiracByteStats EndSequence(); + + /** + * Gets a pointer to all current output bytes + */ + const std::string GetBytes(); + + /** + * Any info pending? + */ + bool IsUnitAvailable() const; + + private: + + void Reset(ParseUnitByteIO* p_curr_unit, int pos); + + private: + + /** + * Parse-units in Dirac stream + */ + typedef std::queue< std::pair <ParseUnitType, ParseUnitByteIO*> > ParseUnitList; + ParseUnitList m_parse_unit_list; + + /** + * Last unit to be processed + * Required for specifying the previous parse-unit + */ + ParseUnitByteIO* mp_prev_parse_unit; + + /** + * Stats for current sequence + */ + DiracByteStats m_sequence_stats; + + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.cpp new file mode 100644 index 000000000..e74a4f278 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.cpp @@ -0,0 +1,502 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: displayparams_byteio.cpp,v 1.10 2008/01/31 11:25:15 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/displayparams_byteio.h> +#include <libdirac_common/dirac_exception.h> + +using namespace dirac; + +SourceParamsByteIO::SourceParamsByteIO( SourceParams& src_params, + const SourceParams& default_src_params, + const ByteIO& stream_data): +ByteIO(stream_data), +m_src_params(src_params), +m_default_src_params(default_src_params) +{ + + +} + +SourceParamsByteIO::~SourceParamsByteIO() +{ +} + +//-----------------public---------------------------------------------------- + +void SourceParamsByteIO::Input() +{ + // input frame dimensions + InputFrameSize(); + + // input chroma sampling format + InputChromaSamplingFormat(); + + // input scan format + InputScanFormat(); + + // input frame rate + InputFrameRate(); + + // input pixel aspect ratio + InputPixelAspectRatio(); + + // input clean area + InputCleanArea(); + + // input signal range + InputSignalRange(); + + // input colour spec + InputColourSpecification(); +} + +void SourceParamsByteIO::Output() +{ + // output frame dimensions + OutputFrameSize(); + + // output chroma sampling format + OutputChromaSamplingFormat(); + + // output scan format + OutputScanFormat(); + + // output frame rate + OutputFrameRate(); + + // output pixel aspect ratio + OutputPixelAspectRatio(); + + // output clean area + OutputCleanArea(); + + // output signal range + OutputSignalRange(); + + // output colour spec + OutputColourSpecification(); +} + +//-------------------private----------------------------------------------- +void SourceParamsByteIO::InputFrameSize() +{ + bool custom_flag = ReadBool(); + + if(!custom_flag) + return; + + // set custom width + m_src_params.SetXl(ReadUint()); + + // set custom height + m_src_params.SetYl(ReadUint()); +} + +void SourceParamsByteIO::InputChromaSamplingFormat() +{ + bool chroma_flag = ReadBool(); + + if(!chroma_flag) + return; + + // set chroma + ChromaFormat chroma_format = IntToChromaFormat(ReadUint()); + if(chroma_format==formatNK) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_CHROMA_FORMAT, + "Dirac does not recognise the specified chroma-format", + SEVERITY_ACCESSUNIT_ERROR) + m_src_params.SetCFormat(chroma_format); +} + +void SourceParamsByteIO::InputPixelAspectRatio() +{ + bool pixel_aspect_ratio_flag = ReadBool(); + if(!pixel_aspect_ratio_flag) + return; + + // read index value + int pixel_aspect_ratio_index = ReadUint(); + PixelAspectRatioType pixel_aspect_ratio=IntToPixelAspectRatioType(pixel_aspect_ratio_index); + if(pixel_aspect_ratio==PIXEL_ASPECT_RATIO_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_PIXEL_ASPECT_RATIO, + "Dirac does not recognise the specified pixel_aspect_ratio", + SEVERITY_ACCESSUNIT_ERROR) + + if(pixel_aspect_ratio_index!=PIXEL_ASPECT_RATIO_CUSTOM) + { + m_src_params.SetPixelAspectRatio(pixel_aspect_ratio); + } + else + { + // read num/denom + int numerator = ReadUint(); + int denominator = ReadUint(); + m_src_params.SetPixelAspectRatio(numerator, denominator); + } + +} + +void SourceParamsByteIO::InputCleanArea() +{ + bool clean_area_flag = ReadBool(); + if(!clean_area_flag) + return; + + m_src_params.SetCleanWidth( ReadUint() ); + m_src_params.SetCleanHeight( ReadUint() ); + m_src_params.SetLeftOffset( ReadUint() ); + m_src_params.SetTopOffset( ReadUint() ); +} + +void SourceParamsByteIO::InputColourMatrix() +{ + bool colour_matrix_flag = ReadBool(); + if(!colour_matrix_flag) + return; + + // read index value + int colour_matrix_index = ReadUint(); + m_src_params.SetColourMatrixIndex(colour_matrix_index); +} + +void SourceParamsByteIO::InputColourPrimaries() +{ + bool colour_primaries_flag = ReadBool(); + if(!colour_primaries_flag) + return; + + // read index value + int colour_primaries_index = ReadUint(); + m_src_params.SetColourPrimariesIndex(colour_primaries_index); +} + +void SourceParamsByteIO::InputColourSpecification() +{ + bool colour_spec_flag = ReadBool(); + if(!colour_spec_flag) + return; + + // read index value + int colour_spec_index = ReadUint(); + m_src_params.SetColourSpecification( colour_spec_index ); + if(colour_spec_index==0) + { + InputColourPrimaries(); + InputColourMatrix(); + InputTransferFunction(); + } +} + +void SourceParamsByteIO::InputFrameRate() +{ + bool fr_flag = ReadBool(); + if(!fr_flag) + return; + + int frame_rate_index = ReadUint(); + FrameRateType frame_rate=IntToFrameRateType(frame_rate_index); + if(frame_rate==FRAMERATE_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_PICTURE_RATE, + "Dirac does not recognise the specified frame-rate", + SEVERITY_ACCESSUNIT_ERROR) + + if(frame_rate_index!=FRAMERATE_CUSTOM) + { + m_src_params.SetFrameRate(frame_rate); + } + else + { + // read num/denom + int numerator = ReadUint(); + int denominator = ReadUint(); + m_src_params.SetFrameRate(numerator, denominator); + } +} + +void SourceParamsByteIO::InputScanFormat() +{ + bool scan_flag = ReadBool(); + if(!scan_flag) + return; + + unsigned int source_sampling = ReadUint(); + if (source_sampling > 1) + { + std::ostringstream errstr; + errstr << "Source Sampling " << source_sampling + << " out of range [0-1]"; + DIRAC_THROW_EXCEPTION( + ERR_UNSUPPORTED_STREAM_DATA, + errstr.str(), + SEVERITY_ACCESSUNIT_ERROR); + } + m_src_params.SetSourceSampling(source_sampling); +} + +void SourceParamsByteIO::InputSignalRange() +{ + bool signal_range_flag = ReadBool(); + if(!signal_range_flag) + return; + + // read index value + int signal_range_index = ReadUint(); + SignalRangeType signal_range = IntToSignalRangeType(signal_range_index); + if(signal_range==SIGNAL_RANGE_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_SIGNAL_RANGE, + "Dirac does not recognise the specified signal-range", + SEVERITY_ACCESSUNIT_ERROR) + + if(signal_range_index!=SIGNAL_RANGE_CUSTOM) + { + m_src_params.SetSignalRange(signal_range); + } + else + { + // read luma values + m_src_params.SetLumaOffset( ReadUint() ); + m_src_params.SetLumaExcursion( ReadUint() ); + // read chroma values + m_src_params.SetChromaOffset( ReadUint() ); + m_src_params.SetChromaExcursion( ReadUint() ); + } +} + +void SourceParamsByteIO::InputTransferFunction() +{ + bool trans_fun_flag = ReadBool(); + if(!trans_fun_flag) + return; + + // read index value + int trans_fun_index = ReadUint(); + m_src_params.SetTransferFunctionIndex(trans_fun_index); +} + +void SourceParamsByteIO::OutputFrameSize() +{ + + // output 'is custom' dimensions flag + bool is_custom = (m_src_params.Xl()!=m_default_src_params.Xl() || + m_src_params.Yl()!=m_default_src_params.Yl()); + + WriteBit(is_custom); + + if(!is_custom) + return; + + // set custom X and Y + WriteUint(m_src_params.Xl()); + WriteUint(m_src_params.Yl()); + +} + +void SourceParamsByteIO::OutputChromaSamplingFormat() +{ + // output 'is default' flag + bool not_default = m_src_params.CFormat()!=m_default_src_params.CFormat(); + + WriteBit(not_default); + + if(!not_default) + return; + + // output chroma index + WriteUint(static_cast<int>(m_src_params.CFormat())); +} + + +void SourceParamsByteIO::OutputPixelAspectRatio() +{ + if (m_src_params.PixelAspectRatioIndex()!= PIXEL_ASPECT_RATIO_CUSTOM + && m_src_params.PixelAspectRatioIndex() == m_default_src_params.PixelAspectRatioIndex()) + { + // default frame rate index + WriteBit(0); + return; + } + // Non-defaults + WriteBit(1); + + // Picture rate index + WriteUint(m_src_params.PixelAspectRatioIndex()); + + if (!m_src_params.PixelAspectRatioIndex()) // i,e. custom value + { + WriteUint(m_src_params.PixelAspectRatio().m_num); + WriteUint(m_src_params.PixelAspectRatio().m_denom); + } +} + + +void SourceParamsByteIO::OutputCleanArea() +{ + if (m_src_params.CleanWidth() != m_default_src_params.CleanWidth() || + m_src_params.CleanHeight() != m_default_src_params.CleanHeight() || + m_src_params.LeftOffset() != m_default_src_params.LeftOffset() || + m_src_params.TopOffset() != m_default_src_params.TopOffset()) + { + WriteBit(1); // non-default value + WriteUint(m_src_params.CleanWidth()); + WriteUint(m_src_params.CleanHeight()); + WriteUint(m_src_params.LeftOffset()); + WriteUint(m_src_params.TopOffset()); + } + else + WriteBit(0); // default value +} + +void SourceParamsByteIO::OutputColourSpecification() +{ + if (m_src_params.ColourSpecificationIndex() && + m_src_params.ColourSpecificationIndex() == + m_default_src_params.ColourSpecificationIndex()) + { + // default colour specification + WriteBit(0); + return; + } + + // Non-defaults + WriteBit(1); + // Output Colour specification index + WriteUint(m_src_params.ColourSpecificationIndex()); + + if (!m_src_params.ColourSpecificationIndex()) // i,e, custom values + { + // Output Colour Primaries + if (m_src_params.ColourPrimariesIndex() == m_default_src_params.ColourPrimariesIndex()) + { + // default value + WriteBit(0); + } + else + { + WriteBit(1); + WriteUint(m_src_params.ColourPrimariesIndex()); + } + + // Output Colour Matrix + if (m_src_params.ColourMatrixIndex() == m_default_src_params.ColourMatrixIndex()) + { + // default value + WriteBit(0); + } + else + { + WriteBit(1); + WriteUint(m_src_params.ColourMatrixIndex()); + } + + // Output TransferFunction + if (m_src_params.TransferFunctionIndex() == m_default_src_params.TransferFunctionIndex()) + { + // default value + WriteBit(0); + } + else + { + WriteBit(1); + WriteUint(m_src_params.TransferFunctionIndex()); + } + } +} + +void SourceParamsByteIO::OutputFrameRate() +{ + if (m_src_params.FrameRateIndex()!=FRAMERATE_CUSTOM + && m_src_params.FrameRateIndex() == m_default_src_params.FrameRateIndex()) + { + // default frame rate index + WriteBit(0); + return; + } + // Non-defaults + WriteBit(1); + + // Picture rate index + WriteUint(m_src_params.FrameRateIndex()); + + if (!m_src_params.FrameRateIndex()) // i,e. custom value + { + WriteUint(m_src_params.FrameRate().m_num); + WriteUint(m_src_params.FrameRate().m_denom); + } +} + +void SourceParamsByteIO::OutputScanFormat() +{ + // output 'is default' flag + bool not_interlace_default = m_src_params.SourceSampling()!=m_default_src_params.SourceSampling(); + + WriteBit(not_interlace_default); + + if(!not_interlace_default) + return; + + // output interlace value + WriteUint(m_src_params.SourceSampling()); +} + + +void SourceParamsByteIO::OutputSignalRange() +{ + if (m_src_params.SignalRangeIndex()!=SIGNAL_RANGE_CUSTOM && + m_src_params.SignalRangeIndex() == m_default_src_params.SignalRangeIndex()) + { + // defaults + WriteBit(0); + return; + } + + // Non-defaults + WriteBit(1); + // Output Signal Range Index + WriteUint(m_src_params.SignalRangeIndex()); + + if (!m_src_params.SignalRangeIndex()) // i.e. custom values + { + WriteUint(m_src_params.LumaOffset()); + WriteUint(m_src_params.LumaExcursion()); + WriteUint(m_src_params.ChromaOffset()); + WriteUint(m_src_params.ChromaExcursion()); + } +} diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h new file mode 100644 index 000000000..bc5fe823d --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/displayparams_byteio.h @@ -0,0 +1,200 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: displayparams_byteio.h,v 1.4 2008/01/15 04:36:23 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class SourceParamsByteIO +*/ +#ifndef displayparams_byteio_h +#define displayparams_byteio_h + + +// DIRAC INCLUDES +#include <libdirac_common/common.h> // SeqParams + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class + + +namespace dirac +{ + + /** + * Represents compressed source-parameter data contained in a sequence header + */ + class SourceParamsByteIO : public ByteIO + { + public: + + /** + * Constructor for Input/Output + *@param src_params Source parameters + *@param default_src_params Default Source parameters + *@param stream_data Source/Destination of data + */ + SourceParamsByteIO( SourceParams& src_params, + const SourceParams& default_src_params, + const ByteIO& stream_data); + /** + * Destructor + */ + ~SourceParamsByteIO(); + + /** + * Reads source params information from Dirac byte-format + */ + void Input(); + + /** + * Outputs source params information to Dirac byte-format + */ + void Output(); + + protected: + + + private: + + /** + * Reads frame dimensions + */ + void InputFrameSize(); + + /** + * Reads Chroma Sampling Format + */ + void InputChromaSamplingFormat(); + + /** + * Reads pixel aspect ratio info + */ + void InputPixelAspectRatio(); + + /** + * Reads clean-area info + */ + void InputCleanArea(); + + /** + * Reads colour-matrix info + */ + void InputColourMatrix(); + + /** + * Reads primary-colour info + */ + void InputColourPrimaries(); + + /** + * Reads colour spec info + */ + void InputColourSpecification(); + + /** + * Reads frame-rate info + */ + void InputFrameRate(); + + /** + * Reads Scan info + */ + void InputScanFormat(); + + /** + * Reads signal range info + */ + void InputSignalRange(); + + /** + * Reads transfer-function info + */ + void InputTransferFunction(); + + /** + * Outputs frame dimensions + */ + void OutputFrameSize(); + + /** + * Outputs Chroma Sampling Format + */ + void OutputChromaSamplingFormat(); + + /** + * Outputs pixel aspect ratio info + */ + void OutputPixelAspectRatio(); + + /** + * Outputs clean-area info + */ + void OutputCleanArea(); + + /** + * Outputs colour spec info + */ + void OutputColourSpecification(); + + /** + * Outputs frame-rate info + */ + void OutputFrameRate(); + + /** + * Outputs Scan info + */ + void OutputScanFormat(); + + /** + * Outputs signal range info + */ + void OutputSignalRange(); + + /** + * Source parameters for input/ouput + */ + SourceParams& m_src_params; + + /** + * Default source parameters + */ + const SourceParams& m_default_src_params; + }; + + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp new file mode 100644 index 000000000..ca0144e8e --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.cpp @@ -0,0 +1,78 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: endofsequence_byteio.cpp,v 1.2 2007/03/29 16:43:38 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include "endofsequence_byteio.h" + +using namespace dirac; +using namespace std; + + +// start & end of end-of-sequence bits +#define PARSE_CODE_END_OF_SEQUENCE (0x10) + + +EndOfSequenceByteIO::EndOfSequenceByteIO(const ByteIO& byte_io): +ParseUnitByteIO(byte_io) +{ + +} + + +EndOfSequenceByteIO::~EndOfSequenceByteIO() +{ + +} + +void EndOfSequenceByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) +{ + dirac_byte_stats.SetByteCount(STAT_TOTAL_BYTE_COUNT, GetSize()); +} + + + +//-------------private------------------------------------------------------- + +unsigned char EndOfSequenceByteIO::CalcParseCode() const +{ + unsigned char code = 0; + + // set end-of-sequence parse-code + SetBits(code, PARSE_CODE_END_OF_SEQUENCE); + + return code; +} + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h new file mode 100644 index 000000000..0bce3997f --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/endofsequence_byteio.h @@ -0,0 +1,104 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: endofsequence_byteio.h,v 1.3 2008/01/31 11:25:15 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class EndOfSequenceByteIO +*/ +#ifndef endofsequence_byteio_h +#define endofsequence_byteio_h + + +//LOCAL INCLUDES +#include <libdirac_byteio/parseunit_byteio.h> // Parent class + +// DIRAC includes +#include <libdirac_common/common.h> // PictureType etc + +namespace dirac +{ + /** + * Signals the end of a sequence in a Dirac-formatted bitstream. Current Accessunit parameters + * are no longer valid for subsequent frames + */ + class EndOfSequenceByteIO : public ParseUnitByteIO + { + public: + + /** + * Constructor + *@param stream_data Stream parameters + */ + EndOfSequenceByteIO(const ByteIO& stream_data); + + /** + * Destructor + */ + ~EndOfSequenceByteIO(); + + + /** + * Gets parse-unit type + */ + ParseUnitType GetType() const { return PU_END_OF_SEQUENCE;} + + /** + * Gathers byte stats on the end of sequence data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + protected: + + /** + * Calculates number of bytes to start of next unit + *@return Zero(0) End of sequence does not specify a 'next'unit + */ + int CalcNextUnitOffset() { return 0;} + + private: + + /** + * Calculates parse-code based on picture parameters + *@return Char bit-set + */ + unsigned char CalcParseCode() const; + + + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp new file mode 100644 index 000000000..2ed0357aa --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.cpp @@ -0,0 +1,332 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: mvdata_byteio.cpp,v 1.13 2008/08/27 00:17:10 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* Andrew Kennedy +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/mvdata_byteio.h> +#include <libdirac_common/video_format_defaults.h> +#include <libdirac_common/dirac_exception.h> + +using namespace dirac; + +MvDataByteIO::MvDataByteIO(PictureParams& pparams, + PicturePredParams& picpredparams): +ByteIO(), +m_pparams(pparams), +m_picpredparams(picpredparams), +m_splitmode_data(), +m_predmode_data(), +m_mv1hblock_data(), +m_mv1vblock_data(), +m_mv2hblock_data(), +m_mv2vblock_data(), +m_ydcblock_data(), +m_udcblock_data(), +m_vdcblock_data() +{} + +MvDataByteIO::MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, + PicturePredParams& picpredparams): +ByteIO(byte_io), +m_pparams(pparams), +m_picpredparams(picpredparams), +m_splitmode_data(byte_io), +m_predmode_data(byte_io), +m_mv1hblock_data(byte_io), +m_mv1vblock_data(byte_io), +m_mv2hblock_data(byte_io), +m_mv2vblock_data(byte_io), +m_ydcblock_data(byte_io), +m_udcblock_data(byte_io), +m_vdcblock_data(byte_io) +{} + +MvDataByteIO::~MvDataByteIO() +{} + +void MvDataByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) +{ + // set number of MV bytes + dirac_byte_stats.SetByteCount(STAT_MV_BYTE_COUNT, + GetSize()); +} + +int MvDataByteIO::GetSize() const +{ + if (m_pparams.NumRefs()==2) + return ByteIO::GetSize() + + m_splitmode_data.GetSize()+ + m_predmode_data.GetSize()+ + m_mv1hblock_data.GetSize()+ + m_mv1vblock_data.GetSize()+ + m_mv2hblock_data.GetSize()+ + m_mv2vblock_data.GetSize()+ + m_ydcblock_data.GetSize()+ + m_udcblock_data.GetSize()+ + m_vdcblock_data.GetSize(); + else + return ByteIO::GetSize() + + m_splitmode_data.GetSize()+ + m_predmode_data.GetSize()+ + m_mv1hblock_data.GetSize()+ + m_mv1vblock_data.GetSize()+ + m_ydcblock_data.GetSize()+ + m_udcblock_data.GetSize()+ + m_vdcblock_data.GetSize(); +} + +const std::string MvDataByteIO::GetBytes() +{ + //Output header and block data + if (m_pparams.NumRefs()==2 ) + return ByteIO::GetBytes() + + m_splitmode_data.GetBytes()+ + m_predmode_data.GetBytes()+ + m_mv1hblock_data.GetBytes()+ + m_mv1vblock_data.GetBytes()+ + m_mv2hblock_data.GetBytes()+ + m_mv2vblock_data.GetBytes()+ + m_ydcblock_data.GetBytes()+ + m_udcblock_data.GetBytes()+ + m_vdcblock_data.GetBytes(); + else + return ByteIO::GetBytes() + + m_splitmode_data.GetBytes()+ + m_predmode_data.GetBytes()+ + m_mv1hblock_data.GetBytes()+ + m_mv1vblock_data.GetBytes()+ + m_ydcblock_data.GetBytes()+ + m_udcblock_data.GetBytes()+ + m_vdcblock_data.GetBytes(); +} + +void MvDataByteIO::Input() +{ + // Byte Alignment + ByteAlignInput(); + + // Input Block Params + InputBlockParams(); + + // Input Motion Vector Precision + InputMVPrecision(); + + // Input chroma + InputGlobalMotionParams(); + + // Input Picture Prediction mode + InputFramePredictionMode(); + + // Input picture weights + InputPictureWeights(); + + // Byte Alignment + ByteAlignInput(); +} + +void MvDataByteIO::Output() +{ + // Output Block Params + OutputBlockParams(); + + // Output Motion Vector Precision + OutputMVPrecision(); + + // output global motion + OutputGlobalMotionParams(); + + // output picture prediction mode + OutputFramePredictionMode(); + + // output picture weights + OutputPictureWeights(); + + // Byte Align + ByteAlignOutput(); +} + +//-------------private--------------------------------------------------------------- + +void MvDataByteIO::OutputBlockParams() +{ + const OLBParams& olb_params = m_picpredparams.LumaBParams(2); + + // output custom block params flag + unsigned int pidx = BlockParametersIndex(olb_params); + WriteUint(pidx); + if (pidx == 0) // custom block params + { + // output Xblen + WriteUint(olb_params.Xblen()); + // output Yblen + WriteUint(olb_params.Yblen()); + // output Xbsep + WriteUint(olb_params.Xbsep()); + // output Ybsep + WriteUint(olb_params.Ybsep()); + } +} + +void MvDataByteIO::InputBlockParams() +{ + OLBParams olb_params; + + unsigned int p_idx = ReadUint(); + if (p_idx == 0) + { + // Input Xblen + olb_params.SetXblen(ReadUint()); + // Input Yblen + olb_params.SetYblen(ReadUint()); + // Input Xbsep + olb_params.SetXbsep(ReadUint()); + // Input Ybsep + olb_params.SetYbsep(ReadUint()); + } + else + SetDefaultBlockParameters (olb_params, p_idx); + + m_picpredparams.SetLumaBlockParams(olb_params); +} + +void MvDataByteIO::OutputMVPrecision() +{ + // Output Motion vector precision + WriteUint(m_picpredparams.MVPrecision()); +} + +void MvDataByteIO::InputMVPrecision() +{ + // Input Motion vector precision + MVPrecisionType mv_prec = IntToMVPrecisionType(ReadUint()); + if(mv_prec==MV_PRECISION_UNDEFINED) + DIRAC_THROW_EXCEPTION( + ERR_INVALID_MOTION_VECTOR_PRECISION, + "Dirac does not recognise the specified MV precision", + SEVERITY_PICTURE_ERROR) + + m_picpredparams.SetMVPrecision(mv_prec); +} + +void MvDataByteIO::OutputGlobalMotionParams() +{ + // Always setting global motion to false + // NOTE: FIXME - output actual global motion params in future + // Using Global motion flag + WriteBit(false); +} + +void MvDataByteIO::InputGlobalMotionParams() +{ + // Always setting global motion to false + // Using Global motion flag + if (ReadBool()) + { + m_picpredparams.SetUsingGlobalMotion(true); + + // NOTE: FIXME - input actual global motion params in future + DIRAC_THROW_EXCEPTION( + ERR_UNSUPPORTED_STREAM_DATA, + "Cannot handle global motion parameters", + SEVERITY_PICTURE_ERROR) + } + else + m_picpredparams.SetUsingGlobalMotion(false); +} + +void MvDataByteIO::OutputFramePredictionMode() +{ + // TODO: Output default picture prediction mode index until other + // modes are supported. + WriteUint(0); +} + +void MvDataByteIO::InputFramePredictionMode() +{ + // TODO - need to process this field when alternative prediction modes + // become available. + unsigned int frame_pred_mode = ReadUint(); + if (frame_pred_mode != 0) + { + DIRAC_THROW_EXCEPTION( + ERR_UNSUPPORTED_STREAM_DATA, + "Non-default Picture Prediction Mode not supported", + SEVERITY_PICTURE_ERROR); + } +} + + +void MvDataByteIO::OutputPictureWeights() +{ + // Output default weights flags + if (m_picpredparams.PictureWeightsBits() != 1 || + m_picpredparams.Ref1Weight() != 1 || + (m_pparams.Refs().size() > 1 && m_picpredparams.Ref2Weight() != 1) ) + { + WriteBit(true); + // Output weight precision bits + WriteUint(m_picpredparams.PictureWeightsBits()); + // Output Ref1 weight + WriteSint(m_picpredparams.Ref1Weight()); + if (m_pparams.Refs().size() > 1) + { + // Output Ref1 weight + WriteSint(m_picpredparams.Ref2Weight()); + } + } + else + { + WriteBit(false); + } +} + +void MvDataByteIO::InputPictureWeights() +{ + if (ReadBool()) + { + m_picpredparams.SetPictureWeightsPrecision(ReadUint()); + m_picpredparams.SetRef1Weight(ReadSint()); + if (m_pparams.Refs().size() > 1) + m_picpredparams.SetRef2Weight(ReadSint()); + else + m_picpredparams.SetRef2Weight(0); + } + else + { + m_picpredparams.SetPictureWeightsPrecision(1); + m_picpredparams.SetRef1Weight(1); + m_picpredparams.SetRef2Weight(1); + } +} diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h new file mode 100644 index 000000000..578a3594e --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdata_byteio.h @@ -0,0 +1,269 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: mvdata_byteio.h,v 1.5 2008/09/10 12:28:46 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class MvDataByteIO +*/ +#ifndef MV_DATA_BYTEIO_H +#define MV_DATA_BYTEIO_H + + +// DIRAC INCLUDES +#include <libdirac_common/common.h> // EncParams + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class +#include <libdirac_byteio/mvdataelement_byteio.h>// Member byteio class + + +namespace dirac +{ + /** + * Represents compressed sequence-parameter data used in an AccessUnit + */ + class MvDataByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param pparams Picture Params + *@param picpredparams Picture prediction parameters + */ + MvDataByteIO(PictureParams& pparams, + PicturePredParams& picpredparams); + + /** + * Constructor + *@param byte_io Input/Output Byte stream + *@param pparams Picture Params + *@param picpredparams Picture prediction parameters + */ + MvDataByteIO(ByteIO &byte_io, PictureParams& pparams, + PicturePredParams& picpredparams); + + /** + * Destructor + */ + virtual ~MvDataByteIO(); + + /** + * Gathers byte stats on the motion vector data + *@param dirac_byte_stats Stat container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Outputs motion vector data Dirac byte-format + */ + void Output(); + + /** + * Inputs motion vector information + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return pointer to the superblock splitting modes ByteIO stream + */ + MvDataElementByteIO* SplitModeData() { return &m_splitmode_data; }; + + /** + * Return pointer to the superblock splitting modes ByteIO stream + */ + MvDataElementByteIO* PredModeData() { return &m_predmode_data; }; + + /** + * Return pointer to the block MVs reference 1 ByteIO stream + */ + MvDataElementByteIO* MV1HorizData() { return &m_mv1hblock_data; }; + + /** + * Return pointer to the block MVs reference 1 ByteIO stream + */ + MvDataElementByteIO* MV1VertData() { return &m_mv1vblock_data; }; + + /** + * Return pointer to the block MV reference 2 ByteIO stream + */ + MvDataElementByteIO* MV2HorizData() { return &m_mv2hblock_data; }; + + /** + * Return pointer to the block MV reference 2 ByteIO stream + */ + MvDataElementByteIO* MV2VertData() { return &m_mv2vblock_data; }; + + /** + * Return pointer to the block Y DC values ByteIO stream + */ + MvDataElementByteIO* YDCData() { return &m_ydcblock_data; }; + + /** + * Return pointer to the block U DC values ByteIO stream + */ + MvDataElementByteIO* UDCData() { return &m_udcblock_data; }; + + /** + * Return pointer to the block V DC values ByteIO stream + */ + MvDataElementByteIO* VDCData() { return &m_vdcblock_data; }; + + /** + * Return the size + */ + int GetSize() const; + + protected: + + + private: + /** + * Inputs block parameters + */ + void InputBlockParams(); + + /** + * Inputs Motion vector precision data + */ + void InputMVPrecision(); + + /** + * Inputs global motion parameters + */ + void InputGlobalMotionParams(); + + /** + * Inputs picture prediction mode + */ + void InputFramePredictionMode(); + + /** + * Inputs Picture Weights + */ + void InputPictureWeights(); + + /** + * Outputs block parameters + */ + void OutputBlockParams(); + + /** + * Outputs Motion vector precision data + */ + void OutputMVPrecision(); + + /** + * Outputs global motion parameters + */ + void OutputGlobalMotionParams(); + + /** + * Outputs picture prediction mode + */ + void OutputFramePredictionMode(); + + /** + * Outputs Picture Weights + */ + void OutputPictureWeights(); + + /** + * Sequence paramters for intput/output + */ + PictureParams& m_pparams; + + /** + * Codec params - EncParams for Output and DecParams for input + */ + PicturePredParams& m_picpredparams; + + /** + * block data containing split modes + */ + MvDataElementByteIO m_splitmode_data; + + /** + * block data containing prediction modes + */ + MvDataElementByteIO m_predmode_data; + + /** + * block data containing horizontal MV components for reference 1 + */ + MvDataElementByteIO m_mv1hblock_data; + + /** + * block data containing vertical MV components for reference 1 + */ + MvDataElementByteIO m_mv1vblock_data; + + /** + * block data containing horizontal MV components for reference 2 + */ + MvDataElementByteIO m_mv2hblock_data; + + /** + * block data containing vertical MV components for reference 2 + */ + MvDataElementByteIO m_mv2vblock_data; + + /** + * block data containing Y DC data + */ + MvDataElementByteIO m_ydcblock_data; + + /** + * block data containing U DC data + */ + MvDataElementByteIO m_udcblock_data; + + /** + * block data containing V DC data + */ + MvDataElementByteIO m_vdcblock_data; + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp new file mode 100644 index 000000000..f8785616d --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.cpp @@ -0,0 +1,97 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: mvdataelement_byteio.cpp,v 1.2 2007/11/16 04:48:44 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* Andrew Kennedy +* Thomas Davies +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/mvdataelement_byteio.h> +#include <libdirac_common/video_format_defaults.h> +#include <libdirac_common/dirac_exception.h> + +using namespace dirac; + +MvDataElementByteIO::MvDataElementByteIO(): +ByteIO(), +m_block_data() +{ +} + +MvDataElementByteIO::MvDataElementByteIO(ByteIO &byte_io): +ByteIO(byte_io), +m_block_data(byte_io) +{ +} + +MvDataElementByteIO::~MvDataElementByteIO() +{ +} + +/* +void MvDataElementByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) +{ + // set number of MV bytes + dirac_byte_stats.SetByteCount(STAT_MV_BYTE_COUNT, + GetSize()); +} +*/ +int MvDataElementByteIO::GetSize() const +{ + return ByteIO::GetSize() + m_block_data.GetSize(); +} + +const std::string MvDataElementByteIO::GetBytes() +{ + //Output header and block data + return ByteIO::GetBytes() + m_block_data.GetBytes(); +} + +void MvDataElementByteIO::Input() +{ + // Input block data size + m_block_size = ReadUint(); + + // Byte Alignment + ByteAlignInput(); +} + +void MvDataElementByteIO::Output() +{ + //Output size of block data + WriteUint(m_block_data.GetSize()); + + // Byte Align + ByteAlignOutput(); +} diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h new file mode 100644 index 000000000..2e0aa4211 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/mvdataelement_byteio.h @@ -0,0 +1,126 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: mvdataelement_byteio.h,v 1.2 2008/12/16 01:19:30 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* Andrew Kennedy +* Thomas Davies +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class MvDataElementByteIO +*/ +#ifndef MV_DATAELEMENT_BYTEIO_H +#define MV_DATAELEMENT_BYTEIO_H + + +// DIRAC INCLUDES +#include <libdirac_common/common.h> // EncParams + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class + + +namespace dirac +{ + + /** + * Represents compressed sequence-parameter data used in an AccessUnit + */ + class MvDataElementByteIO : public ByteIO + { + public: + + /** + * Constructor + */ + MvDataElementByteIO(); + + /** + * Constructor + *@param byte_io Input/Output Byte stream + */ + MvDataElementByteIO(ByteIO &byte_io); + + /** + * Destructor + */ + virtual ~MvDataElementByteIO(); + + /** + * Outputs motion vector data Dirac byte-format + */ + void Output(); + + /** + * Inputs motion vector information + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return pointer to the block data ByteIO stream + */ + ByteIO* DataBlock() { return &m_block_data; }; + + /** + * Return the input block data size + */ + unsigned int DataBlockSize() { return m_block_size; } + + /** + * Return the size + */ + int GetSize() const; + + protected: + + /** + * block data + */ + ByteIO m_block_data; + + /** + * In block data size + */ + unsigned int m_block_size; + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp new file mode 100644 index 000000000..5034933bc --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.cpp @@ -0,0 +1,227 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: parseparams_byteio.cpp,v 1.9 2008/10/21 00:04:08 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <sstream> //For std::ostringstream +#include <libdirac_byteio/parseparams_byteio.h> +#include <libdirac_common/dirac_exception.h> + +const unsigned int PP_AU_PICTURE_NUM_SIZE = 4; + +using namespace dirac; + +ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, + ParseParams &parse_params, + EncoderParams &enc_params): +ByteIO(stream_data), +m_parse_params(parse_params) +{ + if (enc_params.NumL1() == 0) + { + if (!enc_params.UsingAC()) + { + // Simple Profile + m_parse_params.SetProfile(1); + } + else + { + // Main (Intra) profile + m_parse_params.SetProfile(2); + } + } + else + { + // Main (Long GOP) profile + m_parse_params.SetProfile(8); + } + // FIXME - no support for Low Delay Profile +} + +ParseParamsByteIO::ParseParamsByteIO( const ByteIO& stream_data, + ParseParams &parse_params): +ByteIO(stream_data), +m_parse_params(parse_params) +{ + + +} + +ParseParamsByteIO::~ParseParamsByteIO() +{ +} + +void ParseParamsByteIO::CheckVersion() +{ + std::ostringstream errstr; + ParseParams def_parse_params; + + if (m_parse_params.MajorVersion() > def_parse_params.MajorVersion() || + m_parse_params.MajorVersion() == 0 || + (m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && + m_parse_params.MinorVersion() > def_parse_params.MinorVersion())) + { + errstr << "WARNING: Bitstream version is "; + errstr << m_parse_params.MajorVersion() << "."; + errstr << m_parse_params.MinorVersion() << "."; + errstr << " Supported version is "; + errstr << def_parse_params.MajorVersion() << "."; + errstr << def_parse_params.MinorVersion(); + errstr << ". May not be able to decode bitstream correctly" << std::endl; + } + + if (errstr.str().size()) + { + DiracException err( + ERR_UNSUPPORTED_STREAM_DATA, + errstr.str(), + SEVERITY_PICTURE_ERROR); + DIRAC_LOG_EXCEPTION(err); + } +} + +void ParseParamsByteIO::CheckProfile() +{ + std::ostringstream errstr; + ParseParams def_parse_params; + + // No profiles were specified in versions 1.0, 1.1, and 2.0 and 2.1. + // So for these versions profile should be 0 in the bitstream + if (m_parse_params.MajorVersion() <= 2 && + m_parse_params.MinorVersion() < 2 && + m_parse_params.Profile() != 0) + { + errstr << "Cannot handle profile " << m_parse_params.Profile() + << " for bitstream version " << m_parse_params.MajorVersion() + << "." << m_parse_params.MinorVersion(); + errstr << ". May not be able to decode bitstream correctly" << std::endl; + } + else if (m_parse_params.MajorVersion() == def_parse_params.MajorVersion() && + m_parse_params.MinorVersion() == def_parse_params.MinorVersion() && + m_parse_params.Profile() != 1 /* Simple */ && + m_parse_params.Profile() != 2 /* Main (Intra) */ && + m_parse_params.Profile() != 8 /* Main (Long GOP) */ + ) + { + errstr << "Cannot handle profile " << m_parse_params.Profile() + << " for bitstream version " << m_parse_params.MajorVersion() + << ". " << m_parse_params.MinorVersion() + << ". Supported profiles are 1 (Simple) " + << " 2 (Main Intra) and 8 (Long GOP)"; + errstr << ". May not be able to decode bitstream correctly" << std::endl; + } + + if (errstr.str().size()) + { + DiracException err( + ERR_UNSUPPORTED_STREAM_DATA, + errstr.str(), + SEVERITY_PICTURE_ERROR); + DIRAC_LOG_EXCEPTION(err); + } +} + +void ParseParamsByteIO::CheckLevel() +{ + std::ostringstream errstr; + ParseParams def_parse_params; + + // No resources constraints for decoder + if (def_parse_params.Level() == 0) + return; + + // Constraints on Decoder. Can Handles level 1 for Simple and Main (Intra) + // profiles, and level 128 for Main (Long GOP) Profile. + if (def_parse_params.Level() != 0) + { + if ((m_parse_params.Profile() <= 2 && m_parse_params.Level() != 1) || + (m_parse_params.Profile() ==8 && m_parse_params.Level() != 128)) + { + errstr << "Cannot handle Level " << m_parse_params.Level() + << " for bitstream version " << m_parse_params.MajorVersion() + << ". " << m_parse_params.MinorVersion() + << " Profile " << m_parse_params.Profile() + << ". Supported levels are 1 for Profiles 0, 1, 2 " + << " and 128 for Profile 8"; + errstr << ". May not be able to decode bitstream correctly" << std::endl; + } + } + + if (errstr.str().size()) + { + DiracException err( + ERR_UNSUPPORTED_STREAM_DATA, + errstr.str(), + SEVERITY_PICTURE_ERROR); + DIRAC_LOG_EXCEPTION(err); + } + return; +} + +//-------------public--------------------------------------------------------------- + +void ParseParamsByteIO::Input() +{ + + //input version + m_parse_params.SetMajorVersion(ReadUint()); + m_parse_params.SetMinorVersion(ReadUint()); + + // input profile + m_parse_params.SetProfile(ReadUint()); + + // input level + m_parse_params.SetLevel(ReadUint()); + + CheckVersion(); + + CheckProfile(); + + CheckLevel(); +} + +void ParseParamsByteIO::Output() +{ + // output version + WriteUint(m_parse_params.MajorVersion()); + WriteUint(m_parse_params.MinorVersion()); + + // output profile + WriteUint(m_parse_params.Profile()); + + // output level - does not conform to any defined level + WriteUint(m_parse_params.Level()); +} diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h new file mode 100644 index 000000000..1e5423f31 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseparams_byteio.h @@ -0,0 +1,117 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: parseparams_byteio.h,v 1.4 2008/05/07 05:47:00 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Scott R Ladd (Original Author), Thomas Davies +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class ParseParamsByteIO +*/ +#ifndef parseparams_byteio_h +#define parseparams_byteio_h + + +// DIRAC INCLUDES +#include <libdirac_common/common.h> // DiracEncoder + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class + + +namespace dirac +{ + + /** + * Represents compressed parse-parameter data used in an AccessUnit + */ + class ParseParamsByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param stream_data Destination of data + *@param parse_params Parse parameters + *@param enc_params Encoder parameters + */ + ParseParamsByteIO(const ByteIO& stream_data, + ParseParams &parse_params, + EncoderParams &enc_params); + + /** + * Constructor + *@param stream_data Source of data + *@param parse_params Destination of parse params + */ + ParseParamsByteIO(const ByteIO& stream_data, + ParseParams &parse_params); + + /** + * Destructor + */ + ~ParseParamsByteIO(); + + /** + * Reads parse information from Dirac byte-format + */ + void Input(); + + /** + * Outputs parse information to Dirac byte-format + */ + void Output(); + + /** + * Get access-unit number + */ + int GetIdNumber() const; + + protected: + + private: + void CheckVersion(); + void CheckProfile(); + void CheckLevel(); + + private: + /** + * Reference to parse parameters + */ + ParseParams& m_parse_params; + }; + + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp new file mode 100644 index 000000000..56c0ebb8b --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.cpp @@ -0,0 +1,289 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: parseunit_byteio.cpp,v 1.10 2008/05/02 05:57:19 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/parseunit_byteio.h> +#include <libdirac_common/dirac_exception.h> + +#include <iomanip> + +using namespace dirac; +using namespace std; + +// Fixed parse-prefix +const string PU_PREFIX = "BBCD"; + +// Parse-unit byte sizes +const int PU_NEXT_PARSE_OFFSET_SIZE = 4; +const int PU_PREVIOUS_PARSE_OFFSET_SIZE = 4; +const int PU_PREFIX_SIZE = 4; +const int PU_PARSE_CODE_SIZE = 1; +const int PU_PARSEUNIT_SIZE = PU_NEXT_PARSE_OFFSET_SIZE + PU_PREVIOUS_PARSE_OFFSET_SIZE+ + PU_PREFIX_SIZE + PU_PARSE_CODE_SIZE; + +ParseUnitByteIO::ParseUnitByteIO(): +ByteIO(), +m_previous_parse_offset(0), +m_next_parse_offset(0) +{ + +} + +ParseUnitByteIO::ParseUnitByteIO(const ByteIO& byte_io): +ByteIO(byte_io), +m_previous_parse_offset(0), +m_next_parse_offset(0) +{ + +} + +ParseUnitByteIO::ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio): +ByteIO(parseunit_byteio), +m_previous_parse_offset(parseunit_byteio.m_previous_parse_offset), +m_next_parse_offset(parseunit_byteio.m_next_parse_offset), +m_parse_code(parseunit_byteio.m_parse_code) +{ +} + +ParseUnitByteIO::~ParseUnitByteIO() +{ + +} + + +//--------------public--------------------------------------------------------- + +void ParseUnitByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) +{ + dirac_byte_stats.SetByteCount(STAT_TOTAL_BYTE_COUNT, + m_next_parse_offset); +} + +bool ParseUnitByteIO::Input() +{ + + // input prefix + if(!SyncToUnitStart()) + return false; + + // input parse code + m_parse_code = InputUnByte(); + + // input parse-offsets + m_next_parse_offset = ReadUintLit(PU_NEXT_PARSE_OFFSET_SIZE); + + m_previous_parse_offset = ReadUintLit(PU_PREVIOUS_PARSE_OFFSET_SIZE); + + return true; +} + +bool ParseUnitByteIO::IsValid() +{ + if (IsEndOfSequence()) + return true; + + // Skip past the end of current parse unit + SeekGet(m_next_parse_offset-GetSize(), ios_base::cur); + + // check the next series of bytes are the parse-info prefix + string prefix = InputUnString(PU_PREFIX_SIZE); + + if(prefix==PU_PREFIX) + { + unsigned char next_parse_code; + + next_parse_code = InputUnByte(); + // input next unit parse-offsets + int next_unit_next_parse_offset; + next_unit_next_parse_offset = ReadUintLit(PU_NEXT_PARSE_OFFSET_SIZE); + + int next_unit_previous_parse_offset; + next_unit_previous_parse_offset = ReadUintLit(PU_PREVIOUS_PARSE_OFFSET_SIZE); + if (next_unit_previous_parse_offset == m_next_parse_offset) + { + SeekGet(-(m_next_parse_offset-GetSize()+PU_PARSEUNIT_SIZE), ios_base::cur); + return true; + } + } + SeekGet(-(m_next_parse_offset-GetSize()), ios_base::cur); + return false; +} + +bool ParseUnitByteIO::CanSkip() +{ + if(m_next_parse_offset==0 || m_next_parse_offset == GetSize()) + return true; + + // Skip past the end of current parse unit and past the header of the + // next unit + SeekGet(m_next_parse_offset-GetSize() + GetSize(), ios_base::cur); + if(GetReadBytePosition() >= 0) + { + SeekGet(-(m_next_parse_offset-GetSize() + GetSize()), ios_base::cur); + return true; // success + } + + // end of stream reached + mp_stream->clear(); + + return false; +} + +const string ParseUnitByteIO::GetBytes() +{ + stringstream parse_string; + parse_string << PU_PREFIX; + parse_string << CalcParseCode(); + + //FIXME : Need to do this properly. + // Write the parse offsets in Big Endian format + for(int i=PU_NEXT_PARSE_OFFSET_SIZE-1; i >= 0; --i) + { + unsigned char cp = (m_next_parse_offset>>(i*8)) & 0xff; + parse_string << cp; + } + + for(int i=PU_PREVIOUS_PARSE_OFFSET_SIZE-1; i >= 0; --i) + { + unsigned char cp = (m_previous_parse_offset>>(i*8)) & 0xff; + parse_string << cp; + } + + return parse_string.str() + ByteIO::GetBytes(); +} + + +int ParseUnitByteIO::GetSize() const +{ + return PU_PARSEUNIT_SIZE; +} + +int ParseUnitByteIO::GetNextParseOffset() const +{ + return m_next_parse_offset; +} + +int ParseUnitByteIO::GetPreviousParseOffset() const +{ + return m_previous_parse_offset; +} + +void ParseUnitByteIO::SetAdjacentParseUnits(ParseUnitByteIO *p_prev_parseunit) +{ + // set next offset + m_next_parse_offset = CalcNextUnitOffset(); + + if(!p_prev_parseunit) + return; + + // set previous parse offset + m_previous_parse_offset = p_prev_parseunit->m_next_parse_offset; +} + + +ParseUnitType ParseUnitByteIO::GetType() const +{ + if(IsSeqHeader()) + return PU_SEQ_HEADER; + + if(IsCoreSyntax()) + return PU_CORE_PICTURE; + + if(IsLowDelay()) + return PU_LOW_DELAY_PICTURE; + + if(IsPicture()) + return PU_PICTURE; + + if(IsEndOfSequence()) + return PU_END_OF_SEQUENCE; + + if(IsAuxiliaryData()) + return PU_AUXILIARY_DATA; + + if(IsPaddingData()) + return PU_PADDING_DATA; + + return PU_UNDEFINED; +} + +//------------protected------------------------------------------------------- + +int ParseUnitByteIO::CalcNextUnitOffset() +{ + // typically size of current unit + return GetSize(); +} + +bool ParseUnitByteIO::SyncToUnitStart() +{ + // locate parse-unit prefix + string byte_buffer; + + while(CanRead()==true && mp_stream->tellg() >= 0) + { + // ensure current buffer length + if((int)byte_buffer.size() == PU_PREFIX_SIZE) + { + byte_buffer.assign(byte_buffer.substr(1,PU_PREFIX_SIZE-1)); + } + // read next byte + byte_buffer.push_back(InputUnByte()); + + //look to see if we have prefix + if(byte_buffer==PU_PREFIX) + { + // check we can read a parse-unit + //int prev_pos = mp_stream->tellg(); + mp_stream->seekg (PU_PARSEUNIT_SIZE-PU_PREFIX_SIZE, ios_base::cur); + int cur_pos = mp_stream->tellg(); + if (cur_pos < 0) // past end of stream + { + mp_stream->clear(); + return false; + } + mp_stream->seekg(-(PU_PARSEUNIT_SIZE-PU_PREFIX_SIZE), ios_base::cur); + return true; + } + + } + + // Clear the eof flag and throw an error. + mp_stream->clear(); + return false; +} + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h new file mode 100644 index 000000000..8d7742afa --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/parseunit_byteio.h @@ -0,0 +1,247 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: parseunit_byteio.h,v 1.11 2008/05/02 05:57:19 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* Anuradha Suraparaju +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class ParseUnitByteIO +*/ +#ifndef parseunit_byteio_h +#define parseunit_byteio_h + +//SYSTEM INLUDES +#include <map> // Byte-map +#include <string> // stores values + +//LOCAL INCLUDES +#include "byteio.h" // Parent class + + +namespace dirac +{ + + /* Types of parse-unit */ + typedef enum { + PU_SEQ_HEADER=0, + PU_PICTURE, + PU_END_OF_SEQUENCE, + PU_AUXILIARY_DATA, + PU_PADDING_DATA, + PU_CORE_PICTURE, + PU_LOW_DELAY_PICTURE, + PU_UNDEFINED + } ParseUnitType; + + /** + * Represents a collection of data in a Dirac bytestream that can be parsed as a + * self-contained unit + */ + class ParseUnitByteIO : public ByteIO + { + public: + + /** + * Constructor + */ + ParseUnitByteIO(); + + /** + * Constructor + *@param byte_io Stream parameters + */ + ParseUnitByteIO(const ByteIO& byte_io); + + /** + * Constructor + *@param parseunit_byteio Parse-unit parameters + */ + ParseUnitByteIO(const ParseUnitByteIO& parseunit_byteio); + + /** + * Destructor + */ + ~ParseUnitByteIO(); + + /** + * Gathers byte stats on the parse-unit data + *@param dirac_byte_stats Stat container + */ + virtual void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Reads from byte-stream to find parse data + *@return <B>false</B> if not enough data in stream + */ + bool Input(); // decoding + + /** + * Accesses validity of a unit by comparing it with an adjacent unit + */ + bool IsValid(); + + /** + * Can Skip past the entire parse-unit + *@return <B>false</B> Nothing to skip to + */ + bool CanSkip(); + + /** + * Gets string containing coded bytes + */ + virtual const std::string GetBytes(); // encoding + + /** + * Set next/previous parse-unit values + *@param p_prev_parseunit Previous parse-unit + */ + void SetAdjacentParseUnits(ParseUnitByteIO *p_prev_parseunit); // encoding + + /* + * Gets number of bytes input/output within unit + */ + virtual int GetSize() const; + + /** + * Gets expected number of bytes to start of next parse-unit + */ + int GetNextParseOffset() const; + + /** + * Gets number of bytes to start of previous parse-unit + */ + int GetPreviousParseOffset() const; + + /** + * Gets parse-unit type + */ + virtual ParseUnitType GetType() const; + + /** + * Returns true is parse unit is a Sequence Header + */ + bool IsSeqHeader() const + { return m_parse_code==0x00; } + + /** + * Returns true is parse unit is an End of Sequence unit + */ + bool IsEndOfSequence() const + { return m_parse_code==0x10; } + + /** + * Returns true is parse unit is Auxiliary Data + */ + bool IsAuxiliaryData() const + { return (m_parse_code&0xF8)==0x20; } + + /** + * Returns true is parse unit is Padding data + */ + bool IsPaddingData() const + { return m_parse_code==0x30; } + + /** + * Returns true is parse unit is Picture data + */ + bool IsPicture() const + { return ((m_parse_code&0x08)==0x08); } + + /** + * Returns true is parse unit is Low Delay Sybtax unit + */ + bool IsLowDelay() const + { return ((m_parse_code&0x88)==0x88); } + + /** + * Returns true is parse unit is Core syntax unit + */ + bool IsCoreSyntax() const + { return ((m_parse_code&0x88)==0x08); } + + /** + * Returns true is parse unit uses Arithmetic coding + */ + bool IsUsingAC() const + { return ((m_parse_code&0x48)==0x08); } + + protected: + + /** + * Calculates number of bytes to start of next unit + *@return Number of bytes to next unit + */ + virtual int CalcNextUnitOffset(); + + /** + * Pure virtual method for calculating parse-code + *@return Char containing bit-set for parse-unit parameters + */ + virtual unsigned char CalcParseCode() const { return 0;} // encoding + + /** + * Locates start of parse-unit + *@return <B>false</B> if not enough data + */ + bool SyncToUnitStart(); // decoding + + /** + * Get parse code + */ + unsigned char GetParseCode() const { return m_parse_code;} + + private: + + /** + * Number of bytes to next parse-unit + */ + int m_previous_parse_offset; + + /** + * Number of bytes to previous parse-unit + */ + int m_next_parse_offset; + + /** + * Parse-type-identifier + */ + unsigned char m_parse_code; + + }; + + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp new file mode 100644 index 000000000..23231bea7 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.cpp @@ -0,0 +1,279 @@ +/* ***** BEGIN LICENSE BLOCK *****
+*
+* $Id: picture_byteio.cpp,v 1.3 2008/08/14 01:58:39 asuraparaju Exp $ $Name: $
+*
+* Version: MPL 1.1/GPL 2.0/LGPL 2.1
+*
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+* the specific language governing rights and limitations under the License.
+*
+* The Original Code is BBC Research and Development code.
+*
+* The Initial Developer of the Original Code is the British Broadcasting
+* Corporation.
+* Portions created by the Initial Developer are Copyright (C) 2004.
+* All Rights Reserved.
+*
+* Contributor(s): Andrew Kennedy (Original Author),
+* Anuradha Suraparaju
+*
+* Alternatively, the contents of this file may be used under the terms of
+* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
+* Public License Version 2.1 (the "LGPL"), in which case the provisions of
+* the GPL or the LGPL are applicable instead of those above. If you wish to
+* allow use of your version of this file only under the terms of the either
+* the GPL or LGPL and not to allow others to use your version of this file
+* under the MPL, indicate your decision by deleting the provisions above
+* and replace them with the notice and other provisions required by the GPL
+* or LGPL. If you do not delete the provisions above, a recipient may use
+* your version of this file under the terms of any one of the MPL, the GPL
+* or the LGPL.
+* ***** END LICENSE BLOCK ***** */
+
+#include "picture_byteio.h"
+#include <libdirac_common/dirac_exception.h>
+
+using namespace dirac;
+using namespace std;
+
+const unsigned int PP_PICTURE_NUM_SIZE = 4;
+
+const int CODE_ONE_REF_BIT = 0;
+const int CODE_TWO_REF_BIT = 1;
+const int CODE_REF_PICTURE_BIT = 2;
+const int CODE_PUTYPE_1_BIT = 3;
+const int CODE_VLC_ENTROPY_CODING_BIT = 6;
+
+// maximum number of refs allowed
+const unsigned int MAX_NUM_REFS = 2;
+
+PictureByteIO::PictureByteIO(PictureParams& frame_params,
+ int frame_num) :
+ParseUnitByteIO(),
+m_frame_params(frame_params),
+m_frame_num(frame_num),
+m_mv_data(0),
+m_transform_data(0)
+{
+
+}
+
+PictureByteIO::PictureByteIO(PictureParams& frame_params,
+ const ParseUnitByteIO& parseunit_byteio ):
+ParseUnitByteIO(parseunit_byteio),
+m_frame_params(frame_params),
+m_frame_num(0),
+m_mv_data(0),
+m_transform_data(0)
+{
+
+}
+
+
+PictureByteIO::~PictureByteIO()
+{
+ //delete block data
+ if (m_mv_data)
+ {
+ delete m_mv_data;
+ m_mv_data = 0;
+ }
+ if (m_transform_data)
+ {
+ delete m_transform_data;
+ m_transform_data = 0;
+ }
+}
+
+void PictureByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats)
+{
+ if(m_mv_data)
+ m_mv_data->CollateByteStats(dirac_byte_stats);
+ if(m_transform_data)
+ m_transform_data->CollateByteStats(dirac_byte_stats);
+
+ ParseUnitByteIO::CollateByteStats(dirac_byte_stats);
+}
+
+bool PictureByteIO::Input()
+{
+ // set picture type
+ SetPictureType();
+ SetReferenceType();
+ SetEntropyCodingFlag();
+
+ // Use of VLC for entropy coding is supported for
+ // intra frames only
+ if (m_frame_params.GetPictureType() == INTER_PICTURE &&
+ m_frame_params.UsingAC() == false)
+ {
+ DIRAC_THROW_EXCEPTION(
+ ERR_UNSUPPORTED_STREAM_DATA,
+ "VLC codes for entropy coding of coefficient data supported for Intra frames only",
+ SEVERITY_PICTURE_ERROR);
+ }
+
+ // input picture number
+ m_frame_num = ReadUintLit(PP_PICTURE_NUM_SIZE);
+ m_frame_params.SetPictureNum(m_frame_num);
+
+ // input reference Picture numbers
+ InputReferencePictures();
+
+ // input retired Picture numbers list
+ m_frame_params.SetRetiredPictureNum(-1);
+ if (IsRef())
+ InputRetiredPicture();
+
+ // byte align
+ ByteAlignInput();
+
+ return true;
+}
+
+const string PictureByteIO::GetBytes()
+{
+ // Write mv data
+ if(m_frame_params.PicSort().IsInter() && m_mv_data)
+ {
+ OutputBytes(m_mv_data->GetBytes());
+ }
+
+ // Write transform header
+ if (m_transform_data)
+ {
+ OutputBytes(m_transform_data->GetBytes());
+ }
+ return ParseUnitByteIO::GetBytes();
+}
+
+int PictureByteIO::GetSize() const
+{
+ int size = 0;
+ if (m_mv_data)
+ size += m_mv_data->GetSize();
+ if (m_transform_data)
+ size += m_transform_data->GetSize();
+
+ //std::cerr << "Picture Header Size=" << ByteIO::GetSize();
+ //std::cerr << "Data Size=" << size << std::endl;
+
+ return size+ParseUnitByteIO::GetSize()+ByteIO::GetSize();
+}
+
+void PictureByteIO::Output()
+{
+ // output picture number
+ WriteUintLit(m_frame_num, PP_PICTURE_NUM_SIZE);
+
+ if(m_frame_params.GetPictureType()==INTER_PICTURE)
+ {
+ // output reference picture numbers
+ const std::vector<int>& refs = m_frame_params.Refs();
+ for(size_t i=0; i < refs.size() && i < MAX_NUM_REFS; ++i)
+ WriteSint(refs[i] - m_frame_num);
+ }
+
+ // output retired picture
+ ASSERTM (m_frame_params.GetReferenceType() == REFERENCE_PICTURE || m_frame_params.RetiredPictureNum() == -1, "Only Reference frames can retire frames");
+ if(m_frame_params.GetReferenceType() == REFERENCE_PICTURE)
+ {
+ if (m_frame_params.RetiredPictureNum() == -1)
+ WriteSint(0);
+ else
+ {
+ WriteSint (m_frame_params.RetiredPictureNum() - m_frame_num);
+ }
+ }
+ // byte align output
+ ByteAlignOutput();
+
+}
+
+
+//-------------private-------------------------------------------------------
+
+unsigned char PictureByteIO::CalcParseCode() const
+{
+ unsigned char code = 0;
+
+ int num_refs = m_frame_params.Refs().size();
+
+ if(m_frame_params.GetPictureType()==INTER_PICTURE)
+ {
+ // set number of refs
+ if(num_refs == 1)
+ SetBit(code, CODE_ONE_REF_BIT);
+ if(num_refs > 1)
+ SetBit(code, CODE_TWO_REF_BIT);
+ }
+ // set ref type
+ if(m_frame_params.GetReferenceType()==REFERENCE_PICTURE)
+ SetBit(code, CODE_REF_PICTURE_BIT);
+
+ // Set parse unit type
+ SetBit(code, CODE_PUTYPE_1_BIT);
+
+ // Set Entropy Coding type
+ if (!m_frame_params.UsingAC())
+ {
+ SetBit(code, CODE_VLC_ENTROPY_CODING_BIT);
+ }
+ return code;
+
+
+}
+
+void PictureByteIO::InputReferencePictures()
+{
+ // get number of frames referred to
+ int ref_count = NumRefs();
+
+ // get the number of these frames
+ vector<int>& refs = m_frame_params.Refs();
+ refs.resize(ref_count);
+ for(int i=0; i < ref_count; ++i)
+ refs[i]=m_frame_num+ReadSint();
+}
+
+void PictureByteIO::InputRetiredPicture()
+{
+ TESTM(IsRef(), "Retired Picture offset only set for Reference Frames");
+
+ // input retired picture offset
+ int offset = ReadSint();
+ // input retired frames
+ if (offset)
+ {
+ m_frame_params.SetRetiredPictureNum(m_frame_num + offset);
+ }
+}
+
+void PictureByteIO::SetPictureType()
+{
+ if(IsIntra())
+ m_frame_params.SetPictureType(INTRA_PICTURE);
+ else if(IsInter())
+ m_frame_params.SetPictureType(INTER_PICTURE);
+
+}
+
+void PictureByteIO::SetReferenceType()
+{
+ if(IsRef())
+ m_frame_params.SetReferenceType(REFERENCE_PICTURE);
+ else if(IsNonRef())
+ m_frame_params.SetReferenceType(NON_REFERENCE_PICTURE);
+
+}
+
+void PictureByteIO::SetEntropyCodingFlag()
+{
+ m_frame_params.SetUsingAC(IsUsingAC());
+}
diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h new file mode 100644 index 000000000..bdca76f40 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/picture_byteio.h @@ -0,0 +1,208 @@ +/* ***** BEGIN LICENSE BLOCK *****
+*
+* $Id: picture_byteio.h,v 1.1 2008/01/31 11:25:15 tjdwave Exp $ $Name: $
+*
+* Version: MPL 1.1/GPL 2.0/LGPL 2.1
+*
+* The contents of this file are subject to the Mozilla Public License
+* Version 1.1 (the "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+* http://www.mozilla.org/MPL/
+*
+* Software distributed under the License is distributed on an "AS IS" basis,
+* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
+* the specific language governing rights and limitations under the License.
+*
+* The Original Code is BBC Research and Development code.
+*
+* The Initial Developer of the Original Code is the British Broadcasting
+* Corporation.
+* Portions created by the Initial Developer are Copyright (C) 2004.
+* All Rights Reserved.
+*
+* Contributor(s): Andrew Kennedy (Original Author)
+* Anuradha Suraparaju
+*
+* Alternatively, the contents of this file may be used under the terms of
+* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser
+* Public License Version 2.1 (the "LGPL"), in which case the provisions of
+* the GPL or the LGPL are applicable instead of those above. If you wish to
+* allow use of your version of this file only under the terms of the either
+* the GPL or LGPL and not to allow others to use your version of this file
+* under the MPL, indicate your decision by deleting the provisions above
+* and replace them with the notice and other provisions required by the GPL
+* or LGPL. If you do not delete the provisions above, a recipient may use
+* your version of this file under the terms of any one of the MPL, the GPL
+* or the LGPL.
+* ***** END LICENSE BLOCK ***** */
+
+/**
+* Definition of class PictureByteIO
+*/
+#ifndef picture_byteio_h
+#define picture_byteio_h
+
+
+//LOCAL INCLUDES
+#include <libdirac_byteio/parseunit_byteio.h> // Parent class
+#include <libdirac_byteio/mvdata_byteio.h> // Contains mvdata streams
+#include <libdirac_byteio/transform_byteio.h> // Transform header
+
+// DIRAC includes
+#include <libdirac_common/common.h> // PictureType etc
+
+
+namespace dirac
+{
+ /**
+ * A compressed picture in Dirac bytestream format
+ */
+ class PictureByteIO : public ParseUnitByteIO
+ {
+ public:
+
+ /**
+ * Constructor
+ *@param frame_params Picture parameters
+ *@param frame_num Picture number
+ */
+ PictureByteIO(PictureParams& frame_params,
+ int frame_num);
+
+
+ /**
+ * Constructor
+ *@param frame_params Destination of data
+ *@param parseunit_byteio Source of data
+ */
+ PictureByteIO(PictureParams& frame_params,
+ const ParseUnitByteIO& parseunit_byteio);
+
+ /**
+ * Destructor
+ */
+ virtual ~PictureByteIO();
+
+ /**
+ * Gathers byte stats on the picture data
+ *@param dirac_byte_stats Stat container
+ */
+ void CollateByteStats(DiracByteStats& dirac_byte_stats);
+
+ /**
+ * Inputs data from Dirac stream-format
+ */
+ bool Input();
+
+ /**
+ * Outputs picture values to Dirac stream-format
+ */
+ void Output();
+
+
+
+ const std::string GetBytes();
+
+ int GetSize() const;
+
+ /**
+ * Gets parse-unit type
+ */
+ ParseUnitType GetType() const { return PU_PICTURE;}
+
+ /**
+ * Returns true is picture in Reference picture
+ */
+ int IsRef() const { return (GetParseCode()&0x0C)==0x0C;}
+
+ /**
+ * Returns true is picture in Non-Reference picture
+ */
+ int IsNonRef() const { return (GetParseCode()&0x0C)==0x08;}
+
+ /**
+ * Gets parse-unit type
+ */
+ int NumRefs() const { return (GetParseCode()&0x03);}
+
+ /**
+ * Returns true is picture is Intra picture
+ */
+ bool IsIntra() const { return IsPicture() && (NumRefs()==0) ; }
+
+ /**
+ * Returns true is picture is Inter picture
+ */
+ bool IsInter() const { return IsPicture() && (NumRefs()>0) ; }
+
+ /***
+ * Sets the MVDataIO
+ */
+ void SetMvData(MvDataByteIO *mv_data) {m_mv_data = mv_data; }
+
+ /***
+ * Sets the TransformByteIo
+ */
+ void SetTransformData(TransformByteIO *transform_data) {m_transform_data = transform_data; }
+
+ protected:
+
+
+ private:
+
+ /**
+ * Calculates parse-code based on picture parameters
+ *@return Char bit-set
+ */
+ unsigned char CalcParseCode() const;
+
+ /**
+ * Reads reference-picture data
+ */
+ void InputReferencePictures();
+
+ /**
+ * Reads retired picture number
+ */
+ void InputRetiredPicture();
+
+ /**
+ * Calculates picture-type (eg INTRA/INTER) of picture
+ */
+ void SetPictureType();
+
+ /**
+ * Calculates reference-type of picture
+ */
+ void SetReferenceType();
+
+ /**
+ * Sets the entropy coding flag in the picture parameters
+ */
+ void SetEntropyCodingFlag();
+
+ /**
+ * Picture parameters
+ */
+ PictureParams& m_frame_params;
+
+ /**
+ * Picture number
+ */
+ int m_frame_num;
+
+ /**
+ * MV data
+ */
+ MvDataByteIO * m_mv_data;
+
+ /**
+ * Transform data
+ */
+ TransformByteIO * m_transform_data;
+
+ };
+
+} // namespace dirac
+
+#endif
diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp new file mode 100644 index 000000000..63d0607b9 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.cpp @@ -0,0 +1,137 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: subband_byteio.cpp,v 1.4 2008/04/29 08:51:52 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/subband_byteio.h> + +using namespace dirac; +using namespace std; + +SubbandByteIO::SubbandByteIO(Subband& sub_band, + const ByteIO& byteio): +ByteIO(byteio), +m_subband(sub_band), +m_band_data_length(0) +{ + +} + +SubbandByteIO::SubbandByteIO(Subband& sub_band): +ByteIO(), +m_subband(sub_band), +m_band_data_length(0) +{ + +} + +SubbandByteIO::~SubbandByteIO() +{ + +} + +//--------------public---------------------------------------------- + +bool SubbandByteIO::Input() +{ + // read length of Arith-coded data block + m_band_data_length = ReadUint(); + + // set skip flag if no data + m_subband.SetSkip(m_band_data_length==0 ? true : false); + + // check for zero-length sub-band + if(m_subband.Skipped()) + { + ByteAlignInput(); + return true; + } + + // If we're not skipped, we need a quantisation index for the subband + m_subband.SetQuantIndex(ReadUint() ); + + if ( !m_subband.UsingMultiQuants() ) + { + // Propogate the quantiser index to all the code blocks if we + // don't have multiquants + for ( int j=0 ; j<m_subband.GetCodeBlocks().LengthY() ; ++j ) + for ( int i=0 ; i<m_subband.GetCodeBlocks().LengthX() ; ++i ) + m_subband.GetCodeBlocks()[j][i].SetQuantIndex( m_subband.QuantIndex() ); + } + + // byte align + ByteAlignInput(); + //int f=mp_stream->tellg(); + + return true; +} + +int SubbandByteIO::GetBandDataLength() const +{ + return m_band_data_length; +} + +const string SubbandByteIO::GetBytes() +{ + ByteIO byte_io; + + ByteAlignOutput(); + + // output size + byte_io.WriteUint(GetSize()); + + // check for zero-length sub-band + if(GetSize()==0) + { + byte_io.ByteAlignOutput(); + return byte_io.GetBytes(); + } + + // output quantisation + byte_io.WriteUint(m_subband.QuantIndex()); + + // byte align + byte_io.ByteAlignOutput(); + + //std::cerr << "Subband hdr size=" << byte_io.GetSize(); + //std::cerr << " Arithdata size=" << this->GetSize()<< std::endl; + + return byte_io.GetBytes()+ByteIO::GetBytes(); +} + + + +//-------------private------------------------------------------------------- + diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.h new file mode 100644 index 000000000..88d03cf87 --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/subband_byteio.h @@ -0,0 +1,115 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: subband_byteio.h,v 1.1 2006/04/20 10:41:56 asuraparaju Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Andrew Kennedy (Original Author) +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class SubbandByteIO +*/ +#ifndef subband_byteio_h +#define subband_byteio_h + + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class + +// DIRAC includes +#include <libdirac_common/wavelet_utils.h> // Subband class + +namespace dirac +{ + /** + * Subband Dirac-bytestream input/output + */ + class SubbandByteIO : public ByteIO + { + public: + + /** + * Constructor + *@param sub_band Corresponding Subband + *@param byteio Source/Destination of data + */ + SubbandByteIO(Subband& sub_band, + const ByteIO& byteio); + + + /* Constructor + *@param sub_band Corresponding Subband + *@param byteio Source/Destination of data + */ + SubbandByteIO(Subband& sub_band); + + /** + * Destructor + */ + ~SubbandByteIO(); + + /** + * Inputs data from Dirac stream-format + */ + bool Input(); + + + /** + * Gets number of bytes in Arith-coded data block + */ + int GetBandDataLength() const; + + /** + * Gets subband bytes in Dirac-bytestream format + */ + const std::string GetBytes(); + + + protected: + + + private: + + /** + * Sub-band that is inputed/outputed + */ + Subband& m_subband; + + /** + * Number of bytes in arith-coded data block + */ + int m_band_data_length; + }; + +} // namespace dirac + +#endif diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/transform_byteio.cpp b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/transform_byteio.cpp new file mode 100644 index 000000000..6eba5a31d --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/transform_byteio.cpp @@ -0,0 +1,169 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: transform_byteio.cpp,v 1.10 2008/01/31 11:25:15 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +#include <libdirac_byteio/transform_byteio.h> +#include <libdirac_common/dirac_exception.h> + +using namespace dirac; + +TransformByteIO::TransformByteIO(PictureParams& fparams, + CodecParams& cparams): +ByteIO(), +m_fparams(fparams), +m_cparams(cparams), +m_default_cparams(cparams.GetVideoFormat(), fparams.GetPictureType(), fparams.Refs().size(), true) +{ +} + +TransformByteIO::TransformByteIO(ByteIO &byte_io, + PictureParams& fparams, + CodecParams& cparams): +ByteIO(byte_io), +m_fparams(fparams), +m_cparams(cparams), +m_default_cparams(cparams.GetVideoFormat(), fparams.GetPictureType(), fparams.Refs().size(), true) +{ +} + +TransformByteIO::~TransformByteIO() +{ + for(size_t index=0; index < m_component_list.size(); ++index) + delete m_component_list[index]; +} + +void TransformByteIO::CollateByteStats(DiracByteStats& dirac_byte_stats) +{ + // set number of component bytes + for(size_t index=0; index < m_component_list.size(); ++index) + m_component_list[index]->CollateByteStats(dirac_byte_stats); +} + +int TransformByteIO::GetSize() const +{ + //std::cerr << "Transform Size=" << ByteIO::GetSize() << std::endl; + int size=0; + for(size_t index=0; index < m_component_list.size(); ++index) + size += m_component_list[index]->GetSize(); + return ByteIO::GetSize()+size; +} + +const std::string TransformByteIO::GetBytes() +{ + std::string bytes; + for(size_t index=0; index < m_component_list.size(); ++index) + bytes += m_component_list[index]->GetBytes(); + return ByteIO::GetBytes()+bytes; +} + +void TransformByteIO::Output() +{ + // Zero Transform flag - applies only to inter frames + if (m_fparams.PicSort().IsInter()) + WriteBit(false); + // Wavelet index + WriteUint(m_cparams.TransformFilter()); + + // Wavelet Depth + WriteUint(m_cparams.TransformDepth()); + + // Spatial Partition flag + WriteBit(m_cparams.SpatialPartition()); + if (m_cparams.SpatialPartition()) + { + for (unsigned int i = 0; i <= m_cparams.TransformDepth(); ++i) + { + const CodeBlocks &cb = m_cparams.GetCodeBlocks(i); + // Number of Horizontal code blocks for level i + WriteUint(cb.HorizontalCodeBlocks()); + // Number of Vertical code block for level i + WriteUint(cb.VerticalCodeBlocks()); + } + // Code block mode index + WriteUint(m_cparams.GetCodeBlockMode()); + } + // Flush output for bend alignment + ByteAlignOutput(); +} + +void TransformByteIO::Input() +{ + // Byte Alignment + ByteAlignInput(); + + m_cparams.SetZeroTransform(false); + // Zero transform flag - applies only for inter frames + if (m_fparams.PicSort().IsInter()) + m_cparams.SetZeroTransform(ReadBool()); + + if (m_cparams.ZeroTransform()) + return; + + // Transform filter + m_cparams.SetTransformFilter(ReadUint()); + + // transform depth + m_cparams.SetTransformDepth(ReadUint()); + + // Spatial partition flag + m_cparams.SetSpatialPartition(ReadBool()); + + if (m_cparams.SpatialPartition()) + { + // Input number of code blocks for each level + for (unsigned int i = 0; i <= m_cparams.TransformDepth(); ++i) + { + // number of horizontal code blocks for level i + unsigned int hblocks = ReadUint(); + // number of vertical code blocks for level i + unsigned int vblocks = ReadUint(); + m_cparams.SetCodeBlocks(i, hblocks, vblocks); + } + // Code block mode index + m_cparams.SetCodeBlockMode(ReadUint()); + } + // Byte Alignment + ByteAlignInput(); +} + +void TransformByteIO::AddComponent(ComponentByteIO* component_byteio) +{ + m_component_list.push_back(component_byteio); +} + + +//-------------private--------------------------------------------------------------- diff --git a/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/transform_byteio.h b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/transform_byteio.h new file mode 100644 index 000000000..6fa1c0c5f --- /dev/null +++ b/src/filters/parser/DiracSplitter/libdirac/libdirac_byteio/transform_byteio.h @@ -0,0 +1,146 @@ +/* ***** BEGIN LICENSE BLOCK ***** +* +* $Id: transform_byteio.h,v 1.2 2008/01/31 11:25:15 tjdwave Exp $ $Name: $ +* +* Version: MPL 1.1/GPL 2.0/LGPL 2.1 +* +* The contents of this file are subject to the Mozilla Public License +* Version 1.1 (the "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* http://www.mozilla.org/MPL/ +* +* Software distributed under the License is distributed on an "AS IS" basis, +* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +* the specific language governing rights and limitations under the License. +* +* The Original Code is BBC Research and Development code. +* +* The Initial Developer of the Original Code is the British Broadcasting +* Corporation. +* Portions created by the Initial Developer are Copyright (C) 2004. +* All Rights Reserved. +* +* Contributor(s): Anuradha Suraparaju (Original Author) +* Andrew Kennedy +* +* Alternatively, the contents of this file may be used under the terms of +* the GNU General Public License Version 2 (the "GPL"), or the GNU Lesser +* Public License Version 2.1 (the "LGPL"), in which case the provisions of +* the GPL or the LGPL are applicable instead of those above. If you wish to +* allow use of your version of this file only under the terms of the either +* the GPL or LGPL and not to allow others to use your version of this file +* under the MPL, indicate your decision by deleting the provisions above +* and replace them with the notice and other provisions required by the GPL +* or LGPL. If you do not delete the provisions above, a recipient may use +* your version of this file under the terms of any one of the MPL, the GPL +* or the LGPL. +* ***** END LICENSE BLOCK ***** */ + +/** +* Definition of class TransformByteIO +*/ +#ifndef TRANSFORM_BYTEIO_H +#define TRANSFORM_BYTEIO_H + +// DIRAC INCLUDES +#include <libdirac_common/common.h> // EncParams + +//LOCAL INCLUDES +#include <libdirac_byteio/byteio.h> // Parent class +#include <libdirac_byteio/component_byteio.h> // Contains tranform-component + + +namespace dirac +{ + + /** + * Represents compressed sequence-parameter data used in an AccessUnit + */ + class TransformByteIO : public ByteIO + { + public: + + /** + * Output Constructor + *@param fparams Picture parameters + *@param c_params Codec params + */ + TransformByteIO(PictureParams& fparams, + CodecParams& c_params); + + /** + * Input Constructor + *@param byte_io ByteIO object for copy constructor + *@param fparams Picture parameters + *@param c_params Codec params + */ + TransformByteIO(ByteIO &byte_io, PictureParams& fparams, + CodecParams& c_params); + + /** + * Destructor + */ + virtual ~TransformByteIO(); + + /** + * Gathers byte stats on the transform data + *@param dirac_byte_stats Stats container + */ + void CollateByteStats(DiracByteStats& dirac_byte_stats); + + /** + * Outputs sequence information to Dirac byte-format + */ + void Output(); + + /** + * Outputs sequence information to Dirac byte-format + */ + void Input(); + + + /** + * Get string containing coded bytes + */ + virtual const std::string GetBytes(); + + /** + * Return the size + */ + int GetSize() const; + + /** + * Adds a Picture-component in Dirac-bytestream format + *@param component_byteio Picture-component bytestream + */ + void AddComponent(ComponentByteIO *component_byteio); + + protected: + + + private: + + /** + * Sequence paramters for intput/output + */ + PictureParams& m_fparams; + + /** + * Codec params - EncParams for Output and DecParams for input + */ + CodecParams& m_cparams; + + /** + * Default Codec params - EncParams for Output and DecParams for input + */ + CodecParams m_default_cparams; + + /*** + * Transform Component data + */ + std::vector<ComponentByteIO *> m_component_list; + }; + +} // namespace dirac + +#endif |