summaryrefslogtreecommitdiff
path: root/toxav/rtp.c
diff options
context:
space:
mode:
authormannol <eniz_vukovic@hotmail.com>2014-07-21 01:10:57 +0200
committermannol <eniz_vukovic@hotmail.com>2014-07-21 01:10:57 +0200
commit1aeeef58b2b9e817563c9655d6b736cf41d1c110 (patch)
tree512faccefcb5f70c0640e831cd2209b5bbbf7e83 /toxav/rtp.c
parent77c7a3e1030daf9cfba9dae4f850a7a92810ec83 (diff)
Improved protocol and cleaned code a bit
Diffstat (limited to 'toxav/rtp.c')
-rw-r--r--toxav/rtp.c141
1 files changed, 6 insertions, 135 deletions
diff --git a/toxav/rtp.c b/toxav/rtp.c
index 521e4b22..8b94bda7 100644
--- a/toxav/rtp.c
+++ b/toxav/rtp.c
@@ -1,4 +1,4 @@
1/** toxrtp.c 1/** rtp.c
2 * 2 *
3 * Copyright (C) 2013 Tox project All Rights Reserved. 3 * Copyright (C) 2013 Tox project All Rights Reserved.
4 * 4 *
@@ -372,11 +372,6 @@ int rtp_handle_packet ( void *object, const uint8_t *data, uint32_t length )
372 return -1; 372 return -1;
373 } 373 }
374 374
375 if ( _session->queue_limit <= _session->queue_size ) {
376 LOGGER_WARNING("Queue limit reached!");
377 return -1;
378 }
379
380 _msg = msg_parse ( data + 1, length - 1 ); 375 _msg = msg_parse ( data + 1, length - 1 );
381 376
382 if ( !_msg ) { 377 if ( !_msg ) {
@@ -390,18 +385,7 @@ int rtp_handle_packet ( void *object, const uint8_t *data, uint32_t length )
390 _session->timestamp = _msg->header->timestamp; 385 _session->timestamp = _msg->header->timestamp;
391 } 386 }
392 387
393 pthread_mutex_lock(&_session->mutex); 388 toxav_handle_packet(_session, _msg);
394
395 if ( _session->last_msg ) {
396 _session->last_msg->next = _msg;
397 _session->last_msg = _msg;
398 } else {
399 _session->last_msg = _session->oldest_msg = _msg;
400 }
401
402 _session->queue_size++;
403
404 pthread_mutex_unlock(&_session->mutex);
405 389
406 return 0; 390 return 0;
407} 391}
@@ -467,105 +451,6 @@ RTPMessage *rtp_new_message ( RTPSession *session, const uint8_t *data, uint32_t
467} 451}
468 452
469 453
470
471/**
472 * @brief Release all messages held by session.
473 *
474 * @param session The session.
475 * @return int
476 * @retval -1 Error occurred.
477 * @retval 0 Success.
478 */
479int rtp_release_session_recv ( RTPSession *session )
480{
481 if ( !session ) {
482 LOGGER_WARNING("No session!");
483 return -1;
484 }
485
486 RTPMessage *_tmp, * _it;
487
488 pthread_mutex_lock(&session->mutex);
489
490 for ( _it = session->oldest_msg; _it; _it = _tmp ) {
491 _tmp = _it->next;
492 rtp_free_msg( session, _it);
493 }
494
495 session->last_msg = session->oldest_msg = NULL;
496 session->queue_size = 0;
497
498 pthread_mutex_unlock(&session->mutex);
499
500 return 0;
501}
502
503
504/**
505 * @brief Call this to change queue limit
506 *
507 * @param session The session
508 * @param limit new limit
509 * @return void
510 */
511void rtp_queue_adjust_limit(RTPSession *session, uint64_t limit)
512{
513 pthread_mutex_lock(&session->mutex);
514
515 RTPMessage *_tmp, * _it = session->oldest_msg;
516
517 for ( ; session->queue_size > limit; _it = _tmp ) {
518 _tmp = _it->next;
519 rtp_free_msg( session, _it);
520 session->queue_size --;
521 }
522
523 session->oldest_msg = _it;
524 session->queue_limit = limit;
525
526 pthread_mutex_unlock(&session->mutex);
527}
528
529
530/**
531 * @brief Gets oldest message in the list.
532 *
533 * @param session Where the list is.
534 * @return RTPMessage* The message. You _must_ call rtp_msg_free() to free it.
535 * @retval NULL No messages in the list, or no list.
536 */
537RTPMessage *rtp_recv_msg ( RTPSession *session )
538{
539 if ( !session ) {
540 LOGGER_WARNING("No session!");
541 return NULL;
542 }
543
544 pthread_mutex_lock(&session->mutex);
545
546 if ( session->queue_size == 0 ) {
547 pthread_mutex_unlock(&session->mutex);
548 return NULL;
549 }
550
551
552 RTPMessage *_retu = session->oldest_msg;
553
554 /*if (_retu)*/
555 session->oldest_msg = _retu->next;
556
557 if ( !session->oldest_msg )
558 session->last_msg = NULL;
559
560 session->queue_size --;
561
562 pthread_mutex_unlock(&session->mutex);
563
564
565 return _retu;
566}
567
568
569/** 454/**
570 * @brief Sends data to _RTPSession::dest 455 * @brief Sends data to _RTPSession::dest
571 * 456 *
@@ -627,7 +512,6 @@ void rtp_free_msg ( RTPSession *session, RTPMessage *msg )
627 free ( msg ); 512 free ( msg );
628} 513}
629 514
630
631/** 515/**
632 * @brief Must be called before calling any other rtp function. It's used 516 * @brief Must be called before calling any other rtp function. It's used
633 * to initialize RTP control session. 517 * to initialize RTP control session.
@@ -682,11 +566,6 @@ RTPSession *rtp_init_session ( int payload_type, Messenger *messenger, int frien
682 /* Also set payload type as prefix */ 566 /* Also set payload type as prefix */
683 _retu->prefix = payload_type; 567 _retu->prefix = payload_type;
684 568
685 _retu->oldest_msg = _retu->last_msg = NULL;
686 _retu->queue_limit = 100; /* Default */
687 _retu->queue_size = 0;
688
689 pthread_mutex_init(&_retu->mutex, NULL);
690 /* 569 /*
691 * 570 *
692 */ 571 */
@@ -705,24 +584,16 @@ RTPSession *rtp_init_session ( int payload_type, Messenger *messenger, int frien
705 */ 584 */
706void rtp_terminate_session ( RTPSession *session, Messenger *messenger ) 585void rtp_terminate_session ( RTPSession *session, Messenger *messenger )
707{ 586{
708 if ( !session ) return; 587 if ( !session ) return;
709 588
710 custom_lossy_packet_registerhandler(messenger, session->dest, session->prefix, NULL, NULL); 589 custom_lossy_packet_registerhandler(messenger, session->dest, session->prefix, NULL, NULL);
711 590
712 rtp_release_session_recv(session);
713
714 pthread_mutex_lock(&session->mutex);
715
716 free ( session->ext_header ); 591 free ( session->ext_header );
717 free ( session->csrc ); 592 free ( session->csrc );
718 593
719 pthread_mutex_unlock(&session->mutex);
720
721 pthread_mutex_destroy(&session->mutex);
722
723 LOGGER_DEBUG("Terminated RTP session: %p", session); 594 LOGGER_DEBUG("Terminated RTP session: %p", session);
724 595
725 /* And finally free session */ 596 /* And finally free session */
726 free ( session ); 597 free ( session );
727 598
728} \ No newline at end of file 599}