mirror of
https://github.com/moonlight-stream/moonlight-embedded.git
synced 2026-04-12 10:56:04 +00:00
Share some code between the fake and OMX video decoder
This commit is contained in:
65
src/com/limelight/binding/video/AbstractVideoRenderer.java
Normal file
65
src/com/limelight/binding/video/AbstractVideoRenderer.java
Normal file
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user