libgpac
Documentation of the core library of GPAC
Bitstream IO

Bitstream Reading and Writing. More...

+ Collaboration diagram for Bitstream IO:

Typedefs

typedef struct __tag_bitstream GF_BitStream
 

Enumerations

enum  { GF_BITSTREAM_READ = 0 , GF_BITSTREAM_WRITE , GF_BITSTREAM_WRITE_DYN }
 

Functions

GF_BitStreamgf_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_BitStreamgf_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_BitStreamgf_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_BitStreamgf_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...
 

Detailed Description

This section documents the bitstream object of the GPAC framework.

Note
Unless specified, all functions assume Big-Endian ordering of data in the bitstream.

Typedef Documentation

◆ GF_BitStream

typedef struct __tag_bitstream GF_BitStream

bitstream object

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

bitstream creation modes

Enumerator
GF_BITSTREAM_READ 

read-only mode

GF_BITSTREAM_WRITE 

read-write mode

GF_BITSTREAM_WRITE_DYN 

allows reallocating the buffer passed in WRITE mode

Function Documentation

◆ gf_bs_new()

GF_BitStream* gf_bs_new ( const u8 buffer,
u64  size,
u32  mode 
)

Constructs a bitstream from a buffer (read or write mode)

Parameters
bufferbuffer 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.
sizesize of the buffer given.
modeoperation mode for this bitstream: GF_BITSTREAM_READ for read, GF_BITSTREAM_WRITE for write.
Returns
new bitstream object
Note
In write mode on an existing data buffer, data overflow is never signaled but simply ignored, it is the caller responsibility to ensure it does not write more than possible.

◆ gf_bs_reassign_buffer()

GF_Err gf_bs_reassign_buffer ( GF_BitStream bs,
const u8 buffer,
u64  size 
)

Reassigns a bitstream in GF_BITSTREAM_READ mode to a new buffer

Parameters
bsthe bitstream to reassign
bufferbuffer to read
sizesize of the buffer given.
Returns
error code if any

◆ gf_bs_from_file()

GF_BitStream* gf_bs_from_file ( FILE *  f,
u32  mode 
)

Creates a bitstream from a file handle.

Parameters
fhandle of the file to use. This handle must be created with binary mode.
modeoperation mode for this bitstream: GF_BITSTREAM_READ for read, GF_BITSTREAM_WRITE for write.
Returns
new bitstream object
Note
- You have to open your file in the appropriated mode:
  • GF_BITSTREAM_READ: bitstream is constructed for reading
  • GF_BITSTREAM_WRITE: bitstream is constructed for writing
- you may use any of these modes for a file with read/write access.
Warning
RESULTS ARE UNEXPECTED IF YOU TOUCH THE FILE WHILE USING THE BITSTREAM.

◆ gf_bs_del()

void gf_bs_del ( GF_BitStream bs)

Deletes the bitstream object. If the buffer was created by the bitstream, it is deleted if still present.

Warning
If the bitstream was constructed from a FILE object in write mode, the FILE object MUST be closed after destructing the bitstream
Parameters
bsthe target bitstream

◆ gf_bs_new_cbk()

GF_BitStream* gf_bs_new_cbk ( GF_Err(*)(void *cbk, u8 *data, u32 block_size)  on_block_out,
void *  usr_data,
u32  block_size 
)

Creates a bitstream from in write mode suing output callback.

Parameters
on_block_outcallback function used to write blocks.
usr_datauser data for callback.
block_sizeinternal buffer size used while dispatching bytes. If 0, defaults to 40k.
Returns
new bitstream object

◆ gf_bs_new_cbk_buffer()

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 
)

Creates a bitstream from in write mode suing output callback.

Parameters
on_block_outcallback function used to write blocks.
usr_datauser data for callback.
bufferinternal buffer to use while dispatching bytes. If NULL, buffer is allocated internally using buffer_size.
buffer_sizeinternal buffer size used while dispatching bytes. If 0, defaults to 40k.
Returns
new bitstream object

◆ gf_bs_prevent_dispatch()

void gf_bs_prevent_dispatch ( GF_BitStream bs,
Bool  prevent_dispatch 
)
Warning
Block dispatch prevention acts in a counter mode: you must call as many time the function with prevent_dispatch = GF_FALSE as you called the function with prevent_dispatch = GF_TRUE
Parameters
bsthe target bitstream
prevent_dispatchactivates temporary internal storage if set

◆ gf_bs_read_int()

u32 gf_bs_read_int ( GF_BitStream bs,
u32  nBits 
)

