GstBitWriter: GStreamer 1.0 Library Reference Manual

## GstBitWriter GstBitWriter — Writes any number of bits into a memory buffer |

## Functions

GstBitWriter * | gst_bit_writer_new ()
GstBitWriter * | gst_bit_writer_new_with_size ()
GstBitWriter * | gst_bit_writer_new_with_data ()
void | gst_bit_writer_free ()
GstBuffer * | gst_bit_writer_free_and_get_buffer ()
guint8 * | gst_bit_writer_free_and_get_data ()
void | gst_bit_writer_init ()
void | gst_bit_writer_init_with_size ()
void | gst_bit_writer_init_with_data ()
void | gst_bit_writer_reset ()
GstBuffer * | gst_bit_writer_reset_and_get_buffer ()
guint8 * | gst_bit_writer_reset_and_get_data ()
gboolean | gst_bit_writer_set_pos ()
guint | gst_bit_writer_get_size ()
guint8 * | gst_bit_writer_get_data ()
guint | gst_bit_writer_get_remaining ()
guint | gst_bit_writer_get_size_unchecked ()
guint8 * | gst_bit_writer_get_data_unchecked ()
gboolean | gst_bit_writer_set_pos_unchecked ()
guint | gst_bit_writer_get_remaining_unchecked ()
gboolean | gst_bit_writer_put_bits_uint16 ()
gboolean | gst_bit_writer_put_bits_uint32 ()
gboolean | gst_bit_writer_put_bits_uint64 ()
gboolean | gst_bit_writer_put_bits_uint8 ()
gboolean | gst_bit_writer_put_bytes ()
void | gst_bit_writer_put_bits_uint16_unchecked ()
void | gst_bit_writer_put_bits_uint32_unchecked ()
void | gst_bit_writer_put_bits_uint64_unchecked ()
void | gst_bit_writer_put_bits_uint8_unchecked ()
void | gst_bit_writer_put_bytes_unchecked ()
gboolean | gst_bit_writer_align_bytes ()
void | gst_bit_writer_align_bytes_unchecked ()

## Types and Values

struct | GstBitWriter

## Includes

    #include <gst/base/base.h>

## Description

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.

## Functions

### gst_bit_writer_new ()

    GstBitWriter *
    gst_bit_writer_new (void);

Creates a new, empty GstBitWriter instance.

Free-function: gst_bit_writer_free

[skip]

#### Returns

a new, empty GstByteWriter instance.

[transfer full]

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

[skip]

#### Parameters

size | Initial size of data in bytes |
fixed | If `TRUE` the data can't be reallocated |

#### Returns

a new GstBitWriter instance.

[transfer full]

### 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 beginnig.

Free-function: gst_bit_writer_free

[skip]

#### Parameters

data | Memory area for writing |
size | Size of `data` in bytes |
initialized | if `TRUE` the complete data can be read from the beginning |

#### Returns

a new GstBitWriter instance.

[transfer full]

### gst_bit_writer_free ()

    void
    gst_bit_writer_free (GstBitWriter *bitwriter);

Frees `bitwriter` and the allocated data inside.

#### Parameters

bitwriter | GstBitWriter instance. | [in][transfer full]

### 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 | GstBitWriter instance. | [in][transfer full]

#### Returns

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

[transfer full]

### 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 | GstBitWriter instance. | [in][transfer full]

#### Returns

the current data. `g_free()` after usage.

[array][transfer full]

### gst_bit_writer_init ()

    void
    gst_bit_writer_init (GstBitWriter *bitwriter);

Initializes `bitwriter` to an empty instance.

[skip]

#### Parameters

bitwriter | GstBitWriter instance |

### gst_bit_writer_init_with_size ()

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

Initializes a GstBitWriter instance and allocates the given data `size` .

[skip]

#### 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_init_with_data ()

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

[skip]

#### Parameters

bitwriter | GstBitWriter instance |
data | Memory area for writing. | [array length=size][transfer none]
size | Size of `data` in bytes |
initialized | If `TRUE` the complete data can be read from the beginning |

### gst_bit_writer_reset ()

    void
    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

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

[transfer full]

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

the current data. `g_free()` after usage.

