summaryrefslogtreecommitdiff
path: root/toxav/toxav.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-07-05 19:27:31 +0200
committermannol <eniz_vukovic@hotmail.com>2014-07-05 19:27:31 +0200
commit77c7a3e1030daf9cfba9dae4f850a7a92810ec83 (patch)
tree5ba5c2648e1caecfa95f66b27e1c067607394f41 /toxav/toxav.c
parent9af7c335e7f198e6ac2ebe7554be2b30ffcbfbb4 (diff)
Check if call is active after getting mutex handle
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r--toxav/toxav.c84
1 files changed, 66 insertions, 18 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 36053fd5..19fcd854 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -381,8 +381,8 @@ error:
381 */ 381 */
382int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) 382int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
383{ 383{
384 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 384 if (cii(call_index, av->msi_session)) {
385 LOGGER_WARNING("Action on inactive call: %d", call_index); 385 LOGGER_WARNING("Invalid call index: %d", call_index);
386 return ErrorNoCall; 386 return ErrorNoCall;
387 } 387 }
388 388
@@ -390,6 +390,12 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
390 390
391 pthread_mutex_lock(&call->mutex); 391 pthread_mutex_lock(&call->mutex);
392 392
393 if (!call->call_active){
394 pthread_mutex_unlock(&call->mutex);
395 LOGGER_WARNING("Action on inactive call: %d", call_index);
396 return ErrorNoCall;
397 }
398
393 call->call_active = 0; 399 call->call_active = 0;
394 400
395 rtp_terminate_session(call->crtps[audio_index], av->messenger); call->crtps[audio_index] = NULL; 401 rtp_terminate_session(call->crtps[audio_index], av->messenger); call->crtps[audio_index] = NULL;
@@ -527,15 +533,21 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
527{ 533{
528 if ( !output ) return ErrorInternal; 534 if ( !output ) return ErrorInternal;
529 535
530 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 536 if (cii(call_index, av->msi_session)) {
531 LOGGER_WARNING("Action on inactive call: %d", call_index); 537 LOGGER_WARNING("Invalid call index: %d", call_index);
532 return ErrorNoCall; 538 return ErrorNoCall;
533 } 539 }
534 540
535
536 CallSpecific *call = &av->calls[call_index]; 541 CallSpecific *call = &av->calls[call_index];
537 pthread_mutex_lock(&call->mutex); 542 pthread_mutex_lock(&call->mutex);
538 543
544 if (!call->call_active){
545 pthread_mutex_unlock(&call->mutex);
546 LOGGER_WARNING("Action on inactive call: %d", call_index);
547 return ErrorNoCall;
548 }
549
550
539 uint8_t packet [RTP_PAYLOAD_SIZE]; 551 uint8_t packet [RTP_PAYLOAD_SIZE];
540 int recved_size; 552 int recved_size;
541 553
@@ -602,15 +614,23 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
602 */ 614 */
603inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) 615inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size)
604{ 616{
605 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 617 if (cii(call_index, av->msi_session)) {
606 LOGGER_WARNING("Action on inactive call: %d", call_index); 618 LOGGER_WARNING("Invalid call index: %d", call_index);
607 return ErrorNoCall; 619 return ErrorNoCall;
608 } 620 }
609 621
622 CallSpecific* call = &av->calls[call_index];
623 pthread_mutex_lock(&call->mutex);
624
625
626 if (!call->call_active){
627 pthread_mutex_unlock(&call->mutex);
628 LOGGER_WARNING("Action on inactive call: %d", call_index);
629 return ErrorNoCall;
630 }
610 631
611 pthread_mutex_lock(&av->calls[call_index].mutex);
612 int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); 632 int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size);
613 pthread_mutex_unlock(&av->calls[call_index].mutex); 633 pthread_mutex_unlock(&call->mutex);
614 634
615 return rc; 635 return rc;
616} 636}
@@ -628,8 +648,8 @@ inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *fr
628 */ 648 */
629inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input) 649inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input)
630{ 650{
631 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 651 if (cii(call_index, av->msi_session)) {
632 LOGGER_WARNING("Action on inactive call: %d", call_index); 652 LOGGER_WARNING("Invalid call index: %d", call_index);
633 return ErrorNoCall; 653 return ErrorNoCall;
634 } 654 }
635 655
@@ -637,6 +657,12 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
637 CallSpecific *call = &av->calls[call_index]; 657 CallSpecific *call = &av->calls[call_index];
638 pthread_mutex_lock(&call->mutex); 658 pthread_mutex_lock(&call->mutex);
639 659
660 if (!call->call_active){
661 pthread_mutex_unlock(&call->mutex);
662 LOGGER_WARNING("Action on inactive call: %d", call_index);
663 return ErrorNoCall;
664 }
665
640 reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h); 666 reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h);
641 667
642 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); 668 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US);
@@ -685,14 +711,21 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i
685{ 711{
686 if ( !dest ) return ErrorInternal; 712 if ( !dest ) return ErrorInternal;
687 713
688 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 714 if (cii(call_index, av->msi_session)) {
689 LOGGER_WARNING("Action on inactive call: %d", call_index); 715 LOGGER_WARNING("Invalid call index: %d", call_index);
690 return ErrorNoCall; 716 return ErrorNoCall;
691 } 717 }
692 718
693 719
694 CallSpecific *call = &av->calls[call_index]; 720 CallSpecific *call = &av->calls[call_index];
695 pthread_mutex_lock(&call->mutex); 721 pthread_mutex_lock(&call->mutex);
722
723
724 if (!call->call_active){
725 pthread_mutex_unlock(&call->mutex);
726 LOGGER_WARNING("Action on inactive call: %d", call_index);
727 return ErrorNoCall;
728 }
696 729
697 uint8_t packet [RTP_PAYLOAD_SIZE]; 730 uint8_t packet [RTP_PAYLOAD_SIZE];
698 731
@@ -741,10 +774,18 @@ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *fr
741 return ErrorNoCall; 774 return ErrorNoCall;
742 } 775 }
743 776
777 CallSpecific* call = &av->calls[call_index];
778 pthread_mutex_lock(&call->mutex);
779
780
781 if (!call->call_active){
782 pthread_mutex_unlock(&call->mutex);
783 LOGGER_WARNING("Action on inactive call: %d", call_index);
784 return ErrorNoCall;
785 }
744 786
745 pthread_mutex_lock(&av->calls[call_index].mutex);
746 int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); 787 int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size);
747 pthread_mutex_unlock(&av->calls[call_index].mutex); 788 pthread_mutex_unlock(&call->mutex);
748 789
749 return rc; 790 return rc;
750} 791}
@@ -769,12 +810,19 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t
769 return ErrorNoCall; 810 return ErrorNoCall;
770 } 811 }
771 812
813 CallSpecific* call = &av->calls[call_index];
814 pthread_mutex_lock(&call->mutex);
772 815
773 pthread_mutex_lock(&av->calls[call_index].mutex);
774 816
775 int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); 817 if (!call->call_active){
818 pthread_mutex_unlock(&call->mutex);
819 LOGGER_WARNING("Action on inactive call: %d", call_index);
820 return ErrorNoCall;
821 }
822
823 int32_t rc = opus_encode(call->cs->audio_encoder, frame, frame_size, dest, dest_max);
824 pthread_mutex_unlock(&call->mutex);
776 825
777 pthread_mutex_unlock(&av->calls[call_index].mutex);
778 826
779 if (rc < 0) { 827 if (rc < 0) {
780 LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc)); 828 LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc));