MPEG CDVA Experimentation Model (CXM)  1.0
Compact Descriptors for Visual Analisys
bitstream.h
Go to the documentation of this file.
1 
2 /*
3 //
4 // Copyright (c) 2002-2015 Joe Bertolami. All Right Reserved.
5 //
6 // bitstream.h
7 //
8 // Redistribution and use in source and binary forms, with or without
9 // modification, are permitted provided that the following conditions are met:
10 //
11 // * Redistributions of source code must retain the above copyright notice, this
12 // list of conditions and the following disclaimer.
13 //
14 // * Redistributions in binary form must reproduce the above copyright notice,
15 // this list of conditions and the following disclaimer in the documentation
16 // and/or other materials provided with the distribution.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
22 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 //
29 // Additional Information:
30 //
31 // For more information, visit http://www.bertolami.com.
32 //
33 */
34 
35 #ifndef __EVX_BIT_STREAM_H__
36 #define __EVX_BIT_STREAM_H__
37 
38 #include "base.h"
39 
40 #define EVX_READ_BIT(source, bit) (((source) >> (bit)) & 0x1)
41 #define EVX_WRITE_BIT(dest, bit, value) (dest) = (((dest) & ~(0x1 << (bit))) | \
42  (((value) & 0x1) << (bit)))
43 namespace evx {
44 
45 class bitstream
46 {
47  uint32 read_index;
48  uint32 write_index;
49  uint32 data_capacity;
50  uint8 *data_store;
51 
52 public:
53 
54  bitstream();
55  bitstream(uint32 size);
56  bitstream(void *bytes, uint32 size);
57  virtual ~bitstream();
58 
59  uint8 *query_data() const;
60  uint32 query_capacity() const;
61  uint32 query_occupancy() const;
63  uint32 resize_capacity(uint32 size_in_bits);
64 
65  /* seek will only adjust the read index. there is purposely
66  no way to adjust the write index. */
67  evx_status seek(uint32 bit_offset);
68  evx_status assign(const bitstream &rvalue);
69  evx_status assign(void *bytes, uint32 size);
70 
71  void clear();
72  void empty();
73 
74  bool is_empty() const;
75  bool is_full() const;
76 
78  evx_status write_bit(uint8 value);
79  evx_status write_bytes(void *data, uint32 byte_count);
80  evx_status write_bits(void *data, uint32 bit_count);
81 
82  evx_status read_byte(void *data);
83  evx_status read_bit(void *data);
84  evx_status read_bytes(void *data, uint32 *byte_count);
85  evx_status read_bits(void *data, uint32 *bit_count);
86 
87 private:
88 
89  EVX_DISABLE_COPY_AND_ASSIGN(bitstream);
90 };
91 
92 } // namespace EVX
93 
94 #endif // __EVX_BIT_STREAM_H__
u_int8_t uint8
Definition: base.h:137
Definition: base.h:116
Definition: bitstream.h:45
uint32 query_occupancy() const
evx_status write_byte(uint8 value)
bool is_full() const
uint32 query_capacity() const
virtual ~bitstream()
uint32 query_byte_occupancy() const
u_int32_t uint32
Definition: base.h:135
evx_status read_bytes(void *data, uint32 *byte_count)
uint8 * query_data() const
bool is_empty() const
uint8 evx_status
Definition: base.h:152
evx_status write_bits(void *data, uint32 bit_count)
evx_status read_byte(void *data)
evx_status seek(uint32 bit_offset)
evx_status read_bit(void *data)
evx_status write_bit(uint8 value)
evx_status write_bytes(void *data, uint32 byte_count)
uint32 resize_capacity(uint32 size_in_bits)
evx_status read_bits(void *data, uint32 *bit_count)
evx_status assign(const bitstream &rvalue)