[array][transfer full]

### gst_bit_writer_set_pos ()

    gboolean
    gst_bit_writer_set_pos (GstBitWriter *bitwriter,
                            guint pos);

### 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_get_data ()

    guint8 *
    gst_bit_writer_get_data (const GstBitWriter *bitwriter);

Get written data pointer

#### Parameters

bitwriter | a GstBitWriter instance |

#### Returns

data pointer

### gst_bit_writer_get_remaining ()

    guint
    gst_bit_writer_get_remaining (const GstBitWriter *bitwriter);

### gst_bit_writer_get_size_unchecked ()

    guint
    gst_bit_writer_get_size_unchecked (const GstBitWriter *bitwriter);

### gst_bit_writer_get_data_unchecked ()

    guint8 *
    gst_bit_writer_get_data_unchecked (const GstBitWriter *bitwriter);

### gst_bit_writer_set_pos_unchecked ()

    gboolean
    gst_bit_writer_set_pos_unchecked (GstBitWriter *bitwriter,
                                      guint pos);

### gst_bit_writer_get_remaining_unchecked ()

    guint
    gst_bit_writer_get_remaining_unchecked
                                   (const GstBitWriter *bitwriter);

### 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 | pointer of data to write |
nbytes | number of bytes to write |

#### Returns

`TRUE` if successful, `FALSE` otherwise.

### gst_bit_writer_put_bits_uint16_unchecked ()

    void
    gst_bit_writer_put_bits_uint16_unchecked
                                   (GstBitWriter *bitwriter,
                                    guint16 value,
                                    guint nbits);

Write `nbits` bits of `value` to GstBitWriter without checking whether there is enough space

#### Parameters

bitwriter | a GstBitWriter instance |
value | value of guint16 to write |
nbits | number of bits to write |

### gst_bit_writer_put_bits_uint32_unchecked ()

    void
    gst_bit_writer_put_bits_uint32_unchecked
                                   (GstBitWriter *bitwriter,
                                    guint32 value,
                                    guint nbits);

Write `nbits` bits of `value` to GstBitWriter without checking whether there is enough space

#### Parameters

bitwriter | a GstBitWriter instance |
value | value of guint32 to write |
nbits | number of bits to write |

### gst_bit_writer_put_bits_uint64_unchecked ()

    void
    gst_bit_writer_put_bits_uint64_unchecked
                                   (GstBitWriter *bitwriter,
                                    guint64 value,
                                    guint nbits);

Write `nbits` bits of `value` to GstBitWriter without checking whether there is enough space

#### Parameters

bitwriter | a GstBitWriter instance |
value | value of guint64 to write |
nbits | number of bits to write |

### gst_bit_writer_put_bits_uint8_unchecked ()

    void
    gst_bit_writer_put_bits_uint8_unchecked
                                   (GstBitWriter *bitwriter,
                                    guint8 value,
                                    guint nbits);

Write `nbits` bits of `value` to GstBitWriter without checking whether there is enough space

#### Parameters

bitwriter | a GstBitWriter instance |
value | value of guint8 to write |
nbits | number of bits to write |

### gst_bit_writer_put_bytes_unchecked ()

    void
    gst_bit_writer_put_bytes_unchecked (GstBitWriter *bitwriter,
                                        const guint8 *data,
                                        guint nbytes);

Write `nbytes` bytes of `data` to GstBitWriter without checking whether there is enough space

#### Parameters

bitwriter | a GstBitWriter instance |
data | pointer of data to write |
nbytes | number of bytes to write |

### 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_align_bytes_unchecked ()

    void
    gst_bit_writer_align_bytes_unchecked (GstBitWriter *bitwriter,
                                          guint8 trailing_bit);

Write trailing bit to align last byte of `data` without checking whether there is enough space

#### Parameters

bitwriter | a GstBitWriter instance |
trailing_bit | trailing bits of last byte, 0 or 1 |

## Types and Values

### struct GstBitWriter

    struct GstBitWriter {
      guint8 *data;
      guint bit_size;
    };

A bit writer instance.

#### Members

guint8 *`data`; | Allocated `data` for bit writer to write |
guint `bit_size`; | Size of written `data` in bits |