Skip to content

Add bindings to enable WebRTC #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
9ea39d9
[webrtc] Adding GstPromise and GstWebRTCSessionDescription
vinicius-tona May 24, 2018
9593204
[webrtc] [NS] Debugging
vinicius-tona Jun 6, 2018
20ef73c
Get something that doesn't throw null pointer exception
Oct 25, 2018
c0c29c9
get WebRTCSessionDescription to return SDPMessage
Oct 26, 2018
f94c664
instantiate new empty SDPMessage
Oct 29, 2018
40285f1
add hasCurrentCaps to pad
Oct 30, 2018
59b7cec
add another constructor method for WebRTCSessionDescription
Oct 30, 2018
4309d89
clean up names for WebRTCSDPType enum
Oct 30, 2018
a34ee00
add new API structs to LowLevelStructureTest
Oct 30, 2018
12a48b6
Add comments/documentation
Oct 30, 2018
528c094
sort Base nativeClasses in Gst.java
Oct 30, 2018
7d811fa
Merge branch 'master' into webrtc-sendrecv-example
Oct 30, 2018
89b345e
add version when new bindings where available in GStreamer
Oct 31, 2018
1e7dccd
fix error in Gst.java licence comment
Oct 31, 2018
f662cee
create WebRTCBin element to make WebRTC workflow easier
Nov 29, 2018
4f615b8
add checks for parseBuffer for SDPMessage
Nov 29, 2018
07d985d
add isEqual to Structure
Nov 29, 2018
ea6ad11
add tests for Promise
Nov 29, 2018
aeba007
remove unnecessary @ovverride in WebRTCSessionDescription
Nov 29, 2018
2ccd94c
fix callback for ON_ICE_CANDIDATE event for webrtcbin
Nov 30, 2018
a04224c
update SDPMessage initializer to not own handle
Dec 3, 2018
e06d2c9
add copy method to SDPMessage
Dec 17, 2018
3069205
update initializers for Promise so that they can be properly disposed
Dec 17, 2018
befb461
handle WebRTCSessionDescription memory ownership properly
Dec 17, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/org/freedesktop/gstreamer/Gst.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2018 Antonio Morales
* Copyright (c) 2018 Neil C Smith
* Copyright (c) 2007 Wayne Meissner
*
Expand Down Expand Up @@ -44,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;
Expand Down Expand Up @@ -619,9 +621,12 @@ private static synchronized void loadAllClasses() {
PadTemplate.class,
Plugin.class,
PluginFeature.class,
Promise.class,
Query.class,
Registry.class,
SDPMessage.class,
Sample.class,
WebRTCSessionDescription.class,
// ----------- Elements -------------
AppSink.class,
AppSrc.class,
Expand All @@ -632,6 +637,7 @@ private static synchronized void loadAllClasses() {
DecodeBin.class,
Pipeline.class,
PlayBin.class,
URIDecodeBin.class
URIDecodeBin.class,
WebRTCBin.class
);
}
15 changes: 11 additions & 4 deletions src/org/freedesktop/gstreamer/Pad.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/*
* Copyright (C) 2018 Antonio Morales
* Copyright (C) 2014 Tom Greenwood <tgreenwood@cafex.com>
* Copyright (C) 2009 Tamas Korodi <kotyo@zamba.fm>
* Copyright (C) 2007 Wayne Meissner
* Copyright (C) 1999,2000 Erik Walthinsen <omega@cse.ogi.edu>
* 2000 Wim Taymans <wtay@chello.be>
*
*
* This file is part of gstreamer-java.
*
* This code is free software: you can redistribute it and/or modify it under
Expand Down Expand Up @@ -653,9 +654,7 @@ public FlowReturn getRange(long offset, int size, Buffer[] buffer) {
public FlowReturn pullRange(long offset, int size, Buffer[] buffer) {
return GSTPAD_API.gst_pad_pull_range(this, offset, size, buffer);
}




/**
* Pushes a buffer to the peer of pad .
* This function will call installed block probes before triggering any
Expand Down Expand Up @@ -689,4 +688,12 @@ 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);
}
}
123 changes: 123 additions & 0 deletions src/org/freedesktop/gstreamer/Promise.java
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.gst_promise_get_reply(this), false, false);
}
}
36 changes: 36 additions & 0 deletions src/org/freedesktop/gstreamer/PromiseResult.java
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;
}
95 changes: 95 additions & 0 deletions src/org/freedesktop/gstreamer/SDPMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*
* 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) {
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);
}
}

/**
* 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);
}
}
47 changes: 47 additions & 0 deletions src/org/freedesktop/gstreamer/SDPResult.java
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
__UNKNWOND_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;
}
9 changes: 9 additions & 0 deletions src/org/freedesktop/gstreamer/Structure.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading