Skip to content

Commit

Permalink
Wider use of lombok
Browse files Browse the repository at this point in the history
  • Loading branch information
sheinbergon committed Nov 24, 2023
1 parent e414e92 commit ea4819c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
15 changes: 8 additions & 7 deletions src/main/java/org/sheinbergon/aac/encoder/AACAudioEncoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import lombok.val;
import org.sheinbergon.aac.encoder.util.AACAudioEncoderException;
import org.sheinbergon.aac.encoder.util.AACEncodingChannelMode;
import org.sheinbergon.aac.encoder.util.AACEncodingProfile;
Expand Down Expand Up @@ -145,10 +146,10 @@ public AACAudioEncoder build() {
} else if (profile == AACEncodingProfile.HE_AAC_V2 && channels != PARAMETRIC_STEREO_CHANNEL_COUNT) {
throw new AACAudioEncoderException("HE-AACv2 only supports 2 channels (stereo) mode");
} else {
AACEncoder encoder = FdkAACLibFacade.openEncoder(ENCODER_MODULES_MASK, MAX_ENCODER_CHANNELS);
val encoder = FdkAACLibFacade.openEncoder(ENCODER_MODULES_MASK, MAX_ENCODER_CHANNELS);
setEncoderParams(encoder);
FdkAACLibFacade.initEncoder(encoder);
AACEncInfo info = FdkAACLibFacade.getEncoderInfo(encoder);
val info = FdkAACLibFacade.getEncoderInfo(encoder);
return new AACAudioEncoder(encoder, info);
}
}
Expand All @@ -165,12 +166,12 @@ public AACAudioOutput encode(final WAVAudioInput input) throws AACAudioEncoderEx
int read;
verifyState();
try {
AACAudioOutput.Accumulator accumulator = AACAudioOutput.accumulator();
ByteArrayInputStream inputStream = new ByteArrayInputStream(input.data());
byte[] buffer = new byte[inputBufferSize()];
val accumulator = AACAudioOutput.accumulator();
val inputStream = new ByteArrayInputStream(input.data());
val buffer = new byte[inputBufferSize()];
while ((read = inputStream.read(buffer)) != WAVAudioSupport.EOS) {
populateInputBuffer(buffer, read);
byte[] encoded = FdkAACLibFacade
val encoded = FdkAACLibFacade
.encode(encoder, inBufferDescriptor, outBufferDescriptor, inArgs, outArgs, read)
.orElseThrow(() -> new IllegalStateException("No encoded audio data returned"));
accumulator.accumulate(encoded);
Expand All @@ -192,7 +193,7 @@ public AACAudioOutput conclude() throws AACAudioEncoderException {
verifyState();
try {
inBufferDescriptor.clear();
AACAudioOutput.Accumulator accumulator = AACAudioOutput.accumulator();
val accumulator = AACAudioOutput.accumulator();
while ((optional = FdkAACLibFacade
.encode(encoder, inBufferDescriptor, outBufferDescriptor, inArgs, outArgs, WAVAudioSupport.EOS))
.isPresent()) {
Expand Down
21 changes: 11 additions & 10 deletions src/main/java/org/sheinbergon/aac/jna/FdkAACLibFacade.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import lombok.extern.java.Log;
import lombok.val;
import org.sheinbergon.aac.encoder.util.WAVAudioSupport;
import org.sheinbergon.aac.jna.structure.AACEncBufDesc;
import org.sheinbergon.aac.jna.structure.AACEncInArgs;
Expand Down Expand Up @@ -44,8 +45,8 @@ public final class FdkAACLibFacade {
public static AACEncoder openEncoder(
final int modules,
final int maxChannels) {
PointerByReference pointerRef = new PointerByReference();
AACEncError result = AACEncError.valueOf(FdkAACLib.aacEncOpen(pointerRef, modules, maxChannels));
val pointerRef = new PointerByReference();
val result = AACEncError.valueOf(FdkAACLib.aacEncOpen(pointerRef, modules, maxChannels));
verifyResult(result, FdkAACLib.Functions.OPEN);
return AACEncoder.of(pointerRef);
}
Expand All @@ -56,8 +57,8 @@ public static AACEncoder openEncoder(
* @param encoder an {@link AACEncoder} instance, previously opened by the fdk-aac library
*/
public static void closeEncoder(final @Nonnull AACEncoder encoder) {
PointerByReference pointerRef = new PointerByReference(encoder.getPointer());
AACEncError result = AACEncError.valueOf(FdkAACLib.aacEncClose(pointerRef));
val pointerRef = new PointerByReference(encoder.getPointer());
val result = AACEncError.valueOf(FdkAACLib.aacEncClose(pointerRef));
verifyResult(result, FdkAACLib.Functions.CLOSE);
}

Expand All @@ -67,7 +68,7 @@ public static void closeEncoder(final @Nonnull AACEncoder encoder) {
* @param encoder an {@link AACEncoder} instance, previously opened by the fdk-aac library
*/
public static void initEncoder(final @Nonnull AACEncoder encoder) {
AACEncError result = AACEncError.valueOf(FdkAACLib.aacEncEncode(encoder, null, null, null, null));
val result = AACEncError.valueOf(FdkAACLib.aacEncEncode(encoder, null, null, null, null));
verifyResult(result, FdkAACLib.Functions.ENCODE);
}

Expand Down Expand Up @@ -113,8 +114,8 @@ public static Optional<byte[]> encode(
* @return the give encoder's information payload
*/
public static AACEncInfo getEncoderInfo(final @Nonnull AACEncoder encoder) {
AACEncInfo info = new AACEncInfo();
AACEncError result = AACEncError.valueOf(FdkAACLib.aacEncInfo(encoder, info));
val info = new AACEncInfo();
val result = AACEncError.valueOf(FdkAACLib.aacEncInfo(encoder, info));
verifyResult(result, FdkAACLib.Functions.INFO);
info.read();
return info;
Expand All @@ -132,7 +133,7 @@ public static void setEncoderParam(
final @Nonnull AACEncoder encoder,
final @Nonnull AACEncParam param,
final int value) {
AACEncError result = AACEncError.valueOf(FdkAACLib.aacEncoder_SetParam(encoder, param.getValue(), value));
val result = AACEncError.valueOf(FdkAACLib.aacEncoder_SetParam(encoder, param.getValue(), value));
verifyResult(result, FdkAACLib.Functions.SET_PARAM);
}

Expand All @@ -159,7 +160,7 @@ private static void verifyResult(
* @return an out-buffer descriptor structure
*/
public static AACEncBufDesc outBufferDescriptor(final @Nonnull Memory buffer) {
AACEncBufDesc descriptor = new AACEncBufDesc();
val descriptor = new AACEncBufDesc();
descriptor.numBufs = OUT_BUFFER_COUNT;
descriptor.bufs = new PointerByReference(buffer);
descriptor.bufSizes = new IntByReference((int) buffer.size());
Expand All @@ -177,7 +178,7 @@ public static AACEncBufDesc outBufferDescriptor(final @Nonnull Memory buffer) {
* @return an in-buffer descriptor structure
*/
public static AACEncBufDesc inBufferDescriptor(final @Nonnull Memory buffer) {
AACEncBufDesc descriptor = new AACEncBufDesc();
val descriptor = new AACEncBufDesc();
descriptor.numBufs = IN_BUFFER_COUNT;
descriptor.bufs = new PointerByReference(buffer);
descriptor.bufSizes = new IntByReference((int) buffer.size());
Expand Down

0 comments on commit ea4819c

Please sign in to comment.