- Timestamp:
- Oct 18, 2010 4:23:25 AM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjmedia/src/pjmedia/transport_srtp.c
r3221 r3348 481 481 int au_rx_idx = 0; 482 482 int crypto_suites_cnt; 483 pj_status_t status = PJ_SUCCESS; 483 484 484 485 PJ_ASSERT_RETURN(tp && tx && rx, PJ_EINVAL); 486 487 pj_lock_acquire(srtp->mutex); 485 488 486 489 if (srtp->session_inited) { … … 506 509 if (cr_tx_idx == -1 || cr_rx_idx == -1 || au_tx_idx == -1 || 507 510 au_rx_idx == -1) 508 return PJMEDIA_SRTP_ENOTSUPCRYPTO; 511 { 512 status = PJMEDIA_SRTP_ENOTSUPCRYPTO; 513 goto on_return; 514 } 509 515 510 516 /* If all options points to 'NULL' method, just bypass SRTP */ 511 517 if (cr_tx_idx == 0 && cr_rx_idx == 0 && au_tx_idx == 0 && au_rx_idx == 0) { 512 518 srtp->bypass_srtp = PJ_TRUE; 513 return PJ_SUCCESS;519 goto on_return; 514 520 } 515 521 … … 517 523 if (tx->key.slen != (pj_ssize_t)crypto_suites[cr_tx_idx].cipher_key_len || 518 524 rx->key.slen != (pj_ssize_t)crypto_suites[cr_rx_idx].cipher_key_len) 519 return PJMEDIA_SRTP_EINKEYLEN; 525 { 526 status = PJMEDIA_SRTP_EINKEYLEN; 527 goto on_return; 528 } 520 529 521 530 /* Init transmit direction */ … … 543 552 err = srtp_create(&srtp->srtp_tx_ctx, &tx_); 544 553 if (err != err_status_ok) { 545 return PJMEDIA_ERRNO_FROM_LIBSRTP(err); 554 status = PJMEDIA_ERRNO_FROM_LIBSRTP(err); 555 goto on_return; 546 556 } 547 557 srtp->tx_policy = *tx; … … 576 586 if (err != err_status_ok) { 577 587 srtp_dealloc(srtp->srtp_tx_ctx); 578 return PJMEDIA_ERRNO_FROM_LIBSRTP(err); 588 status = PJMEDIA_ERRNO_FROM_LIBSRTP(err); 589 goto on_return; 579 590 } 580 591 srtp->rx_policy = *rx; … … 599 610 } 600 611 601 return PJ_SUCCESS; 612 on_return: 613 pj_lock_release(srtp->mutex); 614 return status; 602 615 } 603 616 … … 612 625 PJ_ASSERT_RETURN(srtp, PJ_EINVAL); 613 626 614 if (!p_srtp->session_inited) 627 pj_lock_acquire(p_srtp->mutex); 628 629 if (!p_srtp->session_inited) { 630 pj_lock_release(p_srtp->mutex); 615 631 return PJ_SUCCESS; 632 } 616 633 617 634 err = srtp_dealloc(p_srtp->srtp_rx_ctx); … … 629 646 630 647 p_srtp->session_inited = PJ_FALSE; 648 649 pj_lock_release(p_srtp->mutex); 631 650 632 651 return PJ_SUCCESS; … … 688 707 689 708 /* Save the callbacks */ 709 pj_lock_acquire(srtp->mutex); 690 710 srtp->rtp_cb = rtp_cb; 691 711 srtp->rtcp_cb = rtcp_cb; 692 712 srtp->user_data = user_data; 713 pj_lock_release(srtp->mutex); 693 714 694 715 /* Attach itself to transport */ … … 697 718 &srtp_rtcp_cb); 698 719 if (status != PJ_SUCCESS) { 720 pj_lock_acquire(srtp->mutex); 699 721 srtp->rtp_cb = NULL; 700 722 srtp->rtcp_cb = NULL; 701 723 srtp->user_data = NULL; 724 pj_lock_release(srtp->mutex); 702 725 return status; 703 726 } … … 718 741 719 742 /* Clear up application infos from transport */ 743 pj_lock_acquire(srtp->mutex); 720 744 srtp->rtp_cb = NULL; 721 745 srtp->rtcp_cb = NULL; 722 746 srtp->user_data = NULL; 747 pj_lock_release(srtp->mutex); 723 748 } 724 749 … … 735 760 return pjmedia_transport_send_rtp(srtp->member_tp, pkt, size); 736 761 737 if (!srtp->session_inited)738 return PJ_SUCCESS;739 740 762 if (size > sizeof(srtp->rtp_tx_buffer)) 741 763 return PJ_ETOOBIG; … … 744 766 745 767 pj_lock_acquire(srtp->mutex); 768 if (!srtp->session_inited) { 769 pj_lock_release(srtp->mutex); 770 return PJ_EINVALIDOP; 771 } 746 772 err = srtp_protect(srtp->srtp_tx_ctx, srtp->rtp_tx_buffer, &len); 747 773 pj_lock_release(srtp->mutex); … … 779 805 } 780 806 781 if (!srtp->session_inited)782 return PJ_SUCCESS;783 784 807 if (size > sizeof(srtp->rtcp_tx_buffer)) 785 808 return PJ_ETOOBIG; … … 788 811 789 812 pj_lock_acquire(srtp->mutex); 813 if (!srtp->session_inited) { 814 pj_lock_release(srtp->mutex); 815 return PJ_EINVALIDOP; 816 } 790 817 err = srtp_protect_rtcp(srtp->srtp_tx_ctx, srtp->rtcp_tx_buffer, &len); 791 818 pj_lock_release(srtp->mutex); … … 820 847 PJ_ASSERT_RETURN(tp, PJ_EINVAL); 821 848 822 pj_lock_acquire(srtp->mutex);823 824 849 if (srtp->setting.close_member_tp && srtp->member_tp) { 825 850 pjmedia_transport_close(srtp->member_tp); … … 828 853 status = pjmedia_transport_srtp_stop(tp); 829 854 855 /* In case mutex is being acquired by other thread */ 856 pj_lock_acquire(srtp->mutex); 830 857 pj_lock_release(srtp->mutex); 831 858 … … 844 871 int len = size; 845 872 err_status_t err; 873 void (*cb)(void*, void*, pj_ssize_t) = NULL; 874 void *cb_data = NULL; 846 875 847 876 if (srtp->bypass_srtp) { … … 850 879 } 851 880 852 if (size < 0 || !srtp->session_inited) {881 if (size < 0) { 853 882 return; 854 883 } … … 862 891 pj_lock_acquire(srtp->mutex); 863 892 893 if (!srtp->session_inited) { 894 pj_lock_release(srtp->mutex); 895 return; 896 } 864 897 err = srtp_unprotect(srtp->srtp_rx_ctx, (pj_uint8_t*)pkt, &len); 865 866 898 if (srtp->probation_cnt > 0 && 867 899 (err == err_status_replay_old || err == err_status_replay_fail)) … … 885 917 } 886 918 887 if (err == err_status_ok) { 888 srtp->rtp_cb(srtp->user_data, pkt, len); 889 } else { 919 if (err != err_status_ok) { 890 920 PJ_LOG(5,(srtp->pool->obj_name, 891 921 "Failed to unprotect SRTP, pkt size=%d, err=%s", 892 922 size, get_libsrtp_errstr(err))); 923 } else { 924 cb = srtp->rtp_cb; 925 cb_data = srtp->user_data; 893 926 } 894 927 895 928 pj_lock_release(srtp->mutex); 929 930 if (cb) { 931 (*cb)(cb_data, pkt, len); 932 } 896 933 } 897 934 … … 904 941 int len = size; 905 942 err_status_t err; 943 void (*cb)(void*, void*, pj_ssize_t) = NULL; 944 void *cb_data = NULL; 906 945 907 946 if (srtp->bypass_srtp) { … … 910 949 } 911 950 912 if (size < 0 || !srtp->session_inited) {951 if (size < 0) { 913 952 return; 914 953 } … … 919 958 pj_lock_acquire(srtp->mutex); 920 959 960 if (!srtp->session_inited) { 961 pj_lock_release(srtp->mutex); 962 return; 963 } 921 964 err = srtp_unprotect_rtcp(srtp->srtp_rx_ctx, (pj_uint8_t*)pkt, &len); 922 923 if (err == err_status_ok) { 924 srtp->rtcp_cb(srtp->user_data, pkt, len); 925 } else { 965 if (err != err_status_ok) { 926 966 PJ_LOG(5,(srtp->pool->obj_name, 927 967 "Failed to unprotect SRTCP, pkt size=%d, err=%s", 928 968 size, get_libsrtp_errstr(err))); 929 } 930 969 } else { 970 cb = srtp->rtcp_cb; 971 cb_data = srtp->user_data; 972 } 973 931 974 pj_lock_release(srtp->mutex); 975 976 if (cb) { 977 (*cb)(cb_data, pkt, len); 978 } 932 979 } 933 980 … … 1572 1619 pj_lock_acquire(srtp->mutex); 1573 1620 1621 if (!srtp->session_inited) { 1622 pj_lock_release(srtp->mutex); 1623 return PJ_EINVALIDOP; 1624 } 1625 1574 1626 if (is_rtp) 1575 1627 err = srtp_unprotect(srtp->srtp_rx_ctx, pkt, pkt_len);
Note: See TracChangeset
for help on using the changeset viewer.