diff options
Diffstat (limited to 'toxav/toxav.c')
-rw-r--r-- | toxav/toxav.c | 68 |
1 files changed, 33 insertions, 35 deletions
diff --git a/toxav/toxav.c b/toxav/toxav.c index 743d7fcf..e98c9c4b 100644 --- a/toxav/toxav.c +++ b/toxav/toxav.c | |||
@@ -66,7 +66,7 @@ typedef struct _CallSpecific { | |||
66 | uint32_t frame_limit; /* largest address written to in frame_buf for current input frame*/ | 66 | uint32_t frame_limit; /* largest address written to in frame_buf for current input frame*/ |
67 | uint8_t frame_id, frame_outid; /* id of input and output video frame */ | 67 | uint8_t frame_id, frame_outid; /* id of input and output video frame */ |
68 | void *frame_buf; /* buffer for split video payloads */ | 68 | void *frame_buf; /* buffer for split video payloads */ |
69 | 69 | ||
70 | _Bool call_active; | 70 | _Bool call_active; |
71 | } CallSpecific; | 71 | } CallSpecific; |
72 | 72 | ||
@@ -298,8 +298,8 @@ int toxav_stop_call ( ToxAv *av, int32_t call_index ) | |||
298 | */ | 298 | */ |
299 | int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettings *codec_settings, int support_video ) | 299 | int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettings *codec_settings, int support_video ) |
300 | { | 300 | { |
301 | if ( !av->msi_session || cii(call_index, av->msi_session) || | 301 | if ( !av->msi_session || cii(call_index, av->msi_session) || |
302 | !av->msi_session->calls[call_index] || av->calls[call_index].call_active) { | 302 | !av->msi_session->calls[call_index] || av->calls[call_index].call_active) { |
303 | LOGGER_ERROR("Error while starting RTP session: invalid call!\n"); | 303 | LOGGER_ERROR("Error while starting RTP session: invalid call!\n"); |
304 | return ErrorInternal; | 304 | return ErrorInternal; |
305 | } | 305 | } |
@@ -323,8 +323,8 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin | |||
323 | 323 | ||
324 | if ( !call->crtps[video_index] ) { | 324 | if ( !call->crtps[video_index] ) { |
325 | LOGGER_ERROR("Error while starting video RTP session!\n"); | 325 | LOGGER_ERROR("Error while starting video RTP session!\n"); |
326 | 326 | ||
327 | rtp_terminate_session(call->crtps[audio_index], av->messenger); | 327 | rtp_terminate_session(call->crtps[audio_index], av->messenger); |
328 | return ErrorStartingVideoRtp; | 328 | return ErrorStartingVideoRtp; |
329 | } | 329 | } |
330 | 330 | ||
@@ -343,7 +343,7 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin | |||
343 | 343 | ||
344 | } | 344 | } |
345 | 345 | ||
346 | if ( !(call->j_buf = create_queue(codec_settings->jbuf_capacity)) ) { | 346 | if ( !(call->j_buf = create_queue(codec_settings->jbuf_capacity)) ) { |
347 | rtp_terminate_session(call->crtps[audio_index], av->messenger); | 347 | rtp_terminate_session(call->crtps[audio_index], av->messenger); |
348 | rtp_terminate_session(call->crtps[video_index], av->messenger); | 348 | rtp_terminate_session(call->crtps[video_index], av->messenger); |
349 | free(call->frame_buf); | 349 | free(call->frame_buf); |
@@ -352,22 +352,22 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin | |||
352 | } | 352 | } |
353 | 353 | ||
354 | if ( (call->cs = codec_init_session(codec_settings->audio_bitrate, | 354 | if ( (call->cs = codec_init_session(codec_settings->audio_bitrate, |
355 | codec_settings->audio_frame_duration, | 355 | codec_settings->audio_frame_duration, |
356 | codec_settings->audio_sample_rate, | 356 | codec_settings->audio_sample_rate, |
357 | codec_settings->audio_channels, | 357 | codec_settings->audio_channels, |
358 | codec_settings->audio_VAD_tolerance, | 358 | codec_settings->audio_VAD_tolerance, |
359 | codec_settings->video_width, | 359 | codec_settings->video_width, |
360 | codec_settings->video_height, | 360 | codec_settings->video_height, |
361 | codec_settings->video_bitrate) )) { | 361 | codec_settings->video_bitrate) )) { |
362 | call->call_active = 1; | 362 | call->call_active = 1; |
363 | return ErrorNone; | 363 | return ErrorNone; |
364 | } | 364 | } |
365 | 365 | ||
366 | rtp_terminate_session(call->crtps[audio_index], av->messenger); | 366 | rtp_terminate_session(call->crtps[audio_index], av->messenger); |
367 | rtp_terminate_session(call->crtps[video_index], av->messenger); | 367 | rtp_terminate_session(call->crtps[video_index], av->messenger); |
368 | free(call->frame_buf); | 368 | free(call->frame_buf); |
369 | terminate_queue(call->j_buf); | 369 | terminate_queue(call->j_buf); |
370 | 370 | ||
371 | return ErrorInternal; | 371 | return ErrorInternal; |
372 | } | 372 | } |
373 | 373 | ||
@@ -381,26 +381,24 @@ int toxav_prepare_transmission ( ToxAv *av, int32_t call_index, ToxAvCodecSettin | |||
381 | */ | 381 | */ |
382 | int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) | 382 | int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) |
383 | { | 383 | { |
384 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 384 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
385 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 385 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
386 | return ErrorNoCall; | 386 | return ErrorNoCall; |
387 | } | 387 | } |
388 | 388 | ||
389 | CallSpecific *call = &av->calls[call_index]; | 389 | CallSpecific *call = &av->calls[call_index]; |
390 | 390 | ||
391 | call->call_active = 0; | 391 | call->call_active = 0; |
392 | 392 | ||
393 | if ( call->crtps[audio_index] && -1 == rtp_terminate_session(call->crtps[audio_index], av->messenger) ) { | 393 | if ( call->crtps[audio_index] && -1 == rtp_terminate_session(call->crtps[audio_index], av->messenger) ) { |
394 | LOGGER_ERROR("Error while terminating audio RTP session!\n"); | 394 | LOGGER_ERROR("Error while terminating audio RTP session!\n"); |
395 | /*return ErrorTerminatingAudioRtp;*/ | 395 | /*return ErrorTerminatingAudioRtp;*/ |
396 | } | 396 | } else call->crtps[audio_index] = NULL; |
397 | else call->crtps[audio_index] = NULL; | ||
398 | 397 | ||
399 | if ( call->crtps[video_index] && -1 == rtp_terminate_session(call->crtps[video_index], av->messenger) ) { | 398 | if ( call->crtps[video_index] && -1 == rtp_terminate_session(call->crtps[video_index], av->messenger) ) { |
400 | LOGGER_ERROR("Error while terminating video RTP session!\n"); | 399 | LOGGER_ERROR("Error while terminating video RTP session!\n"); |
401 | /*return ErrorTerminatingVideoRtp;*/ | 400 | /*return ErrorTerminatingVideoRtp;*/ |
402 | } | 401 | } else call->crtps[video_index] = NULL; |
403 | else call->crtps[video_index] = NULL; | ||
404 | 402 | ||
405 | if ( call->j_buf ) { | 403 | if ( call->j_buf ) { |
406 | terminate_queue(call->j_buf); | 404 | terminate_queue(call->j_buf); |
@@ -414,7 +412,7 @@ int toxav_kill_transmission ( ToxAv *av, int32_t call_index ) | |||
414 | LOGGER_DEBUG("Terminated codec session"); | 412 | LOGGER_DEBUG("Terminated codec session"); |
415 | } else LOGGER_DEBUG("No codec session"); | 413 | } else LOGGER_DEBUG("No codec session"); |
416 | 414 | ||
417 | 415 | ||
418 | return ErrorNone; | 416 | return ErrorNone; |
419 | } | 417 | } |
420 | 418 | ||
@@ -541,11 +539,11 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out | |||
541 | { | 539 | { |
542 | if ( !output ) return ErrorInternal; | 540 | if ( !output ) return ErrorInternal; |
543 | 541 | ||
544 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 542 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
545 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 543 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
546 | return ErrorNoCall; | 544 | return ErrorNoCall; |
547 | } | 545 | } |
548 | 546 | ||
549 | 547 | ||
550 | uint8_t packet [RTP_PAYLOAD_SIZE]; | 548 | uint8_t packet [RTP_PAYLOAD_SIZE]; |
551 | CallSpecific *call = &av->calls[call_index]; | 549 | CallSpecific *call = &av->calls[call_index]; |
@@ -613,11 +611,11 @@ inline__ int toxav_recv_video ( ToxAv *av, int32_t call_index, vpx_image_t **out | |||
613 | */ | 611 | */ |
614 | inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) | 612 | inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) |
615 | { | 613 | { |
616 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 614 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
617 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 615 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
618 | return ErrorNoCall; | 616 | return ErrorNoCall; |
619 | } | 617 | } |
620 | 618 | ||
621 | 619 | ||
622 | return toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); | 620 | return toxav_send_rtp_payload(av, call_index, TypeVideo, frame, frame_size); |
623 | } | 621 | } |
@@ -635,11 +633,11 @@ inline__ int toxav_send_video ( ToxAv *av, int32_t call_index, const uint8_t *fr | |||
635 | */ | 633 | */ |
636 | inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input) | 634 | inline__ int toxav_prepare_video_frame(ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, vpx_image_t *input) |
637 | { | 635 | { |
638 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 636 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
639 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 637 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
640 | return ErrorNoCall; | 638 | return ErrorNoCall; |
641 | } | 639 | } |
642 | 640 | ||
643 | 641 | ||
644 | CallSpecific *call = &av->calls[call_index]; | 642 | CallSpecific *call = &av->calls[call_index]; |
645 | 643 | ||
@@ -684,11 +682,11 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i | |||
684 | { | 682 | { |
685 | if ( !dest ) return ErrorInternal; | 683 | if ( !dest ) return ErrorInternal; |
686 | 684 | ||
687 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 685 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
688 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 686 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
689 | return ErrorNoCall; | 687 | return ErrorNoCall; |
690 | } | 688 | } |
691 | 689 | ||
692 | 690 | ||
693 | CallSpecific *call = &av->calls[call_index]; | 691 | CallSpecific *call = &av->calls[call_index]; |
694 | 692 | ||
@@ -729,11 +727,11 @@ inline__ int toxav_recv_audio ( ToxAv *av, int32_t call_index, int frame_size, i | |||
729 | */ | 727 | */ |
730 | inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) | 728 | inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *frame, int frame_size) |
731 | { | 729 | { |
732 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 730 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
733 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 731 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
734 | return ErrorNoCall; | 732 | return ErrorNoCall; |
735 | } | 733 | } |
736 | 734 | ||
737 | 735 | ||
738 | return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); | 736 | return toxav_send_rtp_payload(av, call_index, TypeAudio, frame, frame_size); |
739 | } | 737 | } |
@@ -753,11 +751,11 @@ inline__ int toxav_send_audio ( ToxAv *av, int32_t call_index, const uint8_t *fr | |||
753 | inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, | 751 | inline__ int toxav_prepare_audio_frame ( ToxAv *av, int32_t call_index, uint8_t *dest, int dest_max, |
754 | const int16_t *frame, int frame_size) | 752 | const int16_t *frame, int frame_size) |
755 | { | 753 | { |
756 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { | 754 | if (cii(call_index, av->msi_session) || !av->calls[call_index].call_active) { |
757 | LOGGER_WARNING("Action on inactive call: %d", call_index); | 755 | LOGGER_WARNING("Action on inactive call: %d", call_index); |
758 | return ErrorNoCall; | 756 | return ErrorNoCall; |
759 | } | 757 | } |
760 | 758 | ||
761 | 759 | ||
762 | int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); | 760 | int32_t rc = opus_encode(av->calls[call_index].cs->audio_encoder, frame, frame_size, dest, dest_max); |
763 | 761 | ||