From c4cdea64994b265ce8634d83dcf97b0701d55285 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Wed, 18 Sep 2024 12:07:30 +0200 Subject: [PATCH] batch of review changes --- toxav/audio.c | 2 +- toxav/audio.h | 8 +------- toxav/bwcontroller.c | 4 ++-- toxav/msi.c | 7 +------ toxav/rtp.c | 5 +---- toxav/toxav.c | 4 ++-- toxav/video.h | 5 ----- toxcore/Messenger.h | 10 ++-------- toxcore/net_crypto.c | 3 +++ toxcore/tox.h | 2 +- 10 files changed, 14 insertions(+), 36 deletions(-) diff --git a/toxav/audio.c b/toxav/audio.c index 2d89355b2a7..ab11cc0d6b8 100644 --- a/toxav/audio.c +++ b/toxav/audio.c @@ -28,7 +28,7 @@ static bool reconfigure_audio_decoder(ACSession *ac, uint32_t sampling_rate, uin -ACSession *ac_new(Mono_Time *mono_time, const Logger *log, Tox *tox, ToxAV *av, uint32_t friend_number, +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) { ACSession *ac = (ACSession *)calloc(1, sizeof(ACSession)); diff --git a/toxav/audio.h b/toxav/audio.h index d7d8fd8b1aa..3ae42511370 100644 --- a/toxav/audio.h +++ b/toxav/audio.h @@ -34,11 +34,6 @@ #define AUDIO_MAX_BUFFER_SIZE_PCM16 ((AUDIO_MAX_SAMPLE_RATE * AUDIO_MAX_FRAME_DURATION_MS) / 1000) #define AUDIO_MAX_BUFFER_SIZE_BYTES (AUDIO_MAX_BUFFER_SIZE_PCM16 * 2) -#ifndef TOX_DEFINED -#define TOX_DEFINED -typedef struct Tox Tox; -#endif /* TOX_DEFINED */ - typedef struct ACSession { Mono_Time *mono_time; const Logger *log; @@ -66,10 +61,9 @@ typedef struct ACSession { /* Audio frame receive callback */ toxav_audio_receive_frame_cb *acb; void *acb_user_data; - Tox *tox; } ACSession; -ACSession *ac_new(Mono_Time *mono_time, const Logger *log, Tox *tox, ToxAV *av, uint32_t friend_number, +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); void ac_kill(ACSession *ac); void ac_iterate(ACSession *ac); diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c index 0294e35d405..8dacc92bb0d 100644 --- a/toxav/bwcontroller.c +++ b/toxav/bwcontroller.c @@ -205,14 +205,14 @@ static void bwc_handle_data(Tox *tox, uint32_t friend_number, const uint8_t *dat const Logger *log = toxav_get_logger(toxav); if (length - 1 != sizeof(struct BWCMessage)) { - LOGGER_ERROR(log, "Actual data size and length argument do not match"); + LOGGER_ERROR(log, "Got BWCMessage of insufficient size."); return; } const ToxAVCall *call = call_get(toxav, friend_number); if (call == nullptr) { - LOGGER_ERROR(log, "Could not get ToxAVCall object from ToxAV"); + LOGGER_ERROR(log, "Could not get ToxAVCall object from ToxAV."); return; } diff --git a/toxav/msi.c b/toxav/msi.c index 6865f5427f9..51736213616 100644 --- a/toxav/msi.c +++ b/toxav/msi.c @@ -20,11 +20,6 @@ #define MSI_MAXMSG_SIZE 256 -#ifndef TOXAV_DEFINED -#define TOXAV_DEFINED -typedef struct ToxAV ToxAV; -#endif /* TOXAV_DEFINED */ - /** * Protocol: * @@ -175,7 +170,7 @@ int msi_kill(const Logger *log, Tox *tox, MSISession *session) } /* - * return true if friend was offline and the call was canceled + * return true if friend is offline and the call was canceled. */ bool check_peer_offline_status(const Logger *log, const Tox *tox, MSISession *session, uint32_t friend_number) { diff --git a/toxav/rtp.c b/toxav/rtp.c index bb3fa14fe1b..32b2545d843 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c @@ -19,7 +19,6 @@ #include "../toxcore/mono_time.h" #include "../toxcore/net_crypto.h" #include "../toxcore/tox_private.h" -#include "../toxcore/tox_struct.h" #include "../toxcore/util.h" /** @@ -676,10 +675,8 @@ size_t rtp_header_unpack(const uint8_t *data, struct RTPHeader *header) static uint32_t rtp_random_u32(void) { - uint32_t randnum; // HINT: uses libsodium function - randombytes((uint8_t *)&randnum, sizeof(randnum)); - return randnum; + return randombytes_random(); } RTPSession *rtp_new(const Logger *log, int payload_type, Tox *tox, ToxAV *toxav, uint32_t friendnumber, diff --git a/toxav/toxav.c b/toxav/toxav.c index 81583221bd5..413b643a32a 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c @@ -239,7 +239,7 @@ ToxAV *toxav_new(Tox *tox, Toxav_Err_New *error) init_decode_time_stats(&av->video_stats); av->msi->av = av; - // save Tox object into toxcore + // save ToxAV object into toxcore tox_set_av_object(av->tox, av); msi_callback_invite(av->msi, callback_invite); @@ -1501,7 +1501,7 @@ static bool call_prepare_transmission(ToxAVCall *call) call->bwc = bwc_new(av->log, av->tox, call->friend_number, callback_bwc, call, av->toxav_mono_time); { /* Prepare audio */ - call->audio = ac_new(av->toxav_mono_time, av->log, av->tox, av, call->friend_number, av->acb, av->acb_user_data); + call->audio = ac_new(av->toxav_mono_time, av->log, av, call->friend_number, av->acb, av->acb_user_data); if (call->audio == nullptr) { LOGGER_ERROR(av->log, "Failed to create audio codec session"); diff --git a/toxav/video.h b/toxav/video.h index 98e937d9841..7bd54fa631b 100644 --- a/toxav/video.h +++ b/toxav/video.h @@ -21,11 +21,6 @@ #include "ring_buffer.h" #include "rtp.h" -#ifndef TOX_DEFINED -#define TOX_DEFINED -typedef struct Tox Tox; -#endif /* TOX_DEFINED */ - typedef struct VCSession { /* encoding */ vpx_codec_ctx_t encoder[1]; diff --git a/toxcore/Messenger.h b/toxcore/Messenger.h index 1fed8d34392..f651bf8d26a 100644 --- a/toxcore/Messenger.h +++ b/toxcore/Messenger.h @@ -177,7 +177,7 @@ typedef enum Filekind { typedef void m_self_connection_status_cb(Messenger *m, Onion_Connection_Status connection_status, void *user_data); typedef void m_friend_status_cb(Messenger *m, uint32_t friend_number, unsigned int status, void *user_data); typedef void m_friend_connection_status_cb(Messenger *m, uint32_t friend_number, unsigned int connection_status, - void *user_data); + void *user_data); typedef void m_friend_message_cb(Messenger *m, uint32_t friend_number, unsigned int message_type, const uint8_t *message, size_t length, void *user_data); typedef void m_file_recv_control_cb(Messenger *m, uint32_t friend_number, uint32_t file_number, unsigned int control, @@ -199,17 +199,11 @@ typedef void m_file_recv_chunk_cb(Messenger *m, uint32_t friend_number, uint32_t typedef void m_friend_lossy_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, size_t length, void *user_data); typedef void m_friend_lossless_packet_cb(Messenger *m, uint32_t friend_number, uint8_t packet_id, const uint8_t *data, - size_t length, void *user_data); + size_t length, void *user_data); typedef void m_conference_invite_cb(Messenger *m, uint32_t friend_number, const uint8_t *cookie, uint16_t length, void *user_data); typedef void m_group_invite_cb(const Messenger *m, uint32_t friend_number, const uint8_t *invite_data, size_t length, const uint8_t *group_name, size_t group_name_length, void *user_data); -typedef int m_lossy_rtp_packet_cb(Messenger *m, uint32_t friend_number, const uint8_t *data, uint16_t len, void *object); - -typedef struct RTP_Packet_Handler { - m_lossy_rtp_packet_cb *function; - void *object; -} RTP_Packet_Handler; typedef struct Friend { uint8_t real_pk[CRYPTO_PUBLIC_KEY_SIZE]; diff --git a/toxcore/net_crypto.c b/toxcore/net_crypto.c index 94b31d007a9..5aafe8a8a9f 100644 --- a/toxcore/net_crypto.c +++ b/toxcore/net_crypto.c @@ -1824,6 +1824,9 @@ static int create_crypto_connection(Net_Crypto *c) c->crypto_connections[id].last_packets_left_rem = 0.0; c->crypto_connections[id].packet_send_rate_requested = 0.0; c->crypto_connections[id].last_packets_left_requested_rem = 0.0; + + // TODO(Green-Sky): This enum is likely unneeded and the same as FREE. + c->crypto_connections[id].status = CRYPTO_CONN_NO_CONNECTION; } return id; diff --git a/toxcore/tox.h b/toxcore/tox.h index dbc3785ecf4..49b0c90d5a9 100644 --- a/toxcore/tox.h +++ b/toxcore/tox.h @@ -3289,7 +3289,7 @@ bool tox_friend_send_lossless_packet( /** * tox_callback_friend_lossy_packet is the compatibility function to - * set callback for all packet IDs except those reserved for ToxAV + * set the callback for all packet IDs except those reserved for ToxAV. * * @param friend_number The friend number of the friend who sent a lossy packet. * @param data A byte array containing the received packet data.