Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/org/freedesktop/gstreamer/Promise.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static org.freedesktop.gstreamer.lowlevel.GstPromiseAPI.GSTPROMISE_API;

import org.freedesktop.gstreamer.glib.NativeObject;
import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback;

import com.sun.jna.Pointer;
Expand Down Expand Up @@ -86,7 +87,9 @@ public PromiseResult waitResult() {
* {@link PromiseResult} state. If the promise has already been interrupted
* than the replied will not be visible to any waiters
*
* @param structure the {@link Structure} to reply the promise with
* @param structure the {@link Structure} to reply the promise with, caller
* should not use this structure afterward as it is invalidated through
* {@link NativeObject#invalidate()}
*/
public void reply(final Structure structure) {
GSTPROMISE_API.gst_promise_reply(this, structure);
Expand Down
20 changes: 20 additions & 0 deletions src/org/freedesktop/gstreamer/glib/Natives.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,26 @@ public static GPointer getPointer(NativeObject obj) {
return obj.getPointer();
}

/**
* Return whether underlying native pointer is owned by this object.
*
* @param obj native object which may hold a reference to native pointer
* @return whether underlying native pointer is owned by this object
*/
public static boolean ownsReference(NativeObject obj) {
return obj.handle.ownsReference();
}

/**
* Returns whether this object is valid or not.
*
* @param obj native object
* @return whether this object is valid or not
*/
public static boolean validReference(NativeObject obj) {
return obj.handle.getPointer() != null;
}

/**
* Increase the reference count of a {@link RefCountedObject}
*
Expand Down
3 changes: 2 additions & 1 deletion src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn;

import com.sun.jna.Pointer;
import org.freedesktop.gstreamer.lowlevel.annotations.Invalidate;

/**
* GstPromise methods and structures
Expand Down Expand Up @@ -65,7 +66,7 @@ protected List<String> getFieldOrder() {

PromiseResult gst_promise_wait(Promise promise);

void gst_promise_reply(Promise promise, Structure s);
void gst_promise_reply(Promise promise, @Invalidate Structure s);
void gst_promise_interrupt(Promise promise);
void gst_promise_expire(Promise promise);

Expand Down
20 changes: 19 additions & 1 deletion test/org/freedesktop/gstreamer/PromiseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@
package org.freedesktop.gstreamer;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import org.freedesktop.gstreamer.glib.Natives;
import org.freedesktop.gstreamer.lowlevel.GPointer;
import org.freedesktop.gstreamer.lowlevel.GType;
import org.junit.BeforeClass;
import org.junit.AfterClass;
Expand Down Expand Up @@ -82,18 +85,33 @@ public void testExpire() {
assertEquals("promise reply state not correct", promiseStatus, PromiseResult.EXPIRED);
}

@Test
public void testInvalidateReply() {
if (!Gst.testVersion(1, 14)) {
return;
}
Promise promise = new Promise();
Structure data = new Structure("data");

assertTrue(Natives.ownsReference(data));
promise.reply(data);
assertFalse(Natives.ownsReference(data));
assertFalse(Natives.validReference(data));
}

@Test
public void testReplyData() {
if (!Gst.testVersion(1, 14)) {
return;
}
Promise promise = new Promise();
Structure data = new Structure("data", "test", GType.UINT, 1);
GPointer pointer = Natives.getPointer(data);

promise.reply(data);
assertEquals("promise state not in replied", promise.waitResult(), PromiseResult.REPLIED);

Structure result = promise.getReply();
assertTrue("result of promise does not match reply", result.isEqual(data));
assertEquals("result of promise does not match reply", pointer, Natives.getPointer(result));
}
}