summaryrefslogtreecommitdiff
path: root/toxav/rtp.h
diff options
context:
space:
mode:
authorzoff99 <zoff@zoff.cc>2018-01-19 22:59:42 +0100
committeriphydf <iphydf@users.noreply.github.com>2018-02-11 23:31:46 +0000
commit721358208b6650c62aa654be922867f10a5d6f38 (patch)
tree988aef376cc8c74b19b5e605133072bdf3d23e27 /toxav/rtp.h
parent0647c2c5bc8c871dbcaed64de40eb252d13d303c (diff)
Improve video key frame sending.
This change does not include the addition of VP9. We do that in a separate pull request. Changes: * fix the video bug (video frames larger than 65KBytes) by sending full frame length in alternate header field * improve video frame reconstruction logic with slots * configure video encoder and decoder to be multihtreaded * set error resilience flags on video codec * change encoder and decoder softdeadline
Diffstat (limited to 'toxav/rtp.h')
-rw-r--r--toxav/rtp.h63
1 files changed, 56 insertions, 7 deletions
diff --git a/toxav/rtp.h b/toxav/rtp.h
index c8af08d7..a310d58a 100644
--- a/toxav/rtp.h
+++ b/toxav/rtp.h
@@ -66,9 +66,10 @@ enum RTPFlags {
66 RTP_KEY_FRAME = 1 << 1, 66 RTP_KEY_FRAME = 1 << 1,
67}; 67};
68 68
69
69struct RTPHeader { 70struct RTPHeader {
70 /* Standard RTP header */ 71 /* Standard RTP header */
71 unsigned protocol_version: 2; /* Version has only 2 bits! */ 72 unsigned ve: 2; /* Version has only 2 bits! */
72 unsigned pe: 1; /* Padding */ 73 unsigned pe: 1; /* Padding */
73 unsigned xe: 1; /* Extra header */ 74 unsigned xe: 1; /* Extra header */
74 unsigned cc: 4; /* Contributing sources count */ 75 unsigned cc: 4; /* Contributing sources count */
@@ -113,33 +114,71 @@ struct RTPHeader {
113 uint16_t data_length_lower; 114 uint16_t data_length_lower;
114}; 115};
115 116
117
116struct RTPMessage { 118struct RTPMessage {
119 /**
120 * This is used in the old code that doesn't deal with large frames, i.e.
121 * the audio code or receiving code for old 16 bit messages. We use it to
122 * record the number of bytes received so far in a multi-part message. The
123 * multi-part message in the old code is stored in \ref RTPSession::mp.
124 */
117 uint16_t len; 125 uint16_t len;
118 126
119 struct RTPHeader header; 127 struct RTPHeader header;
120 uint8_t data[]; 128 uint8_t data[];
121}; 129};
122 130
131#define USED_RTP_WORKBUFFER_COUNT 3
132
133/**
134 * One slot in the work buffer list. Represents one frame that is currently
135 * being assembled.
136 */
137struct RTPWorkBuffer {
138 /**
139 * Whether this slot contains a key frame. This is true iff
140 * buf->header.flags & RTP_KEY_FRAME.
141 */
142 bool is_keyframe;
143 /**
144 * The number of bytes received so far, regardless of which pieces. I.e. we
145 * could have received the first 1000 bytes and the last 1000 bytes with
146 * 4000 bytes in the middle still to come, and this number would be 2000.
147 */
148 uint32_t received_len;
149 /**
150 * The message currently being assembled.
151 */
152 struct RTPMessage *buf;
153};
154
155struct RTPWorkBufferList {
156 int8_t next_free_entry;
157 struct RTPWorkBuffer work_buffer[USED_RTP_WORKBUFFER_COUNT];
158};
159
160#define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10
161
123/** 162/**
124 * RTP control session. 163 * RTP control session.
125 */ 164 */
126typedef struct { 165typedef struct RTPSession {
127 uint8_t payload_type; 166 uint8_t payload_type;
128 uint16_t sequnum; /* Sending sequence number */ 167 uint16_t sequnum; /* Sending sequence number */
129 uint16_t rsequnum; /* Receiving sequence number */ 168 uint16_t rsequnum; /* Receiving sequence number */
130 uint32_t rtimestamp; 169 uint32_t rtimestamp;
131 uint32_t ssrc; 170 uint32_t ssrc; // this seems to be unused!?
132
133 struct RTPMessage *mp; /* Expected parted message */ 171 struct RTPMessage *mp; /* Expected parted message */
134 172 struct RTPWorkBufferList *work_buffer_list;
173 uint8_t first_packets_counter; /* dismiss first few lost video packets */
135 Messenger *m; 174 Messenger *m;
136 uint32_t friend_number; 175 uint32_t friend_number;
137
138 BWController *bwc; 176 BWController *bwc;
139 void *cs; 177 void *cs;
140 int (*mcb)(void *, struct RTPMessage *msg); 178 int (*mcb)(void *, struct RTPMessage *msg);
141} RTPSession; 179} RTPSession;
142 180
181
143/** 182/**
144 * Serialise an RTPHeader to bytes to be sent over the network. 183 * Serialise an RTPHeader to bytes to be sent over the network.
145 * 184 *
@@ -164,7 +203,17 @@ RTPSession *rtp_new(int payload_type, Messenger *m, uint32_t friendnumber,
164void rtp_kill(RTPSession *session); 203void rtp_kill(RTPSession *session);
165int rtp_allow_receiving(RTPSession *session); 204int rtp_allow_receiving(RTPSession *session);
166int rtp_stop_receiving(RTPSession *session); 205int rtp_stop_receiving(RTPSession *session);
167int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Logger *log); 206/**
207 * Send a frame of audio or video data, chunked in \ref RTPMessage instances.
208 *
209 * @param session The A/V session to send the data for.
210 * @param data A byte array of length \p length.
211 * @param length The number of bytes to send from @p data.
212 * @param is_keyframe Whether this video frame is a key frame. If it is an
213 * audio frame, this parameter is ignored.
214 */
215int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
216 bool is_keyframe, Logger *log);
168 217
169#ifdef __cplusplus 218#ifdef __cplusplus
170} // extern "C" 219} // extern "C"