Reads an integer coded on a number of bit.

Parameters
bsthe target bitstream
nBitsthe number of bits to read
Returns
the integer value read.

◆ gf_bs_read_long_int()

u64 gf_bs_read_long_int ( GF_BitStream bs,
u32  nBits 
)

Reads a large integer coded on a number of bit bigger than 32.

Parameters
bsthe target bitstream
nBitsthe number of bits to read
Returns
the large integer value read.

◆ gf_bs_read_float()

Float gf_bs_read_float ( GF_BitStream bs)

Reads a float coded as IEEE 32 bit format.

Parameters
bsthe target bitstream
Returns
the float value read.

◆ gf_bs_read_double()

Double gf_bs_read_double ( GF_BitStream bs)

Reads a double coded as IEEE 64 bit format.

Parameters
bsthe target bitstream
Returns
the double value read.

◆ gf_bs_read_data()

u32 gf_bs_read_data ( GF_BitStream bs,
u8 data,
u32  nbBytes 
)

Reads a data buffer. Emultation prevention byte removal is NOT applied here

Parameters
bsthe target bitstream
datathe data buffer to be filled
nbBytesthe amount of bytes to read
Returns
the number of bytes actually read.
Warning
the data buffer passed must be large enough to hold the desired amount of bytes.

◆ gf_bs_read_u8()

u32 gf_bs_read_u8 ( GF_BitStream bs)

Reads an integer coded on 8 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
Returns
the char value read.

◆ gf_bs_read_u16()

u32 gf_bs_read_u16 ( GF_BitStream bs)

Reads an integer coded on 16 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
Returns
the short value read.

◆ gf_bs_read_u24()

u32 gf_bs_read_u24 ( GF_BitStream bs)

Reads an integer coded on 24 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_read_u32()

u32 gf_bs_read_u32 ( GF_BitStream bs)

Reads an integer coded on 32 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_read_u64()

u64 gf_bs_read_u64 ( GF_BitStream bs)

Reads an integer coded on 64 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
Returns
the large integer value read.

◆ gf_bs_read_u64_le()

u64 gf_bs_read_u64_le ( GF_BitStream bs)

Reads an integer coded on 64 bits in little-endian order.

Parameters
bsthe target bitstream
Returns
the large integer value read.

◆ gf_bs_read_u32_le()

u32 gf_bs_read_u32_le ( GF_BitStream bs)

Reads an integer coded on 32 bits in little-endian order.

Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_read_u16_le()

u16 gf_bs_read_u16_le ( GF_BitStream bs)

Reads an integer coded on 16 bits in little-endian order.

Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_read_vluimsbf5()

u32 gf_bs_read_vluimsbf5 ( GF_BitStream bs)

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.

Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_get_bit_offset()

u32 gf_bs_get_bit_offset ( GF_BitStream bs)

Returns current bit position in the bitstream - only works in memory mode.

Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_get_bit_position()

u32 gf_bs_get_bit_position ( GF_BitStream bs)

Returns bit position in the current byte of the bitstream - only works in memory mode.

Parameters
bsthe target bitstream
Returns
the integer value read.

◆ gf_bs_write_int()

void gf_bs_write_int ( GF_BitStream bs,
s32  value,
s32  nBits 
)

Writes an integer on a given number of bits.

Parameters
bsthe target bitstream
valuethe integer to write
nBitsnumber of bits used to code the integer

◆ gf_bs_write_long_int()

void gf_bs_write_long_int ( GF_BitStream bs,
s64  value,
s32  nBits 
)

Writes an integer on a given number of bits greater than 32.

Parameters
bsthe target bitstream
valuethe large integer to write
nBitsnumber of bits used to code the integer

◆ gf_bs_write_float()

void gf_bs_write_float ( GF_BitStream bs,
Float  value 
)

Writes a float in IEEE 32 bits format.

Parameters
bsthe target bitstream
valuethe float to write

◆ gf_bs_write_double()

void gf_bs_write_double ( GF_BitStream bs,
Double  value 
)

Writes a double in IEEE 64 bits format.

Parameters
bsthe target bitstream
valuethe double to write

◆ gf_bs_write_data()

u32 gf_bs_write_data ( GF_BitStream bs,
const u8 data,
u32  nbBytes 
)

Writes a data buffer.

Parameters
bsthe target bitstream
datathe data to write
nbBytesnumber of data bytes to write
Returns
the number of written bytes

◆ gf_bs_write_u8()

void gf_bs_write_u8 ( GF_BitStream bs,
u32  value 
)

Writes an integer on 8 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
valuethe char value to write

