summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--toxav/msi.h28
-rw-r--r--toxav/toxav.c64
2 files changed, 46 insertions, 46 deletions
diff --git a/toxav/msi.h b/toxav/msi.h
index 660df05e..29d44ccc 100644
--- a/toxav/msi.h
+++ b/toxav/msi.h
@@ -57,7 +57,7 @@ typedef enum {
57/** 57/**
58 * Encoding settings. 58 * Encoding settings.
59 */ 59 */
60typedef struct _MSICodecSettings { 60typedef struct {
61 MSICallType call_type; 61 MSICallType call_type;
62 62
63 uint32_t video_bitrate; /* In kbits/s */ 63 uint32_t video_bitrate; /* In kbits/s */
@@ -100,32 +100,32 @@ typedef enum {
100/** 100/**
101 * The call struct. 101 * The call struct.
102 */ 102 */
103typedef struct _MSICall { /* Call info structure */ 103typedef struct { /* Call info structure */
104 struct _MSISession *session; /* Session pointer */ 104 struct MSISession_s *session; /* Session pointer */
105 105
106 MSICallState state; 106 MSICallState state;
107 107
108 MSICSettings csettings_local; /* Local call settings */ 108 MSICSettings csettings_local; /* Local call settings */
109 MSICSettings *csettings_peer; /* Peers call settings */ 109 MSICSettings *csettings_peer; /* Peers call settings */
110 110
111 MSICallIDType id; /* Random value identifying the call */ 111 MSICallIDType id; /* Random value identifying the call */
112 112
113 int ringing_tout_ms; /* Ringing timeout in ms */ 113 int ringing_tout_ms; /* Ringing timeout in ms */
114 114
115 int request_timer_id; /* Timer id for outgoing request/action */ 115 int request_timer_id; /* Timer id for outgoing request/action */
116 int ringing_timer_id; /* Timer id for ringing timeout */ 116 int ringing_timer_id; /* Timer id for ringing timeout */
117 117
118 uint32_t *peers; 118 uint32_t *peers;
119 uint16_t peer_count; 119 uint16_t peer_count;
120 120
121 int32_t call_idx; /* Index of this call in MSISession */ 121 int32_t call_idx; /* Index of this call in MSISession */
122} MSICall; 122} MSICall;
123 123
124 124
125/** 125/**
126 * Control session struct 126 * Control session struct
127 */ 127 */
128typedef struct _MSISession { 128typedef struct MSISession_s {
129 129
130 /* Call handlers */ 130 /* Call handlers */
131 MSICall **calls; 131 MSICall **calls;
diff --git a/toxav/toxav.c b/toxav/toxav.c
index f8605fd5..b0534ec5 100644
--- a/toxav/toxav.c
+++ b/toxav/toxav.c
@@ -62,7 +62,7 @@ static const uint32_t jbuf_capacity = 6;
62static const uint8_t audio_index = 0, video_index = 1; 62static const uint8_t audio_index = 0, video_index = 1;
63 63
64typedef struct _ToxAvCall { 64typedef struct _ToxAvCall {
65 pthread_mutex_t mutex[1]; 65 pthread_mutex_t mutex_control[1];
66 pthread_mutex_t mutex_encoding_audio[1]; 66 pthread_mutex_t mutex_encoding_audio[1];
67 pthread_mutex_t mutex_encoding_video[1]; 67 pthread_mutex_t mutex_encoding_video[1];
68 pthread_mutex_t mutex_do[1]; 68 pthread_mutex_t mutex_do[1];
@@ -117,7 +117,7 @@ ToxAv *toxav_new( Tox *messenger, int32_t max_calls)
117 unsigned int i; 117 unsigned int i;
118 118
119 for (i = 0; i < max_calls; ++i) { 119 for (i = 0; i < max_calls; ++i) {
120 if (create_recursive_mutex(av->calls[i].mutex) != 0 ) { 120 if (create_recursive_mutex(av->calls[i].mutex_control) != 0 ) {
121 LOGGER_WARNING("Failed to init call(%u) mutex!", i); 121 LOGGER_WARNING("Failed to init call(%u) mutex!", i);
122 msi_kill(av->msi_session); 122 msi_kill(av->msi_session);
123 123
@@ -145,7 +145,7 @@ void toxav_kill ( ToxAv *av )
145 if ( av->calls[i].cs ) 145 if ( av->calls[i].cs )
146 cs_kill(av->calls[i].cs); 146 cs_kill(av->calls[i].cs);
147 147
148 pthread_mutex_destroy(av->calls[i].mutex); 148 pthread_mutex_destroy(av->calls[i].mutex_control);
149 } 149 }
150 150
151 msi_kill(av->msi_session); 151 msi_kill(av->msi_session);
@@ -160,14 +160,14 @@ uint32_t toxav_do_interval(ToxAv *av)
160 uint32_t rc = 200 + av->avgdectms; /* Return 200 if no call is active */ 160 uint32_t rc = 200 + av->avgdectms; /* Return 200 if no call is active */
161 161
162 for (; i < av->max_calls; i ++) { 162 for (; i < av->max_calls; i ++) {
163 pthread_mutex_lock(av->calls[i].mutex); 163 pthread_mutex_lock(av->calls[i].mutex_control);
164 164
165 if (av->calls[i].active) { 165 if (av->calls[i].active) {
166 /* This should work. Video payload will always come in greater intervals */ 166 /* This should work. Video payload will always come in greater intervals */
167 rc = MIN(av->calls[i].cs->audio_decoder_frame_duration, rc); 167 rc = MIN(av->calls[i].cs->audio_decoder_frame_duration, rc);
168 } 168 }
169 169
170 pthread_mutex_unlock(av->calls[i].mutex); 170 pthread_mutex_unlock(av->calls[i].mutex_control);
171 } 171 }
172 172
173 return rc < av->avgdectms ? 0 : rc - av->avgdectms; 173 return rc < av->avgdectms ? 0 : rc - av->avgdectms;
@@ -182,15 +182,15 @@ void toxav_do(ToxAv *av)
182 uint32_t i = 0; 182 uint32_t i = 0;
183 183
184 for (; i < av->max_calls; i ++) { 184 for (; i < av->max_calls; i ++) {
185 pthread_mutex_lock(av->calls[i].mutex); 185 pthread_mutex_lock(av->calls[i].mutex_control);
186 186
187 if (av->calls[i].active) { 187 if (av->calls[i].active) {
188 pthread_mutex_lock(av->calls[i].mutex_do); 188 pthread_mutex_lock(av->calls[i].mutex_do);
189 pthread_mutex_unlock(av->calls[i].mutex); 189 pthread_mutex_unlock(av->calls[i].mutex_control);
190 cs_do(av->calls[i].cs); 190 cs_do(av->calls[i].cs);
191 pthread_mutex_unlock(av->calls[i].mutex_do); 191 pthread_mutex_unlock(av->calls[i].mutex_do);
192 } else { 192 } else {
193 pthread_mutex_unlock(av->calls[i].mutex); 193 pthread_mutex_unlock(av->calls[i].mutex_control);
194 } 194 }
195 } 195 }
196 196
@@ -272,17 +272,17 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide
272 272
273 ToxAvCall *call = &av->calls[call_index]; 273 ToxAvCall *call = &av->calls[call_index];
274 274
275 pthread_mutex_lock(call->mutex); 275 pthread_mutex_lock(call->mutex_control);
276 276
277 if (call->active) { 277 if (call->active) {
278 pthread_mutex_unlock(call->mutex); 278 pthread_mutex_unlock(call->mutex_control);
279 LOGGER_ERROR("Error while starting RTP session: call already active!\n"); 279 LOGGER_ERROR("Error while starting RTP session: call already active!\n");
280 return av_ErrorAlreadyInCallWithPeer; 280 return av_ErrorAlreadyInCallWithPeer;
281 } 281 }
282 282
283 if (pthread_mutex_init(call->mutex_encoding_audio, NULL) != 0 283 if (pthread_mutex_init(call->mutex_encoding_audio, NULL) != 0
284 || pthread_mutex_init(call->mutex_encoding_video, NULL) != 0 || pthread_mutex_init(call->mutex_do, NULL) != 0) { 284 || pthread_mutex_init(call->mutex_encoding_video, NULL) != 0 || pthread_mutex_init(call->mutex_do, NULL) != 0) {
285 pthread_mutex_unlock(call->mutex); 285 pthread_mutex_unlock(call->mutex_control);
286 LOGGER_ERROR("Error while starting RTP session: mutex initializing failed!\n"); 286 LOGGER_ERROR("Error while starting RTP session: mutex initializing failed!\n");
287 return av_ErrorUnknown; 287 return av_ErrorUnknown;
288 } 288 }
@@ -312,7 +312,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide
312 312
313 if ( !(call->cs = cs_new(c_self, c_peer, jbuf_capacity, support_video)) ) { 313 if ( !(call->cs = cs_new(c_self, c_peer, jbuf_capacity, support_video)) ) {
314 LOGGER_ERROR("Error while starting Codec State!\n"); 314 LOGGER_ERROR("Error while starting Codec State!\n");
315 pthread_mutex_unlock(call->mutex); 315 pthread_mutex_unlock(call->mutex_control);
316 return av_ErrorInitializingCodecs; 316 return av_ErrorInitializingCodecs;
317 } 317 }
318 318
@@ -349,7 +349,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, int support_vide
349 } 349 }
350 350
351 call->active = 1; 351 call->active = 1;
352 pthread_mutex_unlock(call->mutex); 352 pthread_mutex_unlock(call->mutex_control);
353 return av_ErrorNone; 353 return av_ErrorNone;
354error: 354error:
355 rtp_kill(call->crtps[audio_index], av->messenger); 355 rtp_kill(call->crtps[audio_index], av->messenger);
@@ -363,7 +363,7 @@ error:
363 pthread_mutex_destroy(call->mutex_encoding_video); 363 pthread_mutex_destroy(call->mutex_encoding_video);
364 pthread_mutex_destroy(call->mutex_do); 364 pthread_mutex_destroy(call->mutex_do);
365 365
366 pthread_mutex_unlock(call->mutex); 366 pthread_mutex_unlock(call->mutex_control);
367 return av_ErrorCreatingRtpSessions; 367 return av_ErrorCreatingRtpSessions;
368} 368}
369 369
@@ -376,10 +376,10 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
376 376
377 ToxAvCall *call = &av->calls[call_index]; 377 ToxAvCall *call = &av->calls[call_index];
378 378
379 pthread_mutex_lock(call->mutex); 379 pthread_mutex_lock(call->mutex_control);
380 380
381 if (!call->active) { 381 if (!call->active) {
382 pthread_mutex_unlock(call->mutex); 382 pthread_mutex_unlock(call->mutex_control);
383 LOGGER_WARNING("Action on inactive call: %d", call_index); 383 LOGGER_WARNING("Action on inactive call: %d", call_index);
384 return av_ErrorInvalidState; 384 return av_ErrorInvalidState;
385 } 385 }
@@ -404,7 +404,7 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index )
404 pthread_mutex_destroy(call->mutex_encoding_video); 404 pthread_mutex_destroy(call->mutex_encoding_video);
405 pthread_mutex_destroy(call->mutex_do); 405 pthread_mutex_destroy(call->mutex_do);
406 406
407 pthread_mutex_unlock(call->mutex); 407 pthread_mutex_unlock(call->mutex_control);
408 408
409 return av_ErrorNone; 409 return av_ErrorNone;
410} 410}
@@ -452,21 +452,21 @@ int toxav_prepare_video_frame ( ToxAv *av, int32_t call_index, uint8_t *dest, in
452 452
453 453
454 ToxAvCall *call = &av->calls[call_index]; 454 ToxAvCall *call = &av->calls[call_index];
455 pthread_mutex_lock(call->mutex); 455 pthread_mutex_lock(call->mutex_control);
456 456
457 if (!call->active) { 457 if (!call->active) {
458 pthread_mutex_unlock(call->mutex); 458 pthread_mutex_unlock(call->mutex_control);
459 LOGGER_WARNING("Action on inactive call: %d", call_index); 459 LOGGER_WARNING("Action on inactive call: %d", call_index);
460 return av_ErrorInvalidState; 460 return av_ErrorInvalidState;
461 } 461 }
462 462
463 if (cs_set_video_encoder_resolution(call->cs, input->d_w, input->d_h) < 0) { 463 if (cs_set_video_encoder_resolution(call->cs, input->d_w, input->d_h) < 0) {
464 pthread_mutex_unlock(call->mutex); 464 pthread_mutex_unlock(call->mutex_control);
465 return av_ErrorSettingVideoResolution; 465 return av_ErrorSettingVideoResolution;
466 } 466 }
467 467
468 pthread_mutex_lock(call->mutex_encoding_video); 468 pthread_mutex_lock(call->mutex_encoding_video);
469 pthread_mutex_unlock(call->mutex); 469 pthread_mutex_unlock(call->mutex_control);
470 470
471 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US); 471 int rc = vpx_codec_encode(&call->cs->v_encoder, input, call->cs->frame_counter, 1, 0, MAX_ENCODE_TIME_US);
472 472
@@ -507,17 +507,17 @@ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, unsi
507 } 507 }
508 508
509 ToxAvCall *call = &av->calls[call_index]; 509 ToxAvCall *call = &av->calls[call_index];
510 pthread_mutex_lock(call->mutex); 510 pthread_mutex_lock(call->mutex_control);
511 511
512 512
513 if (!call->active) { 513 if (!call->active) {
514 pthread_mutex_unlock(call->mutex); 514 pthread_mutex_unlock(call->mutex_control);
515 LOGGER_WARNING("Action on inactive call: %d", call_index); 515 LOGGER_WARNING("Action on inactive call: %d", call_index);
516 return av_ErrorInvalidState; 516 return av_ErrorInvalidState;
517 } 517 }
518 518
519 int rc = toxav_send_rtp_payload(av, call, av_TypeVideo, frame, frame_size); 519 int rc = toxav_send_rtp_payload(av, call, av_TypeVideo, frame, frame_size);
520 pthread_mutex_unlock(call->mutex); 520 pthread_mutex_unlock(call->mutex_control);
521 521
522 return rc; 522 return rc;
523} 523}
@@ -535,16 +535,16 @@ int toxav_prepare_audio_frame ( ToxAv *av,
535 } 535 }
536 536
537 ToxAvCall *call = &av->calls[call_index]; 537 ToxAvCall *call = &av->calls[call_index];
538 pthread_mutex_lock(call->mutex); 538 pthread_mutex_lock(call->mutex_control);
539 539
540 if (!call->active) { 540 if (!call->active) {
541 pthread_mutex_unlock(call->mutex); 541 pthread_mutex_unlock(call->mutex_control);
542 LOGGER_WARNING("Action on inactive call: %d", call_index); 542 LOGGER_WARNING("Action on inactive call: %d", call_index);
543 return av_ErrorInvalidState; 543 return av_ErrorInvalidState;
544 } 544 }
545 545
546 pthread_mutex_lock(call->mutex_encoding_audio); 546 pthread_mutex_lock(call->mutex_encoding_audio);
547 pthread_mutex_unlock(call->mutex); 547 pthread_mutex_unlock(call->mutex_control);
548 int32_t rc = opus_encode(call->cs->audio_encoder, frame, frame_size, dest, dest_max); 548 int32_t rc = opus_encode(call->cs->audio_encoder, frame, frame_size, dest, dest_max);
549 pthread_mutex_unlock(call->mutex_encoding_audio); 549 pthread_mutex_unlock(call->mutex_encoding_audio);
550 550
@@ -564,17 +564,17 @@ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *data, unsig
564 } 564 }
565 565
566 ToxAvCall *call = &av->calls[call_index]; 566 ToxAvCall *call = &av->calls[call_index];
567 pthread_mutex_lock(call->mutex); 567 pthread_mutex_lock(call->mutex_control);
568 568
569 569
570 if (!call->active) { 570 if (!call->active) {
571 pthread_mutex_unlock(call->mutex); 571 pthread_mutex_unlock(call->mutex_control);
572 LOGGER_WARNING("Action on inactive call: %d", call_index); 572 LOGGER_WARNING("Action on inactive call: %d", call_index);
573 return av_ErrorInvalidState; 573 return av_ErrorInvalidState;
574 } 574 }
575 575
576 int rc = toxav_send_rtp_payload(av, call, av_TypeAudio, data, size); 576 int rc = toxav_send_rtp_payload(av, call, av_TypeAudio, data, size);
577 pthread_mutex_unlock(call->mutex); 577 pthread_mutex_unlock(call->mutex_control);
578 return rc; 578 return rc;
579} 579}
580 580
@@ -624,11 +624,11 @@ int toxav_get_active_count(ToxAv *av)
624 int rc = 0, i = 0; 624 int rc = 0, i = 0;
625 625
626 for (; i < av->max_calls; i++) { 626 for (; i < av->max_calls; i++) {
627 pthread_mutex_lock(av->calls[i].mutex); 627 pthread_mutex_lock(av->calls[i].mutex_control);
628 628
629 if (av->calls[i].active) rc++; 629 if (av->calls[i].active) rc++;
630 630
631 pthread_mutex_unlock(av->calls[i].mutex); 631 pthread_mutex_unlock(av->calls[i].mutex_control);
632 } 632 }
633 633
634 return rc; 634 return rc;