Skip to content
Snippets Groups Projects
Commit 4adc909f authored by Lyubomir Marinov's avatar Lyubomir Marinov
Browse files

Applies formatting, simplifies source code.

parent ef67ae72
No related branches found
No related tags found
No related merge requests found
...@@ -73,19 +73,16 @@ public JavaDecoder() ...@@ -73,19 +73,16 @@ public JavaDecoder()
}; };
} }
private void depacketize( private void depacketize(byte[] inFrame, int inFrameOffset, short[] serial)
byte[] inputFrame,
int inputFrameOffset,
short[] serial)
{ {
serial[0] = SYNC_WORD; serial[0] = SYNC_WORD;
serial[1] = SIZE_WORD; serial[1] = SIZE_WORD;
for (int s = 0; s < L_FRAME; s++) for (int s = 0; s < L_FRAME; s++)
{ {
int input = inputFrame[inputFrameOffset + s / 8]; int in = inFrame[inFrameOffset + s / 8];
input &= 1 << (7 - (s % 8)); in &= 1 << (7 - (s % 8));
serial[2 + s] = (0 != input) ? BIT_1 : BIT_0; serial[2 + s] = (0 != in) ? BIT_1 : BIT_0;
} }
} }
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import org.jitsi.impl.neomedia.codec.*; import org.jitsi.impl.neomedia.codec.*;
/** /**
*
* @author Lubomir Marinov * @author Lubomir Marinov
*/ */
public class JavaEncoder public class JavaEncoder
...@@ -34,21 +35,21 @@ public class JavaEncoder ...@@ -34,21 +35,21 @@ public class JavaEncoder
private Coder coder; private Coder coder;
private int outputFrameCount; private int outFrameCount;
/** /**
* The previous input if it was less than the input frame size and which is * The previous input if it was less than the input frame size and which is
* to be prepended to the next input in order to form a complete input * to be prepended to the next input in order to form a complete input
* frame. * frame.
*/ */
private byte[] prevInput; private byte[] prevIn;
/** /**
* The length of the previous input if it was less than the input frame size * The length of the previous input if it was less than the input frame size
* and which is to be prepended to the next input in order to form a * and which is to be prepended to the next input in order to form a
* complete input frame. * complete input frame.
*/ */
private int prevInputLength; private int prevInLength;
private short[] serial; private short[] serial;
...@@ -99,24 +100,24 @@ public JavaEncoder() ...@@ -99,24 +100,24 @@ public JavaEncoder()
@Override @Override
public Format getOutputFormat() public Format getOutputFormat()
{ {
Format outputFormat = super.getOutputFormat(); Format f = super.getOutputFormat();
if ((outputFormat != null) if ((f != null) && (f.getClass() == AudioFormat.class))
&& (outputFormat.getClass() == AudioFormat.class))
{ {
AudioFormat outputAudioFormat = (AudioFormat) outputFormat; AudioFormat af = (AudioFormat) f;
outputFormat = setOutputFormat( f
new AudioFormat( = setOutputFormat(
outputAudioFormat.getEncoding(), new AudioFormat(
outputAudioFormat.getSampleRate(), af.getEncoding(),
outputAudioFormat.getSampleSizeInBits(), af.getSampleRate(),
outputAudioFormat.getChannels(), af.getSampleSizeInBits(),
outputAudioFormat.getEndian(), af.getChannels(),
outputAudioFormat.getSigned(), af.getEndian(),
outputAudioFormat.getFrameSizeInBits(), af.getSigned(),
outputAudioFormat.getFrameRate(), af.getFrameSizeInBits(),
outputAudioFormat.getDataType()) af.getFrameRate(),
af.getDataType())
{ {
private static final long serialVersionUID = 0L; private static final long serialVersionUID = 0L;
...@@ -127,7 +128,7 @@ public long computeDuration(long length) ...@@ -127,7 +128,7 @@ public long computeDuration(long length)
} }
}); });
} }
return outputFormat; return f;
} }
@Override @Override
...@@ -135,7 +136,7 @@ protected void discardOutputBuffer(Buffer outputBuffer) ...@@ -135,7 +136,7 @@ protected void discardOutputBuffer(Buffer outputBuffer)
{ {
super.discardOutputBuffer(outputBuffer); super.discardOutputBuffer(outputBuffer);
outputFrameCount = 0; outFrameCount = 0;
} }
/* /*
...@@ -144,8 +145,8 @@ protected void discardOutputBuffer(Buffer outputBuffer) ...@@ -144,8 +145,8 @@ protected void discardOutputBuffer(Buffer outputBuffer)
@Override @Override
protected void doClose() protected void doClose()
{ {
prevInput = null; prevIn = null;
prevInputLength = 0; prevInLength = 0;
sp16 = null; sp16 = null;
serial = null; serial = null;
...@@ -167,134 +168,122 @@ protected void doClose() ...@@ -167,134 +168,122 @@ protected void doClose()
protected void doOpen() protected void doOpen()
throws ResourceUnavailableException throws ResourceUnavailableException
{ {
prevInput = new byte[INPUT_FRAME_SIZE_IN_BYTES]; prevIn = new byte[INPUT_FRAME_SIZE_IN_BYTES];
prevInputLength = 0; prevInLength = 0;
sp16 = new short[L_FRAME]; sp16 = new short[L_FRAME];
serial = new short[SERIAL_SIZE]; serial = new short[SERIAL_SIZE];
coder = new Coder(); coder = new Coder();
outputFrameCount = 0; outFrameCount = 0;
} }
/* /*
* Implements AbstractCodecExt#doProcess(Buffer, Buffer). * Implements AbstractCodecExt#doProcess(Buffer, Buffer).
*/ */
@Override @Override
protected int doProcess(Buffer inputBuffer, Buffer outputBuffer) protected int doProcess(Buffer inBuffer, Buffer outBuffer)
{ {
byte[] input = (byte[]) inputBuffer.getData(); byte[] in = (byte[]) inBuffer.getData();
int inputLength = inputBuffer.getLength(); int inLength = inBuffer.getLength();
int inputOffset = inputBuffer.getOffset(); int inOffset = inBuffer.getOffset();
if ((prevInputLength + inputLength) < INPUT_FRAME_SIZE_IN_BYTES) if ((prevInLength + inLength) < INPUT_FRAME_SIZE_IN_BYTES)
{ {
System.arraycopy( System.arraycopy(
input, in, inOffset,
inputOffset, prevIn, prevInLength,
prevInput, inLength);
prevInputLength, prevInLength += inLength;
inputLength);
prevInputLength += inputLength;
return BUFFER_PROCESSED_OK | OUTPUT_BUFFER_NOT_FILLED; return BUFFER_PROCESSED_OK | OUTPUT_BUFFER_NOT_FILLED;
} }
int readShorts = 0; int readShorts = 0;
if (prevInputLength > 0) if (prevInLength > 0)
{ {
readShorts readShorts += readShorts(prevIn, 0, sp16, 0, prevInLength / 2);
+= readShorts(prevInput, 0, sp16, 0, prevInputLength / 2); prevInLength = 0;
prevInputLength = 0;
} }
readShorts readShorts
= readShorts( = readShorts(
input, in, inOffset,
inputOffset, sp16, readShorts, sp16.length - readShorts);
sp16,
readShorts,
sp16.length - readShorts);
int readBytes = 2 * readShorts; int readBytes = 2 * readShorts;
inputLength -= readBytes; inLength -= readBytes;
inputBuffer.setLength(inputLength); inBuffer.setLength(inLength);
inputOffset += readBytes; inOffset += readBytes;
inputBuffer.setOffset(inputOffset); inBuffer.setOffset(inOffset);
coder.process(sp16, serial); coder.process(sp16, serial);
byte[] output byte[] output
= validateByteArraySize( = validateByteArraySize(
outputBuffer, outBuffer,
outputBuffer.getOffset() + 2 * OUTPUT_FRAME_SIZE_IN_BYTES, outBuffer.getOffset() + 2 * OUTPUT_FRAME_SIZE_IN_BYTES,
true); true);
packetize( packetize(
serial, serial,
output, output,
outputBuffer.getOffset() outBuffer.getOffset()
+ OUTPUT_FRAME_SIZE_IN_BYTES * outputFrameCount); + OUTPUT_FRAME_SIZE_IN_BYTES * outFrameCount);
outputBuffer.setLength( outBuffer.setLength(outBuffer.getLength() + OUTPUT_FRAME_SIZE_IN_BYTES);
outputBuffer.getLength() + OUTPUT_FRAME_SIZE_IN_BYTES);
outputBuffer.setFormat(outputFormat); outBuffer.setFormat(outputFormat);
int processResult = BUFFER_PROCESSED_OK; int ret = BUFFER_PROCESSED_OK;
if (outputFrameCount == 1) if (outFrameCount == 1)
outputFrameCount = 0; outFrameCount = 0;
else else
{ {
outputFrameCount = 1; outFrameCount = 1;
processResult |= OUTPUT_BUFFER_NOT_FILLED; ret |= OUTPUT_BUFFER_NOT_FILLED;
} }
if (inputLength > 0) if (inLength > 0)
processResult |= INPUT_BUFFER_NOT_CONSUMED; ret |= INPUT_BUFFER_NOT_CONSUMED;
if(processResult == BUFFER_PROCESSED_OK) if(ret == BUFFER_PROCESSED_OK)
{ {
updateOutput( updateOutput(
outputBuffer, outBuffer,
getOutputFormat(), outputBuffer.getLength(), getOutputFormat(),
outputBuffer.getOffset()); outBuffer.getLength(),
outputBuffer.setDuration(duration); outBuffer.getOffset());
outBuffer.setDuration(duration);
} }
return processResult; return ret;
} }
private void packetize( private void packetize(short[] serial, byte[] outFrame, int outFrameOffset)
short[] serial,
byte[] outputFrame,
int outputFrameOffset)
{ {
Arrays.fill( Arrays.fill(
outputFrame, outFrame, outFrameOffset, outFrameOffset + L_FRAME / 8,
outputFrameOffset, (byte) 0);
outputFrameOffset + L_FRAME / 8,
(byte) 0);
for (int s = 0; s < L_FRAME; s++) for (int s = 0; s < L_FRAME; s++)
{
if (BIT_1 == serial[2 + s]) if (BIT_1 == serial[2 + s])
{ {
int o = outputFrameOffset + s / 8; int o = outFrameOffset + s / 8;
int output = outputFrame[o]; int out = outFrame[o];
output |= 1 << (7 - (s % 8)); out |= 1 << (7 - (s % 8));
outputFrame[o] = (byte) (output & 0xFF); outFrame[o] = (byte) (out & 0xFF);
} }
}
} }
private static int readShorts( private static int readShorts(
byte[] input, byte[] in, int inOffset,
int inputOffset, short[] out, int outOffset, int outLength)
short[] output,
int outputOffset,
int outputLength)
{ {
for (int o=outputOffset, i=inputOffset; o<outputLength; o++, i+=2) for (int o=outOffset, i=inOffset; o<outLength; o++, i+=2)
output[o] = ArrayIOUtils.readShort(input, i); out[o] = ArrayIOUtils.readShort(in, i);
return outputLength; return outLength;
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment