Package org.freedesktop.gstreamer.base
Class BitWriter
java.lang.Object
org.javagi.base.ProxyInstance
org.freedesktop.gstreamer.base.BitWriter
- All Implemented Interfaces:
Proxy
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.- Since:
- 1.16
-
Constructor Summary
ConstructorsConstructorDescriptionAllocate a new BitWriter.Allocate a new BitWriter.BitWriter(MemorySegment address) Create a BitWriter proxy instance for the provided memory address.BitWriter(MemorySegment data, int bitSize, int bitCapacity, boolean autoGrow, boolean owned) Allocate a new BitWriter with the fields set to the provided values.BitWriter(MemorySegment data, int bitSize, int bitCapacity, boolean autoGrow, boolean owned, Arena arena) Allocate a new BitWriter with the fields set to the provided values. -
Method Summary
Modifier and TypeMethodDescriptionbooleanalignBytes(byte trailingBit) Write trailing bit to align last byte ofdata.trailingBitcan only be 1 or 0.voidfree()Frees this BitWriter and the allocated data inside.Frees this BitWriter without destroying the internal data, which is returned asGstBuffer.byte[]Frees this BitWriter without destroying the internal data, which is returned.byte[]getData()Get written data pointerstatic MemoryLayoutThe memory layout of the native struct.intintgetSize()Get size of writtendatavoidinit()Initializes this BitWriter to an empty instance.voidinitWithData(@org.jspecify.annotations.Nullable byte @Nullable [] data, boolean initialized) Initializes this BitWriter with the given memory areadata.IFinitializedistrueit is possible to readsizebits from theGstBitWriterfrom the beginning.voidinitWithSize(int size, boolean fixed) Initializes aGstBitWriterinstance and allocates the given datasize.static BitWriternew_()Creates a new, emptyGstBitWriterinstance.static BitWriternewWithData(@org.jspecify.annotations.Nullable byte @Nullable [] data, boolean initialized) Creates a newGstBitWriterinstance with the given memory area.static BitWriternewWithSize(int size, boolean fixed) Creates aGstBitWriterinstance with the given initial data size.booleanputBitsUint16(short value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.booleanputBitsUint32(int value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.booleanputBitsUint64(long value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.booleanputBitsUint8(byte value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.booleanputBytes(@org.jspecify.annotations.Nullable byte @Nullable [] data, int nbytes) Writenbytesbytes ofdatatoGstBitWriter.booleanRead the value of the fieldauto_grow.intRead the value of the fieldbit_capacity.intRead the value of the fieldbit_size.readData()Read the value of the fielddata.booleanRead the value of the fieldowned.voidreset()Resets this BitWriter and frees the data if it's owned bybitwriter.Resets this BitWriter and returns the current data asGstBuffer.byte[]Resets this BitWriter and returns the current data.booleansetPos(int pos) voidwriteAutoGrow(boolean autoGrow) Write a value in the fieldauto_grow.voidwriteBitCapacity(int bitCapacity) Write a value in the fieldbit_capacity.voidwriteBitSize(int bitSize) Write a value in the fieldbit_size.voidwriteData(MemorySegment data) Write a value in the fielddata.voidwriteOwned(boolean owned) Write a value in the fieldowned.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
BitWriter
Create a BitWriter proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
BitWriter
Allocate a new BitWriter.- Parameters:
arena- to control the memory allocation scope
-
BitWriter
public BitWriter()Allocate a new BitWriter. The memory is allocated withArena.ofAuto(). -
BitWriter
public BitWriter(MemorySegment data, int bitSize, int bitCapacity, boolean autoGrow, boolean owned, Arena arena) Allocate a new BitWriter with the fields set to the provided values.- Parameters:
data- value for the fielddatabitSize- value for the fieldbitSizebitCapacity- value for the fieldbitCapacityautoGrow- value for the fieldautoGrowowned- value for the fieldownedarena- to control the memory allocation scope
-
BitWriter
Allocate a new BitWriter with the fields set to the provided values. The memory is allocated withArena.ofAuto().- Parameters:
data- value for the fielddatabitSize- value for the fieldbitSizebitCapacity- value for the fieldbitCapacityautoGrow- value for the fieldautoGrowowned- value for the fieldowned
-
-
Method Details
-
getMemoryLayout
The memory layout of the native struct.- Returns:
- the memory layout
-
readData
Read the value of the fielddata.- Returns:
- The value of the field
data
-
writeData
Write a value in the fielddata.- Parameters:
data- The new value for the fielddata
-
readBitSize
public int readBitSize()Read the value of the fieldbit_size.- Returns:
- The value of the field
bit_size
-
writeBitSize
public void writeBitSize(int bitSize) Write a value in the fieldbit_size.- Parameters:
bitSize- The new value for the fieldbit_size
-
readBitCapacity
public int readBitCapacity()Read the value of the fieldbit_capacity.- Returns:
- The value of the field
bit_capacity
-
writeBitCapacity
public void writeBitCapacity(int bitCapacity) Write a value in the fieldbit_capacity.- Parameters:
bitCapacity- The new value for the fieldbit_capacity
-
readAutoGrow
public boolean readAutoGrow()Read the value of the fieldauto_grow.- Returns:
- The value of the field
auto_grow
-
writeAutoGrow
public void writeAutoGrow(boolean autoGrow) Write a value in the fieldauto_grow.- Parameters:
autoGrow- The new value for the fieldauto_grow
-
readOwned
public boolean readOwned()Read the value of the fieldowned.- Returns:
- The value of the field
owned
-
writeOwned
public void writeOwned(boolean owned) Write a value in the fieldowned.- Parameters:
owned- The new value for the fieldowned
-
new_
Creates a new, emptyGstBitWriterinstance.Free-function: gst_bit_writer_free
- Returns:
- a new, empty
GstByteWriterinstance
-
newWithData
public static BitWriter newWithData(@org.jspecify.annotations.Nullable byte @Nullable [] data, boolean initialized) Creates a newGstBitWriterinstance with the given memory area. Ifinitializedistrueit is possible to readsizebits from theGstBitWriterfrom the beginning.Free-function: gst_bit_writer_free
- Parameters:
data- Memory area for writinginitialized- iftruethe complete data can be read from the beginning- Returns:
- a new
GstBitWriterinstance
-
newWithSize
Creates aGstBitWriterinstance with the given initial data size.Free-function: gst_bit_writer_free
- Parameters:
size- Initial size of data in bytesfixed- Iftruethe data can't be reallocated- Returns:
- a new
GstBitWriterinstance
-
alignBytes
public boolean alignBytes(byte trailingBit) Write trailing bit to align last byte ofdata.trailingBitcan only be 1 or 0.- Parameters:
trailingBit- trailing bits of last byte, 0 or 1- Returns:
trueif successful,falseotherwise.
-
free
public void free()Frees this BitWriter and the allocated data inside. -
freeAndGetBuffer
Frees this BitWriter without destroying the internal data, which is returned asGstBuffer.Free-function: gst_buffer_unref
- Returns:
- a new allocated
GstBufferwrapping the data inside. gst_buffer_unref() after usage.
-
freeAndGetData
public byte[] freeAndGetData()Frees this BitWriter without destroying the internal data, which is returned.Free-function: g_free
- Returns:
- the current data. g_free() after usage.
-
getData
public byte[] getData()Get written data pointer- Returns:
- data pointer
-
getRemaining
public int getRemaining() -
getSize
public int getSize()Get size of writtendata- Returns:
- size of bits written in
data
-
init
public void init()Initializes this BitWriter to an empty instance. -
initWithData
public void initWithData(@org.jspecify.annotations.Nullable byte @Nullable [] data, boolean initialized) Initializes this BitWriter with the given memory areadata.IFinitializedistrueit is possible to readsizebits from theGstBitWriterfrom the beginning.- Parameters:
data- Memory area for writinginitialized- Iftruethe complete data can be read from the beginning
-
initWithSize
public void initWithSize(int size, boolean fixed) Initializes aGstBitWriterinstance and allocates the given datasize.- Parameters:
size- the size on bytes to allocate for datafixed- Iftruethe data can't be reallocated
-
putBitsUint16
public boolean putBitsUint16(short value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.- Parameters:
value- value ofguint16to writenbits- number of bits to write- Returns:
trueif successful,falseotherwise.
-
putBitsUint32
public boolean putBitsUint32(int value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.- Parameters:
value- value ofguint32to writenbits- number of bits to write- Returns:
trueif successful,falseotherwise.
-
putBitsUint64
public boolean putBitsUint64(long value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.- Parameters:
value- value ofguint64to writenbits- number of bits to write- Returns:
trueif successful,falseotherwise.
-
putBitsUint8
public boolean putBitsUint8(byte value, int nbits) Writenbitsbits ofvaluetoGstBitWriter.- Parameters:
value- value ofguint8to writenbits- number of bits to write- Returns:
trueif successful,falseotherwise.
-
putBytes
public boolean putBytes(@org.jspecify.annotations.Nullable byte @Nullable [] data, int nbytes) Writenbytesbytes ofdatatoGstBitWriter.- Parameters:
data- pointer of data to writenbytes- number of bytes to write- Returns:
trueif successful,falseotherwise.
-
reset
public void reset()Resets this BitWriter and frees the data if it's owned bybitwriter. -
resetAndGetBuffer
Resets this BitWriter and returns the current data asGstBuffer.Free-function: gst_buffer_unref
- Returns:
- a new allocated
GstBufferwrapping the current data. gst_buffer_unref() after usage.
-
resetAndGetData
public byte[] resetAndGetData()Resets this BitWriter and returns the current data.Free-function: g_free
- Returns:
- the current data. g_free() after usage.
-
setPos
public boolean setPos(int pos)
-