summaryrefslogtreecommitdiff
path: root/toxav/toxav.c
diff options
context:
space:
mode:
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r--toxav/toxav.c371
1 files changed, 182 insertions, 189 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 6f712af9..5cb614d4 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -23,7 +23,8 @@
23#include "config.h" 23#include "config.h"
24#endif /* HAVE_CONFIG_H */ 24#endif /* HAVE_CONFIG_H */
25 25
26#include "msi.h" /* Includes codec.h, rtp.h and toxav.h */ 26#include "msi.h"
27#include "rtp.h"
27 28
28#include "../toxcore/Messenger.h" 29#include "../toxcore/Messenger.h"
29#include "../toxcore/logger.h" 30#include "../toxcore/logger.h"
@@ -35,20 +36,17 @@
35 36
36#define MAX_ENCODE_TIME_US ((1000 / 24) * 1000) 37#define MAX_ENCODE_TIME_US ((1000 / 24) * 1000)
37 38
38enum {
39 audio_index,
40 video_index,
41};
42 39
43typedef struct ToxAVCall_s { 40typedef struct ToxAVCall_s {
44 ToxAV* av; 41 ToxAV* av;
45 RTPSession *rtps[2]; /* Audio is first and video is second */
46 CSession *cs;
47 42
48 pthread_mutex_t mutex_audio_sending[1]; 43 pthread_mutex_t mutex_audio[1];
49 pthread_mutex_t mutex_video_sending[1]; 44 PAIR(RTPSession *, ACSession *) audio;
50 /* Only audio or video can be decoded at the time */ 45
51 pthread_mutex_t mutex_decoding[1]; 46 pthread_mutex_t mutex_video[1];
47 PAIR(RTPSession *, VCSession *) video;
48
49 pthread_mutex_t mutex[1];
52 50
53 bool active; 51 bool active;
54 MSICall* msi_call; 52 MSICall* msi_call;
@@ -57,8 +55,8 @@ typedef struct ToxAVCall_s {
57 uint32_t audio_bit_rate; /* Sending audio bitrate */ 55 uint32_t audio_bit_rate; /* Sending audio bitrate */
58 uint32_t video_bit_rate; /* Sending video bitrate */ 56 uint32_t video_bit_rate; /* Sending video bitrate */
59 57
60 uint8_t last_self_capabilities; 58 /** Required for monitoring */
61 uint8_t last_peer_capabilities; 59 uint8_t previous_self_capabilities;
62 60
63 /** Quality control */ 61 /** Quality control */
64 uint64_t time_audio_good; 62 uint64_t time_audio_good;
@@ -181,7 +179,7 @@ void toxav_kill(ToxAV* av)
181{ 179{
182 if (av == NULL) 180 if (av == NULL)
183 return; 181 return;
184 LOGGED_LOCK(av->mutex); 182 pthread_mutex_lock(av->mutex);
185 183
186 msi_kill(av->msi); 184 msi_kill(av->msi);
187 185
@@ -194,7 +192,7 @@ void toxav_kill(ToxAV* av)
194 } 192 }
195 } 193 }
196 194
197 LOGGED_UNLOCK(av->mutex); 195 pthread_mutex_unlock(av->mutex);
198 pthread_mutex_destroy(av->mutex); 196 pthread_mutex_destroy(av->mutex);
199 free(av); 197 free(av);
200} 198}
@@ -212,9 +210,9 @@ uint32_t toxav_iteration_interval(const ToxAV* av)
212 210
213void toxav_iterate(ToxAV* av) 211void toxav_iterate(ToxAV* av)
214{ 212{
215 LOGGED_LOCK(av->mutex); 213 pthread_mutex_lock(av->mutex);
216 if (av->calls == NULL) { 214 if (av->calls == NULL) {
217 LOGGED_UNLOCK(av->mutex); 215 pthread_mutex_unlock(av->mutex);
218 return; 216 return;
219 } 217 }
220 218
@@ -224,30 +222,36 @@ void toxav_iterate(ToxAV* av)
224 ToxAVCall* i = av->calls[av->calls_head]; 222 ToxAVCall* i = av->calls[av->calls_head];
225 for (; i; i = i->next) { 223 for (; i; i = i->next) {
226 if (i->active) { 224 if (i->active) {
227 LOGGED_LOCK(i->mutex_decoding); 225 pthread_mutex_lock(i->mutex);
228 LOGGED_UNLOCK(av->mutex); 226 pthread_mutex_unlock(av->mutex);
227
228 rtp_do(i->audio.first);
229 ac_do(i->audio.second);
230
231 rtp_do(i->video.first);
232 vc_do(i->video.second);
229 233
230 cs_do(i->cs);
231 rtp_do(i->rtps[audio_index]);
232 rtp_do(i->rtps[video_index]);
233 qc_do(i); 234 qc_do(i);
234 235
235 if (i->last_self_capabilities & msi_CapRAudio) /* Receiving audio */ 236 if (i->msi_call->self_capabilities & msi_CapRAudio &&
236 rc = MIN(i->cs->last_packet_frame_duration, rc); 237 i->msi_call->peer_capabilities & msi_CapSAudio)
237 if (i->last_self_capabilities & msi_CapRVideo) /* Receiving video */ 238 rc = MIN(i->audio.second->last_packet_frame_duration, rc);
238 rc = MIN(i->cs->lcfd, rc); /* TODO handle on/off */ 239
240 if (i->msi_call->self_capabilities & msi_CapRVideo &&
241 i->msi_call->peer_capabilities & msi_CapSVideo)
242 rc = MIN(i->video.second->lcfd, rc);
239 243
240 uint32_t fid = i->friend_id; 244 uint32_t fid = i->friend_id;
241 245
242 LOGGED_UNLOCK(i->mutex_decoding); 246 pthread_mutex_unlock(i->mutex);
243 LOGGED_LOCK(av->mutex); 247 pthread_mutex_lock(av->mutex);
244 248
245 /* In case this call is popped from container stop iteration */ 249 /* In case this call is popped from container stop iteration */
246 if (call_get(av, fid) != i) 250 if (call_get(av, fid) != i)
247 break; 251 break;
248 } 252 }
249 } 253 }
250 LOGGED_UNLOCK(av->mutex); 254 pthread_mutex_unlock(av->mutex);
251 255
252 av->interval = rc < av->dmssa ? 0 : (rc - av->dmssa); 256 av->interval = rc < av->dmssa ? 0 : (rc - av->dmssa);
253 av->dmsst += current_time_monotonic() - start; 257 av->dmsst += current_time_monotonic() - start;
@@ -261,46 +265,46 @@ void toxav_iterate(ToxAV* av)
261 265
262bool toxav_call(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, TOXAV_ERR_CALL* error) 266bool toxav_call(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, TOXAV_ERR_CALL* error)
263{ 267{
264 LOGGED_LOCK(av->mutex); 268 pthread_mutex_lock(av->mutex);
265 ToxAVCall* call = call_new(av, friend_number, error); 269 ToxAVCall* call = call_new(av, friend_number, error);
266 if (call == NULL) { 270 if (call == NULL) {
267 LOGGED_UNLOCK(av->mutex); 271 pthread_mutex_unlock(av->mutex);
268 return false; 272 return false;
269 } 273 }
270 274
271 call->audio_bit_rate = audio_bit_rate; 275 call->audio_bit_rate = audio_bit_rate;
272 call->video_bit_rate = video_bit_rate; 276 call->video_bit_rate = video_bit_rate;
273 277
274 call->last_self_capabilities = msi_CapRAudio | msi_CapRVideo; 278 call->previous_self_capabilities = msi_CapRAudio | msi_CapRVideo;
275 279
276 call->last_self_capabilities |= audio_bit_rate > 0 ? msi_CapSAudio : 0; 280 call->previous_self_capabilities |= audio_bit_rate > 0 ? msi_CapSAudio : 0;
277 call->last_self_capabilities |= video_bit_rate > 0 ? msi_CapSVideo : 0; 281 call->previous_self_capabilities |= video_bit_rate > 0 ? msi_CapSVideo : 0;
278 282
279 if (msi_invite(av->msi, &call->msi_call, friend_number, call->last_self_capabilities) != 0) { 283 if (msi_invite(av->msi, &call->msi_call, friend_number, call->previous_self_capabilities) != 0) {
280 call_remove(call); 284 call_remove(call);
281 if (error) 285 if (error)
282 *error = TOXAV_ERR_CALL_MALLOC; 286 *error = TOXAV_ERR_CALL_MALLOC;
283 LOGGED_UNLOCK(av->mutex); 287 pthread_mutex_unlock(av->mutex);
284 return false; 288 return false;
285 } 289 }
286 290
287 call->msi_call->av_call = call; 291 call->msi_call->av_call = call;
288 LOGGED_UNLOCK(av->mutex); 292 pthread_mutex_unlock(av->mutex);
289 293
290 return true; 294 return true;
291} 295}
292 296
293void toxav_callback_call(ToxAV* av, toxav_call_cb* function, void* user_data) 297void toxav_callback_call(ToxAV* av, toxav_call_cb* function, void* user_data)
294{ 298{
295 LOGGED_LOCK(av->mutex); 299 pthread_mutex_lock(av->mutex);
296 av->ccb.first = function; 300 av->ccb.first = function;
297 av->ccb.second = user_data; 301 av->ccb.second = user_data;
298 LOGGED_UNLOCK(av->mutex); 302 pthread_mutex_unlock(av->mutex);
299} 303}
300 304
301bool toxav_answer(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, TOXAV_ERR_ANSWER* error) 305bool toxav_answer(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, TOXAV_ERR_ANSWER* error)
302{ 306{
303 LOGGED_LOCK(av->mutex); 307 pthread_mutex_lock(av->mutex);
304 308
305 TOXAV_ERR_ANSWER rc = TOXAV_ERR_ANSWER_OK; 309 TOXAV_ERR_ANSWER rc = TOXAV_ERR_ANSWER_OK;
306 if (m_friend_exists(av->m, friend_number) == 0) { 310 if (m_friend_exists(av->m, friend_number) == 0) {
@@ -329,17 +333,17 @@ bool toxav_answer(ToxAV* av, uint32_t friend_number, uint32_t audio_bit_rate, ui
329 call->audio_bit_rate = audio_bit_rate; 333 call->audio_bit_rate = audio_bit_rate;
330 call->video_bit_rate = video_bit_rate; 334 call->video_bit_rate = video_bit_rate;
331 335
332 call->last_self_capabilities = msi_CapRAudio | msi_CapRVideo; 336 call->previous_self_capabilities = msi_CapRAudio | msi_CapRVideo;
333 337
334 call->last_self_capabilities |= audio_bit_rate > 0 ? msi_CapSAudio : 0; 338 call->previous_self_capabilities |= audio_bit_rate > 0 ? msi_CapSAudio : 0;
335 call->last_self_capabilities |= video_bit_rate > 0 ? msi_CapSVideo : 0; 339 call->previous_self_capabilities |= video_bit_rate > 0 ? msi_CapSVideo : 0;
336 340
337 if (msi_answer(call->msi_call, call->last_self_capabilities) != 0) 341 if (msi_answer(call->msi_call, call->previous_self_capabilities) != 0)
338 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING; /* the only reason for msi_answer to fail */ 342 rc = TOXAV_ERR_ANSWER_FRIEND_NOT_CALLING; /* the only reason for msi_answer to fail */
339 343
340 344
341END: 345END:
342 LOGGED_UNLOCK(av->mutex); 346 pthread_mutex_unlock(av->mutex);
343 347
344 if (error) 348 if (error)
345 *error = rc; 349 *error = rc;
@@ -349,15 +353,15 @@ END:
349 353
350void toxav_callback_call_state(ToxAV* av, toxav_call_state_cb* function, void* user_data) 354void toxav_callback_call_state(ToxAV* av, toxav_call_state_cb* function, void* user_data)
351{ 355{
352 LOGGED_LOCK(av->mutex); 356 pthread_mutex_lock(av->mutex);
353 av->scb.first = function; 357 av->scb.first = function;
354 av->scb.second = user_data; 358 av->scb.second = user_data;
355 LOGGED_UNLOCK(av->mutex); 359 pthread_mutex_unlock(av->mutex);
356} 360}
357 361
358bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL* error) 362bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL* error)
359{ 363{
360 LOGGED_LOCK(av->mutex); 364 pthread_mutex_lock(av->mutex);
361 TOXAV_ERR_CALL_CONTROL rc = TOXAV_ERR_CALL_CONTROL_OK; 365 TOXAV_ERR_CALL_CONTROL rc = TOXAV_ERR_CALL_CONTROL_OK;
362 366
363 if (m_friend_exists(av->m, friend_number) == 0) { 367 if (m_friend_exists(av->m, friend_number) == 0) {
@@ -381,18 +385,18 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
381 385
382 /* Only act if paused and had media transfer active before */ 386 /* Only act if paused and had media transfer active before */
383 if (call->msi_call->self_capabilities == 0 && 387 if (call->msi_call->self_capabilities == 0 &&
384 call->last_self_capabilities ) { 388 call->previous_self_capabilities ) {
385 389
386 if (msi_change_capabilities(call->msi_call, 390 if (msi_change_capabilities(call->msi_call,
387 call->last_self_capabilities) == -1) { 391 call->previous_self_capabilities) == -1) {
388 /* The only reason for this function to fail is invalid state 392 /* The only reason for this function to fail is invalid state
389 * ( not active ) */ 393 * ( not active ) */
390 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL; 394 rc = TOXAV_ERR_CALL_CONTROL_FRIEND_NOT_IN_CALL;
391 goto END; 395 goto END;
392 } 396 }
393 397
394 rtp_start_receiving(call->rtps[audio_index]); 398 rtp_start_receiving(call->audio.first);
395 rtp_start_receiving(call->rtps[video_index]); 399 rtp_start_receiving(call->video.first);
396 } 400 }
397 } break; 401 } break;
398 402
@@ -404,7 +408,7 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
404 408
405 /* Only act if not already paused */ 409 /* Only act if not already paused */
406 if (call->msi_call->self_capabilities) { 410 if (call->msi_call->self_capabilities) {
407 call->last_self_capabilities = call->msi_call->self_capabilities; 411 call->previous_self_capabilities = call->msi_call->self_capabilities;
408 412
409 if (msi_change_capabilities(call->msi_call, 0) == -1 ) { 413 if (msi_change_capabilities(call->msi_call, 0) == -1 ) {
410 /* The only reason for this function to fail is invalid state 414 /* The only reason for this function to fail is invalid state
@@ -413,8 +417,8 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
413 goto END; 417 goto END;
414 } 418 }
415 419
416 rtp_stop_receiving(call->rtps[audio_index]); 420 rtp_stop_receiving(call->audio.first);
417 rtp_stop_receiving(call->rtps[video_index]); 421 rtp_stop_receiving(call->video.first);
418 } 422 }
419 } break; 423 } break;
420 424
@@ -442,7 +446,7 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
442 goto END; 446 goto END;
443 } 447 }
444 448
445 rtp_stop_receiving(call->rtps[audio_index]); 449 rtp_stop_receiving(call->audio.first);
446 } else { 450 } else {
447 /* This call was already muted so notify the friend that he can 451 /* This call was already muted so notify the friend that he can
448 * start sending audio again 452 * start sending audio again
@@ -455,7 +459,7 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
455 goto END; 459 goto END;
456 } 460 }
457 461
458 rtp_start_receiving(call->rtps[audio_index]); 462 rtp_start_receiving(call->audio.first);
459 } 463 }
460 } break; 464 } break;
461 465
@@ -474,7 +478,7 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
474 goto END; 478 goto END;
475 } 479 }
476 480
477 rtp_stop_receiving(call->rtps[video_index]); 481 rtp_stop_receiving(call->video.first);
478 } else { 482 } else {
479 /* This call was already muted so notify the friend that he can 483 /* This call was already muted so notify the friend that he can
480 * start sending video again 484 * start sending video again
@@ -487,13 +491,13 @@ bool toxav_call_control(ToxAV* av, uint32_t friend_number, TOXAV_CALL_CONTROL co
487 goto END; 491 goto END;
488 } 492 }
489 493
490 rtp_start_receiving(call->rtps[video_index]); 494 rtp_start_receiving(call->video.first);
491 } 495 }
492 } break; 496 } break;
493 } 497 }
494 498
495END: 499END:
496 LOGGED_UNLOCK(av->mutex); 500 pthread_mutex_unlock(av->mutex);
497 501
498 if (error) 502 if (error)
499 *error = rc; 503 *error = rc;
@@ -516,19 +520,19 @@ bool toxav_set_audio_bit_rate(ToxAV* av, uint32_t friend_number, uint32_t audio_
516 goto END; 520 goto END;
517 } 521 }
518 522
519 LOGGED_LOCK(av->mutex); 523 pthread_mutex_lock(av->mutex);
520 call = call_get(av, friend_number); 524 call = call_get(av, friend_number);
521 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 525 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
522 LOGGED_UNLOCK(av->mutex); 526 pthread_mutex_unlock(av->mutex);
523 rc = TOXAV_ERR_BIT_RATE_FRIEND_NOT_IN_CALL; 527 rc = TOXAV_ERR_BIT_RATE_FRIEND_NOT_IN_CALL;
524 goto END; 528 goto END;
525 } 529 }
526 530
527 /* Decoding mutex is locked because of quality control */ 531 /* Decoding mutex is locked because of quality control */
528 LOGGED_LOCK(call->mutex_decoding); 532 pthread_mutex_lock(call->mutex);
529 call->audio_bit_rate = audio_bit_rate; 533 call->audio_bit_rate = audio_bit_rate;
530 LOGGED_UNLOCK(call->mutex_decoding); 534 pthread_mutex_unlock(call->mutex);
531 LOGGED_UNLOCK(av->mutex); 535 pthread_mutex_unlock(av->mutex);
532 536
533END: 537END:
534 if (error) 538 if (error)
@@ -552,19 +556,19 @@ bool toxav_set_video_bit_rate(ToxAV* av, uint32_t friend_number, uint32_t video_
552 goto END; 556 goto END;
553 } 557 }
554 558
555 LOGGED_LOCK(av->mutex); 559 pthread_mutex_lock(av->mutex);
556 call = call_get(av, friend_number); 560 call = call_get(av, friend_number);
557 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 561 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
558 LOGGED_UNLOCK(av->mutex); 562 pthread_mutex_unlock(av->mutex);
559 rc = TOXAV_ERR_BIT_RATE_FRIEND_NOT_IN_CALL; 563 rc = TOXAV_ERR_BIT_RATE_FRIEND_NOT_IN_CALL;
560 goto END; 564 goto END;
561 } 565 }
562 566
563 /* Decoding mutex is locked because of quality control */ 567 /* Decoding mutex is locked because of quality control */
564 LOGGED_LOCK(call->mutex_decoding); 568 pthread_mutex_lock(call->mutex);
565 call->video_bit_rate = video_bit_rate; 569 call->video_bit_rate = video_bit_rate;
566 LOGGED_UNLOCK(call->mutex_decoding); 570 pthread_mutex_unlock(call->mutex);
567 LOGGED_UNLOCK(av->mutex); 571 pthread_mutex_unlock(av->mutex);
568 572
569END: 573END:
570 if (error) 574 if (error)
@@ -575,10 +579,10 @@ END:
575 579
576void toxav_callback_video_frame_request(ToxAV* av, toxav_video_frame_request_cb* function, void* user_data) 580void toxav_callback_video_frame_request(ToxAV* av, toxav_video_frame_request_cb* function, void* user_data)
577{ 581{
578 LOGGED_LOCK(av->mutex); 582 pthread_mutex_lock(av->mutex);
579 av->rvcb.first = function; 583 av->rvcb.first = function;
580 av->rvcb.second = user_data; 584 av->rvcb.second = user_data;
581 LOGGED_UNLOCK(av->mutex); 585 pthread_mutex_unlock(av->mutex);
582} 586}
583 587
584bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t* y, const uint8_t* u, const uint8_t* v, TOXAV_ERR_SEND_FRAME* error) 588bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, uint16_t height, const uint8_t* y, const uint8_t* u, const uint8_t* v, TOXAV_ERR_SEND_FRAME* error)
@@ -591,25 +595,25 @@ bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u
591 goto END; 595 goto END;
592 } 596 }
593 597
594 LOGGED_LOCK(av->mutex); 598 pthread_mutex_lock(av->mutex);
595 call = call_get(av, friend_number); 599 call = call_get(av, friend_number);
596 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 600 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
597 LOGGED_UNLOCK(av->mutex); 601 pthread_mutex_unlock(av->mutex);
598 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL; 602 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL;
599 goto END; 603 goto END;
600 } 604 }
601 605
602 LOGGED_LOCK(call->mutex_video_sending); 606 pthread_mutex_lock(call->mutex_video);
603 LOGGED_UNLOCK(av->mutex); 607 pthread_mutex_unlock(av->mutex);
604 608
605 if ( y == NULL || u == NULL || v == NULL ) { 609 if ( y == NULL || u == NULL || v == NULL ) {
606 LOGGED_UNLOCK(call->mutex_video_sending); 610 pthread_mutex_unlock(call->mutex_video);
607 rc = TOXAV_ERR_SEND_FRAME_NULL; 611 rc = TOXAV_ERR_SEND_FRAME_NULL;
608 goto END; 612 goto END;
609 } 613 }
610 614
611 if ( cs_reconfigure_video_encoder(call->cs, call->video_bit_rate, width, height) != 0 ) { 615 if ( vc_reconfigure_encoder(call->video.second, call->video_bit_rate, width, height) != 0 ) {
612 LOGGED_UNLOCK(call->mutex_video_sending); 616 pthread_mutex_unlock(call->mutex_video);
613 rc = TOXAV_ERR_SEND_FRAME_INVALID; 617 rc = TOXAV_ERR_SEND_FRAME_INVALID;
614 goto END; 618 goto END;
615 } 619 }
@@ -626,29 +630,29 @@ bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u
626 memcpy(img.planes[VPX_PLANE_U], u, (width/2) * (height/2)); 630 memcpy(img.planes[VPX_PLANE_U], u, (width/2) * (height/2));
627 memcpy(img.planes[VPX_PLANE_V], v, (width/2) * (height/2)); 631 memcpy(img.planes[VPX_PLANE_V], v, (width/2) * (height/2));
628 632
629 int vrc = vpx_codec_encode(call->cs->v_encoder, &img, 633 int vrc = vpx_codec_encode(call->video.second->v_encoder, &img,
630 call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); 634 call->video.second->frame_counter, 1, 0, MAX_ENCODE_TIME_US);
631 635
632 vpx_img_free(&img); 636 vpx_img_free(&img);
633 if ( vrc != VPX_CODEC_OK) { 637 if ( vrc != VPX_CODEC_OK) {
634 LOGGED_UNLOCK(call->mutex_video_sending); 638 pthread_mutex_unlock(call->mutex_video);
635 LOGGER_ERROR("Could not encode video frame: %s\n", vpx_codec_err_to_string(vrc)); 639 LOGGER_ERROR("Could not encode video frame: %s\n", vpx_codec_err_to_string(vrc));
636 rc = TOXAV_ERR_SEND_FRAME_INVALID; 640 rc = TOXAV_ERR_SEND_FRAME_INVALID;
637 goto END; 641 goto END;
638 } 642 }
639 } 643 }
640 644
641 ++call->cs->frame_counter; 645 ++call->video.second->frame_counter;
642 646
643 { /* Split and send */ 647 { /* Split and send */
644 vpx_codec_iter_t iter = NULL; 648 vpx_codec_iter_t iter = NULL;
645 const vpx_codec_cx_pkt_t *pkt; 649 const vpx_codec_cx_pkt_t *pkt;
646 650
647 cs_init_video_splitter_cycle(call->cs); 651 vc_init_video_splitter_cycle(call->video.second);
648 652
649 while ( (pkt = vpx_codec_get_cx_data(call->cs->v_encoder, &iter)) ) { 653 while ( (pkt = vpx_codec_get_cx_data(call->video.second->v_encoder, &iter)) ) {
650 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { 654 if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) {
651 int parts = cs_update_video_splitter_cycle(call->cs, pkt->data.frame.buf, 655 int parts = vc_update_video_splitter_cycle(call->video.second, pkt->data.frame.buf,
652 pkt->data.frame.sz); 656 pkt->data.frame.sz);
653 657
654 if (parts < 0) /* Should never happen though */ 658 if (parts < 0) /* Should never happen though */
@@ -659,10 +663,10 @@ bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u
659 663
660 int i; 664 int i;
661 for (i = 0; i < parts; i++) { 665 for (i = 0; i < parts; i++) {
662 iter = cs_iterate_split_video_frame(call->cs, &part_size); 666 iter = vc_iterate_split_video_frame(call->video.second, &part_size);
663 667
664 if (rtp_send_msg(call->rtps[video_index], iter, part_size) < 0) { 668 if (rtp_send_msg(call->video.first, iter, part_size) < 0) {
665 LOGGED_UNLOCK(call->mutex_video_sending); 669 pthread_mutex_unlock(call->mutex_video);
666 LOGGER_WARNING("Could not send video frame: %s\n", strerror(errno)); 670 LOGGER_WARNING("Could not send video frame: %s\n", strerror(errno));
667 goto END; 671 goto END;
668 } 672 }
@@ -671,7 +675,7 @@ bool toxav_send_video_frame(ToxAV* av, uint32_t friend_number, uint16_t width, u
671 } 675 }
672 } 676 }
673 677
674 LOGGED_UNLOCK(call->mutex_video_sending); 678 pthread_mutex_unlock(call->mutex_video);
675 679
676END: 680END:
677 if (error) 681 if (error)
@@ -682,10 +686,10 @@ END:
682 686
683void toxav_callback_audio_frame_request(ToxAV* av, toxav_audio_frame_request_cb* function, void* user_data) 687void toxav_callback_audio_frame_request(ToxAV* av, toxav_audio_frame_request_cb* function, void* user_data)
684{ 688{
685 LOGGED_LOCK(av->mutex); 689 pthread_mutex_lock(av->mutex);
686 av->racb.first = function; 690 av->racb.first = function;
687 av->racb.second = user_data; 691 av->racb.second = user_data;
688 LOGGED_UNLOCK(av->mutex); 692 pthread_mutex_unlock(av->mutex);
689} 693}
690 694
691bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pcm, size_t sample_count, uint8_t channels, uint32_t sampling_rate, TOXAV_ERR_SEND_FRAME* error) 695bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pcm, size_t sample_count, uint8_t channels, uint32_t sampling_rate, TOXAV_ERR_SEND_FRAME* error)
@@ -698,32 +702,32 @@ bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
698 goto END; 702 goto END;
699 } 703 }
700 704
701 LOGGED_LOCK(av->mutex); 705 pthread_mutex_lock(av->mutex);
702 call = call_get(av, friend_number); 706 call = call_get(av, friend_number);
703 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) { 707 if (call == NULL || !call->active || call->msi_call->state != msi_CallActive) {
704 LOGGED_UNLOCK(av->mutex); 708 pthread_mutex_unlock(av->mutex);
705 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL; 709 rc = TOXAV_ERR_SEND_FRAME_FRIEND_NOT_IN_CALL;
706 goto END; 710 goto END;
707 } 711 }
708 712
709 LOGGED_LOCK(call->mutex_audio_sending); 713 pthread_mutex_lock(call->mutex_audio);
710 LOGGED_UNLOCK(av->mutex); 714 pthread_mutex_unlock(av->mutex);
711 715
712 if ( pcm == NULL ) { 716 if ( pcm == NULL ) {
713 LOGGED_UNLOCK(call->mutex_audio_sending); 717 pthread_mutex_unlock(call->mutex_audio);
714 rc = TOXAV_ERR_SEND_FRAME_NULL; 718 rc = TOXAV_ERR_SEND_FRAME_NULL;
715 goto END; 719 goto END;
716 } 720 }
717 721
718 if ( channels > 2 ) { 722 if ( channels > 2 ) {
719 LOGGED_UNLOCK(call->mutex_audio_sending); 723 pthread_mutex_unlock(call->mutex_audio);
720 rc = TOXAV_ERR_SEND_FRAME_INVALID; 724 rc = TOXAV_ERR_SEND_FRAME_INVALID;
721 goto END; 725 goto END;
722 } 726 }
723 727
724 { /* Encode and send */ 728 { /* Encode and send */
725 if (cs_reconfigure_audio_encoder(call->cs, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) { 729 if (ac_reconfigure_encoder(call->audio.second, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) {
726 LOGGED_UNLOCK(call->mutex_audio_sending); 730 pthread_mutex_unlock(call->mutex_audio);
727 rc = TOXAV_ERR_SEND_FRAME_INVALID; 731 rc = TOXAV_ERR_SEND_FRAME_INVALID;
728 goto END; 732 goto END;
729 } 733 }
@@ -732,12 +736,12 @@ bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
732 736
733 sampling_rate = htonl(sampling_rate); 737 sampling_rate = htonl(sampling_rate);
734 memcpy(dest, &sampling_rate, sizeof(sampling_rate)); 738 memcpy(dest, &sampling_rate, sizeof(sampling_rate));
735 int vrc = opus_encode(call->cs->audio_encoder, pcm, sample_count, 739 int vrc = opus_encode(call->audio.second->encoder, pcm, sample_count,
736 dest + sizeof(sampling_rate), sizeof(dest) - sizeof(sampling_rate)); 740 dest + sizeof(sampling_rate), sizeof(dest) - sizeof(sampling_rate));
737 741
738 if (vrc < 0) { 742 if (vrc < 0) {
739 LOGGER_WARNING("Failed to encode frame %s", opus_strerror(vrc)); 743 LOGGER_WARNING("Failed to encode frame %s", opus_strerror(vrc));
740 LOGGED_UNLOCK(call->mutex_audio_sending); 744 pthread_mutex_unlock(call->mutex_audio);
741 rc = TOXAV_ERR_SEND_FRAME_INVALID; 745 rc = TOXAV_ERR_SEND_FRAME_INVALID;
742 goto END; 746 goto END;
743 } 747 }
@@ -745,13 +749,13 @@ bool toxav_send_audio_frame(ToxAV* av, uint32_t friend_number, const int16_t* pc
745// LOGGER_DEBUG("Sending encoded audio frame size: %d; channels: %d; srate: %d", vrc, channels, 749// LOGGER_DEBUG("Sending encoded audio frame size: %d; channels: %d; srate: %d", vrc, channels,
746// ntohl(sampling_rate)); 750// ntohl(sampling_rate));
747 751
748 if (rtp_send_msg(call->rtps[audio_index], dest, vrc + sizeof(sampling_rate)) != 0) { 752 if (rtp_send_msg(call->audio.first, dest, vrc + sizeof(sampling_rate)) != 0) {
749 LOGGER_WARNING("Failed to send audio packet"); 753 LOGGER_WARNING("Failed to send audio packet");
750 rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; 754 rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED;
751 } 755 }
752 } 756 }
753 757
754 LOGGED_UNLOCK(call->mutex_audio_sending); 758 pthread_mutex_unlock(call->mutex_audio);
755 759
756END: 760END:
757 if (error) 761 if (error)
@@ -762,18 +766,18 @@ END:
762 766
763void toxav_callback_receive_video_frame(ToxAV* av, toxav_receive_video_frame_cb* function, void* user_data) 767void toxav_callback_receive_video_frame(ToxAV* av, toxav_receive_video_frame_cb* function, void* user_data)
764{ 768{
765 LOGGED_LOCK(av->mutex); 769 pthread_mutex_lock(av->mutex);
766 av->vcb.first = function; 770 av->vcb.first = function;
767 av->vcb.second = user_data; 771 av->vcb.second = user_data;
768 LOGGED_UNLOCK(av->mutex); 772 pthread_mutex_unlock(av->mutex);
769} 773}
770 774
771void toxav_callback_receive_audio_frame(ToxAV* av, toxav_receive_audio_frame_cb* function, void* user_data) 775void toxav_callback_receive_audio_frame(ToxAV* av, toxav_receive_audio_frame_cb* function, void* user_data)
772{ 776{
773 LOGGED_LOCK(av->mutex); 777 pthread_mutex_lock(av->mutex);
774 av->acb.first = function; 778 av->acb.first = function;
775 av->acb.second = user_data; 779 av->acb.second = user_data;
776 LOGGED_UNLOCK(av->mutex); 780 pthread_mutex_unlock(av->mutex);
777} 781}
778 782
779 783
@@ -785,12 +789,12 @@ void toxav_callback_receive_audio_frame(ToxAV* av, toxav_receive_audio_frame_cb*
785int callback_invite(void* toxav_inst, MSICall* call) 789int callback_invite(void* toxav_inst, MSICall* call)
786{ 790{
787 ToxAV* toxav = toxav_inst; 791 ToxAV* toxav = toxav_inst;
788 LOGGED_LOCK(toxav->mutex); 792 pthread_mutex_lock(toxav->mutex);
789 793
790 ToxAVCall* av_call = call_new(toxav, call->friend_id, NULL); 794 ToxAVCall* av_call = call_new(toxav, call->friend_id, NULL);
791 if (av_call == NULL) { 795 if (av_call == NULL) {
792 LOGGER_WARNING("Failed to initialize call..."); 796 LOGGER_WARNING("Failed to initialize call...");
793 LOGGED_UNLOCK(toxav->mutex); 797 pthread_mutex_unlock(toxav->mutex);
794 return -1; 798 return -1;
795 } 799 }
796 800
@@ -801,72 +805,72 @@ int callback_invite(void* toxav_inst, MSICall* call)
801 toxav->ccb.first(toxav, call->friend_id, call->peer_capabilities & msi_CapSAudio, 805 toxav->ccb.first(toxav, call->friend_id, call->peer_capabilities & msi_CapSAudio,
802 call->peer_capabilities & msi_CapSVideo, toxav->ccb.second); 806 call->peer_capabilities & msi_CapSVideo, toxav->ccb.second);
803 807
804 LOGGED_UNLOCK(toxav->mutex); 808 pthread_mutex_unlock(toxav->mutex);
805 return 0; 809 return 0;
806} 810}
807 811
808int callback_start(void* toxav_inst, MSICall* call) 812int callback_start(void* toxav_inst, MSICall* call)
809{ 813{
810 ToxAV* toxav = toxav_inst; 814 ToxAV* toxav = toxav_inst;
811 LOGGED_LOCK(toxav->mutex); 815 pthread_mutex_lock(toxav->mutex);
812 816
813 ToxAVCall* av_call = call_get(toxav, call->friend_id); 817 ToxAVCall* av_call = call_get(toxav, call->friend_id);
814 818
815 if (av_call == NULL) { 819 if (av_call == NULL) {
816 /* Should this ever happen? */ 820 /* Should this ever happen? */
817 LOGGED_UNLOCK(toxav->mutex); 821 pthread_mutex_unlock(toxav->mutex);
818 return -1; 822 return -1;
819 } 823 }
820 824
821 if (!call_prepare_transmission(av_call)) { 825 if (!call_prepare_transmission(av_call)) {
822 callback_error(toxav_inst, call); 826 callback_error(toxav_inst, call);
823 call_remove(av_call); 827 call_remove(av_call);
824 LOGGED_UNLOCK(toxav->mutex); 828 pthread_mutex_unlock(toxav->mutex);
825 return -1; 829 return -1;
826 } 830 }
827 831
828 invoke_call_state(toxav, call->friend_id, call->peer_capabilities); 832 invoke_call_state(toxav, call->friend_id, call->peer_capabilities);
829 833
830 LOGGED_UNLOCK(toxav->mutex); 834 pthread_mutex_unlock(toxav->mutex);
831 return 0; 835 return 0;
832} 836}
833 837
834int callback_end(void* toxav_inst, MSICall* call) 838int callback_end(void* toxav_inst, MSICall* call)
835{ 839{
836 ToxAV* toxav = toxav_inst; 840 ToxAV* toxav = toxav_inst;
837 LOGGED_LOCK(toxav->mutex); 841 pthread_mutex_lock(toxav->mutex);
838 842
839 invoke_call_state(toxav, call->friend_id, TOXAV_CALL_STATE_END); 843 invoke_call_state(toxav, call->friend_id, TOXAV_CALL_STATE_END);
840 844
841 call_kill_transmission(call->av_call); 845 call_kill_transmission(call->av_call);
842 call_remove(call->av_call); 846 call_remove(call->av_call);
843 847
844 LOGGED_UNLOCK(toxav->mutex); 848 pthread_mutex_unlock(toxav->mutex);
845 return 0; 849 return 0;
846} 850}
847 851
848int callback_error(void* toxav_inst, MSICall* call) 852int callback_error(void* toxav_inst, MSICall* call)
849{ 853{
850 ToxAV* toxav = toxav_inst; 854 ToxAV* toxav = toxav_inst;
851 LOGGED_LOCK(toxav->mutex); 855 pthread_mutex_lock(toxav->mutex);
852 856
853 invoke_call_state(toxav, call->friend_id, TOXAV_CALL_STATE_ERROR); 857 invoke_call_state(toxav, call->friend_id, TOXAV_CALL_STATE_ERROR);
854 858
855 call_kill_transmission(call->av_call); 859 call_kill_transmission(call->av_call);
856 call_remove(call->av_call); 860 call_remove(call->av_call);
857 861
858 LOGGED_UNLOCK(toxav->mutex); 862 pthread_mutex_unlock(toxav->mutex);
859 return 0; 863 return 0;
860} 864}
861 865
862int callback_capabilites(void* toxav_inst, MSICall* call) 866int callback_capabilites(void* toxav_inst, MSICall* call)
863{ 867{
864 ToxAV* toxav = toxav_inst; 868 ToxAV* toxav = toxav_inst;
865 LOGGED_LOCK(toxav->mutex); 869 pthread_mutex_lock(toxav->mutex);
866 870
867 invoke_call_state(toxav, call->friend_id, call->peer_capabilities); 871 invoke_call_state(toxav, call->friend_id, call->peer_capabilities);
868 872
869 LOGGED_UNLOCK(toxav->mutex); 873 pthread_mutex_unlock(toxav->mutex);
870 return 0; 874 return 0;
871} 875}
872 876
@@ -982,10 +986,8 @@ ToxAVCall* call_get(ToxAV* av, uint32_t friend_number)
982 986
983void qc_do(ToxAVCall* call) 987void qc_do(ToxAVCall* call)
984{ 988{
985 /* Please NOTE: The quality control is rather basic, 989 /*
986 * advanced algorithms will be applied in the future 990 switch(call->audio.first->tstate) {
987 */
988 switch(call->rtps[audio_index]->tstate) {
989 case rtp_StateBad: 991 case rtp_StateBad:
990 LOGGER_DEBUG("Suggesting lower bitrate for audio..."); 992 LOGGER_DEBUG("Suggesting lower bitrate for audio...");
991 call->time_audio_good = 0; 993 call->time_audio_good = 0;
@@ -1007,9 +1009,9 @@ void qc_do(ToxAVCall* call)
1007 case rtp_StateNormal: 1009 case rtp_StateNormal:
1008 call->time_audio_good = 0; 1010 call->time_audio_good = 0;
1009 break; 1011 break;
1010 } 1012 }*/
1011 1013 /*
1012 switch(call->rtps[video_index]->tstate) { 1014 switch(call->video.first->tstate) {
1013 case rtp_StateBad: 1015 case rtp_StateBad:
1014 LOGGER_DEBUG("Suggesting lower bitrate for video..."); 1016 LOGGER_DEBUG("Suggesting lower bitrate for video...");
1015 call->time_video_good = 0; 1017 call->time_video_good = 0;
@@ -1030,8 +1032,7 @@ void qc_do(ToxAVCall* call)
1030 case rtp_StateNormal: 1032 case rtp_StateNormal:
1031 call->time_video_good = 0; 1033 call->time_video_good = 0;
1032 break; 1034 break;
1033 } 1035 }*/
1034
1035} 1036}
1036 1037
1037void call_remove(ToxAVCall* call) 1038void call_remove(ToxAVCall* call)
@@ -1086,61 +1087,50 @@ bool call_prepare_transmission(ToxAVCall* call)
1086 return true; 1087 return true;
1087 } 1088 }
1088 1089
1089 if (create_recursive_mutex(call->mutex_audio_sending) != 0) 1090 if (create_recursive_mutex(call->mutex_audio) != 0)
1090 return false; 1091 return false;
1091 1092
1092 if (create_recursive_mutex(call->mutex_video_sending) != 0) { 1093 if (create_recursive_mutex(call->mutex_video) != 0) {
1093 goto AUDIO_SENDING_MUTEX_CLEANUP; 1094 goto AUDIO_SENDING_MUTEX_CLEANUP;
1094 } 1095 }
1095 1096
1096 if (create_recursive_mutex(call->mutex_decoding) != 0) { 1097 if (create_recursive_mutex(call->mutex) != 0) {
1097 goto VIDEO_SENDING_MUTEX_CLEANUP; 1098 goto VIDEO_SENDING_MUTEX_CLEANUP;
1098 } 1099 }
1099 1100
1100 /* Creates both audio and video encoders and decoders with some default values.
1101 * Make sure to reconfigure encoders dynamically when sending data
1102 */
1103 call->cs = cs_new(call->msi_call->peer_vfpsz);
1104
1105 if ( !call->cs ) {
1106 LOGGER_ERROR("Error while starting Codec State!\n");
1107 goto FAILURE;
1108 }
1109
1110 call->cs->av = av;
1111 call->cs->friend_id = call->friend_id;
1112
1113 memcpy(&call->cs->acb, &av->acb, sizeof(av->acb));
1114 memcpy(&call->cs->vcb, &av->vcb, sizeof(av->vcb));
1115 1101
1116 { /* Prepare audio RTP */ 1102 { /* Prepare audio */
1117 call->rtps[audio_index] = rtp_new(rtp_TypeAudio, av->m, call->friend_id); 1103 call->audio.first = rtp_new(rtp_TypeAudio, av->m, call->friend_id);
1104 call->audio.second = ac_new(av, call->friend_id, av->acb.first, av->acb.second);
1118 1105
1119 if ( !call->rtps[audio_index] ) { 1106 if ( !call->audio.first || !call->audio.second ) {
1120 LOGGER_ERROR("Error while starting audio RTP session!\n"); 1107 LOGGER_ERROR("Error while starting audio!\n");
1121 goto FAILURE; 1108 goto FAILURE;
1122 } 1109 }
1123 1110
1124 call->rtps[audio_index]->cs = call->cs; 1111 call->audio.first->cs = call->audio.second;
1112 call->audio.first->mcb = ac_queue_message;
1125 1113
1126 if (rtp_start_receiving(call->rtps[audio_index]) != 0) { 1114 if (rtp_start_receiving(call->audio.first) != 0) {
1127 LOGGER_WARNING("Failed to enable audio receiving!"); 1115 LOGGER_WARNING("Failed to enable audio receiving!");
1128 goto FAILURE; 1116 goto FAILURE;
1129 } 1117 }
1130 } 1118 }
1131 1119
1132 { /* Prepare video RTP */ 1120 { /* Prepare video */
1133 call->rtps[video_index] = rtp_new(rtp_TypeVideo, av->m, call->friend_id); 1121 call->video.first = rtp_new(rtp_TypeVideo, av->m, call->friend_id);
1122 call->video.second = vc_new(av, call->friend_id, av->vcb.first, av->vcb.second, call->msi_call->peer_vfpsz);
1134 1123
1135 if ( !call->rtps[video_index] ) { 1124 if ( !call->video.first || !call->video.second ) {
1136 LOGGER_ERROR("Error while starting video RTP session!\n"); 1125 LOGGER_ERROR("Error while starting video!\n");
1137 goto FAILURE; 1126 goto FAILURE;
1138 } 1127 }
1139 1128
1140 call->rtps[video_index]->cs = call->cs; 1129 call->video.first->cs = call->video.second;
1130 call->video.first->mcb = vc_queue_message;
1141 1131
1142 if (rtp_start_receiving(call->rtps[video_index]) != 0) { 1132 if (rtp_start_receiving(call->video.first) != 0) {
1143 LOGGER_WARNING("Failed to enable audio receiving!"); 1133 LOGGER_WARNING("Failed to enable video receiving!");
1144 goto FAILURE; 1134 goto FAILURE;
1145 } 1135 }
1146 } 1136 }
@@ -1149,17 +1139,19 @@ bool call_prepare_transmission(ToxAVCall* call)
1149 return true; 1139 return true;
1150 1140
1151FAILURE: 1141FAILURE:
1152 rtp_kill(call->rtps[audio_index]); 1142 rtp_kill(call->audio.first);
1153 call->rtps[audio_index] = NULL; 1143 ac_kill(call->audio.second);
1154 rtp_kill(call->rtps[video_index]); 1144 call->audio.first = NULL;
1155 call->rtps[video_index] = NULL; 1145 call->audio.second = NULL;
1156 cs_kill(call->cs); 1146 rtp_kill(call->video.first);
1157 call->cs = NULL; 1147 vc_kill(call->video.second);
1158 pthread_mutex_destroy(call->mutex_decoding); 1148 call->video.first = NULL;
1149 call->video.second = NULL;
1150 pthread_mutex_destroy(call->mutex);
1159VIDEO_SENDING_MUTEX_CLEANUP: 1151VIDEO_SENDING_MUTEX_CLEANUP:
1160 pthread_mutex_destroy(call->mutex_video_sending); 1152 pthread_mutex_destroy(call->mutex_video);
1161AUDIO_SENDING_MUTEX_CLEANUP: 1153AUDIO_SENDING_MUTEX_CLEANUP:
1162 pthread_mutex_destroy(call->mutex_audio_sending); 1154 pthread_mutex_destroy(call->mutex_audio);
1163 return false; 1155 return false;
1164} 1156}
1165 1157
@@ -1170,23 +1162,24 @@ void call_kill_transmission(ToxAVCall* call)
1170 1162
1171 call->active = 0; 1163 call->active = 0;
1172 1164
1173 LOGGED_LOCK(call->mutex_audio_sending); 1165 pthread_mutex_lock(call->mutex_audio);
1174 LOGGED_UNLOCK(call->mutex_audio_sending); 1166 pthread_mutex_unlock(call->mutex_audio);
1175 LOGGED_LOCK(call->mutex_video_sending); 1167 pthread_mutex_lock(call->mutex_video);
1176 LOGGED_UNLOCK(call->mutex_video_sending); 1168 pthread_mutex_unlock(call->mutex_video);
1177 LOGGED_LOCK(call->mutex_decoding); 1169 pthread_mutex_lock(call->mutex);
1178 LOGGED_UNLOCK(call->mutex_decoding); 1170 pthread_mutex_unlock(call->mutex);
1179 1171
1180 1172 rtp_kill(call->audio.first);
1181 rtp_kill(call->rtps[audio_index]); 1173 ac_kill(call->audio.second);
1182 call->rtps[audio_index] = NULL; 1174 call->audio.first = NULL;
1183 rtp_kill(call->rtps[video_index]); 1175 call->audio.second = NULL;
1184 call->rtps[video_index] = NULL; 1176
1185 1177 rtp_kill(call->video.first);
1186 cs_kill(call->cs); 1178 vc_kill(call->video.second);
1187 call->cs = NULL; 1179 call->video.first = NULL;
1188 1180 call->video.second = NULL;
1189 pthread_mutex_destroy(call->mutex_audio_sending); 1181
1190 pthread_mutex_destroy(call->mutex_video_sending); 1182 pthread_mutex_destroy(call->mutex_audio);
1191 pthread_mutex_destroy(call->mutex_decoding); 1183 pthread_mutex_destroy(call->mutex_video);
1184 pthread_mutex_destroy(call->mutex);
1192} 1185}