diff options
Diffstat (limited to 'toxav/toxav.c')
-rwxr-xr-x | toxav/toxav.c | 72 |
1 files changed, 46 insertions, 26 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c index 3a41754a..015c6565 100755 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -92,7 +92,7 @@ const ToxAvCodecSettings av_DefaultSettings = { | |||
92 | * @return ToxAv* | 92 | * @return ToxAv* |
93 | * @retval NULL On error. | 93 | * @retval NULL On error. |
94 | */ | 94 | */ |
95 | ToxAv *toxav_new( Tox* messenger, uint32_t max_calls) | 95 | ToxAv *toxav_new( Tox* messenger, int32_t max_calls) |
96 | { | 96 | { |
97 | ToxAv *av = calloc ( sizeof(ToxAv), 1); | 97 | ToxAv *av = calloc ( sizeof(ToxAv), 1); |
98 | 98 | ||
@@ -171,7 +171,7 @@ void toxav_register_callstate_callback ( ToxAVCallback callback, ToxAvCallbackID | |||
171 | * @retval 0 Success. | 171 | * @retval 0 Success. |
172 | * @retval ToxAvError On error. | 172 | * @retval ToxAvError On error. |
173 | */ | 173 | */ |
174 | int toxav_call (ToxAv* av, uint32_t* call_index, int user, ToxAvCallType call_type, int ringing_seconds ) | 174 | int toxav_call (ToxAv* av, int32_t* call_index, int user, ToxAvCallType call_type, int ringing_seconds ) |
175 | { | 175 | { |
176 | return msi_invite(av->msi_session, call_index, call_type, ringing_seconds * 1000, user); | 176 | return msi_invite(av->msi_session, call_index, call_type, ringing_seconds * 1000, user); |
177 | } | 177 | } |
@@ -184,7 +184,7 @@ int toxav_call (ToxAv* av, uint32_t* call_index, int user, ToxAvCallType call_ty | |||
184 | * @retval 0 Success. | 184 | * @retval 0 Success. |
185 | * @retval ToxAvError On error. | 185 | * @retval ToxAvError On error. |
186 | */ | 186 | */ |
187 | int toxav_hangup ( ToxAv* av, uint32_t call_index ) | 187 | int toxav_hangup ( ToxAv* av, int32_t call_index ) |
188 | { | 188 | { |
189 | if ( !av->msi_session->calls[call_index] ) { | 189 | if ( !av->msi_session->calls[call_index] ) { |
190 | return ErrorNoCall; | 190 | return ErrorNoCall; |
@@ -206,7 +206,7 @@ int toxav_hangup ( ToxAv* av, uint32_t call_index ) | |||
206 | * @retval 0 Success. | 206 | * @retval 0 Success. |
207 | * @retval ToxAvError On error. | 207 | * @retval ToxAvError On error. |
208 | */ | 208 | */ |
209 | int toxav_answer ( ToxAv* av, uint32_t call_index, ToxAvCallType call_type ) | 209 | int toxav_answer ( ToxAv* av, int32_t call_index, ToxAvCallType call_type ) |
210 | { | 210 | { |
211 | if ( !av->msi_session->calls[call_index] ) { | 211 | if ( !av->msi_session->calls[call_index] ) { |
212 | return ErrorNoCall; | 212 | return ErrorNoCall; |
@@ -228,7 +228,7 @@ int toxav_answer ( ToxAv* av, uint32_t call_index, ToxAvCallType call_type ) | |||
228 | * @retval 0 Success. | 228 | * @retval 0 Success. |
229 | * @retval ToxAvError On error. | 229 | * @retval ToxAvError On error. |
230 | */ | 230 | */ |
231 | int toxav_reject ( ToxAv* av, uint32_t call_index, const char* reason ) | 231 | int toxav_reject ( ToxAv* av, int32_t call_index, const char* reason ) |
232 | { | 232 | { |
233 | if ( !av->msi_session->calls[call_index] ) { | 233 | if ( !av->msi_session->calls[call_index] ) { |
234 | return ErrorNoCall; | 234 | return ErrorNoCall; |
@@ -251,7 +251,7 @@ int toxav_reject ( ToxAv* av, uint32_t call_index, const char* reason ) | |||
251 | * @retval 0 Success. | 251 | * @retval 0 Success. |
252 | * @retval ToxAvError On error. | 252 | * @retval ToxAvError On error. |
253 | */ | 253 | */ |
254 | int toxav_cancel ( ToxAv* av, uint32_t call_index, int peer_id, const char* reason ) | 254 | int toxav_cancel ( ToxAv* av, int32_t call_index, int peer_id, const char* reason ) |
255 | { | 255 | { |
256 | if ( !av->msi_session->calls[call_index] ) { | 256 | if ( !av->msi_session->calls[call_index] ) { |
257 | return ErrorNoCall; | 257 | return ErrorNoCall; |
@@ -268,7 +268,7 @@ int toxav_cancel ( ToxAv* av, uint32_t call_index, int peer_id, const char* reas | |||
268 | * @retval 0 Success. | 268 | * @retval 0 Success. |
269 | * @retval ToxAvError On error. | 269 | * @retval ToxAvError On error. |
270 | */ | 270 | */ |
271 | int toxav_stop_call ( ToxAv* av, uint32_t call_index ) | 271 | int toxav_stop_call ( ToxAv* av, int32_t call_index ) |
272 | { | 272 | { |
273 | if ( !av->msi_session->calls[call_index] ) { | 273 | if ( !av->msi_session->calls[call_index] ) { |
274 | return ErrorNoCall; | 274 | return ErrorNoCall; |
@@ -285,7 +285,7 @@ int toxav_stop_call ( ToxAv* av, uint32_t call_index ) | |||
285 | * @retval 0 Success. | 285 | * @retval 0 Success. |
286 | * @retval ToxAvError On error. | 286 | * @retval ToxAvError On error. |
287 | */ | 287 | */ |
288 | int toxav_prepare_transmission ( ToxAv* av, uint32_t call_index, ToxAvCodecSettings* codec_settings, int support_video ) | 288 | int toxav_prepare_transmission ( ToxAv* av, int32_t call_index, ToxAvCodecSettings* codec_settings, int support_video ) |
289 | { | 289 | { |
290 | if ( !av->msi_session || av->msi_session->max_calls <= call_index || !av->msi_session->calls[call_index] ) { | 290 | if ( !av->msi_session || av->msi_session->max_calls <= call_index || !av->msi_session->calls[call_index] ) { |
291 | /*fprintf(stderr, "Error while starting audio RTP session: invalid call!\n");*/ | 291 | /*fprintf(stderr, "Error while starting audio RTP session: invalid call!\n");*/ |
@@ -350,7 +350,7 @@ int toxav_prepare_transmission ( ToxAv* av, uint32_t call_index, ToxAvCodecSetti | |||
350 | * @retval 0 Success. | 350 | * @retval 0 Success. |
351 | * @retval ToxAvError On error. | 351 | * @retval ToxAvError On error. |
352 | */ | 352 | */ |
353 | int toxav_kill_transmission ( ToxAv *av, uint32_t call_index ) | 353 | int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) |
354 | { | 354 | { |
355 | CallSpecific* call = &av->calls[call_index]; | 355 | CallSpecific* call = &av->calls[call_index]; |
356 | 356 | ||
@@ -370,12 +370,16 @@ int toxav_kill_transmission ( ToxAv *av, uint32_t call_index ) | |||
370 | if ( call->j_buf ) { | 370 | if ( call->j_buf ) { |
371 | terminate_queue(call->j_buf); | 371 | terminate_queue(call->j_buf); |
372 | call->j_buf = NULL; | 372 | call->j_buf = NULL; |
373 | LOGGER_DEBUG("Terminated j queue"); | ||
373 | } | 374 | } |
375 | else LOGGER_DEBUG("No j queue"); | ||
374 | 376 | ||
375 | if ( call->cs ) { | 377 | if ( call->cs ) { |
376 | codec_terminate_session(call->cs); | 378 | codec_terminate_session(call->cs); |
377 | call->cs = NULL; | 379 | call->cs = NULL; |
380 | LOGGER_DEBUG("Terminated codec session"); | ||
378 | } | 381 | } |
382 | else LOGGER_DEBUG("No codec session"); | ||
379 | 383 | ||
380 | return ErrorNone; | 384 | return ErrorNone; |
381 | } | 385 | } |
@@ -392,7 +396,7 @@ int toxav_kill_transmission ( ToxAv *av, uint32_t call_index ) | |||
392 | * @retval 0 Success. | 396 | * @retval 0 Success. |
393 | * @retval -1 Failure. | 397 | * @retval -1 Failure. |
394 | */ | 398 | */ |
395 | inline__ int toxav_send_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallType type, const uint8_t *payload, uint16_t length ) | 399 | inline__ int toxav_send_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallType type, const uint8_t *payload, uint16_t length ) |
396 | { | 400 | { |
397 | if ( av->calls[call_index].crtps[type - TypeAudio] ) | 401 | if ( av->calls[call_index].crtps[type - TypeAudio] ) |
398 | return rtp_send_msg ( av->calls[call_index].crtps[type - TypeAudio], av->msi_session->messenger_handle, payload, length ); | 402 | return rtp_send_msg ( av->calls[call_index].crtps[type - TypeAudio], av->msi_session->messenger_handle, payload, length ); |
@@ -409,7 +413,7 @@ inline__ int toxav_send_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallT | |||
409 | * @retval ToxAvError On Error. | 413 | * @retval ToxAvError On Error. |
410 | * @retval >=0 Size of received payload. | 414 | * @retval >=0 Size of received payload. |
411 | */ | 415 | */ |
412 | inline__ int toxav_recv_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallType type, uint8_t *dest ) | 416 | inline__ int toxav_recv_rtp_payload ( ToxAv *av, int32_t call_index, ToxAvCallType type, uint8_t *dest ) |
413 | { | 417 | { |
414 | if ( !dest ) return ErrorInternal; | 418 | if ( !dest ) return ErrorInternal; |
415 | 419 | ||
@@ -460,7 +464,7 @@ inline__ int toxav_recv_rtp_payload ( ToxAv *av, uint32_t call_index, ToxAvCallT | |||
460 | * @retval 0 Success. | 464 | * @retval 0 Success. |
461 | * @retval ToxAvError On Error. | 465 | * @retval ToxAvError On Error. |
462 | */ | 466 | */ |
463 | inline__ int toxav_recv_video ( ToxAv *av, uint32_t call_index, vpx_image_t **output) | 467 | inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **output) |
464 | { | 468 | { |
465 | if ( !output ) return ErrorInternal; | 469 | if ( !output ) return ErrorInternal; |
466 | 470 | ||
@@ -496,7 +500,7 @@ inline__ int toxav_recv_video ( ToxAv *av, uint32_t call_index, vpx_image_t **ou | |||
496 | * @retval 0 Success. | 500 | * @retval 0 Success. |
497 | * @retval ToxAvError On error. | 501 | * @retval ToxAvError On error. |
498 | */ | 502 | */ |
499 | inline__ int toxav_send_video ( ToxAv *av, uint32_t call_index, const uint8_t* frame, int frame_size) | 503 | inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t* frame, int frame_size) |
500 | { | 504 | { |
501 | return toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); | 505 | return toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); |
502 | } | 506 | } |
@@ -512,7 +516,7 @@ inline__ int toxav_send_video ( ToxAv *av, uint32_t call_index, const uint8_t* f | |||
512 | * @retval ToxAvError On error. | 516 | * @retval ToxAvError On error. |
513 | * @retval >0 On success | 517 | * @retval >0 On success |
514 | */ | 518 | */ |
515 | inline__ int toxav_prepare_video_frame(ToxAv* av, uint32_t call_index, uint8_t* dest, int dest_max, vpx_image_t* input) | 519 | inline__ int toxav_prepare_video_frame(ToxAv* av, int32_t call_index, uint8_t* dest, int dest_max, vpx_image_t* input) |
516 | { | 520 | { |
517 | CallSpecific* call = &av->calls[call_index]; | 521 | CallSpecific* call = &av->calls[call_index]; |
518 | 522 | ||
@@ -551,7 +555,7 @@ inline__ int toxav_prepare_video_frame(ToxAv* av, uint32_t call_index, uint8_t* | |||
551 | * @retval >=0 Size of received data in frames/samples. | 555 | * @retval >=0 Size of received data in frames/samples. |
552 | * @retval ToxAvError On error. | 556 | * @retval ToxAvError On error. |
553 | */ | 557 | */ |
554 | inline__ int toxav_recv_audio ( ToxAv *av, uint32_t call_index, int frame_size, int16_t *dest ) | 558 | inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, int16_t *dest ) |
555 | { | 559 | { |
556 | if ( !dest ) return ErrorInternal; | 560 | if ( !dest ) return ErrorInternal; |
557 | 561 | ||
@@ -592,7 +596,7 @@ inline__ int toxav_recv_audio ( ToxAv *av, uint32_t call_index, int frame_size, | |||
592 | * @retval 0 Success. | 596 | * @retval 0 Success. |
593 | * @retval ToxAvError On error. | 597 | * @retval ToxAvError On error. |
594 | */ | 598 | */ |
595 | inline__ int toxav_send_audio ( ToxAv *av, uint32_t call_index, const uint8_t *frame, int frame_size) | 599 | inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) |
596 | { | 600 | { |
597 | return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); | 601 | return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); |
598 | } | 602 | } |
@@ -609,7 +613,7 @@ inline__ int toxav_send_audio ( ToxAv *av, uint32_t call_index, const uint8_t *f | |||
609 | * @retval ToxAvError On error. | 613 | * @retval ToxAvError On error. |
610 | * @retval >0 On success | 614 | * @retval >0 On success |
611 | */ | 615 | */ |
612 | inline__ int toxav_prepare_audio_frame ( ToxAv* av, uint32_t call_index, uint8_t* dest, int dest_max, const int16_t* frame, int frame_size) | 616 | inline__ int toxav_prepare_audio_frame ( ToxAv* av, int32_t call_index, uint8_t* dest, int dest_max, const int16_t* frame, int frame_size) |
613 | { | 617 | { |
614 | int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); | 618 | int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); |
615 | 619 | ||
@@ -629,7 +633,7 @@ inline__ int toxav_prepare_audio_frame ( ToxAv* av, uint32_t call_index, uint8_t | |||
629 | * @retval ToxAvCallType On success. | 633 | * @retval ToxAvCallType On success. |
630 | * @retval ToxAvError On error. | 634 | * @retval ToxAvError On error. |
631 | */ | 635 | */ |
632 | int toxav_get_peer_transmission_type ( ToxAv *av, uint32_t call_index, int peer ) | 636 | int toxav_get_peer_transmission_type ( ToxAv *av, int32_t call_index, int peer ) |
633 | { | 637 | { |
634 | assert(av->msi_session); | 638 | assert(av->msi_session); |
635 | 639 | ||
@@ -647,7 +651,7 @@ int toxav_get_peer_transmission_type ( ToxAv *av, uint32_t call_index, int peer | |||
647 | * @return int | 651 | * @return int |
648 | * @retval ToxAvError No peer id | 652 | * @retval ToxAvError No peer id |
649 | */ | 653 | */ |
650 | int toxav_get_peer_id ( ToxAv* av, uint32_t call_index, int peer ) | 654 | int toxav_get_peer_id ( ToxAv* av, int32_t call_index, int peer ) |
651 | { | 655 | { |
652 | assert(av->msi_session); | 656 | assert(av->msi_session); |
653 | 657 | ||
@@ -665,9 +669,10 @@ int toxav_get_peer_id ( ToxAv* av, uint32_t call_index, int peer ) | |||
665 | * @retval 1 Yes. | 669 | * @retval 1 Yes. |
666 | * @retval 0 No. | 670 | * @retval 0 No. |
667 | */ | 671 | */ |
668 | inline__ int toxav_capability_supported ( ToxAv* av, uint32_t call_index, ToxAvCapabilities capability ) | 672 | inline__ int toxav_capability_supported ( ToxAv* av, int32_t call_index, ToxAvCapabilities capability ) |
669 | { | 673 | { |
670 | return av->calls[call_index].cs->capabilities & (Capabilities) capability; | 674 | return av->calls[call_index].cs ? av->calls[call_index].cs->capabilities & (Capabilities) capability : 0; |
675 | /* 0 is error here */ | ||
671 | } | 676 | } |
672 | 677 | ||
673 | /** | 678 | /** |
@@ -678,9 +683,14 @@ inline__ int toxav_capability_supported ( ToxAv* av, uint32_t call_index, ToxAvC | |||
678 | * @param limit the limit | 683 | * @param limit the limit |
679 | * @return void | 684 | * @return void |
680 | */ | 685 | */ |
681 | void toxav_set_audio_queue_limit(ToxAv* av, uint32_t call_index, uint64_t limit) | 686 | inline__ int toxav_set_audio_queue_limit(ToxAv* av, int32_t call_index, uint64_t limit) |
682 | { | 687 | { |
683 | rtp_queue_adjust_limit(av->calls[call_index].crtps[audio_index], limit); | 688 | if ( av->calls[call_index].crtps[audio_index] ) |
689 | rtp_queue_adjust_limit(av->calls[call_index].crtps[audio_index], limit); | ||
690 | else | ||
691 | return ErrorNoRtpSession; | ||
692 | |||
693 | return ErrorNone; | ||
684 | } | 694 | } |
685 | 695 | ||
686 | /** | 696 | /** |
@@ -691,7 +701,17 @@ void toxav_set_audio_queue_limit(ToxAv* av, uint32_t call_index, uint64_t limit) | |||
691 | * @param limit the limit | 701 | * @param limit the limit |
692 | * @return void | 702 | * @return void |
693 | */ | 703 | */ |
694 | void toxav_set_video_queue_limit(ToxAv* av, uint32_t call_index, uint64_t limit) | 704 | inline__ int toxav_set_video_queue_limit(ToxAv* av, int32_t call_index, uint64_t limit) |
695 | { | 705 | { |
696 | rtp_queue_adjust_limit(av->calls[call_index].crtps[video_index], limit); | 706 | if ( av->calls[call_index].crtps[video_index] ) |
707 | rtp_queue_adjust_limit(av->calls[call_index].crtps[video_index], limit); | ||
708 | else | ||
709 | return ErrorNoRtpSession; | ||
710 | |||
711 | return ErrorNone; | ||
697 | } | 712 | } |
713 | |||
714 | inline__ Tox* toxav_get_tox(ToxAv* av) | ||
715 | { | ||
716 | return (Tox*)av->messenger; | ||
717 | } \ No newline at end of file | ||