Dirty Feedback State working!

This commit is contained in:
Florian Märkl 2019-06-29 19:06:43 +02:00
commit caa70ab55f
No known key found for this signature in database
GPG key ID: 125BC8A5A6A1E857
11 changed files with 64 additions and 19 deletions

View file

@ -60,6 +60,7 @@ class StreamSession : public QObject
private slots:
void UpdateGamepads();
void SendFeedbackState();
};
#endif // CHIAKI_STREAMSESSION_H

View file

@ -113,8 +113,26 @@ void StreamSession::UpdateGamepads()
{
gamepad = new QGamepad(connected_pads[0], this);
qDebug() << "gamepad" << connected_pads[0] << "connected: " << gamepad->name();
connect(gamepad, &QGamepad::axisLeftXChanged, this, &StreamSession::SendFeedbackState);
connect(gamepad, &QGamepad::axisLeftYChanged, this, &StreamSession::SendFeedbackState);
connect(gamepad, &QGamepad::axisRightXChanged, this, &StreamSession::SendFeedbackState);
connect(gamepad, &QGamepad::axisRightYChanged, this, &StreamSession::SendFeedbackState);
}
}
SendFeedbackState();
}
void StreamSession::SendFeedbackState()
{
if(!gamepad)
return;
ChiakiFeedbackState state;
state.left_x = static_cast<int16_t>(gamepad->axisLeftX() * 0x7fff);
state.left_y = static_cast<int16_t>(gamepad->axisLeftX() * 0x7fff);
state.right_x = static_cast<int16_t>(gamepad->axisLeftX() * 0x7fff);
state.right_y = static_cast<int16_t>(gamepad->axisLeftX() * 0x7fff);
chiaki_stream_connection_send_feedback_state(&session.stream_connection, &state);
}
void StreamSession::PushAudioFrame(int16_t *buf, size_t samples_count)

View file

@ -28,10 +28,10 @@ extern "C" {
typedef struct chiaki_feedback_state_t
{
uint16_t left_x;
uint16_t left_y;
uint16_t right_x;
uint16_t right_y;
int16_t left_x;
int16_t left_y;
int16_t right_x;
int16_t right_y;
} ChiakiFeedbackState;
#define CHIAKI_FEEDBACK_STATE_BUF_SIZE 0x19

View file

@ -41,6 +41,8 @@ typedef struct chiaki_stream_connection_t
ChiakiGKCrypt *gkcrypt_local;
ChiakiGKCrypt *gkcrypt_remote;
ChiakiSeqNum16 feedback_state_seq_num;
/**
* signaled on change of state_finished or should_stop
*/
@ -70,6 +72,8 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_run(ChiakiStreamConnectio
*/
CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_stop(ChiakiStreamConnection *stream_connection);
CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_send_feedback_state(ChiakiStreamConnection *stream_connection, ChiakiFeedbackState *state);
#ifdef __cplusplus
}
#endif

View file

@ -44,7 +44,7 @@ typedef struct chiaki_mutex_t
pthread_mutex_t mutex;
} ChiakiMutex;
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_init(ChiakiMutex *mutex);
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_init(ChiakiMutex *mutex, bool rec);
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_fini(ChiakiMutex *mutex);
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_lock(ChiakiMutex *mutex);
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_trylock(ChiakiMutex *mutex);

View file

@ -30,7 +30,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_audio_receiver_init(ChiakiAudioReceiver *au
audio_receiver->opus_decoder = NULL;
memset(&audio_receiver->audio_header, 0, sizeof(audio_receiver->audio_header));
ChiakiErrorCode err = chiaki_mutex_init(&audio_receiver->mutex);
ChiakiErrorCode err = chiaki_mutex_init(&audio_receiver->mutex, false);
if(err != CHIAKI_ERR_SUCCESS)
return err;

View file

@ -38,8 +38,8 @@ CHIAKI_EXPORT void chiaki_feedback_state_format(uint8_t *buf, ChiakiFeedbackStat
buf[0xe] = 0xf7; // TODO
buf[0xf] = 0xef; // TODO
buf[0x10] = 0x1f; // TODO
*((uint16_t *)(buf + 0x11)) = htons(state->left_x);
*((uint16_t *)(buf + 0x13)) = htons(state->left_y);
*((uint16_t *)(buf + 0x15)) = htons(state->right_x);
*((uint16_t *)(buf + 0x17)) = htons(state->right_y);
}
*((uint16_t *)(buf + 0x11)) = htons((uint16_t)state->left_x);
*((uint16_t *)(buf + 0x13)) = htons((uint16_t)state->left_y);
*((uint16_t *)(buf + 0x15)) = htons((uint16_t)state->right_x);
*((uint16_t *)(buf + 0x17)) = htons((uint16_t)state->right_y);
}

