GPMF_bitstream.h
Go to the documentation of this file.
1 // SPDX-License-Identifier: MIT
2 // SPDX-FileCopyrightText: Copyright 2017 GoPro Inc (http://gopro.com/).
3 
32 #ifndef _GPMF_BITSTREAM_H
33 #define _GPMF_BITSTREAM_H
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 #include <stdint.h>
40 
41 typedef struct rlv { // Codebook entries for arbitrary runs
42  uint16_t size; // Size of code word in bits
43  uint16_t bits; // Code word bits right justified
44  uint16_t count; // Run length for zeros
45  int16_t value; // Value for difference
46 } RLV;
47 
48 typedef const struct {
49  int length; // Number of entries in the code book
50  RLV entries[39];
51 } RLVTABLE;
52 
53 #define BITSTREAM_WORD_TYPE uint16_t // use 16-bit buffer for compression
54 #define BITSTREAM_WORD_SIZE 16 // use 16-bit buffer for compression
55 #define BITSTREAM_ERROR_OVERFLOW 1
56 
57 #define BITMASK(n) _bitmask[n]
58 #define _BITMASK(n) ((((BITSTREAM_WORD_TYPE )1 << (n))) - 1)
59 
60 static const BITSTREAM_WORD_TYPE _bitmask[] =
61 {
62  _BITMASK(0), _BITMASK(1), _BITMASK(2), _BITMASK(3),
63  _BITMASK(4), _BITMASK(5), _BITMASK(6), _BITMASK(7),
64  _BITMASK(8), _BITMASK(9), _BITMASK(10), _BITMASK(11),
65  _BITMASK(12), _BITMASK(13), _BITMASK(14), _BITMASK(15),
66  0xFFFF
67 };
68 
69 
70 
71 typedef struct bitstream
72 {
73  int32_t error; // Error parsing the bitstream
74  int32_t bitsFree; // Number of bits available in the current word
75  uint8_t *lpCurrentWord; // Pointer to next word in block
76  int32_t wordsUsed; // Number of words used in the block
77  int32_t dwBlockLength; // Number of entries in the block
78  uint16_t wBuffer; // Current word bit buffer
79  uint16_t bits_per_src_word; // Bitused in the source word. e.g. 's' = 16-bits
80 } BITSTREAM;
81 
82 
84  39,
85  {
86  { 1, 0b0, 1, 0 }, // m0
87  { 2, 0b10, 1, 1 }, // m1
88  { 4, 0b1100, 1, 2 }, // m2
89  { 5, 0b11011, 1, 3 }, // m3
90  { 5, 0b11101, 1, 4 }, // m4
91  { 6, 0b110100, 1, 5 }, // m5
92  { 6, 0b110101, 1, 6 }, // m6
93  { 6, 0b111110, 1, 7 }, // m7
94  { 7, 0b1110000, 1, 8 }, // m8
95  { 7, 0b1110011, 1, 9 }, // m9
96  { 7, 0b1111000, 1, 10 }, // m10
97  { 7, 0b1111001, 1, 11 }, // m11
98  { 7, 0b1111011, 1, 12 }, // m12
99  { 8, 0b11100100, 1, 13 }, // m13
100  { 8, 0b11100101, 1, 14 }, // m14
101  { 8, 0b11110100, 1, 15 }, // m15
102  { 9, 0b111000101, 1, 16 }, // m16
103  { 9, 0b111000110, 1, 17 }, // m17
104  { 9, 0b111101010, 1, 18 }, // m18
105  { 10, 0b1110001000, 1, 19 }, // m19
106  { 10, 0b1110001110, 1, 20 }, // m20
107  { 10, 0b1111010110, 1, 21 }, // m21
108  { 10, 0b1111111100, 1, 22 }, // m22
109  { 11, 0b11100010010, 1, 23 }, // m23
110  { 11, 0b11100011111, 1, 24 }, // m24
111  { 11, 0b11110101110, 1, 25 }, // m25
112  { 12, 0b111000100111, 1, 26 }, // m26
113  { 12, 0b111000111101, 1, 27 }, // m27
114  { 12, 0b111101011111, 1, 28 }, // m28
115  { 13, 0b1110001001101, 1, 29 }, // m29
116  { 13, 0b1110001111001, 1, 30 }, // m30
117  { 13, 0b1111010111101, 1, 31 }, // m31
118  { 14, 0b11100010011000, 1, 32 }, // m32
119  { 14, 0b11100011110000, 1, 33 }, // m33
120  { 14, 0b11110101111000, 1, 34 }, // m34
121  { 14, 0b11110101111001, 1, 35 }, // m35
122  { 15, 0b111000100110010, 1, 36 }, // m36
123  { 15, 0b111000100110011, 1, 37 }, // m37
124  { 15, 0b111000111100011, 1, 38 }, // m38
125  }
126 };
127 
128 
129 
131  4,
132  {
133  { 7, 0b1111110, 16, 0 }, // z16
134  { 8, 0b11111110, 32, 0 }, // z32
135  { 9, 0b111111111, 64, 0 }, // z64
136  { 10,0b1111111101, 128, 0 }, // z128
137  }
138 };
139 
140 #define HUFF_ESC_CODE_ENTRY 0
141 #define HUFF_END_CODE_ENTRY 1
143  2,
144  {
145  { 16, 0b1110001111000100, 0, 0 }, // escape code for direct data <ESC><data>Continue
146  { 16, 0b1110001111000101, 0, 0 }, // end code. Ends each compressed stream
147  }
148 };
149 
150 
151 
152 #ifdef __cplusplus
153 }
154 #endif
155 
156 #endif
bitstream::dwBlockLength
int32_t dwBlockLength
Definition: GPMF_bitstream.h:77
rlv::value
int16_t value
Definition: GPMF_bitstream.h:45
BITSTREAM
struct bitstream BITSTREAM
rlv::size
uint16_t size
Definition: GPMF_bitstream.h:42
bitstream::wordsUsed
int32_t wordsUsed
Definition: GPMF_bitstream.h:76
bitstream::lpCurrentWord
uint8_t * lpCurrentWord
Definition: GPMF_bitstream.h:75
bitstream::error
int32_t error
Definition: GPMF_bitstream.h:73
_bitmask
static const BITSTREAM_WORD_TYPE _bitmask[]
Definition: GPMF_bitstream.h:60
_BITMASK
#define _BITMASK(n)
Definition: GPMF_bitstream.h:58
enczerorunstable
static RLVTABLE enczerorunstable
Definition: GPMF_bitstream.h:130
bitstream
Definition: GPMF_bitstream.h:71
RLV
struct rlv RLV
bitstream::bits_per_src_word
uint16_t bits_per_src_word
Definition: GPMF_bitstream.h:79
RLVTABLE::length
int length
Definition: GPMF_bitstream.h:49
bitstream::bitsFree
int32_t bitsFree
Definition: GPMF_bitstream.h:74
entries
constexpr auto entries(std::index_sequence< I... >) noexcept
bitstream::wBuffer
uint16_t wBuffer
Definition: GPMF_bitstream.h:78
RLVTABLE
Definition: GPMF_bitstream.h:48
rlv::count
uint16_t count
Definition: GPMF_bitstream.h:44
enccontrolcodestable
static RLVTABLE enccontrolcodestable
Definition: GPMF_bitstream.h:142
rlv
Definition: GPMF_bitstream.h:41
BITSTREAM_WORD_TYPE
#define BITSTREAM_WORD_TYPE
Definition: GPMF_bitstream.h:53
rlv::bits
uint16_t bits
Definition: GPMF_bitstream.h:43
enchuftable
static RLVTABLE enchuftable
Definition: GPMF_bitstream.h:83


gpmf_metadata_extractor
Author(s): Martin Pecka , Liam Samuel Pach
autogenerated on Wed May 28 2025 02:07:33