From e2d1c110640f37492121bc4108a76b91f7f90370 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Tue, 22 Dec 2020 14:28:36 +0100 Subject: [PATCH] Finish new LaunchSpec --- gui/src/settings.cpp | 3 ++- lib/include/chiaki/common.h | 10 ++++++++++ lib/src/launchspec.c | 22 ++++++++++++++-------- 3 files changed, 26 insertions(+), 9 deletions(-) diff --git a/gui/src/settings.cpp b/gui/src/settings.cpp index e08ec57..3f637bb 100644 --- a/gui/src/settings.cpp +++ b/gui/src/settings.cpp @@ -204,11 +204,12 @@ void Settings::SetAudioBufferSize(unsigned int size) ChiakiConnectVideoProfile Settings::GetVideoProfile() { - ChiakiConnectVideoProfile profile; + ChiakiConnectVideoProfile profile = {}; chiaki_connect_video_profile_preset(&profile, GetResolution(), GetFPS()); unsigned int bitrate = GetBitrate(); if(bitrate) profile.bitrate = bitrate; + profile.codec = CHIAKI_CODEC_H264; // TODO: add a setting return profile; } diff --git a/lib/include/chiaki/common.h b/lib/include/chiaki/common.h index 8ad249b..b28f696 100644 --- a/lib/include/chiaki/common.h +++ b/lib/include/chiaki/common.h @@ -89,6 +89,16 @@ typedef enum CHIAKI_CODEC_H265_HDR } ChiakiCodec; +static inline bool chiaki_codec_is_h265(ChiakiCodec codec) +{ + return codec == CHIAKI_CODEC_H265 || codec == CHIAKI_CODEC_H265_HDR; +} + +static inline bool chiaki_codec_is_hdr(ChiakiCodec codec) +{ + return codec == CHIAKI_CODEC_H265_HDR; +} + #ifdef __cplusplus } #endif diff --git a/lib/src/launchspec.c b/lib/src/launchspec.c index 9da96ba..abed382 100644 --- a/lib/src/launchspec.c +++ b/lib/src/launchspec.c @@ -50,7 +50,8 @@ static const char launchspec_fmt[] = "\"connectedControllers\":[\"xinput\",\"ds3\",\"ds4\"]," "\"yuvCoefficient\":\"bt601\"," "\"videoEncoderProfile\":\"hw4.1\"," - "\"audioEncoderProfile\":\"audio1\"" + "\"audioEncoderProfile\":\"audio1\"" // 6 + "%s" "}," "\"userProfile\":{" "\"onlineId\":\"psnId\"," @@ -58,9 +59,9 @@ static const char launchspec_fmt[] = "\"region\":\"US\"," "\"languagesUsed\":[\"en\",\"jp\"]" "}," - "%s" // 6 "%s" // 7 - "\"handshakeKey\":\"%s\"" // 8 + "%s" // 8 + "\"handshakeKey\":\"%s\"" // 9 "}"; CHIAKI_EXPORT int chiaki_launchspec_format(char *buf, size_t buf_size, ChiakiLaunchSpec *launch_spec) @@ -70,19 +71,24 @@ CHIAKI_EXPORT int chiaki_launchspec_format(char *buf, size_t buf_size, ChiakiLau if(err != CHIAKI_ERR_SUCCESS) return -1; - char *extras[2]; + char *extras[3]; if(chiaki_target_is_ps5(launch_spec->target)) // TODO: probably also for ps4, but only 12 { - extras[0] = "\"videoCodec\":\"avc\","; // TODO: hevc too - extras[1] = "\"dynamicRange\":\"SDR\","; // TODO: HDR too + extras[0] = ",\"adaptiveStreamMode\": \"resize\""; + extras[1] = chiaki_codec_is_h265(launch_spec->codec) + ? "\"videoCodec\":\"hevc\"," + : "\"videoCodec\":\"avc\","; + extras[2] = chiaki_codec_is_hdr(launch_spec->codec) + ? "\"dynamicRange\":\"HDR\"," + : "\"dynamicRange\":\"SDR\","; } else - extras[0] = extras[1] = ""; + extras[0] = extras[1] = extras[2] = ""; int written = snprintf(buf, buf_size, launchspec_fmt, launch_spec->width, launch_spec->height, launch_spec->max_fps, launch_spec->bw_kbps_sent, launch_spec->mtu, launch_spec->rtt, - extras[0], extras[1], handshake_key_b64); + extras[0], extras[1], extras[2], handshake_key_b64); if(written < 0 || written >= buf_size) return -1; return written;