Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Make ToxAV independent of toxcore internals. #2651

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ if(BUILD_TOXAV)
toxav/rtp.h
toxav/toxav.c
toxav/toxav.h
toxav/toxav_hacks.h
toxav/toxav_old.c
toxav/video.c
toxav/video.h)
Expand Down
14 changes: 9 additions & 5 deletions auto_tests/toxav_many_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,29 +168,33 @@ static void test_av_three_calls(void)
Time_Data time_data;
pthread_mutex_init(&time_data.lock, nullptr);
{
Tox_Options *opts = tox_options_new(nullptr);
ck_assert(opts != nullptr);
tox_options_set_experimental_thread_safety(opts, true);
Tox_Err_New error;

bootstrap = tox_new_log(nullptr, &error, &index[0]);
bootstrap = tox_new_log(opts, &error, &index[0]);
ck_assert(error == TOX_ERR_NEW_OK);

time_data.clock = current_time_monotonic(bootstrap->mono_time);
set_current_time_callback(bootstrap, &time_data);

alice = tox_new_log(nullptr, &error, &index[1]);
alice = tox_new_log(opts, &error, &index[1]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(alice, &time_data);

bobs[0] = tox_new_log(nullptr, &error, &index[2]);
bobs[0] = tox_new_log(opts, &error, &index[2]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(bobs[0], &time_data);

bobs[1] = tox_new_log(nullptr, &error, &index[3]);
bobs[1] = tox_new_log(opts, &error, &index[3]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(bobs[1], &time_data);

bobs[2] = tox_new_log(nullptr, &error, &index[4]);
bobs[2] = tox_new_log(opts, &error, &index[4]);
ck_assert(error == TOX_ERR_NEW_OK);
set_current_time_callback(bobs[2], &time_data);
tox_options_free(opts);
}

printf("Created 5 instances of Tox\n");
Expand Down
2 changes: 0 additions & 2 deletions other/analysis/run-cppcheck
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ CPPCHECK+=("--suppress=knownConditionTrueFalse")
CPPCHECK+=("--suppress=missingIncludeSystem")
# TODO(iphydf): Maybe fix?
CPPCHECK+=("--suppress=signConversion")
# TODO(iphydf): Fixed in the toxav refactor PR.
CPPCHECK+=("--suppress=redundantAssignment")

# We use this for VLAs.
CPPCHECK_CXX+=("--suppress=allocaCalled")
Expand Down
123 changes: 14 additions & 109 deletions toxav/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -41,125 +41,30 @@ cc_library(
deps = ["//c-toxcore/toxcore:ccompat"],
)

cc_library(
name = "bwcontroller",
srcs = ["bwcontroller.c"],
hdrs = ["bwcontroller.h"],
deps = [
":ring_buffer",
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
],
)

cc_library(
name = "rtp",
srcs = ["rtp.c"],
hdrs = ["rtp.h"],
deps = [
":bwcontroller",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
],
)

cc_test(
name = "rtp_test",
size = "small",
srcs = ["rtp_test.cc"],
deps = [
":rtp",
"//c-toxcore/toxcore:crypto_core",
"@com_google_googletest//:gtest",
"@com_google_googletest//:gtest_main",
],
)

cc_library(
name = "audio",
srcs = ["audio.c"],
hdrs = ["audio.h"],
deps = [
":public_api",
":rtp",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:util",
"@opus",
],
)

cc_library(
name = "video",
srcs = [
"msi.c",
"video.c",
],
hdrs = [
"msi.h",
"video.h",
],
deps = [
":audio",
":public_api",
":ring_buffer",
":rtp",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:util",
"@libvpx",
],
)

cc_library(
name = "groupav",
srcs = ["groupav.c"],
hdrs = ["groupav.h"],
deps = [
"//c-toxcore/toxcore",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:group",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
"@opus",
],
)

cc_library(
name = "toxav",
srcs = [
"toxav.c",
"toxav_old.c",
],
hdrs = [
"toxav.h",
],
srcs = glob(
[
"*.c",
"*.h",
],
exclude = ["toxav.h"],
),
hdrs = ["toxav.h"],
visibility = ["//c-toxcore:__subpackages__"],
deps = [
":groupav",
":rtp",
":video",
"//c-toxcore/toxcore:Messenger",
"//c-toxcore/toxcore:ccompat",
"//c-toxcore/toxcore:group",
"//c-toxcore/toxcore:logger",
"//c-toxcore/toxcore:mono_time",
"//c-toxcore/toxcore:net_crypto",
"//c-toxcore/toxcore:network",
"//c-toxcore/toxcore:tox",
"//c-toxcore/toxcore:util",
"@libsodium",
"@libvpx",
"@opus",
],
)

Expand Down
1 change: 1 addition & 0 deletions toxav/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ libtoxav_la_SOURCES = ../toxav/rtp.h \
../toxav/ring_buffer.h \
../toxav/ring_buffer.c \
../toxav/toxav.h \
../toxav/toxav_hacks.h \
../toxav/toxav.c \
../toxav/toxav_old.c

Expand Down
17 changes: 14 additions & 3 deletions toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "../toxcore/ccompat.h"
#include "../toxcore/logger.h"
#include "../toxcore/mono_time.h"
#include "../toxcore/network.h"

static struct JitterBuffer *jbuf_new(uint32_t capacity);
static void jbuf_clear(struct JitterBuffer *q);
Expand All @@ -25,6 +26,8 @@ static bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, uint32
uint8_t new_ch, uint32_t *old_br, uint32_t *old_sr, uint8_t *old_ch);
static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uint8_t channels);



ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number,
toxav_audio_receive_frame_cb *cb, void *cb_data)
{
Expand Down Expand Up @@ -150,9 +153,9 @@ void ac_iterate(ACSession *ac)

ac->lp_channel_count = opus_packet_get_nb_channels(msg->data + 4);

/* NOTE: even though OPUS supports decoding mono frames with stereo decoder and vice versa,
* it didn't work quite well.
*/
/** NOTE: even though OPUS supports decoding mono frames with stereo decoder and vice versa,
* it didn't work quite well.
*/
if (!reconfigure_audio_decoder(ac, ac->lp_sampling_rate, ac->lp_channel_count)) {
LOGGER_WARNING(ac->log, "Failed to reconfigure decoder!");
free(msg);
Expand Down Expand Up @@ -273,6 +276,7 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity)
q->capacity = capacity;
return q;
}

static void jbuf_clear(struct JitterBuffer *q)
{
while (q->bottom != q->top) {
Expand All @@ -281,6 +285,7 @@ static void jbuf_clear(struct JitterBuffer *q)
++q->bottom;
}
}

static void jbuf_free(struct JitterBuffer *q)
{
if (q == nullptr) {
Expand All @@ -291,6 +296,11 @@ static void jbuf_free(struct JitterBuffer *q)
free(q->queue);
free(q);
}

/*
* if -1 is returned the RTPMessage m needs to be free'd by the caller
* if 0 is returned the RTPMessage m is stored in the ringbuffer and must NOT be freed by the caller
*/
static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessage *m)
{
const uint16_t sequnum = m->header.sequnum;
Expand Down Expand Up @@ -319,6 +329,7 @@ static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessa

return 0;
}

static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
{
if (q->top == q->bottom) {
Expand Down
Loading
Loading