From 5a78d53f324bb36c4ee4ee29273c723741d48215 Mon Sep 17 00:00:00 2001 From: Ningyuan Li Date: Wed, 24 Apr 2024 14:21:03 +0900 Subject: [PATCH] write vui info for hdr --- src/app/stream/session.c | 33 +++++++++++++++++++++++++++++++++ third_party/ss4s | 2 +- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/app/stream/session.c b/src/app/stream/session.c index 961a25ba..0571ba80 100644 --- a/src/app/stream/session.c +++ b/src/app/stream/session.c @@ -29,6 +29,8 @@ static bool streaming_sops_supported(PDISPLAY_MODE modes, int w, int h, int fps) static void session_config_init(app_t *app, session_config_t *config, const SERVER_DATA *server, const CONFIGURATION *app_config); +static void populate_hdr_info_vui(SS4S_VideoHDRInfo *info, const STREAM_CONFIGURATION *config); + session_t *session_create(app_t *app, const CONFIGURATION *config, const SERVER_DATA *server, const APP_LIST *gs_app) { session_t *session = malloc(sizeof(session_t)); SDL_memset(session, 0, sizeof(session_t)); @@ -200,6 +202,7 @@ void streaming_set_hdr(session_t *session, bool hdr) { .maxContentLightLevel = hdr_metadata.maxContentLightLevel, .maxPicAverageLightLevel = hdr_metadata.maxFrameAverageLightLevel, }; + populate_hdr_info_vui(&info, &session->config.stream); SS4S_PlayerVideoSetHDRInfo(session->player, &info); } else { SS4S_VideoHDRInfo info = { @@ -212,6 +215,7 @@ void streaming_set_hdr(session_t *session, bool hdr) { .maxContentLightLevel = 1000, .maxPicAverageLightLevel = 400, }; + populate_hdr_info_vui(&info, &session->config.stream); SS4S_PlayerVideoSetHDRInfo(session->player, &info); } } @@ -313,3 +317,32 @@ void session_config_init(app_t *app, session_config_t *config, const SERVER_DATA config->stream.encryptionFlags = ENCFLG_AUDIO; } +/** + * Populate HDR info from stream configuration. + * Corresponds to @p avcodec_colorspace_from_sunshine_colorspace in video_colorspace.cpp in Sunshine. + * + * @param info Info for SS4S_PlayerVideoSetHDRInfo + * @param config Moonlight stream configuration + */ +static void populate_hdr_info_vui(SS4S_VideoHDRInfo *info, const STREAM_CONFIGURATION *config) { + switch (config->colorSpace) { + case COLORSPACE_REC_601: + info->colorPrimaries = 6 /* SMPTE 170M */; + info->transferCharacteristics = 6 /* SMPTE 170M */; + info->matrixCoefficients = 6 /* SMPTE 170M */; + break; + case COLORSPACE_REC_709: + info->colorPrimaries = 1 /* BT.709 */; + info->transferCharacteristics = 1 /* BT.709 */; + info->matrixCoefficients = 1 /* BT.709 */; + break; + case COLORSPACE_REC_2020: { + info->colorPrimaries = 9 /* BT.2020 */; + info->transferCharacteristics = 16 /* SMPTE ST 2084 */; + info->matrixCoefficients = 9 /* BT.2020 NCL */; + break; + } + } + info->videoFullRange = config->colorRange == COLOR_RANGE_FULL; +} + diff --git a/third_party/ss4s b/third_party/ss4s index d519091e..eed82f99 160000 --- a/third_party/ss4s +++ b/third_party/ss4s @@ -1 +1 @@ -Subproject commit d519091e166279f54e04af197de9991a9258ac0a +Subproject commit eed82f99bef239b7cfd5c492156c13e93147e381