From b9b4b7321bb7e194fd06db52d1a43e77dff0b893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Wed, 21 Aug 2019 13:36:10 +0200 Subject: [PATCH] Set Bitrate in LaunchSpec --- lib/include/chiaki/launchspec.h | 1 + lib/include/chiaki/session.h | 1 + lib/src/launchspec.c | 16 ++++++++-------- lib/src/session.c | 7 ++++++- lib/src/streamconnection.c | 1 + 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/include/chiaki/launchspec.h b/lib/include/chiaki/launchspec.h index ce52527..7772dc3 100644 --- a/lib/include/chiaki/launchspec.h +++ b/lib/include/chiaki/launchspec.h @@ -35,6 +35,7 @@ typedef struct chiaki_launch_spec_t unsigned int width; unsigned int height; unsigned int max_fps; + unsigned int bw_kbps_sent; } ChiakiLaunchSpec; CHIAKI_EXPORT int chiaki_launchspec_format(char *buf, size_t buf_size, ChiakiLaunchSpec *launch_spec); diff --git a/lib/include/chiaki/session.h b/lib/include/chiaki/session.h index 79bb97f..8d8e712 100644 --- a/lib/include/chiaki/session.h +++ b/lib/include/chiaki/session.h @@ -48,6 +48,7 @@ typedef struct chiaki_connect_video_profile_t unsigned int width; unsigned int height; unsigned int max_fps; + unsigned int bitrate; } ChiakiConnectVideoProfile; typedef enum { diff --git a/lib/src/launchspec.c b/lib/src/launchspec.c index 76bfdb1..438ae9d 100644 --- a/lib/src/launchspec.c +++ b/lib/src/launchspec.c @@ -28,18 +28,18 @@ static const char launchspec_fmt[] = "{" "\"resolution\":" "{" - "\"width\":%u," - "\"height\":%u" + "\"width\":%u," // 0 + "\"height\":%u" // 1 "}," - "\"maxFps\":%u," + "\"maxFps\":%u," // 2 "\"score\":10" "}" "]," "\"network\":{" - "\"bwKbpsSent\":2000," + "\"bwKbpsSent\":%u," // 3 "\"bwLoss\":0.001000," - "\"mtu\":%u," // 0 - "\"rtt\":%u," // 1 + "\"mtu\":%u," // 4 + "\"rtt\":%u," // 5 "\"ports\":[53,2053]" "}," "\"slotId\":1," @@ -73,7 +73,7 @@ static const char launchspec_fmt[] = "\"region\":\"US\"," "\"languagesUsed\":[\"en\",\"jp\"]" "}," - "\"handshakeKey\":\"%s\"" // 2 + "\"handshakeKey\":\"%s\"" // 6 "}"; CHIAKI_EXPORT int chiaki_launchspec_format(char *buf, size_t buf_size, ChiakiLaunchSpec *launch_spec) @@ -85,7 +85,7 @@ CHIAKI_EXPORT int chiaki_launchspec_format(char *buf, size_t buf_size, ChiakiLau int written = snprintf(buf, buf_size, launchspec_fmt, launch_spec->width, launch_spec->height, launch_spec->max_fps, - launch_spec->mtu, launch_spec->rtt, handshake_key_b64); + launch_spec->bw_kbps_sent, launch_spec->mtu, launch_spec->rtt, handshake_key_b64); if(written < 0 || written >= buf_size) return -1; return written; diff --git a/lib/src/session.c b/lib/src/session.c index f7f093d..c423b5d 100644 --- a/lib/src/session.c +++ b/lib/src/session.c @@ -54,22 +54,27 @@ CHIAKI_EXPORT void chiaki_connect_video_profile_preset(ChiakiConnectVideoProfile case CHIAKI_VIDEO_RESOLUTION_PRESET_360p: profile->width = 640; profile->height = 360; + profile->bitrate = 2000; break; case CHIAKI_VIDEO_RESOLUTION_PRESET_540p: profile->width = 960; profile->height = 540; + profile->bitrate = 6000; break; case CHIAKI_VIDEO_RESOLUTION_PRESET_720p: profile->width = 1280; profile->height = 720; + profile->bitrate = 6000; // TODO: 10000 by default break; case CHIAKI_VIDEO_RESOLUTION_PRESET_1080p: profile->width = 1920; profile->height = 1080; + profile->bitrate = 10000; // TODO break; default: profile->width = 0; profile->height = 0; + profile->bitrate = 0; break; } @@ -595,7 +600,7 @@ static bool session_thread_request_session(ChiakiSession *session) ChiakiHttpResponse http_response; CHIAKI_LOGV(session->log, "Session Response Header:"); - chiaki_log_hexdump(session->log, CHIAKI_LOG_VERBOSE, buf, header_size); + chiaki_log_hexdump(session->log, CHIAKI_LOG_VERBOSE, (const uint8_t *)buf, header_size); err = chiaki_http_response_parse(&http_response, buf, header_size); if(err != CHIAKI_ERR_SUCCESS) { diff --git a/lib/src/streamconnection.c b/lib/src/streamconnection.c index 2bde304..58ada6e 100644 --- a/lib/src/streamconnection.c +++ b/lib/src/streamconnection.c @@ -659,6 +659,7 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream launch_spec.width = session->connect_info.video_profile.width; launch_spec.height = session->connect_info.video_profile.height; launch_spec.max_fps = session->connect_info.video_profile.max_fps; + launch_spec.bw_kbps_sent = session->connect_info.video_profile.bitrate; union {