Skip to content

Commit

Permalink
Implement foundation for HDR support
Browse files Browse the repository at this point in the history
Likely not functional for any decoder yet
  • Loading branch information
cgutman committed Nov 9, 2022
1 parent 28ace51 commit c2f21b9
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 46 deletions.
4 changes: 3 additions & 1 deletion libgamestream/client.c
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,9 @@ int gs_start_app(PSERVER_DATA server, STREAM_CONFIGURATION *config, int appId, b
// used to use 60 here but that locked the frame rate to 60 FPS
// on GFE 3.20.3.
int fps = config->fps > 60 ? 0 : config->fps;
snprintf(url, sizeof(url), "https://%s:%u/launch?uniqueid=%s&uuid=%s&appid=%d&mode=%dx%dx%d&additionalStates=1&sops=%d&rikey=%s&rikeyid=%d&localAudioPlayMode=%d&surroundAudioInfo=%d&remoteControllersBitmap=%d&gcmap=%d", server->serverInfo.address, server->httpsPort, unique_id, uuid_str, appId, config->width, config->height, fps, sops, rikey_hex, rikeyid, localaudio, surround_info, gamepad_mask, gamepad_mask);
snprintf(url, sizeof(url), "https://%s:%u/launch?uniqueid=%s&uuid=%s&appid=%d&mode=%dx%dx%d&additionalStates=1&sops=%d&rikey=%s&rikeyid=%d&localAudioPlayMode=%d&surroundAudioInfo=%d&remoteControllersBitmap=%d&gcmap=%d%s",
server->serverInfo.address, server->httpsPort, unique_id, uuid_str, appId, config->width, config->height, fps, sops, rikey_hex, rikeyid, localaudio, surround_info, gamepad_mask, gamepad_mask,
config->enableHdr ? "&hdrMode=1&clientHdrCapVersion=0&clientHdrCapSupportedFlagsInUint32=0&clientHdrCapMetaDataId=NV_STATIC_METADATA_TYPE_1&clientHdrCapDisplayData=0x0x0x0x0x0x0x0x0x0x0" : "");
} else
snprintf(url, sizeof(url), "https://%s:%u/resume?uniqueid=%s&uuid=%s&rikey=%s&rikeyid=%d&surroundAudioInfo=%d", server->serverInfo.address, server->httpsPort, unique_id, uuid_str, rikey_hex, rikeyid, surround_info);

Expand Down
4 changes: 4 additions & 0 deletions src/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ static struct option long_options[] = {
{"nomouseemulation", no_argument, NULL, '4'},
{"pin", required_argument, NULL, '5'},
{"port", required_argument, NULL, '6'},
{"hdr", no_argument, NULL, '7'},
{0, 0, 0, 0},
};

