summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorirungentoo <irungentoo@gmail.com>2014-07-05 17:31:06 -0400
committerirungentoo <irungentoo@gmail.com>2014-07-05 17:31:06 -0400
commit9d154029cb0141d78cdfca74fa2a1177b88bc677 (patch)
tree670e31752b3306b9e6a533340b7cbaeeb6949702
parent5b60c8f3d3f2e7ac285fe8c59f8e81b0327f5cf3 (diff)
parent77c7a3e1030daf9cfba9dae4f850a7a92810ec83 (diff)
Merge branch 'master' of https://github.com/mannol1/toxcore
-rw-r--r--toxav/codec.c3
-rw-r--r--toxav/toxav.c87
2 files changed, 70 insertions, 20 deletions
diff --git a/toxav/codec.c b/toxav/codec.c
index 595c0359..ae24a976 100644
--- a/toxav/codec.c
+++ b/toxav/codec.c
@@ -343,7 +343,8 @@ CodecState *codec_init_session ( uint32_t audio_bitrate,
343 /*video_width = 320; 343 /*video_width = 320;
344 video_height = 240; */ 344 video_height = 240; */
345 } else { 345 } else {
346 retu->capabilities |= ( 0 == init_video_encoder(retu, max_video_width, max_video_height, video_bitrate) ) ? v_encoding : 0; 346 retu->capabilities |= ( 0 == init_video_encoder(retu, max_video_width, max_video_height,
347 video_bitrate) ) ? v_encoding : 0;
347 retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0; 348 retu->capabilities |= ( 0 == init_video_decoder(retu) ) ? v_decoding : 0;
348 } 349 }
349 350
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 606f1370..81196af9 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,13 @@ 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
399
393 call->call_active = 0; 400 call->call_active = 0;
394 401
395 rtp_terminate_session(call->crtps[audio_index], av->messenger); 402 rtp_terminate_session(call->crtps[audio_index], av->messenger);
@@ -532,15 +539,20 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
532{ 539{
533 if ( !output ) return ErrorInternal; 540 if ( !output ) return ErrorInternal;
534 541
535 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 542 if (cii(call_index, av->msi_session)) {
536 LOGGER_WARNING("Action on inactive call: %d", call_index); 543 LOGGER_WARNING("Invalid call index: %d", call_index);
537 return ErrorNoCall; 544 return ErrorNoCall;
538 } 545 }
539 546
540
541 CallSpecific *call = &av->calls[call_index]; 547 CallSpecific *call = &av->calls[call_index];
542 pthread_mutex_lock(&call->mutex); 548 pthread_mutex_lock(&call->mutex);
543 549
550 if (!call->call_active) {
551 pthread_mutex_unlock(&call->mutex);
552 LOGGER_WARNING("Action on inactive call: %d", call_index);
553 return ErrorNoCall;
554 }
555
544 uint8_t packet [RTP_PAYLOAD_SIZE]; 556 uint8_t packet [RTP_PAYLOAD_SIZE];
545 int recved_size; 557 int recved_size;
546 558
@@ -607,15 +619,23 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out
607 */ 619 */
608inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) 620inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size)
609{ 621{
610 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 622 if (cii(call_index, av->msi_session)) {
611 LOGGER_WARNING("Action on inactive call: %d", call_index); 623 LOGGER_WARNING("Invalid call index: %d", call_index);
612 return ErrorNoCall; 624 return ErrorNoCall;
613 } 625 }
614 626
627 CallSpecific *call = &av->calls[call_index];
628 pthread_mutex_lock(&call->mutex);
629
630
631 if (!call->call_active) {
632 pthread_mutex_unlock(&call->mutex);
633 LOGGER_WARNING("Action on inactive call: %d", call_index);
634 return ErrorNoCall;
635 }
615 636
616 pthread_mutex_lock(&av->calls[call_index].mutex);
617 int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); 637 int rc = toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size);
618 pthread_mutex_unlock(&av->calls[call_index].mutex); 638 pthread_mutex_unlock(&call->mutex);
619 639
620 return rc; 640 return rc;
621} 641}
@@ -633,8 +653,8 @@ inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *fr
633 */ 653 */
634inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input) 654inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input)
635{ 655{
636 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 656 if (cii(call_index, av->msi_session)) {
637 LOGGER_WARNING("Action on inactive call: %d", call_index); 657 LOGGER_WARNING("Invalid call index: %d", call_index);
638 return ErrorNoCall; 658 return ErrorNoCall;
639 } 659 }
640 660
@@ -642,8 +662,16 @@ inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *d
642 CallSpecific *call = &av->calls[call_index]; 662 CallSpecific *call = &av->calls[call_index];
643 pthread_mutex_lock(&call->mutex); 663 pthread_mutex_lock(&call->mutex);
644 664
645 if (reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h) != 0) 665 if (!call->call_active) {
666 pthread_mutex_unlock(&call->mutex);
667 LOGGER_WARNING("Action on inactive call: %d", call_index);
668 return ErrorNoCall;
669 }
670
671 if (reconfigure_video_encoder_resolution(call->cs, input->d_w, input->d_h) != 0) {
672 pthread_mutex_unlock(&call->mutex);
646 return ErrorInternal; 673 return ErrorInternal;
674 }
647 675
648 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); 676 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US);
649 677
@@ -691,8 +719,8 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i
691{ 719{
692 if ( !dest ) return ErrorInternal; 720 if ( !dest ) return ErrorInternal;
693 721
694 if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { 722 if (cii(call_index, av->msi_session)) {
695 LOGGER_WARNING("Action on inactive call: %d", call_index); 723 LOGGER_WARNING("Invalid call index: %d", call_index);
696 return ErrorNoCall; 724 return ErrorNoCall;
697 } 725 }
698 726
@@ -700,6 +728,13 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i
700 CallSpecific *call = &av->calls[call_index]; 728 CallSpecific *call = &av->calls[call_index];
701 pthread_mutex_lock(&call->mutex); 729 pthread_mutex_lock(&call->mutex);
702 730
731
732 if (!call->call_active) {
733 pthread_mutex_unlock(&call->mutex);
734 LOGGER_WARNING("Action on inactive call: %d", call_index);
735 return ErrorNoCall;
736 }
737
703 uint8_t packet [RTP_PAYLOAD_SIZE]; 738 uint8_t packet [RTP_PAYLOAD_SIZE];
704 739
705 int recved_size = toxav_recv_rtp_payload(av, call_index, TypeAudio, packet); 740 int recved_size = toxav_recv_rtp_payload(av, call_index, TypeAudio, packet);
@@ -747,10 +782,18 @@ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *fr
747 return ErrorNoCall; 782 return ErrorNoCall;
748 } 783 }
749 784
785 CallSpecific *call = &av->calls[call_index];
786 pthread_mutex_lock(&call->mutex);
787
788
789 if (!call->call_active) {
790 pthread_mutex_unlock(&call->mutex);
791 LOGGER_WARNING("Action on inactive call: %d", call_index);
792 return ErrorNoCall;
793 }
750 794
751 pthread_mutex_lock(&av->calls[call_index].mutex);
752 int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); 795 int rc = toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size);
753 pthread_mutex_unlock(&av->calls[call_index].mutex); 796 pthread_mutex_unlock(&call->mutex);
754 797
755 return rc; 798 return rc;
756} 799}
@@ -775,12 +818,18 @@ inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t
775 return ErrorNoCall; 818 return ErrorNoCall;
776 } 819 }
777 820
821 CallSpecific *call = &av->calls[call_index];
822 pthread_mutex_lock(&call->mutex);
778 823
779 pthread_mutex_lock(&av->calls[call_index].mutex);
780 824
781 int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); 825 if (!call->call_active) {
826 pthread_mutex_unlock(&call->mutex);
827 LOGGER_WARNING("Action on inactive call: %d", call_index);
828 return ErrorNoCall;
829 }
782 830
783 pthread_mutex_unlock(&av->calls[call_index].mutex); 831 int32_t rc = opus_encode(call->cs->audio_encoder, frame, frame_size, dest, dest_max);
832 pthread_mutex_unlock(&call->mutex);
784 833
785 if (rc < 0) { 834 if (rc < 0) {
786 LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc)); 835 LOGGER_ERROR("Failed to encode payload: %s\n", opus_strerror(rc));