From fae1910f1a213ef956703220c34d7d157f023ced Mon Sep 17 00:00:00 2001 From: Green Sky Date: Thu, 16 May 2024 17:20:20 +0200 Subject: [PATCH] start with toxav interface (no callbacks yet, gonna use threading) --- src/CMakeLists.txt | 3 ++ src/main_screen.cpp | 2 ++ src/main_screen.hpp | 2 ++ src/tox_av.cpp | 82 +++++++++++++++++++++++++++++++++++++++++++++ src/tox_av.hpp | 37 ++++++++++++++++++++ 5 files changed, 126 insertions(+) create mode 100644 src/tox_av.cpp create mode 100644 src/tox_av.hpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 4d986c8..c2c92d2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,6 +16,9 @@ add_executable(tomato ./tox_client.cpp ./auto_dirty.hpp ./auto_dirty.cpp + ./tox_private_impl.hpp + ./tox_av.hpp + ./tox_av.cpp ./theme.hpp diff --git a/src/main_screen.cpp b/src/main_screen.cpp index a7fdedf..f06c491 100644 --- a/src/main_screen.cpp +++ b/src/main_screen.cpp @@ -20,6 +20,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_ tc(save_path, save_password), tpi(tc.getTox()), ad(tc), + tav(tc.getTox()), tcm(cr, tc, tc), tmm(rmm, cr, tcm, tc, tc), ttm(rmm, cr, tcm, tc, tc), @@ -69,6 +70,7 @@ MainScreen::MainScreen(SDL_Renderer* renderer_, Theme& theme_, std::string save_ g_provideInstance("ToxI", "host", &tc); g_provideInstance("ToxPrivateI", "host", &tpi); g_provideInstance("ToxEventProviderI", "host", &tc); + g_provideInstance("ToxAV", "host", &tav); g_provideInstance("ToxContactModel2", "host", &tcm); // TODO: pm? diff --git a/src/main_screen.hpp b/src/main_screen.hpp index d1a0dc6..7735ce9 100644 --- a/src/main_screen.hpp +++ b/src/main_screen.hpp @@ -11,6 +11,7 @@ #include #include #include "./tox_private_impl.hpp" +#include "./tox_av.hpp" #include #include @@ -58,6 +59,7 @@ struct MainScreen final : public Screen { ToxClient tc; ToxPrivateImpl tpi; AutoDirty ad; + ToxAV tav; ToxContactModel2 tcm; ToxMessageManager tmm; ToxTransferManager ttm; diff --git a/src/tox_av.cpp b/src/tox_av.cpp new file mode 100644 index 0000000..eeefb2b --- /dev/null +++ b/src/tox_av.cpp @@ -0,0 +1,82 @@ +#include "./tox_av.hpp" + +#include + +// https://almogfx.bandcamp.com/track/crushed-w-cassade + +ToxAV::ToxAV(Tox* tox) : _tox(tox) { + Toxav_Err_New err_new {TOXAV_ERR_NEW_OK}; + _tox_av = toxav_new(_tox, &err_new); + // TODO: throw + assert(err_new == TOXAV_ERR_NEW_OK); +} +ToxAV::~ToxAV(void) { + toxav_kill(_tox_av); +} + +uint32_t ToxAV::toxavIterationInterval(void) const { + return toxav_iteration_interval(_tox_av); +} + +void ToxAV::toxavIterate(void) { + toxav_iterate(_tox_av); +} + +uint32_t ToxAV::toxavAudioIterationInterval(void) const { + return toxav_audio_iteration_interval(_tox_av); +} + +void ToxAV::toxavAudioIterate(void) { + toxav_audio_iterate(_tox_av); +} + +uint32_t ToxAV::toxavVideoIterationInterval(void) const { + return toxav_video_iteration_interval(_tox_av); +} + +void ToxAV::toxavVideoIterate(void) { + toxav_video_iterate(_tox_av); +} + +Toxav_Err_Call ToxAV::toxavCall(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate) { + Toxav_Err_Call err {TOXAV_ERR_CALL_OK}; + toxav_call(_tox_av, friend_number, audio_bit_rate, video_bit_rate, &err); + return err; +} + +Toxav_Err_Answer ToxAV::toxavAnswer(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate) { + Toxav_Err_Answer err {TOXAV_ERR_ANSWER_OK}; + toxav_answer(_tox_av, friend_number, audio_bit_rate, video_bit_rate, &err); + return err; +} + +Toxav_Err_Call_Control ToxAV::toxavCallControl(uint32_t friend_number, Toxav_Call_Control control) { + Toxav_Err_Call_Control err {TOXAV_ERR_CALL_CONTROL_OK}; + toxav_call_control(_tox_av, friend_number, control, &err); + return err; +} + +Toxav_Err_Send_Frame ToxAV::toxavAudioSendFrame(uint32_t friend_number, const int16_t pcm[], size_t sample_count, uint8_t channels, uint32_t sampling_rate) { + Toxav_Err_Send_Frame err {TOXAV_ERR_SEND_FRAME_OK}; + toxav_audio_send_frame(_tox_av, friend_number, pcm, sample_count, channels, sampling_rate, &err); + return err; +} + +Toxav_Err_Bit_Rate_Set ToxAV::toxavAudioSetBitRate(uint32_t friend_number, uint32_t bit_rate) { + Toxav_Err_Bit_Rate_Set err {TOXAV_ERR_BIT_RATE_SET_OK}; + toxav_audio_set_bit_rate(_tox_av, friend_number, bit_rate, &err); + return err; +} + +Toxav_Err_Send_Frame ToxAV::toxavVideoSendFrame(uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t y[], const uint8_t u[], const uint8_t v[]) { + Toxav_Err_Send_Frame err {TOXAV_ERR_SEND_FRAME_OK}; + toxav_video_send_frame(_tox_av, friend_number, width, height, y, u, v, &err); + return err; +} + +Toxav_Err_Bit_Rate_Set ToxAV::toxavVideoSetBitRate(uint32_t friend_number, uint32_t bit_rate) { + Toxav_Err_Bit_Rate_Set err {TOXAV_ERR_BIT_RATE_SET_OK}; + toxav_video_set_bit_rate(_tox_av, friend_number, bit_rate, &err); + return err; +} + diff --git a/src/tox_av.hpp b/src/tox_av.hpp new file mode 100644 index 0000000..c116cc5 --- /dev/null +++ b/src/tox_av.hpp @@ -0,0 +1,37 @@ +#pragma once + +#include + +struct ToxAV { + Tox* _tox = nullptr; + ToxAV* _tox_av = nullptr; + + ToxAV(Tox* tox); + virtual ~ToxAV(void); + + // interface + uint32_t toxavIterationInterval(void) const; + void toxavIterate(void); + + uint32_t toxavAudioIterationInterval(void) const; + void toxavAudioIterate(void); + uint32_t toxavVideoIterationInterval(void) const; + void toxavVideoIterate(void); + + Toxav_Err_Call toxavCall(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate); + Toxav_Err_Answer toxavAnswer(uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate); + Toxav_Err_Call_Control toxavCallControl(uint32_t friend_number, Toxav_Call_Control control); + Toxav_Err_Send_Frame toxavAudioSendFrame(uint32_t friend_number, const int16_t pcm[], size_t sample_count, uint8_t channels, uint32_t sampling_rate); + Toxav_Err_Bit_Rate_Set toxavAudioSetBitRate(uint32_t friend_number, uint32_t bit_rate); + Toxav_Err_Send_Frame toxavVideoSendFrame(uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t y[/*! height * width */], const uint8_t u[/*! height/2 * width/2 */], const uint8_t v[/*! height/2 * width/2 */]); + Toxav_Err_Bit_Rate_Set toxavVideoSetBitRate(uint32_t friend_number, uint32_t bit_rate); + +//int32_t toxav_add_av_groupchat(Tox *tox, toxav_audio_data_cb *audio_callback, void *userdata); +//int32_t toxav_join_av_groupchat(Tox *tox, uint32_t friendnumber, const uint8_t data[], uint16_t length, toxav_audio_data_cb *audio_callback, void *userdata); +//int32_t toxav_group_send_audio(Tox *tox, uint32_t groupnumber, const int16_t pcm[], uint32_t samples, uint8_t channels, uint32_t sample_rate); +//int32_t toxav_groupchat_enable_av(Tox *tox, uint32_t groupnumber, toxav_audio_data_cb *audio_callback, void *userdata); +//int32_t toxav_groupchat_disable_av(Tox *tox, uint32_t groupnumber); +//bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber); + +}; +