Skip to content

Commit a57c2c8

Browse files
zoff99Green-Sky
authored andcommitted
refactor: Make ToxAV independent of toxcore internals.
1 parent 5752fc2 commit a57c2c8

24 files changed

+912
-973
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ if(BUILD_TOXAV)
392392
toxav/rtp.h
393393
toxav/toxav.c
394394
toxav/toxav.h
395+
toxav/toxav_hacks.h
395396
toxav/toxav_old.c
396397
toxav/video.c
397398
toxav/video.h)

auto_tests/toxav_many_test.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,33 @@ static void test_av_three_calls(void)
168168
Time_Data time_data;
169169
pthread_mutex_init(&time_data.lock, nullptr);
170170
{
171+
Tox_Options *opts = tox_options_new(nullptr);
172+
ck_assert(opts != nullptr);
173+
tox_options_set_experimental_thread_safety(opts, true);
171174
Tox_Err_New error;
172175

173-
bootstrap = tox_new_log(nullptr, &error, &index[0]);
176+
bootstrap = tox_new_log(opts, &error, &index[0]);
174177
ck_assert(error == TOX_ERR_NEW_OK);
175178

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

179-
alice = tox_new_log(nullptr, &error, &index[1]);
182+
alice = tox_new_log(opts, &error, &index[1]);
180183
ck_assert(error == TOX_ERR_NEW_OK);
181184
set_current_time_callback(alice, &time_data);
182185

183-
bobs[0] = tox_new_log(nullptr, &error, &index[2]);
186+
bobs[0] = tox_new_log(opts, &error, &index[2]);
184187
ck_assert(error == TOX_ERR_NEW_OK);
185188
set_current_time_callback(bobs[0], &time_data);
186189

187-
bobs[1] = tox_new_log(nullptr, &error, &index[3]);
190+
bobs[1] = tox_new_log(opts, &error, &index[3]);
188191
ck_assert(error == TOX_ERR_NEW_OK);
189192
set_current_time_callback(bobs[1], &time_data);
190193

191-
bobs[2] = tox_new_log(nullptr, &error, &index[4]);
194+
bobs[2] = tox_new_log(opts, &error, &index[4]);
192195
ck_assert(error == TOX_ERR_NEW_OK);
193196
set_current_time_callback(bobs[2], &time_data);
197+
tox_options_free(opts);
194198
}
195199

196200
printf("Created 5 instances of Tox\n");

other/analysis/run-cppcheck

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ CPPCHECK+=("--suppress=knownConditionTrueFalse")
2020
CPPCHECK+=("--suppress=missingIncludeSystem")
2121
# TODO(iphydf): Maybe fix?
2222
CPPCHECK+=("--suppress=signConversion")
23-
# TODO(iphydf): Fixed in the toxav refactor PR.
24-
CPPCHECK+=("--suppress=redundantAssignment")
2523

2624
# We use this for VLAs.
2725
CPPCHECK_CXX+=("--suppress=allocaCalled")

toxav/BUILD.bazel

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -41,125 +41,30 @@ cc_library(
4141
deps = ["//c-toxcore/toxcore:ccompat"],
4242
)
4343

