Skip to content

Commit

Permalink
batch of review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Green-Sky authored and iphydf committed Nov 6, 2024
1 parent ab7a879 commit c4cdea6
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 36 deletions.
2 changes: 1 addition & 1 deletion toxav/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
8 changes: 1 addition & 7 deletions toxav/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
7 changes: 1 addition & 6 deletions toxav/msi.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@

#define MSI_MAXMSG_SIZE 256

#ifndef TOXAV_DEFINED
#define TOXAV_DEFINED
typedef struct ToxAV ToxAV;
#endif /* TOXAV_DEFINED */

/**
* Protocol:
*
Expand Down Expand Up @@ -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)
{
Expand Down
5 changes: 1 addition & 4 deletions toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"

/**
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
5 changes: 0 additions & 5 deletions toxav/video.h
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 2 additions & 8 deletions toxcore/Messenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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];
Expand Down
3 changes: 3 additions & 0 deletions toxcore/net_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion toxcore/tox.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit c4cdea6

Please sign in to comment.