From bd434921aeb347a069294e1d9749731760bc0f94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Florian=20M=C3=A4rkl?= Date: Thu, 29 Nov 2018 17:48:06 +0100 Subject: [PATCH] Prepare Audio Receiver --- gui/main.c | 6 +++++ lib/CMakeLists.txt | 2 +- lib/include/chiaki/audioreceiver.h | 42 ++++++++++++++++++++++++++++++ lib/include/chiaki/session.h | 22 ++++++++++++++-- lib/src/audioreceiver.c | 33 +++++++++++++++++++++++ 5 files changed, 102 insertions(+), 3 deletions(-) create mode 100644 lib/include/chiaki/audioreceiver.h create mode 100644 lib/src/audioreceiver.c diff --git a/gui/main.c b/gui/main.c index 2096582..cfb341a 100644 --- a/gui/main.c +++ b/gui/main.c @@ -4,6 +4,11 @@ #include #include +void audio_frame_cb(uint8_t *buf, size_t buf_size, void *user) +{ + printf("AUDIO FRAME CB %lu\n", buf_size); +} + int main(int argc, const char *argv[]) { if(argc != 7) @@ -42,6 +47,7 @@ int main(int argc, const char *argv[]) ChiakiSession session; chiaki_session_init(&session, &connect_info); + chiaki_session_set_audio_frame_cb(&session, audio_frame_cb, NULL); chiaki_session_start(&session); chiaki_session_join(&session); chiaki_session_fini(&session); diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index 9c158f0..4b1c133 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -36,7 +36,7 @@ set(SOURCE_FILES src/ecdh.c src/launchspec.c src/random.c - src/gkcrypt.c src/audio.c) + src/gkcrypt.c src/audio.c include/chiaki/audioreceiver.h src/audioreceiver.c) add_subdirectory(protobuf) include_directories("${NANOPB_SOURCE_DIR}") diff --git a/lib/include/chiaki/audioreceiver.h b/lib/include/chiaki/audioreceiver.h new file mode 100644 index 0000000..e1ef0d8 --- /dev/null +++ b/lib/include/chiaki/audioreceiver.h @@ -0,0 +1,42 @@ +/* + * 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 . + */ + +#ifndef CHIAKI_AUDIORECEIVER_H +#define CHIAKI_AUDIORECEIVER_H + +#include "common.h" +#include "log.h" + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct chiaki_audio_receiver_t +{ + struct chiaki_session_t *session; + ChiakiLog *log; +} ChiakiAudioReceiver; + +CHIAKI_EXPORT void chiaki_audio_receiver_init(ChiakiAudioReceiver *audio_receiver, struct chiaki_session_t *session); +CHIAKI_EXPORT void chiaki_audio_receiver_fini(ChiakiAudioReceiver *audio_receiver); + + +#ifdef __cplusplus +} +#endif + +#endif // CHIAKI_AUDIORECEIVER_H diff --git a/lib/include/chiaki/session.h b/lib/include/chiaki/session.h index 1a4e7bc..5bd94f1 100644 --- a/lib/include/chiaki/session.h +++ b/lib/include/chiaki/session.h @@ -26,6 +26,7 @@ #include "rpcrypt.h" #include "takion.h" #include "ecdh.h" +#include "audio.h" #include #include @@ -65,8 +66,16 @@ typedef struct chiaki_quit_event_t ChiakiQuitReason reason; } ChiakiQuitEvent; +typedef struct chiaki_audio_stream_info_event_t +{ + ChiakiAudioHeader audio_header; +} ChiakiAudioStreamInfoEvent; -typedef enum { CHIAKI_EVENT_QUIT } ChiakiEventType; + +typedef enum { + CHIAKI_EVENT_QUIT, + CHIAKI_EVENT_AUDIO_STREAM_INFO +} ChiakiEventType; typedef struct chiaki_event_t { @@ -74,11 +83,12 @@ typedef struct chiaki_event_t union { ChiakiQuitEvent quit; + ChiakiAudioStreamInfoEvent audio_stream_info; }; } ChiakiEvent; typedef void (*ChiakiEventCallback)(ChiakiEvent *event, void *user); - +typedef void (*ChiakiAudioFrameCallback)(uint8_t *buf, size_t buf_size, void *user); @@ -108,6 +118,8 @@ typedef struct chiaki_session_t ChiakiEventCallback event_cb; void *event_cb_user; + ChiakiAudioFrameCallback audio_frame_cb; + void *audio_frame_cb_user; ChiakiThread session_thread; @@ -132,6 +144,12 @@ static inline void chiaki_session_set_event_cb(ChiakiSession *session, ChiakiEve session->event_cb_user = user; } +static inline void chiaki_session_set_audio_frame_cb(ChiakiSession *session, ChiakiAudioFrameCallback cb, void *user) +{ + session->audio_frame_cb = cb; + session->audio_frame_cb_user = user; +} + static inline void chiaki_session_set_quit_reason(ChiakiSession *session, ChiakiQuitReason reason) { if(session->quit_reason != CHIAKI_QUIT_REASON_NONE) diff --git a/lib/src/audioreceiver.c b/lib/src/audioreceiver.c new file mode 100644 index 0000000..b233f79 --- /dev/null +++ b/lib/src/audioreceiver.c @@ -0,0 +1,33 @@ +/* + * 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 . + */ + +#include +#include + + +CHIAKI_EXPORT void chiaki_audio_receiver_init(ChiakiAudioReceiver *audio_receiver, ChiakiSession *session) +{ + audio_receiver->session = session; + audio_receiver->log = &session->log; + +} + + +CHIAKI_EXPORT void chiaki_audio_receiver_fini(ChiakiAudioReceiver *audio_receiver) +{ + +} \ No newline at end of file