◆ gf_bs_write_u16()

void gf_bs_write_u16 ( GF_BitStream bs,
u32  value 
)

Writes an integer on 16 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
valuethe short value to write

◆ gf_bs_write_u24()

void gf_bs_write_u24 ( GF_BitStream bs,
u32  value 
)

Writes an integer on 24 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
valuethe integer value to write

◆ gf_bs_write_u32()

void gf_bs_write_u32 ( GF_BitStream bs,
u32  value 
)

Writes an integer on 32 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
valuethe integer value to write

◆ gf_bs_write_u64()

void gf_bs_write_u64 ( GF_BitStream bs,
u64  value 
)

Writes an integer on 64 bits starting at a byte boundary in the bitstream.

Warning
you must not use this function if the bitstream is not aligned
Parameters
bsthe target bitstream
valuethe large integer value to write

◆ gf_bs_write_u32_le()

void gf_bs_write_u32_le ( GF_BitStream bs,
u32  value 
)

Writes an integer on 32 bits in little-endian order.

Parameters
bsthe target bitstream
valuethe integer value to write

◆ gf_bs_write_u64_le()

void gf_bs_write_u64_le ( GF_BitStream bs,
u64  value 
)

Writes an integer on 64 bits in little-endian order.

Parameters
bsthe target bitstream
valuethe integer value to write

◆ gf_bs_write_u16_le()

void gf_bs_write_u16_le ( GF_BitStream bs,
u32  value 
)

Writes an integer on 16 bits in little-endian order.

Parameters
bsthe target bitstream
valuethe short value to write

◆ gf_bs_write_byte()

u32 gf_bs_write_byte ( GF_BitStream bs,
u8  byte,
u32  count 
)

Writes a give byte multiple times.

Parameters
bsthe target bitstream
bytethe byte value to write
countthe number of times the byte should be written
Returns
the number of bytes written

◆ gf_bs_set_eos_callback()

void gf_bs_set_eos_callback ( GF_BitStream bs,
void(*)(void *par)  EndOfStream,
void *  par 
)

Assigns a notification callback function for end of stream signaling in read mode

Parameters
bsthe target bitstream
EndOfStreamthe notification function to use
paropaque user data passed to the bitstream

◆ gf_bs_is_align()

Bool gf_bs_is_align ( GF_BitStream bs)

Checks if bitstream position is aligned to a byte boundary.

Parameters
bsthe target bitstream
Returns
GF_TRUE if aligned with regard to the read/write mode, GF_FALSE otherwise

◆ gf_bs_align()

u8 gf_bs_align ( GF_BitStream bs)

Aligns bitstream to next byte boundary. In write mode, this will write 0 bit values until alignment.

Parameters
bsthe target bitstream
Returns
the number of bits read/written until alignment

◆ gf_bs_available()

u64 gf_bs_available ( GF_BitStream bs)

Returns the number of bytes still available in the bitstream in read mode.

Parameters
bsthe target bitstream
Returns
the number of bytes still available in read mode, -1 in write modes.

◆ gf_bs_get_content()

void gf_bs_get_content ( GF_BitStream bs,
u8 **  output,
u32 outSize 
)

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.

Parameters
bsthe target bitstream
outputaddress of the memory block allocated by the bitstream.
outSizesize of the allocated memory block.
Note
  • It is the user responsibility to destroy the allocated buffer
  • Once this function has been called, the internal bitstream buffer is reseted.

◆ gf_bs_get_content_no_truncate()

void gf_bs_get_content_no_truncate ( GF_BitStream bs,
u8 **  output,
u32 outSize,
u32 allocSize 
)

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

Parameters
bsthe target bitstream
outputaddress of the memory block allocated by the bitstream.
outSizenumber of bytes written in the allocated memory block.
allocSizesize of the allocated memory block.
Note
  • It is the user responsibility to destroy the allocated buffer
  • Once this function has been called, the internal bitstream buffer is reseted.

◆ gf_bs_skip_bytes()

void gf_bs_skip_bytes ( GF_BitStream bs,
u64  nbBytes 
)

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

Parameters
bsthe target bitstream
nbBytesthe number of bytes to skip

◆ gf_bs_seek()

GF_Err gf_bs_seek ( GF_BitStream bs,
u64  offset 
)

Seeks the bitstream to a given offset after the beginning of the stream. This will perform alignment of the bitstream in all modes.

Warning
Results are unpredictable if seeking beyond the bitstream end is performed.
Parameters
bsthe target bitstream
offsetbuffer/file offset to seek to
Returns
error if any

