diff options
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r-- | toxav/rtp.c | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index ca4a4a7b..61297937 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -35,13 +35,11 @@ | |||
35 | #include "../toxcore/mono_time.h" | 35 | #include "../toxcore/mono_time.h" |
36 | #include "../toxcore/util.h" | 36 | #include "../toxcore/util.h" |
37 | 37 | ||
38 | enum { | 38 | /** |
39 | /** | 39 | * The number of milliseconds we want to keep a keyframe in the buffer for, |
40 | * The number of milliseconds we want to keep a keyframe in the buffer for, | 40 | * even though there are no free slots for incoming frames. |
41 | * even though there are no free slots for incoming frames. | 41 | */ |
42 | */ | 42 | #define VIDEO_KEEP_KEYFRAME_IN_BUFFER_FOR_MS 15 |
43 | VIDEO_KEEP_KEYFRAME_IN_BUFFER_FOR_MS = 15, | ||
44 | }; | ||
45 | 43 | ||
46 | // allocate_len is NOT including header! | 44 | // allocate_len is NOT including header! |
47 | static struct RTPMessage *new_message(const struct RTPHeader *header, size_t allocate_len, const uint8_t *data, | 45 | static struct RTPMessage *new_message(const struct RTPHeader *header, size_t allocate_len, const uint8_t *data, |
@@ -60,16 +58,15 @@ static struct RTPMessage *new_message(const struct RTPHeader *header, size_t all | |||
60 | return msg; | 58 | return msg; |
61 | } | 59 | } |
62 | 60 | ||
63 | enum { | 61 | /** |
64 | /** | 62 | * Instruct the caller to clear slot 0. |
65 | * Instruct the caller to clear slot 0. | 63 | */ |
66 | */ | 64 | #define GET_SLOT_RESULT_DROP_OLDEST_SLOT (-1) |
67 | GET_SLOT_RESULT_DROP_OLDEST_SLOT = -1, | 65 | |
68 | /** | 66 | /** |
69 | * Instruct the caller to drop the incoming packet. | 67 | * Instruct the caller to drop the incoming packet. |
70 | */ | 68 | */ |
71 | GET_SLOT_RESULT_DROP_INCOMING = -2, | 69 | #define GET_SLOT_RESULT_DROP_INCOMING (-2) |
72 | }; | ||
73 | 70 | ||
74 | /** | 71 | /** |
75 | * Find the next free slot in work_buffer for the incoming data packet. | 72 | * Find the next free slot in work_buffer for the incoming data packet. |
@@ -89,7 +86,7 @@ static int8_t get_slot(const Logger *log, struct RTPWorkBufferList *wkbl, bool i | |||
89 | if (is_multipart) { | 86 | if (is_multipart) { |
90 | // This RTP message is part of a multipart frame, so we try to find an | 87 | // This RTP message is part of a multipart frame, so we try to find an |
91 | // existing slot with the previous parts of the frame in it. | 88 | // existing slot with the previous parts of the frame in it. |
92 | for (uint8_t i = 0; i < wkbl->next_free_entry; i++) { | 89 | for (uint8_t i = 0; i < wkbl->next_free_entry; ++i) { |
93 | const struct RTPWorkBuffer *slot = &wkbl->work_buffer[i]; | 90 | const struct RTPWorkBuffer *slot = &wkbl->work_buffer[i]; |
94 | 91 | ||
95 | if ((slot->buf->header.sequnum == header->sequnum) && (slot->buf->header.timestamp == header->timestamp)) { | 92 | if ((slot->buf->header.sequnum == header->sequnum) && (slot->buf->header.timestamp == header->timestamp)) { |
@@ -228,14 +225,14 @@ static struct RTPMessage *process_frame(const Logger *log, struct RTPWorkBufferL | |||
228 | if (slot_id != wkbl->next_free_entry - 1) { | 225 | if (slot_id != wkbl->next_free_entry - 1) { |
229 | // The slot is not the last slot, so we created a gap. We move all the | 226 | // The slot is not the last slot, so we created a gap. We move all the |
230 | // entries after it one step up. | 227 | // entries after it one step up. |
231 | for (uint8_t i = slot_id; i < wkbl->next_free_entry - 1; i++) { | 228 | for (uint8_t i = slot_id; i < wkbl->next_free_entry - 1; ++i) { |
232 | // Move entry (i+1) into entry (i). | 229 | // Move entry (i+1) into entry (i). |
233 | wkbl->work_buffer[i] = wkbl->work_buffer[i + 1]; | 230 | wkbl->work_buffer[i] = wkbl->work_buffer[i + 1]; |
234 | } | 231 | } |
235 | } | 232 | } |
236 | 233 | ||
237 | // We now have a free entry at the end of the array. | 234 | // We now have a free entry at the end of the array. |
238 | wkbl->next_free_entry--; | 235 | --wkbl->next_free_entry; |
239 | 236 | ||
240 | // Clear the newly freed entry. | 237 | // Clear the newly freed entry. |
241 | const struct RTPWorkBuffer empty = {0}; | 238 | const struct RTPWorkBuffer empty = {0}; |
@@ -290,7 +287,7 @@ static bool fill_data_into_slot(const Logger *log, struct RTPWorkBufferList *wkb | |||
290 | slot->received_len = 0; | 287 | slot->received_len = 0; |
291 | 288 | ||
292 | assert(wkbl->next_free_entry < USED_RTP_WORKBUFFER_COUNT); | 289 | assert(wkbl->next_free_entry < USED_RTP_WORKBUFFER_COUNT); |
293 | wkbl->next_free_entry++; | 290 | ++wkbl->next_free_entry; |
294 | } | 291 | } |
295 | 292 | ||
296 | // We already checked this when we received the packet, but we rely on it | 293 | // We already checked this when we received the packet, but we rely on it |
@@ -317,7 +314,7 @@ static bool fill_data_into_slot(const Logger *log, struct RTPWorkBufferList *wkb | |||
317 | static void update_bwc_values(const Logger *log, RTPSession *session, const struct RTPMessage *msg) | 314 | static void update_bwc_values(const Logger *log, RTPSession *session, const struct RTPMessage *msg) |
318 | { | 315 | { |
319 | if (session->first_packets_counter < DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT) { | 316 | if (session->first_packets_counter < DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT) { |
320 | session->first_packets_counter++; | 317 | ++session->first_packets_counter; |
321 | } else { | 318 | } else { |
322 | uint32_t data_length_full = msg->header.data_length_full; // without header | 319 | uint32_t data_length_full = msg->header.data_length_full; // without header |
323 | uint32_t received_length_full = msg->header.received_length_full; // without header | 320 | uint32_t received_length_full = msg->header.received_length_full; // without header |
@@ -586,12 +583,14 @@ NEW_MULTIPARTED: | |||
586 | size_t rtp_header_pack(uint8_t *const rdata, const struct RTPHeader *header) | 583 | size_t rtp_header_pack(uint8_t *const rdata, const struct RTPHeader *header) |
587 | { | 584 | { |
588 | uint8_t *p = rdata; | 585 | uint8_t *p = rdata; |
589 | *p++ = (header->ve & 3) << 6 | 586 | *p = (header->ve & 3) << 6 |
590 | | (header->pe & 1) << 5 | 587 | | (header->pe & 1) << 5 |
591 | | (header->xe & 1) << 4 | 588 | | (header->xe & 1) << 4 |
592 | | (header->cc & 0xf); | 589 | | (header->cc & 0xf); |
593 | *p++ = (header->ma & 1) << 7 | 590 | ++p; |
594 | | (header->pt & 0x7f); | 591 | *p = (header->ma & 1) << 7 |
592 | | (header->pt & 0x7f); | ||
593 | ++p; | ||
595 | 594 | ||
596 | p += net_pack_u16(p, header->sequnum); | 595 | p += net_pack_u16(p, header->sequnum); |
597 | p += net_pack_u32(p, header->timestamp); | 596 | p += net_pack_u32(p, header->timestamp); |
@@ -601,7 +600,7 @@ size_t rtp_header_pack(uint8_t *const rdata, const struct RTPHeader *header) | |||
601 | p += net_pack_u32(p, header->data_length_full); | 600 | p += net_pack_u32(p, header->data_length_full); |
602 | p += net_pack_u32(p, header->received_length_full); | 601 | p += net_pack_u32(p, header->received_length_full); |
603 | 602 | ||
604 | for (size_t i = 0; i < RTP_PADDING_FIELDS; i++) { | 603 | for (size_t i = 0; i < RTP_PADDING_FIELDS; ++i) { |
605 | p += net_pack_u32(p, 0); | 604 | p += net_pack_u32(p, 0); |
606 | } | 605 | } |
607 | 606 | ||
@@ -640,10 +639,8 @@ size_t rtp_header_unpack(const uint8_t *data, struct RTPHeader *header) | |||
640 | return p - data; | 639 | return p - data; |
641 | } | 640 | } |
642 | 641 | ||
643 | |||
644 | RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber, | 642 | RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber, |
645 | BWController *bwc, void *cs, | 643 | BWController *bwc, void *cs, rtp_m_cb *mcb) |
646 | int (*mcb)(void *, struct RTPMessage *)) | ||
647 | { | 644 | { |
648 | assert(mcb != nullptr); | 645 | assert(mcb != nullptr); |
649 | assert(cs != nullptr); | 646 | assert(cs != nullptr); |
@@ -851,6 +848,6 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length, | |||
851 | } | 848 | } |
852 | } | 849 | } |
853 | 850 | ||
854 | session->sequnum ++; | 851 | ++session->sequnum; |
855 | return 0; | 852 | return 0; |
856 | } | 853 | } |