Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions webrtc-jni/src/main/cpp/include/api/RTCConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ namespace jni
jfieldID rtcpMuxPolicy;
jfieldID certificates;
jfieldID portAllocatorConfig;
jfieldID audioJitterBufferMaxPackets;
jfieldID audioJitterBufferFastAccelerate;
jfieldID audioJitterBufferMinDelayMs;
};

JavaLocalRef<jobject> toJava(JNIEnv * env, const webrtc::PeerConnectionInterface::RTCConfiguration & config);
Expand Down
13 changes: 12 additions & 1 deletion webrtc-jni/src/main/cpp/src/api/RTCConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ namespace jni
auto pac = jni::PortAllocatorConfig::toJava(env, nativeType.port_allocator_config);
env->SetObjectField(config, javaClass->portAllocatorConfig, pac.get());

env->SetIntField(config, javaClass->audioJitterBufferMaxPackets, nativeType.audio_jitter_buffer_max_packets);
env->SetBooleanField(config, javaClass->audioJitterBufferFastAccelerate, nativeType.audio_jitter_buffer_fast_accelerate);
env->SetIntField(config, javaClass->audioJitterBufferMinDelayMs, nativeType.audio_jitter_buffer_min_delay_ms);

return JavaLocalRef<jobject>(env, config);
}

Expand All @@ -83,7 +87,7 @@ namespace jni
configuration.type = JavaEnums::toNative<webrtc::PeerConnectionInterface::IceTransportsType>(env, tp);
configuration.bundle_policy = JavaEnums::toNative<webrtc::PeerConnectionInterface::BundlePolicy>(env, bp);
configuration.rtcp_mux_policy = JavaEnums::toNative<webrtc::PeerConnectionInterface::RtcpMuxPolicy>(env, mp);

for (auto & item : JavaIterable(env, cr)) {
auto certificate = webrtc::RTCCertificate::FromPEM(jni::RTCCertificatePEM::toNative(env, item));

Expand All @@ -103,6 +107,10 @@ namespace jni
configuration.port_allocator_config.flags = pacObj.getInt(pacJavaClass->flags);
}

configuration.audio_jitter_buffer_fast_accelerate = obj.getBoolean(javaClass->audioJitterBufferFastAccelerate);
configuration.audio_jitter_buffer_max_packets = obj.getInt(javaClass->audioJitterBufferMaxPackets);
configuration.audio_jitter_buffer_min_delay_ms = obj.getInt(javaClass->audioJitterBufferMinDelayMs);

return configuration;
}

Expand All @@ -118,6 +126,9 @@ namespace jni
rtcpMuxPolicy = GetFieldID(env, cls, "rtcpMuxPolicy", "L" PKG "RTCRtcpMuxPolicy;");
certificates = GetFieldID(env, cls, "certificates", LIST_SIG);
portAllocatorConfig = GetFieldID(env, cls, "portAllocatorConfig", "L" PKG "PortAllocatorConfig;");
audioJitterBufferMaxPackets = GetFieldID(env, cls, "audioJitterBufferMaxPackets", "I");
audioJitterBufferFastAccelerate = GetFieldID(env, cls, "audioJitterBufferFastAccelerate", "Z");
audioJitterBufferMinDelayMs = GetFieldID(env, cls, "audioJitterBufferMinDelayMs", "I");
}
}
}
20 changes: 20 additions & 0 deletions webrtc/src/main/java/dev/onvoid/webrtc/RTCConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
*/
public class RTCConfiguration {

/**
* Default maximum number of packets in the audio jitter buffer.
*/
public static final int kAudioJitterBufferMaxPackets = 200;

/**
* A list of ICE server's describing servers available to be used by ICE,
* such as STUN and TURN servers.
Expand Down Expand Up @@ -64,6 +69,21 @@ public class RTCConfiguration {
*/
public PortAllocatorConfig portAllocatorConfig;

/**
* The maximum number of packets that can be stored in the NetEq audio
* jitter buffer. Can be reduced to lower tolerated audio latency.
*/
public int audioJitterBufferMaxPackets = kAudioJitterBufferMaxPackets;

/** Whether to use the NetEq "fast mode" which will accelerate audio quicker
* if it falls behind.
Comment on lines +78 to +79
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The JavaDoc comment formatting is inconsistent with the other comments in this file. The opening '/**' should be on its own line, and there should be no leading tabs before the asterisks. This comment should follow the same style as the comments above and below it.

Suggested change
/** Whether to use the NetEq "fast mode" which will accelerate audio quicker
* if it falls behind.
/**
* Whether to use the NetEq "fast mode" which will accelerate audio quicker
* if it falls behind.

Copilot uses AI. Check for mistakes.
*/
public boolean audioJitterBufferFastAccelerate;

/**
* The minimum delay in milliseconds for the audio jitter buffer.
*/
public int audioJitterBufferMinDelayMs;
Comment on lines +72 to +86
Copy link

Copilot AI Dec 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new audio jitter buffer fields lack test coverage. Based on the existing test pattern in RTCPeerConnectionTests.configuration(), these fields should be tested to verify they are properly round-tripped through the JNI layer (set in Java configuration, create peer connection, retrieve configuration, and verify values match).

Copilot uses AI. Check for mistakes.

/**
* Creates an instance of RTCConfiguration.
Expand Down