Add SPX fix which works on all lengths

This commit is contained in:
Iwan Timmer
2014-01-10 18:06:19 +01:00
parent 92068b28fe
commit fadae8c9d7

View File

@@ -4,7 +4,6 @@ import com.limelight.nvstream.av.ByteBufferDescriptor;
import com.limelight.nvstream.av.DecodeUnit; import com.limelight.nvstream.av.DecodeUnit;
import com.limelight.nvstream.av.video.VideoDecoderRenderer; import com.limelight.nvstream.av.video.VideoDecoderRenderer;
import java.nio.ByteBuffer;
import java.util.List; import java.util.List;
/** /**
@@ -13,6 +12,8 @@ import java.util.List;
*/ */
public class OmxDecoderRenderer implements VideoDecoderRenderer { public class OmxDecoderRenderer implements VideoDecoderRenderer {
private final static int BITSTREAM_RESTRICTIONS = (int) 0xF1832C00l;
@Override @Override
public void setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) { public void setup(int width, int height, int redrawRate, Object renderTarget, int drFlags) {
int err = OmxDecoder.init(); int err = OmxDecoder.init();
@@ -42,6 +43,27 @@ public class OmxDecoderRenderer implements VideoDecoderRenderer {
public boolean submitDecodeUnit(DecodeUnit decodeUnit) { public boolean submitDecodeUnit(DecodeUnit decodeUnit) {
boolean ok = true; boolean ok = true;
List<ByteBufferDescriptor> units = decodeUnit.getBufferList(); List<ByteBufferDescriptor> units = decodeUnit.getBufferList();
ByteBufferDescriptor header = units.get(0);
if (header.data[header.offset+4] == 0x67) {
byte last = header.data[header.length+header.offset-1];
//Start bit before stop bit
int shift = (Integer.numberOfLeadingZeros(last & - last) - 1)%8;
int bitstream_restriction = BITSTREAM_RESTRICTIONS >>> shift;
boolean twoBytes = shift==7;
int index = header.length + header.offset - (twoBytes?2:1);
header.data[index] = (byte) (((int) header.data[index] & 0xFF) | (bitstream_restriction >>> 24));
header.data[index+1] = (byte) ((twoBytes?((int) header.data[index+1] & 0xFF):0) | (bitstream_restriction >>> 16));
header.data[index+2] = (byte) (bitstream_restriction >>> 8);
header.length += twoBytes?1:2;
if (Integer.numberOfTrailingZeros(bitstream_restriction) < 8) {
header.data[index+3] = (byte) (bitstream_restriction);
header.length++;
}
}
for (int i=0;i<units.size();i++) { for (int i=0;i<units.size();i++) {
ByteBufferDescriptor bbd = units.get(i); ByteBufferDescriptor bbd = units.get(i);
if (ok) if (ok)