Share libopus' encoder controls between bindings
libopus' constants and the encoder settings built on opus_encoder_ctl (clamping, voice/music signal) move into core, so the Android binding reuses them rather than copying them from the desktop's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package com.ts3client.audio.opus;
|
||||
|
||||
/** An {@link OpusEncoder} configured through libopus' own controls; a binding supplies {@link #ctl}. */
|
||||
public abstract class CtlOpusEncoder implements OpusEncoder {
|
||||
|
||||
/** Calls {@code opus_encoder_ctl(encoder, request, value)}. */
|
||||
protected abstract void ctl(int request, int value);
|
||||
|
||||
@Override
|
||||
public void setBitrate(int bitsPerSecond) {
|
||||
ctl(LibOpus.SET_BITRATE_REQUEST, bitsPerSecond);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setComplexity(int complexity) {
|
||||
ctl(LibOpus.SET_COMPLEXITY_REQUEST, Math.max(0, Math.min(10, complexity)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVbr(boolean vbr) {
|
||||
ctl(LibOpus.SET_VBR_REQUEST, vbr ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setInbandFec(boolean fec) {
|
||||
ctl(LibOpus.SET_INBAND_FEC_REQUEST, fec ? 1 : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setExpectedPacketLoss(int percent) {
|
||||
ctl(LibOpus.SET_PACKET_LOSS_PERC_REQUEST, Math.max(0, Math.min(100, percent)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSignal(Signal signal) {
|
||||
ctl(LibOpus.SET_SIGNAL_REQUEST, signal == Signal.MUSIC ? LibOpus.SIGNAL_MUSIC : LibOpus.SIGNAL_VOICE);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.ts3client.audio.opus;
|
||||
|
||||
/** libopus' numeric constants (opus_defines.h), shared by every binding of it. */
|
||||
public final class LibOpus {
|
||||
|
||||
public static final int APPLICATION_VOIP = 2048;
|
||||
public static final int APPLICATION_AUDIO = 2049;
|
||||
|
||||
public static final int SET_BITRATE_REQUEST = 4002;
|
||||
public static final int SET_VBR_REQUEST = 4006;
|
||||
public static final int SET_COMPLEXITY_REQUEST = 4010;
|
||||
public static final int SET_INBAND_FEC_REQUEST = 4012;
|
||||
public static final int SET_PACKET_LOSS_PERC_REQUEST = 4014;
|
||||
public static final int SET_SIGNAL_REQUEST = 4024;
|
||||
public static final int RESET_STATE = 4028;
|
||||
|
||||
public static final int SIGNAL_VOICE = 3001;
|
||||
public static final int SIGNAL_MUSIC = 3002;
|
||||
|
||||
private LibOpus() {
|
||||
}
|
||||
|
||||
public static int application(OpusCodec.Application application) {
|
||||
return application == OpusCodec.Application.AUDIO ? APPLICATION_AUDIO : APPLICATION_VOIP;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user