From 448a9f9528486da27413a1104db92b7057beefd3 Mon Sep 17 00:00:00 2001 From: Vinicius Tona Date: Thu, 24 May 2018 10:49:14 -0400 Subject: [PATCH 01/13] [webrtc] Adding GstPromise and GstWebRTCSessionDescription --- src/org/freedesktop/gstreamer/Gst.java | 2 + src/org/freedesktop/gstreamer/Promise.java | 73 +++++++++++++++++ .../gstreamer/WebRTCSessionDescription.java | 26 ++++++ .../gstreamer/lowlevel/GstPromiseAPI.java | 79 +++++++++++++++++++ .../GstWebRTCSessionDescriptionAPI.java | 73 +++++++++++++++++ 5 files changed, 253 insertions(+) create mode 100644 src/org/freedesktop/gstreamer/Promise.java create mode 100644 src/org/freedesktop/gstreamer/WebRTCSessionDescription.java create mode 100644 src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java create mode 100644 src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java diff --git a/src/org/freedesktop/gstreamer/Gst.java b/src/org/freedesktop/gstreamer/Gst.java index 7036af39..253b63f7 100644 --- a/src/org/freedesktop/gstreamer/Gst.java +++ b/src/org/freedesktop/gstreamer/Gst.java @@ -619,9 +619,11 @@ private static synchronized void loadAllClasses() { PadTemplate.class, Plugin.class, PluginFeature.class, + Promise.class, Query.class, Registry.class, Sample.class, + WebRTCSessionDescription.class, // ----------- Elements ------------- AppSink.class, AppSrc.class, diff --git a/src/org/freedesktop/gstreamer/Promise.java b/src/org/freedesktop/gstreamer/Promise.java new file mode 100644 index 00000000..a47dcc9d --- /dev/null +++ b/src/org/freedesktop/gstreamer/Promise.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2015 Neil C Smith Copyright (c) 2007,2008 Wayne Meissner Copyright (C) 1999,2000 + * Erik Walthinsen 2004,2005 Wim Taymans + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + +package org.freedesktop.gstreamer; + +import static org.freedesktop.gstreamer.lowlevel.GstPromiseAPI.*; + +import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback; + +import com.sun.jna.Pointer; + +/** + + */ +public class Promise extends MiniObject +{ + public static final String GTYPE_NAME = "GstPromise"; + + public Promise(final Initializer init) + { + super(init); + } + + public Promise(final GstCallback callback) + { + this(initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(callback))); + } + + protected static Initializer initializer(final Pointer ptr) + { + return new Initializer(ptr, false, true); + } + + public void waitResult() + { + GSTPROMISE_API.gst_promise_wait(this); + } + + public void reply(final Structure s) + { + GSTPROMISE_API.gst_promise_reply(this, s); + } + + public void interrupt() + { + GSTPROMISE_API.gst_promise_interrupt(this); + } + + public void expire() + { + GSTPROMISE_API.gst_promise_expire(this); + } + + public Structure getReply() + { + return GSTPROMISE_API.gst_promise_get_reply(this); + } + +} diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java new file mode 100644 index 00000000..2da7b69e --- /dev/null +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -0,0 +1,26 @@ +package org.freedesktop.gstreamer; + +import static org.freedesktop.gstreamer.lowlevel.GstWebRTCSessionDescriptionAPI.*; + +import com.sun.jna.Pointer; + +public class WebRTCSessionDescription extends MiniObject +{ + public static final String GTYPE_NAME = "GstWebRTCSessionDescription"; + + public WebRTCSessionDescription(final Initializer init) + { + super(init); + } + + public WebRTCSessionDescription(final Pointer type, final Pointer sdp) + { + this(initializer( + GSTWEBRTCSESSIONDESCRIPTION_API.ptr_gst_webrtc_session_description_new(type, sdp))); + } + + protected static Initializer initializer(final Pointer ptr) + { + return new Initializer(ptr, false, true); + } +} diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java new file mode 100644 index 00000000..e1d501c4 --- /dev/null +++ b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2009 Levente Farkas Copyright (c) 2007, 2008 Wayne Meissner + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + +package org.freedesktop.gstreamer.lowlevel; + +import java.util.Arrays; +import java.util.List; + +import org.freedesktop.gstreamer.Promise; +import org.freedesktop.gstreamer.Structure; +import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback; +import org.freedesktop.gstreamer.lowlevel.GstMiniObjectAPI.MiniObjectStruct; +import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn; + +import com.sun.jna.Pointer; + +/** + * GstPromise methods and structures + * + * @see https://github.com/GStreamer/gstreamer/blob/master/gst/gstpromise.h + */ + +public interface GstPromiseAPI extends com.sun.jna.Library +{ + GstPromiseAPI GSTPROMISE_API = GstNative.load(GstPromiseAPI.class); + + public static final class PromiseStruct extends com.sun.jna.Structure + { + public volatile MiniObjectStruct parent; + + public PromiseStruct() + { + } + + public PromiseStruct(final Pointer ptr) + { + useMemory(ptr); + } + + @Override + protected List getFieldOrder() + { + return Arrays.asList(new String[] { "parent" }); + } + } + + GType gst_promise_get_type(); + + @CallerOwnsReturn + Promise gst_promise_new_with_change_func(GstCallback callback); + + @CallerOwnsReturn + Pointer ptr_gst_promise_new_with_change_func(GstCallback callback); + + void gst_promise_wait(Promise promise); + + void gst_promise_reply(Promise promise, Structure s); + + void gst_promise_interrupt(Promise promise); + + void gst_promise_expire(Promise promise); + + Structure gst_promise_get_reply(Promise promise); + + GType gst_static_promise_get_type(); +} diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java new file mode 100644 index 00000000..a1ca51cc --- /dev/null +++ b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java @@ -0,0 +1,73 @@ +/* + * Copyright (c) 2009 Levente Farkas Copyright (c) 2007, 2008 Wayne Meissner + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + +package org.freedesktop.gstreamer.lowlevel; + +import java.util.Arrays; +import java.util.List; + +import org.freedesktop.gstreamer.WebRTCSessionDescription; +import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn; + +import com.sun.jna.Pointer; + +/** + * GstWebRTCSessionDescription methods and structures + * + * @see https://github.com/GStreamer/gst-plugins-bad/blob/master/gst-libs/gst/webrtc/rtcsessiondescription.h + */ + +public interface GstWebRTCSessionDescriptionAPI extends com.sun.jna.Library +{ + GstWebRTCSessionDescriptionAPI GSTWEBRTCSESSIONDESCRIPTION_API = + GstNative.load(GstWebRTCSessionDescriptionAPI.class); + + public static final class GstWebRTCSessionDescription extends com.sun.jna.Structure + { + public volatile Pointer type; + public volatile Pointer sdp; + + public GstWebRTCSessionDescription() + { + } + + public GstWebRTCSessionDescription(final Pointer ptr) + { + useMemory(ptr); + } + + @Override + protected List getFieldOrder() + { + return Arrays.asList(new String[] { "type", "sdp" }); + } + } + + GType gst_webrtc_session_description_get_type(); + + @CallerOwnsReturn + WebRTCSessionDescription gst_webrtc_session_description_new(Pointer type, Pointer sdp); + + @CallerOwnsReturn + Pointer ptr_gst_webrtc_session_description_new(Pointer type, Pointer sdp); + + String gst_webrtc_sdp_type_to_string(Pointer type); + + @CallerOwnsReturn + WebRTCSessionDescription gst_webrtc_session_description_copy(WebRTCSessionDescription src); + + void gst_webrtc_session_description_free(WebRTCSessionDescription desc); +} From 2236620ab811854b1815fe7a6acfc9f3197a2fb3 Mon Sep 17 00:00:00 2001 From: Vinicius Tona Date: Wed, 6 Jun 2018 08:45:39 -0400 Subject: [PATCH 02/13] [webrtc] [NS] Debugging --- src/org/freedesktop/gstreamer/Gst.java | 1 + src/org/freedesktop/gstreamer/Promise.java | 9 +- .../freedesktop/gstreamer/PromiseResult.java | 8 ++ src/org/freedesktop/gstreamer/SDPMessage.java | 49 ++++++++ src/org/freedesktop/gstreamer/SDPResult.java | 22 ++++ .../freedesktop/gstreamer/WebRTCSDPType.java | 19 +++ .../gstreamer/WebRTCSessionDescription.java | 39 ++++-- .../gstreamer/lowlevel/GstPromiseAPI.java | 12 +- .../gstreamer/lowlevel/GstSDPMessageAPI.java | 118 ++++++++++++++++++ .../GstWebRTCSessionDescriptionAPI.java | 41 +++--- 10 files changed, 275 insertions(+), 43 deletions(-) create mode 100644 src/org/freedesktop/gstreamer/PromiseResult.java create mode 100644 src/org/freedesktop/gstreamer/SDPMessage.java create mode 100644 src/org/freedesktop/gstreamer/SDPResult.java create mode 100644 src/org/freedesktop/gstreamer/WebRTCSDPType.java create mode 100644 src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java diff --git a/src/org/freedesktop/gstreamer/Gst.java b/src/org/freedesktop/gstreamer/Gst.java index 253b63f7..8d613429 100644 --- a/src/org/freedesktop/gstreamer/Gst.java +++ b/src/org/freedesktop/gstreamer/Gst.java @@ -623,6 +623,7 @@ private static synchronized void loadAllClasses() { Query.class, Registry.class, Sample.class, + SDPMessage.class, WebRTCSessionDescription.class, // ----------- Elements ------------- AppSink.class, diff --git a/src/org/freedesktop/gstreamer/Promise.java b/src/org/freedesktop/gstreamer/Promise.java index a47dcc9d..367b2b52 100644 --- a/src/org/freedesktop/gstreamer/Promise.java +++ b/src/org/freedesktop/gstreamer/Promise.java @@ -35,6 +35,11 @@ public Promise(final Initializer init) super(init); } + public Promise() + { + this(initializer(GSTPROMISE_API.ptr_gst_promise_new())); + } + public Promise(final GstCallback callback) { this(initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(callback))); @@ -45,9 +50,9 @@ protected static Initializer initializer(final Pointer ptr) return new Initializer(ptr, false, true); } - public void waitResult() + public PromiseResult waitResult() { - GSTPROMISE_API.gst_promise_wait(this); + return GSTPROMISE_API.gst_promise_wait(this); } public void reply(final Structure s) diff --git a/src/org/freedesktop/gstreamer/PromiseResult.java b/src/org/freedesktop/gstreamer/PromiseResult.java new file mode 100644 index 00000000..5ec9db33 --- /dev/null +++ b/src/org/freedesktop/gstreamer/PromiseResult.java @@ -0,0 +1,8 @@ +package org.freedesktop.gstreamer; + +public enum PromiseResult { + PENDING, + INTERRUPTED, + REPLIED, + EXPIRED; +} diff --git a/src/org/freedesktop/gstreamer/SDPMessage.java b/src/org/freedesktop/gstreamer/SDPMessage.java new file mode 100644 index 00000000..89a074c9 --- /dev/null +++ b/src/org/freedesktop/gstreamer/SDPMessage.java @@ -0,0 +1,49 @@ + +package org.freedesktop.gstreamer; + +import java.nio.charset.StandardCharsets; + +import static org.freedesktop.gstreamer.lowlevel.GstSDPMessageAPI.GSTSDPMESSAGE_API; + +import org.freedesktop.gstreamer.lowlevel.NativeObject; +import org.freedesktop.gstreamer.lowlevel.GstSDPMessageAPI; + +import com.sun.jna.Pointer; + +public class SDPMessage extends NativeObject { + public static final String GTYPE_NAME = "GstSDPMessage"; + + public SDPMessage(Initializer init) { + super(init); + } + + public SDPMessage() { + this(initializer()); + } + + protected static Initializer initializer(final Pointer ptr) { + return new Initializer(ptr, false, true); + } + + private static Initializer initializer() { + Pointer[] ptr = new Pointer[1]; + GSTSDPMESSAGE_API.gst_sdp_message_new(ptr); + return initializer(ptr[0], false, true); + } + + protected void disposeNativeHandle(Pointer ptr) { + GSTSDPMESSAGE_API.gst_sdp_message_free(ptr); + } + + public String toString() { + return GSTSDPMESSAGE_API.gst_sdp_message_as_text(this); + } + + public void parseBuffer(String sdpString) { + if (sdpString != null && sdpString.length() != 0) { + byte[] data = sdpString.getBytes(StandardCharsets.US_ASCII); + int length = sdpString.length(); + GSTSDPMESSAGE_API.gst_sdp_message_parse_buffer(data, length, this); + } + } +} diff --git a/src/org/freedesktop/gstreamer/SDPResult.java b/src/org/freedesktop/gstreamer/SDPResult.java new file mode 100644 index 00000000..5b92666c --- /dev/null +++ b/src/org/freedesktop/gstreamer/SDPResult.java @@ -0,0 +1,22 @@ +package org.freedesktop.gstreamer; + +import org.freedesktop.gstreamer.lowlevel.IntegerEnum; +import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue; + +public enum SDPResult { + OK(0), + EINVAL(-1), + + @DefaultEnumValue + __UNKNWOND_NATIVE_VALUE(~0); + + SDPResult(int value) { + this.value = value; + } + + public int intValue() { + return value; + } + + private int value; +} diff --git a/src/org/freedesktop/gstreamer/WebRTCSDPType.java b/src/org/freedesktop/gstreamer/WebRTCSDPType.java new file mode 100644 index 00000000..c7d309fc --- /dev/null +++ b/src/org/freedesktop/gstreamer/WebRTCSDPType.java @@ -0,0 +1,19 @@ +package org.freedesktop.gstreamer; + +import org.freedesktop.gstreamer.lowlevel.IntegerEnum; + +public enum WebRTCSDPType implements IntegerEnum { + OFFER(1), + PRANSWER(2), + ANSWER(3), + ROLLBACK(4); + + WebRTCSDPType(int value) { + this.value = value; + } + + public int intValue() { + return value; + } + private final int value; +} diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java index 2da7b69e..1fd04302 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -1,26 +1,41 @@ package org.freedesktop.gstreamer; -import static org.freedesktop.gstreamer.lowlevel.GstWebRTCSessionDescriptionAPI.*; +import static org.freedesktop.gstreamer.lowlevel.GstWebRTCSessionDescriptionAPI.GSTWEBRTCSESSIONDESCRIPTION_API; + +import org.freedesktop.gstreamer.lowlevel.GstWebRTCSessionDescriptionAPI; +import org.freedesktop.gstreamer.lowlevel.NativeObject; +import org.freedesktop.gstreamer.lowlevel.GType; import com.sun.jna.Pointer; -public class WebRTCSessionDescription extends MiniObject -{ +public class WebRTCSessionDescription extends NativeObject { public static final String GTYPE_NAME = "GstWebRTCSessionDescription"; + public static final GType GTYPE = GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_get_type(); + + protected GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct sessionDescriptionStruct; - public WebRTCSessionDescription(final Initializer init) - { + /** + * Internally used constructor. Do not use. + * + * @param init internal initialization data. + */ + public WebRTCSessionDescription(Initializer init) { super(init); + sessionDescriptionStruct = new GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct(handle()); } - public WebRTCSessionDescription(final Pointer type, final Pointer sdp) - { - this(initializer( - GSTWEBRTCSESSIONDESCRIPTION_API.ptr_gst_webrtc_session_description_new(type, sdp))); + public WebRTCSessionDescription(WebRTCSDPType type, SDPMessage sdpMessage) { + this(initializer(GSTWEBRTCSESSIONDESCRIPTION_API.ptr_gst_webrtc_session_description_new(type, sdpMessage))); } - protected static Initializer initializer(final Pointer ptr) - { - return new Initializer(ptr, false, true); + @Override + protected void disposeNativeHandle(Pointer ptr) { + GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_free(ptr); } + + public SDPMessage getSDPMessage() { + SDPMessage sdp = (SDPMessage)sessionDescriptionStruct.readField("sdp"); + return sdp; + } + } diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java index e1d501c4..9120e11b 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java @@ -20,6 +20,7 @@ import java.util.List; import org.freedesktop.gstreamer.Promise; +import org.freedesktop.gstreamer.PromiseResult; import org.freedesktop.gstreamer.Structure; import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback; import org.freedesktop.gstreamer.lowlevel.GstMiniObjectAPI.MiniObjectStruct; @@ -45,7 +46,7 @@ public PromiseStruct() { } - public PromiseStruct(final Pointer ptr) + public PromiseStruct(Pointer ptr) { useMemory(ptr); } @@ -59,13 +60,17 @@ protected List getFieldOrder() GType gst_promise_get_type(); + @CallerOwnsReturn Promise gst_promise_new(); + + @CallerOwnsReturn Pointer ptr_gst_promise_new(); + @CallerOwnsReturn Promise gst_promise_new_with_change_func(GstCallback callback); @CallerOwnsReturn Pointer ptr_gst_promise_new_with_change_func(GstCallback callback); - void gst_promise_wait(Promise promise); + PromiseResult gst_promise_wait(Promise promise); void gst_promise_reply(Promise promise, Structure s); @@ -73,7 +78,8 @@ protected List getFieldOrder() void gst_promise_expire(Promise promise); - Structure gst_promise_get_reply(Promise promise); + @CallerOwnsReturn Structure gst_promise_get_reply(Promise promise); + @CallerOwnsReturn Pointer ptr_gst_promise_get_reply(Promise promise); GType gst_static_promise_get_type(); } diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java new file mode 100644 index 00000000..77b22307 --- /dev/null +++ b/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java @@ -0,0 +1,118 @@ +package org.freedesktop.gstreamer.lowlevel; + +import java.util.Arrays; +import java.util.List; + +import org.freedesktop.gstreamer.SDPResult; +import org.freedesktop.gstreamer.SDPMessage; +import org.freedesktop.gstreamer.lowlevel.GValueAPI.GValueArray; + +import com.sun.jna.Pointer; + +public interface GstSDPMessageAPI extends com.sun.jna.Library { + GstSDPMessageAPI GSTSDPMESSAGE_API = GstNative.load("gstsdp", GstSDPMessageAPI.class); + + public static final class SDPMessageStruct extends com.sun.jna.Structure { + public volatile String version; + public volatile SDPOriginStruct origin; + public volatile String session_name; + public volatile String information; + public volatile String uri; + public volatile GValueArray emails; + public volatile GValueArray phones; + public volatile SDPConnectionStruct connection; + public volatile GValueArray bandwidths; + public volatile GValueArray times; + public volatile GValueArray zones; + public volatile SDPKeyStruct key; + public volatile GValueArray attributes; + public volatile GValueArray medias; + + public SDPMessageStruct(final Pointer ptr) { + useMemory(ptr); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { + "version", + "origin", + "session_name", + "information", + "uri", + "emails", + "phones", + "connection", + "bandwidths", + "times", + "zones", + "key", + "attributes", + "medias" + }); + } + } + + public static final class SDPOriginStruct extends com.sun.jna.Structure { + public volatile String username; + public volatile String sess_id; + public volatile String sess_version; + public volatile String nettype; + public volatile String addrtype; + public volatile String addr; + + public SDPOriginStruct(final Pointer ptr) { + useMemory(ptr); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "username", "sess_id", "sess_version", "nettype", "addrtype", "addr" }); + } + + } + + public static final class SDPKeyStruct extends com.sun.jna.Structure { + public volatile String type; + public volatile String data; + + public SDPKeyStruct(final Pointer ptr) { + useMemory(ptr); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "type", "data" }); + } + } + + public static final class SDPConnectionStruct extends com.sun.jna.Structure { + public volatile String nettype; + public volatile String addrtype; + public volatile String address; + public volatile int ttl; + public volatile int addr_number; + + public SDPConnectionStruct(final Pointer ptr) { + useMemory(ptr); + } + + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "nettype", "addrtype", "address", "ttl", "addr_number" }); + } + } + + SDPResult gst_sdp_connection_set(SDPConnectionStruct conn, String nettype, String address, int ttl, int addr_number); + SDPResult gst_sdp_connection_clear(SDPConnectionStruct conn); + + SDPResult gst_sdp_message_free(Pointer msg); + SDPResult ptr_gst_sdp_message_free(Pointer msg); + + SDPResult gst_sdp_message_new(Pointer[] msg); + + SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, Pointer[] msg); + SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, SDPMessage msg); + + String gst_sdp_message_as_text(SDPMessage msg); +} diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java index a1ca51cc..57a0c6fa 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java @@ -20,7 +20,10 @@ import java.util.List; import org.freedesktop.gstreamer.WebRTCSessionDescription; +import org.freedesktop.gstreamer.WebRTCSDPType; +import org.freedesktop.gstreamer.SDPMessage; import org.freedesktop.gstreamer.lowlevel.annotations.CallerOwnsReturn; +import org.freedesktop.gstreamer.lowlevel.GValueAPI.GValueArray; import com.sun.jna.Pointer; @@ -30,44 +33,30 @@ * @see https://github.com/GStreamer/gst-plugins-bad/blob/master/gst-libs/gst/webrtc/rtcsessiondescription.h */ -public interface GstWebRTCSessionDescriptionAPI extends com.sun.jna.Library -{ +public interface GstWebRTCSessionDescriptionAPI extends com.sun.jna.Library { GstWebRTCSessionDescriptionAPI GSTWEBRTCSESSIONDESCRIPTION_API = - GstNative.load(GstWebRTCSessionDescriptionAPI.class); + GstNative.load("gstwebrtc", GstWebRTCSessionDescriptionAPI.class); - public static final class GstWebRTCSessionDescription extends com.sun.jna.Structure - { - public volatile Pointer type; - public volatile Pointer sdp; + public static final class WebRTCSessionDescriptionStruct extends com.sun.jna.Structure { + public volatile WebRTCSDPType type; + public volatile SDPMessage sdp; - public GstWebRTCSessionDescription() - { - } - - public GstWebRTCSessionDescription(final Pointer ptr) - { + public WebRTCSessionDescriptionStruct(final Pointer ptr) { useMemory(ptr); } @Override - protected List getFieldOrder() - { + protected List getFieldOrder() { return Arrays.asList(new String[] { "type", "sdp" }); } } GType gst_webrtc_session_description_get_type(); + @CallerOwnsReturn WebRTCSessionDescription gst_webrtc_session_description_new(WebRTCSDPType type, SDPMessage sdp); + @CallerOwnsReturn Pointer ptr_gst_webrtc_session_description_new(WebRTCSDPType type, SDPMessage sdp); - @CallerOwnsReturn - WebRTCSessionDescription gst_webrtc_session_description_new(Pointer type, Pointer sdp); - - @CallerOwnsReturn - Pointer ptr_gst_webrtc_session_description_new(Pointer type, Pointer sdp); - - String gst_webrtc_sdp_type_to_string(Pointer type); - - @CallerOwnsReturn - WebRTCSessionDescription gst_webrtc_session_description_copy(WebRTCSessionDescription src); + @CallerOwnsReturn WebRTCSessionDescription gst_webrtc_session_description_copy(WebRTCSessionDescription src); + @CallerOwnsReturn Pointer ptr_gst_webrtc_session_description_copy(WebRTCSessionDescription src); - void gst_webrtc_session_description_free(WebRTCSessionDescription desc); + void gst_webrtc_session_description_free(Pointer desc); } From f6231ffb2c75c11bf3999ba4cbd9800ef7a1ac3a Mon Sep 17 00:00:00 2001 From: a-morales Date: Thu, 29 Nov 2018 12:31:13 -0800 Subject: [PATCH 03/13] Get WebRTC related elements to work without throwing null exceptions --- src/org/freedesktop/gstreamer/WebRTCSessionDescription.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java index 1fd04302..7562cf65 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -15,7 +15,7 @@ public class WebRTCSessionDescription extends NativeObject { protected GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct sessionDescriptionStruct; /** - * Internally used constructor. Do not use. + * Internally used constructor. Do not use. * * @param init internal initialization data. */ @@ -28,7 +28,6 @@ public WebRTCSessionDescription(WebRTCSDPType type, SDPMessage sdpMessage) { this(initializer(GSTWEBRTCSESSIONDESCRIPTION_API.ptr_gst_webrtc_session_description_new(type, sdpMessage))); } - @Override protected void disposeNativeHandle(Pointer ptr) { GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_free(ptr); } From 969d239b494b6fd2776081078cb1a68c393adcf4 Mon Sep 17 00:00:00 2001 From: a-morales Date: Tue, 30 Oct 2018 09:59:17 -0700 Subject: [PATCH 04/13] add hasCurrentCaps to pad --- src/org/freedesktop/gstreamer/Gst.java | 1 + src/org/freedesktop/gstreamer/Pad.java | 12 +++++++- .../freedesktop/gstreamer/PromiseResult.java | 30 ++++++++++++++++++- .../freedesktop/gstreamer/WebRTCSDPType.java | 27 +++++++++++++++++ .../gstreamer/lowlevel/GstPadAPI.java | 2 ++ .../gstreamer/lowlevel/GstPromiseAPI.java | 1 + .../GstWebRTCSessionDescriptionAPI.java | 1 + 7 files changed, 72 insertions(+), 2 deletions(-) diff --git a/src/org/freedesktop/gstreamer/Gst.java b/src/org/freedesktop/gstreamer/Gst.java index 8d613429..9cf71556 100644 --- a/src/org/freedesktop/gstreamer/Gst.java +++ b/src/org/freedesktop/gstreamer/Gst.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2018 Antonio Morales * Copyright (c) 2018 Neil C Smith * Copyright (c) 2007 Wayne Meissner * diff --git a/src/org/freedesktop/gstreamer/Pad.java b/src/org/freedesktop/gstreamer/Pad.java index 6a5005e6..378c1d34 100644 --- a/src/org/freedesktop/gstreamer/Pad.java +++ b/src/org/freedesktop/gstreamer/Pad.java @@ -1,10 +1,11 @@ /* + * Copyright (C) 2018 Antonio Morales * Copyright (C) 2014 Tom Greenwood * Copyright (C) 2009 Tamas Korodi * Copyright (C) 2007 Wayne Meissner * Copyright (C) 1999,2000 Erik Walthinsen * 2000 Wim Taymans - * + * * This file is part of gstreamer-java. * * This code is free software: you can redistribute it and/or modify it under @@ -689,4 +690,13 @@ public PadTemplate getTemplate() { return GSTPAD_API.gst_pad_get_pad_template(this); } + + /** + * Check if the pad has caps set on it with a GST_EVENT_CAPS events + * + * @return true if the pad has caps set + */ + public boolean hasCurrentCaps() { + return GSTPAD_API.gst_pad_has_current_caps(this); + } } diff --git a/src/org/freedesktop/gstreamer/PromiseResult.java b/src/org/freedesktop/gstreamer/PromiseResult.java index 5ec9db33..7b9741ef 100644 --- a/src/org/freedesktop/gstreamer/PromiseResult.java +++ b/src/org/freedesktop/gstreamer/PromiseResult.java @@ -1,8 +1,36 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + package org.freedesktop.gstreamer; +import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue; + +/** + * The result of a {@link Promise} + * Available since GStreamer 1.14 + */ public enum PromiseResult { + /** The initial state of a promise */ PENDING, + /** The promise was interrupted */ INTERRUPTED, + /** The promise has been resolved and it has a value */ REPLIED, - EXPIRED; + /** The promise is expired and won't return a result */ + EXPIRED, + /** Unknown result */ + @DefaultEnumValue UNKNOWN; } diff --git a/src/org/freedesktop/gstreamer/WebRTCSDPType.java b/src/org/freedesktop/gstreamer/WebRTCSDPType.java index c7d309fc..f363360c 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSDPType.java +++ b/src/org/freedesktop/gstreamer/WebRTCSDPType.java @@ -1,7 +1,30 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License version 3 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with this work. If not, see . + */ package org.freedesktop.gstreamer; import org.freedesktop.gstreamer.lowlevel.IntegerEnum; +/** + * The type of a {@link WebRTCSessionDescription} + * + * @see https://w3c.github.io/webrtc-pc/#rtcsdptype + * Available since GStreamer 1.12 + */ public enum WebRTCSDPType implements IntegerEnum { OFFER(1), PRANSWER(2), @@ -12,6 +35,10 @@ public enum WebRTCSDPType implements IntegerEnum { this.value = value; } + /** + * Gets the integer value of the enum + * @return the integer value for this enum. + */ public int intValue() { return value; } diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstPadAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstPadAPI.java index 2f8768bb..3186ad91 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstPadAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstPadAPI.java @@ -1,4 +1,5 @@ /* + * Copyright (c) 2018 Antonio Morales * Copyright (c) 2014 Tom Greenwood * Copyright (c) 2009 Levente Farkas * Copyright (c) 2007, 2008 Wayne Meissner @@ -99,6 +100,7 @@ public interface GstPadAPI extends com.sun.jna.Library { boolean gst_pad_activate_push(Pad pad, boolean active); boolean gst_pad_is_blocked(Pad pad); boolean gst_pad_is_blocking(Pad pad); + boolean gst_pad_has_current_caps(Pad pad); /* get_pad_template returns a non-refcounted PadTemplate */ PadTemplate gst_pad_get_pad_template(Pad pad); diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java index 9120e11b..ee27c7aa 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java @@ -32,6 +32,7 @@ * GstPromise methods and structures * * @see https://github.com/GStreamer/gstreamer/blob/master/gst/gstpromise.h + * available since GStreamer 1.14 */ public interface GstPromiseAPI extends com.sun.jna.Library diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java index 57a0c6fa..4be37364 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java @@ -31,6 +31,7 @@ * GstWebRTCSessionDescription methods and structures * * @see https://github.com/GStreamer/gst-plugins-bad/blob/master/gst-libs/gst/webrtc/rtcsessiondescription.h + * Available since GStreamer 1.14 */ public interface GstWebRTCSessionDescriptionAPI extends com.sun.jna.Library { From 88697888b5c71b1deea93b991701ac69852a15c2 Mon Sep 17 00:00:00 2001 From: a-morales Date: Tue, 30 Oct 2018 11:50:01 -0700 Subject: [PATCH 05/13] Add comments/documentation --- src/org/freedesktop/gstreamer/Gst.java | 6 +- src/org/freedesktop/gstreamer/Promise.java | 103 +++++-- src/org/freedesktop/gstreamer/SDPMessage.java | 60 +++- src/org/freedesktop/gstreamer/SDPResult.java | 29 +- .../gstreamer/WebRTCPeerConnectionState.java | 40 +++ .../gstreamer/WebRTCSessionDescription.java | 36 ++- .../gstreamer/elements/WebRTCBin.java | 263 ++++++++++++++++++ .../gstreamer/lowlevel/GstPromiseAPI.java | 32 +-- .../gstreamer/lowlevel/GstSDPMessageAPI.java | 189 +++++++------ .../GstWebRTCSessionDescriptionAPI.java | 5 +- 10 files changed, 601 insertions(+), 162 deletions(-) create mode 100644 src/org/freedesktop/gstreamer/WebRTCPeerConnectionState.java create mode 100644 src/org/freedesktop/gstreamer/elements/WebRTCBin.java diff --git a/src/org/freedesktop/gstreamer/Gst.java b/src/org/freedesktop/gstreamer/Gst.java index 9cf71556..f55b0f14 100644 --- a/src/org/freedesktop/gstreamer/Gst.java +++ b/src/org/freedesktop/gstreamer/Gst.java @@ -45,6 +45,7 @@ import org.freedesktop.gstreamer.elements.DecodeBin; import org.freedesktop.gstreamer.elements.PlayBin; import org.freedesktop.gstreamer.elements.URIDecodeBin; +import org.freedesktop.gstreamer.elements.WebRTCBin; import org.freedesktop.gstreamer.glib.GDate; import org.freedesktop.gstreamer.glib.GInetAddress; import org.freedesktop.gstreamer.glib.GSocketAddress; @@ -623,8 +624,8 @@ private static synchronized void loadAllClasses() { Promise.class, Query.class, Registry.class, - Sample.class, SDPMessage.class, + Sample.class, WebRTCSessionDescription.class, // ----------- Elements ------------- AppSink.class, @@ -636,6 +637,7 @@ private static synchronized void loadAllClasses() { DecodeBin.class, Pipeline.class, PlayBin.class, - URIDecodeBin.class + URIDecodeBin.class, + WebRTCBin.class ); } diff --git a/src/org/freedesktop/gstreamer/Promise.java b/src/org/freedesktop/gstreamer/Promise.java index 367b2b52..1e82dd2b 100644 --- a/src/org/freedesktop/gstreamer/Promise.java +++ b/src/org/freedesktop/gstreamer/Promise.java @@ -1,6 +1,6 @@ /* - * Copyright (c) 2015 Neil C Smith Copyright (c) 2007,2008 Wayne Meissner Copyright (C) 1999,2000 - * Erik Walthinsen 2004,2005 Wim Taymans + * Copyright (c) 2018 Vinicius Tona + * Copyright (c) 2018 Antonio Morales * * This file is part of gstreamer-java. * @@ -17,62 +17,107 @@ package org.freedesktop.gstreamer; -import static org.freedesktop.gstreamer.lowlevel.GstPromiseAPI.*; +import static org.freedesktop.gstreamer.lowlevel.GstPromiseAPI.GSTPROMISE_API; import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback; import com.sun.jna.Pointer; -/** - - */ -public class Promise extends MiniObject -{ +public class Promise extends MiniObject { public static final String GTYPE_NAME = "GstPromise"; - public Promise(final Initializer init) - { + public static interface PROMISE_CHANGE { + /** + * Called whenever the state of the promise is changed from PENDING to any other {@link PromiseResult} + * + * @param promise the original promise that had the callback attached to + */ + public void onChange(Promise promise); + } + + /** + * Creates a new instance of Promise. This constructor is used internally. + * + * @param init internal initialization data. + */ + public Promise(final Initializer init) { super(init); } - public Promise() - { + /** + * Creates a new instance of promise + */ + public Promise() { this(initializer(GSTPROMISE_API.ptr_gst_promise_new())); } - public Promise(final GstCallback callback) - { - this(initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(callback))); + /** + * Creates a new instance of promise with a callback attached. + * + * @param listerner Listener to be called whenever the state of a {@link Promise} is changed + */ + public Promise(final PROMISE_CHANGE listener) { + this(initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(new GstCallback() { + @SuppressWarnings("unused") + public void callback(Promise promise, Pointer userData) { + listener.onChange(promise); + } + }))); } - protected static Initializer initializer(final Pointer ptr) - { + protected static Initializer initializer(final Pointer ptr) { return new Initializer(ptr, false, true); } - public PromiseResult waitResult() - { + /** + * Wait for the promise to move out of the PENDING {@link PromiseResult} state. + * If the promise is not in PENDING then it will immediately return. + * + * @return the {@link PromiseResult} of the promise. + */ + public PromiseResult waitResult() { return GSTPROMISE_API.gst_promise_wait(this); } - public void reply(final Structure s) - { - GSTPROMISE_API.gst_promise_reply(this, s); + /** + * Set a reply on the promise. + * + * Will wake up any waiters on the promise with the REPLIED {@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 + */ + public void reply(final Structure structure) { + GSTPROMISE_API.gst_promise_reply(this, structure); } - public void interrupt() - { + /** + * Interrupt waiting for the result of the prommise. + * + * Any waiters on the promise will receive the INTERRUPTED {@link PromiseResult} state. + */ + public void interrupt() { GSTPROMISE_API.gst_promise_interrupt(this); } - public void expire() - { + /** + * Expire a promise. + * + * Any waiters on the promise will recieved the EXPIRED {@link PromiseResult} state. + */ + public void expire() { GSTPROMISE_API.gst_promise_expire(this); } - public Structure getReply() - { + /** + * Retrieve the reply set on the promise. + * + * The state of the promise must be in the REPLIED {@link PromiseResult} state. + * The return structure is owned by the promise and thus cannot be modified. + * + * @return the {@link Structure} set on the promise reply. + */ + public Structure getReply() { return GSTPROMISE_API.gst_promise_get_reply(this); } - } diff --git a/src/org/freedesktop/gstreamer/SDPMessage.java b/src/org/freedesktop/gstreamer/SDPMessage.java index 89a074c9..cbdadab3 100644 --- a/src/org/freedesktop/gstreamer/SDPMessage.java +++ b/src/org/freedesktop/gstreamer/SDPMessage.java @@ -1,3 +1,18 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ package org.freedesktop.gstreamer; @@ -6,21 +21,52 @@ import static org.freedesktop.gstreamer.lowlevel.GstSDPMessageAPI.GSTSDPMESSAGE_API; import org.freedesktop.gstreamer.lowlevel.NativeObject; -import org.freedesktop.gstreamer.lowlevel.GstSDPMessageAPI; import com.sun.jna.Pointer; public class SDPMessage extends NativeObject { public static final String GTYPE_NAME = "GstSDPMessage"; + /** + * Internally used constructor. Do not use. + * + * @param init internal initialization data + */ public SDPMessage(Initializer init) { super(init); } + /** + * Creates a new instance of SDPMessage + */ public SDPMessage() { this(initializer()); } + /** + * A SDP formatted string representation of SDPMessage. + * + * Used for offer/answer exchanges for real time communicationse + * + * @return the SDP string representation of SDPMessage. + */ + public String toString() { + return GSTSDPMESSAGE_API.gst_sdp_message_as_text(this); + } + + /** + * Takes a SDP string and parses it and fills in all fields for SDPMessage. + * + * Look at https://tools.ietf.org/html/rfc4566 for more information on SDP + * + * @param sdpString the sdp string + */ + public void parseBuffer(String sdpString) { + byte[] data = sdpString.getBytes(StandardCharsets.US_ASCII); + int length = sdpString.length(); + GSTSDPMESSAGE_API.gst_sdp_message_parse_buffer(data, length, this); + } + protected static Initializer initializer(final Pointer ptr) { return new Initializer(ptr, false, true); } @@ -34,16 +80,4 @@ private static Initializer initializer() { protected void disposeNativeHandle(Pointer ptr) { GSTSDPMESSAGE_API.gst_sdp_message_free(ptr); } - - public String toString() { - return GSTSDPMESSAGE_API.gst_sdp_message_as_text(this); - } - - public void parseBuffer(String sdpString) { - if (sdpString != null && sdpString.length() != 0) { - byte[] data = sdpString.getBytes(StandardCharsets.US_ASCII); - int length = sdpString.length(); - GSTSDPMESSAGE_API.gst_sdp_message_parse_buffer(data, length, this); - } - } } diff --git a/src/org/freedesktop/gstreamer/SDPResult.java b/src/org/freedesktop/gstreamer/SDPResult.java index 5b92666c..5ea67d8a 100644 --- a/src/org/freedesktop/gstreamer/SDPResult.java +++ b/src/org/freedesktop/gstreamer/SDPResult.java @@ -1,12 +1,33 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + package org.freedesktop.gstreamer; import org.freedesktop.gstreamer.lowlevel.IntegerEnum; import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue; -public enum SDPResult { +/** + * The possible results for {@link SDPMessage} functions + */ +public enum SDPResult implements IntegerEnum { + /** A successful return value*/ OK(0), + /** A function to SDPMessage was given invalid paramters */ EINVAL(-1), - + /** An unknown result */ @DefaultEnumValue __UNKNWOND_NATIVE_VALUE(~0); @@ -14,6 +35,10 @@ public enum SDPResult { this.value = value; } + /** + * Gets the integer value of the enum + * @return the integer value for this enum. + */ public int intValue() { return value; } diff --git a/src/org/freedesktop/gstreamer/WebRTCPeerConnectionState.java b/src/org/freedesktop/gstreamer/WebRTCPeerConnectionState.java new file mode 100644 index 00000000..b41b93cf --- /dev/null +++ b/src/org/freedesktop/gstreamer/WebRTCPeerConnectionState.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + +package org.freedesktop.gstreamer; + +import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue; + +/** + * The state of a WebRTC peer connection + * Available since GStreamer 1.14 + */ +public enum WebRTCPeerConnectionState { + /** New WebRTC connection */ + NEW, + /** A WebRTC connection is being made */ + CONNECTING, + /** A WebRTC connection has been made */ + CONNECTED, + /** A WebRTC connection has been disconnected */ + DISCONNECTED, + /** Attempt to make a WebRTC connection failed */ + FAILED, + /** A WebRTC connection has been closed */ + CLOSED, + /** Unknown result */ + @DefaultEnumValue UNKNOWN; +} diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java index 7562cf65..6acee384 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2018 Vinicius Tona + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + package org.freedesktop.gstreamer; import static org.freedesktop.gstreamer.lowlevel.GstWebRTCSessionDescriptionAPI.GSTWEBRTCSESSIONDESCRIPTION_API; @@ -24,17 +41,28 @@ public WebRTCSessionDescription(Initializer init) { sessionDescriptionStruct = new GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct(handle()); } + /** + * Creates a new instance of WebRTCSessionDescription. + * + * @param type The {@link WebRTCSDPType} type of the session description + * @param sdpMessage The {@link SDPMessage} of the session description + */ public WebRTCSessionDescription(WebRTCSDPType type, SDPMessage sdpMessage) { this(initializer(GSTWEBRTCSESSIONDESCRIPTION_API.ptr_gst_webrtc_session_description_new(type, sdpMessage))); } - protected void disposeNativeHandle(Pointer ptr) { - GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_free(ptr); - } - + /** + * Get the SDPMessage from the WebRTCSessionDescription. + * + * @return the {@link SDPMessage} for the WebRTCSessionDescription + */ public SDPMessage getSDPMessage() { SDPMessage sdp = (SDPMessage)sessionDescriptionStruct.readField("sdp"); return sdp; } + @Override + protected void disposeNativeHandle(Pointer ptr) { + GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_free(ptr); + } } diff --git a/src/org/freedesktop/gstreamer/elements/WebRTCBin.java b/src/org/freedesktop/gstreamer/elements/WebRTCBin.java new file mode 100644 index 00000000..27322e00 --- /dev/null +++ b/src/org/freedesktop/gstreamer/elements/WebRTCBin.java @@ -0,0 +1,263 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under + * the terms of the GNU Lesser General Public License version 3 only, as + * published by the Free Software Foundation. + * + * This code 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 + * version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with this work. If not, see . + */ + +package org.freedesktop.gstreamer.elements; + +import org.freedesktop.gstreamer.Bin; +import org.freedesktop.gstreamer.Element; +import org.freedesktop.gstreamer.Promise; +import org.freedesktop.gstreamer.State; +import org.freedesktop.gstreamer.Structure; +import org.freedesktop.gstreamer.GstObject; +import org.freedesktop.gstreamer.WebRTCSessionDescription; +import org.freedesktop.gstreamer.WebRTCPeerConnectionState; + +import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback; + +import com.sun.jna.Pointer; +import com.sun.jna.ptr.PointerByReference; + +/** + * WebRTCBin is an abstraction over gstreamers webrtcbin element + * It is structured to mimic the RTCPeerConnection API that is available in web browsers + * @see https://developer.mozilla.org/en-US/docs/Web/API/RTCPeerConnection + * + * @see https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/blob/master/ext/webrtc/gstwebrtcbin.c + * available since Gstreamer 1.14 + */ +public class WebRTCBin extends Bin { + public static final String GST_NAME = "webrtcbin"; + public static final String GTYPE_NAME = "GstWebrtcBin"; + + public WebRTCBin(Initializer init) { + super(init); + } + + public WebRTCBin(String name) { + super(makeRawElement(GST_NAME, name)); + } + + /** + * Signal emitted when this {@link WebRTCBin} is ready to do negotiation to setup a WebRTC connection + * Good starting point to have the WebRTCBin send an offer to potential clients + */ + public static interface ON_NEGOTIATION_NEEDED { + /** + * @param elem the original webrtc bin that had the callback attached to + */ + public void onNegotiationNeeded(Element elem); + } + + /* + * Signal emmited when this {@link WebRTCBin} gets a new ice candidate + */ + public static interface ON_ICE_CANDIDATE { + /** + * @param sdpMLineIndex the zero-based index of the m-line attribute within the SDP to which the candidate should be associated to + * @param candidate the ICE candidate + */ + public void onIceCandidate(int sdpMLineIndex, String candidate); + } + + /** + * Signal emitted when this {@link WebRTCBin} creates an offer + */ + public static interface CREATE_OFFER { + /** + * @param a @WebRTCSessionDescription of the offer + */ + public void onOfferCreated(WebRTCSessionDescription offer); + } + + /** + * Signal emitted when this {@link WebRTCBin} creates an answer + */ + public static interface CREATE_ANSWER { + /** + * @param a @WebRTCSessionDescription of the answer + */ + public void onAnswerCreated(WebRTCSessionDescription answer); + } + + /** + * Adds a listener for the on-negotiation-needed signal. + * @param listener + */ + public void connect(final ON_NEGOTIATION_NEEDED listener) { + connect(ON_NEGOTIATION_NEEDED.class, listener, new GstCallback() { + @SuppressWarnings("unused") + public void callback(Element elem) { + listener.onNegotiationNeeded(elem); + } + }); + } + + /** + * Adds a listener for the on-ice-candidate signal. + * @param listener + */ + public void connect(final ON_ICE_CANDIDATE listener) { + connect(ON_ICE_CANDIDATE.class, listener, new GstCallback() { + @SuppressWarnings("unused") + public void callback(int sdpMLineIndex, String candidate) { + listener.onIceCandidate(sdpMLineIndex, candidate); + } + }); + } + + /** + * Create an offer that can be sent to other clients to setup a WebRTC connection. + *

+ * In most cases {@link #setLocalDescription} should be called after an answer is created + * + * @param listener callback that is called when a offer is created + */ + public void createOffer(final CREATE_OFFER listener) { + Promise promise = new Promise(new Promise.PROMISE_CHANGE() { + @SuppressWarnings("unused") + public void onChange(Promise promise) { + Structure reply = promise.getReply(); + WebRTCSessionDescription description = (WebRTCSessionDescription)reply.getValue("offer"); + listener.onOfferCreated(description); + promise.dispose(); + } + }); + emit("create-offer", null, promise); + } + + /** + * Create an answer in response to an offer received in order for the WebRTC signaling protocol to start. + *

+ * Should be called after {@link #setRemoteDescription} is called + *

+ * In most cases {@link #setLocalDescription} should be called after an answer is created + * + * @param listener callback that is called when an answer is created. + */ + public void createAnswer(final CREATE_ANSWER listener) { + Promise promise = new Promise(new Promise.PROMISE_CHANGE() { + @SuppressWarnings("unused") + public void onChange(Promise promise) { + Structure reply = promise.getReply(); + WebRTCSessionDescription description = (WebRTCSessionDescription)reply.getValue("answer"); + listener.onAnswerCreated(description); + promise.dispose(); + } + }); + emit("create-answer", null, promise); + } + + /** + * Adds a remote ice candidate to the bin + * + * @param sdpMLineIndex the zero-based index of the m-line attribute within the SDP to which the candidate should be associated to + * @param candidate the ICE candidate + */ + public void addIceCandidate(int sdpMLineIndex, String candidate) { + emit("add-ice-candidate", sdpMLineIndex, candidate); + } + + /** + * Sets the local description for the WebRTC connection. + * Should be called after {@link #createOffer} or {@link #createAnser} is called. + * + * @param description the {@link WebRTCSessionDescription} to set for the local description + */ + public void setLocalDescription(WebRTCSessionDescription description) { + Promise promise = new Promise(); + emit("set-local-description", description, promise); + promise.interrupt(); + promise.dispose(); + } + + /** + * Sets the remote description for the WebRTC connection. + * Shoud be called after receiving an offer or answer from other clients. + * + * @param description the {@link WebRTCSessionDescription} to set for the remote description + */ + public void setRemoteDescription(WebRTCSessionDescription description) { + Promise promise = new Promise(); + emit("set-remote-description", description, promise); + promise.interrupt(); + promise.dispose(); + } + + /** + * Sets the stun-server property for this {@link WebRTCBin} which is use to gather ICE data + * + * @param server STUN server url + */ + public void setStunServer(String server) { + set("stun-server", server); + } + + /** + * Retrieves the STUN server that is used. + * + * @return the url for the STUN server + */ + public String getStunServer() { + return (String)get("stun-server"); + } + + /** + * Sets the turn-server property for this {@link WebRTCBin} which is used whenever a direct peer-to-peer connection can be established + * + * @param server TURN server url + */ + public void setTurnServer(String server) { + set("turn-server", server); + } + + /** + * Retrieves the TURN server that is used. + * + * @return the url for the TURN server + */ + public String getTurnServer() { + return (String)get("turn-server"); + } + + /** + * Retrieve the connection state this {@link WebRTCBin} is currently in + * + * @return a {@link WebRTCPeerConnectionState} describing the connection state + */ + public WebRTCPeerConnectionState getConnectionState() { + return (WebRTCPeerConnectionState)get("connection-state"); + } + + /** + * Retrieve the local description for this {@link WebRTCBin} + * + * @return the local {@link WebRTCSessionDescription} + */ + public WebRTCSessionDescription getLocalDescription() { + return (WebRTCSessionDescription)get("local-description"); + } + + /** + * Retrieve the remote description for this {@link WebRTCBin} + * + * @return the remote {@link WebRTCSessionDescription} + */ + public WebRTCSessionDescription getRemoteDescription() { + return (WebRTCSessionDescription)get("remote-description"); + } +} diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java index ee27c7aa..0cd04d99 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstPromiseAPI.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2009 Levente Farkas Copyright (c) 2007, 2008 Wayne Meissner + * Copyright (c) 2018 Vinicius Tona + * Copyright (c) 2018 Antonio Morales * * This file is part of gstreamer-java. * @@ -34,53 +35,40 @@ * @see https://github.com/GStreamer/gstreamer/blob/master/gst/gstpromise.h * available since GStreamer 1.14 */ - -public interface GstPromiseAPI extends com.sun.jna.Library -{ +public interface GstPromiseAPI extends com.sun.jna.Library { GstPromiseAPI GSTPROMISE_API = GstNative.load(GstPromiseAPI.class); - public static final class PromiseStruct extends com.sun.jna.Structure - { + public static final class PromiseStruct extends com.sun.jna.Structure { public volatile MiniObjectStruct parent; - public PromiseStruct() - { + public PromiseStruct() { } - public PromiseStruct(Pointer ptr) - { + public PromiseStruct(Pointer ptr) { useMemory(ptr); } @Override - protected List getFieldOrder() - { + protected List getFieldOrder() { return Arrays.asList(new String[] { "parent" }); } } GType gst_promise_get_type(); + GType gst_static_promise_get_type(); @CallerOwnsReturn Promise gst_promise_new(); - @CallerOwnsReturn Pointer ptr_gst_promise_new(); - @CallerOwnsReturn - Promise gst_promise_new_with_change_func(GstCallback callback); - - @CallerOwnsReturn - Pointer ptr_gst_promise_new_with_change_func(GstCallback callback); + @CallerOwnsReturn Promise gst_promise_new_with_change_func(GstCallback callback); + @CallerOwnsReturn Pointer ptr_gst_promise_new_with_change_func(GstCallback callback); PromiseResult gst_promise_wait(Promise promise); void gst_promise_reply(Promise promise, Structure s); - void gst_promise_interrupt(Promise promise); - void gst_promise_expire(Promise promise); @CallerOwnsReturn Structure gst_promise_get_reply(Promise promise); @CallerOwnsReturn Pointer ptr_gst_promise_get_reply(Promise promise); - - GType gst_static_promise_get_type(); } diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java index 77b22307..92723059 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java @@ -1,3 +1,19 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * This code is free software: you can redistribute it and/or modify it under the terms of the GNU + * Lesser General Public License version 3 only, as published by the Free Software Foundation. + * + * This code 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 version 3 for more details. + * + * You should have received a copy of the GNU Lesser General Public License version 3 along with + * this work. If not, see . + */ + package org.freedesktop.gstreamer.lowlevel; import java.util.Arrays; @@ -9,110 +25,107 @@ import com.sun.jna.Pointer; +/** + * GstSDPMessage methods and structures + * + * @see https://github.com/GStreamer/gst-plugins-base/blob/master/gst-libs/gst/sdp/gstsdpmessage.h + */ public interface GstSDPMessageAPI extends com.sun.jna.Library { - GstSDPMessageAPI GSTSDPMESSAGE_API = GstNative.load("gstsdp", GstSDPMessageAPI.class); - - public static final class SDPMessageStruct extends com.sun.jna.Structure { - public volatile String version; - public volatile SDPOriginStruct origin; - public volatile String session_name; - public volatile String information; - public volatile String uri; - public volatile GValueArray emails; - public volatile GValueArray phones; - public volatile SDPConnectionStruct connection; - public volatile GValueArray bandwidths; - public volatile GValueArray times; - public volatile GValueArray zones; - public volatile SDPKeyStruct key; - public volatile GValueArray attributes; - public volatile GValueArray medias; - - public SDPMessageStruct(final Pointer ptr) { - useMemory(ptr); - } - - @Override - protected List getFieldOrder() { - return Arrays.asList(new String[] { - "version", - "origin", - "session_name", - "information", - "uri", - "emails", - "phones", - "connection", - "bandwidths", - "times", - "zones", - "key", - "attributes", - "medias" - }); - } + GstSDPMessageAPI GSTSDPMESSAGE_API = GstNative.load("gstsdp", GstSDPMessageAPI.class); + + public static final class SDPMessageStruct extends com.sun.jna.Structure { + public volatile String version; + public volatile SDPOriginStruct origin; + public volatile String session_name; + public volatile String information; + public volatile String uri; + public volatile GValueArray emails; + public volatile GValueArray phones; + public volatile SDPConnectionStruct connection; + public volatile GValueArray bandwidths; + public volatile GValueArray times; + public volatile GValueArray zones; + public volatile SDPKeyStruct key; + public volatile GValueArray attributes; + public volatile GValueArray medias; + + public SDPMessageStruct(final Pointer ptr) { + useMemory(ptr); } - public static final class SDPOriginStruct extends com.sun.jna.Structure { - public volatile String username; - public volatile String sess_id; - public volatile String sess_version; - public volatile String nettype; - public volatile String addrtype; - public volatile String addr; + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { + "version", "origin", "session_name", "information", "uri", + "emails", "phones", "connection", "bandwidths", "times", + "zones", "key", "attributes", "medias" + }); + } + } + + public static final class SDPOriginStruct extends com.sun.jna.Structure { + public volatile String username; + public volatile String sess_id; + public volatile String sess_version; + public volatile String nettype; + public volatile String addrtype; + public volatile String addr; + + public SDPOriginStruct(final Pointer ptr) { + useMemory(ptr); + } - public SDPOriginStruct(final Pointer ptr) { - useMemory(ptr); - } + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { + "username", "sess_id", "sess_version", "nettype", "addrtype", "addr" + }); + } + } - @Override - protected List getFieldOrder() { - return Arrays.asList(new String[] { "username", "sess_id", "sess_version", "nettype", "addrtype", "addr" }); - } + public static final class SDPKeyStruct extends com.sun.jna.Structure { + public volatile String type; + public volatile String data; + public SDPKeyStruct(final Pointer ptr) { + useMemory(ptr); } - public static final class SDPKeyStruct extends com.sun.jna.Structure { - public volatile String type; - public volatile String data; + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { "type", "data" }); + } + } - public SDPKeyStruct(final Pointer ptr) { - useMemory(ptr); - } + public static final class SDPConnectionStruct extends com.sun.jna.Structure { + public volatile String nettype; + public volatile String addrtype; + public volatile String address; + public volatile int ttl; + public volatile int addr_number; - @Override - protected List getFieldOrder() { - return Arrays.asList(new String[] { "type", "data" }); - } + public SDPConnectionStruct(final Pointer ptr) { + useMemory(ptr); } - public static final class SDPConnectionStruct extends com.sun.jna.Structure { - public volatile String nettype; - public volatile String addrtype; - public volatile String address; - public volatile int ttl; - public volatile int addr_number; - - public SDPConnectionStruct(final Pointer ptr) { - useMemory(ptr); - } - - @Override - protected List getFieldOrder() { - return Arrays.asList(new String[] { "nettype", "addrtype", "address", "ttl", "addr_number" }); - } + @Override + protected List getFieldOrder() { + return Arrays.asList(new String[] { + "nettype", "addrtype", "address", "ttl", "addr_number" + }); } + } - SDPResult gst_sdp_connection_set(SDPConnectionStruct conn, String nettype, String address, int ttl, int addr_number); - SDPResult gst_sdp_connection_clear(SDPConnectionStruct conn); + SDPResult gst_sdp_connection_set(SDPConnectionStruct conn, String nettype, String address, int ttl, int addr_number); + SDPResult gst_sdp_connection_clear(SDPConnectionStruct conn); - SDPResult gst_sdp_message_free(Pointer msg); - SDPResult ptr_gst_sdp_message_free(Pointer msg); + SDPResult gst_sdp_message_free(Pointer msg); + SDPResult ptr_gst_sdp_message_free(Pointer msg); - SDPResult gst_sdp_message_new(Pointer[] msg); + SDPResult gst_sdp_message_new(Pointer[] msg); - SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, Pointer[] msg); - SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, SDPMessage msg); + SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, Pointer[] msg); + SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, SDPMessage msg); - String gst_sdp_message_as_text(SDPMessage msg); + String gst_sdp_message_as_text(SDPMessage msg); } diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java index 4be37364..fa926345 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstWebRTCSessionDescriptionAPI.java @@ -1,5 +1,6 @@ /* - * Copyright (c) 2009 Levente Farkas Copyright (c) 2007, 2008 Wayne Meissner + * Copyright (c) 2018 Vinicius Tona + * Copyright (c) 2018 Antonio Morales * * This file is part of gstreamer-java. * @@ -33,7 +34,6 @@ * @see https://github.com/GStreamer/gst-plugins-bad/blob/master/gst-libs/gst/webrtc/rtcsessiondescription.h * Available since GStreamer 1.14 */ - public interface GstWebRTCSessionDescriptionAPI extends com.sun.jna.Library { GstWebRTCSessionDescriptionAPI GSTWEBRTCSESSIONDESCRIPTION_API = GstNative.load("gstwebrtc", GstWebRTCSessionDescriptionAPI.class); @@ -53,6 +53,7 @@ protected List getFieldOrder() { } GType gst_webrtc_session_description_get_type(); + @CallerOwnsReturn WebRTCSessionDescription gst_webrtc_session_description_new(WebRTCSDPType type, SDPMessage sdp); @CallerOwnsReturn Pointer ptr_gst_webrtc_session_description_new(WebRTCSDPType type, SDPMessage sdp); From 2326047a2c5d84f00600ec285108ddf9683eebf3 Mon Sep 17 00:00:00 2001 From: a-morales Date: Thu, 29 Nov 2018 16:37:05 -0800 Subject: [PATCH 06/13] create WebRTCBin --- src/org/freedesktop/gstreamer/elements/WebRTCBin.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/freedesktop/gstreamer/elements/WebRTCBin.java b/src/org/freedesktop/gstreamer/elements/WebRTCBin.java index 27322e00..4d6875eb 100644 --- a/src/org/freedesktop/gstreamer/elements/WebRTCBin.java +++ b/src/org/freedesktop/gstreamer/elements/WebRTCBin.java @@ -114,7 +114,7 @@ public void callback(Element elem) { public void connect(final ON_ICE_CANDIDATE listener) { connect(ON_ICE_CANDIDATE.class, listener, new GstCallback() { @SuppressWarnings("unused") - public void callback(int sdpMLineIndex, String candidate) { + public void callback(Element elem, int sdpMLineIndex, String candidate) { listener.onIceCandidate(sdpMLineIndex, candidate); } }); From 81bc8d2755cc858c70d9166f13b69c6a059c4ba4 Mon Sep 17 00:00:00 2001 From: a-morales Date: Thu, 29 Nov 2018 12:30:08 -0800 Subject: [PATCH 07/13] add isEqual to Structure --- src/org/freedesktop/gstreamer/Structure.java | 9 +++++++++ .../freedesktop/gstreamer/lowlevel/GstStructureAPI.java | 1 + .../gstreamer/lowlevel/LowLevelStructureTest.java | 3 ++- 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/org/freedesktop/gstreamer/Structure.java b/src/org/freedesktop/gstreamer/Structure.java index 2273e2a8..988c0a3c 100644 --- a/src/org/freedesktop/gstreamer/Structure.java +++ b/src/org/freedesktop/gstreamer/Structure.java @@ -623,6 +623,15 @@ public String getName(int i) { return GSTSTRUCTURE_API.gst_structure_nth_field_name(this, i); } + /** + * Checks that two structures are equal + * @param structure the stucture to check if it's equal to this structure + * @return true if both structures are equal + */ + public boolean isEqual(Structure structure) { + return GSTSTRUCTURE_API.gst_structure_is_equal(this, structure); + } + @Override public String toString() { return GSTSTRUCTURE_API.gst_structure_to_string(this); diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstStructureAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstStructureAPI.java index 8827954f..d5721789 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstStructureAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstStructureAPI.java @@ -57,6 +57,7 @@ public interface GstStructureAPI extends com.sun.jna.Library { String gst_structure_nth_field_name(Structure structure, int index); boolean gst_structure_has_field(Structure structure, String fieldname); boolean gst_structure_has_field_typed(Structure structure, String fieldname, GType type); + boolean gst_structure_is_equal(Structure structure1, Structure structure2); /* utility functions */ boolean gst_structure_get_boolean(Structure structure, String fieldname, int[] value); diff --git a/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java b/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java index 80cada23..244cd6fc 100644 --- a/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java +++ b/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java @@ -179,7 +179,8 @@ private static void initStructList() { structs.add(GstQueryAPI.QueryStruct.class); - + structs.add(GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct.class); + structs.add(GstSDPMessageAPI.SDPMessageStruct.class); } } From 8fae2322a24991cd4a110513ff87f081c2c55fa4 Mon Sep 17 00:00:00 2001 From: a-morales Date: Thu, 29 Nov 2018 12:30:37 -0800 Subject: [PATCH 08/13] add tests for Promise --- src/org/freedesktop/gstreamer/Promise.java | 6 +- src/org/freedesktop/gstreamer/SDPMessage.java | 16 +++- .../gstreamer/lowlevel/GstSDPMessageAPI.java | 1 + .../freedesktop/gstreamer/PromiseTest.java | 86 +++++++++++++++++++ .../lowlevel/LowLevelStructureTest.java | 1 + 5 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 test/org/freedesktop/gstreamer/PromiseTest.java diff --git a/src/org/freedesktop/gstreamer/Promise.java b/src/org/freedesktop/gstreamer/Promise.java index 1e82dd2b..683f062e 100644 --- a/src/org/freedesktop/gstreamer/Promise.java +++ b/src/org/freedesktop/gstreamer/Promise.java @@ -57,12 +57,12 @@ public Promise() { * @param listerner Listener to be called whenever the state of a {@link Promise} is changed */ public Promise(final PROMISE_CHANGE listener) { - this(initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(new GstCallback() { + this(new Initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(new GstCallback() { @SuppressWarnings("unused") public void callback(Promise promise, Pointer userData) { listener.onChange(promise); } - }))); + }), false, false)); } protected static Initializer initializer(final Pointer ptr) { @@ -118,6 +118,6 @@ public void expire() { * @return the {@link Structure} set on the promise reply. */ public Structure getReply() { - return GSTPROMISE_API.gst_promise_get_reply(this); + return Structure.objectFor(GSTPROMISE_API.gst_promise_get_reply(this), false, false); } } diff --git a/src/org/freedesktop/gstreamer/SDPMessage.java b/src/org/freedesktop/gstreamer/SDPMessage.java index cbdadab3..38906f08 100644 --- a/src/org/freedesktop/gstreamer/SDPMessage.java +++ b/src/org/freedesktop/gstreamer/SDPMessage.java @@ -67,14 +67,24 @@ public void parseBuffer(String sdpString) { GSTSDPMESSAGE_API.gst_sdp_message_parse_buffer(data, length, this); } - protected static Initializer initializer(final Pointer ptr) { - return new Initializer(ptr, false, true); + /** + * Creates a copy of this SDPMessage. + * + * @return a copy of SDPMessage. + */ + public SDPMessage copy(boolean shouldInvalidateOriginal) { + Pointer[] ptr = new Pointer[1]; + GSTSDPMESSAGE_API.gst_sdp_message_copy(this, ptr); + if (shouldInvalidateOriginal) { + this.invalidate(); + } + return new SDPMessage(initializer(ptr[0])); } private static Initializer initializer() { Pointer[] ptr = new Pointer[1]; GSTSDPMESSAGE_API.gst_sdp_message_new(ptr); - return initializer(ptr[0], false, true); + return initializer(ptr[0]); } protected void disposeNativeHandle(Pointer ptr) { diff --git a/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java b/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java index 92723059..374e6775 100644 --- a/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java +++ b/src/org/freedesktop/gstreamer/lowlevel/GstSDPMessageAPI.java @@ -126,6 +126,7 @@ protected List getFieldOrder() { SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, Pointer[] msg); SDPResult gst_sdp_message_parse_buffer(byte[] data, int size, SDPMessage msg); + SDPResult gst_sdp_message_copy(SDPMessage msg, Pointer[] copy); String gst_sdp_message_as_text(SDPMessage msg); } diff --git a/test/org/freedesktop/gstreamer/PromiseTest.java b/test/org/freedesktop/gstreamer/PromiseTest.java new file mode 100644 index 00000000..8804f4e5 --- /dev/null +++ b/test/org/freedesktop/gstreamer/PromiseTest.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2018 Antonio Morales + * + * This file is part of gstreamer-java. + * + * gstreamer-java 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 3 of the License, or + * (at your option) any later version. + * + * gstreamer-java 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 gstreamer-java. If not, see . + */ +package org.freedesktop.gstreamer; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import org.freedesktop.gstreamer.lowlevel.GType; +import org.junit.BeforeClass; +import org.junit.AfterClass; +import org.junit.Test; + +public class PromiseTest { + + public PromiseTest() { + } + + @BeforeClass + public static void setUpClass() throws Exception { + Gst.init("PromiseTest", new String[] {}); + } + + @AfterClass + public static void tearDownClass() throws Exception { + Gst.deinit(); + } + + @Test + public void testReply() { + Promise promise = new Promise(); + + promise.reply(null); + + PromiseResult promiseStatus = promise.waitResult(); + + assertEquals("promise reply state not correct", promiseStatus, PromiseResult.REPLIED); + } + + @Test + public void testInterrupt() { + Promise promise = new Promise(); + promise.interrupt(); + + PromiseResult promiseStatus = promise.waitResult(); + + assertEquals("promise reply state not correct", promiseStatus, PromiseResult.INTERRUPTED); + } + + @Test + public void testExpire() { + Promise promise = new Promise(); + promise.expire(); + + PromiseResult promiseStatus = promise.waitResult(); + + assertEquals("promise reply state not correct", promiseStatus, PromiseResult.EXPIRED); + } + + @Test + public void testReplyData() { + Promise promise = new Promise(); + Structure data = new Structure("data", "test", GType.UINT, 1); + + 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)); + } +} diff --git a/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java b/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java index 244cd6fc..9fdf2184 100644 --- a/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java +++ b/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java @@ -181,6 +181,7 @@ private static void initStructList() { structs.add(GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct.class); structs.add(GstSDPMessageAPI.SDPMessageStruct.class); + structs.add(GstPromiseAPI.PromiseStruct.class); } } From b01f75b1f5a8a0092095c4950c25028ba6d4b227 Mon Sep 17 00:00:00 2001 From: a-morales Date: Mon, 17 Dec 2018 11:19:48 -0800 Subject: [PATCH 09/13] handle WebRTCSessionDescription memory ownership properly --- .../gstreamer/WebRTCSessionDescription.java | 9 ++++++--- .../freedesktop/gstreamer/elements/WebRTCBin.java | 12 ++++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java index 6acee384..aff016d3 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -52,13 +52,16 @@ public WebRTCSessionDescription(WebRTCSDPType type, SDPMessage sdpMessage) { } /** - * Get the SDPMessage from the WebRTCSessionDescription. + * Gets the SDPMessage from the WebRTCSessionDescription. * * @return the {@link SDPMessage} for the WebRTCSessionDescription */ public SDPMessage getSDPMessage() { - SDPMessage sdp = (SDPMessage)sessionDescriptionStruct.readField("sdp"); - return sdp; + SDPMessage originalSDP = (SDPMessage)sessionDescriptionStruct.readField("sdp"); + // making a copy of the SDPMessage since the original SDPMessage in the struct belongs to WebRTCSessionDescription. + // Once WebRTCSessionDescription is disposed it would also dispose of SDPMessage leading to any objects with a reference + // to the original SDPMessage to be invalid and potentially lead to runtime errors. + return originalSDP.copy(true); } @Override diff --git a/src/org/freedesktop/gstreamer/elements/WebRTCBin.java b/src/org/freedesktop/gstreamer/elements/WebRTCBin.java index 4d6875eb..589d8667 100644 --- a/src/org/freedesktop/gstreamer/elements/WebRTCBin.java +++ b/src/org/freedesktop/gstreamer/elements/WebRTCBin.java @@ -180,6 +180,8 @@ public void addIceCandidate(int sdpMLineIndex, String candidate) { */ public void setLocalDescription(WebRTCSessionDescription description) { Promise promise = new Promise(); + // the raw WebRTCBin element gets ownership of the description so it must be disown in order to prevent it from being deallocated + description.disown(); emit("set-local-description", description, promise); promise.interrupt(); promise.dispose(); @@ -193,6 +195,8 @@ public void setLocalDescription(WebRTCSessionDescription description) { */ public void setRemoteDescription(WebRTCSessionDescription description) { Promise promise = new Promise(); + // the raw WebRTCBin element gets ownership of the description so it must be disown in order to prevent it from being deallocated + description.disown(); emit("set-remote-description", description, promise); promise.interrupt(); promise.dispose(); @@ -249,7 +253,9 @@ public WebRTCPeerConnectionState getConnectionState() { * @return the local {@link WebRTCSessionDescription} */ public WebRTCSessionDescription getLocalDescription() { - return (WebRTCSessionDescription)get("local-description"); + WebRTCSessionDescription description = (WebRTCSessionDescription)get("local-description"); + description.disown(); + return description; } /** @@ -258,6 +264,8 @@ public WebRTCSessionDescription getLocalDescription() { * @return the remote {@link WebRTCSessionDescription} */ public WebRTCSessionDescription getRemoteDescription() { - return (WebRTCSessionDescription)get("remote-description"); + WebRTCSessionDescription description = (WebRTCSessionDescription)get("remote-description"); + description.disown(); + return description; } } From 155ec1df62c65d9fd77ed9ef5bea4b56b84285b8 Mon Sep 17 00:00:00 2001 From: a-morales Date: Mon, 17 Dec 2018 12:35:10 -0800 Subject: [PATCH 10/13] self review --- src/org/freedesktop/gstreamer/SDPResult.java | 2 +- src/org/freedesktop/gstreamer/WebRTCSessionDescription.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/org/freedesktop/gstreamer/SDPResult.java b/src/org/freedesktop/gstreamer/SDPResult.java index 5ea67d8a..8ca26724 100644 --- a/src/org/freedesktop/gstreamer/SDPResult.java +++ b/src/org/freedesktop/gstreamer/SDPResult.java @@ -29,7 +29,7 @@ public enum SDPResult implements IntegerEnum { EINVAL(-1), /** An unknown result */ @DefaultEnumValue - __UNKNWOND_NATIVE_VALUE(~0); + __UNKNWON_NATIVE_VALUE(~0); SDPResult(int value) { this.value = value; diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java index aff016d3..d71a018d 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -64,7 +64,6 @@ public SDPMessage getSDPMessage() { return originalSDP.copy(true); } - @Override protected void disposeNativeHandle(Pointer ptr) { GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_free(ptr); } From d751a6c699cb22436031159a72c0aaa96f7d78f0 Mon Sep 17 00:00:00 2001 From: a-morales Date: Thu, 20 Dec 2018 10:27:39 -0800 Subject: [PATCH 11/13] use pointer method for Promise.getReply() --- src/org/freedesktop/gstreamer/Promise.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/org/freedesktop/gstreamer/Promise.java b/src/org/freedesktop/gstreamer/Promise.java index 683f062e..c386f05a 100644 --- a/src/org/freedesktop/gstreamer/Promise.java +++ b/src/org/freedesktop/gstreamer/Promise.java @@ -118,6 +118,6 @@ public void expire() { * @return the {@link Structure} set on the promise reply. */ public Structure getReply() { - return Structure.objectFor(GSTPROMISE_API.gst_promise_get_reply(this), false, false); + return Structure.objectFor(GSTPROMISE_API.ptr_gst_promise_get_reply(this), false, false); } } From 7664a8eeaec32c41e420c42011f6923be5625c92 Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Wed, 23 Jan 2019 18:14:50 +0000 Subject: [PATCH 12/13] Add version testing for GStreamer 1.14 to PromiseTest and webrtc related low level structure tests. --- test/org/freedesktop/gstreamer/PromiseTest.java | 15 ++++++++++++++- .../gstreamer/lowlevel/LowLevelStructureTest.java | 9 ++++++--- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/test/org/freedesktop/gstreamer/PromiseTest.java b/test/org/freedesktop/gstreamer/PromiseTest.java index 8804f4e5..516ad6ca 100644 --- a/test/org/freedesktop/gstreamer/PromiseTest.java +++ b/test/org/freedesktop/gstreamer/PromiseTest.java @@ -24,6 +24,7 @@ import org.freedesktop.gstreamer.lowlevel.GType; import org.junit.BeforeClass; import org.junit.AfterClass; +import org.junit.Before; import org.junit.Test; public class PromiseTest { @@ -40,9 +41,12 @@ public static void setUpClass() throws Exception { public static void tearDownClass() throws Exception { Gst.deinit(); } - + @Test public void testReply() { + if (Gst.getVersion().getMinor() < 14) { + return; + } Promise promise = new Promise(); promise.reply(null); @@ -54,6 +58,9 @@ public void testReply() { @Test public void testInterrupt() { + if (Gst.getVersion().getMinor() < 14) { + return; + } Promise promise = new Promise(); promise.interrupt(); @@ -64,6 +71,9 @@ public void testInterrupt() { @Test public void testExpire() { + if (Gst.getVersion().getMinor() < 14) { + return; + } Promise promise = new Promise(); promise.expire(); @@ -74,6 +84,9 @@ public void testExpire() { @Test public void testReplyData() { + if (Gst.getVersion().getMinor() < 14) { + return; + } Promise promise = new Promise(); Structure data = new Structure("data", "test", GType.UINT, 1); diff --git a/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java b/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java index 9fdf2184..89fe4592 100644 --- a/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java +++ b/test/org/freedesktop/gstreamer/lowlevel/LowLevelStructureTest.java @@ -17,6 +17,7 @@ import org.junit.Test; import com.sun.jna.Structure; +import org.freedesktop.gstreamer.Gst; /** * @@ -179,9 +180,11 @@ private static void initStructList() { structs.add(GstQueryAPI.QueryStruct.class); - structs.add(GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct.class); - structs.add(GstSDPMessageAPI.SDPMessageStruct.class); - structs.add(GstPromiseAPI.PromiseStruct.class); + if (Gst.getVersion().getMinor() >= 14) { + structs.add(GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct.class); + structs.add(GstSDPMessageAPI.SDPMessageStruct.class); + structs.add(GstPromiseAPI.PromiseStruct.class); + } } } From 82e3db3584f1930354349b1845000b75e2b7c9aa Mon Sep 17 00:00:00 2001 From: Neil C Smith Date: Wed, 23 Jan 2019 18:55:53 +0000 Subject: [PATCH 13/13] Remove GTYPE field from WebRTCSessionDescription which causes eager loading of native library. --- src/org/freedesktop/gstreamer/WebRTCSessionDescription.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java index d71a018d..819a5a80 100644 --- a/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java +++ b/src/org/freedesktop/gstreamer/WebRTCSessionDescription.java @@ -21,13 +21,11 @@ import org.freedesktop.gstreamer.lowlevel.GstWebRTCSessionDescriptionAPI; import org.freedesktop.gstreamer.lowlevel.NativeObject; -import org.freedesktop.gstreamer.lowlevel.GType; import com.sun.jna.Pointer; public class WebRTCSessionDescription extends NativeObject { public static final String GTYPE_NAME = "GstWebRTCSessionDescription"; - public static final GType GTYPE = GSTWEBRTCSESSIONDESCRIPTION_API.gst_webrtc_session_description_get_type(); protected GstWebRTCSessionDescriptionAPI.WebRTCSessionDescriptionStruct sessionDescriptionStruct;