mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-06-17 06:11:36 +00:00
Share some code between the fake and OMX video decoder
This commit is contained in:
@@ -0,0 +1,65 @@
|
|||||||
|
package com.limelight.binding.video;
|
||||||
|
|
||||||
|
import com.limelight.LimeLog;
|
||||||
|
import com.limelight.nvstream.av.DecodeUnit;
|
||||||
|
import com.limelight.nvstream.av.video.VideoDecoderRenderer;
|
||||||
|
import com.limelight.nvstream.av.video.VideoDepacketizer;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract implementation of a video decoder.
|
||||||
|
* @author Iwan Timmer
|
||||||
|
*/
|
||||||
|
public abstract class AbstractVideoRenderer implements VideoDecoderRenderer {
|
||||||
|
|
||||||
|
private Thread thread;
|
||||||
|
private boolean running;
|
||||||
|
|
||||||
|
private int dataSize;
|
||||||
|
private long last;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void start(final VideoDepacketizer depacketizer) {
|
||||||
|
last = System.currentTimeMillis();
|
||||||
|
thread = new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
while (running) {
|
||||||
|
try {
|
||||||
|
DecodeUnit decodeUnit = depacketizer.takeNextDecodeUnit();
|
||||||
|
|
||||||
|
dataSize += decodeUnit.getDataLength();
|
||||||
|
decodeUnit(decodeUnit);
|
||||||
|
|
||||||
|
if (System.currentTimeMillis()>last+2000) {
|
||||||
|
int bitrate = (dataSize/2)/1024;
|
||||||
|
System.out.println("Video " + bitrate + "kB/s");
|
||||||
|
dataSize = 0;
|
||||||
|
last = System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
} catch (InterruptedException ex) { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
running = true;
|
||||||
|
thread.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stop() {
|
||||||
|
running = false;
|
||||||
|
thread.interrupt();
|
||||||
|
try {
|
||||||
|
thread.join();
|
||||||
|
} catch (InterruptedException ex) {
|
||||||
|
LimeLog.severe(ex.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void decodeUnit(DecodeUnit decodeUnit);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCapabilities() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -3,8 +3,6 @@ package com.limelight.binding.video;
|
|||||||
import com.limelight.LimeLog;
|
import com.limelight.LimeLog;
|
||||||
import com.limelight.nvstream.av.ByteBufferDescriptor;
|
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.VideoDepacketizer;
|
|
||||||
import java.io.FileNotFoundException;
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -14,14 +12,8 @@ import java.io.OutputStream;
|
|||||||
* Implementation of a video decoder and renderer.
|
* Implementation of a video decoder and renderer.
|
||||||
* @author Iwan Timmer
|
* @author Iwan Timmer
|
||||||
*/
|
*/
|
||||||
public class FakeVideoRenderer implements VideoDecoderRenderer {
|
public class FakeVideoRenderer extends AbstractVideoRenderer {
|
||||||
|
|
||||||
private Thread thread;
|
|
||||||
private boolean running;
|
|
||||||
|
|
||||||
private int dataSize;
|
|
||||||
private long last;
|
|
||||||
|
|
||||||
private OutputStream out;
|
private OutputStream out;
|
||||||
|
|
||||||
public FakeVideoRenderer(String videoFile) {
|
public FakeVideoRenderer(String videoFile) {
|
||||||
@@ -38,33 +30,10 @@ public class FakeVideoRenderer implements VideoDecoderRenderer {
|
|||||||
System.out.println("Fake " + width + "x" + height + " " + redrawRate + "fps video output");
|
System.out.println("Fake " + width + "x" + height + " " + redrawRate + "fps video output");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(final VideoDepacketizer depacketizer) {
|
|
||||||
last = System.currentTimeMillis();
|
|
||||||
thread = new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (running) {
|
|
||||||
try {
|
|
||||||
decodeUnit(depacketizer.takeNextDecodeUnit());
|
|
||||||
} catch (InterruptedException ex) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
running = true;
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
running = false;
|
super.stop();
|
||||||
thread.interrupt();
|
|
||||||
try {
|
|
||||||
thread.join();
|
|
||||||
} catch (InterruptedException ex) {
|
|
||||||
LimeLog.severe(ex.getMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (out!=null)
|
if (out!=null)
|
||||||
out.close();
|
out.close();
|
||||||
@@ -77,31 +46,16 @@ public class FakeVideoRenderer implements VideoDecoderRenderer {
|
|||||||
public void release() {
|
public void release() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean decodeUnit(DecodeUnit decodeUnit) {
|
@Override
|
||||||
if (System.currentTimeMillis()>last+2000) {
|
public void decodeUnit(DecodeUnit decodeUnit) {
|
||||||
int bitrate = (dataSize/2)/1024;
|
|
||||||
System.out.println("Video " + bitrate + "kB/s");
|
|
||||||
dataSize = 0;
|
|
||||||
last = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
dataSize += decodeUnit.getDataLength();
|
|
||||||
|
|
||||||
if (out!=null) {
|
if (out!=null) {
|
||||||
try {
|
try {
|
||||||
for (ByteBufferDescriptor buf:decodeUnit.getBufferList())
|
for (ByteBufferDescriptor buf:decodeUnit.getBufferList())
|
||||||
out.write(buf.data, buf.offset, buf.length);
|
out.write(buf.data, buf.offset, buf.length);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LimeLog.severe(e.getMessage());
|
LimeLog.severe(e.getMessage());
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCapabilities() {
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package com.limelight.binding.video;
|
|||||||
|
|
||||||
import com.limelight.nvstream.av.ByteBufferDescriptor;
|
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.VideoDepacketizer;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -11,12 +9,9 @@ import java.util.List;
|
|||||||
* Implementation of a video decoder and renderer.
|
* Implementation of a video decoder and renderer.
|
||||||
* @author Iwan Timmer
|
* @author Iwan Timmer
|
||||||
*/
|
*/
|
||||||
public class OmxDecoderRenderer implements VideoDecoderRenderer {
|
public class OmxDecoderRenderer extends AbstractVideoRenderer {
|
||||||
|
|
||||||
private final static byte[] BITSTREAM_RESTRICTIONS = new byte[] {(byte) 0xF1, (byte) 0x83, 0x2A, 0x00};
|
private final static byte[] BITSTREAM_RESTRICTIONS = new byte[] {(byte) 0xF1, (byte) 0x83, 0x2A, 0x00};
|
||||||
|
|
||||||
private Thread thread;
|
|
||||||
private boolean running;
|
|
||||||
|
|
||||||
@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) {
|
||||||
@@ -25,24 +20,9 @@ public class OmxDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
throw new IllegalStateException("AVC decoder initialization failure: "+err);
|
throw new IllegalStateException("AVC decoder initialization failure: "+err);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void start(final VideoDepacketizer depacketizer) {
|
|
||||||
thread = new Thread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (running) {
|
|
||||||
try {
|
|
||||||
decodeUnit(depacketizer.takeNextDecodeUnit());
|
|
||||||
} catch (InterruptedException ex) { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
running = true;
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
|
super.stop();
|
||||||
OmxDecoder.stop();
|
OmxDecoder.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,6 +31,7 @@ public class OmxDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
OmxDecoder.destroy();
|
OmxDecoder.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void decodeUnit(DecodeUnit decodeUnit) {
|
public void decodeUnit(DecodeUnit decodeUnit) {
|
||||||
List<ByteBufferDescriptor> units = decodeUnit.getBufferList();
|
List<ByteBufferDescriptor> units = decodeUnit.getBufferList();
|
||||||
|
|
||||||
@@ -72,11 +53,6 @@ public class OmxDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getCapabilities() {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Replace bits in array
|
* Replace bits in array
|
||||||
* @param source array in which bits should be replaced
|
* @param source array in which bits should be replaced
|
||||||
|
|||||||
Reference in New Issue
Block a user