diff options
author | zoff99 <zoff@zoff.cc> | 2020-04-08 19:58:06 +0200 |
---|---|---|
committer | iphydf <iphydf@users.noreply.github.com> | 2020-04-09 11:51:34 +0000 |
commit | af6e27bbf1b447e6e85520b965f009b7ece81004 (patch) | |
tree | fc9a0523adfd2303732f00e7e0b1742205943167 /toxav/rtp.c | |
parent | 2a79748ed955c4f8670adb6f04f3217f641e8965 (diff) |
Use public API for sending in RTP.
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r-- | toxav/rtp.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index f48c483b..69aed2dc 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -26,6 +26,23 @@ | |||
26 | */ | 26 | */ |
27 | #define VIDEO_KEEP_KEYFRAME_IN_BUFFER_FOR_MS 15 | 27 | #define VIDEO_KEEP_KEYFRAME_IN_BUFFER_FOR_MS 15 |
28 | 28 | ||
29 | |||
30 | /* | ||
31 | * return -1 on failure, 0 on success | ||
32 | * | ||
33 | */ | ||
34 | static int rtp_send_custom_lossy_packet(Tox *tox, int32_t friendnumber, const uint8_t *data, uint32_t length) | ||
35 | { | ||
36 | Tox_Err_Friend_Custom_Packet error; | ||
37 | tox_friend_send_lossy_packet(tox, friendnumber, data, (size_t)length, &error); | ||
38 | |||
39 | if (error == TOX_ERR_FRIEND_CUSTOM_PACKET_OK) { | ||
40 | return 0; | ||
41 | } | ||
42 | |||
43 | return -1; | ||
44 | } | ||
45 | |||
29 | // allocate_len is NOT including header! | 46 | // allocate_len is NOT including header! |
30 | static struct RTPMessage *new_message(const struct RTPHeader *header, size_t allocate_len, const uint8_t *data, | 47 | static struct RTPMessage *new_message(const struct RTPHeader *header, size_t allocate_len, const uint8_t *data, |
31 | uint16_t data_length) | 48 | uint16_t data_length) |
@@ -626,7 +643,7 @@ size_t rtp_header_unpack(const uint8_t *data, struct RTPHeader *header) | |||
626 | return p - data; | 643 | return p - data; |
627 | } | 644 | } |
628 | 645 | ||
629 | RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber, | 646 | RTPSession *rtp_new(int payload_type, Messenger *m, Tox *tox, uint32_t friendnumber, |
630 | BWController *bwc, void *cs, rtp_m_cb *mcb) | 647 | BWController *bwc, void *cs, rtp_m_cb *mcb) |
631 | { | 648 | { |
632 | assert(mcb != nullptr); | 649 | assert(mcb != nullptr); |
@@ -654,6 +671,7 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber, | |||
654 | session->ssrc = payload_type == RTP_TYPE_VIDEO ? 0 : random_u32(); | 671 | session->ssrc = payload_type == RTP_TYPE_VIDEO ? 0 : random_u32(); |
655 | session->payload_type = payload_type; | 672 | session->payload_type = payload_type; |
656 | session->m = m; | 673 | session->m = m; |
674 | session->tox = tox; | ||
657 | session->friend_number = friendnumber; | 675 | session->friend_number = friendnumber; |
658 | 676 | ||
659 | // set NULL just in case | 677 | // set NULL just in case |
@@ -787,7 +805,7 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | |||
787 | rtp_header_pack(rdata + 1, &header); | 805 | rtp_header_pack(rdata + 1, &header); |
788 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length); | 806 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data, length); |
789 | 807 | ||
790 | if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, SIZEOF_VLA(rdata))) { | 808 | if (-1 == rtp_send_custom_lossy_packet(session->tox, session->friend_number, rdata, SIZEOF_VLA(rdata))) { |
791 | const char *netstrerror = net_new_strerror(net_error()); | 809 | const char *netstrerror = net_new_strerror(net_error()); |
792 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %u)! std error: %s, net error: %s", | 810 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %u)! std error: %s, net error: %s", |
793 | (unsigned)SIZEOF_VLA(rdata), strerror(errno), netstrerror); | 811 | (unsigned)SIZEOF_VLA(rdata), strerror(errno), netstrerror); |
@@ -805,8 +823,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | |||
805 | rtp_header_pack(rdata + 1, &header); | 823 | rtp_header_pack(rdata + 1, &header); |
806 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece); | 824 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece); |
807 | 825 | ||
808 | if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, | 826 | if (-1 == rtp_send_custom_lossy_packet(session->tox, session->friend_number, |
809 | rdata, piece + RTP_HEADER_SIZE + 1)) { | 827 | rdata, piece + RTP_HEADER_SIZE + 1)) { |
810 | const char *netstrerror = net_new_strerror(net_error()); | 828 | const char *netstrerror = net_new_strerror(net_error()); |
811 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s, net error: %s", | 829 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s, net error: %s", |
812 | piece + RTP_HEADER_SIZE + 1, strerror(errno), netstrerror); | 830 | piece + RTP_HEADER_SIZE + 1, strerror(errno), netstrerror); |
@@ -825,8 +843,8 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | |||
825 | rtp_header_pack(rdata + 1, &header); | 843 | rtp_header_pack(rdata + 1, &header); |
826 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece); | 844 | memcpy(rdata + 1 + RTP_HEADER_SIZE, data + sent, piece); |
827 | 845 | ||
828 | if (-1 == m_send_custom_lossy_packet(session->m, session->friend_number, rdata, | 846 | if (-1 == rtp_send_custom_lossy_packet(session->tox, session->friend_number, rdata, |
829 | piece + RTP_HEADER_SIZE + 1)) { | 847 | piece + RTP_HEADER_SIZE + 1)) { |
830 | const char *netstrerror = net_new_strerror(net_error()); | 848 | const char *netstrerror = net_new_strerror(net_error()); |
831 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s, net error: %s", | 849 | LOGGER_WARNING(session->m->log, "RTP send failed (len: %d)! std error: %s, net error: %s", |
832 | piece + RTP_HEADER_SIZE + 1, strerror(errno), netstrerror); | 850 | piece + RTP_HEADER_SIZE + 1, strerror(errno), netstrerror); |