Skip to content

Commit

Permalink
Merge pull request #5 from johanvos/moregroupcalls
Browse files Browse the repository at this point in the history
Add more functionality related to group-calls
  • Loading branch information
johanvos authored May 20, 2024
2 parents ce695d1 + c9f0adb commit abf4de8
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/java/tring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<dependency>
<groupId>io.privacyresearch</groupId>
<artifactId>tringapi</artifactId>
<version>0.0.12</version>
<version>0.0.13-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
Expand Down Expand Up @@ -74,7 +75,7 @@ public String getVersionInfo() {
public static long getNativeVersion() {
return nativeVersion;
}

@Override
public void setApi(io.privacyresearch.tringapi.TringApi api) {
this.api = api;
Expand Down Expand Up @@ -137,8 +138,9 @@ public void receivedAnswer(String peerId, long callId, int senderDeviceId,
toJByteArray(scope, opaque));
}

public void setSelfUuid(String uuid) {
tringlib_h.setSelfUuid(callEndpoint, toJString(scope, uuid));
public void setSelfUuid(byte[] uuid) {
LOG.info("Pass our uuid to tring: "+uuid);
tringlib_h.setSelfUuid(callEndpoint, toJByteArray(scope, uuid));
}

@Override
Expand Down Expand Up @@ -250,11 +252,11 @@ public void setArray() {
}

@Override
public TringFrame getRemoteVideoFrame(boolean skip) {
public TringFrame getRemoteVideoFrame(int demuxId, boolean skip) {
int CAP = 5000000;
try (Arena rscope = Arena.ofShared()) {
MemorySegment segment = rscope.allocate(CAP);
long res = tringlib_h.fillRemoteVideoFrame(callEndpoint, segment, CAP);
long res = tringlib_h.fillRemoteVideoFrame(callEndpoint, demuxId, segment, CAP);
if (res != 0) {
int w = (int) (res >> 16);
int h = (int) (res % (1 <<16));
Expand All @@ -272,7 +274,12 @@ public TringFrame getRemoteVideoFrame(boolean skip) {

@Override
public void enableOutgoingVideo(boolean enable) {
tringlib_h.setOutgoingVideoEnabled(callEndpoint, enable);
LOG.info("Toggle own video to "+enable+", for clientid = "+this.clientId);
if (this.clientId < 0) {
tringlib_h.setOutgoingVideoEnabled(callEndpoint, enable);
} else {
tringlib_h.setOutgoingVideoMuted(callEndpoint, clientId, !enable);
}
}

@Override
Expand Down Expand Up @@ -304,15 +311,13 @@ static MemorySegment toJByteArray2D(Arena ms, List<byte[]> rows) {
}

static MemorySegment toJByteArray(Arena arena, byte[] raw) {
LOG.info("Create JB with "+raw.length+" bytes");
MemorySegment answer = JByteArray.allocate(arena);
int size = raw.length;
MemorySegment rawSegment = MemorySegment.ofArray(raw);
MemorySegment transfer = arena.allocate(size);
transfer.copyFrom(rawSegment);
JByteArray.len(answer, size);
JByteArray.buff(answer, transfer);
LOG.info("Size of JB = "+answer.byteSize());
return answer;
}

Expand Down Expand Up @@ -369,13 +374,16 @@ public void handlePeekResponse(List joined, byte[] creator, String era, long max

public void handleRemoteDevicesChanged(List devices) {
LOG.info("Devices changed into "+devices);
List<Integer> demuxIds = new LinkedList<>();
for (Object entry : devices) {
ByteBuffer bb = ByteBuffer.wrap((byte[]) entry);
int demuxId = bb.getInt();
demuxIds.add(demuxId);
LOG.info("Schedule call to request video from "+demuxId);
Runnable r = () -> requestVideo(callEndpoint, clientId, demuxId);
executeRequest(r);
}
api.updateRemoteDevices(demuxIds);
}

public void makeHttpRequest(String uri, byte m, int reqid, byte[] headers, byte[] body) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ public interface TringApi {

public void sendOpaqueCallMessage(UUID recipient, byte[] opaque, int urgency);

public void updateRemoteDevices(List<Integer> demuxIds);

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.Optional;
import java.util.ServiceLoader;
import java.util.UUID;
import java.util.logging.Logger;
import java.util.stream.Collectors;

Expand All @@ -20,12 +21,13 @@ public class TringBridge {
private TringService service;
private static final Logger LOG = Logger.getLogger(TringBridge.class.getName());

public TringBridge(final TringApi api) {
public TringBridge(final TringApi api, final byte[] uuid) {
ServiceLoader<TringService> loader = ServiceLoader.load(TringService.class);
Optional<TringService> serviceOpt = loader.findFirst();
serviceOpt.ifPresentOrElse(s -> {
this.service = s;
this.service.setApi(api);
this.service.setSelfUuid(uuid);
}, () -> {
LOG.warning("No tring service!");
});
Expand Down Expand Up @@ -84,8 +86,8 @@ public void enableOutgoingVideo(boolean enable) {
service.enableOutgoingVideo(enable);
}

public TringFrame getRemoteVideoFrame() {
return service.getRemoteVideoFrame();
public TringFrame getRemoteVideoFrame(int demuxId) {
return service.getRemoteVideoFrame(demuxId);
}

public void sendVideoFrame(int width, int height, int pixelFormat, byte[] raw) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.privacyresearch.tringapi;

import java.util.List;
import java.util.UUID;

/**
* Implementations of this interface provides the access points for the application to interact with
Expand All @@ -13,6 +14,7 @@
public interface TringService {

public void setApi(TringApi api);
public void setSelfUuid(byte[] aci);

public void acceptCall();
public void ignoreCall();
Expand Down Expand Up @@ -47,10 +49,10 @@ public default String getVersionInfo() {
* @param skip if true, ignore all old frames, and return the most recent one
* @return a frame
*/
public TringFrame getRemoteVideoFrame(boolean skip);
public TringFrame getRemoteVideoFrame(int demuxId, boolean skip);

public default TringFrame getRemoteVideoFrame() {
return getRemoteVideoFrame(false);
public default TringFrame getRemoteVideoFrame(int demuxId) {
return getRemoteVideoFrame(demuxId, false);
}
public void sendVideoFrame(int w, int h, int pixelFormat, byte[] raw);

Expand Down
2 changes: 1 addition & 1 deletion src/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn main() {
.with_crate(crate_dir)
.with_language(cbindgen::Language::C)
.generate()
.expect("uunable to generate bindings")
.expect("unable to generate bindings")
.write_to_file("tringlib.h");
}
let target = env::var("TARGET").unwrap();
Expand Down
2 changes: 1 addition & 1 deletion src/rust/src/core/group_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1990,7 +1990,7 @@ impl Client {
self.client_id, requests, active_speaker_height,
);
self.actor.send(move |state| {
debug!(
info!(
"group_call::Client(inner)::request_video(client_id: {})",
state.client_id
);
Expand Down
20 changes: 10 additions & 10 deletions src/rust/src/java/java.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1015,7 +1015,7 @@ struct LastFramesVideoSink {

impl VideoSink for LastFramesVideoSink {
fn on_video_frame(&self, track_id: u32, frame: VideoFrame) {
info!("Got videoframe!");
info!("Got videoframe for track_id {}", track_id);
// let myframe: &mut[u8;512] = &mut [0;512];
// frame.to_rgba(myframe.as_mut_slice());
// info!("uploading frame = {:?}", myframe);
Expand Down Expand Up @@ -1095,10 +1095,10 @@ pub unsafe extern "C" fn createCallEndpoint(
}

#[no_mangle]
pub unsafe extern "C" fn setSelfUuid(endpoint: i64, ts: JPString) -> i64 {
let txt = ts.to_string();
info!("setSelfUuid to : {}", txt);
let uuid = txt.into_bytes();
// pub unsafe extern "C" fn setSelfUuid(endpoint: i64, ts: JPString) -> i64 {
pub unsafe extern "C" fn setSelfUuid(endpoint: i64, me: JByteArray) -> i64 {
let uuid = me.to_vec_u8();
debug!("setSelfUuid to {:?}", uuid);
let callendpoint = ptr_as_mut(endpoint as *mut CallEndpoint).unwrap();
callendpoint.call_manager.set_self_uuid(uuid);
1
Expand Down Expand Up @@ -1448,10 +1448,10 @@ pub unsafe extern "C" fn fillLargeArray(endpoint: i64, mybuffer: *mut u8) -> i64
}

#[no_mangle]
pub unsafe extern "C" fn fillRemoteVideoFrame(endpoint: i64, mybuffer: *mut u8, len: usize) -> i64 {
info!("Have to retrieve remote video frame");
pub unsafe extern "C" fn fillRemoteVideoFrame(endpoint: i64, demuxId: u32, mybuffer: *mut u8, len: usize) -> i64 {
info!("Have to retrieve remote video frame, trackId = {}", demuxId);
let endpoint = ptr_as_mut(endpoint as *mut CallEndpoint).unwrap();
let frame = endpoint.incoming_video_sink.pop(0);
let frame = endpoint.incoming_video_sink.pop(demuxId);
if let Some(frame) = frame {
let frame = frame.apply_rotation();
let width: u32 = frame.width();
Expand Down Expand Up @@ -1494,7 +1494,7 @@ fn deserialize_to_group_member_info(
Ok(group_members)
}

// Group Calls
// Group Calls GROUP CALLS start here

#[no_mangle]
pub unsafe extern "C" fn peekGroupCall(endpoint: i64, mp: JByteArray, gm: JByteArray) -> i64 {
Expand Down Expand Up @@ -1698,6 +1698,6 @@ pub unsafe extern "C" fn requestVideo(endpoint: i64, client_id: u32, demux_id: u

callendpoint
.call_manager
.request_video(client_id, rendered_resolutions, 1);
.request_video(client_id, rendered_resolutions, 150);
1
}

0 comments on commit abf4de8

Please sign in to comment.