Skip to content

Commit e45c0e2

Browse files
Create Bindings to enable WebRTC (#135)
* [webrtc] Adding GstPromise and GstWebRTCSessionDescription * [webrtc] [NS] Debugging * Get WebRTC related elements to work without throwing null exceptions * add hasCurrentCaps to pad * Add comments/documentation * create WebRTCBin * add isEqual to Structure * add tests for Promise * handle WebRTCSessionDescription memory ownership properly * self review * use pointer method for Promise.getReply() * Add version testing for GStreamer 1.14 to PromiseTest and webrtc related low level structure tests. * Remove GTYPE field from WebRTCSessionDescription which causes eager loading of native library.
1 parent b8814ac commit e45c0e2

18 files changed

+1129
-3
lines changed

src/org/freedesktop/gstreamer/Gst.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
* Copyright (c) 2018 Antonio Morales
23
* Copyright (c) 2018 Neil C Smith
34
* Copyright (c) 2007 Wayne Meissner
45
*
@@ -44,6 +45,7 @@
4445
import org.freedesktop.gstreamer.elements.DecodeBin;
4546
import org.freedesktop.gstreamer.elements.PlayBin;
4647
import org.freedesktop.gstreamer.elements.URIDecodeBin;
48+
import org.freedesktop.gstreamer.elements.WebRTCBin;
4749
import org.freedesktop.gstreamer.glib.GDate;
4850
import org.freedesktop.gstreamer.glib.GInetAddress;
4951
import org.freedesktop.gstreamer.glib.GSocketAddress;
@@ -619,9 +621,12 @@ private static synchronized void loadAllClasses() {
619621
PadTemplate.class,
620622
Plugin.class,
621623
PluginFeature.class,
624+
Promise.class,
622625
Query.class,
623626
Registry.class,
627+
SDPMessage.class,
624628
Sample.class,
629+
WebRTCSessionDescription.class,
625630
// ----------- Elements -------------
626631
AppSink.class,
627632
AppSrc.class,
@@ -632,6 +637,7 @@ private static synchronized void loadAllClasses() {
632637
DecodeBin.class,
633638
Pipeline.class,
634639
PlayBin.class,
635-
URIDecodeBin.class
640+
URIDecodeBin.class,
641+
WebRTCBin.class
636642
);
637643
}

src/org/freedesktop/gstreamer/Pad.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2+
* Copyright (C) 2018 Antonio Morales
23
* Copyright (C) 2014 Tom Greenwood <tgreenwood@cafex.com>
34
* Copyright (C) 2009 Tamas Korodi <kotyo@zamba.fm>
45
* Copyright (C) 2007 Wayne Meissner
56
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
67
* 2000 Wim Taymans <wtay@chello.be>
7-
*
8+
*
89
* This file is part of gstreamer-java.
910
*
1011
* This code is free software: you can redistribute it and/or modify it under
@@ -689,4 +690,13 @@ public PadTemplate getTemplate() {
689690
return GSTPAD_API.gst_pad_get_pad_template(this);
690691
}
691692

693+
694+
/**
695+
* Check if the pad has caps set on it with a GST_EVENT_CAPS events
696+
*
697+
* @return true if the pad has caps set
698+
*/
699+
public boolean hasCurrentCaps() {
700+
return GSTPAD_API.gst_pad_has_current_caps(this);
701+
}
692702
}
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
/*
2+
* Copyright (c) 2018 Vinicius Tona
3+
* Copyright (c) 2018 Antonio Morales
4+
*
5+
* This file is part of gstreamer-java.
6+
*
7+
* This code is free software: you can redistribute it and/or modify it under the terms of the GNU
8+
* Lesser General Public License version 3 only, as published by the Free Software Foundation.
9+
*
10+
* This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
11+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License version 3 for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public License version 3 along with
15+
* this work. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
18+
package org.freedesktop.gstreamer;
19+
20+
import static org.freedesktop.gstreamer.lowlevel.GstPromiseAPI.GSTPROMISE_API;
21+
22+
import org.freedesktop.gstreamer.lowlevel.GstAPI.GstCallback;
23+
24+
import com.sun.jna.Pointer;
25+
26+
public class Promise extends MiniObject {
27+
public static final String GTYPE_NAME = "GstPromise";
28+
29+
public static interface PROMISE_CHANGE {
30+
/**
31+
* Called whenever the state of the promise is changed from PENDING to any other {@link PromiseResult}
32+
*
33+
* @param promise the original promise that had the callback attached to
34+
*/
35+
public void onChange(Promise promise);
36+
}
37+
38+
/**
39+
* Creates a new instance of Promise. This constructor is used internally.
40+
*
41+
* @param init internal initialization data.
42+
*/
43+
public Promise(final Initializer init) {
44+
super(init);
45+
}
46+
47+
/**
48+
* Creates a new instance of promise
49+
*/
50+
public Promise() {
51+
this(initializer(GSTPROMISE_API.ptr_gst_promise_new()));
52+
}
53+
54+
/**
55+
* Creates a new instance of promise with a callback attached.
56+
*
57+
* @param listerner Listener to be called whenever the state of a {@link Promise} is changed
58+
*/
59+
public Promise(final PROMISE_CHANGE listener) {
60+
this(new Initializer(GSTPROMISE_API.ptr_gst_promise_new_with_change_func(new GstCallback() {
61+
@SuppressWarnings("unused")
62+
public void callback(Promise promise, Pointer userData) {
63+
listener.onChange(promise);
64+
}
65+
}), false, false));
66+
}
67+
68+
protected static Initializer initializer(final Pointer ptr) {
69+
return new Initializer(ptr, false, true);
70+
}
71+
72+
/**
73+
* Wait for the promise to move out of the PENDING {@link PromiseResult} state.
74+
* If the promise is not in PENDING then it will immediately return.
75+
*
76+
* @return the {@link PromiseResult} of the promise.
77+
*/
78+
public PromiseResult waitResult() {
79+
return GSTPROMISE_API.gst_promise_wait(this);
80+
}
81+
82+
/**
83+
* Set a reply on the promise.
84+
*
85+
* Will wake up any waiters on the promise with the REPLIED {@link PromiseResult} state.
86+
* If the promise has already been interrupted than the replied will not be visible to any waiters
87+
*
88+
* @param structure the {@link Structure} to reply the promise with
89+
*/
90+
public void reply(final Structure structure) {
91+
GSTPROMISE_API.gst_promise_reply(this, structure);
92+
}
93+
94+
/**
95+
* Interrupt waiting for the result of the prommise.
96+
*
97+
* Any waiters on the promise will receive the INTERRUPTED {@link PromiseResult} state.
98+
*/
99+
public void interrupt() {
100+
GSTPROMISE_API.gst_promise_interrupt(this);
101+
}
102+
103+
/**
104+
* Expire a promise.
105+
*
106+
* Any waiters on the promise will recieved the EXPIRED {@link PromiseResult} state.
107+
*/
108+
public void expire() {
109+
GSTPROMISE_API.gst_promise_expire(this);
110+
}
111+
112+
/**
113+
* Retrieve the reply set on the promise.
114+
*
115+
* The state of the promise must be in the REPLIED {@link PromiseResult} state.
116+
* The return structure is owned by the promise and thus cannot be modified.
117+
*
118+
* @return the {@link Structure} set on the promise reply.
119+
*/
120+
public Structure getReply() {
121+
return Structure.objectFor(GSTPROMISE_API.ptr_gst_promise_get_reply(this), false, false);
122+
}
123+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2018 Antonio Morales
3+
*
4+
* This file is part of gstreamer-java.
5+
*
6+
* This code is free software: you can redistribute it and/or modify it under the terms of the GNU
7+
* Lesser General Public License version 3 only, as published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* Lesser General Public License version 3 for more details.
12+
*
13+
* You should have received a copy of the GNU Lesser General Public License version 3 along with
14+
* this work. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package org.freedesktop.gstreamer;
18+
19+
import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue;
20+
21+
/**
22+
* The result of a {@link Promise}
23+
* Available since GStreamer 1.14
24+
*/
25+
public enum PromiseResult {
26+
/** The initial state of a promise */
27+
PENDING,
28+
/** The promise was interrupted */
29+
INTERRUPTED,
30+
/** The promise has been resolved and it has a value */
31+
REPLIED,
32+
/** The promise is expired and won't return a result */
33+
EXPIRED,
34+
/** Unknown result */
35+
@DefaultEnumValue UNKNOWN;
36+
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Copyright (c) 2018 Antonio Morales
3+
*
4+
* This file is part of gstreamer-java.
5+
*
6+
* This code is free software: you can redistribute it and/or modify it under the terms of the GNU
7+
* Lesser General Public License version 3 only, as published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* Lesser General Public License version 3 for more details.
12+
*
13+
* You should have received a copy of the GNU Lesser General Public License version 3 along with
14+
* this work. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package org.freedesktop.gstreamer;
18+
19+
import java.nio.charset.StandardCharsets;
20+
21+
import static org.freedesktop.gstreamer.lowlevel.GstSDPMessageAPI.GSTSDPMESSAGE_API;
22+
23+
import org.freedesktop.gstreamer.lowlevel.NativeObject;
24+
25+
import com.sun.jna.Pointer;
26+
27+
public class SDPMessage extends NativeObject {
28+
public static final String GTYPE_NAME = "GstSDPMessage";
29+
30+
/**
31+
* Internally used constructor. Do not use.
32+
*
33+
* @param init internal initialization data
34+
*/
35+
public SDPMessage(Initializer init) {
36+
super(init);
37+
}
38+
39+
/**
40+
* Creates a new instance of SDPMessage
41+
*/
42+
public SDPMessage() {
43+
this(initializer());
44+
}
45+
46+
/**
47+
* A SDP formatted string representation of SDPMessage.
48+
*
49+
* Used for offer/answer exchanges for real time communicationse
50+
*
51+
* @return the SDP string representation of SDPMessage.
52+
*/
53+
public String toString() {
54+
return GSTSDPMESSAGE_API.gst_sdp_message_as_text(this);
55+
}
56+
57+
/**
58+
* Takes a SDP string and parses it and fills in all fields for SDPMessage.
59+
*
60+
* Look at https://tools.ietf.org/html/rfc4566 for more information on SDP
61+
*
62+
* @param sdpString the sdp string
63+
*/
64+
public void parseBuffer(String sdpString) {
65+
byte[] data = sdpString.getBytes(StandardCharsets.US_ASCII);
66+
int length = sdpString.length();
67+
GSTSDPMESSAGE_API.gst_sdp_message_parse_buffer(data, length, this);
68+
}
69+
70+
/**
71+
* Creates a copy of this SDPMessage.
72+
*
73+
* @return a copy of SDPMessage.
74+
*/
75+
public SDPMessage copy(boolean shouldInvalidateOriginal) {
76+
Pointer[] ptr = new Pointer[1];
77+
GSTSDPMESSAGE_API.gst_sdp_message_copy(this, ptr);
78+
if (shouldInvalidateOriginal) {
79+
this.invalidate();
80+
}
81+
return new SDPMessage(initializer(ptr[0]));
82+
}
83+
84+
private static Initializer initializer() {
85+
Pointer[] ptr = new Pointer[1];
86+
GSTSDPMESSAGE_API.gst_sdp_message_new(ptr);
87+
return initializer(ptr[0]);
88+
}
89+
90+
protected void disposeNativeHandle(Pointer ptr) {
91+
GSTSDPMESSAGE_API.gst_sdp_message_free(ptr);
92+
}
93+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2018 Antonio Morales
3+
*
4+
* This file is part of gstreamer-java.
5+
*
6+
* This code is free software: you can redistribute it and/or modify it under the terms of the GNU
7+
* Lesser General Public License version 3 only, as published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
10+
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11+
* Lesser General Public License version 3 for more details.
12+
*
13+
* You should have received a copy of the GNU Lesser General Public License version 3 along with
14+
* this work. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package org.freedesktop.gstreamer;
18+
19+
import org.freedesktop.gstreamer.lowlevel.IntegerEnum;
20+
import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue;
21+
22+
/**
23+
* The possible results for {@link SDPMessage} functions
24+
*/
25+
public enum SDPResult implements IntegerEnum {
26+
/** A successful return value*/
27+
OK(0),
28+
/** A function to SDPMessage was given invalid paramters */
29+
EINVAL(-1),
30+
/** An unknown result */
31+
@DefaultEnumValue
32+
__UNKNWON_NATIVE_VALUE(~0);
33+
34+
SDPResult(int value) {
35+
this.value = value;
36+
}
37+
38+
/**
39+
* Gets the integer value of the enum
40+
* @return the integer value for this enum.
41+
*/
42+
public int intValue() {
43+
return value;
44+
}
45+
46+
private int value;
47+
}

src/org/freedesktop/gstreamer/Structure.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -623,6 +623,15 @@ public String getName(int i) {
623623
return GSTSTRUCTURE_API.gst_structure_nth_field_name(this, i);
624624
}
625625

626+
/**
627+
* Checks that two structures are equal
628+
* @param structure the stucture to check if it's equal to this structure
629+
* @return true if both structures are equal
630+
*/
631+
public boolean isEqual(Structure structure) {
632+
return GSTSTRUCTURE_API.gst_structure_is_equal(this, structure);
633+
}
634+
626635
@Override
627636
public String toString() {
628637
return GSTSTRUCTURE_API.gst_structure_to_string(this);

0 commit comments

Comments
 (0)