UltraGrid
UltraGrid Low-Latency High-Resolution Transmission System
Loading...
Searching...
No Matches
bitstream.h File Reference
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define RAT_BITSTREAM_H
 

Typedefs

typedef struct s_bitstream bitstream_t
 

Functions

int bs_attach (bitstream_t *b, u_char *buf, int blen)
 
int bs_bytes_used (bitstream_t *b)
 
int bs_create (bitstream_t **b)
 
int bs_destroy (bitstream_t **b)
 
u_char bs_get (bitstream_t *b, uint8_t nbits)
 
int bs_put (bitstream_t *b, u_char bits, uint8_t nbits)
 

Macro Definition Documentation

◆ RAT_BITSTREAM_H

#define RAT_BITSTREAM_H

Definition at line 22 of file bitstream.h.

Typedef Documentation

◆ bitstream_t

typedef struct s_bitstream bitstream_t

Definition at line 24 of file bitstream.h.

Function Documentation

◆ bs_attach()

int bs_attach ( bitstream_t * b,
u_char * buf,
int blen )

Definition at line 41 of file bitstream.c.

42{
43 b->buf = b->pos = buf;
44 b->remain = 8;
45 b->len = blen;
46 memset(b->buf, 0, b->len);
47 return TRUE;
48}
#define TRUE
u_char * pos
Definition bitstream.c:18
u_char * buf
Definition bitstream.c:17
unsigned int remain
Definition bitstream.c:19
unsigned int len
Definition bitstream.c:20

References s_bitstream::buf, s_bitstream::len, s_bitstream::pos, s_bitstream::remain, and TRUE.

Referenced by test_bitstream().

◆ bs_bytes_used()

int bs_bytes_used ( bitstream_t * b)

Definition at line 102 of file bitstream.c.

103{
104 unsigned int used = (unsigned int)(b->pos - b->buf);
105 if (b->remain != 8) {
106 used++;
107 }
108 return used;
109}

References s_bitstream::buf, s_bitstream::pos, and s_bitstream::remain.

◆ bs_create()

int bs_create ( bitstream_t ** b)

Definition at line 23 of file bitstream.c.

24{
25 bs *pb;
26 pb = (bs *) malloc(sizeof(bs));
27 if (pb) {
28 memset(pb, 0, sizeof(bs));
29 *ppb = pb;
30 return TRUE;
31 }
32 return FALSE;
33}
#define FALSE

References FALSE, and TRUE.

Referenced by test_bitstream().

◆ bs_destroy()

int bs_destroy ( bitstream_t ** b)

Definition at line 35 of file bitstream.c.

36{
37 free(*ppb);
38 return TRUE;
39}

References TRUE.

Referenced by test_bitstream().

◆ bs_get()

u_char bs_get ( bitstream_t * b,
uint8_t nbits )

Definition at line 74 of file bitstream.c.

75{
76 u_char out;
77
78 if (b->remain == 0) {
79 b->pos++;
80 b->remain = 8;
81 }
82
83 if (nbits > b->remain) {
84 /* Get high bits */
85 out = *b->pos;
86 out <<= (8 - b->remain);
87 out >>= (8 - nbits);
88 b->pos++;
89 b->remain += 8 - nbits;
90 out |= (*b->pos) >> b->remain;
91 } else {
92 out = *b->pos;
93 out <<= (8 - b->remain);
94 out >>= (8 - nbits);
95 b->remain -= nbits;
96 }
97
98 assert((unsigned int)(b->pos - b->buf) <= b->len);
99 return out;
100}

References s_bitstream::buf, s_bitstream::len, s_bitstream::pos, and s_bitstream::remain.

◆ bs_put()

int bs_put ( bitstream_t * b,
u_char bits,
uint8_t nbits )

Definition at line 50 of file bitstream.c.

51{
52 assert(nbits != 0 && nbits <= 8);
53
54 if (b->remain == 0) {
55 b->pos++;
56 b->remain = 8;
57 }
58
59 if (nbits > b->remain) {
60 unsigned int over = nbits - b->remain;
61 (*b->pos) |= (bits >> over);
62 b->pos++;
63 b->remain = 8 - over;
64 (*b->pos) = (bits << b->remain);
65 } else {
66 (*b->pos) |= bits << (b->remain - nbits);
67 b->remain -= nbits;
68 }
69
70 assert((unsigned int)(b->pos - b->buf) <= b->len);
71 return TRUE;
72}

References s_bitstream::buf, s_bitstream::len, s_bitstream::pos, s_bitstream::remain, and TRUE.

Referenced by test_bitstream().