Skip to content
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

Refine comments and validation for some config fields #118

Merged
merged 1 commit into from
May 31, 2023
Merged
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
7 changes: 7 additions & 0 deletions src/main/java/org/rocstreaming/roctoolkit/Check.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,11 @@ static int notNegative(int value, String name) {
}
return value;
}

static long notNegative(long value, String name) {
if (value < 0) {
throw new IllegalArgumentException(name + " must not be negative");
}
return value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,18 @@ public class RocContextConfig {
* Maximum size in bytes of a network packet.
* Defines the amount of bytes allocated per network packet.
* Sender and receiver won't handle packets larger than this.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private int maxPacketSize;

/**
* Maximum size in bytes of an audio frame.
* Defines the amount of bytes allocated per intermediate internal
* frame in the pipeline. Does not limit the size of the frames
* provided by user. If zero, default value is used.
* provided by user.
* If zero or unset, default value is used.
* Should not be negative.
*/
private int maxFrameSize;

Expand Down
31 changes: 23 additions & 8 deletions src/main/java/org/rocstreaming/roctoolkit/RocReceiverConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,39 @@ public class RocReceiverConfig {
/**
* The rate of the samples in the frames returned to the user.
* Number of samples per channel per second.
* Should be set to a positive value.
*/
private int frameSampleRate;

/**
* The channel set in the frames returned to the user.
* Should be set to a non-null value.
*/
private ChannelSet frameChannels;

/**
* The sample encoding in the frames returned to the user.
* Should be set to a non-null value.
*/
private FrameEncoding frameEncoding;

/**
* Clock source to use.
* Defines whether read operation will be blocking or non-blocking.
* If zero, default value is used.
* If null or unset, default value is used.
*/
private ClockSource clockSource;

/**
* Resampler backend to use.
* If null or unset, default value is used.
*/
private ResamplerBackend resamplerBackend;

/**
* Resampler profile to use.
* If non-zero, the receiver employs resampler for two purposes:
* If null or unset, default value is used.
* If resampling is enabled, the receiver employs resampler for two purposes:
* <ul>
* <li>
* adjust the sender clock to the receiver clock, which
Expand All @@ -65,15 +70,17 @@ public class RocReceiverConfig {
* requested latency.
* Then, if resampler is enabled, the session will adjust its clock
* to keep actual latency as close as possible to the target latency.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private long targetLatency;

/**
* Maximum delta between current and target latency, in nanoseconds.
* If current latency becomes larger than the target latency plus
* this value, the session is terminated.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private long maxLatencyOverrun;

Expand All @@ -84,7 +91,8 @@ public class RocReceiverConfig {
* May be larger than the target latency because current latency may
* be negative, which means that the playback run ahead of the last
* packet received from network.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private long maxLatencyUnderrun;

Expand All @@ -93,7 +101,8 @@ public class RocReceiverConfig {
* If there is no playback during this period, the session is terminated.
* This mechanism allows to detect dead, hanging, or broken clients
* generating invalid packets.
* If zero, default value is used. If negative, the timeout is disabled.
* If zero or unset, default value is used.
* If negative, the timeout is disabled.
*/
private long noPlaybackTimeout;

Expand All @@ -106,13 +115,15 @@ public class RocReceiverConfig {
* This mechanism allows to detect vicious circles like when all
* client packets are a bit late and receiver constantly drops them
* producing unpleasant noise.
* If zero, default value is used. If negative, the timeout is disabled.
* If zero or unset, default value is used.
* If negative, the timeout is disabled.
*/
private long brokenPlaybackTimeout;

/**
* Breakage detection window, in nanoseconds.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*
* @see ConfigBuilder#brokenPlaybackTimeout
*/
Expand All @@ -128,6 +139,10 @@ public RocReceiverConfig build() {
Check.notNegative(super.frameSampleRate, "frameSampleRate");
Check.notNull(super.frameChannels, "frameChannels");
Check.notNull(super.frameEncoding, "frameEncoding");
Check.notNegative(super.targetLatency, "targetLatency");
Check.notNegative(super.maxLatencyUnderrun, "maxLatencyUnderrun");
Check.notNegative(super.maxLatencyUnderrun, "maxLatencyUnderrun");
Check.notNegative(super.breakageDetectionWindow, "breakageDetectionWindow");
return super.build();
}
}
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/org/rocstreaming/roctoolkit/RocSenderConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,39 @@ public class RocSenderConfig {
/**
* The rate of the samples in the frames returned to the user.
* Number of samples per channel per second.
* Should be set to a positive value.
*/
private int frameSampleRate;

/**
* The channel set in the frames returned to the user.
* Should be set to a non-null value.
*/
private ChannelSet frameChannels;

/**
* The sample encoding in the frames returned to the user.
* Should be set to a non-null value.
*/
private FrameEncoding frameEncoding;

/**
* The rate of the samples in the packets generated by sender.
* Number of samples per channel per second.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private int packetSampleRate;

/**
* The channel set in the packets generated by sender.
* If null, default value is used.
* If null or unset, default value is used.
*/
private ChannelSet packetChannels;

/**
* The sample encoding in the packets generated by sender.
* If null, default value is used.
* If null or unset, default value is used.
*/
private PacketEncoding packetEncoding;

Expand All @@ -56,7 +60,8 @@ public class RocSenderConfig {
* The samples written to the sender are buffered until the full
* packet is accumulated or the sender is flushed or closed.
* Larger number reduces packet overhead but also increases latency.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private long packetLength;

Expand All @@ -70,25 +75,28 @@ public class RocSenderConfig {
/**
* Clock source to use.
* Defines whether write operation will be blocking or non-blocking.
* If zero, default value is used.
* If null or unset, default value is used.
*/
private ClockSource clockSource;

/**
* Resampler backend to use.
* If null or unset, default value is used.
*/
private ResamplerBackend resamplerBackend;

/**
* Resampler profile to use.
* If non-null, the sender employs resampler if the frame sample rate
* If null or unset, default value is used.
* If resampling is enabled, the sender employs resampler if the frame sample rate
* differs from the packet sample rate.
*/
private ResamplerProfile resamplerProfile;

/**
* FEC encoding to use.
* If non-null, the sender employs a FEC codec to generate redundant
* If null or unset, default value is used.
* If FEC is enabled, the sender employs a FEC codec to generate redundant
* packets which may be used on receiver to restore lost packets.
* This requires both sender and receiver to use two separate source
* and repair ports.
Expand All @@ -99,15 +107,17 @@ public class RocSenderConfig {
* Number of source packets per FEC block.
* Used if some FEC encoding is selected.
* Larger number increases robustness but also increases latency.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private int fecBlockSourcePackets;

/**
* Number of repair packets per FEC block.
* Used if some FEC encoding is selected.
* Larger number increases robustness but also increases traffic.
* If zero, default value is used.
* If zero or unset, default value is used.
* Should not be negative.
*/
private int fecBlockRepairPackets;

Expand All @@ -122,6 +132,7 @@ public RocSenderConfig build() {
Check.notNull(super.frameChannels, "frameChannels");
Check.notNull(super.frameEncoding, "frameEncoding");
Check.notNegative(super.packetSampleRate, "packetSampleRate");
Check.notNegative(super.packetLength, "packetLength");
Check.notNegative(super.fecBlockSourcePackets, "fecBlockSourcePackets");
Check.notNegative(super.fecBlockRepairPackets, "fecBlockRepairPackets");
return super.build();
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/org/rocstreaming/roctoolkit/Slot.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
@EqualsAndHashCode
public class Slot {

/**
* Alias for the slot with index zero.
*/
public static final Slot DEFAULT = new Slot(0);

private final int value;
Expand Down