Plumb colorspace and color range into MediaCodecDecoderRenderer

This commit is contained in:
Cameron Gutman 2022-10-13 00:51:15 -05:00
parent 2cbc94e51d
commit d0432de981
6 changed files with 47 additions and 4 deletions

View File

@ -475,6 +475,8 @@ public class Game extends Activity implements SurfaceHolder.Callback,
.setClientRefreshRateX100((int)(displayRefreshRate * 100)) .setClientRefreshRateX100((int)(displayRefreshRate * 100))
.setAudioConfiguration(prefConfig.audioConfiguration) .setAudioConfiguration(prefConfig.audioConfiguration)
.setAudioEncryption(true) .setAudioEncryption(true)
.setColorSpace(decoderRenderer.getPreferredColorSpace())
.setColorRange(decoderRenderer.getPreferredColorRange())
.build(); .build();
// Initialize the connection // Initialize the connection

View File

@ -326,6 +326,14 @@ public class MediaCodecDecoderRenderer extends VideoDecoderRenderer implements C
return false; return false;
} }
public int getPreferredColorSpace() {
return MoonBridge.COLORSPACE_REC_601;
}
public int getPreferredColorRange() {
return MoonBridge.COLOR_RANGE_LIMITED;
}
public void notifyVideoForeground() { public void notifyVideoForeground() {
foreground = true; foreground = true;
} }

View File

@ -319,7 +319,9 @@ public class NvConnection {
context.streamConfig.getClientRefreshRateX100(), context.streamConfig.getClientRefreshRateX100(),
context.streamConfig.getEncryptionFlags(), context.streamConfig.getEncryptionFlags(),
context.riKey.getEncoded(), ib.array(), context.riKey.getEncoded(), ib.array(),
context.videoCapabilities); context.videoCapabilities,
context.streamConfig.getColorSpace(),
context.streamConfig.getColorRange());
if (ret != 0) { if (ret != 0) {
// LiStartConnection() failed, so the caller is not expected // LiStartConnection() failed, so the caller is not expected
// to stop the connection themselves. We need to release their // to stop the connection themselves. We need to release their

View File

@ -27,6 +27,8 @@ public class StreamConfiguration {
private boolean enableHdr; private boolean enableHdr;
private int attachedGamepadMask; private int attachedGamepadMask;
private int encryptionFlags; private int encryptionFlags;
private int colorRange;
private int colorSpace;
public static class Builder { public static class Builder {
private StreamConfiguration config = new StreamConfiguration(); private StreamConfiguration config = new StreamConfiguration();
@ -131,7 +133,17 @@ public class StreamConfiguration {
config.supportsHevc = supportsHevc; config.supportsHevc = supportsHevc;
return this; return this;
} }
public StreamConfiguration.Builder setColorRange(int colorRange) {
config.colorRange = colorRange;
return this;
}
public StreamConfiguration.Builder setColorSpace(int colorSpace) {
config.colorSpace = colorSpace;
return this;
}
public StreamConfiguration build() { public StreamConfiguration build() {
return config; return config;
} }
@ -226,4 +238,12 @@ public class StreamConfiguration {
public int getEncryptionFlags() { public int getEncryptionFlags() {
return encryptionFlags; return encryptionFlags;
} }
public int getColorRange() {
return colorRange;
}
public int getColorSpace() {
return colorSpace;
}
} }

View File

@ -30,6 +30,13 @@ public class MoonBridge {
public static final int FRAME_TYPE_PFRAME = 0; public static final int FRAME_TYPE_PFRAME = 0;
public static final int FRAME_TYPE_IDR = 1; public static final int FRAME_TYPE_IDR = 1;
public static final int COLORSPACE_REC_601 = 0;
public static final int COLORSPACE_REC_709 = 1;
public static final int COLORSPACE_REC_2020 = 2;
public static final int COLOR_RANGE_LIMITED = 0;
public static final int COLOR_RANGE_FULL = 1;
public static final int CAPABILITY_DIRECT_SUBMIT = 1; public static final int CAPABILITY_DIRECT_SUBMIT = 1;
public static final int CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC = 2; public static final int CAPABILITY_REFERENCE_FRAME_INVALIDATION_AVC = 2;
public static final int CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC = 4; public static final int CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC = 4;
@ -272,7 +279,8 @@ public class MoonBridge {
int clientRefreshRateX100, int clientRefreshRateX100,
int encryptionFlags, int encryptionFlags,
byte[] riAesKey, byte[] riAesIv, byte[] riAesKey, byte[] riAesIv,
int videoCapabilities); int videoCapabilities,
int colorSpace, int colorRange);
public static native void stopConnection(); public static native void stopConnection();

View File

@ -386,7 +386,8 @@ Java_com_limelight_nvstream_jni_MoonBridge_startConnection(JNIEnv *env, jclass c
jint clientRefreshRateX100, jint clientRefreshRateX100,
jint encryptionFlags, jint encryptionFlags,
jbyteArray riAesKey, jbyteArray riAesIv, jbyteArray riAesKey, jbyteArray riAesIv,
jint videoCapabilities) { jint videoCapabilities,
jint colorSpace, jint colorRange) {
SERVER_INFORMATION serverInfo = { SERVER_INFORMATION serverInfo = {
.address = (*env)->GetStringUTFChars(env, address, 0), .address = (*env)->GetStringUTFChars(env, address, 0),
.serverInfoAppVersion = (*env)->GetStringUTFChars(env, appVersion, 0), .serverInfoAppVersion = (*env)->GetStringUTFChars(env, appVersion, 0),
@ -406,6 +407,8 @@ Java_com_limelight_nvstream_jni_MoonBridge_startConnection(JNIEnv *env, jclass c
.hevcBitratePercentageMultiplier = hevcBitratePercentageMultiplier, .hevcBitratePercentageMultiplier = hevcBitratePercentageMultiplier,
.clientRefreshRateX100 = clientRefreshRateX100, .clientRefreshRateX100 = clientRefreshRateX100,
.encryptionFlags = encryptionFlags, .encryptionFlags = encryptionFlags,
.colorSpace = colorSpace,
.colorRange = colorRange
}; };
jbyte* riAesKeyBuf = (*env)->GetByteArrayElements(env, riAesKey, NULL); jbyte* riAesKeyBuf = (*env)->GetByteArrayElements(env, riAesKey, NULL);