Skip to content
Merged
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
10 changes: 7 additions & 3 deletions toxav/bwcontroller.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ static void dummy()

#undef LOGGER_DEBUG
#define LOGGER_DEBUG(log, ...) dummy()
#undef LOGGER_INFO
#define LOGGER_INFO(log, ...) dummy()
// #undef LOGGER_INFO
// #define LOGGER_INFO(log, ...) dummy()

#define BWC_PACKET_ID 196
#define BWC_SEND_INTERVAL_MS 950 // 0.95s
Expand Down Expand Up @@ -69,7 +69,7 @@ struct BWCMessage {
uint32_t recv;
};

static int bwc_handle_data(Tox *t, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object);
// static int bwc_handle_data(Tox *t, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object);
static void send_update(BWController *bwc);

#if 0
Expand Down Expand Up @@ -188,6 +188,7 @@ static void send_update(BWController *bwc)
}
}

#if 0
static int on_update(BWController *bwc, const struct BWCMessage *msg)
{
LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc);
Expand All @@ -213,7 +214,9 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg)

return 0;
}
#endif

#if 0
static int bwc_handle_data(Tox *t, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object)
{
if (length - 1 != sizeof(struct BWCMessage)) {
Expand All @@ -228,3 +231,4 @@ static int bwc_handle_data(Tox *t, uint32_t friendnumber, const uint8_t *data, u

return on_update((BWController *)object, &msg);
}
#endif
32 changes: 9 additions & 23 deletions toxav/rtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,21 +466,13 @@ static int handle_video_packet(RTPSession *session, const struct RTPHeader *head
return 0;
}

typedef struct ToxAVCall_hack {
void *av;

pthread_mutex_t mutex_audio[1];
void *audio_rtp;
void *audio;

pthread_mutex_t mutex_video[1];
void *video_rtp;
} ToxAVCall_hack;

ToxAVCall_hack *call_get(void *av, uint32_t friend_number);
/* !!hack!! TODO:fix me */
void *call_get(void *av, uint32_t friend_number);
RTPSession *rtp_session_get(void *call, int payload_type);
/* !!hack!! TODO:fix me */

/**
* receive custom lossypackets and process them. they can be incoming audio or video patckets
* receive custom lossypackets and process them. they can be incoming audio or video packets
*/
void handle_rtp_packet(Tox *tox, uint32_t friendnumber, const uint8_t *data, size_t length2, void *dummy)
{
Expand All @@ -499,21 +491,15 @@ void handle_rtp_packet(Tox *tox, uint32_t friendnumber, const uint8_t *data, siz
return;
}

ToxAVCall_hack *call = call_get(toxav, friendnumber);
void *call = NULL;
call = (void *)call_get(toxav, friendnumber);

if (!call) {
return;
}

RTPSession *session = nullptr;

if (data[0] == RTP_TYPE_VIDEO) {
session = (RTPSession *)call->video_rtp;
} else if (data[0] == RTP_TYPE_AUDIO) {
session = (RTPSession *)call->audio_rtp;
} else {
return;
}
RTPSession *session = NULL;
session = rtp_session_get(call, data[0]);

if (!session) {
LOGGER_WARNING(m->log, "No session!");
Expand Down
45 changes: 34 additions & 11 deletions toxav/toxav.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,14 +130,15 @@ static bool audio_bit_rate_invalid(uint32_t bit_rate);
static bool video_bit_rate_invalid(uint32_t bit_rate);
static bool invoke_call_state_callback(ToxAV *av, uint32_t friend_number, uint32_t state);
static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *error);
static ToxAVCall *call_get(ToxAV *av, uint32_t friend_number);
static ToxAVCall *call_remove(ToxAVCall *call);
static bool call_prepare_transmission(ToxAVCall *call);
static void call_kill_transmission(ToxAVCall *call);

MSISession *tox_av_msi_get(ToxAV *av);
int toxav_friend_exists(const Tox *tox, int32_t friendnumber);
Mono_Time *toxav_get_av_mono_time(ToxAV *toxav);
ToxAVCall *call_get(ToxAV *av, uint32_t friend_number);
RTPSession *rtp_session_get(void *call, int payload_type);

MSISession *tox_av_msi_get(ToxAV *av)
{
Expand All @@ -148,6 +149,38 @@ MSISession *tox_av_msi_get(ToxAV *av)
return av->msi;
}

ToxAVCall *call_get(ToxAV *av, uint32_t friend_number)
{
if (av == nullptr) {
return nullptr;
}

/* Assumes mutex locked */
if (av->calls == nullptr || av->calls_tail < friend_number) {
return nullptr;
}

return av->calls[friend_number];
}

RTPSession *rtp_session_get(void *call, int payload_type)
{
if (((ToxAVCall *)call) == nullptr) {
return nullptr;
}

if (payload_type == RTP_TYPE_VIDEO)
{
return ((ToxAVCall *)call)->video_rtp;
}
else
{
return ((ToxAVCall *)call)->audio_rtp;
}

return nullptr;
}

ToxAV *toxav_new(Tox *tox, Toxav_Err_New *error)
{
Toxav_Err_New rc = TOXAV_ERR_NEW_OK;
Expand Down Expand Up @@ -1292,16 +1325,6 @@ static ToxAVCall *call_new(ToxAV *av, uint32_t friend_number, Toxav_Err_Call *er
return call;
}

static ToxAVCall *call_get(ToxAV *av, uint32_t friend_number)
{
/* Assumes mutex locked */
if (av->calls == nullptr || av->calls_tail < friend_number) {
return nullptr;
}

return av->calls[friend_number];
}

static ToxAVCall *call_remove(ToxAVCall *call)
{
if (call == nullptr) {
Expand Down