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))
.setAudioConfiguration(prefConfig.audioConfiguration)
.setAudioEncryption(true)
.setColorSpace(decoderRenderer.getPreferredColorSpace())
.setColorRange(decoderRenderer.getPreferredColorRange())
.build();
// Initialize the connection

View File

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

View File

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

View File

@ -27,6 +27,8 @@ public class StreamConfiguration {
private boolean enableHdr;
private int attachedGamepadMask;
private int encryptionFlags;
private int colorRange;
private int colorSpace;
public static class Builder {
private StreamConfiguration config = new StreamConfiguration();
@ -132,6 +134,16 @@ public class StreamConfiguration {
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() {
return config;
}
@ -226,4 +238,12 @@ public class StreamConfiguration {
public int getEncryptionFlags() {
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_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_REFERENCE_FRAME_INVALIDATION_AVC = 2;
public static final int CAPABILITY_REFERENCE_FRAME_INVALIDATION_HEVC = 4;
@ -272,7 +279,8 @@ public class MoonBridge {
int clientRefreshRateX100,
int encryptionFlags,
byte[] riAesKey, byte[] riAesIv,
int videoCapabilities);
int videoCapabilities,
int colorSpace, int colorRange);
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 encryptionFlags,
jbyteArray riAesKey, jbyteArray riAesIv,
jint videoCapabilities) {
jint videoCapabilities,
jint colorSpace, jint colorRange) {
SERVER_INFORMATION serverInfo = {
.address = (*env)->GetStringUTFChars(env, address, 0),
.serverInfoAppVersion = (*env)->GetStringUTFChars(env, appVersion, 0),
@ -406,6 +407,8 @@ Java_com_limelight_nvstream_jni_MoonBridge_startConnection(JNIEnv *env, jclass c
.hevcBitratePercentageMultiplier = hevcBitratePercentageMultiplier,
.clientRefreshRateX100 = clientRefreshRateX100,
.encryptionFlags = encryptionFlags,
.colorSpace = colorSpace,
.colorRange = colorRange
};
jbyte* riAesKeyBuf = (*env)->GetByteArrayElements(env, riAesKey, NULL);