diff options
author | iphydf <iphydf@users.noreply.github.com> | 2018-08-12 10:55:20 +0000 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2018-08-12 11:38:23 +0000 |
commit | 1de8b020cb5f79c3e52a0fb502b5abdbbd20a2f0 (patch) | |
tree | afae3b1329d340f92484571676c36a0e0fba836c /toxav | |
parent | 5d15b5930d2b3e442f3927d72a76dd6a9c3b3357 (diff) |
Remove all uses of the PAIR macro in toxav.
Diffstat (limited to 'toxav')
-rw-r--r-- | toxav/BUILD.bazel | 7 | ||||
-rw-r--r-- | toxav/Makefile.inc | 1 | ||||
-rw-r--r-- | toxav/audio.c | 10 | ||||
-rw-r--r-- | toxav/audio.h | 5 | ||||
-rw-r--r-- | toxav/pair.h | 6 | ||||
-rw-r--r-- | toxav/toxav.c | 196 | ||||
-rw-r--r-- | toxav/video.c | 12 | ||||
-rw-r--r-- | toxav/video.h | 5 |
8 files changed, 122 insertions, 120 deletions
diff --git a/toxav/BUILD.bazel b/toxav/BUILD.bazel index ec67d986..1c1b3556 100644 --- a/toxav/BUILD.bazel +++ b/toxav/BUILD.bazel | |||
@@ -65,16 +65,10 @@ cc_test( | |||
65 | ) | 65 | ) |
66 | 66 | ||
67 | cc_library( | 67 | cc_library( |
68 | name = "pair", | ||
69 | hdrs = ["pair.h"], | ||
70 | ) | ||
71 | |||
72 | cc_library( | ||
73 | name = "audio", | 68 | name = "audio", |
74 | srcs = ["audio.c"], | 69 | srcs = ["audio.c"], |
75 | hdrs = ["audio.h"], | 70 | hdrs = ["audio.h"], |
76 | deps = [ | 71 | deps = [ |
77 | ":pair", | ||
78 | ":public", | 72 | ":public", |
79 | ":rtp", | 73 | ":rtp", |
80 | "//c-toxcore/toxcore:network", | 74 | "//c-toxcore/toxcore:network", |
@@ -94,7 +88,6 @@ cc_library( | |||
94 | ], | 88 | ], |
95 | deps = [ | 89 | deps = [ |
96 | ":audio", | 90 | ":audio", |
97 | ":pair", | ||
98 | ":public", | 91 | ":public", |
99 | "//c-toxcore/toxcore:network", | 92 | "//c-toxcore/toxcore:network", |
100 | "@libvpx", | 93 | "@libvpx", |
diff --git a/toxav/Makefile.inc b/toxav/Makefile.inc index 5f6342c0..7b788198 100644 --- a/toxav/Makefile.inc +++ b/toxav/Makefile.inc | |||
@@ -16,7 +16,6 @@ libtoxav_la_SOURCES = ../toxav/rtp.h \ | |||
16 | ../toxav/video.c \ | 16 | ../toxav/video.c \ |
17 | ../toxav/bwcontroller.h \ | 17 | ../toxav/bwcontroller.h \ |
18 | ../toxav/bwcontroller.c \ | 18 | ../toxav/bwcontroller.c \ |
19 | ../toxav/pair.h \ | ||
20 | ../toxav/ring_buffer.h \ | 19 | ../toxav/ring_buffer.h \ |
21 | ../toxav/ring_buffer.c \ | 20 | ../toxav/ring_buffer.c \ |
22 | ../toxav/toxav.h \ | 21 | ../toxav/toxav.h \ |
diff --git a/toxav/audio.c b/toxav/audio.c index 6889ef09..99bb7c97 100644 --- a/toxav/audio.c +++ b/toxav/audio.c | |||
@@ -100,8 +100,8 @@ ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_au | |||
100 | 100 | ||
101 | ac->av = av; | 101 | ac->av = av; |
102 | ac->friend_number = friend_number; | 102 | ac->friend_number = friend_number; |
103 | ac->acb.first = cb; | 103 | ac->acb = cb; |
104 | ac->acb.second = cb_data; | 104 | ac->acb_user_data = cb_data; |
105 | 105 | ||
106 | return ac; | 106 | return ac; |
107 | 107 | ||
@@ -201,11 +201,11 @@ void ac_iterate(ACSession *ac) | |||
201 | 201 | ||
202 | if (rc < 0) { | 202 | if (rc < 0) { |
203 | LOGGER_WARNING(ac->log, "Decoding error: %s", opus_strerror(rc)); | 203 | LOGGER_WARNING(ac->log, "Decoding error: %s", opus_strerror(rc)); |
204 | } else if (ac->acb.first) { | 204 | } else if (ac->acb) { |
205 | ac->lp_frame_duration = (rc * 1000) / ac->lp_sampling_rate; | 205 | ac->lp_frame_duration = (rc * 1000) / ac->lp_sampling_rate; |
206 | 206 | ||
207 | ac->acb.first(ac->av, ac->friend_number, temp_audio_buffer, rc, ac->lp_channel_count, | 207 | ac->acb(ac->av, ac->friend_number, temp_audio_buffer, rc, ac->lp_channel_count, |
208 | ac->lp_sampling_rate, ac->acb.second); | 208 | ac->lp_sampling_rate, ac->acb_user_data); |
209 | } | 209 | } |
210 | 210 | ||
211 | return; | 211 | return; |
diff --git a/toxav/audio.h b/toxav/audio.h index 39d534e0..3c646f76 100644 --- a/toxav/audio.h +++ b/toxav/audio.h | |||
@@ -24,7 +24,6 @@ | |||
24 | 24 | ||
25 | #include "../toxcore/logger.h" | 25 | #include "../toxcore/logger.h" |
26 | #include "../toxcore/util.h" | 26 | #include "../toxcore/util.h" |
27 | #include "pair.h" | ||
28 | 27 | ||
29 | #include <opus.h> | 28 | #include <opus.h> |
30 | #include <pthread.h> | 29 | #include <pthread.h> |
@@ -74,7 +73,9 @@ typedef struct ACSession_s { | |||
74 | 73 | ||
75 | ToxAV *av; | 74 | ToxAV *av; |
76 | uint32_t friend_number; | 75 | uint32_t friend_number; |
77 | PAIR(toxav_audio_receive_frame_cb *, void *) acb; /* Audio frame receive callback */ | 76 | /* Audio frame receive callback */ |
77 | toxav_audio_receive_frame_cb *acb; | ||
78 | void *acb_user_data; | ||
78 | } ACSession; | 79 | } ACSession; |
79 | 80 | ||
80 | ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, | 81 | ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, |
diff --git a/toxav/pair.h b/toxav/pair.h deleted file mode 100644 index 59ef2b62..00000000 --- a/toxav/pair.h +++ /dev/null | |||
@@ -1,6 +0,0 @@ | |||
1 | #ifndef C_TOXCORE_TOXAV_PAIR_H | ||
2 | #define C_TOXCORE_TOXAV_PAIR_H | ||
3 | |||
4 | #define PAIR(TYPE1__, TYPE2__) struct { TYPE1__ first; TYPE2__ second; } | ||
5 | |||
6 | #endif // C_TOXCORE_TOXAV_PAIR_H | ||
diff --git a/toxav/toxav.c b/toxav/toxav.c index df44418f..302657ce 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -54,10 +54,12 @@ typedef struct ToxAVCall_s { | |||
54 | ToxAV *av; | 54 | ToxAV *av; |
55 | 55 | ||
56 | pthread_mutex_t mutex_audio[1]; | 56 | pthread_mutex_t mutex_audio[1]; |
57 | PAIR(RTPSession *, ACSession *) audio; | 57 | RTPSession *audio_rtp; |
58 | ACSession *audio; | ||
58 | 59 | ||
59 | pthread_mutex_t mutex_video[1]; | 60 | pthread_mutex_t mutex_video[1]; |
60 | PAIR(RTPSession *, VCSession *) video; | 61 | RTPSession *video_rtp; |
62 | VCSession *video; | ||
61 | 63 | ||
62 | BWController *bwc; | 64 | BWController *bwc; |
63 | 65 | ||
@@ -87,12 +89,24 @@ struct ToxAV { | |||
87 | uint32_t calls_head; | 89 | uint32_t calls_head; |
88 | pthread_mutex_t mutex[1]; | 90 | pthread_mutex_t mutex[1]; |
89 | 91 | ||
90 | PAIR(toxav_call_cb *, void *) ccb; /* Call callback */ | 92 | /* Call callback */ |
91 | PAIR(toxav_call_state_cb *, void *) scb; /* Call state callback */ | 93 | toxav_call_cb *ccb; |
92 | PAIR(toxav_audio_receive_frame_cb *, void *) acb; /* Audio frame receive callback */ | 94 | void *ccb_user_data; |
93 | PAIR(toxav_video_receive_frame_cb *, void *) vcb; /* Video frame receive callback */ | 95 | /* Call state callback */ |
94 | PAIR(toxav_audio_bit_rate_cb *, void *) abcb; /* Bit rate control callback */ | 96 | toxav_call_state_cb *scb; |
95 | PAIR(toxav_video_bit_rate_cb *, void *) vbcb; /* Bit rate control callback */ | 97 | void *scb_user_data; |
98 | /* Audio frame receive callback */ | ||
99 | toxav_audio_receive_frame_cb *acb; | ||
100 | void *acb_user_data; | ||
101 | /* Video frame receive callback */ | ||
102 | toxav_video_receive_frame_cb *vcb; | ||
103 | void *vcb_user_data; | ||
104 | /* Bit rate control callback */ | ||
105 | toxav_audio_bit_rate_cb *abcb; | ||
106 | void *abcb_user_data; | ||
107 | /* Bit rate control callback */ | ||
108 | toxav_video_bit_rate_cb *vbcb; | ||
109 | void *vbcb_user_data; | ||
96 | 110 | ||
97 | /** Decode time measures */ | 111 | /** Decode time measures */ |
98 | int32_t dmssc; /** Measure count */ | 112 | int32_t dmssc; /** Measure count */ |
@@ -242,17 +256,17 @@ void toxav_iterate(ToxAV *av) | |||
242 | pthread_mutex_lock(i->mutex); | 256 | pthread_mutex_lock(i->mutex); |
243 | pthread_mutex_unlock(av->mutex); | 257 | pthread_mutex_unlock(av->mutex); |
244 | 258 | ||
245 | ac_iterate(i->audio.second); | 259 | ac_iterate(i->audio); |
246 | vc_iterate(i->video.second); | 260 | vc_iterate(i->video); |
247 | 261 | ||
248 | if (i->msi_call->self_capabilities & msi_CapRAudio && | 262 | if (i->msi_call->self_capabilities & msi_CapRAudio && |
249 | i->msi_call->peer_capabilities & msi_CapSAudio) { | 263 | i->msi_call->peer_capabilities & msi_CapSAudio) { |
250 | rc = min_s32(i->audio.second->lp_frame_duration, rc); | 264 | rc = min_s32(i->audio->lp_frame_duration, rc); |
251 | } | 265 | } |
252 | 266 | ||
253 | if (i->msi_call->self_capabilities & msi_CapRVideo && | 267 | if (i->msi_call->self_capabilities & msi_CapRVideo && |
254 | i->msi_call->peer_capabilities & msi_CapSVideo) { | 268 | i->msi_call->peer_capabilities & msi_CapSVideo) { |
255 | rc = min_u32(i->video.second->lcfd, rc); | 269 | rc = min_u32(i->video->lcfd, (uint32_t) rc); |
256 | } | 270 | } |
257 | 271 | ||
258 | uint32_t fid = i->friend_number; | 272 | uint32_t fid = i->friend_number; |
@@ -326,8 +340,8 @@ END: | |||
326 | void toxav_callback_call(ToxAV *av, toxav_call_cb *callback, void *user_data) | 340 | void toxav_callback_call(ToxAV *av, toxav_call_cb *callback, void *user_data) |
327 | { | 341 | { |
328 | pthread_mutex_lock(av->mutex); | 342 | pthread_mutex_lock(av->mutex); |
329 | av->ccb.first = callback; | 343 | av->ccb = callback; |
330 | av->ccb.second = user_data; | 344 | av->ccb_user_data = user_data; |
331 | pthread_mutex_unlock(av->mutex); | 345 | pthread_mutex_unlock(av->mutex); |
332 | } | 346 | } |
333 | bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, | 347 | bool toxav_answer(ToxAV *av, uint32_t friend_number, uint32_t audio_bit_rate, uint32_t video_bit_rate, |
@@ -386,8 +400,8 @@ END: | |||
386 | void toxav_callback_call_state(ToxAV *av, toxav_call_state_cb *callback, void *user_data) | 400 | void toxav_callback_call_state(ToxAV *av, toxav_call_state_cb *callback, void *user_data) |
387 | { | 401 | { |
388 | pthread_mutex_lock(av->mutex); | 402 | pthread_mutex_lock(av->mutex); |
389 | av->scb.first = callback; | 403 | av->scb = callback; |
390 | av->scb.second = user_data; | 404 | av->scb_user_data = user_data; |
391 | pthread_mutex_unlock(av->mutex); | 405 | pthread_mutex_unlock(av->mutex); |
392 | } | 406 | } |
393 | bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL *error) | 407 | bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL control, TOXAV_ERR_CALL_CONTROL *error) |
@@ -420,8 +434,8 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
420 | goto END; | 434 | goto END; |
421 | } | 435 | } |
422 | 436 | ||
423 | rtp_allow_receiving(call->audio.first); | 437 | rtp_allow_receiving(call->audio_rtp); |
424 | rtp_allow_receiving(call->video.first); | 438 | rtp_allow_receiving(call->video_rtp); |
425 | } else { | 439 | } else { |
426 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; | 440 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; |
427 | goto END; | 441 | goto END; |
@@ -439,8 +453,8 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
439 | goto END; | 453 | goto END; |
440 | } | 454 | } |
441 | 455 | ||
442 | rtp_stop_receiving(call->audio.first); | 456 | rtp_stop_receiving(call->audio_rtp); |
443 | rtp_stop_receiving(call->video.first); | 457 | rtp_stop_receiving(call->video_rtp); |
444 | } else { | 458 | } else { |
445 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; | 459 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; |
446 | goto END; | 460 | goto END; |
@@ -475,7 +489,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
475 | goto END; | 489 | goto END; |
476 | } | 490 | } |
477 | 491 | ||
478 | rtp_stop_receiving(call->audio.first); | 492 | rtp_stop_receiving(call->audio_rtp); |
479 | } else { | 493 | } else { |
480 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; | 494 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; |
481 | goto END; | 495 | goto END; |
@@ -491,7 +505,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
491 | goto END; | 505 | goto END; |
492 | } | 506 | } |
493 | 507 | ||
494 | rtp_allow_receiving(call->audio.first); | 508 | rtp_allow_receiving(call->audio_rtp); |
495 | } else { | 509 | } else { |
496 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; | 510 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; |
497 | goto END; | 511 | goto END; |
@@ -507,7 +521,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
507 | goto END; | 521 | goto END; |
508 | } | 522 | } |
509 | 523 | ||
510 | rtp_stop_receiving(call->video.first); | 524 | rtp_stop_receiving(call->video_rtp); |
511 | } else { | 525 | } else { |
512 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; | 526 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; |
513 | goto END; | 527 | goto END; |
@@ -523,7 +537,7 @@ bool toxav_call_control(ToxAV *av, uint32_t friend_number, TOXAV_CALL_CONTROL co | |||
523 | goto END; | 537 | goto END; |
524 | } | 538 | } |
525 | 539 | ||
526 | rtp_allow_receiving(call->video.first); | 540 | rtp_allow_receiving(call->video_rtp); |
527 | } else { | 541 | } else { |
528 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; | 542 | rc = TOXAV_ERR_CALL_CONTROL_INVALID_TRANSITION; |
529 | goto END; | 543 | goto END; |
@@ -688,15 +702,15 @@ END: | |||
688 | void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback, void *user_data) | 702 | void toxav_callback_audio_bit_rate(ToxAV *av, toxav_audio_bit_rate_cb *callback, void *user_data) |
689 | { | 703 | { |
690 | pthread_mutex_lock(av->mutex); | 704 | pthread_mutex_lock(av->mutex); |
691 | av->abcb.first = callback; | 705 | av->abcb = callback; |
692 | av->abcb.second = user_data; | 706 | av->abcb_user_data = user_data; |
693 | pthread_mutex_unlock(av->mutex); | 707 | pthread_mutex_unlock(av->mutex); |
694 | } | 708 | } |
695 | void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback, void *user_data) | 709 | void toxav_callback_video_bit_rate(ToxAV *av, toxav_video_bit_rate_cb *callback, void *user_data) |
696 | { | 710 | { |
697 | pthread_mutex_lock(av->mutex); | 711 | pthread_mutex_lock(av->mutex); |
698 | av->vbcb.first = callback; | 712 | av->vbcb = callback; |
699 | av->vbcb.second = user_data; | 713 | av->vbcb_user_data = user_data; |
700 | pthread_mutex_unlock(av->mutex); | 714 | pthread_mutex_unlock(av->mutex); |
701 | } | 715 | } |
702 | bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count, | 716 | bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pcm, size_t sample_count, |
@@ -747,7 +761,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc | |||
747 | } | 761 | } |
748 | 762 | ||
749 | { /* Encode and send */ | 763 | { /* Encode and send */ |
750 | if (ac_reconfigure_encoder(call->audio.second, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) { | 764 | if (ac_reconfigure_encoder(call->audio, call->audio_bit_rate * 1000, sampling_rate, channels) != 0) { |
751 | pthread_mutex_unlock(call->mutex_audio); | 765 | pthread_mutex_unlock(call->mutex_audio); |
752 | rc = TOXAV_ERR_SEND_FRAME_INVALID; | 766 | rc = TOXAV_ERR_SEND_FRAME_INVALID; |
753 | goto END; | 767 | goto END; |
@@ -757,7 +771,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc | |||
757 | 771 | ||
758 | sampling_rate = net_htonl(sampling_rate); | 772 | sampling_rate = net_htonl(sampling_rate); |
759 | memcpy(dest, &sampling_rate, sizeof(sampling_rate)); | 773 | memcpy(dest, &sampling_rate, sizeof(sampling_rate)); |
760 | int vrc = opus_encode(call->audio.second->encoder, pcm, sample_count, | 774 | int vrc = opus_encode(call->audio->encoder, pcm, sample_count, |
761 | dest + sizeof(sampling_rate), SIZEOF_VLA(dest) - sizeof(sampling_rate)); | 775 | dest + sizeof(sampling_rate), SIZEOF_VLA(dest) - sizeof(sampling_rate)); |
762 | 776 | ||
763 | if (vrc < 0) { | 777 | if (vrc < 0) { |
@@ -767,7 +781,7 @@ bool toxav_audio_send_frame(ToxAV *av, uint32_t friend_number, const int16_t *pc | |||
767 | goto END; | 781 | goto END; |
768 | } | 782 | } |
769 | 783 | ||
770 | if (rtp_send_data(call->audio.first, dest, vrc + sizeof(sampling_rate), false, av->m->log) != 0) { | 784 | if (rtp_send_data(call->audio_rtp, dest, vrc + sizeof(sampling_rate), false, av->m->log) != 0) { |
771 | LOGGER_WARNING(av->m->log, "Failed to send audio packet"); | 785 | LOGGER_WARNING(av->m->log, "Failed to send audio packet"); |
772 | rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; | 786 | rc = TOXAV_ERR_SEND_FRAME_RTP_FAILED; |
773 | } | 787 | } |
@@ -827,24 +841,24 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
827 | goto END; | 841 | goto END; |
828 | } | 842 | } |
829 | 843 | ||
830 | if (vc_reconfigure_encoder(call->video.second, call->video_bit_rate * 1000, width, height, -1) != 0) { | 844 | if (vc_reconfigure_encoder(call->video, call->video_bit_rate * 1000, width, height, -1) != 0) { |
831 | pthread_mutex_unlock(call->mutex_video); | 845 | pthread_mutex_unlock(call->mutex_video); |
832 | rc = TOXAV_ERR_SEND_FRAME_INVALID; | 846 | rc = TOXAV_ERR_SEND_FRAME_INVALID; |
833 | goto END; | 847 | goto END; |
834 | } | 848 | } |
835 | 849 | ||
836 | if (call->video.first->ssrc < VIDEO_SEND_X_KEYFRAMES_FIRST) { | 850 | if (call->video_rtp->ssrc < VIDEO_SEND_X_KEYFRAMES_FIRST) { |
837 | // Key frame flag for first frames | 851 | // Key frame flag for first frames |
838 | vpx_encode_flags = VPX_EFLAG_FORCE_KF; | 852 | vpx_encode_flags = VPX_EFLAG_FORCE_KF; |
839 | LOGGER_INFO(av->m->log, "I_FRAME_FLAG:%d only-i-frame mode", call->video.first->ssrc); | 853 | LOGGER_INFO(av->m->log, "I_FRAME_FLAG:%d only-i-frame mode", call->video_rtp->ssrc); |
840 | 854 | ||
841 | call->video.first->ssrc++; | 855 | call->video_rtp->ssrc++; |
842 | } else if (call->video.first->ssrc == VIDEO_SEND_X_KEYFRAMES_FIRST) { | 856 | } else if (call->video_rtp->ssrc == VIDEO_SEND_X_KEYFRAMES_FIRST) { |
843 | // normal keyframe placement | 857 | // normal keyframe placement |
844 | vpx_encode_flags = 0; | 858 | vpx_encode_flags = 0; |
845 | LOGGER_INFO(av->m->log, "I_FRAME_FLAG:%d normal mode", call->video.first->ssrc); | 859 | LOGGER_INFO(av->m->log, "I_FRAME_FLAG:%d normal mode", call->video_rtp->ssrc); |
846 | 860 | ||
847 | call->video.first->ssrc++; | 861 | call->video_rtp->ssrc++; |
848 | } | 862 | } |
849 | 863 | ||
850 | // we start with I-frames (full frames) and then switch to normal mode later | 864 | // we start with I-frames (full frames) and then switch to normal mode later |
@@ -861,8 +875,8 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
861 | memcpy(img.planes[VPX_PLANE_U], u, (width / 2) * (height / 2)); | 875 | memcpy(img.planes[VPX_PLANE_U], u, (width / 2) * (height / 2)); |
862 | memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2)); | 876 | memcpy(img.planes[VPX_PLANE_V], v, (width / 2) * (height / 2)); |
863 | 877 | ||
864 | vpx_codec_err_t vrc = vpx_codec_encode(call->video.second->encoder, &img, | 878 | vpx_codec_err_t vrc = vpx_codec_encode(call->video->encoder, &img, |
865 | call->video.second->frame_counter, 1, vpx_encode_flags, MAX_ENCODE_TIME_US); | 879 | call->video->frame_counter, 1, vpx_encode_flags, MAX_ENCODE_TIME_US); |
866 | 880 | ||
867 | vpx_img_free(&img); | 881 | vpx_img_free(&img); |
868 | 882 | ||
@@ -874,13 +888,13 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
874 | } | 888 | } |
875 | } | 889 | } |
876 | 890 | ||
877 | ++call->video.second->frame_counter; | 891 | ++call->video->frame_counter; |
878 | 892 | ||
879 | { /* Send frames */ | 893 | { /* Send frames */ |
880 | vpx_codec_iter_t iter = nullptr; | 894 | vpx_codec_iter_t iter = nullptr; |
881 | const vpx_codec_cx_pkt_t *pkt; | 895 | const vpx_codec_cx_pkt_t *pkt; |
882 | 896 | ||
883 | while ((pkt = vpx_codec_get_cx_data(call->video.second->encoder, &iter)) != nullptr) { | 897 | while ((pkt = vpx_codec_get_cx_data(call->video->encoder, &iter)) != nullptr) { |
884 | if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { | 898 | if (pkt->kind == VPX_CODEC_CX_FRAME_PKT) { |
885 | const bool is_keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; | 899 | const bool is_keyframe = (pkt->data.frame.flags & VPX_FRAME_IS_KEY) != 0; |
886 | 900 | ||
@@ -889,7 +903,7 @@ bool toxav_video_send_frame(ToxAV *av, uint32_t friend_number, uint16_t width, u | |||
889 | const uint32_t frame_length_in_bytes = pkt->data.frame.sz; | 903 | const uint32_t frame_length_in_bytes = pkt->data.frame.sz; |
890 | 904 | ||
891 | const int res = rtp_send_data( | 905 | const int res = rtp_send_data( |
892 | call->video.first, | 906 | call->video_rtp, |
893 | (const uint8_t *)pkt->data.frame.buf, | 907 | (const uint8_t *)pkt->data.frame.buf, |
894 | frame_length_in_bytes, | 908 | frame_length_in_bytes, |
895 | is_keyframe, | 909 | is_keyframe, |
@@ -924,16 +938,16 @@ END: | |||
924 | void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb *callback, void *user_data) | 938 | void toxav_callback_audio_receive_frame(ToxAV *av, toxav_audio_receive_frame_cb *callback, void *user_data) |
925 | { | 939 | { |
926 | pthread_mutex_lock(av->mutex); | 940 | pthread_mutex_lock(av->mutex); |
927 | av->acb.first = callback; | 941 | av->acb = callback; |
928 | av->acb.second = user_data; | 942 | av->acb_user_data = user_data; |
929 | pthread_mutex_unlock(av->mutex); | 943 | pthread_mutex_unlock(av->mutex); |
930 | } | 944 | } |
931 | 945 | ||
932 | void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data) | 946 | void toxav_callback_video_receive_frame(ToxAV *av, toxav_video_receive_frame_cb *callback, void *user_data) |
933 | { | 947 | { |
934 | pthread_mutex_lock(av->mutex); | 948 | pthread_mutex_lock(av->mutex); |
935 | av->vcb.first = callback; | 949 | av->vcb = callback; |
936 | av->vcb.second = user_data; | 950 | av->vcb_user_data = user_data; |
937 | pthread_mutex_unlock(av->mutex); | 951 | pthread_mutex_unlock(av->mutex); |
938 | } | 952 | } |
939 | 953 | ||
@@ -964,25 +978,25 @@ void callback_bwc(BWController *bwc, uint32_t friend_number, float loss, void *u | |||
964 | pthread_mutex_lock(call->av->mutex); | 978 | pthread_mutex_lock(call->av->mutex); |
965 | 979 | ||
966 | if (call->video_bit_rate) { | 980 | if (call->video_bit_rate) { |
967 | if (!call->av->vbcb.first) { | 981 | if (!call->av->vbcb) { |
968 | pthread_mutex_unlock(call->av->mutex); | 982 | pthread_mutex_unlock(call->av->mutex); |
969 | LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); | 983 | LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); |
970 | return; | 984 | return; |
971 | } | 985 | } |
972 | 986 | ||
973 | (*call->av->vbcb.first)(call->av, friend_number, | 987 | (*call->av->vbcb)(call->av, friend_number, |
974 | call->video_bit_rate - (call->video_bit_rate * loss), | 988 | call->video_bit_rate - (call->video_bit_rate * loss), |
975 | call->av->vbcb.second); | 989 | call->av->vbcb_user_data); |
976 | } else if (call->audio_bit_rate) { | 990 | } else if (call->audio_bit_rate) { |
977 | if (!call->av->abcb.first) { | 991 | if (!call->av->abcb) { |
978 | pthread_mutex_unlock(call->av->mutex); | 992 | pthread_mutex_unlock(call->av->mutex); |
979 | LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); | 993 | LOGGER_WARNING(call->av->m->log, "No callback to report loss on"); |
980 | return; | 994 | return; |
981 | } | 995 | } |
982 | 996 | ||
983 | (*call->av->abcb.first)(call->av, friend_number, | 997 | (*call->av->abcb)(call->av, friend_number, |
984 | call->audio_bit_rate - (call->audio_bit_rate * loss), | 998 | call->audio_bit_rate - (call->audio_bit_rate * loss), |
985 | call->av->abcb.second); | 999 | call->av->abcb_user_data); |
986 | } | 1000 | } |
987 | 1001 | ||
988 | pthread_mutex_unlock(call->av->mutex); | 1002 | pthread_mutex_unlock(call->av->mutex); |
@@ -1003,9 +1017,9 @@ int callback_invite(void *toxav_inst, MSICall *call) | |||
1003 | call->av_call = av_call; | 1017 | call->av_call = av_call; |
1004 | av_call->msi_call = call; | 1018 | av_call->msi_call = call; |
1005 | 1019 | ||
1006 | if (toxav->ccb.first) { | 1020 | if (toxav->ccb) { |
1007 | toxav->ccb.first(toxav, call->friend_number, call->peer_capabilities & msi_CapSAudio, | 1021 | toxav->ccb(toxav, call->friend_number, call->peer_capabilities & msi_CapSAudio, |
1008 | call->peer_capabilities & msi_CapSVideo, toxav->ccb.second); | 1022 | call->peer_capabilities & msi_CapSVideo, toxav->ccb_user_data); |
1009 | } else { | 1023 | } else { |
1010 | /* No handler to capture the call request, send failure */ | 1024 | /* No handler to capture the call request, send failure */ |
1011 | pthread_mutex_unlock(toxav->mutex); | 1025 | pthread_mutex_unlock(toxav->mutex); |
@@ -1079,15 +1093,15 @@ int callback_capabilites(void *toxav_inst, MSICall *call) | |||
1079 | pthread_mutex_lock(toxav->mutex); | 1093 | pthread_mutex_lock(toxav->mutex); |
1080 | 1094 | ||
1081 | if (call->peer_capabilities & msi_CapSAudio) { | 1095 | if (call->peer_capabilities & msi_CapSAudio) { |
1082 | rtp_allow_receiving(((ToxAVCall *)call->av_call)->audio.first); | 1096 | rtp_allow_receiving(((ToxAVCall *)call->av_call)->audio_rtp); |
1083 | } else { | 1097 | } else { |
1084 | rtp_stop_receiving(((ToxAVCall *)call->av_call)->audio.first); | 1098 | rtp_stop_receiving(((ToxAVCall *)call->av_call)->audio_rtp); |
1085 | } | 1099 | } |
1086 | 1100 | ||
1087 | if (call->peer_capabilities & msi_CapSVideo) { | 1101 | if (call->peer_capabilities & msi_CapSVideo) { |
1088 | rtp_allow_receiving(((ToxAVCall *)call->av_call)->video.first); | 1102 | rtp_allow_receiving(((ToxAVCall *)call->av_call)->video_rtp); |
1089 | } else { | 1103 | } else { |
1090 | rtp_stop_receiving(((ToxAVCall *)call->av_call)->video.first); | 1104 | rtp_stop_receiving(((ToxAVCall *)call->av_call)->video_rtp); |
1091 | } | 1105 | } |
1092 | 1106 | ||
1093 | invoke_call_state_callback(toxav, call->friend_number, call->peer_capabilities); | 1107 | invoke_call_state_callback(toxav, call->friend_number, call->peer_capabilities); |
@@ -1115,8 +1129,8 @@ bool video_bit_rate_invalid(uint32_t bit_rate) | |||
1115 | } | 1129 | } |
1116 | bool invoke_call_state_callback(ToxAV *av, uint32_t friend_number, uint32_t state) | 1130 | bool invoke_call_state_callback(ToxAV *av, uint32_t friend_number, uint32_t state) |
1117 | { | 1131 | { |
1118 | if (av->scb.first) { | 1132 | if (av->scb) { |
1119 | av->scb.first(av, friend_number, state, av->scb.second); | 1133 | av->scb(av, friend_number, state, av->scb_user_data); |
1120 | } else { | 1134 | } else { |
1121 | return false; | 1135 | return false; |
1122 | } | 1136 | } |
@@ -1274,7 +1288,7 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1274 | 1288 | ||
1275 | ToxAV *av = call->av; | 1289 | ToxAV *av = call->av; |
1276 | 1290 | ||
1277 | if (!av->acb.first && !av->vcb.first) { | 1291 | if (!av->acb && !av->vcb) { |
1278 | /* It makes no sense to have CSession without callbacks */ | 1292 | /* It makes no sense to have CSession without callbacks */ |
1279 | return false; | 1293 | return false; |
1280 | } | 1294 | } |
@@ -1300,33 +1314,33 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1300 | call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); | 1314 | call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); |
1301 | 1315 | ||
1302 | { /* Prepare audio */ | 1316 | { /* Prepare audio */ |
1303 | call->audio.second = ac_new(av->m->log, av, call->friend_number, av->acb.first, av->acb.second); | 1317 | call->audio = ac_new(av->m->log, av, call->friend_number, av->acb, av->acb_user_data); |
1304 | 1318 | ||
1305 | if (!call->audio.second) { | 1319 | if (!call->audio) { |
1306 | LOGGER_ERROR(av->m->log, "Failed to create audio codec session"); | 1320 | LOGGER_ERROR(av->m->log, "Failed to create audio codec session"); |
1307 | goto FAILURE; | 1321 | goto FAILURE; |
1308 | } | 1322 | } |
1309 | 1323 | ||
1310 | call->audio.first = rtp_new(rtp_TypeAudio, av->m, call->friend_number, call->bwc, | 1324 | call->audio_rtp = rtp_new(rtp_TypeAudio, av->m, call->friend_number, call->bwc, |
1311 | call->audio.second, ac_queue_message); | 1325 | call->audio, ac_queue_message); |
1312 | 1326 | ||
1313 | if (!call->audio.first) { | 1327 | if (!call->audio_rtp) { |
1314 | LOGGER_ERROR(av->m->log, "Failed to create audio rtp session");; | 1328 | LOGGER_ERROR(av->m->log, "Failed to create audio rtp session");; |
1315 | goto FAILURE; | 1329 | goto FAILURE; |
1316 | } | 1330 | } |
1317 | } | 1331 | } |
1318 | { /* Prepare video */ | 1332 | { /* Prepare video */ |
1319 | call->video.second = vc_new(av->m->log, av, call->friend_number, av->vcb.first, av->vcb.second); | 1333 | call->video = vc_new(av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data); |
1320 | 1334 | ||
1321 | if (!call->video.second) { | 1335 | if (!call->video) { |
1322 | LOGGER_ERROR(av->m->log, "Failed to create video codec session"); | 1336 | LOGGER_ERROR(av->m->log, "Failed to create video codec session"); |
1323 | goto FAILURE; | 1337 | goto FAILURE; |
1324 | } | 1338 | } |
1325 | 1339 | ||
1326 | call->video.first = rtp_new(rtp_TypeVideo, av->m, call->friend_number, call->bwc, | 1340 | call->video_rtp = rtp_new(rtp_TypeVideo, av->m, call->friend_number, call->bwc, |
1327 | call->video.second, vc_queue_message); | 1341 | call->video, vc_queue_message); |
1328 | 1342 | ||
1329 | if (!call->video.first) { | 1343 | if (!call->video_rtp) { |
1330 | LOGGER_ERROR(av->m->log, "Failed to create video rtp session"); | 1344 | LOGGER_ERROR(av->m->log, "Failed to create video rtp session"); |
1331 | goto FAILURE; | 1345 | goto FAILURE; |
1332 | } | 1346 | } |
@@ -1337,14 +1351,14 @@ bool call_prepare_transmission(ToxAVCall *call) | |||
1337 | 1351 | ||
1338 | FAILURE: | 1352 | FAILURE: |
1339 | bwc_kill(call->bwc); | 1353 | bwc_kill(call->bwc); |
1340 | rtp_kill(call->audio.first); | 1354 | rtp_kill(call->audio_rtp); |
1341 | ac_kill(call->audio.second); | 1355 | ac_kill(call->audio); |
1342 | call->audio.first = nullptr; | 1356 | call->audio_rtp = nullptr; |
1343 | call->audio.second = nullptr; | 1357 | call->audio = nullptr; |
1344 | rtp_kill(call->video.first); | 1358 | rtp_kill(call->video_rtp); |
1345 | vc_kill(call->video.second); | 1359 | vc_kill(call->video); |
1346 | call->video.first = nullptr; | 1360 | call->video_rtp = nullptr; |
1347 | call->video.second = nullptr; | 1361 | call->video = nullptr; |
1348 | pthread_mutex_destroy(call->mutex); | 1362 | pthread_mutex_destroy(call->mutex); |
1349 | FAILURE_2: | 1363 | FAILURE_2: |
1350 | pthread_mutex_destroy(call->mutex_video); | 1364 | pthread_mutex_destroy(call->mutex_video); |
@@ -1370,15 +1384,15 @@ void call_kill_transmission(ToxAVCall *call) | |||
1370 | 1384 | ||
1371 | bwc_kill(call->bwc); | 1385 | bwc_kill(call->bwc); |
1372 | 1386 | ||
1373 | rtp_kill(call->audio.first); | 1387 | rtp_kill(call->audio_rtp); |
1374 | ac_kill(call->audio.second); | 1388 | ac_kill(call->audio); |
1375 | call->audio.first = nullptr; | 1389 | call->audio_rtp = nullptr; |
1376 | call->audio.second = nullptr; | 1390 | call->audio = nullptr; |
1377 | 1391 | ||
1378 | rtp_kill(call->video.first); | 1392 | rtp_kill(call->video_rtp); |
1379 | vc_kill(call->video.second); | 1393 | vc_kill(call->video); |
1380 | call->video.first = nullptr; | 1394 | call->video_rtp = nullptr; |
1381 | call->video.second = nullptr; | 1395 | call->video = nullptr; |
1382 | 1396 | ||
1383 | pthread_mutex_destroy(call->mutex_audio); | 1397 | pthread_mutex_destroy(call->mutex_audio); |
1384 | pthread_mutex_destroy(call->mutex_video); | 1398 | pthread_mutex_destroy(call->mutex_video); |
diff --git a/toxav/video.c b/toxav/video.c index 6a5672e3..034a8b56 100644 --- a/toxav/video.c +++ b/toxav/video.c | |||
@@ -258,8 +258,8 @@ VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_vi | |||
258 | */ | 258 | */ |
259 | vc->linfts = current_time_monotonic(); | 259 | vc->linfts = current_time_monotonic(); |
260 | vc->lcfd = 60; | 260 | vc->lcfd = 60; |
261 | vc->vcb.first = cb; | 261 | vc->vcb = cb; |
262 | vc->vcb.second = cb_data; | 262 | vc->vcb_user_data = cb_data; |
263 | vc->friend_number = friend_number; | 263 | vc->friend_number = friend_number; |
264 | vc->av = av; | 264 | vc->av = av; |
265 | vc->log = log; | 265 | vc->log = log; |
@@ -337,10 +337,10 @@ void vc_iterate(VCSession *vc) | |||
337 | vpx_image_t *dest = nullptr; | 337 | vpx_image_t *dest = nullptr; |
338 | 338 | ||
339 | while ((dest = vpx_codec_get_frame(vc->decoder, &iter)) != nullptr) { | 339 | while ((dest = vpx_codec_get_frame(vc->decoder, &iter)) != nullptr) { |
340 | if (vc->vcb.first) { | 340 | if (vc->vcb) { |
341 | vc->vcb.first(vc->av, vc->friend_number, dest->d_w, dest->d_h, | 341 | vc->vcb(vc->av, vc->friend_number, dest->d_w, dest->d_h, |
342 | (const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2], | 342 | (const uint8_t *)dest->planes[0], (const uint8_t *)dest->planes[1], (const uint8_t *)dest->planes[2], |
343 | dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb.second); | 343 | dest->stride[0], dest->stride[1], dest->stride[2], vc->vcb_user_data); |
344 | } | 344 | } |
345 | 345 | ||
346 | vpx_img_free(dest); // is this needed? none of the VPx examples show that | 346 | vpx_img_free(dest); // is this needed? none of the VPx examples show that |
diff --git a/toxav/video.h b/toxav/video.h index 7a0913a0..19ceb9ba 100644 --- a/toxav/video.h +++ b/toxav/video.h | |||
@@ -24,7 +24,6 @@ | |||
24 | 24 | ||
25 | #include "../toxcore/logger.h" | 25 | #include "../toxcore/logger.h" |
26 | #include "../toxcore/util.h" | 26 | #include "../toxcore/util.h" |
27 | #include "pair.h" | ||
28 | 27 | ||
29 | #include <vpx/vpx_decoder.h> | 28 | #include <vpx/vpx_decoder.h> |
30 | #include <vpx/vpx_encoder.h> | 29 | #include <vpx/vpx_encoder.h> |
@@ -55,7 +54,9 @@ typedef struct VCSession_s { | |||
55 | ToxAV *av; | 54 | ToxAV *av; |
56 | uint32_t friend_number; | 55 | uint32_t friend_number; |
57 | 56 | ||
58 | PAIR(toxav_video_receive_frame_cb *, void *) vcb; /* Video frame receive callback */ | 57 | /* Video frame receive callback */ |
58 | toxav_video_receive_frame_cb *vcb; | ||
59 | void *vcb_user_data; | ||
59 | 60 | ||
60 | pthread_mutex_t queue_mutex[1]; | 61 | pthread_mutex_t queue_mutex[1]; |
61 | } VCSession; | 62 | } VCSession; |