2013-09-19 07:35:34 +00:00
|
|
|
#ifndef BITSTREAM_H_
|
|
|
|
#define BITSTREAM_H_
|
2014-01-24 10:37:15 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
* This file is part of Kvazaar HEVC encoder.
|
2014-03-06 16:14:01 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Copyright (C) 2013-2015 Tampere University of Technology and others (see
|
2014-01-24 10:37:15 +00:00
|
|
|
* COPYING file).
|
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is free software: you can redistribute it and/or modify it under
|
|
|
|
* the terms of the GNU Lesser General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2.1 of the License, or (at your
|
|
|
|
* option) any later version.
|
2014-01-24 10:37:15 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* Kvazaar is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
|
|
|
|
* more details.
|
2014-01-24 10:37:15 +00:00
|
|
|
*
|
2015-02-23 11:18:48 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with Kvazaar. If not, see <http://www.gnu.org/licenses/>.
|
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
|
|
|
|
2016-01-22 13:07:49 +00:00
|
|
|
#include "kvazaar.h"
|
|
|
|
|
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.
|
2015-06-30 09:04:00 +00:00
|
|
|
kvz_data_chunk *first;
|
2015-06-25 08:15:34 +00:00
|
|
|
|
|
|
|
/// \brief Pointer to the last chunk, or NULL.
|
2015-06-30 09:04:00 +00:00
|
|
|
kvz_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;
|
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
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_bitstream_init(bitstream_t * stream);
|
|
|
|
kvz_data_chunk * kvz_bitstream_alloc_chunk();
|
|
|
|
kvz_data_chunk * kvz_bitstream_take_chunks(bitstream_t *stream);
|
|
|
|
void kvz_bitstream_free_chunks(kvz_data_chunk *chunk);
|
|
|
|
void kvz_bitstream_finalize(bitstream_t * stream);
|
2014-04-23 08:19:11 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
uint64_t kvz_bitstream_tell(const bitstream_t * stream);
|
2015-06-25 08:15:34 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_bitstream_writebyte(bitstream_t *stream, uint8_t byte);
|
|
|
|
void kvz_bitstream_move(bitstream_t *dst, bitstream_t *src);
|
|
|
|
void kvz_bitstream_clear(bitstream_t *stream);
|
2015-06-25 08:15:34 +00:00
|
|
|
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_bitstream_put(bitstream_t *stream, uint32_t data, uint8_t bits);
|
2016-12-23 14:12:32 +00:00
|
|
|
void kvz_bitstream_put_byte(bitstream_t *const stream, const uint32_t data);
|
2017-01-31 15:53:47 +00:00
|
|
|
|
2017-01-31 16:38:02 +00:00
|
|
|
void kvz_bitstream_put_ue(bitstream_t *stream, uint32_t data);
|
|
|
|
void kvz_bitstream_put_se(bitstream_t *stream, int32_t data);
|
2012-06-05 11:01:47 +00:00
|
|
|
|
2015-08-27 11:33:30 +00:00
|
|
|
void kvz_bitstream_add_rbsp_trailing_bits(bitstream_t *stream);
|
2015-08-27 11:56:05 +00:00
|
|
|
void kvz_bitstream_align(bitstream_t *stream);
|
2015-08-26 08:50:27 +00:00
|
|
|
void kvz_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 */
|
2015-08-26 08:50:27 +00:00
|
|
|
#define WRITE_U(stream, data, bits, name) { printf("%-40s u(%d) : %d\n", name,bits,data); kvz_bitstream_put(stream,data,bits);}
|
2017-01-31 16:38:02 +00:00
|
|
|
#define WRITE_UE(stream, data, name) { printf("%-40s ue(v): %d\n", name,data); kvz_bitstream_put_ue(stream,data);}
|
|
|
|
#define WRITE_SE(stream, data, name) { printf("%-40s se(v): %d\n", name,data); kvz_bitstream_put_se(stream,(data));}
|
2012-06-05 11:01:47 +00:00
|
|
|
#else
|
2015-08-26 08:50:27 +00:00
|
|
|
#define WRITE_U(stream, data, bits, name) { kvz_bitstream_put(stream,data,bits); }
|
2017-01-31 16:38:02 +00:00
|
|
|
#define WRITE_UE(stream, data, name) { kvz_bitstream_put_ue(stream,data); }
|
|
|
|
#define WRITE_SE(stream, data, name) { kvz_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
|