2013-09-19 07:35:34 +00:00
|
|
|
#ifndef BITSTREAM_H_
|
|
|
|
#define BITSTREAM_H_
|
2014-01-24 10:37:15 +00:00
|
|
|
/*****************************************************************************
|
2021-11-23 06:46:06 +00:00
|
|
|
* This file is part of uvg266 VVC encoder.
|
2014-03-06 16:14:01 +00:00
|
|
|
*
|
2021-10-07 08:32:59 +00:00
|
|
|
* Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
|
|
* are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* * Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* * Redistributions in binary form must reproduce the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer in the documentation and/or
|
|
|
|
* other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived from
|
|
|
|
* this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
|
|
|
|
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
* INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
|
2014-01-24 10:37:15 +00:00
|
|
|
****************************************************************************/
|
|
|
|
|
2015-12-17 11:42:57 +00:00
|
|
|
/**
|
|
|
|
* \ingroup CABAC
|
2013-09-18 14:29:30 +00:00
|
|
|
* \file
|
2015-12-17 11:42:57 +00:00
|
|
|
* Appending bits into an Annex-B coded bitstream.
|
2013-09-18 14:29:30 +00:00
|
|
|
*/
|
2014-03-06 16:14:01 +00:00
|
|
|
|
2016-03-30 09:41:37 +00:00
|
|
|
#include "global.h" // IWYU pragma: keep
|
2013-09-18 09:16:03 +00:00
|
|
|
|
2022-04-28 11:26:05 +00:00
|
|
|
#include "uvg266.h"
|
2016-01-22 13:07:49 +00:00
|
|
|
|
2016-04-01 14:14:23 +00:00
|
|
|
|
2015-06-25 08:15:34 +00:00
|
|
|
/**
|
|
|
|
* A stream of bits.
|
|
|
|
*/
|
|
|
|
typedef struct bitstream_t
|
2014-04-17 06:34:56 +00:00
|
|
|
{
|
2015-06-25 08:15:34 +00:00
|
|
|
/// \brief Total number of complete bytes.
|
|
|
|
uint32_t len;
|
|
|
|
|
|
|
|
/// \brief Pointer to the first chunk, or NULL.
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_data_chunk *first;
|
2015-06-25 08:15:34 +00:00
|
|
|
|
|
|
|
/// \brief Pointer to the last chunk, or NULL.
|
2022-04-28 11:18:09 +00:00
|
|
|
uvg_data_chunk *last;
|
2015-06-25 08:15:34 +00:00
|
|
|
|
|
|
|
/// \brief The incomplete byte.
|
|
|
|
uint8_t data;
|
|
|
|
|
|
|
|
/// \brief Number of bits in the incomplete byte.
|
|
|
|
uint8_t cur_bit;
|
|
|
|
|
|
|
|
uint8_t zerocount;
|
2021-09-14 06:22:40 +00:00
|
|
|
|
2015-03-04 11:20:18 +00:00
|
|
|
} bitstream_t;
|
2014-04-17 06:34:56 +00:00
|
|
|
|
2012-06-05 11:01:47 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
uint8_t len;
|
|
|
|
uint32_t value;
|
2015-03-04 11:20:57 +00:00
|
|
|
} bit_table_t;
|
2012-06-05 11:01:47 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_bitstream_init(bitstream_t * stream);
|
|
|
|
uvg_data_chunk * uvg_bitstream_alloc_chunk();
|
|
|
|
uvg_data_chunk * uvg_bitstream_take_chunks(bitstream_t *stream);
|
|
|
|
void uvg_bitstream_free_chunks(uvg_data_chunk *chunk);
|
|
|
|
void uvg_bitstream_finalize(bitstream_t * stream);
|
2014-04-23 08:19:11 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
uint64_t uvg_bitstream_tell(const bitstream_t * stream);
|
2015-06-25 08:15:34 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_bitstream_writebyte(bitstream_t *stream, uint8_t byte);
|
|
|
|
void uvg_bitstream_move(bitstream_t *dst, bitstream_t *src);
|
|
|
|
void uvg_bitstream_clear(bitstream_t *stream);
|
2015-06-25 08:15:34 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_bitstream_put(bitstream_t *stream, uint32_t data, uint8_t bits);
|
|
|
|
void uvg_bitstream_put_byte(bitstream_t *const stream, const uint32_t data);
|
2017-01-31 15:53:47 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_bitstream_put_ue(bitstream_t *stream, uint32_t data);
|
|
|
|
void uvg_bitstream_put_se(bitstream_t *stream, int32_t data);
|
2012-06-05 11:01:47 +00:00
|
|
|
|
2022-04-28 11:18:09 +00:00
|
|
|
void uvg_bitstream_add_rbsp_trailing_bits(bitstream_t *stream);
|
|
|
|
void uvg_bitstream_align(bitstream_t *stream);
|
|
|
|
void uvg_bitstream_align_zero(bitstream_t *stream);
|
2013-02-05 13:48:06 +00:00
|
|
|
|
|
|
|
/* In debug mode print out some extra info */
|
2018-09-26 09:01:23 +00:00
|
|
|
#ifdef VERBOSE
|
2013-02-05 13:48:06 +00:00
|
|
|
/* Counter to keep up with bits written */
|
2022-04-28 11:18:09 +00:00
|
|
|
#define WRITE_U(stream, data, bits, name) { printf("%-50s u(%d) : %d\n", name,bits,data); uvg_bitstream_put(stream,data,bits);}
|
|
|
|
#define WRITE_UE(stream, data, name) { printf("%-50s ue(v): %d\n", name,data); uvg_bitstream_put_ue(stream,data);}
|
|
|
|
#define WRITE_SE(stream, data, name) { printf("%-50s se(v): %d\n", name,data); uvg_bitstream_put_se(stream,(data));}
|
2012-06-05 11:01:47 +00:00
|
|
|
#else
|
2022-04-28 11:18:09 +00:00
|
|
|
#define WRITE_U(stream, data, bits, name) { uvg_bitstream_put(stream,data,bits); }
|
|
|
|
#define WRITE_UE(stream, data, name) { uvg_bitstream_put_ue(stream,data); }
|
|
|
|
#define WRITE_SE(stream, data, name) { uvg_bitstream_put_se(stream,data); }
|
2012-06-05 11:01:47 +00:00
|
|
|
#endif
|
|
|
|
|
2014-03-06 16:14:01 +00:00
|
|
|
|
2014-01-31 18:34:50 +00:00
|
|
|
#endif
|