org.freedesktop.gstreamer.gst.BufferList Maven / Gradle / Ivy
Show all versions of gst Show documentation
/* Java-GI - Java language bindings for GObject-Introspection-based libraries
* Copyright (C) 2022-2023 Jan-Willem Harmannij
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see .
*/
/* This file has been generated with Java-GI.
* Do not edit this file directly!
* Visit https://jwharm.github.io/java-gi for more information.
*/
package org.freedesktop.gstreamer.gst;
import io.github.jwharm.javagi.gobject.*;
import io.github.jwharm.javagi.gobject.types.*;
import io.github.jwharm.javagi.base.*;
import io.github.jwharm.javagi.interop.*;
import java.lang.foreign.*;
import java.lang.invoke.*;
import org.jetbrains.annotations.*;
/**
* Buffer lists are an object containing a list of buffers.
*
* Buffer lists are created with gst_buffer_list_new() and filled with data
* using gst_buffer_list_insert().
*
* Buffer lists can be pushed on a srcpad with gst_pad_push_list(). This is
* interesting when multiple buffers need to be pushed in one go because it
* can reduce the amount of overhead for pushing each buffer individually.
*/
public class BufferList extends ManagedInstance {
static {
Gst.javagi$ensureInitialized();
}
/**
* Get the GType of the GstBufferList class.
* @return the GType
*/
public static org.gnome.glib.Type getType() {
return Interop.getType("gst_buffer_list_get_type");
}
/**
* Create a BufferList proxy instance for the provided memory address.
* @param address the memory address of the native object
*/
public BufferList(MemorySegment address) {
super(address);
MemoryCleaner.setFreeFunc(this.handle(), "gst_buffer_list_unref");
}
/**
* Creates a new, empty {@link BufferList}.
*/
public BufferList() {
super(constructNew());
}
/**
* Helper function for the {@code gst_buffer_list_new} constructor
*/
private static MemorySegment constructNew() {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_new", _fdesc, false).invokeExact();
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
return _result;
}
/**
* Creates a new, empty {@link BufferList}. The list will have {@code size} space
* preallocated so that memory reallocations can be avoided.
* @param size an initial reserved size
* @return the new {@link BufferList}.
*/
public static BufferList sized(int size) {
var _result = constructSized(size);
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.BufferList(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_list_unref");
}
return _instance;
}
/**
* Creates a new, empty {@link BufferList}. The list will have {@code size} space
* preallocated so that memory reallocations can be avoided.
* @param size an initial reserved size
* @return the new {@link BufferList}.
* @deprecated See {@link #sized}
*/
@Deprecated
public static BufferList newSized(int size) {
var _result = constructSized(size);
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.BufferList(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_list_unref");
}
return _instance;
}
/**
* Helper function for the {@code gst_buffer_list_new_sized} constructor
*/
private static MemorySegment constructSized(int size) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_new_sized", _fdesc, false).invokeExact(size);
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
return _result;
}
/**
* Calculates the size of the data contained in {@code list} by adding the
* size of all buffers.
* @return the size of the data contained in {@code list} in bytes.
*/
public long calculateSize() {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_LONG, ValueLayout.ADDRESS);
long _result;
try {
_result = (long) Interop.downcallHandle("gst_buffer_list_calculate_size", _fdesc, false).invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
return _result;
}
/**
* Creates a shallow copy of the given buffer list. This will make a newly
* allocated copy of the source list with copies of buffer pointers. The
* refcount of buffers pointed to will be increased by one.
* @return a new copy of {@code list}.
* @throws UnsupportedPlatformException when run on a platform other than Macos
*/
public org.freedesktop.gstreamer.gst.BufferList copy() {
Platform.checkSupportedPlatform("macos");
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_copy", _fdesc, false).invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.BufferList(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_list_unref");
}
return _instance;
}
/**
* Creates a copy of the given buffer list. This will make a newly allocated
* copy of the buffers that the source buffer list contains.
* @return a new copy of {@code list}.
*/
public org.freedesktop.gstreamer.gst.BufferList copyDeep() {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_copy_deep", _fdesc, false).invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.BufferList(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_list_unref");
}
return _instance;
}
/**
* Calls {@code func} with {@code data} for each buffer in {@code list}.
*
* {@code func} can modify the passed buffer pointer or its contents. The return value
* of {@code func} defines if this function returns or if the remaining buffers in
* the list should be skipped.
* @param func a {@link BufferListFunc} to call
* @return {@code true} when {@code func} returned {@code true} for each buffer in {@code list} or when
* {@code list} is empty.
*/
public boolean foreach(org.freedesktop.gstreamer.gst.BufferListFunc func) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
try (Arena _arena = Arena.ofConfined()) {
int _result;
try {
_result = (int) Interop.downcallHandle("gst_buffer_list_foreach", _fdesc, false).invokeExact(handle(),
(MemorySegment) (func == null ? MemorySegment.NULL : func.toCallback(_arena)),
MemorySegment.NULL);
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
return _result != 0;
}
}
/**
* Gets the buffer at {@code idx}.
*
* You must make sure that {@code idx} does not exceed the number of
* buffers available.
* @param idx the index
* @return the buffer at {@code idx} in {@code group}
* or {@code null} when there is no buffer. The buffer remains valid as
* long as {@code list} is valid and buffer is not removed from the list.
*/
public @Nullable org.freedesktop.gstreamer.gst.Buffer get(int idx) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_get", _fdesc, false).invokeExact(handle(),
idx);
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.Buffer(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_unref");
}
return _instance;
}
/**
* Gets the buffer at {@code idx}, ensuring it is a writable buffer.
*
* You must make sure that {@code idx} does not exceed the number of
* buffers available.
* @param idx the index
* @return the buffer at {@code idx} in {@code group}.
* The returned buffer remains valid as long as {@code list} is valid and
* the buffer is not removed from the list.
*/
public @Nullable org.freedesktop.gstreamer.gst.Buffer getWritable(int idx) {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS, ValueLayout.JAVA_INT);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_get_writable", _fdesc, false).invokeExact(handle(),
idx);
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.Buffer(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_unref");
}
return _instance;
}
/**
* Inserts {@code buffer} at {@code idx} in {@code list}. Other buffers are moved to make room for
* this new buffer.
*
* A -1 value for {@code idx} will append the buffer at the end.
* @param idx the index
* @param buffer a {@link Buffer}
*/
public void insert(int idx, org.freedesktop.gstreamer.gst.Buffer buffer) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
try {
Interop.downcallHandle("gst_buffer_list_insert", _fdesc, false).invokeExact(handle(),
idx,
(MemorySegment) (buffer == null ? MemorySegment.NULL : buffer.handle()));
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
if (buffer != null) MemoryCleaner.yieldOwnership(buffer.handle());
}
/**
* Returns the number of buffers in {@code list}.
* @return the number of buffers in the buffer list
*/
public int length() {
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS);
int _result;
try {
_result = (int) Interop.downcallHandle("gst_buffer_list_length", _fdesc, false).invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
return _result;
}
/**
* Increases the refcount of the given buffer list by one.
*
* Note that the refcount affects the writability of {@code list} and its data, see
* gst_buffer_list_make_writable(). It is important to note that keeping
* additional references to GstBufferList instances can potentially increase
* the number of memcpy operations in a pipeline.
* @return {@code list}
* @throws UnsupportedPlatformException when run on a platform other than Macos
*/
public org.freedesktop.gstreamer.gst.BufferList ref() {
Platform.checkSupportedPlatform("macos");
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.ADDRESS, ValueLayout.ADDRESS);
MemorySegment _result;
try {
_result = (MemorySegment) Interop.downcallHandle("gst_buffer_list_ref", _fdesc, false).invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
var _instance = MemorySegment.NULL.equals(_result) ? null : new org.freedesktop.gstreamer.gst.BufferList(_result);
if (_instance != null) {
MemoryCleaner.takeOwnership(_instance.handle());
MemoryCleaner.setFreeFunc(_instance.handle(), "gst_buffer_list_unref");
}
return _instance;
}
/**
* Removes {@code length} buffers starting from {@code idx} in {@code list}. The following buffers
* are moved to close the gap.
* @param idx the index
* @param length the amount to remove
*/
public void remove(int idx, int length) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT, ValueLayout.JAVA_INT);
try {
Interop.downcallHandle("gst_buffer_list_remove", _fdesc, false).invokeExact(handle(),
idx,
length);
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
}
/**
* Decreases the refcount of the buffer list. If the refcount reaches 0, the
* buffer list will be freed.
* @throws UnsupportedPlatformException when run on a platform other than Macos
*/
public void unref() {
Platform.checkSupportedPlatform("macos");
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
try {
Interop.downcallHandle("gst_buffer_list_unref", _fdesc, false).invokeExact(handle());
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
MemoryCleaner.yieldOwnership(this.handle());
}
/**
* Modifies a pointer to a {@link BufferList} to point to a different
* {@link BufferList}. The modification is done atomically (so this is useful for
* ensuring thread safety in some cases), and the reference counts are updated
* appropriately (the old buffer list is unreffed, the new is reffed).
*
* Either {@code new_list} or the {@link BufferList} pointed to by {@code old_list} may be {@code null}.
* @param oldList pointer to a pointer to a
* {@link BufferList} to be replaced.
* @param newList pointer to a {@link BufferList} that
* will replace the buffer list pointed to by {@code old_list}.
* @return {@code true} if {@code new_list} was different from {@code old_list}
* @throws UnsupportedPlatformException when run on a platform other than Macos
*/
public static boolean replace(@Nullable Out oldList, @Nullable org.freedesktop.gstreamer.gst.BufferList newList) {
Platform.checkSupportedPlatform("macos");
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _oldListPointer = _arena.allocate(ValueLayout.ADDRESS);
int _result;
try {
_result = (int) Interop.downcallHandle("gst_buffer_list_replace", _fdesc, false).invokeExact((MemorySegment) (oldList == null ? MemorySegment.NULL : _oldListPointer),
(MemorySegment) (newList == null ? MemorySegment.NULL : newList.handle()));
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
if (oldList != null) oldList.set(MemorySegment.NULL.equals(_oldListPointer.get(ValueLayout.ADDRESS, 0)) ? null : new org.freedesktop.gstreamer.gst.BufferList(_oldListPointer.get(ValueLayout.ADDRESS, 0)));
return _result != 0;
}
}
/**
* Modifies a pointer to a {@link BufferList} to point to a different
* {@link BufferList}. This function is similar to gst_buffer_list_replace() except
* that it takes ownership of {@code new_list}.
* @param oldList pointer to a pointer to a {@link BufferList}
* to be replaced.
* @param newList pointer to a {@link BufferList}
* that will replace the bufferlist pointed to by {@code old_list}.
* @return {@code true} if {@code new_list} was different from {@code old_list}
* @throws UnsupportedPlatformException when run on a platform other than Macos
*/
public static boolean take(Out oldList, @Nullable org.freedesktop.gstreamer.gst.BufferList newList) {
Platform.checkSupportedPlatform("macos");
FunctionDescriptor _fdesc = FunctionDescriptor.of(ValueLayout.JAVA_INT, ValueLayout.ADDRESS, ValueLayout.ADDRESS);
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _oldListPointer = _arena.allocate(ValueLayout.ADDRESS);
int _result;
try {
_result = (int) Interop.downcallHandle("gst_buffer_list_take", _fdesc, false).invokeExact((MemorySegment) (oldList == null ? MemorySegment.NULL : _oldListPointer),
(MemorySegment) (newList == null ? MemorySegment.NULL : newList.handle()));
} catch (Throwable _err) {
throw new AssertionError("Unexpected exception occurred: ", _err);
}
if (oldList != null) oldList.set(MemorySegment.NULL.equals(_oldListPointer.get(ValueLayout.ADDRESS, 0)) ? null : new org.freedesktop.gstreamer.gst.BufferList(_oldListPointer.get(ValueLayout.ADDRESS, 0)));
if (newList != null) MemoryCleaner.yieldOwnership(newList.handle());
return _result != 0;
}
}
}