mirror of
https://git.sr.ht/~thestr4ng3r/chiaki
synced 2025-08-14 02:36:51 -07:00
Add SessionLog
This commit is contained in:
parent
da719d8b8a
commit
c4921ad682
16 changed files with 187 additions and 87 deletions
|
@ -31,6 +31,8 @@ add_executable(chiaki
|
|||
src/discoverymanager.cpp
|
||||
include/streamsession.h
|
||||
src/streamsession.cpp
|
||||
include/sessionlog.h
|
||||
src/sessionlog.cpp
|
||||
include/avopenglwidget.h
|
||||
src/avopenglwidget.cpp
|
||||
include/avopenglframeuploader.h
|
||||
|
|
44
gui/include/sessionlog.h
Normal file
44
gui/include/sessionlog.h
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef CHIAKI_SESSIONLOG_H
|
||||
#define CHIAKI_SESSIONLOG_H
|
||||
|
||||
#include <chiaki/log.h>
|
||||
|
||||
#include <QString>
|
||||
|
||||
class StreamSession;
|
||||
|
||||
class SessionLog
|
||||
{
|
||||
friend class SessionLogPrivate;
|
||||
|
||||
private:
|
||||
StreamSession *session;
|
||||
ChiakiLog chiaki_log;
|
||||
|
||||
void Log(ChiakiLogLevel level, const char *msg);
|
||||
|
||||
public:
|
||||
SessionLog(StreamSession *session, uint32_t level_mask, const QString &filename);
|
||||
|
||||
ChiakiLog *GetChiakiLog() { return &chiaki_log; }
|
||||
|
||||
};
|
||||
|
||||
#endif //CHIAKI_SESSIONLOG_H
|
|
@ -20,6 +20,7 @@
|
|||
|
||||
#include "videodecoder.h"
|
||||
#include "exception.h"
|
||||
#include "sessionlog.h"
|
||||
|
||||
#include <QObject>
|
||||
#include <QImage>
|
||||
|
@ -42,6 +43,8 @@ class ChiakiException: public Exception
|
|||
|
||||
struct StreamSessionConnectInfo
|
||||
{
|
||||
uint32_t log_level_mask;
|
||||
QString log_file;
|
||||
QString host;
|
||||
QString registkey;
|
||||
QString ostype;
|
||||
|
@ -58,6 +61,7 @@ class StreamSession : public QObject
|
|||
Q_OBJECT
|
||||
|
||||
private:
|
||||
SessionLog log;
|
||||
ChiakiSession session;
|
||||
|
||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||
|
|
|
@ -63,6 +63,9 @@ int main(int argc, char *argv[])
|
|||
if(args[0] == "stream")
|
||||
{
|
||||
StreamSessionConnectInfo connect_info;
|
||||
|
||||
connect_info.log_level_mask = CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE;
|
||||
|
||||
connect_info.host = host;
|
||||
connect_info.registkey = parser.value(regist_key_option);
|
||||
connect_info.ostype = parser.value(ostype_option);
|
||||
|
|
46
gui/src/sessionlog.cpp
Normal file
46
gui/src/sessionlog.cpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* This file is part of Chiaki.
|
||||
*
|
||||
* Chiaki is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* Chiaki is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with Chiaki. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <sessionlog.h>
|
||||
#include <chiaki/log.h>
|
||||
|
||||
static void LogCb(ChiakiLogLevel level, const char *msg, void *user);
|
||||
|
||||
SessionLog::SessionLog(StreamSession *session, uint32_t level_mask, const QString &filename)
|
||||
: session(session)
|
||||
{
|
||||
chiaki_log_init(&chiaki_log, level_mask, LogCb, this);
|
||||
|
||||
// TODO: file
|
||||
}
|
||||
|
||||
void SessionLog::Log(ChiakiLogLevel level, const char *msg)
|
||||
{
|
||||
chiaki_log_cb_print(level, msg, nullptr);
|
||||
}
|
||||
|
||||
class SessionLogPrivate
|
||||
{
|
||||
public:
|
||||
static void Log(SessionLog *log, ChiakiLogLevel level, const char *msg) { log->Log(level, msg); }
|
||||
};
|
||||
|
||||
static void LogCb(ChiakiLogLevel level, const char *msg, void *user)
|
||||
{
|
||||
auto log = reinterpret_cast<SessionLog *>(user);
|
||||
SessionLogPrivate::Log(log, level, msg);
|
||||
}
|
|
@ -35,7 +35,8 @@ static void VideoSampleCb(uint8_t *buf, size_t buf_size, void *user);
|
|||
static void EventCb(ChiakiEvent *event, void *user);
|
||||
|
||||
StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObject *parent)
|
||||
: QObject(parent)
|
||||
: QObject(parent),
|
||||
log(this, connect_info.log_level_mask, connect_info.log_file)
|
||||
#if CHIAKI_GUI_ENABLE_QT_GAMEPAD
|
||||
,gamepad(nullptr)
|
||||
#endif
|
||||
|
@ -89,7 +90,7 @@ StreamSession::StreamSession(const StreamSessionConnectInfo &connect_info, QObje
|
|||
|
||||
memset(&keyboard_state, 0, sizeof(keyboard_state));
|
||||
|
||||
err = chiaki_session_init(&session, &chiaki_connect_info);
|
||||
err = chiaki_session_init(&session, &chiaki_connect_info, log.GetChiakiLog());
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
throw ChiakiException("Chiaki Session Init failed: " + QString::fromLocal8Bit(chiaki_error_string(err)));
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ set(SOURCE_FILES
|
|||
src/thread.c
|
||||
src/base64.c
|
||||
src/http.c
|
||||
src/log.c
|
||||
src/sessionlog.c
|
||||
src/ctrl.c
|
||||
src/rpcrypt.c
|
||||
src/takion.c
|
||||
|
|
|
@ -67,4 +67,4 @@ CHIAKI_EXPORT void chiaki_log_hexdump_raw(ChiakiLog *log, ChiakiLogLevel level,
|
|||
}
|
||||
#endif
|
||||
|
||||
#endif // CHIAKI_LOG_H
|
||||
#endif //CHIAKI_LOG_H
|
||||
|
|
|
@ -171,7 +171,7 @@ typedef struct chiaki_session_t
|
|||
|
||||
ChiakiCtrl ctrl;
|
||||
|
||||
ChiakiLog log;
|
||||
ChiakiLog *log;
|
||||
|
||||
ChiakiStreamConnection stream_connection;
|
||||
ChiakiAudioReceiver *audio_receiver;
|
||||
|
@ -180,7 +180,7 @@ typedef struct chiaki_session_t
|
|||
ChiakiControllerState controller_state;
|
||||
} ChiakiSession;
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, ChiakiConnectInfo *connect_info);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, ChiakiConnectInfo *connect_info, ChiakiLog *log);
|
||||
CHIAKI_EXPORT void chiaki_session_fini(ChiakiSession *session);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_start(ChiakiSession *session);
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_stop(ChiakiSession *session);
|
||||
|
|
|
@ -27,7 +27,7 @@ static void chiaki_audio_receiver_frame(ChiakiAudioReceiver *audio_receiver, Chi
|
|||
CHIAKI_EXPORT ChiakiErrorCode chiaki_audio_receiver_init(ChiakiAudioReceiver *audio_receiver, ChiakiSession *session)
|
||||
{
|
||||
audio_receiver->session = session;
|
||||
audio_receiver->log = &session->log;
|
||||
audio_receiver->log = session->log;
|
||||
audio_receiver->opus_decoder = NULL;
|
||||
memset(&audio_receiver->audio_header, 0, sizeof(audio_receiver->audio_header));
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ static void *ctrl_thread_func(void *user)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&ctrl->session->log, "Ctrl connected");
|
||||
CHIAKI_LOGI(ctrl->session->log, "Ctrl connected");
|
||||
|
||||
while(true)
|
||||
{
|
||||
|
@ -108,7 +108,7 @@ static void *ctrl_thread_func(void *user)
|
|||
{
|
||||
if(8 + payload_size > sizeof(ctrl->recv_buf))
|
||||
{
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Ctrl buffer overflow!");
|
||||
CHIAKI_LOGE(ctrl->session->log, "Ctrl buffer overflow!");
|
||||
overflow = true;
|
||||
}
|
||||
break;
|
||||
|
@ -133,7 +133,7 @@ static void *ctrl_thread_func(void *user)
|
|||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
if(err == CHIAKI_ERR_CANCELED)
|
||||
CHIAKI_LOGI(&ctrl->session->log, "Ctrl requested to stop");
|
||||
CHIAKI_LOGI(ctrl->session->log, "Ctrl requested to stop");
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, CtrlMessageType type,
|
|||
ssize_t sent = send(ctrl->sock, header, sizeof(header), 0);
|
||||
if(sent < 0)
|
||||
{
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Failed to send Ctrl Message Header");
|
||||
CHIAKI_LOGE(ctrl->session->log, "Failed to send Ctrl Message Header");
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
|
||||
|
@ -174,7 +174,7 @@ static ChiakiErrorCode ctrl_message_send(ChiakiCtrl *ctrl, CtrlMessageType type,
|
|||
sent = send(ctrl->sock, payload, payload_size, 0);
|
||||
if(sent < 0)
|
||||
{
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Failed to send Ctrl Message Payload");
|
||||
CHIAKI_LOGE(ctrl->session->log, "Failed to send Ctrl Message Payload");
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ static void ctrl_message_received(ChiakiCtrl *ctrl, uint16_t msg_type, uint8_t *
|
|||
ChiakiErrorCode err = chiaki_rpcrypt_decrypt(&ctrl->session->rpcrypt, ctrl->crypt_counter_remote++, payload, payload, payload_size);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Failed to decrypt payload for Ctrl Message type %#x", msg_type);
|
||||
CHIAKI_LOGE(ctrl->session->log, "Failed to decrypt payload for Ctrl Message type %#x", msg_type);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -207,7 +207,7 @@ static void ctrl_message_received(ChiakiCtrl *ctrl, uint16_t msg_type, uint8_t *
|
|||
ctrl_message_received_heartbeat_req(ctrl, payload, payload_size);
|
||||
break;
|
||||
default:
|
||||
CHIAKI_LOGW(&ctrl->session->log, "Received Ctrl Message with unknown type %#x", msg_type);
|
||||
CHIAKI_LOGW(ctrl->session->log, "Received Ctrl Message with unknown type %#x", msg_type);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -217,13 +217,13 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
|
|||
{
|
||||
if(ctrl->session->ctrl_session_id_received)
|
||||
{
|
||||
CHIAKI_LOGW(&ctrl->session->log, "Received another Session Id Message");
|
||||
CHIAKI_LOGW(ctrl->session->log, "Received another Session Id Message");
|
||||
return;
|
||||
}
|
||||
|
||||
if(payload_size < 2 || (char)payload[0] != 'J')
|
||||
{
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Invalid Session Id received");
|
||||
CHIAKI_LOGE(ctrl->session->log, "Invalid Session Id received");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -233,7 +233,7 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
|
|||
|
||||
if(payload_size >= CHIAKI_SESSION_ID_SIZE_MAX - 1)
|
||||
{
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Received Session Id is too long");
|
||||
CHIAKI_LOGE(ctrl->session->log, "Received Session Id is too long");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -246,7 +246,7 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
|
|||
continue;
|
||||
if(c >= '0' && c <= '9')
|
||||
continue;
|
||||
CHIAKI_LOGE(&ctrl->session->log, "Received Session Id contains invalid characters");
|
||||
CHIAKI_LOGE(ctrl->session->log, "Received Session Id contains invalid characters");
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -257,15 +257,15 @@ static void ctrl_message_received_session_id(ChiakiCtrl *ctrl, uint8_t *payload,
|
|||
chiaki_mutex_unlock(&ctrl->session->state_mutex);
|
||||
chiaki_cond_signal(&ctrl->session->state_cond);
|
||||
|
||||
CHIAKI_LOGI(&ctrl->session->log, "Received valid Session Id: %s", ctrl->session->session_id);
|
||||
CHIAKI_LOGI(ctrl->session->log, "Received valid Session Id: %s", ctrl->session->session_id);
|
||||
}
|
||||
|
||||
static void ctrl_message_received_heartbeat_req(ChiakiCtrl *ctrl, uint8_t *payload, size_t payload_size)
|
||||
{
|
||||
if(payload_size != 0)
|
||||
CHIAKI_LOGW(&ctrl->session->log, "Received Heartbeat request with non-empty payload");
|
||||
CHIAKI_LOGW(ctrl->session->log, "Received Heartbeat request with non-empty payload");
|
||||
|
||||
CHIAKI_LOGI(&ctrl->session->log, "Received Ctrl Heartbeat, sending reply");
|
||||
CHIAKI_LOGI(ctrl->session->log, "Received Ctrl Heartbeat, sending reply");
|
||||
|
||||
ctrl_message_send(ctrl, CTRL_MESSAGE_TYPE_HEARTBEAT_REP, NULL, 0);
|
||||
}
|
||||
|
@ -322,7 +322,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
int sock = socket(sa->sa_family, SOCK_STREAM, IPPROTO_TCP);
|
||||
if(sock < 0)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Session ctrl socket creation failed.");
|
||||
CHIAKI_LOGE(session->log, "Session ctrl socket creation failed.");
|
||||
ctrl_failed(ctrl, CHIAKI_QUIT_REASON_CTRL_UNKNOWN);
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
|
@ -332,13 +332,13 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
if(r < 0)
|
||||
{
|
||||
int errsv = errno;
|
||||
CHIAKI_LOGE(&session->log, "Ctrl connect failed: %s", strerror(errsv));
|
||||
CHIAKI_LOGE(session->log, "Ctrl connect failed: %s", strerror(errsv));
|
||||
ctrl_failed(ctrl, errsv == ECONNREFUSED ? CHIAKI_QUIT_REASON_CTRL_CONNECTION_REFUSED : CHIAKI_QUIT_REASON_CTRL_UNKNOWN);
|
||||
close(sock);
|
||||
return CHIAKI_ERR_NETWORK;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_CTRL_PORT);
|
||||
CHIAKI_LOGI(session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_CTRL_PORT);
|
||||
|
||||
|
||||
uint8_t auth_enc[CHIAKI_KEY_BYTES];
|
||||
|
@ -392,12 +392,12 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
if(request_len < 0 || request_len >= sizeof(buf))
|
||||
goto error;
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Sending ctrl request");
|
||||
CHIAKI_LOGI(session->log, "Sending ctrl request");
|
||||
|
||||
ssize_t sent = send(sock, buf, (size_t)request_len, 0);
|
||||
if(sent < 0)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Failed to send ctrl request");
|
||||
CHIAKI_LOGE(session->log, "Failed to send ctrl request");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -407,7 +407,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
if(err != CHIAKI_ERR_CANCELED)
|
||||
CHIAKI_LOGE(&session->log, "Failed to receive ctrl request response");
|
||||
CHIAKI_LOGE(session->log, "Failed to receive ctrl request response");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -415,7 +415,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
err = chiaki_http_response_parse(&http_response, buf, header_size);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Failed to parse ctrl request response");
|
||||
CHIAKI_LOGE(session->log, "Failed to parse ctrl request response");
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
@ -440,7 +440,7 @@ static ChiakiErrorCode ctrl_connect(ChiakiCtrl *ctrl)
|
|||
}
|
||||
|
||||
if(!response.server_type_valid)
|
||||
CHIAKI_LOGE(&session->log, "No valid Server Type in ctrl response");
|
||||
CHIAKI_LOGE(session->log, "No valid Server Type in ctrl response");
|
||||
|
||||
ctrl->sock = sock;
|
||||
|
||||
|
|
|
@ -48,7 +48,7 @@ static ChiakiErrorCode senkusha_send_disconnect(ChiakiSenkusha *senkusha);
|
|||
CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_init(ChiakiSenkusha *senkusha, ChiakiSession *session)
|
||||
{
|
||||
senkusha->session = session;
|
||||
senkusha->log = &session->log;
|
||||
senkusha->log = session->log;
|
||||
|
||||
ChiakiErrorCode err = chiaki_mutex_init(&senkusha->state_mutex, false);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
|
@ -129,7 +129,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha)
|
|||
free(takion_info.sa);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Senkusha connect failed");
|
||||
CHIAKI_LOGE(session->log, "Senkusha connect failed");
|
||||
QUIT(quit);
|
||||
}
|
||||
|
||||
|
@ -138,17 +138,17 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha)
|
|||
if(!senkusha->state_finished)
|
||||
{
|
||||
if(err == CHIAKI_ERR_TIMEOUT)
|
||||
CHIAKI_LOGE(&session->log, "Senkusha connect timeout");
|
||||
CHIAKI_LOGE(session->log, "Senkusha connect timeout");
|
||||
|
||||
if(senkusha->should_stop)
|
||||
err = CHIAKI_ERR_CANCELED;
|
||||
else
|
||||
CHIAKI_LOGE(&session->log, "Senkusha Takion connect failed");
|
||||
CHIAKI_LOGE(session->log, "Senkusha Takion connect failed");
|
||||
|
||||
QUIT(quit_takion);
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Senkusha sending big");
|
||||
CHIAKI_LOGI(session->log, "Senkusha sending big");
|
||||
|
||||
senkusha->state = STATE_EXPECT_BANG;
|
||||
senkusha->state_finished = false;
|
||||
|
@ -156,7 +156,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha)
|
|||
err = senkusha_send_big(senkusha);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Senkusha failed to send big");
|
||||
CHIAKI_LOGE(session->log, "Senkusha failed to send big");
|
||||
QUIT(quit_takion);
|
||||
}
|
||||
|
||||
|
@ -166,21 +166,21 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha)
|
|||
if(!senkusha->state_finished)
|
||||
{
|
||||
if(err == CHIAKI_ERR_TIMEOUT)
|
||||
CHIAKI_LOGE(&session->log, "Senkusha bang receive timeout");
|
||||
CHIAKI_LOGE(session->log, "Senkusha bang receive timeout");
|
||||
|
||||
if(senkusha->should_stop)
|
||||
err = CHIAKI_ERR_CANCELED;
|
||||
else
|
||||
CHIAKI_LOGE(&session->log, "Senkusha didn't receive bang");
|
||||
CHIAKI_LOGE(session->log, "Senkusha didn't receive bang");
|
||||
|
||||
QUIT(quit_takion);
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Senkusha successfully received bang");
|
||||
CHIAKI_LOGI(session->log, "Senkusha successfully received bang");
|
||||
|
||||
// TODO: Do the actual tests
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Senkusha is disconnecting");
|
||||
CHIAKI_LOGI(session->log, "Senkusha is disconnecting");
|
||||
|
||||
senkusha_send_disconnect(senkusha);
|
||||
chiaki_mutex_unlock(&senkusha->state_mutex);
|
||||
|
@ -188,7 +188,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_senkusha_run(ChiakiSenkusha *senkusha)
|
|||
err = CHIAKI_ERR_SUCCESS;
|
||||
quit_takion:
|
||||
chiaki_takion_close(&senkusha->takion);
|
||||
CHIAKI_LOGI(&session->log, "Senkusha closed takion");
|
||||
CHIAKI_LOGI(session->log, "Senkusha closed takion");
|
||||
quit:
|
||||
return err;
|
||||
}
|
||||
|
|
|
@ -114,11 +114,11 @@ CHIAKI_EXPORT const char *chiaki_quit_reason_string(ChiakiQuitReason reason)
|
|||
static void *session_thread_func(void *arg);
|
||||
|
||||
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, ChiakiConnectInfo *connect_info)
|
||||
CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, ChiakiConnectInfo *connect_info, ChiakiLog *log)
|
||||
{
|
||||
memset(session, 0, sizeof(ChiakiSession));
|
||||
|
||||
chiaki_log_init(&session->log, CHIAKI_LOG_ALL & ~CHIAKI_LOG_VERBOSE, NULL, NULL);
|
||||
session->log = log;
|
||||
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_NONE;
|
||||
|
||||
|
@ -140,7 +140,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki
|
|||
err = chiaki_stream_connection_init(&session->stream_connection, session);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection init failed");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection init failed");
|
||||
goto error_stop_pipe;
|
||||
}
|
||||
|
||||
|
@ -279,20 +279,20 @@ static void *session_thread_func(void *arg)
|
|||
|
||||
CHECK_STOP(quit);
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Starting session request");
|
||||
CHIAKI_LOGI(session->log, "Starting session request");
|
||||
|
||||
success = session_thread_request_session(session);
|
||||
if(!success)
|
||||
QUIT(quit);
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Session request successful");
|
||||
CHIAKI_LOGI(session->log, "Session request successful");
|
||||
|
||||
chiaki_rpcrypt_init(&session->rpcrypt, session->nonce, session->connect_info.morning);
|
||||
|
||||
// PS4 doesn't always react right away, sleep a bit
|
||||
chiaki_cond_timedwait_pred(&session->state_cond, &session->state_mutex, 10, session_check_state_pred, session);
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Starting ctrl");
|
||||
CHIAKI_LOGI(session->log, "Starting ctrl");
|
||||
|
||||
ChiakiErrorCode err = chiaki_ctrl_start(&session->ctrl, session);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
|
@ -303,14 +303,14 @@ static void *session_thread_func(void *arg)
|
|||
|
||||
if(!session->ctrl_session_id_received)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Ctrl has failed, shutting down");
|
||||
CHIAKI_LOGE(session->log, "Ctrl has failed, shutting down");
|
||||
if(session->quit_reason == CHIAKI_QUIT_REASON_NONE)
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_CTRL_UNKNOWN;
|
||||
QUIT(quit_ctrl);
|
||||
}
|
||||
|
||||
#ifdef ENABLE_SENKUSHA
|
||||
CHIAKI_LOGI(&session->log, "Starting Senkusha");
|
||||
CHIAKI_LOGI(session->log, "Starting Senkusha");
|
||||
|
||||
ChiakiSenkusha senkusha;
|
||||
err = chiaki_senkusha_init(&senkusha, session);
|
||||
|
@ -322,11 +322,11 @@ static void *session_thread_func(void *arg)
|
|||
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Senkusha failed");
|
||||
CHIAKI_LOGE(session->log, "Senkusha failed");
|
||||
QUIT(quit_ctrl);
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Senkusha completed successfully");
|
||||
CHIAKI_LOGI(session->log, "Senkusha completed successfully");
|
||||
#endif
|
||||
|
||||
// TODO: Senkusha should set that
|
||||
|
@ -336,28 +336,28 @@ static void *session_thread_func(void *arg)
|
|||
err = chiaki_random_bytes(session->handshake_key, sizeof(session->handshake_key));
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Session failed to generate handshake key");
|
||||
CHIAKI_LOGE(session->log, "Session failed to generate handshake key");
|
||||
QUIT(quit_ctrl);
|
||||
}
|
||||
|
||||
err = chiaki_ecdh_init(&session->ecdh);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Session failed to initialize ECDH");
|
||||
CHIAKI_LOGE(session->log, "Session failed to initialize ECDH");
|
||||
QUIT(quit_ctrl);
|
||||
}
|
||||
|
||||
session->audio_receiver = chiaki_audio_receiver_new(session);
|
||||
if(!session->audio_receiver)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Session failed to initialize Audio Receiver");
|
||||
CHIAKI_LOGE(session->log, "Session failed to initialize Audio Receiver");
|
||||
QUIT(quit_ecdh);
|
||||
}
|
||||
|
||||
session->video_receiver = chiaki_video_receiver_new(session);
|
||||
if(!session->video_receiver)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Session failed to initialize Video Receiver");
|
||||
CHIAKI_LOGE(session->log, "Session failed to initialize Video Receiver");
|
||||
QUIT(quit_audio_receiver);
|
||||
}
|
||||
|
||||
|
@ -366,18 +366,18 @@ static void *session_thread_func(void *arg)
|
|||
chiaki_mutex_lock(&session->state_mutex);
|
||||
if(err == CHIAKI_ERR_DISCONNECTED)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Remote disconnected from StreamConnection");
|
||||
CHIAKI_LOGE(session->log, "Remote disconnected from StreamConnection");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_STREAM_CONNECTION_REMOTE_DISCONNECTED;
|
||||
session->quit_reason_str = strdup(session->stream_connection.remote_disconnect_reason);
|
||||
}
|
||||
else if(err != CHIAKI_ERR_SUCCESS && err != CHIAKI_ERR_CANCELED)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection run failed");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection run failed");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_STREAM_CONNECTION_UNKNOWN;
|
||||
}
|
||||
else
|
||||
{
|
||||
CHIAKI_LOGI(&session->log, "StreamConnection completed successfully");
|
||||
CHIAKI_LOGI(session->log, "StreamConnection completed successfully");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_STOPPED;
|
||||
}
|
||||
|
||||
|
@ -396,12 +396,12 @@ quit_ecdh:
|
|||
quit_ctrl:
|
||||
chiaki_ctrl_stop(&session->ctrl);
|
||||
chiaki_ctrl_join(&session->ctrl);
|
||||
CHIAKI_LOGI(&session->log, "Ctrl stopped");
|
||||
CHIAKI_LOGI(session->log, "Ctrl stopped");
|
||||
|
||||
ChiakiEvent quit_event;
|
||||
quit:
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Session has quit");
|
||||
CHIAKI_LOGI(session->log, "Session has quit");
|
||||
quit_event.type = CHIAKI_EVENT_QUIT;
|
||||
quit_event.quit.reason = session->quit_reason;
|
||||
quit_event.quit.reason_str = session->quit_reason_str;
|
||||
|
@ -477,7 +477,7 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
continue;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Trying to request session from %s:%d", session->connect_info.hostname, SESSION_PORT);
|
||||
CHIAKI_LOGI(session->log, "Trying to request session from %s:%d", session->connect_info.hostname, SESSION_PORT);
|
||||
|
||||
session_sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
|
||||
if(session_sock < 0)
|
||||
|
@ -486,7 +486,7 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
if(r < 0)
|
||||
{
|
||||
int errsv = errno;
|
||||
CHIAKI_LOGE(&session->log, "Session request connect failed: %s", strerror(errsv));
|
||||
CHIAKI_LOGE(session->log, "Session request connect failed: %s", strerror(errsv));
|
||||
if(errsv == ECONNREFUSED)
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_CONNECTION_REFUSED;
|
||||
else
|
||||
|
@ -505,13 +505,13 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
|
||||
if(session_sock < 0)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Session request connect failed eventually.");
|
||||
CHIAKI_LOGE(session->log, "Session request connect failed eventually.");
|
||||
if(session->quit_reason == CHIAKI_QUIT_REASON_NONE)
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_PORT);
|
||||
CHIAKI_LOGI(session->log, "Connected to %s:%d", session->connect_info.hostname, SESSION_PORT);
|
||||
|
||||
static const char session_request_fmt[] =
|
||||
"GET /sce/rp/session HTTP/1.1\r\n"
|
||||
|
@ -533,12 +533,12 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
return false;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "Sending session request");
|
||||
CHIAKI_LOGI(session->log, "Sending session request");
|
||||
|
||||
ssize_t sent = send(session_sock, buf, (size_t)request_len, 0);
|
||||
if(sent < 0)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Failed to send session request");
|
||||
CHIAKI_LOGE(session->log, "Failed to send session request");
|
||||
close(session_sock);
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
|
@ -558,7 +558,7 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
}
|
||||
else
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Failed to receive session request response");
|
||||
CHIAKI_LOGE(session->log, "Failed to receive session request response");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
}
|
||||
close(session_sock);
|
||||
|
@ -569,7 +569,7 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
err = chiaki_http_response_parse(&http_response, buf, header_size);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Failed to parse session request response");
|
||||
CHIAKI_LOGE(session->log, "Failed to parse session request response");
|
||||
close(session_sock);
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
return false;
|
||||
|
@ -584,7 +584,7 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
err = chiaki_base64_decode(response.nonce, strlen(response.nonce), session->nonce, &nonce_len);
|
||||
if(err != CHIAKI_ERR_SUCCESS || nonce_len != CHIAKI_KEY_BYTES)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "Nonce invalid");
|
||||
CHIAKI_LOGE(session->log, "Nonce invalid");
|
||||
response.success = false;
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_UNKNOWN;
|
||||
}
|
||||
|
@ -594,11 +594,11 @@ static bool session_thread_request_session(ChiakiSession *session)
|
|||
switch(response.error_code)
|
||||
{
|
||||
case RP_APPLICATION_REASON_IN_USE:
|
||||
CHIAKI_LOGE(&session->log, "Remote is already in use");
|
||||
CHIAKI_LOGE(session->log, "Remote is already in use");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_IN_USE;
|
||||
break;
|
||||
case RP_APPLICATION_REASON_CRASH:
|
||||
CHIAKI_LOGE(&session->log, "Remote seems to have crashed");
|
||||
CHIAKI_LOGE(session->log, "Remote seems to have crashed");
|
||||
session->quit_reason = CHIAKI_QUIT_REASON_SESSION_REQUEST_RP_CRASH;
|
||||
break;
|
||||
default:
|
||||
|
|
|
@ -66,7 +66,7 @@ static ChiakiErrorCode stream_connection_send_heartbeat(ChiakiStreamConnection *
|
|||
CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_init(ChiakiStreamConnection *stream_connection, ChiakiSession *session)
|
||||
{
|
||||
stream_connection->session = session;
|
||||
stream_connection->log = &session->log;
|
||||
stream_connection->log = session->log;
|
||||
|
||||
stream_connection->ecdh_secret = NULL;
|
||||
stream_connection->gkcrypt_remote = NULL;
|
||||
|
@ -159,7 +159,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
|||
free(takion_info.sa);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection connect failed");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection connect failed");
|
||||
chiaki_mutex_unlock(&stream_connection->state_mutex);
|
||||
return err;
|
||||
}
|
||||
|
@ -169,11 +169,11 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
|||
CHECK_STOP(close_takion);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection Takion connect failed");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection Takion connect failed");
|
||||
goto close_takion;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "StreamConnection sending big");
|
||||
CHIAKI_LOGI(session->log, "StreamConnection sending big");
|
||||
|
||||
stream_connection->state = STATE_EXPECT_BANG;
|
||||
stream_connection->state_finished = false;
|
||||
|
@ -181,7 +181,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
|||
err = stream_connection_send_big(stream_connection);
|
||||
if(err != CHIAKI_ERR_SUCCESS)
|
||||
{
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection failed to send big");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection failed to send big");
|
||||
goto disconnect;
|
||||
}
|
||||
|
||||
|
@ -192,14 +192,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
|||
if(!stream_connection->state_finished)
|
||||
{
|
||||
if(err == CHIAKI_ERR_TIMEOUT)
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection bang receive timeout");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection bang receive timeout");
|
||||
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive bang or failed to handle it");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection didn't receive bang or failed to handle it");
|
||||
err = CHIAKI_ERR_UNKNOWN;
|
||||
goto disconnect;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "StreamConnection successfully received bang");
|
||||
CHIAKI_LOGI(session->log, "StreamConnection successfully received bang");
|
||||
|
||||
stream_connection->state = STATE_EXPECT_STREAMINFO;
|
||||
stream_connection->state_finished = false;
|
||||
|
@ -211,14 +211,14 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
|||
if(!stream_connection->state_finished)
|
||||
{
|
||||
if(err == CHIAKI_ERR_TIMEOUT)
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection streaminfo receive timeout");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection streaminfo receive timeout");
|
||||
|
||||
CHIAKI_LOGE(&session->log, "StreamConnection didn't receive streaminfo");
|
||||
CHIAKI_LOGE(session->log, "StreamConnection didn't receive streaminfo");
|
||||
err = CHIAKI_ERR_UNKNOWN;
|
||||
goto disconnect;
|
||||
}
|
||||
|
||||
CHIAKI_LOGI(&session->log, "StreamConnection successfully received streaminfo");
|
||||
CHIAKI_LOGI(session->log, "StreamConnection successfully received streaminfo");
|
||||
|
||||
err = chiaki_mutex_lock(&stream_connection->feedback_sender_mutex);
|
||||
assert(err == CHIAKI_ERR_SUCCESS);
|
||||
|
@ -258,7 +258,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
|
|||
err = CHIAKI_ERR_SUCCESS;
|
||||
|
||||
disconnect:
|
||||
CHIAKI_LOGI(&session->log, "StreamConnection is disconnecting");
|
||||
CHIAKI_LOGI(session->log, "StreamConnection is disconnecting");
|
||||
stream_connection_send_disconnect(stream_connection);
|
||||
|
||||
if(stream_connection->should_stop)
|
||||
|
@ -276,7 +276,7 @@ close_takion:
|
|||
chiaki_mutex_unlock(&stream_connection->state_mutex);
|
||||
|
||||
chiaki_takion_close(&stream_connection->takion);
|
||||
CHIAKI_LOGI(&session->log, "StreamConnection closed takion");
|
||||
CHIAKI_LOGI(session->log, "StreamConnection closed takion");
|
||||
|
||||
return err;
|
||||
}
|
||||
|
@ -535,7 +535,7 @@ static bool pb_decode_resolution(pb_istream_t *stream, const pb_field_t *field,
|
|||
|
||||
if(!header_buf.buf)
|
||||
{
|
||||
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Failed to decode video header");
|
||||
CHIAKI_LOGE(ctx->stream_connection->session->log, "Failed to decode video header");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -543,14 +543,14 @@ static bool pb_decode_resolution(pb_istream_t *stream, const pb_field_t *field,
|
|||
if(!header_buf_padded)
|
||||
{
|
||||
free(header_buf.buf);
|
||||
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Failed to realloc video header with padding");
|
||||
CHIAKI_LOGE(ctx->stream_connection->session->log, "Failed to realloc video header with padding");
|
||||
return true;
|
||||
}
|
||||
memset(header_buf_padded + header_buf.size, 0, CHIAKI_VIDEO_BUFFER_PADDING_SIZE);
|
||||
|
||||
if(ctx->video_profiles_count >= CHIAKI_VIDEO_PROFILES_MAX)
|
||||
{
|
||||
CHIAKI_LOGE(&ctx->stream_connection->session->log, "Received more resolutions than the maximum");
|
||||
CHIAKI_LOGE(ctx->stream_connection->session->log, "Received more resolutions than the maximum");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ static ChiakiErrorCode chiaki_video_receiver_flush_frame(ChiakiVideoReceiver *vi
|
|||
CHIAKI_EXPORT void chiaki_video_receiver_init(ChiakiVideoReceiver *video_receiver, struct chiaki_session_t *session)
|
||||
{
|
||||
video_receiver->session = session;
|
||||
video_receiver->log = &session->log;
|
||||
video_receiver->log = session->log;
|
||||
memset(video_receiver->profiles, 0, sizeof(video_receiver->profiles));
|
||||
video_receiver->profiles_count = 0;
|
||||
video_receiver->profile_cur = -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue