diff options
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r-- | toxav/toxav.c | 57 |
1 files changed, 29 insertions, 28 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c index 1aece0b3..4ef5d2b3 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -132,13 +132,14 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error) | |||
132 | { | 132 | { |
133 | TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK; | 133 | TOXAV_ERR_NEW rc = TOXAV_ERR_NEW_OK; |
134 | ToxAV *av = NULL; | 134 | ToxAV *av = NULL; |
135 | Messenger *m = (Messenger *)tox; | ||
135 | 136 | ||
136 | if (tox == NULL) { | 137 | if (tox == NULL) { |
137 | rc = TOXAV_ERR_NEW_NULL; | 138 | rc = TOXAV_ERR_NEW_NULL; |
138 | goto END; | 139 | goto END; |
139 | } | 140 | } |
140 | 141 | ||
141 | if (((Messenger *)tox)->msi_packet) { | 142 | if (m->msi_packet) { |
142 | rc = TOXAV_ERR_NEW_MULTIPLE; | 143 | rc = TOXAV_ERR_NEW_MULTIPLE; |
143 | goto END; | 144 | goto END; |
144 | } | 145 | } |
@@ -146,18 +147,18 @@ ToxAV *toxav_new(Tox *tox, TOXAV_ERR_NEW *error) | |||
146 | av = calloc (sizeof(ToxAV), 1); | 147 | av = calloc (sizeof(ToxAV), 1); |
147 | 148 | ||
148 | if (av == NULL) { | 149 | if (av == NULL) { |
149 | LOGGER_WARNING("Allocation failed!"); | 150 | LOGGER_WARNING(m->log, "Allocation failed!"); |
150 | rc = TOXAV_ERR_NEW_MALLOC; | 151 | rc = TOXAV_ERR_NEW_MALLOC; |
151 | goto END; | 152 | goto END; |
152 | } | 153 | } |
153 | 154 | ||
154 | if (create_recursive_mutex(av->mutex) != 0) { | 155 | if (create_recursive_mutex(av->mutex) != 0) { |
155 | LOGGER_WARNING("Mutex creation failed!"); | 156 | LOGGER_WARNING(m->log, "Mutex creation failed!"); |
156 | rc = TOXAV_ERR_NEW_MALLOC; | 157 | rc = TOXAV_ERR_NEW_MALLOC; |
157 | goto END; | 158 | goto END; |
158 | } | 159 | } |
159 | 160 | ||
160 | av->m = (Messenger *)tox; | 161 | av->m = m; |
161 | av->msi = msi_new(av->m); | 162 | av->msi = msi_new(av->m); |
162 | 163 | ||
163 | if (av->msi == NULL) { | 164 | if (av->msi == NULL) { |
@@ -563,12 +564,12 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
563 | } | 564 | } |
564 | 565 | ||
565 | if (audio_bit_rate >= 0) { | 566 | if (audio_bit_rate >= 0) { |
566 | LOGGER_DEBUG("Setting new audio bitrate to: %d", audio_bit_rate); | 567 | LOGGER_DEBUG(av->m->log, "Setting new audio bitrate to: %d", audio_bit_rate); |
567 | 568 | ||
568 | if (call->audio_bit_rate == audio_bit_rate) { | 569 | if (call->audio_bit_rate == audio_bit_rate) { |
569 | LOGGER_DEBUG("Audio bitrate already set to: %d", audio_bit_rate); | 570 | LOGGER_DEBUG(av->m->log, "Audio bitrate already set to: %d", audio_bit_rate); |
570 | } else if (audio_bit_rate == 0) { | 571 | } else if (audio_bit_rate == 0) { |
571 | LOGGER_DEBUG("Turned off audio sending"); | 572 | LOGGER_DEBUG(av->m->log, "Turned off audio sending"); |
572 | 573 | ||
573 | if (msi_change_capabilities(call->msi_call, call->msi_call-> | 574 | if (msi_change_capabilities(call->msi_call, call->msi_call-> |
574 | self_capabilities ^ msi_CapSAudio) != 0) { | 575 | self_capabilities ^ msi_CapSAudio) != 0) { |
@@ -583,7 +584,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
583 | pthread_mutex_lock(call->mutex); | 584 | pthread_mutex_lock(call->mutex); |
584 | 585 | ||
585 | if (call->audio_bit_rate == 0) { | 586 | if (call->audio_bit_rate == 0) { |
586 | LOGGER_DEBUG("Turned on audio sending"); | 587 | LOGGER_DEBUG(av->m->log, "Turned on audio sending"); |
587 | 588 | ||
588 | /* The audio has been turned off before this */ | 589 | /* The audio has been turned off before this */ |
589 | if (msi_change_capabilities(call->msi_call, call-> | 590 | if (msi_change_capabilities(call->msi_call, call-> |
@@ -594,7 +595,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
594 | goto END; | 595 | goto END; |
595 | } | 596 | } |
596 | } else | 597 | } else |
597 | LOGGER_DEBUG("Set new audio bit rate %d", audio_bit_rate); | 598 | LOGGER_DEBUG(av->m->log, "Set new audio bit rate %d", audio_bit_rate); |
598 | 599 | ||
599 | call->audio_bit_rate = audio_bit_rate; | 600 | call->audio_bit_rate = audio_bit_rate; |
600 | pthread_mutex_unlock(call->mutex); | 601 | pthread_mutex_unlock(call->mutex); |
@@ -602,12 +603,12 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
602 | } | 603 | } |
603 | 604 | ||
604 | if (video_bit_rate >= 0) { | 605 | if (video_bit_rate >= 0) { |
605 | LOGGER_DEBUG("Setting new video bitrate to: %d", video_bit_rate); | 606 | LOGGER_DEBUG(av->m->log, "Setting new video bitrate to: %d", video_bit_rate); |
606 | 607 | ||
607 | if (call->video_bit_rate == video_bit_rate) { | 608 | if (call->video_bit_rate == video_bit_rate) { |
608 | LOGGER_DEBUG("Video bitrate already set to: %d", video_bit_rate); | 609 | LOGGER_DEBUG(av->m->log, "Video bitrate already set to: %d", video_bit_rate); |
609 | } else if (video_bit_rate == 0) { | 610 | } else if (video_bit_rate == 0) { |
610 | LOGGER_DEBUG("Turned off video sending"); | 611 | LOGGER_DEBUG(av->m->log, "Turned off video sending"); |
611 | 612 | ||
612 | /* Video sending is turned off; notify peer */ | 613 | /* Video sending is turned off; notify peer */ |
613 | if (msi_change_capabilities(call->msi_call, call->msi_call-> | 614 | if (msi_change_capabilities(call->msi_call, call->msi_call-> |
@@ -622,7 +623,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
622 | pthread_mutex_lock(call->mutex); | 623 | pthread_mutex_lock(call->mutex); |
623 | 624 | ||
624 | if (call->video_bit_rate == 0) { | 625 | if (call->video_bit_rate == 0) { |
625 | LOGGER_DEBUG("Turned on video sending"); | 626 | LOGGER_DEBUG(av->m->log, "Turned on video sending"); |
626 | 627 | ||
627 | /* The video has been turned off before this */ | 628 | /* The video has been turned off before this */ |
628 | if (msi_change_capabilities(call->msi_call, call-> | 629 | if (msi_change_capabilities(call->msi_call, call-> |
@@ -633,7 +634,7 @@ bool toxav_bit_rate_set(ToxAV *av, uint32_t friend_number, int32_t audio_bit_rat | |||
633 | goto END; | 634 | goto END; |
634 | } | 635 | } |
635 | } else | 636 | } else |
636 | LOGGER_DEBUG("Set new video bit rate %d", video_bit_rate); | 637 | LOGGER_DEBUG(av->m->log, "Set new video bit rate %d", video_bit_rate); |
637 | 638 | ||
638 | call->video_bit_rate = video_bit_rate; | 639 | call->video_bit_rate = video_bit_rate; |
639 | pthread_mutex_unlock(call->mutex); | 640 | pthread_mutex_unlock(call->mutex); |
@@ -717,14 +718,14 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc | |||
717 | dest + sizeof(sampling_rate), sizeof(dest) - sizeof(sampling_rate)); | 718 | dest + sizeof(sampling_rate), sizeof(dest) - sizeof(sampling_rate)); |
718 | 719 | ||
719 | if (vrc < 0) { | 720 | if (vrc < 0) { |
720 | LOGGER_WARNING("Failed to encode frame %s", opus_strerror(vrc)); | 721 | LOGGER_WARNING(av->m->log, "Failed to encode frame %s", opus_strerror(vrc)); |
721 | pthread_mutex_unlock(call->mutex_audio); | 722 | pthread_mutex_unlock(call->mutex_audio); |
722 | rc = TOXAV_ERR_SEND_FRAME_INVALID; | 723 | rc = TOXAV_ERR_SEND_FRAME_INVALID; |
723 | goto END; | 724 | goto END; |
724 | } | 725 | } |
725 | 726 | ||
726 | if (rtp_send_data(call->audio.first, dest, vrc + sizeof(sampling_rate)) != 0) { | 727 | if (rtp_send_data(call->audio.first, dest, vrc + sizeof(sampling_rate)) != 0) { |
727 | LOGGER_WARNING("Failed to send audio packet"); | 728 | LOGGER_WARNING(av->m->log, "Failed to send audio packet"); |
728 | rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; | 729 | rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; |
729 | } | 730 | } |
730 | } | 731 | } |
@@ -805,7 +806,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
805 | 806 | ||
806 | if (vrc != VPX_CODEC_OK) { | 807 | if (vrc != VPX_CODEC_OK) { |
807 | pthread_mutex_unlock(call->mutex_video); | 808 | pthread_mutex_unlock(call->mutex_video); |
808 | LOGGER_ERROR("Could not encode video frame: %s\n", vpx_codec_err_to_string(vrc)); | 809 | LOGGER_ERROR(av->m->log, "Could not encode video frame: %s\n", vpx_codec_err_to_string(vrc)); |
809 | rc = TOXAV_ERR_SEND_FRAME_INVALID; | 810 | rc = TOXAV_ERR_SEND_FRAME_INVALID; |
810 | goto END; | 811 | goto END; |
811 | } | 812 | } |
@@ -822,7 +823,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
822 | rtp_send_data(call->video.first, pkt->data.frame.buf, pkt->data.frame.sz) < 0) { | 823 | rtp_send_data(call->video.first, pkt->data.frame.buf, pkt->data.frame.sz) < 0) { |
823 | 824 | ||
824 | pthread_mutex_unlock(call->mutex_video); | 825 | pthread_mutex_unlock(call->mutex_video); |
825 | LOGGER_WARNING("Could not send video frame: %s\n", strerror(errno)); | 826 | LOGGER_WARNING(av->m->log, "Could not send video frame: %s\n", strerror(errno)); |
826 | rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; | 827 | rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; |
827 | goto END; | 828 | goto END; |
828 | } | 829 | } |
@@ -871,7 +872,7 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u | |||
871 | ToxAVCall *call = user_data; | 872 | ToxAVCall *call = user_data; |
872 | assert(call); | 873 | assert(call); |
873 | 874 | ||
874 | LOGGER_DEBUG("Reported loss of %f%%", loss * 100); | 875 | LOGGER_DEBUG(call->av->m->log, "Reported loss of %f%%", loss * 100); |
875 | 876 | ||
876 | if (loss < .01f) | 877 | if (loss < .01f) |
877 | return; | 878 | return; |
@@ -880,7 +881,7 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u | |||
880 | 881 | ||
881 | if (!call->av->bcb.first) { | 882 | if (!call->av->bcb.first) { |
882 | pthread_mutex_unlock(call->av->mutex); | 883 | pthread_mutex_unlock(call->av->mutex); |
883 | LOGGER_WARNING("No callback to report loss on"); | 884 | LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); |
884 | return; | 885 | return; |
885 | } | 886 | } |
886 | 887 | ||
@@ -903,7 +904,7 @@ int callback_invite(void *toxav_inst, MSICall *call) | |||
903 | ToxAVCall *av_call = call_new(toxav, call->friend_number, NULL); | 904 | ToxAVCall *av_call = call_new(toxav, call->friend_number, NULL); |
904 | 905 | ||
905 | if (av_call == NULL) { | 906 | if (av_call == NULL) { |
906 | LOGGER_WARNING("Failed to initialize call..."); | 907 | LOGGER_WARNING(toxav->m->log, "Failed to initialize call..."); |
907 | pthread_mutex_unlock(toxav->mutex); | 908 | pthread_mutex_unlock(toxav->mutex); |
908 | return -1; | 909 | return -1; |
909 | } | 910 | } |
@@ -1169,7 +1170,7 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1169 | return false; | 1170 | return false; |
1170 | 1171 | ||
1171 | if (call->active) { | 1172 | if (call->active) { |
1172 | LOGGER_WARNING("Call already active!\n"); | 1173 | LOGGER_WARNING(av->m->log, "Call already active!\n"); |
1173 | return true; | 1174 | return true; |
1174 | } | 1175 | } |
1175 | 1176 | ||
@@ -1186,10 +1187,10 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1186 | call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); | 1187 | call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); |
1187 | 1188 | ||
1188 | { /* Prepare audio */ | 1189 | { /* Prepare audio */ |
1189 | call->audio.second = ac_new(av, call->friend_number, av->acb.first, av->acb.second); | 1190 | call->audio.second = ac_new(av->m->log, av, call->friend_number, av->acb.first, av->acb.second); |
1190 | 1191 | ||
1191 | if (!call->audio.second) { | 1192 | if (!call->audio.second) { |
1192 | LOGGER_ERROR("Failed to create audio codec session"); | 1193 | LOGGER_ERROR(av->m->log, "Failed to create audio codec session"); |
1193 | goto FAILURE; | 1194 | goto FAILURE; |
1194 | } | 1195 | } |
1195 | 1196 | ||
@@ -1197,15 +1198,15 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1197 | call->audio.second, ac_queue_message); | 1198 | call->audio.second, ac_queue_message); |
1198 | 1199 | ||
1199 | if (!call->audio.first) { | 1200 | if (!call->audio.first) { |
1200 | LOGGER_ERROR("Failed to create audio rtp session");; | 1201 | LOGGER_ERROR(av->m->log, "Failed to create audio rtp session");; |
1201 | goto FAILURE; | 1202 | goto FAILURE; |
1202 | } | 1203 | } |
1203 | } | 1204 | } |
1204 | { /* Prepare video */ | 1205 | { /* Prepare video */ |
1205 | call->video.second = vc_new(av, call->friend_number, av->vcb.first, av->vcb.second); | 1206 | call->video.second = vc_new(av->m->log, av, call->friend_number, av->vcb.first, av->vcb.second); |
1206 | 1207 | ||
1207 | if (!call->video.second) { | 1208 | if (!call->video.second) { |
1208 | LOGGER_ERROR("Failed to create video codec session"); | 1209 | LOGGER_ERROR(av->m->log, "Failed to create video codec session"); |
1209 | goto FAILURE; | 1210 | goto FAILURE; |
1210 | } | 1211 | } |
1211 | 1212 | ||
@@ -1213,7 +1214,7 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1213 | call->video.second, vc_queue_message); | 1214 | call->video.second, vc_queue_message); |
1214 | 1215 | ||
1215 | if (!call->video.first) { | 1216 | if (!call->video.first) { |
1216 | LOGGER_ERROR("Failed to create video rtp session"); | 1217 | LOGGER_ERROR(av->m->log, "Failed to create video rtp session"); |
1217 | goto FAILURE; | 1218 | goto FAILURE; |
1218 | } | 1219 | } |
1219 | } | 1220 | } |