www in docker support
This commit is contained in:
parent
539a848e95
commit
c227fce036
2145 changed files with 399596 additions and 58 deletions
|
|
@ -0,0 +1,90 @@
|
|||
package org.jcodec.codecs.s302;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
import org.jcodec.common.AudioCodecMeta;
|
||||
import org.jcodec.common.AudioDecoder;
|
||||
import org.jcodec.common.AudioFormat;
|
||||
import org.jcodec.common.model.AudioBuffer;
|
||||
import org.jcodec.common.tools.MathUtil;
|
||||
|
||||
public class S302MDecoder implements AudioDecoder {
|
||||
public static int SAMPLE_RATE = 48000;
|
||||
|
||||
public AudioBuffer decodeFrame(ByteBuffer frame, ByteBuffer dst) {
|
||||
frame.order(ByteOrder.BIG_ENDIAN);
|
||||
ByteBuffer dup = dst.duplicate();
|
||||
int h = frame.getInt();
|
||||
int frameSize = h >> 16 & 0xFFFF;
|
||||
if (frame.remaining() != frameSize)
|
||||
throw new IllegalArgumentException("Wrong s302m frame");
|
||||
int channels = (h >> 14 & 0x3) * 2 + 2;
|
||||
int sampleSizeInBits = (h >> 4 & 0x3) * 4 + 16;
|
||||
if (sampleSizeInBits == 24) {
|
||||
int i = frame.remaining() / 7 * 2;
|
||||
while (frame.remaining() > 6) {
|
||||
byte c = (byte)MathUtil.reverse(frame.get() & 0xFF);
|
||||
byte b = (byte)MathUtil.reverse(frame.get() & 0xFF);
|
||||
byte a = (byte)MathUtil.reverse(frame.get() & 0xFF);
|
||||
int g = MathUtil.reverse(frame.get() & 0xF);
|
||||
int f = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int e = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int d = MathUtil.reverse(frame.get() & 0xF0);
|
||||
dup.put(a);
|
||||
dup.put(b);
|
||||
dup.put(c);
|
||||
dup.put((byte)(d << 4 | e >> 4));
|
||||
dup.put((byte)(e << 4 | f >> 4));
|
||||
dup.put((byte)(f << 4 | g >> 4));
|
||||
}
|
||||
dup.flip();
|
||||
return new AudioBuffer(dup, new AudioFormat(SAMPLE_RATE, 24, channels, true, true), i / channels);
|
||||
}
|
||||
if (sampleSizeInBits == 20) {
|
||||
int i = frame.remaining() / 6 * 2;
|
||||
while (frame.remaining() > 5) {
|
||||
int c = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int b = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int a = MathUtil.reverse(frame.get() & 0xF0);
|
||||
dup.put((byte)(a << 4 | b >> 4));
|
||||
dup.put((byte)(b << 4 | c >> 4));
|
||||
dup.put((byte)(c << 4));
|
||||
int cc = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int bb = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int aa = MathUtil.reverse(frame.get() & 0xF0);
|
||||
dup.put((byte)(aa << 4 | bb >> 4));
|
||||
dup.put((byte)(bb << 4 | cc >> 4));
|
||||
dup.put((byte)(cc << 4));
|
||||
}
|
||||
dup.flip();
|
||||
return new AudioBuffer(dup, new AudioFormat(SAMPLE_RATE, 24, channels, true, true), i / channels);
|
||||
}
|
||||
int nSamples = frame.remaining() / 5 * 2;
|
||||
while (frame.remaining() > 4) {
|
||||
byte bb = (byte)MathUtil.reverse(frame.get() & 0xFF);
|
||||
byte aa = (byte)MathUtil.reverse(frame.get() & 0xFF);
|
||||
int c = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int b = MathUtil.reverse(frame.get() & 0xFF);
|
||||
int a = MathUtil.reverse(frame.get() & 0xF0);
|
||||
dst.put(aa);
|
||||
dst.put(bb);
|
||||
dst.put((byte)(a << 4 | b >> 4));
|
||||
dst.put((byte)(b << 4 | c >> 4));
|
||||
}
|
||||
dup.flip();
|
||||
return new AudioBuffer(dup, new AudioFormat(SAMPLE_RATE, 16, channels, true, true), nSamples / channels);
|
||||
}
|
||||
|
||||
public AudioCodecMeta getCodecMeta(ByteBuffer _data) throws IOException {
|
||||
ByteBuffer frame = _data.duplicate();
|
||||
frame.order(ByteOrder.BIG_ENDIAN);
|
||||
int h = frame.getInt();
|
||||
int frameSize = h >> 16 & 0xFFFF;
|
||||
if (frame.remaining() != frameSize)
|
||||
throw new IllegalArgumentException("Wrong s302m frame");
|
||||
int channels = (h >> 14 & 0x3) * 2 + 2;
|
||||
int sampleSizeInBits = (h >> 4 & 0x3) * 4 + 16;
|
||||
return AudioCodecMeta.fromAudioFormat(new AudioFormat(SAMPLE_RATE, sampleSizeInBits, channels, true, true));
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package org.jcodec.codecs.s302;
|
||||
|
||||
import org.jcodec.common.model.ChannelLabel;
|
||||
|
||||
public class S302MUtils {
|
||||
public static String name(int channels) {
|
||||
switch (channels) {
|
||||
case 1:
|
||||
return "Mono";
|
||||
case 2:
|
||||
return "Stereo 2.0";
|
||||
case 4:
|
||||
return "Surround 4.0";
|
||||
case 8:
|
||||
return "Stereo 2.0 + Surround 5.1";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ChannelLabel[] labels(int channels) {
|
||||
switch (channels) {
|
||||
case 1:
|
||||
return new ChannelLabel[] { ChannelLabel.MONO };
|
||||
case 2:
|
||||
return new ChannelLabel[] { ChannelLabel.STEREO_LEFT, ChannelLabel.STEREO_RIGHT };
|
||||
case 4:
|
||||
return new ChannelLabel[] { ChannelLabel.FRONT_LEFT, ChannelLabel.FRONT_RIGHT, ChannelLabel.REAR_LEFT, ChannelLabel.REAR_RIGHT };
|
||||
case 8:
|
||||
return new ChannelLabel[] { ChannelLabel.STEREO_LEFT, ChannelLabel.STEREO_RIGHT, ChannelLabel.FRONT_LEFT, ChannelLabel.FRONT_RIGHT, ChannelLabel.REAR_LEFT, ChannelLabel.REAR_RIGHT, ChannelLabel.CENTER, ChannelLabel.LFE };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue