Fixed tests and conflicts

This commit is contained in:
mannol 2014-07-27 00:26:58 +02:00
commit fc230c8671
8 changed files with 151 additions and 168 deletions

View File

@ -1,7 +1,7 @@
if BUILD_TESTS
TESTS = messenger_autotest# crypto_test network_test assoc_test onion_test TCP_test tox_test
check_PROGRAMS = messenger_autotest# crypto_test network_test assoc_test onion_test TCP_test tox_test
TESTS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
check_PROGRAMS = messenger_autotest crypto_test network_test assoc_test onion_test TCP_test tox_test
AUTOTEST_CFLAGS = \
$(LIBSODIUM_CFLAGS) \
@ -20,8 +20,8 @@ AUTOTEST_LDADD = \
if BUILD_AV
TESTS += toxav_basic_test #toxav_many_test
check_PROGRAMS += toxav_basic_test #toxav_many_test
TESTS += toxav_basic_test toxav_many_test
check_PROGRAMS += toxav_basic_test toxav_many_test
AUTOTEST_LDADD += libtoxav.la
endif
@ -32,7 +32,46 @@ messenger_autotest_CFLAGS = $(AUTOTEST_CFLAGS)
messenger_autotest_LDADD = $(AUTOTEST_LDADD)
crypto_test_SOURCES = ../auto_tests/crypto_test.c
crypto_test_CFLAGS = $(AUTOTEST_CFLAGS)
crypto_test_LDADD = $(AUTOTEST_LDADD)
network_test_SOURCES = ../auto_tests/network_test.c
network_test_CFLAGS = $(AUTOTEST_CFLAGS)
network_test_LDADD = $(AUTOTEST_LDADD)
assoc_test_SOURCES = ../auto_tests/assoc_test.c
assoc_test_CFLAGS = $(AUTOTEST_CFLAGS)
assoc_test_LDADD = $(AUTOTEST_LDADD)
onion_test_SOURCES = ../auto_tests/onion_test.c
onion_test_CFLAGS = $(AUTOTEST_CFLAGS)
onion_test_LDADD = $(AUTOTEST_LDADD)
TCP_test_SOURCES = ../auto_tests/TCP_test.c
TCP_test_CFLAGS = $(AUTOTEST_CFLAGS)
TCP_test_LDADD = $(AUTOTEST_LDADD)
tox_test_SOURCES = ../auto_tests/tox_test.c
tox_test_CFLAGS = $(AUTOTEST_CFLAGS)
tox_test_LDADD = $(AUTOTEST_LDADD)
@ -44,14 +83,13 @@ toxav_basic_test_CFLAGS = $(AUTOTEST_CFLAGS)
toxav_basic_test_LDADD = $(AUTOTEST_LDADD)
#toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c
toxav_many_test_SOURCES = ../auto_tests/toxav_many_test.c
#toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS)
toxav_many_test_CFLAGS = $(AUTOTEST_CFLAGS)
#toxav_many_test_LDADD = $(AUTOTEST_LDADD)
toxav_many_test_LDADD = $(AUTOTEST_LDADD)
endif
endif
EXTRA_DIST += $(top_srcdir)/auto_tests/friends_test.c
EXTRA_DIST += $(top_srcdir)/auto_tests/friends_test.c

View File

@ -49,7 +49,7 @@ typedef struct _Status {
} Status;
/* My default settings */
static ToxAvCodecSettings muhcaps;
static ToxAvCSettings muhcaps;
void accept_friend_request(Tox *m, const uint8_t *public_key, const uint8_t *data, uint16_t length, void *userdata)
{
@ -82,7 +82,7 @@ void callback_recv_starting ( void *av, int32_t call_index, void *_arg )
/* Alice always sends invite */
printf("Call started on Alice side...\n");
cast->Alice.status = InCall;
toxav_prepare_transmission(av, call_index, 3, 0, 1);
toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
}
void callback_recv_ending ( void *av, int32_t call_index, void *_arg )
{
@ -105,7 +105,7 @@ void callback_call_started ( void *av, int32_t call_index, void *_arg )
/* Alice always sends invite */
printf("Call started on Bob side...\n");
cast->Bob.status = InCall;
toxav_prepare_transmission(av, call_index, 3, 0, 1);
toxav_prepare_transmission(av, call_index, av_jbufdc, av_VADd, 1);
}
void callback_call_canceled ( void *av, int32_t call_index, void *_arg )
{
@ -133,7 +133,7 @@ void callback_call_ended ( void *av, int32_t call_index, void *_arg )
void callback_call_type_change ( void *av, int32_t call_index, void *_arg )
{
ToxAvCodecSettings csettings;
ToxAvCSettings csettings;
toxav_get_peer_csettings(av, call_index, 0, &csettings);
printf("New settings: \n"
@ -312,7 +312,7 @@ START_TEST(test_AV_flows)
step++; /* This terminates the loop */
toxav_kill_transmission(status_control.Alice.av, status_control.Alice.call_index);
toxav_kill_transmission(status_control.Bob.av, status_control.Bob.call_index);
/* Call over Alice hangs up */
toxav_hangup(status_control.Alice.av, status_control.Alice.call_index);
}

View File

@ -174,7 +174,7 @@ void *in_thread_call (void *arg)
switch ( step ) {
case 0: /* CALLER */
toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, TypeVideo, 10);
toxav_call(this_call->Caller.av, &call_idx, this_call->Callee.id, &av_DefaultSettings, 10);
call_print(call_idx, "Calling ...");
step++;
break;
@ -182,7 +182,7 @@ void *in_thread_call (void *arg)
case 1: /* CALLEE */
if (this_call->Caller.status == Ringing) {
call_print(call_idx, "Callee answers ...");
toxav_answer(this_call->Callee.av, 0, TypeVideo);
toxav_answer(this_call->Callee.av, 0, &av_DefaultSettings);
step++;
start = time(NULL);
}
@ -193,11 +193,9 @@ void *in_thread_call (void *arg)
if (this_call->Caller.status == InCall) { /* I think this is okay */
call_print(call_idx, "Sending rtp ...");
ToxAvCodecSettings cast = av_DefaultSettings;
c_sleep(1000); /* We have race condition here */
toxav_prepare_transmission(this_call->Callee.av, 0, &cast, 1);
toxav_prepare_transmission(this_call->Caller.av, call_idx, &cast, 1);
toxav_prepare_transmission(this_call->Callee.av, 0, 3, 0, 1);
toxav_prepare_transmission(this_call->Caller.av, call_idx, 3, 0, 1);
int payload_size = toxav_prepare_audio_frame(this_call->Caller.av, call_idx, prepared_payload, RTP_PAYLOAD_SIZE,
sample_payload, frame_size);

View File

@ -36,152 +36,96 @@
#include "rtp.h"
#include "codec.h"
const uint16_t min_jbuf_size = 4;
const uint16_t min_readiness_idx = 2; /* when is buffer ready to dqq */
int empty_queue(JitterBuffer *q)
JitterBuffer *create_queue(unsigned int capacity)
{
while (q->size > 0) {
rtp_free_msg(NULL, q->queue[q->front]);
q->front++;
unsigned int size = 1;
if (q->front == q->capacity)
q->front = 0;
q->size--;
while (size <= (capacity + 4) * 2) {
size *= 2;
}
q->id_set = 0;
q->queue_ready = 0;
return 0;
}
JitterBuffer *create_queue(int capacity)
{
JitterBuffer *q;
if ( !(q = calloc(sizeof(JitterBuffer), 1)) ) return NULL;
if (!(q->queue = calloc(sizeof(RTPMessage *), capacity))) {
if (!(q->queue = calloc(sizeof(RTPMessage *), size))) {
free(q);
return NULL;
}
q->size = 0;
q->capacity = capacity >= min_jbuf_size ? capacity : min_jbuf_size;
q->front = 0;
q->rear = -1;
q->queue_ready = 0;
q->current_id = 0;
q->current_ts = 0;
q->id_set = 0;
q->size = size;
q->capacity = capacity;
return q;
}
static void clear_queue(JitterBuffer *q)
{
for (; q->bottom != q->top; ++q->bottom) {
if (q->queue[q->bottom % q->size]) {
rtp_free_msg(NULL, q->queue[q->bottom % q->size]);
q->queue[q->bottom % q->size] = NULL;
}
}
}
void terminate_queue(JitterBuffer *q)
{
if (!q) return;
empty_queue(q);
clear_queue(q);
free(q->queue);
LOGGER_DEBUG("Terminated jitter buffer: %p", q);
free(q);
}
#define sequnum_older(sn_a, sn_b, ts_a, ts_b) (sn_a > sn_b || ts_a > ts_b)
void queue(JitterBuffer *q, RTPMessage *pk)
{
uint16_t sequnum = pk->header->sequnum;
unsigned int num = sequnum % q->size;
if (sequnum - q->bottom > q->size) {
clear_queue(q);
q->bottom = sequnum;
q->queue[num] = pk;
q->top = sequnum + 1;
return;
}
if (q->queue[num])
return;
q->queue[num] = pk;
if ((sequnum - q->bottom) >= (q->top - q->bottom))
q->top = sequnum + 1;
}
/* success is 0 when there is nothing to dequeue, 1 when there's a good packet, 2 when there's a lost packet */
RTPMessage *dequeue(JitterBuffer *q, int *success)
{
if (q->size == 0 || q->queue_ready == 0) { /* Empty queue */
q->queue_ready = 0;
if (q->top == q->bottom) {
*success = 0;
return NULL;
}
int front = q->front;
unsigned int num = q->bottom % q->size;
if (q->id_set == 0) {
q->current_id = q->queue[front]->header->sequnum;
q->current_ts = q->queue[front]->header->timestamp;
q->id_set = 1;
} else {
int next_id = q->queue[front]->header->sequnum;
int next_ts = q->queue[front]->header->timestamp;
/* if this packet is indeed the expected packet */
if (next_id == (q->current_id + 1) % MAX_SEQU_NUM) {
q->current_id = next_id;
q->current_ts = next_ts;
} else {
if (sequnum_older(next_id, q->current_id, next_ts, q->current_ts)) {
LOGGER_DEBUG("nextid: %d current: %d\n", next_id, q->current_id);
q->current_id = (q->current_id + 1) % MAX_SEQU_NUM;
*success = 2; /* tell the decoder the packet is lost */
return NULL;
} else {
LOGGER_DEBUG("Packet too old");
*success = 0;
return NULL;
}
}
if (q->queue[num]) {
RTPMessage *ret = q->queue[num];
q->queue[num] = NULL;
++q->bottom;
*success = 1;
return ret;
}
q->size--;
q->front++;
if (q->front == q->capacity)
q->front = 0;
*success = 1;
q->current_id = q->queue[front]->header->sequnum;
q->current_ts = q->queue[front]->header->timestamp;
return q->queue[front];
}
void queue(JitterBuffer *q, RTPMessage *pk)
{
if (q->size == q->capacity) { /* Full, empty queue */
LOGGER_DEBUG("Queue full s(%d) c(%d), emptying...", q->size, q->capacity);
empty_queue(q);
if (q->top - q->bottom > q->capacity) {
++q->bottom;
*success = 2;
return NULL;
}
if (q->size >= min_readiness_idx) q->queue_ready = 1;
++q->size;
++q->rear;
if (q->rear == q->capacity) q->rear = 0;
q->queue[q->rear] = pk;
int a;
int j;
a = q->rear;
for (j = 0; j < q->size - 1; ++j) {
int b = a - 1;
if (b < 0)
b += q->capacity;
if (sequnum_older(q->queue[b]->header->sequnum, q->queue[a]->header->sequnum,
q->queue[b]->header->timestamp, q->queue[a]->header->timestamp)) {
RTPMessage *temp;
temp = q->queue[a];
q->queue[a] = q->queue[b];
q->queue[b] = temp;
LOGGER_DEBUG("Had to swap");
} else {
break;
}
a -= 1;
if (a < 0) a += q->capacity;
}
*success = 0;
return NULL;
}

View File

@ -78,17 +78,13 @@ typedef struct _CodecState {
typedef struct _JitterBuffer {
RTPMessage **queue;
uint16_t capacity;
uint16_t size;
uint16_t front;
uint16_t rear;
uint8_t queue_ready;
uint16_t current_id;
uint32_t current_ts;
uint8_t id_set;
unsigned int size;
unsigned int capacity;
uint16_t bottom;
uint16_t top;
} JitterBuffer;
JitterBuffer *create_queue(int capacity);
JitterBuffer *create_queue(unsigned int capacity);
void terminate_queue(JitterBuffer *q);
void queue(JitterBuffer *q, RTPMessage *pk);
RTPMessage *dequeue(JitterBuffer *q, int *success);

View File

@ -551,7 +551,7 @@ RTPSession *rtp_init_session ( int payload_type, Messenger *messenger, int frien
_retu->dest = friend_num;
_retu->rsequnum = _retu->sequnum = 1;
_retu->rsequnum = _retu->sequnum = 0;
_retu->ext_header = NULL; /* When needed allocate */

View File

@ -51,6 +51,24 @@
/* call index invalid: true if invalid */
#define cii(c_idx, session) (c_idx < 0 || c_idx >= session->max_calls)
const ToxAvCSettings av_DefaultSettings = {
TypeAudio,
500,
1280,
720,
64000,
20,
48000,
1
};
const uint32_t av_jbufdc = 3;
const uint32_t av_VADd = 40;
static const uint8_t audio_index = 0, video_index = 1;
typedef struct _CallSpecific {
@ -84,20 +102,7 @@ struct _ToxAv {
uint32_t max_calls;
};
const ToxAvCodecSettings av_DefaultSettings = {
TypeAudio,
500,
1280,
720,
64000,
20,
48000,
1
};
static MSICSettings msicsettings_cast (const ToxAvCodecSettings* from)
static MSICSettings msicsettings_cast (const ToxAvCSettings* from)
{
MSICSettings csettings;
csettings.call_type = from->call_type;
@ -114,9 +119,9 @@ static MSICSettings msicsettings_cast (const ToxAvCodecSettings* from)
return csettings;
}
static ToxAvCodecSettings toxavcsettings_cast (const MSICSettings* from)
static ToxAvCSettings toxavcsettings_cast (const MSICSettings* from)
{
ToxAvCodecSettings csettings;
ToxAvCSettings csettings;
csettings.call_type = from->call_type;
csettings.video_bitrate = from->video_bitrate;
@ -237,7 +242,7 @@ void toxav_register_video_recv_callback (ToxAv *av, void (*callback)(ToxAv *, in
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_call (ToxAv* av, int32_t* call_index, int user, const ToxAvCodecSettings* csettings, int ringing_seconds )
int toxav_call (ToxAv* av, int32_t* call_index, int user, const ToxAvCSettings* csettings, int ringing_seconds )
{
return msi_invite(av->msi_session, call_index, msicsettings_cast(csettings), ringing_seconds * 1000, user);
}
@ -272,7 +277,7 @@ int toxav_hangup ( ToxAv *av, int32_t call_index )
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_answer ( ToxAv* av, int32_t call_index, const ToxAvCodecSettings* csettings )
int toxav_answer ( ToxAv* av, int32_t call_index, const ToxAvCSettings* csettings )
{
if ( cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -339,7 +344,7 @@ int toxav_cancel ( ToxAv *av, int32_t call_index, int peer_id, const char *reaso
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_change_settings(ToxAv* av, int32_t call_index, const ToxAvCodecSettings* csettings)
int toxav_change_settings(ToxAv* av, int32_t call_index, const ToxAvCSettings* csettings)
{
if ( cii(call_index, av->msi_session) || !av->msi_session->calls[call_index] ) {
return ErrorNoCall;
@ -426,7 +431,7 @@ int toxav_prepare_transmission ( ToxAv* av, int32_t call_index, uint32_t jbuf_ca
goto error;
}
ToxAvCodecSettings csettings = toxavcsettings_cast(&av->msi_session->calls[call_index]->csettings_peer[0]);
ToxAvCSettings csettings = toxavcsettings_cast(&av->msi_session->calls[call_index]->csettings_peer[0]);
LOGGER_DEBUG(
"Type: %u \n"
"Video bitrate: %u \n"
@ -754,7 +759,7 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t
* @retval ToxAvCallType On success.
* @retval ToxAvError On error.
*/
int toxav_get_peer_csettings ( ToxAv *av, int32_t call_index, int peer, ToxAvCodecSettings* dest )
int toxav_get_peer_csettings ( ToxAv *av, int32_t call_index, int peer, ToxAvCSettings* dest )
{
if ( peer < 0 || cii(call_index, av->msi_session) || !av->msi_session->calls[call_index]
|| av->msi_session->calls[call_index]->peer_count <= peer )

View File

@ -129,9 +129,11 @@ typedef struct _ToxAvCodecSettings {
uint16_t audio_frame_duration; /* In ms */
uint32_t audio_sample_rate; /* In Hz */
uint32_t audio_channels;
} ToxAvCodecSettings;
} ToxAvCSettings;
extern const ToxAvCodecSettings av_DefaultSettings;
extern const ToxAvCSettings av_DefaultSettings;
extern const uint32_t av_jbufdc; /* Jitter buffer default capacity */
extern const uint32_t av_VADd; /* VAD default treshold */
/**
* @brief Start new A/V session. There can only be one session at the time. If you register more
@ -193,7 +195,7 @@ void toxav_register_video_recv_callback (ToxAv *av, void (*callback)(ToxAv *, in
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_call(ToxAv* av, int32_t* call_index, int user, const ToxAvCodecSettings* csettings, int ringing_seconds);
int toxav_call(ToxAv* av, int32_t* call_index, int user, const ToxAvCSettings* csettings, int ringing_seconds);
/**
* @brief Hangup active call.
@ -214,7 +216,7 @@ int toxav_hangup(ToxAv *av, int32_t call_index);
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_answer(ToxAv *av, int32_t call_index, const ToxAvCodecSettings* csettings );
int toxav_answer(ToxAv *av, int32_t call_index, const ToxAvCSettings* csettings );
/**
* @brief Reject incomming call.
@ -240,14 +242,14 @@ int toxav_reject(ToxAv *av, int32_t call_index, const char *reason);
int toxav_cancel(ToxAv *av, int32_t call_index, int peer_id, const char *reason);
/**
* @brief Notify peer that we are changing call type
* @brief Notify peer that we are changing call settings
*
* @param av Handler.
* @return int
* @retval 0 Success.
* @retval ToxAvError On error.
*/
int toxav_change_settings(ToxAv *av, int32_t call_index, const ToxAvCodecSettings* csettings);
int toxav_change_settings(ToxAv *av, int32_t call_index, const ToxAvCSettings* csettings);
/**
* @brief Terminate transmission. Note that transmission will be terminated without informing remote peer.
@ -342,7 +344,7 @@ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t *dest, in
* @retval ToxAvCallType On success.
* @retval ToxAvError On error.
*/
int toxav_get_peer_csettings ( ToxAv *av, int32_t call_index, int peer, ToxAvCodecSettings* dest );
int toxav_get_peer_csettings ( ToxAv *av, int32_t call_index, int peer, ToxAvCSettings* dest );
/**
* @brief Get id of peer participating in conversation