-
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
1 parent
b8814ac
commit e45c0e2
Showing
18 changed files
with
1,129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.freedesktop.gstreamer; | ||
|
||
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 static final String GTYPE_NAME = "GstPromise"; | ||
|
||
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); | ||
} | ||
|
||
/** | ||
* Creates a new instance of promise | ||
*/ | ||
public Promise() { | ||
this(initializer(GSTPROMISE_API.ptr_gst_promise_new())); | ||
} | ||
|
||
/** | ||
* 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(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) { | ||
return new Initializer(ptr, false, true); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
/** | ||
* 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); | ||
} | ||
|
||
/** | ||
* Expire a promise. | ||
* | ||
* Any waiters on the promise will recieved the EXPIRED {@link PromiseResult} state. | ||
*/ | ||
public void expire() { | ||
GSTPROMISE_API.gst_promise_expire(this); | ||
} | ||
|
||
/** | ||
* 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 Structure.objectFor(GSTPROMISE_API.ptr_gst_promise_get_reply(this), false, false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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, | ||
/** The promise is expired and won't return a result */ | ||
EXPIRED, | ||
/** Unknown result */ | ||
@DefaultEnumValue UNKNOWN; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
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 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); | ||
} | ||
|
||
/** | ||
* 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]); | ||
} | ||
|
||
protected void disposeNativeHandle(Pointer ptr) { | ||
GSTSDPMESSAGE_API.gst_sdp_message_free(ptr); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* 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 <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.freedesktop.gstreamer; | ||
|
||
import org.freedesktop.gstreamer.lowlevel.IntegerEnum; | ||
import org.freedesktop.gstreamer.lowlevel.annotations.DefaultEnumValue; | ||
|
||
/** | ||
* 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 | ||
__UNKNWON_NATIVE_VALUE(~0); | ||
|
||
SDPResult(int value) { | ||
this.value = value; | ||
} | ||
|
||
/** | ||
* Gets the integer value of the enum | ||
* @return the integer value for this enum. | ||
*/ | ||
public int intValue() { | ||
return value; | ||
} | ||
|
||
private int value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.