This commit is contained in:
irungentoo 2015-11-03 13:42:05 -05:00
parent f435e94397
commit 6a494e2cbd
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98
15 changed files with 890 additions and 831 deletions

View File

@ -153,7 +153,8 @@ void test_addto_lists_bad(DHT *dht,
{
// check "bad" clients replacement
int used, test1, test2, test3;
uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES], test_id3[crypto_box_PUBLICKEYBYTES];
uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES],
test_id3[crypto_box_PUBLICKEYBYTES];
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
randombytes(public_key, sizeof(public_key));
@ -196,7 +197,8 @@ void test_addto_lists_possible_bad(DHT *dht,
{
// check "possibly bad" clients replacement
int used, test1, test2, test3;
uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES], test_id3[crypto_box_PUBLICKEYBYTES];
uint8_t public_key[crypto_box_PUBLICKEYBYTES], test_id1[crypto_box_PUBLICKEYBYTES], test_id2[crypto_box_PUBLICKEYBYTES],
test_id3[crypto_box_PUBLICKEYBYTES];
uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
randombytes(public_key, sizeof(public_key));

View File

@ -64,7 +64,7 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool
(void) video_enabled;
printf("Handling CALL callback\n");
((CallControl*)user_data)->incoming = true;
((CallControl *)user_data)->incoming = true;
}
void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
{
@ -72,7 +72,7 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo
(void) friend_number;
printf("Handling CALL STATE callback: %d\n", state);
((CallControl*)user_data)->state = state;
((CallControl *)user_data)->state = state;
}
void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
uint16_t width, uint16_t height,
@ -122,7 +122,7 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t
/**
* Iterate helper
*/
int iterate_tox(Tox* bootstrap, Tox* Alice, Tox* Bob)
int iterate_tox(Tox *bootstrap, Tox *Alice, Tox *Bob)
{
tox_iterate(bootstrap);
tox_iterate(Alice);
@ -135,8 +135,8 @@ int iterate_tox(Tox* bootstrap, Tox* Alice, Tox* Bob)
START_TEST(test_AV_flows)
{
Tox* Alice, *Bob, *bootstrap;
ToxAV* AliceAV, *BobAV;
Tox *Alice, *Bob, *bootstrap;
ToxAV *AliceAV, *BobAV;
CallControl AliceCC, BobCC;

View File

@ -42,10 +42,10 @@ typedef struct {
} CallControl;
typedef struct {
ToxAV* AliceAV;
ToxAV* BobAV;
CallControl* AliceCC;
CallControl* BobCC;
ToxAV *AliceAV;
ToxAV *BobAV;
CallControl *AliceCC;
CallControl *BobCC;
uint32_t friend_number;
} thread_data;
@ -59,12 +59,12 @@ void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool
(void) video_enabled;
printf("Handling CALL callback\n");
((CallControl*)user_data)[friend_number].incoming = true;
((CallControl *)user_data)[friend_number].incoming = true;
}
void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
{
printf("Handling CALL STATE callback: %d %p\n", state, av);
((CallControl*)user_data)[friend_number].state = state;
((CallControl *)user_data)[friend_number].state = state;
}
void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
uint16_t width, uint16_t height,
@ -102,6 +102,7 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
{
(void) userdata;
if (length == 7 && memcmp("gentoo", data, 7) == 0) {
ck_assert(tox_friend_add_norequest(m, public_key, NULL) != (uint32_t) ~0);
}
@ -111,11 +112,11 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t
/**
* Iterate helper
*/
ToxAV* setup_av_instance(Tox* tox, CallControl *CC)
ToxAV *setup_av_instance(Tox *tox, CallControl *CC)
{
TOXAV_ERR_NEW error;
ToxAV* av = toxav_new(tox, &error);
ToxAV *av = toxav_new(tox, &error);
ck_assert(error == TOXAV_ERR_NEW_OK);
toxav_callback_call(av, t_toxav_call_cb, CC);
@ -125,13 +126,13 @@ ToxAV* setup_av_instance(Tox* tox, CallControl *CC)
return av;
}
void* call_thread(void* pd)
void *call_thread(void *pd)
{
ToxAV* AliceAV = ((thread_data*) pd)->AliceAV;
ToxAV* BobAV = ((thread_data*) pd)->BobAV;
CallControl* AliceCC = ((thread_data*) pd)->AliceCC;
CallControl* BobCC = ((thread_data*) pd)->BobCC;
uint32_t friend_number = ((thread_data*) pd)->friend_number;
ToxAV *AliceAV = ((thread_data *) pd)->AliceAV;
ToxAV *BobAV = ((thread_data *) pd)->BobAV;
CallControl *AliceCC = ((thread_data *) pd)->AliceCC;
CallControl *BobCC = ((thread_data *) pd)->BobCC;
uint32_t friend_number = ((thread_data *) pd)->friend_number;
memset(AliceCC, 0, sizeof(CallControl));
@ -163,9 +164,9 @@ void* call_thread(void* pd)
c_sleep(30);
int16_t PCM[960];
uint8_t video_y[800*600];
uint8_t video_u[800*600 / 2];
uint8_t video_v[800*600 / 2];
uint8_t video_y[800 * 600];
uint8_t video_u[800 * 600 / 2];
uint8_t video_v[800 * 600 / 2];
memset(PCM, 0, sizeof(PCM));
memset(video_y, 0, sizeof(video_y));
@ -173,7 +174,8 @@ void* call_thread(void* pd)
memset(video_v, 0, sizeof(video_v));
time_t start_time = time(NULL);
while(time(NULL) - start_time < 4) {
while (time(NULL) - start_time < 4) {
toxav_iterate(AliceAV);
toxav_iterate(BobAV);
@ -204,8 +206,8 @@ void* call_thread(void* pd)
START_TEST(test_AV_three_calls)
{
Tox* Alice, *bootstrap, *Bobs[3];
ToxAV* AliceAV, *BobsAV[3];
Tox *Alice, *bootstrap, *Bobs[3];
ToxAV *AliceAV, *BobsAV[3];
CallControl AliceCC[3], BobsCC[3];
@ -309,6 +311,7 @@ START_TEST(test_AV_three_calls)
(void) pthread_detach(tids[2]);
time_t start_time = time(NULL);
while (time(NULL) - start_time < 5) {
tox_iterate(Alice);
tox_iterate(Bobs[0]);

View File

@ -75,35 +75,36 @@ typedef struct {
bool incoming;
uint32_t state;
pthread_mutex_t arb_mutex[1];
RingBuffer* arb; /* Audio ring buffer */
RingBuffer *arb; /* Audio ring buffer */
} CallControl;
struct toxav_thread_data {
ToxAV* AliceAV;
ToxAV* BobAV;
ToxAV *AliceAV;
ToxAV *BobAV;
int32_t sig;
};
const char* vdout = "AV Test"; /* Video output */
PaStream* adout = NULL; /* Audio output */
const char *vdout = "AV Test"; /* Video output */
PaStream *adout = NULL; /* Audio output */
typedef struct {
uint16_t size;
int16_t data[];
} frame;
void* pa_write_thread (void* d)
void *pa_write_thread (void *d)
{
/* The purpose of this thread is to make sure Pa_WriteStream will not block
* toxav_iterate thread
*/
CallControl* cc = d;
CallControl *cc = d;
while (Pa_IsStreamActive(adout)) {
frame* f;
frame *f;
pthread_mutex_lock(cc->arb_mutex);
if (rb_read(cc->arb, (void**)&f)) {
if (rb_read(cc->arb, (void **)&f)) {
pthread_mutex_unlock(cc->arb_mutex);
Pa_WriteStream(adout, f->data, f->size);
free(f);
@ -120,12 +121,12 @@ void* pa_write_thread (void* d)
void t_toxav_call_cb(ToxAV *av, uint32_t friend_number, bool audio_enabled, bool video_enabled, void *user_data)
{
printf("Handling CALL callback\n");
((CallControl*)user_data)->incoming = true;
((CallControl *)user_data)->incoming = true;
}
void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, void *user_data)
{
printf("Handling CALL STATE callback: %d\n", state);
((CallControl*)user_data)->state = state;
((CallControl *)user_data)->state = state;
}
void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
uint16_t width, uint16_t height,
@ -140,9 +141,10 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
uint16_t *img_data = malloc(height * width * 6);
unsigned long int i, j;
for (i = 0; i < height; ++i) {
for (j = 0; j < width; ++j) {
uint8_t *point = (uint8_t*) img_data + 3 * ((i * width) + j);
uint8_t *point = (uint8_t *) img_data + 3 * ((i * width) + j);
int yx = y[(i * ystride) + j];
int ux = u[((i / 2) * ustride) + (j / 2)];
int vx = v[((i / 2) * vstride) + (j / 2)];
@ -158,8 +160,8 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
CvSize sz = {.height = height, .width = width};
IplImage* header = cvCreateImageHeader(sz, 1, 3);
IplImage* img = cvGetImage(&mat, header);
IplImage *header = cvCreateImageHeader(sz, 1, 3);
IplImage *img = cvGetImage(&mat, header);
cvShowImage(vdout, img);
free(img_data);
}
@ -170,8 +172,8 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
uint32_t sampling_rate,
void *user_data)
{
CallControl* cc = user_data;
frame* f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels);
CallControl *cc = user_data;
frame *f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t) * channels);
memcpy(f->data, pcm, sample_count * sizeof(int16_t) * channels);
f->size = sample_count;
@ -194,10 +196,10 @@ void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t
/**
*/
void initialize_tox(Tox** bootstrap, ToxAV** AliceAV, CallControl* AliceCC, ToxAV** BobAV, CallControl* BobCC)
void initialize_tox(Tox **bootstrap, ToxAV **AliceAV, CallControl *AliceCC, ToxAV **BobAV, CallControl *BobCC)
{
Tox* Alice;
Tox* Bob;
Tox *Alice;
Tox *Bob;
struct Tox_Options opts;
tox_options_default(&opts);
@ -282,7 +284,7 @@ void initialize_tox(Tox** bootstrap, ToxAV** AliceAV, CallControl* AliceCC, ToxA
printf("Created 2 instances of ToxAV\n");
printf("All set after %llu seconds!\n", time(NULL) - cur_time);
}
int iterate_tox(Tox* bootstrap, ToxAV* AliceAV, ToxAV* BobAV)
int iterate_tox(Tox *bootstrap, ToxAV *AliceAV, ToxAV *BobAV)
{
tox_iterate(bootstrap);
tox_iterate(toxav_get_tox(AliceAV));
@ -290,9 +292,9 @@ int iterate_tox(Tox* bootstrap, ToxAV* AliceAV, ToxAV* BobAV)
return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV)));
}
void* iterate_toxav (void * data)
void *iterate_toxav (void *data)
{
struct toxav_thread_data* data_cast = data;
struct toxav_thread_data *data_cast = data;
#if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1
cvNamedWindow(vdout, CV_WINDOW_AUTOSIZE);
#endif
@ -306,6 +308,7 @@ void* iterate_toxav (void * data)
fflush(stdout);
#if defined TEST_TRANSFER_V && TEST_TRANSFER_V == 1
if (!rc)
rc = 1;
@ -324,10 +327,10 @@ void* iterate_toxav (void * data)
pthread_exit(NULL);
}
int send_opencv_img(ToxAV* av, uint32_t friend_number, const IplImage* img)
int send_opencv_img(ToxAV *av, uint32_t friend_number, const IplImage *img)
{
int32_t strides[3] = { 1280, 640, 640 };
uint8_t* planes[3] = {
uint8_t *planes[3] = {
malloc(img->height * img->width),
malloc(img->height * img->width / 4),
malloc(img->height * img->width / 4),
@ -337,6 +340,7 @@ int send_opencv_img(ToxAV* av, uint32_t friend_number, const IplImage* img)
int y_chroma_shift = 1;
int x, y;
for (y = 0; y < img->height; ++y) {
for (x = 0; x < img->width; ++x) {
uint8_t r = img->imageData[(x + y * img->width) * 3 + 0];
@ -344,6 +348,7 @@ int send_opencv_img(ToxAV* av, uint32_t friend_number, const IplImage* img)
uint8_t b = img->imageData[(x + y * img->width) * 3 + 2];
planes[0][x + y * strides[0]] = RGB2Y(r, g, b);
if (!(x % (1 << x_chroma_shift)) && !(y % (1 << y_chroma_shift))) {
const int i = x / (1 << x_chroma_shift);
const int j = y / (1 << y_chroma_shift);
@ -363,15 +368,17 @@ int send_opencv_img(ToxAV* av, uint32_t friend_number, const IplImage* img)
int print_audio_devices()
{
int i = 0;
for (i = 0; i < Pa_GetDeviceCount(); ++i) {
const PaDeviceInfo* info = Pa_GetDeviceInfo(i);
const PaDeviceInfo *info = Pa_GetDeviceInfo(i);
if (info)
printf("%d) %s\n", i, info->name);
}
return 0;
}
int print_help (const char* name)
int print_help (const char *name)
{
printf("Usage: %s -[a:v:o:dh]\n"
"-a <path> audio input file\n"
@ -385,7 +392,7 @@ int print_help (const char* name)
return 0;
}
int main (int argc, char** argv)
int main (int argc, char **argv)
{
freopen("/dev/zero", "w", stderr);
Pa_Initialize();
@ -393,55 +400,72 @@ int main (int argc, char** argv)
struct stat st;
/* AV files for testing */
const char* af_name = NULL;
const char* vf_name = NULL;
const char *af_name = NULL;
const char *vf_name = NULL;
long audio_out_dev_idx = -1;
int32_t audio_frame_duration = 20;
int32_t video_frame_duration = 10;
/* Parse settings */
CHECK_ARG: switch (getopt(argc, argv, "a:b:v:x:o:dh")) {
CHECK_ARG:
switch (getopt(argc, argv, "a:b:v:x:o:dh")) {
case 'a':
af_name = optarg;
goto CHECK_ARG;
case 'b':{
case 'b': {
char *d;
audio_frame_duration = strtol(optarg, &d, 10);
if (*d) {
printf("Invalid value for argument: 'b'");
exit(1);
}
goto CHECK_ARG;
}
case 'v':
vf_name = optarg;
goto CHECK_ARG;
case 'x':{
case 'x': {
char *d;
video_frame_duration = strtol(optarg, &d, 10);
if (*d) {
printf("Invalid value for argument: 'x'");
exit(1);
}
goto CHECK_ARG;
}
case 'o': {
char *d;
audio_out_dev_idx = strtol(optarg, &d, 10);
if (*d) {
printf("Invalid value for argument: 'o'");
exit(1);
}
goto CHECK_ARG;
}
case 'd':
return print_audio_devices();
case 'h':
return print_help(argv[0]);
case '?':
exit(1);
case -1:;
case -1:
;
}
{ /* Check files */
@ -456,14 +480,12 @@ int main (int argc, char** argv)
}
/* Check for files */
if(stat(af_name, &st) != 0 || !S_ISREG(st.st_mode))
{
if (stat(af_name, &st) != 0 || !S_ISREG(st.st_mode)) {
printf("%s doesn't seem to be a regular file!\n", af_name);
exit(1);
}
if(stat(vf_name, &st) != 0 || !S_ISREG(st.st_mode))
{
if (stat(vf_name, &st) != 0 || !S_ISREG(st.st_mode)) {
printf("%s doesn't seem to be a regular file!\n", vf_name);
exit(1);
}
@ -472,7 +494,8 @@ int main (int argc, char** argv)
if (audio_out_dev_idx < 0)
audio_out_dev_idx = Pa_GetDefaultOutputDevice();
const PaDeviceInfo* audio_dev = Pa_GetDeviceInfo(audio_out_dev_idx);
const PaDeviceInfo *audio_dev = Pa_GetDeviceInfo(audio_out_dev_idx);
if (!audio_dev) {
fprintf(stderr, "Device under index: %ld invalid", audio_out_dev_idx);
return 1;
@ -494,7 +517,7 @@ int main (int argc, char** argv)
initialize_tox(&bootstrap, &AliceAV, &AliceCC, &BobAV, &BobCC);
if (TEST_TRANSFER_A) {
SNDFILE* af_handle;
SNDFILE *af_handle;
SF_INFO af_info;
printf("\nTrying audio enc/dec...\n");
@ -536,6 +559,7 @@ int main (int argc, char** argv)
/* Open audio file */
af_handle = sf_open(af_name, SFM_READ, &af_info);
if (af_handle == NULL) {
printf("Failed to open the file.\n");
exit(1);
@ -581,15 +605,20 @@ int main (int argc, char** argv)
pthread_detach(t);
printf("Sample rate %d\n", af_info.samplerate);
while (start_time + expected_time > time(NULL) ) {
uint64_t enc_start_time = current_time_monotonic();
int64_t count = sf_read_short(af_handle, PCM, frame_size);
if (count > 0) {
TOXAV_ERR_SEND_FRAME rc;
if (toxav_audio_send_frame(AliceAV, 0, PCM, count/af_info.channels, af_info.channels, af_info.samplerate, &rc) == false) {
if (toxav_audio_send_frame(AliceAV, 0, PCM, count / af_info.channels, af_info.channels, af_info.samplerate,
&rc) == false) {
printf("Error sending frame of size %ld: %d\n", count, rc);
}
}
iterate_tox(bootstrap, AliceAV, BobAV);
c_sleep(abs(audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1));
}
@ -614,17 +643,19 @@ int main (int argc, char** argv)
/* Stop decode thread */
data.sig = -1;
while(data.sig != 1)
while (data.sig != 1)
pthread_yield();
pthread_mutex_destroy(AliceCC.arb_mutex);
pthread_mutex_destroy(BobCC.arb_mutex);
void* f = NULL;
while(rb_read(AliceCC.arb, &f))
void *f = NULL;
while (rb_read(AliceCC.arb, &f))
free(f);
while(rb_read(BobCC.arb, &f))
while (rb_read(BobCC.arb, &f))
free(f);
printf("Success!");
@ -672,7 +703,8 @@ int main (int argc, char** argv)
pthread_create(&dect, NULL, iterate_toxav, &data);
pthread_detach(dect);
CvCapture* capture = cvCreateFileCapture(vf_name);
CvCapture *capture = cvCreateFileCapture(vf_name);
if (!capture) {
printf("Failed to open video file: %s\n", vf_name);
exit(1);
@ -681,8 +713,10 @@ int main (int argc, char** argv)
// toxav_video_bit_rate_set(AliceAV, 0, 5000, false, NULL);
time_t start_time = time(NULL);
while(start_time + 90 > time(NULL)) {
IplImage* frame = cvQueryFrame(capture );
while (start_time + 90 > time(NULL)) {
IplImage *frame = cvQueryFrame(capture );
if (!frame)
break;
@ -709,15 +743,16 @@ int main (int argc, char** argv)
/* Stop decode thread */
printf("Stopping decode thread\n");
data.sig = -1;
while(data.sig != 1)
while (data.sig != 1)
pthread_yield();
printf("Success!");
}
Tox* Alice = toxav_get_tox(AliceAV);
Tox* Bob = toxav_get_tox(BobAV);
Tox *Alice = toxav_get_tox(AliceAV);
Tox *Bob = toxav_get_tox(BobAV);
toxav_kill(BobAV);
toxav_kill(AliceAV);
tox_kill(Bob);

View File

@ -77,6 +77,7 @@ BWControler *bwc_new(Messenger *m, uint32_t friendnumber,
/* Fill with zeros */
int i = 0;
for (; i < BWC_AVG_PKT_COUNT; i ++)
rb_write(retu->rcvpkt.rb, retu->rcvpkt.rb_s + i);
@ -94,11 +95,11 @@ void bwc_kill(BWControler *bwc)
rb_kill(bwc->rcvpkt.rb);
free(bwc);
}
void bwc_feed_avg(BWControler* bwc, uint32_t bytes)
void bwc_feed_avg(BWControler *bwc, uint32_t bytes)
{
uint32_t *p;
rb_read(bwc->rcvpkt.rb, (void**) &p);
rb_read(bwc->rcvpkt.rb, (void **) &p);
rb_write(bwc->rcvpkt.rb, p);
*p = bytes;
@ -109,11 +110,12 @@ void bwc_add_lost(BWControler *bwc, uint32_t bytes)
return;
if (!bytes) {
uint32_t* t_avg[BWC_AVG_PKT_COUNT], c = 1;
uint32_t *t_avg[BWC_AVG_PKT_COUNT], c = 1;
rb_data(bwc->rcvpkt.rb, (void**) t_avg);
rb_data(bwc->rcvpkt.rb, (void **) t_avg);
int i = 0;
for (; i < BWC_AVG_PKT_COUNT; i ++) {
bytes += *(t_avg[i]);
@ -149,16 +151,14 @@ void send_update(BWControler *bwc)
bwc->cycle.lost /= 10;
bwc->cycle.recv /= 10;
bwc->cycle.lfu = current_time_monotonic();
}
else if (current_time_monotonic() - bwc->cycle.lsu > BWC_SEND_INTERVAL_MS) {
} else if (current_time_monotonic() - bwc->cycle.lsu > BWC_SEND_INTERVAL_MS) {
if (bwc->cycle.lost)
{
if (bwc->cycle.lost) {
LOGGER_DEBUG ("%p Sent update rcv: %u lost: %u",
bwc, bwc->cycle.recv, bwc->cycle.lost);
uint8_t p_msg[sizeof(struct BWCMessage) + 1];
struct BWCMessage* b_msg = (struct BWCMessage*)(p_msg + 1);
struct BWCMessage *b_msg = (struct BWCMessage *)(p_msg + 1);
p_msg[0] = BWC_PACKET_ID;
b_msg->lost = htonl(bwc->cycle.lost);
@ -195,7 +195,7 @@ int on_update (BWControler *bwc, struct BWCMessage *msg)
return 0;
}
int bwc_handle_data(Messenger* m, uint32_t friendnumber, const uint8_t* data, uint16_t length, void* object)
int bwc_handle_data(Messenger *m, uint32_t friendnumber, const uint8_t *data, uint16_t length, void *object)
{
if (length - 1 != sizeof(struct BWCMessage))
return -1;

View File

@ -619,7 +619,7 @@ void on_peer_status(Messenger *m, uint32_t friend_number, uint8_t status, void *
break;
}
}
void handle_init (MSICall* call, const MSIMessage* msg)
void handle_init (MSICall *call, const MSIMessage *msg)
{
assert(call);
LOGGER_DEBUG("Session: %p Handling 'init' friend: %d", call->session, call->friend_number);
@ -630,8 +630,7 @@ void handle_init (MSICall* call, const MSIMessage* msg)
goto FAILURE;
}
switch (call->state)
{
switch (call->state) {
case msi_CallInactive: {
/* Call requested */
call->peer_capabilities = msg->capabilities.value;
@ -814,9 +813,11 @@ void handle_msi_packet (Messenger *m, uint32_t friend_number, const uint8_t *dat
case requ_init:
handle_init(call, &msg);
break;
case requ_push:
handle_push(call, &msg);
break;
case requ_pop:
handle_pop(call, &msg); /* always kills the call */
break;

View File

@ -197,8 +197,9 @@ bool chloss (const RTPSession *session, const struct RTPHeader *header)
session->rsequnum - hosq;
puts ("Lost packet");
while (lost --)
bwc_add_lost(session->bwc ,0);
bwc_add_lost(session->bwc , 0);
return true;
}

View File

@ -441,6 +441,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co
case TOXAV_CALL_CONTROL_CANCEL: {
/* Hang up */
pthread_mutex_lock(call->mutex);
if (msi_hangup(call->msi_call) != 0) {
rc = TOXAV_ERR_CALL_CONTROL_SYNC;
pthread_mutex_unlock(call->mutex);
@ -566,18 +567,22 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
LOGGER_DEBUG("Audio bitrate already set to: %d", audio_bit_rate);
} else if (audio_bit_rate == 0) {
LOGGER_DEBUG("Turned off audio sending");
if (msi_change_capabilities(call->msi_call, call->msi_call->
self_capabilities ^ msi_CapSAudio) != 0) {
pthread_mutex_unlock(av->mutex);
rc = TOXAV_ERR_BIT_RATE_SET_SYNC;
goto END;
}
/* Audio sending is turned off; notify peer */
call->audio_bit_rate = 0;
} else {
pthread_mutex_lock(call->mutex);
if (call->audio_bit_rate == 0) {
LOGGER_DEBUG("Turned on audio sending");
/* The audio has been turned off before this */
if (msi_change_capabilities(call->msi_call, call->
msi_call->self_capabilities | msi_CapSAudio) != 0) {
@ -588,6 +593,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
}
} else
LOGGER_DEBUG("Set new audio bit rate %d", audio_bit_rate);
call->audio_bit_rate = audio_bit_rate;
pthread_mutex_unlock(call->mutex);
}
@ -600,6 +606,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
LOGGER_DEBUG("Video bitrate already set to: %d", video_bit_rate);
} else if (video_bit_rate == 0) {
LOGGER_DEBUG("Turned off video sending");
/* Video sending is turned off; notify peer */
if (msi_change_capabilities(call->msi_call, call->msi_call->
self_capabilities ^ msi_CapSVideo) != 0) {
@ -607,11 +614,14 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
rc = TOXAV_ERR_BIT_RATE_SET_SYNC;
goto END;
}
call->video_bit_rate = 0;
} else {
pthread_mutex_lock(call->mutex);
if (call->video_bit_rate == 0) {
LOGGER_DEBUG("Turned on video sending");
/* The video has been turned off before this */
if (msi_change_capabilities(call->msi_call, call->
msi_call->self_capabilities | msi_CapSVideo) != 0) {
@ -622,6 +632,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
}
} else
LOGGER_DEBUG("Set new video bit rate %d", video_bit_rate);
call->video_bit_rate = video_bit_rate;
pthread_mutex_unlock(call->mutex);
}
@ -629,6 +640,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat
pthread_mutex_unlock(av->mutex);
END:
if (error)
*error = rc;
@ -719,6 +731,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc
pthread_mutex_unlock(call->mutex_audio);
END:
if (error)
*error = rc;
@ -817,6 +830,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u
pthread_mutex_unlock(call->mutex_video);
END:
if (error)
*error = rc;
@ -843,7 +857,7 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb
* :: Internal
*
******************************************************************************/
void callback_bwc(BWControler* bwc, uint32_t friend_number, float loss, void* user_data)
void callback_bwc(BWControler *bwc, uint32_t friend_number, float loss, void *user_data)
{
/* Callback which is called when the internal measure mechanism reported packet loss.
* We report suggested lowered bitrate to an app. If app is sending both audio and video,
@ -852,15 +866,16 @@ void callback_bwc(BWControler* bwc, uint32_t friend_number, float loss, void* us
* The application may choose to disable video totally if the stream is too bad.
*/
ToxAVCall* call = user_data;
ToxAVCall *call = user_data;
assert(call);
LOGGER_DEBUG("Reported loss of %f%%", loss*100);
LOGGER_DEBUG("Reported loss of %f%%", loss * 100);
if (loss < .01f)
return;
pthread_mutex_lock(call->av->mutex);
if (!call->av->bcb.first) {
pthread_mutex_unlock(call->av->mutex);
LOGGER_WARNING("No callback to report loss on");

View File

@ -341,7 +341,8 @@ typedef enum TOXAV_ERR_ANSWER {
* @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
* video sending.
*/
bool toxav_answer(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, TOXAV_ERR_ANSWER *error);
bool toxav_answer(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate,
TOXAV_ERR_ANSWER *error);
/*******************************************************************************
@ -474,7 +475,8 @@ typedef enum TOXAV_ERR_CALL_CONTROL {
*
* @return true on success.
*/
bool toxav_call_control(ToxAV *toxAV, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL *error);
bool toxav_call_control(ToxAV *toxAV, uint32_t friend_number, TOXAV_CALL_CONTROL control,
TOXAV_ERR_CALL_CONTROL *error);
/*******************************************************************************
@ -533,7 +535,8 @@ bool toxav_bit_rate_set(ToxAV *toxAV, uint32_t friend_number, int32_t audio_bit_
* @param audio_bit_rate Suggested maximum audio bit rate in Kb/sec.
* @param video_bit_rate Suggested maximum video bit rate in Kb/sec.
*/
typedef void toxav_bit_rate_status_cb(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, void *user_data);
typedef void toxav_bit_rate_status_cb(ToxAV *toxAV, uint32_t friend_number, uint32_t audio_bit_rate,
uint32_t video_bit_rate, void *user_data);
/**
* Set the callback for the `bit_rate_status` event. Pass NULL to unset.
@ -700,7 +703,7 @@ void toxav_callback_video_receive_frame(ToxAV *toxAV, toxav_video_receive_frame_
*
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
*/
int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void*, int, int, const int16_t *, unsigned int, uint8_t,
int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t,
unsigned int, void *), void *userdata);
/* Join a AV group (you need to have been invited first.)
@ -714,7 +717,7 @@ int toxav_add_av_groupchat(Tox *tox, void (*audio_callback)(void*, int, int, con
* Note that total size of pcm in bytes is equal to (samples * channels * sizeof(int16_t)).
*/
int toxav_join_av_groupchat(Tox *tox, int32_t friendnumber, const uint8_t *data, uint16_t length,
void (*audio_callback)(void*, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata);
void (*audio_callback)(void *, int, int, const int16_t *, unsigned int, uint8_t, unsigned int, void *), void *userdata);
/* Send audio to the group chat.
*

View File

@ -207,7 +207,7 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
return 0;
}
int vc_reconfigure_encoder(VCSession* vc, uint32_t bit_rate, uint16_t width, uint16_t height)
int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height)
{
if (!vc)
return -1;
@ -218,8 +218,7 @@ int vc_reconfigure_encoder(VCSession* vc, uint32_t bit_rate, uint16_t width, uin
if (cfg.rc_target_bitrate == bit_rate && cfg.g_w == width && cfg.g_h == height)
return 0; /* Nothing changed */
if (cfg.g_w == width && cfg.g_h == height)
{
if (cfg.g_w == width && cfg.g_h == height) {
/* Only bit rate changed */
cfg.rc_target_bitrate = bit_rate;
@ -229,9 +228,7 @@ int vc_reconfigure_encoder(VCSession* vc, uint32_t bit_rate, uint16_t width, uin
LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc));
return -1;
}
}
else
{
} else {
/* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support
* reconfiguring encoder to use resolutions greater than initially set.
*/

View File

@ -58,7 +58,7 @@ typedef struct VCSession_s {
pthread_mutex_t queue_mutex[1];
} VCSession;
VCSession *vc_new(ToxAV* av, uint32_t friend_number, toxav_video_receive_frame_cb* cb, void* cb_data);
VCSession *vc_new(ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data);
void vc_kill(VCSession *vc);
void vc_iterate(VCSession *vc);
int vc_queue_message(void *vcp, struct RTPMessage *msg);

View File

@ -209,9 +209,10 @@ bool rb_empty(const RingBuffer *b)
{
return b->end == b->start;
}
void* rb_write(RingBuffer *b, void *p)
void *rb_write(RingBuffer *b, void *p)
{
void* rc = NULL;
void *rc = NULL;
if ((b->end + 1) % b->size == b->start) /* full */
rc = b->data[b->start];
@ -256,7 +257,7 @@ void rb_kill(RingBuffer *b)
free(b);
}
}
uint16_t rb_size(const RingBuffer* b)
uint16_t rb_size(const RingBuffer *b)
{
if (rb_empty(b))
return 0;
@ -266,9 +267,10 @@ uint16_t rb_size(const RingBuffer* b)
b->end - b->start :
(b->size - b->start) + b->end;
}
uint16_t rb_data(const RingBuffer* b, void** dest)
uint16_t rb_data(const RingBuffer *b, void **dest)
{
uint16_t i = 0;
for (; i < rb_size(b); i++)
dest[i] = b->data[(b->start + i) % b->size];

View File

@ -62,11 +62,11 @@ int create_recursive_mutex(pthread_mutex_t *mutex);
typedef struct RingBuffer RingBuffer;
bool rb_full(const RingBuffer *b);
bool rb_empty(const RingBuffer *b);
void* rb_write(RingBuffer* b, void* p);
bool rb_read(RingBuffer* b, void** p);
void *rb_write(RingBuffer *b, void *p);
bool rb_read(RingBuffer *b, void **p);
RingBuffer *rb_new(int size);
void rb_kill(RingBuffer *b);
uint16_t rb_size(const RingBuffer *b);
uint16_t rb_data(const RingBuffer* b, void** dest);
uint16_t rb_data(const RingBuffer *b, void **dest);
#endif /* __UTIL_H__ */