Request limited color range by default

Most devices currently use limited color range, but some recent devices
encode in full color range, which is currently not supported by the SDL
opengl render driver.

Fixes #4756 <https://github.com/Genymobile/scrcpy/issues/4756>
Refs <https://github.com/Genymobile/scrcpy/issues/4756#issuecomment-2003710860>
Refs libusb/#9311 <https://github.com/libsdl-org/SDL/issues/9311>

Signed-off-by: Romain Vimont <rom@rom1v.com>
This commit is contained in:
Simon Chan 2024-03-30 15:25:14 +01:00 committed by Romain Vimont
parent db55edb196
commit bf625790fa

View File

@ -3,6 +3,7 @@ package com.genymobile.scrcpy;
import android.media.MediaCodec;
import android.media.MediaCodecInfo;
import android.media.MediaFormat;
import android.os.Build;
import android.os.Looper;
import android.os.SystemClock;
import android.view.Surface;
@ -220,6 +221,9 @@ public class SurfaceEncoder implements AsyncProcessor {
// must be present to configure the encoder, but does not impact the actual frame rate, which is variable
format.setInteger(MediaFormat.KEY_FRAME_RATE, 60);
format.setInteger(MediaFormat.KEY_COLOR_FORMAT, MediaCodecInfo.CodecCapabilities.COLOR_FormatSurface);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
format.setInteger(MediaFormat.KEY_COLOR_RANGE, MediaFormat.COLOR_RANGE_LIMITED);
}
format.setInteger(MediaFormat.KEY_I_FRAME_INTERVAL, DEFAULT_I_FRAME_INTERVAL);
// display the very first frame, and recover from bad quality when no new frames
format.setLong(MediaFormat.KEY_REPEAT_PREVIOUS_FRAME_AFTER, REPEAT_FRAME_DELAY_US); // µs