44-
cc_library(
45-
name = "bwcontroller",
46-
srcs = ["bwcontroller.c"],
47-
hdrs = ["bwcontroller.h"],
48-
deps = [
49-
":ring_buffer",
50-
"//c-toxcore/toxcore",
51-
"//c-toxcore/toxcore:Messenger",
52-
"//c-toxcore/toxcore:ccompat",
53-
"//c-toxcore/toxcore:logger",
54-
"//c-toxcore/toxcore:mono_time",
55-
"//c-toxcore/toxcore:tox",
56-
"//c-toxcore/toxcore:util",
57-
],
58-
)
59-
60-
cc_library(
61-
name = "rtp",
62-
srcs = ["rtp.c"],
63-
hdrs = ["rtp.h"],
64-
deps = [
65-
":bwcontroller",
66-
"//c-toxcore/toxcore:Messenger",
67-
"//c-toxcore/toxcore:ccompat",
68-
"//c-toxcore/toxcore:logger",
69-
"//c-toxcore/toxcore:mono_time",
70-
"//c-toxcore/toxcore:tox",
71-
"//c-toxcore/toxcore:util",
72-
],
73-
)
74-
75-
cc_test(
76-
name = "rtp_test",
77-
size = "small",
78-
srcs = ["rtp_test.cc"],
79-
deps = [
80-
":rtp",
81-
"//c-toxcore/toxcore:crypto_core",
82-
"@com_google_googletest//:gtest",
83-
"@com_google_googletest//:gtest_main",
84-
],
85-
)
86-
87-
cc_library(
88-
name = "audio",
89-
srcs = ["audio.c"],
90-
hdrs = ["audio.h"],
91-
deps = [
92-
":public_api",
93-
":rtp",
94-
"//c-toxcore/toxcore:ccompat",
95-
"//c-toxcore/toxcore:logger",
96-
"//c-toxcore/toxcore:mono_time",
97-
"//c-toxcore/toxcore:util",
98-
"@opus",
99-
],
100-
)
101-
102-
cc_library(
103-
name = "video",
104-
srcs = [
105-
"msi.c",
106-
"video.c",
107-
],
108-
hdrs = [
109-
"msi.h",
110-
"video.h",
111-
],
112-
deps = [
113-
":audio",
114-
":public_api",
115-
":ring_buffer",
116-
":rtp",
117-
"//c-toxcore/toxcore:Messenger",
118-
"//c-toxcore/toxcore:ccompat",
119-
"//c-toxcore/toxcore:logger",
120-
"//c-toxcore/toxcore:mono_time",
121-
"//c-toxcore/toxcore:network",
122-
"//c-toxcore/toxcore:util",
123-
"@libvpx",
124-
],
125-
)
126-
127-
cc_library(
128-
name = "groupav",
129-
srcs = ["groupav.c"],
130-
hdrs = ["groupav.h"],
131-
deps = [
132-
"//c-toxcore/toxcore",
133-
"//c-toxcore/toxcore:ccompat",
134-
"//c-toxcore/toxcore:group",
135-
"//c-toxcore/toxcore:logger",
136-
"//c-toxcore/toxcore:mono_time",
137-
"//c-toxcore/toxcore:tox",
138-
"//c-toxcore/toxcore:util",
139-
"@opus",
140-
],
141-
)
142-
14344
cc_library(
14445
name = "toxav",
145-
srcs = [
146-
"toxav.c",
147-
"toxav_old.c",
148-
],
149-
hdrs = [
150-
"toxav.h",
151-
],
46+
srcs = glob(
47+
[
48+
"*.c",
49+
"*.h",
50+
],
51+
exclude = ["toxav.h"],
52+
),
53+
hdrs = ["toxav.h"],
15254
visibility = ["//c-toxcore:__subpackages__"],
15355
deps = [
154-
":groupav",
155-
":rtp",
156-
":video",
15756
"//c-toxcore/toxcore:Messenger",
15857
"//c-toxcore/toxcore:ccompat",
58+
"//c-toxcore/toxcore:group",
15959
"//c-toxcore/toxcore:logger",
16060
"//c-toxcore/toxcore:mono_time",
61+
"//c-toxcore/toxcore:net_crypto",
62+
"//c-toxcore/toxcore:network",
16163
"//c-toxcore/toxcore:tox",
16264
"//c-toxcore/toxcore:util",
65+
"@libsodium",
66+
"@libvpx",
67+
"@opus",
16368
],
16469
)
16570

toxav/Makefile.inc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ libtoxav_la_SOURCES = ../toxav/rtp.h \
1919
../toxav/ring_buffer.h \
2020
../toxav/ring_buffer.c \
2121
../toxav/toxav.h \
22+
../toxav/toxav_hacks.h \
2223
../toxav/toxav.c \
2324
../toxav/toxav_old.c
2425

toxav/audio.c

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "../toxcore/ccompat.h"
1414
#include "../toxcore/logger.h"
1515
#include "../toxcore/mono_time.h"
16+
#include "../toxcore/network.h"
1617

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

29+
30+
2831
ACSession *ac_new(Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number,
2932
toxav_audio_receive_frame_cb *cb, void *cb_data)
3033
{
@@ -150,9 +153,9 @@ void ac_iterate(ACSession *ac)
150153

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

153-
/* NOTE: even though OPUS supports decoding mono frames with stereo decoder and vice versa,
154-
* it didn't work quite well.
155-
*/
156+
/** NOTE: even though OPUS supports decoding mono frames with stereo decoder and vice versa,
157+
* it didn't work quite well.
158+
*/
156159
if (!reconfigure_audio_decoder(ac, ac->lp_sampling_rate, ac->lp_channel_count)) {
157160
LOGGER_WARNING(ac->log, "Failed to reconfigure decoder!");
158161
free(msg);
@@ -273,6 +276,7 @@ static struct JitterBuffer *jbuf_new(uint32_t capacity)
273276
q->capacity = capacity;
274277
return q;
275278
}
279+
276280
static void jbuf_clear(struct JitterBuffer *q)
277281
{
278282
while (q->bottom != q->top) {
@@ -281,6 +285,7 @@ static void jbuf_clear(struct JitterBuffer *q)
281285
++q->bottom;
282286
}
283287
}
288+
284289
static void jbuf_free(struct JitterBuffer *q)
285290
{
286291
if (q == nullptr) {
@@ -291,6 +296,11 @@ static void jbuf_free(struct JitterBuffer *q)
291296
free(q->queue);
292297
free(q);
293298
}
299+
300+
/*
301+
* if -1 is returned the RTPMessage m needs to be free'd by the caller
302+
* if 0 is returned the RTPMessage m is stored in the ringbuffer and must NOT be freed by the caller
303+
*/
294304
static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessage *m)
295305
{
296306
const uint16_t sequnum = m->header.sequnum;
@@ -319,6 +329,7 @@ static int jbuf_write(const Logger *log, struct JitterBuffer *q, struct RTPMessa
319329

320330
return 0;
321331
}
332+
322333
static struct RTPMessage *jbuf_read(struct JitterBuffer *q, int32_t *success)
323334
{
324335
if (q->top == q->bottom) {

0 commit comments

Comments
 (0)