summaryrefslogtreecommitdiff
path: root/toxav/av_test.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/av_test.c')
-rw-r--r--toxav/av_test.c66
1 files changed, 34 insertions, 32 deletions
diff --git a/toxav/av_test.c b/toxav/av_test.c
index e24f0a06..d669e380 100644
--- a/toxav/av_test.c
+++ b/toxav/av_test.c
@@ -77,8 +77,8 @@
77#define TEST_REJECT 0 77#define TEST_REJECT 0
78#define TEST_CANCEL 0 78#define TEST_CANCEL 0
79#define TEST_MUTE_UNMUTE 0 79#define TEST_MUTE_UNMUTE 0
80#define TEST_TRANSFER_A 1 80#define TEST_TRANSFER_A 0
81#define TEST_TRANSFER_V 0 81#define TEST_TRANSFER_V 1
82 82
83 83
84typedef struct { 84typedef struct {
@@ -119,8 +119,10 @@ void* pa_write_thread (void* d)
119 pthread_mutex_unlock(cc->arb_mutex); 119 pthread_mutex_unlock(cc->arb_mutex);
120 Pa_WriteStream(adout, f->data, f->size); 120 Pa_WriteStream(adout, f->data, f->size);
121 free(f); 121 free(f);
122 } else 122 } else {
123 pthread_mutex_unlock(cc->arb_mutex); 123 pthread_mutex_unlock(cc->arb_mutex);
124 c_sleep(10);
125 }
124 } 126 }
125} 127}
126 128
@@ -165,9 +167,9 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo
165// printf("Decreasing bitrate to: %d\n", abitrate); 167// printf("Decreasing bitrate to: %d\n", abitrate);
166// toxav_set_audio_bit_rate(av, friend_number, abitrate, 0); 168// toxav_set_audio_bit_rate(av, friend_number, abitrate, 0);
167// 169//
168 } 170 } else if (state & TOXAV_CALL_STATE_INCREASE_VIDEO_BITRATE) {
169 171
170 if (state & TOXAV_CALL_STATE_INCREASE_VIDEO_BITRATE) { 172 } else if (state & TOXAV_CALL_STATE_DECREASE_VIDEO_BITRATE) {
171 173
172 } else { 174 } else {
173 printf("Handling CALL STATE callback: %d\n", state); 175 printf("Handling CALL STATE callback: %d\n", state);
@@ -175,7 +177,8 @@ void t_toxav_call_state_cb(ToxAV *av, uint32_t friend_number, uint32_t state, vo
175} 177}
176void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number, 178void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
177 uint16_t width, uint16_t height, 179 uint16_t width, uint16_t height,
178 uint8_t const *planes[], int32_t const stride[], 180 uint8_t const *y, uint8_t const *u, uint8_t const *v,
181 int32_t ystride, int32_t ustride, int32_t vstride,
179 void *user_data) 182 void *user_data)
180{ 183{
181 uint16_t *img_data = malloc(height * width * 6); 184 uint16_t *img_data = malloc(height * width * 6);
@@ -184,13 +187,13 @@ void t_toxav_receive_video_frame_cb(ToxAV *av, uint32_t friend_number,
184 for (i = 0; i < height; ++i) { 187 for (i = 0; i < height; ++i) {
185 for (j = 0; j < width; ++j) { 188 for (j = 0; j < width; ++j) {
186 uint8_t *point = (void*)img_data + 3 * ((i * width) + j); 189 uint8_t *point = (void*)img_data + 3 * ((i * width) + j);
187 int y = planes[0][(i * stride[0]) + j]; 190 int yx = y[(i * ystride) + j];
188 int u = planes[1][((i / 2) * stride[1]) + (j / 2)]; 191 int ux = u[((i / 2) * ustride) + (j / 2)];
189 int v = planes[2][((i / 2) * stride[2]) + (j / 2)]; 192 int vx = v[((i / 2) * vstride) + (j / 2)];
190 193
191 point[0] = YUV2R(y, u, v); 194 point[0] = YUV2R(yx, ux, vx);
192 point[1] = YUV2G(y, u, v); 195 point[1] = YUV2G(yx, ux, vx);
193 point[2] = YUV2B(y, u, v); 196 point[2] = YUV2B(yx, ux, vx);
194 } 197 }
195 } 198 }
196 199
@@ -211,16 +214,14 @@ void t_toxav_receive_audio_frame_cb(ToxAV *av, uint32_t friend_number,
211 uint32_t sampling_rate, 214 uint32_t sampling_rate,
212 void *user_data) 215 void *user_data)
213{ 216{
214// CallControl* cc = user_data; 217 CallControl* cc = user_data;
215// frame* f = malloc(sizeof(frame) + sample_count * sizeof(int16_t)); 218 frame* f = malloc(sizeof(uint16_t) + sample_count * sizeof(int16_t));
216// memcpy(f->data, pcm, sample_count); 219 memcpy(f->data, pcm, sample_count * sizeof(int16_t));
217// f->size = sample_count/channels; 220 f->size = sample_count/channels;
218// 221
219// pthread_mutex_lock(cc->arb_mutex); 222 pthread_mutex_lock(cc->arb_mutex);
220// free(rb_write(cc->arb, f)); 223 free(rb_write(cc->arb, f));
221// pthread_mutex_unlock(cc->arb_mutex); 224 pthread_mutex_unlock(cc->arb_mutex);
222
223 Pa_WriteStream(adout, pcm, sample_count/channels);
224} 225}
225void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata) 226void t_accept_friend_request_cb(Tox *m, const uint8_t *public_key, const uint8_t *data, size_t length, void *userdata)
226{ 227{
@@ -317,7 +318,7 @@ int iterate_tox(Tox* bootstrap, ToxAV* AliceAV, ToxAV* BobAV)
317 return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV))); 318 return MIN(tox_iteration_interval(toxav_get_tox(AliceAV)), tox_iteration_interval(toxav_get_tox(BobAV)));
318} 319}
319void* iterate_toxav (void * data) 320void* iterate_toxav (void * data)
320{ 321{
321 struct toxav_thread_data* data_cast = data; 322 struct toxav_thread_data* data_cast = data;
322 323
323// cvNamedWindow(vdout, CV_WINDOW_AUTOSIZE); 324// cvNamedWindow(vdout, CV_WINDOW_AUTOSIZE);
@@ -327,9 +328,7 @@ void* iterate_toxav (void * data)
327 toxav_iterate(data_cast->BobAV); 328 toxav_iterate(data_cast->BobAV);
328 int rc = MIN(toxav_iteration_interval(data_cast->AliceAV), toxav_iteration_interval(data_cast->BobAV)); 329 int rc = MIN(toxav_iteration_interval(data_cast->AliceAV), toxav_iteration_interval(data_cast->BobAV));
329 330
330// cvWaitKey(10); 331// cvWaitKey(rc);
331 printf("\rSleeping for: %d ", rc);
332 fflush(stdout);
333 c_sleep(rc); 332 c_sleep(rc);
334 } 333 }
335 334
@@ -751,7 +750,7 @@ int main (int argc, char** argv)
751 AliceCC.arb = rb_new(16); 750 AliceCC.arb = rb_new(16);
752 BobCC.arb = rb_new(16); 751 BobCC.arb = rb_new(16);
753 752
754 AliceCC.abitrate = BobCC.abitrate = 16; 753 AliceCC.abitrate = BobCC.abitrate = 48;
755 754
756 { /* Call */ 755 { /* Call */
757 TOXAV_ERR_CALL rc; 756 TOXAV_ERR_CALL rc;
@@ -803,7 +802,6 @@ int main (int argc, char** argv)
803 pthread_create(&dect, NULL, iterate_toxav, &data); 802 pthread_create(&dect, NULL, iterate_toxav, &data);
804 pthread_detach(dect); 803 pthread_detach(dect);
805 804
806
807 int frame_size = (af_info.samplerate * audio_frame_duration / 1000) * af_info.channels; 805 int frame_size = (af_info.samplerate * audio_frame_duration / 1000) * af_info.channels;
808 806
809 struct PaStreamParameters output; 807 struct PaStreamParameters output;
@@ -819,6 +817,11 @@ int main (int argc, char** argv)
819 err = Pa_StartStream(adout); 817 err = Pa_StartStream(adout);
820 assert(err == paNoError); 818 assert(err == paNoError);
821 819
820 /* Start write thread */
821 pthread_t t;
822 pthread_create(&t, NULL, pa_write_thread, &BobCC);
823 pthread_detach(t);
824
822 printf("Sample rate %d\n", af_info.samplerate); 825 printf("Sample rate %d\n", af_info.samplerate);
823 while ( start_time + expected_time > time(NULL) ) { 826 while ( start_time + expected_time > time(NULL) ) {
824 uint64_t enc_start_time = current_time_monotonic(); 827 uint64_t enc_start_time = current_time_monotonic();
@@ -833,10 +836,9 @@ int main (int argc, char** argv)
833 c_sleep(abs(audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1)); 836 c_sleep(abs(audio_frame_duration - (current_time_monotonic() - enc_start_time) - 1));
834 } 837 }
835 838
836 Pa_StopStream(adout); 839 printf("Played file in: %lu; stopping stream...\n", time(NULL) - start_time);
837
838 printf("Played file in: %lu\n", time(NULL) - start_time);
839 840
841 Pa_StopStream(adout);
840 sf_close(af_handle); 842 sf_close(af_handle);
841 843
842 { /* Hangup */ 844 { /* Hangup */