Expand Down Expand Up @@ -252,6 +253,9 @@ static void parse_argument(int c, char* value, PCONFIGURATION config) {
case '6':
config->port = atoi(value);
break;
case '7':
config->stream.enableHdr = true;
break;
case 1:
if (config->action == NULL)
config->action = value;
Expand Down
5 changes: 5 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ static void help() {
printf("\t-bitrate <bitrate>\tSpecify the bitrate in Kbps\n");
printf("\t-packetsize <size>\tSpecify the maximum packetsize in bytes\n");
printf("\t-codec <codec>\t\tSelect used codec: auto/h264/h265 (default auto)\n");
printf("\t-hdr\t\tEnable HDR streaming (experimental, requires host and device support)\n");
printf("\t-remote <yes/no/auto>\t\t\tEnable optimizations for WAN streaming (default auto)\n");
printf("\t-app <app>\t\tName of app to stream\n");
printf("\t-nosops\t\t\tDon't allow GFE to modify game settings\n");
Expand Down Expand Up @@ -316,6 +317,10 @@ int main(int argc, char* argv[]) {
exit(-1);
}
config.stream.supportsHevc = config.codec != CODEC_H264 && (config.codec == CODEC_HEVC || platform_supports_hevc(system));
if (config.stream.enableHdr && !config.stream.supportsHevc) {
fprintf(stderr, "HDR streaming requires HEVC codec\n");
exit(-1);
}

#ifdef HAVE_SDL
if (system == SDL)
Expand Down
47 changes: 22 additions & 25 deletions src/video/aml.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,28 @@ int aml_setup(int videoFormat, int width, int height, int redrawRate, void* cont
codecParam.noblock = 0;
codecParam.am_sysinfo.param = 0;

switch (videoFormat) {
case VIDEO_FORMAT_H264:
if (width > 1920 || height > 1080) {
codecParam.video_type = VFORMAT_H264_4K2K;
codecParam.am_sysinfo.format = VIDEO_DEC_FORMAT_H264_4K2K;
} else {
codecParam.video_type = VFORMAT_H264;
codecParam.am_sysinfo.format = VIDEO_DEC_FORMAT_H264;

// Workaround for decoding special case of C1, 1080p, H264
int major, minor;
struct utsname name;
uname(&name);
int ret = sscanf(name.release, "%d.%d", &major, &minor);
if (!(major > 3 || (major == 3 && minor >= 14)) && width == 1920 && height == 1080)
codecParam.am_sysinfo.param = (void*) UCODE_IP_ONLY_PARAM;
}
break;
case VIDEO_FORMAT_H265:
codecParam.video_type = VFORMAT_HEVC;
codecParam.am_sysinfo.format = VIDEO_DEC_FORMAT_HEVC;
break;
default:
printf("Video format not supported\n");
return -1;
if (videoFormat & VIDEO_FORMAT_MASK_H264) {
if (width > 1920 || height > 1080) {
codecParam.video_type = VFORMAT_H264_4K2K;
codecParam.am_sysinfo.format = VIDEO_DEC_FORMAT_H264_4K2K;
} else {
codecParam.video_type = VFORMAT_H264;
codecParam.am_sysinfo.format = VIDEO_DEC_FORMAT_H264;

// Workaround for decoding special case of C1, 1080p, H264
int major, minor;
struct utsname name;
uname(&name);
int ret = sscanf(name.release, "%d.%d", &major, &minor);
if (!(major > 3 || (major == 3 && minor >= 14)) && width == 1920 && height == 1080)
codecParam.am_sysinfo.param = (void*) UCODE_IP_ONLY_PARAM;
}
} else if (videoFormat & VIDEO_FORMAT_MASK_H265) {
codecParam.video_type = VFORMAT_HEVC;
codecParam.am_sysinfo.format = VIDEO_DEC_FORMAT_HEVC;
} else {
printf("Video format not supported\n");
return -1;
}

codecParam.am_sysinfo.width = width;
Expand Down
14 changes: 7 additions & 7 deletions src/video/ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ int ffmpeg_init(int videoFormat, int width, int height, int perf_lvl, int buffer
}

ffmpeg_decoder = perf_lvl & VAAPI_ACCELERATION ? VAAPI : SOFTWARE;
switch (videoFormat) {
case VIDEO_FORMAT_H264:
decoder = avcodec_find_decoder_by_name("h264");
break;
case VIDEO_FORMAT_H265:
decoder = avcodec_find_decoder_by_name("hevc");
break;
if (videoFormat & VIDEO_FORMAT_MASK_H264) {
decoder = avcodec_find_decoder_by_name("h264");
} else if (videoFormat & VIDEO_FORMAT_MASK_H265) {
decoder = avcodec_find_decoder_by_name("hevc");
} else {
printf("Video format not supported\n");
return -1;
}

if (decoder == NULL) {
Expand Down
23 changes: 10 additions & 13 deletions src/video/rk.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,18 +254,15 @@ int rk_setup(int videoFormat, int width, int height, int redrawRate, void* conte
int ret;
int i;
int j;
int format = 0;

switch (videoFormat) {
case VIDEO_FORMAT_H264:
format = RK_H264;
break;
case VIDEO_FORMAT_H265:
format = RK_H265;
break;
default:
fprintf(stderr, "Video format not supported\n");
return -1;
int format;

if (videoFormat & VIDEO_FORMAT_MASK_H264) {
format = RK_H264;
} else if (videoFormat & VIDEO_FORMAT_MASK_H265) {
format = RK_H265;
} else {
fprintf(stderr, "Video format not supported\n");
return -1;
}

MppCodingType mpp_type = (MppCodingType)format;
Expand Down Expand Up @@ -328,7 +325,7 @@ int rk_setup(int videoFormat, int width, int height, int redrawRate, void* conte
continue;
}
for (j = 0; j < ovr->count_formats; j++) {
if (ovr->formats[j] == DRM_FORMAT_NV12) {
if (ovr->formats[j] == ((videoFormat & VIDEO_FORMAT_MASK_10BIT) ? DRM_FORMAT_NV12_10 : DRM_FORMAT_NV12)) {
break;
}
}
Expand Down

0 comments on commit c2f21b9

Please sign in to comment.