◆ gf_bs_truncate()

void gf_bs_truncate ( GF_BitStream bs)

Truncates the bitstream at the current position

Parameters
bsthe target bitstream

◆ gf_bs_peek_bits()

u32 gf_bs_peek_bits ( GF_BitStream bs,
u32  numBits,
u64  byte_offset 
)

Peeks a given number of bits (read without moving the position indicator) for read modes only.

Parameters
bsthe target bitstream
numBitsthe number of bits to peek
byte_offsetif 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
Returns
the integer value read

◆ gf_bs_bits_available()

u8 gf_bs_bits_available ( GF_BitStream bs)

Queries the number of bits available in read mode.

Parameters
bsthe target bitstream
Returns
number of available bits if position is in the last byte of the buffer/stream, 8 otherwise

◆ gf_bs_get_position()

u64 gf_bs_get_position ( GF_BitStream bs)

Returns the reading/writting position in the buffer/file.

Parameters
bsthe target bitstream
Returns
the read/write position of the bitstream

◆ gf_bs_get_size()

u64 gf_bs_get_size ( GF_BitStream bs)

Returns the size of the associated buffer/file.

Parameters
bsthe target bitstream
Returns
the size of the bitstream

◆ gf_bs_get_refreshed_size()

u64 gf_bs_get_refreshed_size ( GF_BitStream bs)

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?

Parameters
bsthe target bitstream
Returns
the disk size of the associated file

◆ gf_bs_transfer()

GF_Err gf_bs_transfer ( GF_BitStream dst,
GF_BitStream src,
Bool  keep_src 
)
Parameters
dstthe target bitstream
srcthe source bitstream.
keep_srcIf not set, the source bitstream is empty after calling the function
Returns
error if any

◆ gf_bs_flush()

void gf_bs_flush ( GF_BitStream bs)

Flushes bitstream contet to disk

Parameters
bsthe target bitstream

◆ gf_bs_enable_emulation_byte_removal()

void gf_bs_enable_emulation_byte_removal ( GF_BitStream bs,
Bool  do_remove 
)

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

Parameters
bsthe target bitstream
do_removeif true, emulation prevention bytes will be removed

◆ gf_bs_get_emulation_byte_removed()

u32 gf_bs_get_emulation_byte_removed ( GF_BitStream bs)

Enables or disable emulation byte prevention for NALU-based annex B formats in read mode.

Parameters
bsthe target bitstream
Returns
number of bytes currently removed

◆ gf_bs_insert_data()

GF_Err gf_bs_insert_data ( GF_BitStream bs,
u8 data,
u32  size,
u64  offset 
)

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.

Parameters
bsthe target bitstream
datablock to insert
sizesize of the block to insert
offsetinsertion offset from bitstream start
Returns
error code if any

◆ gf_bs_set_cookie()

u64 gf_bs_set_cookie ( GF_BitStream bs,
u64  cookie 
)

Sets a 64 bit cookie (integer, pointer) on the bitstream, returning the current cookie value

Parameters
bsthe target bitstream
cookiethe new cookie to assign
Returns
the cookie value before re-assign

◆ gf_bs_get_cookie()

u64 gf_bs_get_cookie ( GF_BitStream bs)

Gets the current cookie on the bitstream

Parameters
bsthe target bitstream
Returns
the current cookie value

◆ gf_bs_read_utf8()

char* gf_bs_read_utf8 ( GF_BitStream bs)

reads utf-8 NULL-terminated string - bitstream must be aligned

Parameters
bsthe target bitstream
Returns
the string read or NULL if error - MUST be freed by user

◆ gf_bs_write_utf8()

GF_Err gf_bs_write_utf8 ( GF_BitStream bs,
const char *  str 
)

Writes utf-8 NULL-terminated string - bitstream must be aligned

Parameters
bsthe target bitstream
strUTF-8 string to write
Returns
error if any

◆ gf_bs_mark_overflow()

void gf_bs_mark_overflow ( GF_BitStream bs,
Bool  reset 
)

Marks the bitstream as overflown (reading outside of buffer range). Marking is done automatically when reading but can be forced using this function.

Parameters
bsthe target bitstream
resetif GF_TRUE, reset overflown state, otherwise mark as overflown

◆ gf_bs_is_overflow()

u32 gf_bs_is_overflow ( GF_BitStream bs)

Gets overflow state of the bitstream

Parameters
bsthe target bitstream
Returns
2 if an overflow was marked by user using gf_bs_mark_overflow, 1 if an overflow occured, 0 otherwise