View file

@ -56,7 +56,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_session_init(ChiakiSession *session, Chiaki
return CHIAKI_ERR_UNKNOWN;
}
if(chiaki_mutex_init(&session->ctrl_cond_mutex) != CHIAKI_ERR_SUCCESS)
if(chiaki_mutex_init(&session->ctrl_cond_mutex, false) != CHIAKI_ERR_SUCCESS)
{
chiaki_cond_fini(&session->ctrl_cond);
return CHIAKI_ERR_UNKNOWN;

View file

@ -72,7 +72,9 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_init(ChiakiStreamConnecti
stream_connection->gkcrypt_remote = NULL;
stream_connection->gkcrypt_local = NULL;
ChiakiErrorCode err = chiaki_mutex_init(&stream_connection->state_mutex);
stream_connection->feedback_state_seq_num = 0;
ChiakiErrorCode err = chiaki_mutex_init(&stream_connection->state_mutex, false);
if(err != CHIAKI_ERR_SUCCESS)
goto error;
@ -726,4 +728,12 @@ static ChiakiErrorCode stream_connection_send_heartbeat(ChiakiStreamConnection *
}
return chiaki_takion_send_message_data(&stream_connection->takion, 1, 1, buf, stream.bytes_written);
}
CHIAKI_EXPORT ChiakiErrorCode chiaki_stream_connection_send_feedback_state(ChiakiStreamConnection *stream_connection, ChiakiFeedbackState *state)
{
ChiakiErrorCode err = chiaki_takion_send_feedback_state(&stream_connection->takion, stream_connection->feedback_state_seq_num++, state);
if(err != CHIAKI_ERR_SUCCESS)
CHIAKI_LOGE(stream_connection->log, "StreamConnection failed to send feedback state\n");
return err;
}

View file

@ -175,7 +175,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_connect(ChiakiTakion *takion, Chiaki
takion->log = info->log;
takion->gkcrypt_local = NULL;
ret = chiaki_mutex_init(&takion->gkcrypt_local_mutex);
ret = chiaki_mutex_init(&takion->gkcrypt_local_mutex, true);
if(ret != CHIAKI_ERR_SUCCESS)
return ret;
takion->key_pos_local = 0;
@ -431,11 +431,13 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_takion_send_feedback_state(ChiakiTakion *ta
if(err != CHIAKI_ERR_SUCCESS)
goto beach;
err = chiaki_gkcrypt_gmac(takion->gkcrypt_local, key_pos, buf, sizeof(buf), buf + 4);
*((uint32_t *)(buf + 4)) = htonl((uint32_t)key_pos);
err = chiaki_gkcrypt_gmac(takion->gkcrypt_local, key_pos, buf, sizeof(buf), buf + 8);
if(err != CHIAKI_ERR_SUCCESS)
goto beach;
*((uint32_t *)(buf + 4)) = htonl((uint32_t)key_pos);
chiaki_takion_send_raw(takion, buf, sizeof(buf));
beach:
chiaki_mutex_unlock(&takion->gkcrypt_local_mutex);

View file

@ -39,9 +39,19 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_thread_join(ChiakiThread *thread, void **re
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_init(ChiakiMutex *mutex)
CHIAKI_EXPORT ChiakiErrorCode chiaki_mutex_init(ChiakiMutex *mutex, bool rec)
{
int r = pthread_mutex_init(&mutex->mutex, NULL);
pthread_mutexattr_t attr;
int r = pthread_mutexattr_init(&attr);
if(r != 0)
return CHIAKI_ERR_UNKNOWN;
pthread_mutexattr_settype(&attr, rec ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_DEFAULT);
r = pthread_mutex_init(&mutex->mutex, &attr);
pthread_mutexattr_destroy(&attr);
if(r != 0)
return CHIAKI_ERR_UNKNOWN;
return CHIAKI_ERR_SUCCESS;
@ -203,7 +213,7 @@ CHIAKI_EXPORT ChiakiErrorCode chiaki_bool_pred_cond_init(ChiakiBoolPredCond *con
{
cond->pred = false;
ChiakiErrorCode err = chiaki_mutex_init(&cond->mutex);
ChiakiErrorCode err = chiaki_mutex_init(&cond->mutex, false);
if(err != CHIAKI_ERR_SUCCESS)
return err;