Changeset 729 for pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
- Timestamp:
- Sep 19, 2006 1:37:53 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
pjproject/trunk/pjsip/src/pjsua-lib/pjsua_call.c
r719 r729 384 384 return PJ_FALSE; 385 385 386 PJSUA_LOCK(); 386 387 387 388 /* Verify that we can handle the request. */ … … 408 409 } 409 410 411 PJSUA_UNLOCK(); 410 412 return PJ_TRUE; 411 413 } … … 428 430 PJ_LOG(2,(THIS_FILE, 429 431 "Unable to accept incoming call (too many calls)")); 432 PJSUA_UNLOCK(); 430 433 return PJ_TRUE; 431 434 } … … 446 449 pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 447 450 NULL, NULL); 451 PJSUA_UNLOCK(); 448 452 return PJ_TRUE; 449 453 } … … 463 467 pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 464 468 NULL, NULL); 469 PJSUA_UNLOCK(); 465 470 return PJ_TRUE; 466 471 } … … 472 477 pjsip_endpt_respond_stateless(pjsua_var.endpt, rdata, 500, NULL, 473 478 NULL, NULL); 474 479 PJSUA_UNLOCK(); 475 480 return PJ_TRUE; 476 481 } … … 500 505 pjsip_dlg_terminate(dlg); 501 506 */ 507 PJSUA_UNLOCK(); 502 508 return PJ_TRUE; 503 509 } … … 521 527 pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL); 522 528 pjsip_inv_terminate(inv, 500, PJ_FALSE); 529 PJSUA_UNLOCK(); 523 530 return PJ_TRUE; 524 531 … … 537 544 538 545 /* This INVITE request has been handled. */ 546 PJSUA_UNLOCK(); 539 547 return PJ_TRUE; 540 548 } … … 566 574 567 575 576 /* Acquire lock to the specified call_id */ 577 static pj_status_t acquire_call(const char *title, 578 pjsua_call_id call_id, 579 pjsua_call **p_call) 580 { 581 enum { MAX_RETRY=50 }; 582 unsigned retry; 583 pjsua_call *call; 584 pj_bool_t has_pjsua_lock; 585 pj_status_t status; 586 587 for (retry=0; retry<MAX_RETRY; ++retry) { 588 589 has_pjsua_lock = PJ_FALSE; 590 591 status = PJSUA_TRY_LOCK(); 592 if (status != PJ_SUCCESS) { 593 pj_thread_sleep(retry/10); 594 continue; 595 } 596 597 has_pjsua_lock = PJ_TRUE; 598 call = &pjsua_var.calls[call_id]; 599 600 if (call->inv == NULL) { 601 PJSUA_UNLOCK(); 602 PJ_LOG(3,(THIS_FILE, "Invalid call_id %d in %s", call_id, title)); 603 return PJSIP_ESESSIONTERMINATED; 604 } 605 606 status = pjsip_dlg_try_inc_lock(call->inv->dlg); 607 if (status != PJ_SUCCESS) { 608 PJSUA_UNLOCK(); 609 pj_thread_sleep(retry/10); 610 continue; 611 } 612 613 PJSUA_UNLOCK(); 614 615 break; 616 } 617 618 if (status != PJ_SUCCESS) { 619 if (has_pjsua_lock == PJ_FALSE) 620 PJ_LOG(1,(THIS_FILE, "Timed-out trying to acquire PJSUA mutex " 621 "(possibly system has deadlocked) in %s", 622 title)); 623 else 624 PJ_LOG(1,(THIS_FILE, "Timed-out trying to acquire dialog mutex " 625 "(possibly system has deadlocked) in %s", 626 title)); 627 return PJ_ETIMEDOUT; 628 } 629 630 *p_call = call; 631 632 return PJ_SUCCESS; 633 } 634 635 568 636 /* 569 637 * Get the conference port identification associated with the call. … … 571 639 PJ_DEF(pjsua_conf_port_id) pjsua_call_get_conf_port(pjsua_call_id call_id) 572 640 { 641 pjsua_call *call; 642 pjsua_conf_port_id port_id; 643 pj_status_t status; 644 573 645 PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 574 646 PJ_EINVAL); 575 return pjsua_var.calls[call_id].conf_slot; 576 } 647 648 status = acquire_call("pjsua_call_get_conf_port()", call_id, &call); 649 if (status != PJ_SUCCESS) 650 return -1; 651 652 port_id = call->conf_slot; 653 654 pjsip_dlg_dec_lock(call->inv->dlg); 655 656 return port_id; 657 } 658 577 659 578 660 … … 584 666 { 585 667 pjsua_call *call; 668 pj_status_t status; 586 669 587 670 PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, … … 590 673 pj_bzero(info, sizeof(*info)); 591 674 592 PJSUA_LOCK(); 593 594 call = &pjsua_var.calls[call_id]; 595 596 if (call->inv == NULL) { 597 PJSUA_UNLOCK(); 598 return PJ_SUCCESS; 599 } 600 601 pjsip_dlg_inc_lock(call->inv->dlg); 602 675 status = acquire_call("pjsua_call_get_info()", call_id, &call); 676 if (status != PJ_SUCCESS) { 677 return status; 678 } 603 679 604 680 /* id and role */ … … 697 773 698 774 pjsip_dlg_dec_lock(call->inv->dlg); 699 PJSUA_UNLOCK();700 775 701 776 return PJ_SUCCESS; … … 743 818 PJ_EINVAL); 744 819 745 PJSUA_LOCK(); 746 747 call = &pjsua_var.calls[call_id]; 748 749 if (call->inv == NULL) { 750 PJ_LOG(3,(THIS_FILE, "Call %d already disconnected", call_id)); 751 PJSUA_UNLOCK(); 752 return PJSIP_ESESSIONTERMINATED; 753 } 820 status = acquire_call("pjsua_call_answer()", call_id, &call); 821 if (status != PJ_SUCCESS) 822 return status; 754 823 755 824 if (call->res_time.sec == 0) … … 761 830 pjsua_perror(THIS_FILE, "Error creating response", 762 831 status); 763 PJSUA_UNLOCK();832 pjsip_dlg_dec_lock(call->inv->dlg); 764 833 return status; 765 834 } … … 774 843 status); 775 844 776 PJSUA_UNLOCK();845 pjsip_dlg_dec_lock(call->inv->dlg); 777 846 778 847 return status; … … 794 863 795 864 865 if (call_id<0 || call_id>=(int)pjsua_var.ua_cfg.max_calls) { 866 PJ_LOG(1,(THIS_FILE, "pjsua_call_hangup(): invalid call id %d", 867 call_id)); 868 } 869 796 870 PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 797 871 PJ_EINVAL); 798 872 799 PJSUA_LOCK(); 800 801 call = &pjsua_var.calls[call_id]; 802 803 if (!call->inv) { 804 PJ_LOG(3,(THIS_FILE,"Invalid call or call has been disconnected")); 805 PJSUA_UNLOCK(); 806 return PJ_EINVAL; 807 } 873 status = acquire_call("pjsua_call_hangup()", call_id, &call); 874 if (status != PJ_SUCCESS) 875 return status; 808 876 809 877 if (code==0) { … … 821 889 "Failed to create end session message", 822 890 status); 823 PJSUA_UNLOCK();891 pjsip_dlg_dec_lock(call->inv->dlg); 824 892 return status; 825 893 } … … 830 898 */ 831 899 if (tdata == NULL) { 832 PJSUA_UNLOCK();900 pjsip_dlg_dec_lock(call->inv->dlg); 833 901 return PJ_SUCCESS; 834 902 } … … 843 911 "Failed to send end session message", 844 912 status); 845 PJSUA_UNLOCK();913 pjsip_dlg_dec_lock(call->inv->dlg); 846 914 return status; 847 915 } 848 916 849 PJSUA_UNLOCK();917 pjsip_dlg_dec_lock(call->inv->dlg); 850 918 851 919 return PJ_SUCCESS; … … 867 935 PJ_EINVAL); 868 936 869 PJSUA_LOCK(); 870 871 call = &pjsua_var.calls[call_id]; 872 873 if (!call->inv) { 874 PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 875 PJSUA_UNLOCK(); 876 return PJSIP_ESESSIONTERMINATED; 877 } 937 status = acquire_call("pjsua_call_set_hold()", call_id, &call); 938 if (status != PJ_SUCCESS) 939 return status; 940 878 941 879 942 if (call->inv->state != PJSIP_INV_STATE_CONFIRMED) { 880 943 PJ_LOG(3,(THIS_FILE, "Can not hold call that is not confirmed")); 881 PJSUA_UNLOCK();944 pjsip_dlg_dec_lock(call->inv->dlg); 882 945 return PJSIP_ESESSIONSTATE; 883 946 } … … 885 948 status = create_inactive_sdp(call, &sdp); 886 949 if (status != PJ_SUCCESS) { 887 PJSUA_UNLOCK();950 pjsip_dlg_dec_lock(call->inv->dlg); 888 951 return status; 889 952 } … … 893 956 if (status != PJ_SUCCESS) { 894 957 pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status); 895 PJSUA_UNLOCK();958 pjsip_dlg_dec_lock(call->inv->dlg); 896 959 return status; 897 960 } … … 904 967 if (status != PJ_SUCCESS) { 905 968 pjsua_perror(THIS_FILE, "Unable to send re-INVITE", status); 906 PJSUA_UNLOCK();969 pjsip_dlg_dec_lock(call->inv->dlg); 907 970 return status; 908 971 } 909 972 910 PJSUA_UNLOCK();973 pjsip_dlg_dec_lock(call->inv->dlg); 911 974 912 975 return PJ_SUCCESS; … … 930 993 PJ_EINVAL); 931 994 932 PJSUA_LOCK(); 933 934 call = &pjsua_var.calls[call_id]; 935 936 if (!call->inv) { 937 PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 938 PJSUA_UNLOCK(); 939 return PJSIP_ESESSIONTERMINATED; 940 } 941 995 status = acquire_call("pjsua_call_reinvite()", call_id, &call); 996 if (status != PJ_SUCCESS) 997 return status; 942 998 943 999 if (call->inv->state != PJSIP_INV_STATE_CONFIRMED) { 944 1000 PJ_LOG(3,(THIS_FILE, "Can not re-INVITE call that is not confirmed")); 945 PJSUA_UNLOCK();1001 pjsip_dlg_dec_lock(call->inv->dlg); 946 1002 return PJSIP_ESESSIONSTATE; 947 1003 } … … 955 1011 pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint", 956 1012 status); 957 PJSUA_UNLOCK();1013 pjsip_dlg_dec_lock(call->inv->dlg); 958 1014 return status; 959 1015 } … … 963 1019 if (status != PJ_SUCCESS) { 964 1020 pjsua_perror(THIS_FILE, "Unable to create re-INVITE", status); 965 PJSUA_UNLOCK();1021 pjsip_dlg_dec_lock(call->inv->dlg); 966 1022 return status; 967 1023 } … … 974 1030 if (status != PJ_SUCCESS) { 975 1031 pjsua_perror(THIS_FILE, "Unable to send re-INVITE", status); 976 PJSUA_UNLOCK();1032 pjsip_dlg_dec_lock(call->inv->dlg); 977 1033 return status; 978 1034 } 979 1035 980 PJSUA_UNLOCK();1036 pjsip_dlg_dec_lock(call->inv->dlg); 981 1037 982 1038 return PJ_SUCCESS; … … 1000 1056 PJ_EINVAL); 1001 1057 1002 PJSUA_LOCK(); 1003 1004 call = &pjsua_var.calls[call_id]; 1005 1006 if (!call->inv) { 1007 PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 1008 PJSUA_UNLOCK(); 1009 return PJSIP_ESESSIONTERMINATED; 1010 } 1058 pjsip_dlg_dec_lock(call->inv->dlg); 1059 status = acquire_call("pjsua_call_xfer()", call_id, &call); 1060 if (status != PJ_SUCCESS) 1061 return status; 1062 1011 1063 1012 1064 /* Create xfer client subscription. … … 1017 1069 if (status != PJ_SUCCESS) { 1018 1070 pjsua_perror(THIS_FILE, "Unable to create xfer", status); 1019 PJSUA_UNLOCK();1071 pjsip_dlg_dec_lock(call->inv->dlg); 1020 1072 return status; 1021 1073 } … … 1027 1079 if (status != PJ_SUCCESS) { 1028 1080 pjsua_perror(THIS_FILE, "Unable to create REFER request", status); 1029 PJSUA_UNLOCK();1081 pjsip_dlg_dec_lock(call->inv->dlg); 1030 1082 return status; 1031 1083 } … … 1038 1090 if (status != PJ_SUCCESS) { 1039 1091 pjsua_perror(THIS_FILE, "Unable to send REFER request", status); 1040 PJSUA_UNLOCK();1092 pjsip_dlg_dec_lock(call->inv->dlg); 1041 1093 return status; 1042 1094 } … … 1047 1099 */ 1048 1100 1049 PJSUA_UNLOCK();1101 pjsip_dlg_dec_lock(call->inv->dlg); 1050 1102 1051 1103 return PJ_SUCCESS; … … 1066 1118 PJ_EINVAL); 1067 1119 1068 PJSUA_LOCK(); 1120 status = acquire_call("pjsua_call_dial_dtmf()", call_id, &call); 1121 if (status != PJ_SUCCESS) 1122 return status; 1069 1123 1070 1124 call = &pjsua_var.calls[call_id]; … … 1072 1126 if (!call->session) { 1073 1127 PJ_LOG(3,(THIS_FILE, "Media is not established yet!")); 1074 PJSUA_UNLOCK();1128 pjsip_dlg_dec_lock(call->inv->dlg); 1075 1129 return PJ_EINVALIDOP; 1076 1130 } … … 1078 1132 status = pjmedia_session_dial_dtmf( call->session, 0, digits); 1079 1133 1080 PJSUA_UNLOCK();1134 pjsip_dlg_dec_lock(call->inv->dlg); 1081 1135 1082 1136 return status; … … 1104 1158 PJ_EINVAL); 1105 1159 1106 PJSUA_LOCK(); 1107 1108 call = &pjsua_var.calls[call_id]; 1109 1110 if (!call->inv) { 1111 PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 1112 PJSUA_UNLOCK(); 1113 return PJSIP_ESESSIONTERMINATED; 1114 } 1115 1116 /* Lock dialog. */ 1117 pjsip_dlg_inc_lock(call->inv->dlg); 1118 1160 status = acquire_call("pjsua_call_send_im", call_id, &call); 1161 if (status != PJ_SUCCESS) 1162 return status; 1163 1119 1164 /* Set default media type if none is specified */ 1120 1165 if (mime_type == NULL) { … … 1168 1213 on_return: 1169 1214 pjsip_dlg_dec_lock(call->inv->dlg); 1170 PJSUA_UNLOCK();1171 1215 return status; 1172 1216 } … … 1184 1228 pj_status_t status; 1185 1229 1186 1187 1230 PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls, 1188 1231 PJ_EINVAL); 1189 1232 1190 PJSUA_LOCK(); 1191 1192 call = &pjsua_var.calls[call_id]; 1193 1194 if (!call->inv) { 1195 PJ_LOG(3,(THIS_FILE,"Call has been disconnected")); 1196 PJSUA_UNLOCK(); 1197 return PJSIP_ESESSIONTERMINATED; 1198 } 1199 1200 /* Lock dialog. */ 1201 pjsip_dlg_inc_lock(call->inv->dlg); 1202 1233 status = acquire_call("pjsua_call_send_typing_ind", call_id, &call); 1234 if (status != PJ_SUCCESS) 1235 return status; 1236 1203 1237 /* Create request message. */ 1204 1238 status = pjsip_dlg_create_request( call->inv->dlg, &pjsip_message_method, … … 1225 1259 on_return: 1226 1260 pjsip_dlg_dec_lock(call->inv->dlg); 1227 PJSUA_UNLOCK();1228 1261 return status; 1229 1262 } … … 1502 1535 char tmp[128]; 1503 1536 char *p, *end; 1537 pj_status_t status; 1504 1538 int len; 1505 1539 … … 1507 1541 PJ_EINVAL); 1508 1542 1509 PJSUA_LOCK();1510 1511 call = &pjsua_var.calls[call_id];1543 status = acquire_call("pjsua_call_dump()", call_id, &call); 1544 if (status != PJ_SUCCESS) 1545 return status; 1512 1546 1513 1547 *buffer = '\0'; … … 1515 1549 end = buffer + maxlen; 1516 1550 len = 0; 1517 1518 if (call->inv == NULL) {1519 PJSUA_UNLOCK();1520 return PJ_EINVALIDOP;1521 }1522 1551 1523 1552 print_call(indent, call_id, tmp, sizeof(tmp)); … … 1570 1599 dump_media_session(indent, p, end-p, call->session); 1571 1600 1572 PJSUA_UNLOCK();1601 pjsip_dlg_dec_lock(call->inv->dlg); 1573 1602 1574 1603 return PJ_SUCCESS;
Note: See TracChangeset
for help on using the changeset viewer.