![]() |
libgpac
Documentation of the core library of GPAC
|
Bitstream Reading and Writing. More...
Enumerations | |
enum | { GF_BITSTREAM_READ = 0 , GF_BITSTREAM_WRITE , GF_BITSTREAM_WRITE_DYN } |
Functions | |
GF_BitStream * | gf_bs_new (const u8 *buffer, u64 size, u32 mode) |
bitstream constructor More... | |
GF_Err | gf_bs_reassign_buffer (GF_BitStream *bs, const u8 *buffer, u64 size) |
bitstream reassignment More... | |
GF_BitStream * | gf_bs_from_file (FILE *f, u32 mode) |
bitstream constructor from file handle More... | |
void | gf_bs_del (GF_BitStream *bs) |
bitstream destructor from file handle More... | |
GF_BitStream * | gf_bs_new_cbk (GF_Err(*on_block_out)(void *cbk, u8 *data, u32 block_size), void *usr_data, u32 block_size) |
bitstream constructor from callback output More... | |
GF_BitStream * | gf_bs_new_cbk_buffer (GF_Err(*on_block_out)(void *cbk, u8 *data, u32 block_size), void *usr_data, u8 *buffer, u32 buffer_size) |
bitstream constructor from callback output and preallocated buffer More... | |
void | gf_bs_prevent_dispatch (GF_BitStream *bs, Bool prevent_dispatch) |
prevents block dispatch Prevents byte dispatching in callback mode. This is used when seek operations are used. More... | |
u32 | gf_bs_read_int (GF_BitStream *bs, u32 nBits) |
integer reading More... | |
u64 | gf_bs_read_long_int (GF_BitStream *bs, u32 nBits) |
large integer reading More... | |
Float | gf_bs_read_float (GF_BitStream *bs) |
float reading More... | |
Double | gf_bs_read_double (GF_BitStream *bs) |
double reading More... | |
u32 | gf_bs_read_data (GF_BitStream *bs, u8 *data, u32 nbBytes) |
data reading More... | |
u32 | gf_bs_read_u8 (GF_BitStream *bs) |
align char reading More... | |
u32 | gf_bs_read_u16 (GF_BitStream *bs) |
align short reading More... | |
u32 | gf_bs_read_u24 (GF_BitStream *bs) |
align 24-bit integer reading More... | |
u32 | gf_bs_read_u32 (GF_BitStream *bs) |
align integer reading More... | |
u64 | gf_bs_read_u64 (GF_BitStream *bs) |
align large integer reading More... | |
u64 | gf_bs_read_u64_le (GF_BitStream *bs) |
little endian integer reading More... | |
u32 | gf_bs_read_u32_le (GF_BitStream *bs) |
little endian integer reading More... | |
u16 | gf_bs_read_u16_le (GF_BitStream *bs) |
little endian integer reading More... | |
u32 | gf_bs_read_vluimsbf5 (GF_BitStream *bs) |
variable length integer reading More... | |
u32 | gf_bs_get_bit_offset (GF_BitStream *bs) |
bit position More... | |
u32 | gf_bs_get_bit_position (GF_BitStream *bs) |
current bit position More... | |
void | gf_bs_write_int (GF_BitStream *bs, s32 value, s32 nBits) |
integer writing More... | |
void | gf_bs_write_long_int (GF_BitStream *bs, s64 value, s32 nBits) |
large integer writing More... | |
void | gf_bs_write_float (GF_BitStream *bs, Float value) |
float writing More... | |
void | gf_bs_write_double (GF_BitStream *bs, Double value) |
double writing More... | |
u32 | gf_bs_write_data (GF_BitStream *bs, const u8 *data, u32 nbBytes) |
data writing More... | |
void | gf_bs_write_u8 (GF_BitStream *bs, u32 value) |
align char writing More... | |
void | gf_bs_write_u16 (GF_BitStream *bs, u32 value) |
align short writing More... | |
void | gf_bs_write_u24 (GF_BitStream *bs, u32 value) |
align 24-bits integer writing More... | |
void | gf_bs_write_u32 (GF_BitStream *bs, u32 value) |
align integer writing More... | |
void | gf_bs_write_u64 (GF_BitStream *bs, u64 value) |
align large integer writing More... | |
void | gf_bs_write_u32_le (GF_BitStream *bs, u32 value) |
little endian integer writing More... | |
void | gf_bs_write_u64_le (GF_BitStream *bs, u64 value) |
little endian large integer writing More... | |
void | gf_bs_write_u16_le (GF_BitStream *bs, u32 value) |
little endian short writing More... | |
u32 | gf_bs_write_byte (GF_BitStream *bs, u8 byte, u32 count) |
write byte multiple times More... | |
void | gf_bs_set_eos_callback (GF_BitStream *bs, void(*EndOfStream)(void *par), void *par) |
end of bitstream management More... | |
Bool | gf_bs_is_align (GF_BitStream *bs) |
bitstream alignment checking More... | |
u8 | gf_bs_align (GF_BitStream *bs) |
bitstream alignment More... | |
u64 | gf_bs_available (GF_BitStream *bs) |
capacity query More... | |
void | gf_bs_get_content (GF_BitStream *bs, u8 **output, u32 *outSize) |
buffer fetching More... | |
void | gf_bs_get_content_no_truncate (GF_BitStream *bs, u8 **output, u32 *outSize, u32 *allocSize) |
buffer fetching More... | |
void | gf_bs_skip_bytes (GF_BitStream *bs, u64 nbBytes) |
byte skipping More... | |
GF_Err | gf_bs_seek (GF_BitStream *bs, u64 offset) |
bitstream seeking More... | |
void | gf_bs_truncate (GF_BitStream *bs) |
bitstream truncation More... | |
u32 | gf_bs_peek_bits (GF_BitStream *bs, u32 numBits, u64 byte_offset) |
bit peeking More... | |
u8 | gf_bs_bits_available (GF_BitStream *bs) |
bit reservoir query More... | |
u64 | gf_bs_get_position (GF_BitStream *bs) |
position query More... | |
u64 | gf_bs_get_size (GF_BitStream *bs) |
size query More... | |
u64 | gf_bs_get_refreshed_size (GF_BitStream *bs) |
file-based size query More... | |
GF_Err | gf_bs_transfer (GF_BitStream *dst, GF_BitStream *src, Bool keep_src) |
transfer content from source bitstream to destination bitstream More... | |
void | gf_bs_flush (GF_BitStream *bs) |
Flushes bitstream content to disk. More... | |
void | gf_bs_enable_emulation_byte_removal (GF_BitStream *bs, Bool do_remove) |
NALU-based Annex B mode, only used for read mode. More... | |
u32 | gf_bs_get_emulation_byte_removed (GF_BitStream *bs) |
NALU-based Annex B mode, only used for read mode. More... | |
GF_Err | gf_bs_insert_data (GF_BitStream *bs, u8 *data, u32 size, u64 offset) |
Inserts a data block, moving bytes to the end. More... | |
u64 | gf_bs_set_cookie (GF_BitStream *bs, u64 cookie) |
Sets cookie. More... | |
u64 | gf_bs_get_cookie (GF_BitStream *bs) |
Gets cookie. More... | |
char * | gf_bs_read_utf8 (GF_BitStream *bs) |
Reads string. More... | |
GF_Err | gf_bs_write_utf8 (GF_BitStream *bs, const char *str) |
Writes string. More... | |
void | gf_bs_mark_overflow (GF_BitStream *bs, Bool reset) |
Marks overflow access. More... | |
u32 | gf_bs_is_overflow (GF_BitStream *bs) |
Gets overflow state. More... | |
Bitstream Reading and Writing.
This section documents the bitstream object of the GPAC framework.
anonymous enum |
bitstream constructor
Constructs a bitstream from a buffer (read or write mode)
buffer | buffer to read or write. In WRITE mode, this can be NULL to let the bitstream object dynamically allocate memory, in which case the size param is ignored. |
size | size of the buffer given. |
mode | operation mode for this bitstream: GF_BITSTREAM_READ for read, GF_BITSTREAM_WRITE for write. |
bitstream reassignment
Reassigns a bitstream in GF_BITSTREAM_READ mode to a new buffer
bs | the bitstream to reassign |
buffer | buffer to read |
size | size of the buffer given. |
GF_BitStream* gf_bs_from_file | ( | FILE * | f, |
u32 | mode | ||
) |
bitstream constructor from file handle
Creates a bitstream from a file handle.
f | handle of the file to use. This handle must be created with binary mode. |
mode | operation mode for this bitstream: GF_BITSTREAM_READ for read, GF_BITSTREAM_WRITE for write. |
void gf_bs_del | ( | GF_BitStream * | bs | ) |
bitstream destructor from file handle
Deletes the bitstream object. If the buffer was created by the bitstream, it is deleted if still present.
bs | the target bitstream |
GF_BitStream* gf_bs_new_cbk | ( | GF_Err(*)(void *cbk, u8 *data, u32 block_size) | on_block_out, |
void * | usr_data, | ||
u32 | block_size | ||
) |
bitstream constructor from callback output
Creates a bitstream from in write mode suing output callback.
on_block_out | callback function used to write blocks. |
usr_data | user data for callback. |
block_size | internal buffer size used while dispatching bytes. If 0, defaults to 40k. |
GF_BitStream* gf_bs_new_cbk_buffer | ( | GF_Err(*)(void *cbk, u8 *data, u32 block_size) | on_block_out, |
void * | usr_data, | ||
u8 * | buffer, | ||
u32 | buffer_size | ||
) |
bitstream constructor from callback output and preallocated buffer
Creates a bitstream from in write mode suing output callback.
on_block_out | callback function used to write blocks. |
usr_data | user data for callback. |
buffer | internal buffer to use while dispatching bytes. If NULL, buffer is allocated internally using buffer_size. |
buffer_size | internal buffer size used while dispatching bytes. If 0, defaults to 40k. |
void gf_bs_prevent_dispatch | ( | GF_BitStream * | bs, |
Bool | prevent_dispatch | ||
) |
prevents block dispatch Prevents byte dispatching in callback mode. This is used when seek operations are used.
bs | the target bitstream |
prevent_dispatch | activates temporary internal storage if set |
integer reading
Reads an integer coded on a number of bit.
bs | the target bitstream |
nBits | the number of bits to read |
large integer reading
Reads a large integer coded on a number of bit bigger than 32.
bs | the target bitstream |
nBits | the number of bits to read |
Float gf_bs_read_float | ( | GF_BitStream * | bs | ) |
float reading
Reads a float coded as IEEE 32 bit format.
bs | the target bitstream |
Double gf_bs_read_double | ( | GF_BitStream * | bs | ) |
double reading
Reads a double coded as IEEE 64 bit format.
bs | the target bitstream |
data reading
Reads a data buffer. Emultation prevention byte removal is NOT applied here
bs | the target bitstream |
data | the data buffer to be filled |
nbBytes | the amount of bytes to read |
u32 gf_bs_read_u8 | ( | GF_BitStream * | bs | ) |
align char reading
Reads an integer coded on 8 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
u32 gf_bs_read_u16 | ( | GF_BitStream * | bs | ) |
align short reading
Reads an integer coded on 16 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
u32 gf_bs_read_u24 | ( | GF_BitStream * | bs | ) |
align 24-bit integer reading
Reads an integer coded on 24 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
u32 gf_bs_read_u32 | ( | GF_BitStream * | bs | ) |
align integer reading
Reads an integer coded on 32 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
u64 gf_bs_read_u64 | ( | GF_BitStream * | bs | ) |
align large integer reading
Reads an integer coded on 64 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
u64 gf_bs_read_u64_le | ( | GF_BitStream * | bs | ) |
little endian integer reading
Reads an integer coded on 64 bits in little-endian order.
bs | the target bitstream |
u32 gf_bs_read_u32_le | ( | GF_BitStream * | bs | ) |
little endian integer reading
Reads an integer coded on 32 bits in little-endian order.
bs | the target bitstream |
u16 gf_bs_read_u16_le | ( | GF_BitStream * | bs | ) |
little endian integer reading
Reads an integer coded on 16 bits in little-endian order.
bs | the target bitstream |
u32 gf_bs_read_vluimsbf5 | ( | GF_BitStream * | bs | ) |
variable length integer reading
Reads an integer coded on a variable number of 4-bits chunks. The number of chunks is given by the number of non-0 bits at the beginning.
bs | the target bitstream |
u32 gf_bs_get_bit_offset | ( | GF_BitStream * | bs | ) |
bit position
Returns current bit position in the bitstream - only works in memory mode.
bs | the target bitstream |
u32 gf_bs_get_bit_position | ( | GF_BitStream * | bs | ) |
current bit position
Returns bit position in the current byte of the bitstream - only works in memory mode.
bs | the target bitstream |
integer writing
Writes an integer on a given number of bits.
bs | the target bitstream |
value | the integer to write |
nBits | number of bits used to code the integer |
large integer writing
Writes an integer on a given number of bits greater than 32.
bs | the target bitstream |
value | the large integer to write |
nBits | number of bits used to code the integer |
void gf_bs_write_float | ( | GF_BitStream * | bs, |
Float | value | ||
) |
float writing
Writes a float in IEEE 32 bits format.
bs | the target bitstream |
value | the float to write |
void gf_bs_write_double | ( | GF_BitStream * | bs, |
Double | value | ||
) |
double writing
Writes a double in IEEE 64 bits format.
bs | the target bitstream |
value | the double to write |
data writing
Writes a data buffer.
bs | the target bitstream |
data | the data to write |
nbBytes | number of data bytes to write |
void gf_bs_write_u8 | ( | GF_BitStream * | bs, |
u32 | value | ||
) |
align char writing
Writes an integer on 8 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
value | the char value to write |
void gf_bs_write_u16 | ( | GF_BitStream * | bs, |
u32 | value | ||
) |
align short writing
Writes an integer on 16 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
value | the short value to write |
void gf_bs_write_u24 | ( | GF_BitStream * | bs, |
u32 | value | ||
) |
align 24-bits integer writing
Writes an integer on 24 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
value | the integer value to write |
void gf_bs_write_u32 | ( | GF_BitStream * | bs, |
u32 | value | ||
) |
align integer writing
Writes an integer on 32 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
value | the integer value to write |
void gf_bs_write_u64 | ( | GF_BitStream * | bs, |
u64 | value | ||
) |
align large integer writing
Writes an integer on 64 bits starting at a byte boundary in the bitstream.
bs | the target bitstream |
value | the large integer value to write |
void gf_bs_write_u32_le | ( | GF_BitStream * | bs, |
u32 | value | ||
) |
little endian integer writing
Writes an integer on 32 bits in little-endian order.
bs | the target bitstream |
value | the integer value to write |
void gf_bs_write_u64_le | ( | GF_BitStream * | bs, |
u64 | value | ||
) |
little endian large integer writing
Writes an integer on 64 bits in little-endian order.
bs | the target bitstream |
value | the integer value to write |
void gf_bs_write_u16_le | ( | GF_BitStream * | bs, |
u32 | value | ||
) |
little endian short writing
Writes an integer on 16 bits in little-endian order.
bs | the target bitstream |
value | the short value to write |
write byte multiple times
Writes a give byte multiple times.
bs | the target bitstream |
byte | the byte value to write |
count | the number of times the byte should be written |
void gf_bs_set_eos_callback | ( | GF_BitStream * | bs, |
void(*)(void *par) | EndOfStream, | ||
void * | par | ||
) |
end of bitstream management
Assigns a notification callback function for end of stream signaling in read mode
bs | the target bitstream |
EndOfStream | the notification function to use |
par | opaque user data passed to the bitstream |
Bool gf_bs_is_align | ( | GF_BitStream * | bs | ) |
bitstream alignment checking
Checks if bitstream position is aligned to a byte boundary.
bs | the target bitstream |
u8 gf_bs_align | ( | GF_BitStream * | bs | ) |
bitstream alignment
Aligns bitstream to next byte boundary. In write mode, this will write 0 bit values until alignment.
bs | the target bitstream |
u64 gf_bs_available | ( | GF_BitStream * | bs | ) |
capacity query
Returns the number of bytes still available in the bitstream in read mode.
bs | the target bitstream |
buffer fetching
Fetches the internal bitstream buffer in write mode. If a buffer was given at the bitstream construction, or if the bitstream is in read mode, this does nothing.
bs | the target bitstream |
output | address of the memory block allocated by the bitstream. |
outSize | size of the allocated memory block. |
void gf_bs_get_content_no_truncate | ( | GF_BitStream * | bs, |
u8 ** | output, | ||
u32 * | outSize, | ||
u32 * | allocSize | ||
) |
buffer fetching
Fetches the internal bitstream buffer in write mode. If a buffer was given at the bitstream construction, or if the bitstream is in read mode, this does nothing. Retrieves both the allocated buffer size and the written size
bs | the target bitstream |
output | address of the memory block allocated by the bitstream. |
outSize | number of bytes written in the allocated memory block. |
allocSize | size of the allocated memory block. |
void gf_bs_skip_bytes | ( | GF_BitStream * | bs, |
u64 | nbBytes | ||
) |
byte skipping
Skips bytes in the bitstream. In Write mode, this will write the 0 integer value for memory-based bitstreams or seek the stream for file-based bitstream. In read mode, emultation prevention byte is applied if enabled
bs | the target bitstream |
nbBytes | the number of bytes to skip |
bitstream seeking
Seeks the bitstream to a given offset after the beginning of the stream. This will perform alignment of the bitstream in all modes.
bs | the target bitstream |
offset | buffer/file offset to seek to |
void gf_bs_truncate | ( | GF_BitStream * | bs | ) |
bitstream truncation
Truncates the bitstream at the current position
bs | the target bitstream |
bit peeking
Peeks a given number of bits (read without moving the position indicator) for read modes only.
bs | the target bitstream |
numBits | the number of bits to peek |
byte_offset | if set, bitstream is aligned and moved from byte_offset before peeking (byte-aligned picking) otherwise, bitstream is not aligned and bits are peeked from current state |
u8 gf_bs_bits_available | ( | GF_BitStream * | bs | ) |
bit reservoir query
Queries the number of bits available in read mode.
bs | the target bitstream |
u64 gf_bs_get_position | ( | GF_BitStream * | bs | ) |
position query
Returns the reading/writting position in the buffer/file.
bs | the target bitstream |
u64 gf_bs_get_size | ( | GF_BitStream * | bs | ) |
size query
Returns the size of the associated buffer/file.
bs | the target bitstream |
u64 gf_bs_get_refreshed_size | ( | GF_BitStream * | bs | ) |
file-based size query
Returns the size of a file-based bitstream and force a seek to end of file. This is used in case the file handle describes a file being constructed on disk while being read?
bs | the target bitstream |
transfer content from source bitstream to destination bitstream
dst | the target bitstream |
src | the source bitstream. |
keep_src | If not set, the source bitstream is empty after calling the function |
void gf_bs_flush | ( | GF_BitStream * | bs | ) |
Flushes bitstream content to disk.
Flushes bitstream contet to disk
bs | the target bitstream |
void gf_bs_enable_emulation_byte_removal | ( | GF_BitStream * | bs, |
Bool | do_remove | ||
) |
NALU-based Annex B mode, only used for read mode.
Enables or disable emulation byte prevention for NALU-based annex B formats in read mode. This does NOT apply to gf_bs_read_data nor gf_bs_skip_bytes
bs | the target bitstream |
do_remove | if true, emulation prevention bytes will be removed |
u32 gf_bs_get_emulation_byte_removed | ( | GF_BitStream * | bs | ) |
NALU-based Annex B mode, only used for read mode.
Enables or disable emulation byte prevention for NALU-based annex B formats in read mode.
bs | the target bitstream |
Inserts a data block, moving bytes to the end.
Inserts a data block at a given position, pushing all bytes after the insertion point to the end of the stream. This does NOT work if gf_bs_enable_emulation_byte_removal or gf_bs_new_cbk where used. The position after the call will be the same as before the call. If the position is not the end of the bitstream all bytes after the position will be lost.
bs | the target bitstream |
data | block to insert |
size | size of the block to insert |
offset | insertion offset from bitstream start |
Sets cookie.
Sets a 64 bit cookie (integer, pointer) on the bitstream, returning the current cookie value
bs | the target bitstream |
cookie | the new cookie to assign |
u64 gf_bs_get_cookie | ( | GF_BitStream * | bs | ) |
Gets cookie.
Gets the current cookie on the bitstream
bs | the target bitstream |
char* gf_bs_read_utf8 | ( | GF_BitStream * | bs | ) |
Reads string.
reads utf-8 NULL-terminated string - bitstream must be aligned
bs | the target bitstream |
GF_Err gf_bs_write_utf8 | ( | GF_BitStream * | bs, |
const char * | str | ||
) |
Writes string.
Writes utf-8 NULL-terminated string - bitstream must be aligned
bs | the target bitstream |
str | UTF-8 string to write |
void gf_bs_mark_overflow | ( | GF_BitStream * | bs, |
Bool | reset | ||
) |
Marks overflow access.
Marks the bitstream as overflown (reading outside of buffer range). Marking is done automatically when reading but can be forced using this function.
bs | the target bitstream |
reset | if GF_TRUE, reset overflown state, otherwise mark as overflown |
u32 gf_bs_is_overflow | ( | GF_BitStream * | bs | ) |
Gets overflow state.
Gets overflow state of the bitstream
bs | the target bitstream |