-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Add and use a generic Buffer class. * fix: Improve isStunPacket check. Return early when the first two bits don't match. This is for: 1. Correctness: A packet that doesn't start with 00 is not STUN even if the magic cookie happens to match 2. Performance: Most packets are RTP and will fail the first byte check, so no need to check the magic cookie. * feat: Add a push API for payload When enabled packets are passed directly to the application, * feat: Allow Component.send to send over a valid (but not selected) pair. --------- Co-authored-by: Jonathan Lennox <[email protected]>
- Loading branch information
1 parent
4a3574e
commit a982207
Showing
7 changed files
with
380 additions
and
106 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Purpose | ||
The push API is a mode in which ice4j passes received payload packets to the application directly via a callback, | ||
instead of making them available for reading from a virtual DatagramSocket. This avoids packets being copied into queues | ||
handled by different threads, and is intended to reduce the workload and delay. | ||
|
||
# Use | ||
First, the API has to be enabled by setting `AbstractUdpListener.USE_PUSH_API` to true. This needs to be done before any | ||
`SinglePortUdpHarvester`s are created. | ||
|
||
A callback for payload packets needs to be configured for each `Component` using `setBufferCallback()`. | ||
|
||
Finally, sending data should be done via `Component.send(byte[] data, int offset, int length)` instead of one of the | ||
virtual sockets. | ||
|
||
# Memory model | ||
Buffers for each packet are allocated using `BufferPool.getBuffer`, which can be set externally. The default | ||
implementation just allocates new memory on the java heap. | ||
|
||
If a buffer is not passed to the application, it will be returned via `BufferPool.returnBuffer`. Otherwise, it is the | ||
responsibility of the application. | ||
|
||
Two new config options can be used to specify a non-zero offset and space to be left at the end of the buffers (which | ||
could be used to e.g. make RTP processing more efficient): | ||
|
||
```AbstractUdpListener.BYTES_TO_LEAVE_AT_START_OF_PACKET``` | ||
```AbstractUdpListener.BYTES_TO_LEAVE_AT_END_OF_PACKET``` | ||
|
||
# Limitations | ||
The push API currently only supports `SinglePortUdpHarvester`. If the application uses regular `HostCandidate`s, it | ||
has to read the packets from a `DatagramSocket`. Sending via `Component.send()` works either way. |
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
Oops, something went wrong.