From 389676899c6d1b066e7321e4a649d19d67221804 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Sat, 3 Aug 2019 19:29:51 +0200 Subject: [PATCH] Specify Video Profile --- gui/include/streamsession.h | 1 + gui/src/main.cpp | 7 +++++- gui/src/streamsession.cpp | 1 + lib/include/chiaki/launchspec.h | 3 +++ lib/include/chiaki/session.h | 23 +++++++++++++++++ lib/src/launchspec.c | 10 +++++--- lib/src/log.c | 9 +++++++ lib/src/session.c | 44 +++++++++++++++++++++++++++++++++ lib/src/streamconnection.c | 5 ++++ 9 files changed, 98 insertions(+), 5 deletions(-) diff --git a/gui/include/streamsession.h b/gui/include/streamsession.h index 3f0c238..79afb13 100644 --- a/gui/include/streamsession.h +++ b/gui/include/streamsession.h @@ -51,6 +51,7 @@ struct StreamSessionConnectInfo QString auth; QString morning; QString did; + ChiakiConnectVideoProfile video_profile; }; class StreamSession : public QObject diff --git a/gui/src/main.cpp b/gui/src/main.cpp index f539dca..d1074cc 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -69,6 +69,11 @@ int main(int argc, char *argv[]) connect_info.auth = parser.value(auth_option); connect_info.morning = parser.value(morning_option); connect_info.did = parser.value(did_option); + + chiaki_connect_video_profile_preset(&connect_info.video_profile, + CHIAKI_VIDEO_RESOLUTION_PRESET_540p, + CHIAKI_VIDEO_FPS_PRESET_30); + if(connect_info.registkey.isEmpty() || connect_info.ostype.isEmpty() || connect_info.auth.isEmpty() || connect_info.morning.isEmpty() || connect_info.did.isEmpty()) parser.showHelp(1); return RunStream(app, connect_info); @@ -95,7 +100,7 @@ int RunMain(QApplication &app) int RunStream(QApplication &app, const StreamSessionConnectInfo &connect_info) { StreamWindow window(connect_info); - window.resize(640, 360); + window.resize(connect_info.video_profile.width, connect_info.video_profile.height); window.show(); app.setQuitOnLastWindowClosed(true); diff --git a/gui/src/streamsession.cpp b/gui/src/streamsession.cpp index a14b0be..627c12a 100644 --- a/gui/src/streamsession.cpp +++ b/gui/src/streamsession.cpp @@ -48,6 +48,7 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje chiaki_connect_info.host = host_str.constData(); chiaki_connect_info.regist_key = registkey_str.constData(); chiaki_connect_info.ostype = ostype_str.constData(); + chiaki_connect_info.video_profile = connect_info.video_profile; QByteArray auth_str = connect_info.auth.toUtf8(); size_t auth_len = auth_str.length(); diff --git a/lib/include/chiaki/launchspec.h b/lib/include/chiaki/launchspec.h index 518e6ff..ce52527 100644 --- a/lib/include/chiaki/launchspec.h +++ b/lib/include/chiaki/launchspec.h @@ -32,6 +32,9 @@ typedef struct chiaki_launch_spec_t unsigned int mtu; unsigned int rtt; uint8_t *handshake_key; + unsigned int width; + unsigned int height; + unsigned int max_fps; } 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 dae1df9..c3766f4 100644 --- a/lib/include/chiaki/session.h +++ b/lib/include/chiaki/session.h @@ -44,6 +44,27 @@ extern "C" { #define CHIAKI_SESSION_ID_SIZE_MAX 80 #define CHIAKI_HANDSHAKE_KEY_SIZE 0x10 +typedef struct chiaki_connect_video_profile_t +{ + unsigned int width; + unsigned int height; + unsigned int max_fps; +} ChiakiConnectVideoProfile; + +typedef enum { + CHIAKI_VIDEO_RESOLUTION_PRESET_360p, + CHIAKI_VIDEO_RESOLUTION_PRESET_540p, + CHIAKI_VIDEO_RESOLUTION_PRESET_720p, + CHIAKI_VIDEO_RESOLUTION_PRESET_1080p +} ChiakiVideoResolutionPreset; + +typedef enum { + CHIAKI_VIDEO_FPS_PRESET_30, + CHIAKI_VIDEO_FPS_PRESET_60 +} ChiakiVideoFPSPreset; + +CHIAKI_EXPORT void chiaki_connect_video_profile_preset(ChiakiConnectVideoProfile *profile, ChiakiVideoResolutionPreset resolution, ChiakiVideoFPSPreset fps); + typedef struct chiaki_connect_info_t { const char *host; // null terminated @@ -52,6 +73,7 @@ typedef struct chiaki_connect_info_t char auth[0x10]; // must be completely filled (pad with \0) uint8_t morning[0x10]; uint8_t did[CHIAKI_RP_DID_SIZE]; + ChiakiConnectVideoProfile video_profile; } ChiakiConnectInfo; @@ -111,6 +133,7 @@ typedef struct chiaki_session_t char auth[CHIAKI_KEY_BYTES]; uint8_t morning[CHIAKI_KEY_BYTES]; uint8_t did[CHIAKI_RP_DID_SIZE]; + ChiakiConnectVideoProfile video_profile; } connect_info; uint8_t nonce[CHIAKI_KEY_BYTES]; diff --git a/lib/src/launchspec.c b/lib/src/launchspec.c index 5de623f..76bfdb1 100644 --- a/lib/src/launchspec.c +++ b/lib/src/launchspec.c @@ -28,10 +28,10 @@ static const char launchspec_fmt[] = "{" "\"resolution\":" "{" - "\"width\":640," - "\"height\":360" + "\"width\":%u," + "\"height\":%u" "}," - "\"maxFps\":30," + "\"maxFps\":%u," "\"score\":10" "}" "]," @@ -83,7 +83,9 @@ CHIAKI_EXPORT int chiaki_launchspec_format(char *buf, size_t buf_size, ChiakiLau if(err != CHIAKI_ERR_SUCCESS) return -1; - int written = snprintf(buf, buf_size, launchspec_fmt, launch_spec->mtu, launch_spec->rtt, handshake_key_b64); + 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); if(written < 0 || written >= buf_size) return -1; return written; diff --git a/lib/src/log.c b/lib/src/log.c index 2eeb98a..4752ce2 100644 --- a/lib/src/log.c +++ b/lib/src/log.c @@ -35,6 +35,9 @@ CHIAKI_EXPORT void chiaki_log_cb_print(ChiakiLogLevel level, const char *msg, vo const char *color = NULL; switch(level) { + case CHIAKI_LOG_VERBOSE: + c = 'V'; + break; case CHIAKI_LOG_DEBUG: c = 'D'; color = "34"; @@ -110,6 +113,9 @@ static const char hex_char[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9 CHIAKI_EXPORT void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size) { + if(log && !(log->level_mask & level)) + return; + chiaki_log(log, level, "offset 0 1 2 3 4 5 6 7 8 9 a b c d e f 0123456789abcdef"); size_t offset = 0; @@ -161,6 +167,9 @@ CHIAKI_EXPORT void chiaki_log_hexdump(ChiakiLog *log, ChiakiLogLevel level, cons CHIAKI_EXPORT void chiaki_log_hexdump_raw(ChiakiLog *log, ChiakiLogLevel level, const uint8_t *buf, size_t buf_size) { + if(log && !(log->level_mask & level)) + return; + char *str = malloc(buf_size * 2 + 1); if(!str) return; diff --git a/lib/src/session.c b/lib/src/session.c index 42329ad..008f67b 100644 --- a/lib/src/session.c +++ b/lib/src/session.c @@ -43,6 +43,46 @@ #define SESSION_EXPECT_TIMEOUT_MS 5000 +CHIAKI_EXPORT void chiaki_connect_video_profile_preset(ChiakiConnectVideoProfile *profile, ChiakiVideoResolutionPreset resolution, ChiakiVideoFPSPreset fps) +{ + switch(resolution) + { + case CHIAKI_VIDEO_RESOLUTION_PRESET_360p: + profile->width = 640; + profile->height = 360; + break; + case CHIAKI_VIDEO_RESOLUTION_PRESET_540p: + profile->width = 960; + profile->height = 540; + break; + case CHIAKI_VIDEO_RESOLUTION_PRESET_720p: + profile->width = 1280; + profile->height = 720; + break; + case CHIAKI_VIDEO_RESOLUTION_PRESET_1080p: + profile->width = 1920; + profile->height = 1080; + break; + default: + profile->width = 0; + profile->height = 0; + break; + } + + switch(fps) + { + case CHIAKI_VIDEO_FPS_PRESET_30: + profile->max_fps = 30; + break; + case CHIAKI_VIDEO_FPS_PRESET_60: + profile->max_fps = 60; + break; + default: + profile->max_fps = 0; + break; + } +} + CHIAKI_EXPORT const char *chiaki_quit_reason_string(ChiakiQuitReason reason) { switch(reason) @@ -129,6 +169,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki memcpy(session->connect_info.morning, connect_info->morning, sizeof(session->connect_info.morning)); memcpy(session->connect_info.did, connect_info->did, sizeof(session->connect_info.did)); + session->connect_info.video_profile = connect_info->video_profile; + return CHIAKI_ERR_SUCCESS; error_stop_pipe: chiaki_stop_pipe_fini(&session->stop_pipe); @@ -329,6 +371,8 @@ static void *session_thread_func(void *arg) chiaki_video_receiver_free(session->video_receiver); session->video_receiver = NULL; + chiaki_mutex_unlock(&session->state_mutex); + quit_audio_receiver: chiaki_audio_receiver_free(session->audio_receiver); session->audio_receiver = NULL; diff --git a/lib/src/streamconnection.c b/lib/src/streamconnection.c index 4ab99dc..45a427e 100644 --- a/lib/src/streamconnection.c +++ b/lib/src/streamconnection.c @@ -532,6 +532,7 @@ static void stream_connection_takion_data_expect_streaminfo(ChiakiStreamConnecti if(msg.type != tkproto_TakionMessage_PayloadType_STREAMINFO || !msg.has_stream_info_payload) { CHIAKI_LOGE(stream_connection->log, "StreamConnection expected streaminfo payload but received something else"); + chiaki_log_hexdump(stream_connection->log, CHIAKI_LOG_VERBOSE, buf, buf_size); return; } @@ -583,6 +584,10 @@ static ChiakiErrorCode stream_connection_send_big(ChiakiStreamConnection *stream launch_spec.rtt = session->rtt; launch_spec.handshake_key = session->handshake_key; + 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; + union { char json[LAUNCH_SPEC_JSON_BUF_SIZE];