TUT HEVC Encoder
Loading...
Searching...
No Matches
bitstream.h
Go to the documentation of this file.
1#ifndef BITSTREAM_H_
2#define BITSTREAM_H_
3/*****************************************************************************
4 * This file is part of Kvazaar HEVC encoder.
5 *
6 * Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without modification,
10 * are permitted provided that the following conditions are met:
11 *
12 * * Redistributions of source code must retain the above copyright notice, this
13 * list of conditions and the following disclaimer.
14 *
15 * * Redistributions in binary form must reproduce the above copyright notice, this
16 * list of conditions and the following disclaimer in the documentation and/or
17 * other materials provided with the distribution.
18 *
19 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its
20 * contributors may be used to endorse or promote products derived from
21 * this software without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
28 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON
30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS
33 ****************************************************************************/
34
41#include "global.h" // IWYU pragma: keep
42
43#include "kvazaar.h"
44
45
49typedef struct bitstream_t
50{
52 uint32_t len;
53
56
59
61 uint8_t data;
62
64 uint8_t cur_bit;
65
66 uint8_t zerocount;
68
69typedef struct
70{
71 uint8_t len;
72 uint32_t value;
74
75void kvz_bitstream_init(bitstream_t * stream);
80
81uint64_t kvz_bitstream_tell(const bitstream_t * stream);
82
83void kvz_bitstream_writebyte(bitstream_t *stream, uint8_t byte);
86
87void kvz_bitstream_put(bitstream_t *stream, uint32_t data, uint8_t bits);
88void kvz_bitstream_put_byte(bitstream_t *const stream, const uint32_t data);
89
90void kvz_bitstream_put_ue(bitstream_t *stream, uint32_t data);
91void kvz_bitstream_put_se(bitstream_t *stream, int32_t data);
92
96
97/* In debug mode print out some extra info */
98#ifdef KVZ_DEBUG_PRINT_CABAC
99/* Counter to keep up with bits written */
100#define WRITE_U(stream, data, bits, name) { printf("%-40s u(%d) : %d\n", name,bits,data); kvz_bitstream_put(stream,data,bits);}
101#define WRITE_UE(stream, data, name) { printf("%-40s ue(v): %d\n", name,data); kvz_bitstream_put_ue(stream,data);}
102#define WRITE_SE(stream, data, name) { printf("%-40s se(v): %d\n", name,data); kvz_bitstream_put_se(stream,(data));}
103#else
104#define WRITE_U(stream, data, bits, name) { kvz_bitstream_put(stream,data,bits); }
105#define WRITE_UE(stream, data, name) { kvz_bitstream_put_ue(stream,data); }
106#define WRITE_SE(stream, data, name) { kvz_bitstream_put_se(stream,data); }
107#endif
108
109
110#endif
uint64_t kvz_bitstream_tell(const bitstream_t *stream)
Get the number of bits written.
Definition bitstream.c:134
void kvz_bitstream_free_chunks(kvz_data_chunk *chunk)
Free a list of chunks.
Definition bitstream.c:112
void kvz_bitstream_clear(bitstream_t *stream)
Reset stream.
Definition bitstream.c:201
void kvz_bitstream_align(bitstream_t *stream)
Align the bitstream, unless it's already aligned.
Definition bitstream.c:288
void kvz_bitstream_init(bitstream_t *stream)
Initialize a new bitstream.
Definition bitstream.c:73
void kvz_bitstream_put_ue(bitstream_t *stream, uint32_t data)
Write unsigned Exp-Golomb bit string.
Definition bitstream.c:253
void kvz_bitstream_finalize(bitstream_t *stream)
Free resources used by a bitstream.
Definition bitstream.c:124
void kvz_bitstream_put_byte(bitstream_t *const stream, const uint32_t data)
Write a byte to a byte aligned bitstream.
Definition bitstream.c:212
kvz_data_chunk * kvz_bitstream_alloc_chunk()
Allocates a new bitstream chunk.
Definition bitstream.c:99
void kvz_bitstream_add_rbsp_trailing_bits(bitstream_t *stream)
Add rbsp_trailing_bits syntax element, which aligns the bitstream.
Definition bitstream.c:277
void kvz_bitstream_writebyte(bitstream_t *stream, uint8_t byte)
Write a byte to bitstream.
Definition bitstream.c:148
void kvz_bitstream_move(bitstream_t *dst, bitstream_t *src)
Move data from one stream to another.
Definition bitstream.c:173
void kvz_bitstream_put_se(bitstream_t *stream, int32_t data)
Write signed Exp-Golomb bit string.
Definition bitstream.c:267
void kvz_bitstream_align_zero(bitstream_t *stream)
Align the bitstream with zero.
Definition bitstream.c:298
void kvz_bitstream_put(bitstream_t *stream, uint32_t data, uint8_t bits)
Write bits to bitstream Buffers individual bits untill they make a full byte.
Definition bitstream.c:232
kvz_data_chunk * kvz_bitstream_take_chunks(bitstream_t *stream)
Take chunks from a bitstream.
Definition bitstream.c:85
Header that is included in every other header.
This file defines the public API of Kvazaar when used as a library.
static kvz_rc_data * data
Definition rate_control.c:48
Definition bitstream.h:70
uint32_t value
Definition bitstream.h:72
uint8_t len
Definition bitstream.h:71
A stream of bits.
Definition bitstream.h:50
kvz_data_chunk * first
Pointer to the first chunk, or NULL.
Definition bitstream.h:55
uint8_t data
The incomplete byte.
Definition bitstream.h:61
uint32_t len
Total number of complete bytes.
Definition bitstream.h:52
uint8_t zerocount
Definition bitstream.h:66
uint8_t cur_bit
Number of bits in the incomplete byte.
Definition bitstream.h:64
kvz_data_chunk * last
Pointer to the last chunk, or NULL.
Definition bitstream.h:58
A linked list of chunks of data.
Definition kvazaar.h:653