diff options
author | Diadlo <polsha3@gmail.com> | 2017-01-07 11:28:53 +0300 |
---|---|---|
committer | Diadlo <polsha3@gmail.com> | 2017-02-26 23:16:16 +0300 |
commit | b19a9e54643eceaa52e71c0f38fa2ecae5a6809e (patch) | |
tree | 4c6fff0a086988ab21636e88dbf65c2e40a76a67 /toxav/rtp.c | |
parent | b2d04eae9d9b76523b877a9e5efd5989f83b143d (diff) |
Add part of platform-independent network API implementation
socket -> net_socket
htons -> net_htons
htonl -> net_htonl
connect -> net_connect
sendto -> net_sendto_ip4
getaddrinfo -> net_getipport
sa_family_t -> Family
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r-- | toxav/rtp.c | 52 |
1 files changed, 26 insertions, 26 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c index 9403a43d..6f939082 100644 --- a/toxav/rtp.c +++ b/toxav/rtp.c | |||
@@ -131,12 +131,12 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log | |||
131 | header->ma = 0; | 131 | header->ma = 0; |
132 | header->pt = session->payload_type % 128; | 132 | header->pt = session->payload_type % 128; |
133 | 133 | ||
134 | header->sequnum = htons(session->sequnum); | 134 | header->sequnum = net_htons(session->sequnum); |
135 | header->timestamp = htonl(current_time_monotonic()); | 135 | header->timestamp = net_htonl(current_time_monotonic()); |
136 | header->ssrc = htonl(session->ssrc); | 136 | header->ssrc = net_htonl(session->ssrc); |
137 | 137 | ||
138 | header->cpart = 0; | 138 | header->cpart = 0; |
139 | header->tlen = htons(length); | 139 | header->tlen = net_htons(length); |
140 | 140 | ||
141 | if (MAX_CRYPTO_DATA_SIZE > length + sizeof(struct RTPHeader) + 1) { | 141 | if (MAX_CRYPTO_DATA_SIZE > length + sizeof(struct RTPHeader) + 1) { |
142 | 142 | ||
@@ -170,7 +170,7 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log | |||
170 | } | 170 | } |
171 | 171 | ||
172 | sent += piece; | 172 | sent += piece; |
173 | header->cpart = htons(sent); | 173 | header->cpart = net_htons(sent); |
174 | } | 174 | } |
175 | 175 | ||
176 | /* Send remaining */ | 176 | /* Send remaining */ |
@@ -194,10 +194,10 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint16_t length, Log | |||
194 | 194 | ||
195 | static bool chloss(const RTPSession *session, const struct RTPHeader *header) | 195 | static bool chloss(const RTPSession *session, const struct RTPHeader *header) |
196 | { | 196 | { |
197 | if (ntohl(header->timestamp) < session->rtimestamp) { | 197 | if (net_ntohl(header->timestamp) < session->rtimestamp) { |
198 | uint16_t hosq, lost = 0; | 198 | uint16_t hosq, lost = 0; |
199 | 199 | ||
200 | hosq = ntohs(header->sequnum); | 200 | hosq = net_ntohs(header->sequnum); |
201 | 201 | ||
202 | lost = (hosq > session->rsequnum) ? | 202 | lost = (hosq > session->rsequnum) ? |
203 | (session->rsequnum + 65535) - hosq : | 203 | (session->rsequnum + 65535) - hosq : |
@@ -224,12 +224,12 @@ static struct RTPMessage *new_message(size_t allocate_len, const uint8_t *data, | |||
224 | msg->len = data_length - sizeof(struct RTPHeader); | 224 | msg->len = data_length - sizeof(struct RTPHeader); |
225 | memcpy(&msg->header, data, data_length); | 225 | memcpy(&msg->header, data, data_length); |
226 | 226 | ||
227 | msg->header.sequnum = ntohs(msg->header.sequnum); | 227 | msg->header.sequnum = net_ntohs(msg->header.sequnum); |
228 | msg->header.timestamp = ntohl(msg->header.timestamp); | 228 | msg->header.timestamp = net_ntohl(msg->header.timestamp); |
229 | msg->header.ssrc = ntohl(msg->header.ssrc); | 229 | msg->header.ssrc = net_ntohl(msg->header.ssrc); |
230 | 230 | ||
231 | msg->header.cpart = ntohs(msg->header.cpart); | 231 | msg->header.cpart = net_ntohs(msg->header.cpart); |
232 | msg->header.tlen = ntohs(msg->header.tlen); | 232 | msg->header.tlen = net_ntohs(msg->header.tlen); |
233 | 233 | ||
234 | return msg; | 234 | return msg; |
235 | } | 235 | } |
@@ -255,14 +255,14 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, | |||
255 | return -1; | 255 | return -1; |
256 | } | 256 | } |
257 | 257 | ||
258 | if (ntohs(header->cpart) >= ntohs(header->tlen)) { | 258 | if (net_ntohs(header->cpart) >= net_ntohs(header->tlen)) { |
259 | /* Never allow this case to happen */ | 259 | /* Never allow this case to happen */ |
260 | return -1; | 260 | return -1; |
261 | } | 261 | } |
262 | 262 | ||
263 | bwc_feed_avg(session->bwc, length); | 263 | bwc_feed_avg(session->bwc, length); |
264 | 264 | ||
265 | if (ntohs(header->tlen) == length - sizeof(struct RTPHeader)) { | 265 | if (net_ntohs(header->tlen) == length - sizeof(struct RTPHeader)) { |
266 | /* The message is sent in single part */ | 266 | /* The message is sent in single part */ |
267 | 267 | ||
268 | /* Only allow messages which have arrived in order; | 268 | /* Only allow messages which have arrived in order; |
@@ -273,8 +273,8 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, | |||
273 | } | 273 | } |
274 | 274 | ||
275 | /* Message is not late; pick up the latest parameters */ | 275 | /* Message is not late; pick up the latest parameters */ |
276 | session->rsequnum = ntohs(header->sequnum); | 276 | session->rsequnum = net_ntohs(header->sequnum); |
277 | session->rtimestamp = ntohl(header->timestamp); | 277 | session->rtimestamp = net_ntohl(header->timestamp); |
278 | 278 | ||
279 | bwc_add_recv(session->bwc, length); | 279 | bwc_add_recv(session->bwc, length); |
280 | 280 | ||
@@ -311,20 +311,20 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, | |||
311 | * processing message | 311 | * processing message |
312 | */ | 312 | */ |
313 | 313 | ||
314 | if (session->mp->header.sequnum == ntohs(header->sequnum) && | 314 | if (session->mp->header.sequnum == net_ntohs(header->sequnum) && |
315 | session->mp->header.timestamp == ntohl(header->timestamp)) { | 315 | session->mp->header.timestamp == net_ntohl(header->timestamp)) { |
316 | /* First case */ | 316 | /* First case */ |
317 | 317 | ||
318 | /* Make sure we have enough allocated memory */ | 318 | /* Make sure we have enough allocated memory */ |
319 | if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) || | 319 | if (session->mp->header.tlen - session->mp->len < length - sizeof(struct RTPHeader) || |
320 | session->mp->header.tlen <= ntohs(header->cpart)) { | 320 | session->mp->header.tlen <= net_ntohs(header->cpart)) { |
321 | /* There happened to be some corruption on the stream; | 321 | /* There happened to be some corruption on the stream; |
322 | * continue wihtout this part | 322 | * continue wihtout this part |
323 | */ | 323 | */ |
324 | return 0; | 324 | return 0; |
325 | } | 325 | } |
326 | 326 | ||
327 | memcpy(session->mp->data + ntohs(header->cpart), data + sizeof(struct RTPHeader), | 327 | memcpy(session->mp->data + net_ntohs(header->cpart), data + sizeof(struct RTPHeader), |
328 | length - sizeof(struct RTPHeader)); | 328 | length - sizeof(struct RTPHeader)); |
329 | 329 | ||
330 | session->mp->len += length - sizeof(struct RTPHeader); | 330 | session->mp->len += length - sizeof(struct RTPHeader); |
@@ -346,7 +346,7 @@ int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t *data, | |||
346 | } else { | 346 | } else { |
347 | /* Second case */ | 347 | /* Second case */ |
348 | 348 | ||
349 | if (session->mp->header.timestamp > ntohl(header->timestamp)) { | 349 | if (session->mp->header.timestamp > net_ntohl(header->timestamp)) { |
350 | /* The received message part is from the old message; | 350 | /* The received message part is from the old message; |
351 | * discard it. | 351 | * discard it. |
352 | */ | 352 | */ |
@@ -386,22 +386,22 @@ NEW_MULTIPARTED: | |||
386 | } | 386 | } |
387 | 387 | ||
388 | /* Message is not late; pick up the latest parameters */ | 388 | /* Message is not late; pick up the latest parameters */ |
389 | session->rsequnum = ntohs(header->sequnum); | 389 | session->rsequnum = net_ntohs(header->sequnum); |
390 | session->rtimestamp = ntohl(header->timestamp); | 390 | session->rtimestamp = net_ntohl(header->timestamp); |
391 | 391 | ||
392 | bwc_add_recv(session->bwc, length); | 392 | bwc_add_recv(session->bwc, length); |
393 | 393 | ||
394 | /* Again, only store message if handler is present | 394 | /* Again, only store message if handler is present |
395 | */ | 395 | */ |
396 | if (session->mcb) { | 396 | if (session->mcb) { |
397 | session->mp = new_message(ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); | 397 | session->mp = new_message(net_ntohs(header->tlen) + sizeof(struct RTPHeader), data, length); |
398 | 398 | ||
399 | /* Reposition data if necessary */ | 399 | /* Reposition data if necessary */ |
400 | if (ntohs(header->cpart)) { | 400 | if (net_ntohs(header->cpart)) { |
401 | ; | 401 | ; |
402 | } | 402 | } |
403 | 403 | ||
404 | memmove(session->mp->data + ntohs(header->cpart), session->mp->data, session->mp->len); | 404 | memmove(session->mp->data + net_ntohs(header->cpart), session->mp->data, session->mp->len); |
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||