summaryrefslogtreecommitdiff
path: root/toxav
diff options
context:
space:
mode:
authorzugz (tox) <mbays+tox@sdf.org>2018-08-17 19:22:18 +0200
committerzugz (tox) <mbays+tox@sdf.org>2018-08-19 23:41:43 +0200
commit14484c6879ff5796d962b49aa76a7f3e04c2319c (patch)
treec02cf58bb7e047d01f5493d811a75eec2dfaecee /toxav
parente32e0b3402006dabfc44e9a3eb1e806d9d3fc00d (diff)
make Mono_Time an argument to current_time_monotonic
Diffstat (limited to 'toxav')
-rw-r--r--toxav/audio.c10
-rw-r--r--toxav/audio.h7
-rw-r--r--toxav/bwcontroller.c10
-rw-r--r--toxav/rtp.c16
-rw-r--r--toxav/rtp.h2
-rw-r--r--toxav/toxav.c8
-rw-r--r--toxav/video.c11
-rw-r--r--toxav/video.h6
8 files changed, 37 insertions, 33 deletions
diff --git a/toxav/audio.c b/toxav/audio.c
index 729a4922..f1284f54 100644
--- a/toxav/audio.c
+++ b/toxav/audio.c
@@ -44,7 +44,8 @@ static bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8
44 44
45 45
46 46
47ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, void *cb_data) 47ACSession *ac_new(const Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number,
48 toxav_audio_receive_frame_cb *cb, void *cb_data)
48{ 49{
49 ACSession *ac = (ACSession *)calloc(sizeof(ACSession), 1); 50 ACSession *ac = (ACSession *)calloc(sizeof(ACSession), 1);
50 51
@@ -75,6 +76,7 @@ ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_au
75 goto BASE_CLEANUP; 76 goto BASE_CLEANUP;
76 } 77 }
77 78
79 ac->mono_time = mono_time;
78 ac->log = log; 80 ac->log = log;
79 81
80 /* Initialize encoders with default values */ 82 /* Initialize encoders with default values */
@@ -214,7 +216,7 @@ void ac_iterate(ACSession *ac)
214 pthread_mutex_unlock(ac->queue_mutex); 216 pthread_mutex_unlock(ac->queue_mutex);
215} 217}
216 218
217int ac_queue_message(void *acp, struct RTPMessage *msg) 219int ac_queue_message(const Mono_Time *mono_time, void *acp, struct RTPMessage *msg)
218{ 220{
219 if (!acp || !msg) { 221 if (!acp || !msg) {
220 return -1; 222 return -1;
@@ -496,7 +498,7 @@ bool reconfigure_audio_encoder(const Logger *log, OpusEncoder **e, int32_t new_b
496bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels) 498bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t channels)
497{ 499{
498 if (sampling_rate != ac->ld_sample_rate || channels != ac->ld_channel_count) { 500 if (sampling_rate != ac->ld_sample_rate || channels != ac->ld_channel_count) {
499 if (current_time_monotonic() - ac->ldrts < 500) { 501 if (current_time_monotonic(ac->mono_time) - ac->ldrts < 500) {
500 return false; 502 return false;
501 } 503 }
502 504
@@ -510,7 +512,7 @@ bool reconfigure_audio_decoder(ACSession *ac, int32_t sampling_rate, int8_t chan
510 512
511 ac->ld_sample_rate = sampling_rate; 513 ac->ld_sample_rate = sampling_rate;
512 ac->ld_channel_count = channels; 514 ac->ld_channel_count = channels;
513 ac->ldrts = current_time_monotonic(); 515 ac->ldrts = current_time_monotonic(ac->mono_time);
514 516
515 opus_decoder_destroy(ac->decoder); 517 opus_decoder_destroy(ac->decoder);
516 ac->decoder = new_dec; 518 ac->decoder = new_dec;
diff --git a/toxav/audio.h b/toxav/audio.h
index f71aaed3..6a19e6b6 100644
--- a/toxav/audio.h
+++ b/toxav/audio.h
@@ -50,6 +50,7 @@
50#define AUDIO_MAX_BUFFER_SIZE_BYTES (AUDIO_MAX_BUFFER_SIZE_PCM16 * 2) 50#define AUDIO_MAX_BUFFER_SIZE_BYTES (AUDIO_MAX_BUFFER_SIZE_PCM16 * 2)
51 51
52typedef struct ACSession_s { 52typedef struct ACSession_s {
53 const Mono_Time *mono_time;
53 const Logger *log; 54 const Logger *log;
54 55
55 /* encoding */ 56 /* encoding */
@@ -77,11 +78,11 @@ typedef struct ACSession_s {
77 void *acb_user_data; 78 void *acb_user_data;
78} ACSession; 79} ACSession;
79 80
80ACSession *ac_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_audio_receive_frame_cb *cb, 81ACSession *ac_new(const Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number,
81 void *cb_data); 82 toxav_audio_receive_frame_cb *cb, void *cb_data);
82void ac_kill(ACSession *ac); 83void ac_kill(ACSession *ac);
83void ac_iterate(ACSession *ac); 84void ac_iterate(ACSession *ac);
84int ac_queue_message(void *acp, struct RTPMessage *msg); 85int ac_queue_message(const Mono_Time *mono_time, void *acp, struct RTPMessage *msg);
85int ac_reconfigure_encoder(ACSession *ac, int32_t bit_rate, int32_t sampling_rate, uint8_t channels); 86int ac_reconfigure_encoder(ACSession *ac, int32_t bit_rate, int32_t sampling_rate, uint8_t channels);
86 87
87#endif /* AUDIO_H */ 88#endif /* AUDIO_H */
diff --git a/toxav/bwcontroller.c b/toxav/bwcontroller.c
index 460cf118..695bb99b 100644
--- a/toxav/bwcontroller.c
+++ b/toxav/bwcontroller.c
@@ -83,7 +83,7 @@ BWController *bwc_new(Messenger *m, uint32_t friendnumber, m_cb *mcb, void *mcb_
83 retu->mcb_user_data = mcb_user_data; 83 retu->mcb_user_data = mcb_user_data;
84 retu->m = m; 84 retu->m = m;
85 retu->friend_number = friendnumber; 85 retu->friend_number = friendnumber;
86 uint64_t now = current_time_monotonic(); 86 uint64_t now = current_time_monotonic(m->mono_time);
87 retu->cycle.last_sent_timestamp = now; 87 retu->cycle.last_sent_timestamp = now;
88 retu->cycle.last_refresh_timestamp = now; 88 retu->cycle.last_refresh_timestamp = now;
89 retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT); 89 retu->rcvpkt.rb = rb_new(BWC_AVG_PKT_COUNT);
@@ -138,7 +138,7 @@ void bwc_add_recv(BWController *bwc, uint32_t recv_bytes)
138void send_update(BWController *bwc) 138void send_update(BWController *bwc)
139{ 139{
140 if (bwc->packet_loss_counted_cycles > BWC_AVG_LOSS_OVER_CYCLES_COUNT && 140 if (bwc->packet_loss_counted_cycles > BWC_AVG_LOSS_OVER_CYCLES_COUNT &&
141 current_time_monotonic() - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) { 141 current_time_monotonic(bwc->m->mono_time) - bwc->cycle.last_sent_timestamp > BWC_SEND_INTERVAL_MS) {
142 bwc->packet_loss_counted_cycles = 0; 142 bwc->packet_loss_counted_cycles = 0;
143 143
144 if (bwc->cycle.lost) { 144 if (bwc->cycle.lost) {
@@ -159,7 +159,7 @@ void send_update(BWController *bwc)
159 } 159 }
160 } 160 }
161 161
162 bwc->cycle.last_sent_timestamp = current_time_monotonic(); 162 bwc->cycle.last_sent_timestamp = current_time_monotonic(bwc->m->mono_time);
163 bwc->cycle.lost = 0; 163 bwc->cycle.lost = 0;
164 bwc->cycle.recv = 0; 164 bwc->cycle.recv = 0;
165 } 165 }
@@ -170,12 +170,12 @@ static int on_update(BWController *bwc, const struct BWCMessage *msg)
170 LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc); 170 LOGGER_DEBUG(bwc->m->log, "%p Got update from peer", (void *)bwc);
171 171
172 /* Peers sent update too soon */ 172 /* Peers sent update too soon */
173 if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic()) { 173 if (bwc->cycle.last_recv_timestamp + BWC_SEND_INTERVAL_MS > current_time_monotonic(bwc->m->mono_time)) {
174 LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc); 174 LOGGER_INFO(bwc->m->log, "%p Rejecting extra update", (void *)bwc);
175 return -1; 175 return -1;
176 } 176 }
177 177
178 bwc->cycle.last_recv_timestamp = current_time_monotonic(); 178 bwc->cycle.last_recv_timestamp = current_time_monotonic(bwc->m->mono_time);
179 179
180 uint32_t recv = net_ntohl(msg->recv); 180 uint32_t recv = net_ntohl(msg->recv);
181 uint32_t lost = net_ntohl(msg->lost); 181 uint32_t lost = net_ntohl(msg->lost);
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 61297937..77cae626 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -389,7 +389,7 @@ static int handle_video_packet(RTPSession *session, const struct RTPHeader *head
389 LOGGER_DEBUG(log, "-- handle_video_packet -- CALLBACK-001a b0=%d b1=%d", (int)m_new->data[0], (int)m_new->data[1]); 389 LOGGER_DEBUG(log, "-- handle_video_packet -- CALLBACK-001a b0=%d b1=%d", (int)m_new->data[0], (int)m_new->data[1]);
390 update_bwc_values(log, session, m_new); 390 update_bwc_values(log, session, m_new);
391 // Pass ownership of m_new to the callback. 391 // Pass ownership of m_new to the callback.
392 session->mcb(session->cs, m_new); 392 session->mcb(session->m->mono_time, session->cs, m_new);
393 // Now we no longer own m_new. 393 // Now we no longer own m_new.
394 m_new = nullptr; 394 m_new = nullptr;
395 395
@@ -426,7 +426,7 @@ static int handle_video_packet(RTPSession *session, const struct RTPHeader *head
426 if (m_new) { 426 if (m_new) {
427 LOGGER_DEBUG(log, "-- handle_video_packet -- CALLBACK-003a b0=%d b1=%d", (int)m_new->data[0], (int)m_new->data[1]); 427 LOGGER_DEBUG(log, "-- handle_video_packet -- CALLBACK-003a b0=%d b1=%d", (int)m_new->data[0], (int)m_new->data[1]);
428 update_bwc_values(log, session, m_new); 428 update_bwc_values(log, session, m_new);
429 session->mcb(session->cs, m_new); 429 session->mcb(session->m->mono_time, session->cs, m_new);
430 430
431 m_new = nullptr; 431 m_new = nullptr;
432 } 432 }
@@ -499,15 +499,15 @@ static int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t
499 499
500 /* Invoke processing of active multiparted message */ 500 /* Invoke processing of active multiparted message */
501 if (session->mp) { 501 if (session->mp) {
502 session->mcb(session->cs, session->mp); 502 session->mcb(session->m->mono_time, session->cs, session->mp);
503 session->mp = nullptr; 503 session->mp = nullptr;
504 } 504 }
505 505
506 /* The message came in the allowed time; 506 /* The message came in the allowed time;
507 */ 507 */
508 508
509 return session->mcb(session->cs, new_message(&header, length - RTP_HEADER_SIZE, data + RTP_HEADER_SIZE, 509 return session->mcb(session->m->mono_time, session->cs, new_message(&header, length - RTP_HEADER_SIZE,
510 length - RTP_HEADER_SIZE)); 510 data + RTP_HEADER_SIZE, length - RTP_HEADER_SIZE));
511 } 511 }
512 512
513 /* The message is sent in multiple parts */ 513 /* The message is sent in multiple parts */
@@ -542,7 +542,7 @@ static int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t
542 /* Received a full message; now push it for the further 542 /* Received a full message; now push it for the further
543 * processing. 543 * processing.
544 */ 544 */
545 session->mcb(session->cs, session->mp); 545 session->mcb(session->m->mono_time, session->cs, session->mp);
546 session->mp = nullptr; 546 session->mp = nullptr;
547 } 547 }
548 } else { 548 } else {
@@ -555,7 +555,7 @@ static int handle_rtp_packet(Messenger *m, uint32_t friendnumber, const uint8_t
555 } 555 }
556 556
557 /* Push the previous message for processing */ 557 /* Push the previous message for processing */
558 session->mcb(session->cs, session->mp); 558 session->mcb(session->m->mono_time, session->cs, session->mp);
559 559
560 session->mp = nullptr; 560 session->mp = nullptr;
561 goto NEW_MULTIPARTED; 561 goto NEW_MULTIPARTED;
@@ -760,7 +760,7 @@ int rtp_send_data(RTPSession *session, const uint8_t *data, uint32_t length,
760 760
761 header.sequnum = session->sequnum; 761 header.sequnum = session->sequnum;
762 762
763 header.timestamp = current_time_monotonic(); 763 header.timestamp = current_time_monotonic(session->m->mono_time);
764 764
765 header.ssrc = session->ssrc; 765 header.ssrc = session->ssrc;
766 766
diff --git a/toxav/rtp.h b/toxav/rtp.h
index 225f4c03..42997594 100644
--- a/toxav/rtp.h
+++ b/toxav/rtp.h
@@ -159,7 +159,7 @@ struct RTPWorkBufferList {
159 159
160#define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10 160#define DISMISS_FIRST_LOST_VIDEO_PACKET_COUNT 10
161 161
162typedef int rtp_m_cb(void *cs, struct RTPMessage *msg); 162typedef int rtp_m_cb(const Mono_Time *mono_time, void *cs, struct RTPMessage *msg);
163 163
164/** 164/**
165 * RTP control session. 165 * RTP control session.
diff --git a/toxav/toxav.c b/toxav/toxav.c
index 84e67858..19648936 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -248,7 +248,7 @@ void toxav_iterate(ToxAV *av)
248 return; 248 return;
249 } 249 }
250 250
251 uint64_t start = current_time_monotonic(); 251 uint64_t start = current_time_monotonic(av->m->mono_time);
252 int32_t rc = 500; 252 int32_t rc = 500;
253 253
254 ToxAVCall *i = av->calls[av->calls_head]; 254 ToxAVCall *i = av->calls[av->calls_head];
@@ -286,7 +286,7 @@ void toxav_iterate(ToxAV *av)
286 pthread_mutex_unlock(av->mutex); 286 pthread_mutex_unlock(av->mutex);
287 287
288 av->interval = rc < av->dmssa ? 0 : (rc - av->dmssa); 288 av->interval = rc < av->dmssa ? 0 : (rc - av->dmssa);
289 av->dmsst += current_time_monotonic() - start; 289 av->dmsst += current_time_monotonic(av->m->mono_time) - start;
290 290
291 if (++av->dmssc == 3) { 291 if (++av->dmssc == 3) {
292 av->dmssa = av->dmsst / 3 + 5 /* NOTE Magic Offset for precission */; 292 av->dmssa = av->dmsst / 3 + 5 /* NOTE Magic Offset for precission */;
@@ -1325,7 +1325,7 @@ bool call_prepare_transmission(ToxAVCall *call)
1325 call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call); 1325 call->bwc = bwc_new(av->m, call->friend_number, callback_bwc, call);
1326 1326
1327 { /* Prepare audio */ 1327 { /* Prepare audio */
1328 call->audio = ac_new(av->m->log, av, call->friend_number, av->acb, av->acb_user_data); 1328 call->audio = ac_new(av->m->mono_time, av->m->log, av, call->friend_number, av->acb, av->acb_user_data);
1329 1329
1330 if (!call->audio) { 1330 if (!call->audio) {
1331 LOGGER_ERROR(av->m->log, "Failed to create audio codec session"); 1331 LOGGER_ERROR(av->m->log, "Failed to create audio codec session");
@@ -1341,7 +1341,7 @@ bool call_prepare_transmission(ToxAVCall *call)
1341 } 1341 }
1342 } 1342 }
1343 { /* Prepare video */ 1343 { /* Prepare video */
1344 call->video = vc_new(av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data); 1344 call->video = vc_new(av->m->mono_time, av->m->log, av, call->friend_number, av->vcb, av->vcb_user_data);
1345 1345
1346 if (!call->video) { 1346 if (!call->video) {
1347 LOGGER_ERROR(av->m->log, "Failed to create video codec session"); 1347 LOGGER_ERROR(av->m->log, "Failed to create video codec session");
diff --git a/toxav/video.c b/toxav/video.c
index 94f10230..bc164cea 100644
--- a/toxav/video.c
+++ b/toxav/video.c
@@ -159,7 +159,8 @@ static void vc_init_encoder_cfg(const Logger *log, vpx_codec_enc_cfg_t *cfg, int
159#endif 159#endif
160} 160}
161 161
162VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, void *cb_data) 162VCSession *vc_new(const Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number,
163 toxav_video_receive_frame_cb *cb, void *cb_data)
163{ 164{
164 VCSession *vc = (VCSession *)calloc(sizeof(VCSession), 1); 165 VCSession *vc = (VCSession *)calloc(sizeof(VCSession), 1);
165 vpx_codec_err_t rc; 166 vpx_codec_err_t rc;
@@ -264,7 +265,7 @@ VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_vi
264 goto BASE_CLEANUP_1; 265 goto BASE_CLEANUP_1;
265 } 266 }
266 */ 267 */
267 vc->linfts = current_time_monotonic(); 268 vc->linfts = current_time_monotonic(mono_time);
268 vc->lcfd = 60; 269 vc->lcfd = 60;
269 vc->vcb = cb; 270 vc->vcb = cb;
270 vc->vcb_user_data = cb_data; 271 vc->vcb_user_data = cb_data;
@@ -355,7 +356,7 @@ void vc_iterate(VCSession *vc)
355 } 356 }
356} 357}
357 358
358int vc_queue_message(void *vcp, struct RTPMessage *msg) 359int vc_queue_message(const Mono_Time *mono_time, void *vcp, struct RTPMessage *msg)
359{ 360{
360 /* This function is called with complete messages 361 /* This function is called with complete messages
361 * they have already been assembled. 362 * they have already been assembled.
@@ -389,9 +390,9 @@ int vc_queue_message(void *vcp, struct RTPMessage *msg)
389 free(rb_write(vc->vbuf_raw, msg)); 390 free(rb_write(vc->vbuf_raw, msg));
390 391
391 /* Calculate time it took for peer to send us this frame */ 392 /* Calculate time it took for peer to send us this frame */
392 uint32_t t_lcfd = current_time_monotonic() - vc->linfts; 393 uint32_t t_lcfd = current_time_monotonic(mono_time) - vc->linfts;
393 vc->lcfd = t_lcfd > 100 ? vc->lcfd : t_lcfd; 394 vc->lcfd = t_lcfd > 100 ? vc->lcfd : t_lcfd;
394 vc->linfts = current_time_monotonic(); 395 vc->linfts = current_time_monotonic(mono_time);
395 pthread_mutex_unlock(vc->queue_mutex); 396 pthread_mutex_unlock(vc->queue_mutex);
396 return 0; 397 return 0;
397} 398}
diff --git a/toxav/video.h b/toxav/video.h
index 898c986a..14d866d1 100644
--- a/toxav/video.h
+++ b/toxav/video.h
@@ -60,11 +60,11 @@ typedef struct VCSession_s {
60 pthread_mutex_t queue_mutex[1]; 60 pthread_mutex_t queue_mutex[1];
61} VCSession; 61} VCSession;
62 62
63VCSession *vc_new(const Logger *log, ToxAV *av, uint32_t friend_number, toxav_video_receive_frame_cb *cb, 63VCSession *vc_new(const Mono_Time *mono_time, const Logger *log, ToxAV *av, uint32_t friend_number,
64 void *cb_data); 64 toxav_video_receive_frame_cb *cb, void *cb_data);
65void vc_kill(VCSession *vc); 65void vc_kill(VCSession *vc);
66void vc_iterate(VCSession *vc); 66void vc_iterate(VCSession *vc);
67int vc_queue_message(void *vcp, struct RTPMessage *msg); 67int vc_queue_message(const Mono_Time *mono_time, void *vcp, struct RTPMessage *msg);
68int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist); 68int vc_reconfigure_encoder(VCSession *vc, uint32_t bit_rate, uint16_t width, uint16_t height, int16_t kf_max_dist);
69 69
70#endif /* VIDEO_H */ 70#endif /* VIDEO_H */