forked from Green-Sky/tomato
start with toxav interface (wip)
no callbacks yet, gonna use threading
This commit is contained in:
parent
09372b3865
commit
b550810db5
@ -20,6 +20,9 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
|
||||
|
||||
option(TOMATO_MAIN_SO "Build tomato as a shared object (for eg android apps)" ANDROID)
|
||||
option(TOMATO_ASAN "Build tomato with asan (gcc/clang/msvc)" OFF)
|
||||
option(TOMATO_TOX_AV "Build tomato with ToxAV" OFF)
|
||||
|
||||
message("II TOMATO_TOX_AV: ${TOMATO_TOX_AV}")
|
||||
|
||||
if (TOMATO_ASAN)
|
||||
if (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang")
|
||||
|
5
external/toxcore/CMakeLists.txt
vendored
5
external/toxcore/CMakeLists.txt
vendored
@ -3,7 +3,10 @@ cmake_minimum_required(VERSION 3.13...3.16 FATAL_ERROR)
|
||||
set(EXPERIMENTAL_API ON CACHE BOOL "" FORCE)
|
||||
set(UNITTEST OFF CACHE BOOL "" FORCE)
|
||||
set(BOOTSTRAP_DAEMON OFF CACHE BOOL "" FORCE)
|
||||
#set(BUILD_TOXAV ON CACHE BOOL "")
|
||||
if (TOMATO_TOX_AV)
|
||||
set(BUILD_TOXAV ON CACHE BOOL "" FORCE)
|
||||
set(MUST_BUILD_TOXAV ON CACHE BOOL "" FORCE)
|
||||
endif()
|
||||
|
||||
add_subdirectory(./c-toxcore)
|
||||
|
||||
|
@ -104,6 +104,15 @@ target_sources(tomato PUBLIC
|
||||
./chat_gui4.cpp
|
||||
)
|
||||
|
||||
if (TOMATO_TOX_AV)
|
||||
target_sources(tomato PUBLIC
|
||||
./tox_av.hpp
|
||||
./tox_av.cpp
|
||||
)
|
||||
|
||||
target_compile_definitions(tomato PUBLIC TOMATO_TOX_AV)
|
||||
endif()
|
||||
|
||||
target_compile_features(tomato PUBLIC cxx_std_17)
|
||||
target_link_libraries(tomato PUBLIC
|
||||
solanaceae_util
|
||||
|
@ -21,6 +21,9 @@ MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme
|
||||
tc(save_path, save_password),
|
||||
tpi(tc.getTox()),
|
||||
ad(tc),
|
||||
#if TOMATO_TOX_AV
|
||||
tav(tc.getTox()),
|
||||
#endif
|
||||
tcm(cr, tc, tc),
|
||||
tmm(rmm, cr, tcm, tc, tc),
|
||||
ttm(rmm, cr, tcm, tc, tc),
|
||||
@ -70,6 +73,9 @@ MainScreen::MainScreen(SimpleConfigModel&& conf_, SDL_Renderer* renderer_, Theme
|
||||
g_provideInstance<ToxI>("ToxI", "host", &tc);
|
||||
g_provideInstance<ToxPrivateI>("ToxPrivateI", "host", &tpi);
|
||||
g_provideInstance<ToxEventProviderI>("ToxEventProviderI", "host", &tc);
|
||||
#if TOMATO_TOX_AV
|
||||
g_provideInstance<ToxAV>("ToxAV", "host", &tav);
|
||||
#endif
|
||||
g_provideInstance<ToxContactModel2>("ToxContactModel2", "host", &tcm);
|
||||
|
||||
// TODO: pm?
|
||||
|
@ -34,6 +34,10 @@
|
||||
#include "./tox_dht_cap_histo.hpp"
|
||||
#include "./tox_friend_faux_offline_messaging.hpp"
|
||||
|
||||
#if TOMATO_TOX_AV
|
||||
#include "./tox_av.hpp"
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <chrono>
|
||||
@ -58,6 +62,9 @@ struct MainScreen final : public Screen {
|
||||
ToxClient tc;
|
||||
ToxPrivateImpl tpi;
|
||||
AutoDirty ad;
|
||||
#if TOMATO_TOX_AV
|
||||
ToxAV tav;
|
||||
#endif
|
||||
ToxContactModel2 tcm;
|
||||
ToxMessageManager tmm;
|
||||
ToxTransferManager ttm;
|
||||
|
82
src/tox_av.cpp
Normal file
82
src/tox_av.cpp
Normal file
@ -0,0 +1,82 @@
|
||||
#include "./tox_av.hpp"
|
||||
|
||||
#include <cassert>
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
37
src/tox_av.hpp
Normal file
37
src/tox_av.hpp
Normal file
@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
#include <tox/toxav.h>
|
||||
|
||||
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);
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user