Skip to content

Bugfix WebRTCBin.createOffer/createAnswer; Support for WebRTC DataChannel (string/data) - #271

Open
jw-tecuri wants to merge 4 commits into
gstreamer-java:masterfrom
jw-tecuri:master
Open

Bugfix WebRTCBin.createOffer/createAnswer; Support for WebRTC DataChannel (string/data)#271
jw-tecuri wants to merge 4 commits into
gstreamer-java:masterfrom
jw-tecuri:master

Conversation

@jw-tecuri

@jw-tecurijw-tecuri commented Jun 16, 2023

Copy link
Copy Markdown

Fixes#270

@jw-tecurijw-tecuri changed the title Avoid garbage collection of promise for createOffer/createAnswerAvoid garbage collection of promise for WebRTCBin.createOffer/createAnswerJun 18, 2023
@jw-tecurijw-tecuri changed the title Avoid garbage collection of promise for WebRTCBin.createOffer/createAnswerBugfix WebRTCBin.createOffer/createAnswer; Support for WebRTC DataChannel (string/data)Jul 8, 2023
@svnhub

Copy link
Copy Markdown

Quite useful changes! - especially the garbage collection of promises are really important. Maybe other parts of the codebase actually has the same/similar issue?

Suggestion: Add offset+length versions of the GBytes and datachannel data methods for effeciency reasons, to avoid having to copy over byte arrays in situations where only a portion needs to be used (very common). Maybe something along the lines of:

WebRTCDataChannel:

 /**
* Sends a sub-section of binary data through this {@link WebRTCDataChannel}.
*
* @param bytes The source array.
* @param offset The starting position in the source array.
* @param length The number of bytes to send.
*/
public void sendMessage(byte[] bytes, int offset, int length) {
GBytes gbytes = GBytes.createInstance(bytes, offset, length);
gbytes.disown();
emit("send-data", gbytes);
}
/**
* Sends binary data through this {@link WebRTCDataChannel} which will be received by connected remote peers.
* * @param bytes that should be sent over the WebRTC data-channel connection.
*/
public void sendMessage(byte[] bytes) {
sendMessage(bytes, 0, bytes.length);
} 

GBytes:

 /**
* Creates a GBytes instance from a sub-section of a byte array.
* @param bytes The source array.
* @param offset The starting position in the source array.
* @param length The number of bytes to copy.
* @return A new GBytes instance.
*/
public static GBytes createInstance(byte[] bytes, int offset, int length) {
// Allocate native memory specifically for the 'length' we want to copy
Pointer source = new Memory(length);
// write(long peerOffset, byte[] buf, int arrayOffset, int len)
source.write(0, bytes, offset, length);
Pointer ptr = GLIB_API.g_bytes_new(source, length);
return new GBytes(new Handle(new GPointer(ptr), true));
}
/**
* Creates a GBytes instance from the full byte array.
*/
public static GBytes createInstance(byte[] bytes) {
return createInstance(bytes, 0, bytes.length);
}

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

WebRTCBin.createAnswer() callback not called sporadically (promise garbage collected)

2 participants

@jw-tecuri@svnhub