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 // check "bad" clients replacement
int used, test1, test2, test3; 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; uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
randombytes(public_key, sizeof(public_key)); randombytes(public_key, sizeof(public_key));
@ -196,7 +197,8 @@ void test_addto_lists_possible_bad(DHT *dht,
{ {
// check "possibly bad" clients replacement // check "possibly bad" clients replacement
int used, test1, test2, test3; 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; uint8_t ipv6 = ip_port->ip.family == AF_INET6 ? 1 : 0;
randombytes(public_key, sizeof(public_key)); 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; (void) video_enabled;
printf("Handling CALL callback\n"); 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) 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; (void) friend_number;
printf("Handling CALL STATE callback: %d\n", state); 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, void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
uint16_t width, uint16_t height, 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 * 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(bootstrap);
tox_iterate(Alice); tox_iterate(Alice);
@ -135,8 +135,8 @@ int iterate_tox(Tox* bootstrap, Tox* Alice, Tox* Bob)
START_TEST(test_AV_flows) START_TEST(test_AV_flows)
{ {
Tox* Alice, *Bob, *bootstrap; Tox *Alice, *Bob, *bootstrap;
ToxAV* AliceAV, *BobAV; ToxAV *AliceAV, *BobAV;
CallControl AliceCC, BobCC; CallControl AliceCC, BobCC;

View File

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

View File

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

View File

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

View File

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

View File

@ -197,8 +197,9 @@ bool chloss (const RTPSession *session, const struct RTPHeader *header)
session->rsequnum - hosq; session->rsequnum - hosq;
puts ("Lost packet"); puts ("Lost packet");
while (lost --) while (lost --)
bwc_add_lost(session->bwc ,0); bwc_add_lost(session->bwc , 0);
return true; 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: { case TOXAV_CALL_CONTROL_CANCEL: {
/* Hang up */ /* Hang up */
pthread_mutex_lock(call->mutex); pthread_mutex_lock(call->mutex);
if (msi_hangup(call->msi_call) != 0) { if (msi_hangup(call->msi_call) != 0) {
rc = TOXAV_ERR_CALL_CONTROL_SYNC; rc = TOXAV_ERR_CALL_CONTROL_SYNC;
pthread_mutex_unlock(call->mutex); 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); LOGGER_DEBUG("Audio bitrate already set to: %d", audio_bit_rate);
} else if (audio_bit_rate == 0) { } else if (audio_bit_rate == 0) {
LOGGER_DEBUG("Turned off audio sending"); LOGGER_DEBUG("Turned off audio sending");
if (msi_change_capabilities(call->msi_call, call->msi_call-> if (msi_change_capabilities(call->msi_call, call->msi_call->
self_capabilities ^ msi_CapSAudio) != 0) { self_capabilities ^ msi_CapSAudio) != 0) {
pthread_mutex_unlock(av->mutex); pthread_mutex_unlock(av->mutex);
rc = TOXAV_ERR_BIT_RATE_SET_SYNC; rc = TOXAV_ERR_BIT_RATE_SET_SYNC;
goto END; goto END;
} }
/* Audio sending is turned off; notify peer */ /* Audio sending is turned off; notify peer */
call->audio_bit_rate = 0; call->audio_bit_rate = 0;
} else { } else {
pthread_mutex_lock(call->mutex); pthread_mutex_lock(call->mutex);
if (call->audio_bit_rate == 0) { if (call->audio_bit_rate == 0) {
LOGGER_DEBUG("Turned on audio sending"); LOGGER_DEBUG("Turned on audio sending");
/* The audio has been turned off before this */ /* The audio has been turned off before this */
if (msi_change_capabilities(call->msi_call, call-> if (msi_change_capabilities(call->msi_call, call->
msi_call->self_capabilities | msi_CapSAudio) != 0) { 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 } else
LOGGER_DEBUG("Set new audio bit rate %d", audio_bit_rate); LOGGER_DEBUG("Set new audio bit rate %d", audio_bit_rate);
call->audio_bit_rate = audio_bit_rate; call->audio_bit_rate = audio_bit_rate;
pthread_mutex_unlock(call->mutex); 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); LOGGER_DEBUG("Video bitrate already set to: %d", video_bit_rate);
} else if (video_bit_rate == 0) { } else if (video_bit_rate == 0) {
LOGGER_DEBUG("Turned off video sending"); LOGGER_DEBUG("Turned off video sending");
/* Video sending is turned off; notify peer */ /* Video sending is turned off; notify peer */
if (msi_change_capabilities(call->msi_call, call->msi_call-> if (msi_change_capabilities(call->msi_call, call->msi_call->
self_capabilities ^ msi_CapSVideo) != 0) { 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; rc = TOXAV_ERR_BIT_RATE_SET_SYNC;
goto END; goto END;
} }
call->video_bit_rate = 0; call->video_bit_rate = 0;
} else { } else {
pthread_mutex_lock(call->mutex); pthread_mutex_lock(call->mutex);
if (call->video_bit_rate == 0) { if (call->video_bit_rate == 0) {
LOGGER_DEBUG("Turned on video sending"); LOGGER_DEBUG("Turned on video sending");
/* The video has been turned off before this */ /* The video has been turned off before this */
if (msi_change_capabilities(call->msi_call, call-> if (msi_change_capabilities(call->msi_call, call->
msi_call->self_capabilities | msi_CapSVideo) != 0) { 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 } else
LOGGER_DEBUG("Set new video bit rate %d", video_bit_rate); LOGGER_DEBUG("Set new video bit rate %d", video_bit_rate);
call->video_bit_rate = video_bit_rate; call->video_bit_rate = video_bit_rate;
pthread_mutex_unlock(call->mutex); 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); pthread_mutex_unlock(av->mutex);
END: END:
if (error) if (error)
*error = rc; *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); pthread_mutex_unlock(call->mutex_audio);
END: END:
if (error) if (error)
*error = rc; *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); pthread_mutex_unlock(call->mutex_video);
END: END:
if (error) if (error)
*error = rc; *error = rc;
@ -843,7 +857,7 @@ void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb
* :: Internal * :: 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. /* 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, * 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. * The application may choose to disable video totally if the stream is too bad.
*/ */
ToxAVCall* call = user_data; ToxAVCall *call = user_data;
assert(call); assert(call);
LOGGER_DEBUG("Reported loss of %f%%", loss*100); LOGGER_DEBUG("Reported loss of %f%%", loss * 100);
if (loss < .01f) if (loss < .01f)
return; return;
pthread_mutex_lock(call->av->mutex); pthread_mutex_lock(call->av->mutex);
if (!call->av->bcb.first) { if (!call->av->bcb.first) {
pthread_mutex_unlock(call->av->mutex); pthread_mutex_unlock(call->av->mutex);
LOGGER_WARNING("No callback to report loss on"); 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 * @param video_bit_rate Video bit rate in Kb/sec. Set this to 0 to disable
* video sending. * 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. * @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 audio_bit_rate Suggested maximum audio bit rate in Kb/sec.
* @param video_bit_rate Suggested maximum video 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. * 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)). * 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); unsigned int, void *), void *userdata);
/* Join a AV group (you need to have been invited first.) /* 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)). * 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, 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. /* Send audio to the group chat.
* *

View File

@ -207,7 +207,7 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
return 0; 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) if (!vc)
return -1; 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) if (cfg.rc_target_bitrate == bit_rate && cfg.g_w == width && cfg.g_h == height)
return 0; /* Nothing changed */ 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 */ /* Only bit rate changed */
cfg.rc_target_bitrate = bit_rate; 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)); LOGGER_ERROR("Failed to set encoder control setting: %s", vpx_codec_err_to_string(rc));
return -1; return -1;
} }
} } else {
else
{
/* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support /* Resolution is changed, must reinitialize encoder since libvpx v1.4 doesn't support
* reconfiguring encoder to use resolutions greater than initially set. * 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]; pthread_mutex_t queue_mutex[1];
} VCSession; } 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_kill(VCSession *vc);
void vc_iterate(VCSession *vc); void vc_iterate(VCSession *vc);
int vc_queue_message(void *vcp, struct RTPMessage *msg); 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; 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 */ if ((b->end + 1) % b->size == b->start) /* full */
rc = b->data[b->start]; rc = b->data[b->start];
@ -256,7 +257,7 @@ void rb_kill(RingBuffer *b)
free(b); free(b);
} }
} }
uint16_t rb_size(const RingBuffer* b) uint16_t rb_size(const RingBuffer *b)
{ {
if (rb_empty(b)) if (rb_empty(b))
return 0; return 0;
@ -266,9 +267,10 @@ uint16_t rb_size(const RingBuffer* b)
b->end - b->start : b->end - b->start :
(b->size - b->start) + b->end; (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; uint16_t i = 0;
for (; i < rb_size(b); i++) for (; i < rb_size(b); i++)
dest[i] = b->data[(b->start + i) % b->size]; 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; typedef struct RingBuffer RingBuffer;
bool rb_full(const RingBuffer *b); bool rb_full(const RingBuffer *b);
bool rb_empty(const RingBuffer *b); bool rb_empty(const RingBuffer *b);
void* rb_write(RingBuffer* b, void* p); void *rb_write(RingBuffer *b, void *p);
bool rb_read(RingBuffer* b, void** p); bool rb_read(RingBuffer *b, void **p);
RingBuffer *rb_new(int size); RingBuffer *rb_new(int size);
void rb_kill(RingBuffer *b); void rb_kill(RingBuffer *b);
uint16_t rb_size(const 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__ */ #endif /* __UTIL_H__ */