mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 12:03:02 +00:00
Improve performance of the CPU decoder and add some details about changing decoders
This commit is contained in:
parent
a17af070c5
commit
4ae29b0075
@ -21,14 +21,14 @@ import com.limelight.nvstream.av.video.cpu.AvcDecoder;
|
|||||||
@SuppressWarnings("EmptyCatchBlock")
|
@SuppressWarnings("EmptyCatchBlock")
|
||||||
public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
||||||
|
|
||||||
private Thread rendererThread;
|
private Thread rendererThread, decoderThread;
|
||||||
private int targetFps;
|
private int targetFps;
|
||||||
|
|
||||||
private static final int DECODER_BUFFER_SIZE = 92*1024;
|
private static final int DECODER_BUFFER_SIZE = 92*1024;
|
||||||
private ByteBuffer decoderBuffer;
|
private ByteBuffer decoderBuffer;
|
||||||
|
|
||||||
// Only sleep if the difference is above this value
|
// Only sleep if the difference is above this value
|
||||||
private static final int WAIT_CEILING_MS = 8;
|
private static final int WAIT_CEILING_MS = 5;
|
||||||
|
|
||||||
private static final int LOW_PERF = 1;
|
private static final int LOW_PERF = 1;
|
||||||
private static final int MED_PERF = 2;
|
private static final int MED_PERF = 2;
|
||||||
@ -108,9 +108,7 @@ public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
|
|
||||||
case LOW_PERF:
|
case LOW_PERF:
|
||||||
// Disable the loop filter for performance reasons
|
// Disable the loop filter for performance reasons
|
||||||
avcFlags = AvcDecoder.DISABLE_LOOP_FILTER |
|
avcFlags = AvcDecoder.FAST_BILINEAR_FILTERING;
|
||||||
AvcDecoder.FAST_BILINEAR_FILTERING |
|
|
||||||
AvcDecoder.FAST_DECODE;
|
|
||||||
|
|
||||||
// Use plenty of threads to try to utilize the CPU as best we can
|
// Use plenty of threads to try to utilize the CPU as best we can
|
||||||
threadCount = cpuCount - 1;
|
threadCount = cpuCount - 1;
|
||||||
@ -118,8 +116,7 @@ public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
case MED_PERF:
|
case MED_PERF:
|
||||||
avcFlags = AvcDecoder.BILINEAR_FILTERING |
|
avcFlags = AvcDecoder.BILINEAR_FILTERING;
|
||||||
AvcDecoder.FAST_DECODE;
|
|
||||||
|
|
||||||
// Only use 2 threads to minimize frame processing latency
|
// Only use 2 threads to minimize frame processing latency
|
||||||
threadCount = 2;
|
threadCount = 2;
|
||||||
@ -156,6 +153,26 @@ public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean start(final VideoDepacketizer depacketizer) {
|
public boolean start(final VideoDepacketizer depacketizer) {
|
||||||
|
decoderThread = new Thread() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
DecodeUnit du;
|
||||||
|
while (!isInterrupted()) {
|
||||||
|
try {
|
||||||
|
du = depacketizer.takeNextDecodeUnit();
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
submitDecodeUnit(du);
|
||||||
|
depacketizer.freeDecodeUnit(du);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
decoderThread.setName("Video - Decoder (CPU)");
|
||||||
|
decoderThread.setPriority(Thread.MAX_PRIORITY - 1);
|
||||||
|
decoderThread.start();
|
||||||
|
|
||||||
rendererThread = new Thread() {
|
rendererThread = new Thread() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
@ -163,17 +180,15 @@ public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
DecodeUnit du;
|
DecodeUnit du;
|
||||||
while (!isInterrupted())
|
while (!isInterrupted())
|
||||||
{
|
{
|
||||||
du = depacketizer.pollNextDecodeUnit();
|
|
||||||
if (du != null) {
|
|
||||||
submitDecodeUnit(du);
|
|
||||||
depacketizer.freeDecodeUnit(du);
|
|
||||||
}
|
|
||||||
|
|
||||||
long diff = nextFrameTime - System.currentTimeMillis();
|
long diff = nextFrameTime - System.currentTimeMillis();
|
||||||
|
|
||||||
if (diff > WAIT_CEILING_MS) {
|
if (diff > WAIT_CEILING_MS) {
|
||||||
LockSupport.parkNanos(1);
|
try {
|
||||||
continue;
|
Thread.sleep(diff - WAIT_CEILING_MS);
|
||||||
|
} catch (InterruptedException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
nextFrameTime = computePresentationTimeMs(targetFps);
|
nextFrameTime = computePresentationTimeMs(targetFps);
|
||||||
@ -194,10 +209,14 @@ public class AndroidCpuDecoderRenderer implements VideoDecoderRenderer {
|
|||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
rendererThread.interrupt();
|
rendererThread.interrupt();
|
||||||
|
decoderThread.interrupt();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
rendererThread.join();
|
rendererThread.join();
|
||||||
} catch (InterruptedException e) { }
|
} catch (InterruptedException e) { }
|
||||||
|
try {
|
||||||
|
decoderThread.join();
|
||||||
|
} catch (InterruptedException e) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -106,4 +106,5 @@
|
|||||||
|
|
||||||
<string name="category_advanced_settings">Advanced Settings</string>
|
<string name="category_advanced_settings">Advanced Settings</string>
|
||||||
<string name="title_decoder_list">Change decoder</string>
|
<string name="title_decoder_list">Change decoder</string>
|
||||||
|
<string name="summary_decoder_list">Software decoding may improve video latency at lower streaming settings</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -52,6 +52,7 @@
|
|||||||
android:title="@string/title_decoder_list"
|
android:title="@string/title_decoder_list"
|
||||||
android:entries="@array/decoder_names"
|
android:entries="@array/decoder_names"
|
||||||
android:entryValues="@array/decoder_values"
|
android:entryValues="@array/decoder_values"
|
||||||
|
android:summary="@string/summary_decoder_list"
|
||||||
android:defaultValue="auto" />
|
android:defaultValue="auto" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user