GPAC
Open Source Multimedia Framework. For more information, check out http://gpac.wp.mines-telecom.fr
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups
bitstream

BitStream object. More...

+ Collaboration diagram for bitstream:

Enumerations

enum  { GF_BITSTREAM_READ = 0, GF_BITSTREAM_WRITE }
 

Functions

GF_BitStream * gf_bs_new (const char *buffer, u64 size, u32 mode)
 bitstream constructor 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 constructor from file handle More...
 
GF_Err gf_bs_set_output_buffering (GF_BitStream *bs, u32 size)
 sets bitstream write cache size More...
 
u32 gf_bs_get_output_buffering (GF_BitStream *bs)
 gets bitstream write cache size 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, char *data, u32 nbBytes)
 data reading More...
 
u32 gf_bs_read_u8 (GF_BitStream *bs)
 align char reading More...
 
u32 gf_bs_read_u8_until_delimiter (GF_BitStream *bs, u8 delimiter, u8 *out, u32 max_length)
 align char reading until reaching the given value 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...
 
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 char *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_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...
 
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, char **output, u32 *outSize)
 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, u32 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)
 transfer content from source bitstream to destination bitstream More...
 
void gf_bs_flush (GF_BitStream *bs)
 Flushes bitstream contet to disk. More...
 
void gf_bs_reassign (GF_BitStream *bs, FILE *stream)
 Reassigns FILE object for stream-based bitstreams. 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.

Enumeration Type Documentation

anonymous enum
Enumerator
GF_BITSTREAM_READ 
GF_BITSTREAM_WRITE 

Function Documentation

GF_BitStream* gf_bs_new ( const char *  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 responsability to ensure it does not write more than possible.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

GF_Err gf_bs_set_output_buffering ( GF_BitStream *  bs,
u32  size 
)

Sets the write cache size for file-based bitstreams.

Parameters
bsthe target bitstream
sizesize of the write cache in bytes
Returns
error if any.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 gf_bs_get_output_buffering ( GF_BitStream *  bs)

Gets the write cache size for file-based bitstreams.

Parameters
bsthe target bitstream
Returns
size of the write cache in bytes, 0 if no cache

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 gf_bs_read_data ( GF_BitStream *  bs,
char *  data,
u32  nbBytes 
)

Reads a data buffer

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.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

u32 gf_bs_read_u8_until_delimiter ( GF_BitStream *  bs,
u8  delimiter,
u8 out,
u32  max_length 
)
Reads an integer coded on 8 bits starting at a byte boundary in the bitstream until

the given appears on the bitstream.

Note
the bytes read in the bitstream will only be update if the delimiter is found
Parameters
bsthe target bitstream
delimiterthe stop condition
outthe resulting value
max_lengththe maximum length of the output
Returns
the number of value read.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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 begining.

Parameters
bsthe target bitstream
Returns
the integer value read.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

+ Here is the caller graph for this function:

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.

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

u32 gf_bs_write_data ( GF_BitStream *  bs,
const char *  data,
u32  nbBytes 
)

Writes a data buffer.

Parameters
bsthe target bitstream
datathe data to write
nbBytesnumber of data bytes to write

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

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.

+ Here is the call graph for this function:

void gf_bs_get_content ( GF_BitStream *  bs,
char **  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 a memory block to be allocated for bitstream data.
outSizeset to the size of the allocated memory block.
Note
It is the user responsability to destroy the allocated buffer Once this function has been called, the internal bitstream buffer is reseted.

+ Here is the call graph for this function:

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.

Parameters
bsthe target bitstream
nbBytesthe number of bytes to skip

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GF_Err gf_bs_seek ( GF_BitStream *  bs,
u64  offset 
)

Seeks the bitstream to a given offset after the begining 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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gf_bs_truncate ( GF_BitStream *  bs)

Truncates the bitstream at the current position

Parameters
bsthe target bitstream

+ Here is the caller graph for this function:

u32 gf_bs_peek_bits ( GF_BitStream *  bs,
u32  numBits,
u32  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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

+ Here is the caller graph for this function:

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
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

+ Here is the caller graph for this function:

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

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

GF_Err gf_bs_transfer ( GF_BitStream *  dst,
GF_BitStream *  src 
)

Returns the size of the associated buffer/file.

Parameters
dstthe target bitstream
srcthe source bitstream. This bitstream is empty after calling teh function
Returns
error if any

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gf_bs_flush ( GF_BitStream *  bs)

Flushes bitstream contet to disk

Parameters
bsthe target bitstream

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void gf_bs_reassign ( GF_BitStream *  bs,
FILE *  stream 
)

Reassigns FILE object for stream-based bitstreams. Automatically sets the stream position to the bitstream position

Parameters
bsthe target bitstream
streamthe new stream to assign

+ Here is the call graph for this function:

+ Here is the caller graph for this function: