GstBitWriter

GstBitWriter provides a bit writer that can write any number of bits into a memory buffer. It provides functions for writing any number of bits into 8, 16, 32 and 64 bit variables.

GstBitWriter

A bit writer instance.

Members

data (guint8 *) –

Allocated data for bit writer to write

bit_size (guint) –

Size of written data in bits

Since : 1.16


Methods

gst_bit_writer_align_bytes

gboolean
gst_bit_writer_align_bytes (GstBitWriter * bitwriter,
                            guint8 trailing_bit)

Write trailing bit to align last byte of data. trailing_bit can only be 1 or 0.

Parameters:

bitwriter

a GstBitWriter instance

trailing_bit

trailing bits of last byte, 0 or 1

Returns

TRUE if successful, FALSE otherwise.


gst_bit_writer_free

gst_bit_writer_free (GstBitWriter * bitwriter)

Frees bitwriter and the allocated data inside.

Parameters:

bitwriter ( [in][transfer: full])

GstBitWriter instance


gst_bit_writer_free_and_get_buffer

GstBuffer *
gst_bit_writer_free_and_get_buffer (GstBitWriter * bitwriter)

Frees bitwriter without destroying the internal data, which is returned as GstBuffer.

Free-function: gst_buffer_unref

Parameters:

bitwriter ( [in][transfer: full])

GstBitWriter instance

Returns ( [transfer: full])

a new allocated GstBuffer wrapping the data inside. gst_buffer_unref after usage.


gst_bit_writer_free_and_get_data

guint8 *
gst_bit_writer_free_and_get_data (GstBitWriter * bitwriter)

Frees bitwriter without destroying the internal data, which is returned.

Free-function: g_free

Parameters:

bitwriter ( [in][transfer: full])

GstBitWriter instance

Returns ( [array][transfer: full])

the current data. g_free after usage.


gst_bit_writer_get_data

guint8 *
gst_bit_writer_get_data (const GstBitWriter * bitwriter)

Get written data pointer

Parameters:

bitwriter

a GstBitWriter instance

Returns ( [array][transfer: none])

data pointer


gst_bit_writer_get_remaining

guint
gst_bit_writer_get_remaining (const GstBitWriter * bitwriter)

Parameters:

bitwriter
No description available
Returns
No description available

gst_bit_writer_get_size

guint
gst_bit_writer_get_size (const GstBitWriter * bitwriter)

Get size of written data

Parameters:

bitwriter

a GstBitWriter instance

Returns

size of bits written in data


gst_bit_writer_init

gst_bit_writer_init (GstBitWriter * bitwriter)

Initializes bitwriter to an empty instance.

Parameters:

bitwriter

GstBitWriter instance


gst_bit_writer_init_with_data

gst_bit_writer_init_with_data (GstBitWriter * bitwriter,
                               guint8 * data,
                               guint size,
                               gboolean initialized)

Initializes bitwriter with the given memory area data. IF initialized is TRUE it is possible to read size bits from the GstBitWriter from the beginning.

Parameters:

bitwriter

GstBitWriter instance

data ( [arraylength=size][transfer: none])

Memory area for writing

size

Size of data in bytes

initialized

If TRUE the complete data can be read from the beginning


gst_bit_writer_init_with_size

gst_bit_writer_init_with_size (GstBitWriter * bitwriter,
                               guint32 size,
                               gboolean fixed)

Initializes a GstBitWriter instance and allocates the given data size.

Parameters:

bitwriter

GstBitWriter instance

size

the size on bytes to allocate for data

fixed

If TRUE the data can't be reallocated


gst_bit_writer_put_bits_uint16

gboolean
gst_bit_writer_put_bits_uint16 (GstBitWriter * bitwriter,
                                guint16 value,
                                guint nbits)

Write nbits bits of value to GstBitWriter.

Parameters:

bitwriter

a GstBitWriter instance

value

value of guint16 to write

nbits

number of bits to write

Returns

TRUE if successful, FALSE otherwise.


gst_bit_writer_put_bits_uint32

gboolean
gst_bit_writer_put_bits_uint32 (GstBitWriter * bitwriter,
                                guint32 value,
                                guint nbits)

Write nbits bits of value to GstBitWriter.

Parameters:

bitwriter

a GstBitWriter instance

value

value of guint32 to write

nbits

number of bits to write

Returns

TRUE if successful, FALSE otherwise.


gst_bit_writer_put_bits_uint64

gboolean
gst_bit_writer_put_bits_uint64 (GstBitWriter * bitwriter,
                                guint64 value,
                                guint nbits)

Write nbits bits of value to GstBitWriter.

Parameters:

bitwriter

a GstBitWriter instance

value

value of guint64 to write

nbits

number of bits to write

Returns

TRUE if successful, FALSE otherwise.


gst_bit_writer_put_bits_uint8

gboolean
gst_bit_writer_put_bits_uint8 (GstBitWriter * bitwriter,
                               guint8 value,
                               guint nbits)

Write nbits bits of value to GstBitWriter.

Parameters:

bitwriter

a GstBitWriter instance

value

value of guint8 to write

nbits

number of bits to write

Returns

TRUE if successful, FALSE otherwise.


gst_bit_writer_put_bytes

gboolean
gst_bit_writer_put_bytes (GstBitWriter * bitwriter,
                          const guint8 * data,
                          guint nbytes)

Write nbytes bytes of data to GstBitWriter.

Parameters:

bitwriter

a GstBitWriter instance

data ( [array])

pointer of data to write

nbytes

number of bytes to write

Returns

TRUE if successful, FALSE otherwise.


gst_bit_writer_reset

gst_bit_writer_reset (GstBitWriter * bitwriter)

Resets bitwriter and frees the data if it's owned by bitwriter.

Parameters:

bitwriter

GstBitWriter instance


gst_bit_writer_reset_and_get_buffer

GstBuffer *
gst_bit_writer_reset_and_get_buffer (GstBitWriter * bitwriter)

Resets bitwriter and returns the current data as GstBuffer.

Free-function: gst_buffer_unref

Parameters:

bitwriter

a GstBitWriter instance

Returns ( [transfer: full])

a new allocated GstBuffer wrapping the current data. gst_buffer_unref after usage.


gst_bit_writer_reset_and_get_data

guint8 *
gst_bit_writer_reset_and_get_data (GstBitWriter * bitwriter)

Resets bitwriter and returns the current data.

Free-function: g_free

Parameters:

bitwriter

a GstBitWriter instance

Returns ( [array][transfer: full])

the current data. g_free after usage.


gst_bit_writer_set_pos

gboolean
gst_bit_writer_set_pos (GstBitWriter * bitwriter,
                        guint pos)

Parameters:

bitwriter
No description available
pos
No description available
Returns
No description available

Functions

gst_bit_writer_new

GstBitWriter *
gst_bit_writer_new ()

Creates a new, empty GstBitWriter instance.

Free-function: gst_bit_writer_free

Returns ( [transfer: full])

a new, empty GstByteWriter instance


gst_bit_writer_new_with_data

GstBitWriter *
gst_bit_writer_new_with_data (guint8 * data,
                              guint size,
                              gboolean initialized)

Creates a new GstBitWriter instance with the given memory area. If initialized is TRUE it is possible to read size bits from the GstBitWriter from the beginning.

Free-function: gst_bit_writer_free

Parameters:

data ( [arraylength=size][transfer: none])

Memory area for writing

size

Size of data in bytes

initialized

if TRUE the complete data can be read from the beginning

Returns ( [transfer: full])

a new GstBitWriter instance


gst_bit_writer_new_with_size

GstBitWriter *
gst_bit_writer_new_with_size (guint32 size,
                              gboolean fixed)

Creates a GstBitWriter instance with the given initial data size.

Free-function: gst_bit_writer_free

Parameters:

size

Initial size of data in bytes

fixed

If TRUE the data can't be reallocated

Returns ( [transfer: full])

a new GstBitWriter instance


Function Macros

GST_BIT_WRITER_BIT_SIZE

#define GST_BIT_WRITER_BIT_SIZE(writer) ((writer)->bit_size)

GST_BIT_WRITER_DATA

#define GST_BIT_WRITER_DATA(writer)     ((writer)->data)

__GST_BITS_WRITER_ALIGNED

#define __GST_BITS_WRITER_ALIGNED(bitsize)                   \
    (((bitsize) + __GST_BITS_WRITER_ALIGNMENT_MASK)&(~__GST_BITS_WRITER_ALIGNMENT_MASK))

__GST_BIT_WRITER_WRITE_BITS_INLINE

#define __GST_BIT_WRITER_WRITE_BITS_INLINE(bits) \
static inline gboolean \
_gst_bit_writer_put_bits_uint##bits##_inline( \
    GstBitWriter *bitwriter, \
    guint##bits value, \
    guint nbits \
) \
{ \
    g_return_val_if_fail(bitwriter != NULL, FALSE); \
    g_return_val_if_fail(nbits != 0, FALSE); \
    g_return_val_if_fail(nbits <= bits, FALSE); \
    \
    if (!_gst_bit_writer_check_remaining(bitwriter, nbits)) \
        return FALSE; \
    gst_bit_writer_put_bits_uint##bits##_unchecked(bitwriter, value, nbits); \
    return TRUE; \
}

__GST_BIT_WRITER_WRITE_BITS_UNCHECKED

#define __GST_BIT_WRITER_WRITE_BITS_UNCHECKED(bits) \
static inline void \
gst_bit_writer_put_bits_uint##bits##_unchecked( \
    GstBitWriter *bitwriter, \
    guint##bits value, \
    guint nbits \
) \
{ \
    guint byte_pos, bit_offset; \
    guint8  *cur_byte; \
    guint fill_bits; \
    \
    byte_pos = (bitwriter->bit_size >> 3); \
    bit_offset = (bitwriter->bit_size & 0x07); \
    cur_byte = bitwriter->data + byte_pos; \
    g_assert (nbits <= bits); \
    g_assert( bit_offset < 8 && \
            bitwriter->bit_size <= bitwriter->bit_capacity); \
    \
    while (nbits) { \
        fill_bits = ((8 - bit_offset) < nbits ? (8 - bit_offset) : nbits); \
        nbits -= fill_bits; \
        bitwriter->bit_size += fill_bits; \
        \
        *cur_byte |= (((value >> nbits) & _gst_bit_writer_bit_filling_mask[fill_bits]) \
                      << (8 - bit_offset - fill_bits)); \
        ++cur_byte; \
        bit_offset = 0; \
    } \
    g_assert(cur_byte <= \
           (bitwriter->data + (bitwriter->bit_capacity >> 3))); \
}

Constants

__GST_BITS_WRITER_ALIGNMENT_MASK

#define __GST_BITS_WRITER_ALIGNMENT_MASK 2047

The results of the search are