Ok I am grabbing this question because I am able to do this with this version. This is exactly how I do...you need to setup an on_incoming_call handler like this: /** * Handler when there is incoming call. for ANI, DNIS and name. */ void on_incoming_call(pjsua_acc_id acc_id, pjsua_call_id call_id, pjsip_rx_data *rdata) { char str[1024]; int line=assign_line_to_new_call_id(call_id); // assign this call_id to a application line not in use pjsua_call_info call_info; char *ptr; char *sptr; char *dptr; int ANI; int DNIS; int ANI_name; char isdn_switch_type[76]; char ANI_str[76]; char ANI_Name_str[76]; char DNIS_str[76]; PACKET_HEADER *header; PACKET_INCOMING_CALL *incoming_call_packet; register_thread(); i_strcpy(isdn_switch_type, sip_data[line].isdn_switch_type); // a configuration string to tell me to look for a +1 or not. PJ_UNUSED_ARG(acc_id); PJ_UNUSED_ARG(rdata); pjsua_call_get_info(call_id, &call_info); if (app_config.auto_answer > 0) pjsua_call_answer(call_id, app_config.auto_answer, NULL, NULL); sprintf(str, "on_incoming_call(): Incoming call for account %d, call_id=%d, From: %s, To: %s", acc_id, call_id, call_info.remote_info.ptr, call_info.local_info.ptr); write_logfile(line, str); if ((sip_data[line].in_use==0) && (sip_data[line].installed==1)) { if (sip_data[line].in_use==0) { sip_data[line].in_use=1; // ok line in use now. sprintf(str, "line %d in_use=1", line); write_logfile(line, str); // call my logging function to log the string } } sip_data[line].line_thread_started=0; if (sip_data[line].installed) { sip_data[line].outbound_account=-1; // no outbound account for this line. i_strcpy(&sip_data[line].ANI, ""); i_strcpy(&sip_data[line].DNIS, ""); i_strcpy(&sip_data[line].ANI_Name, ""); ANI=0; DNIS=0; ANI_name=0; if (i_stricmp(isdn_switch_type, "bandwidth.com")==0) // DOES the SIP provider use +1 in front of ANI/DNIS { ptr=strstr(call_info.remote_info.ptr, "<sip:+1"); // find ANI if (ptr) { strncpy(ANI_str, ptr+strlen("<sip:+1"), 10); ANI_str[10]='\0'; i_strcpy(&sip_data[line].ANI, ANI_str); ANI=1; if (debug & 1) { sprintf(str, "GetANI(%d, %s)\n", line, ANI_str); logit(line, str); // log the string and display it. } } } else { ptr=strstr(call_info.remote_info.ptr, "<sip:"); // find ANI if (ptr) { strncpy(ANI_str, ptr+strlen("<sip:"), 10); ANI_str[10]='\0'; i_strcpy(&sip_data[line].ANI, ANI_str); ANI=1; if (debug & 1) { sprintf(str, "GetANI(%d, %s)\n", line, ANI_str); logit(line, str); } } } if (ANI==0) { sprintf(str, "on_incoming_call(%d): ANI not in Contact message\n", line); logit(line, str); } if (i_stricmp(isdn_switch_type, "bandwidth.com")==0) // only bandwidth.com delivers name { ptr=strstr(call_info.remote_info.ptr, "\""); // find caller name if (ptr) { sptr=ptr+strlen("\""); dptr=ANI_Name_str; while (*sptr!='\"') *dptr++=*sptr++; *dptr='\0'; ANI_name=1; i_strcpy(&sip_data[line].ANI_Name, ANI_Name_str); if (debug & 1) { sprintf(str, "get_CID(%d, %s)\n", line, ANI_Name_str); logit(line, str); } } } if (i_stricmp(isdn_switch_type, "bandwidth.com")==0) { if (ANI_name==0) { sprintf(str, "on_incoming_call(%d): ANI_name not in From message\n", line); logit(line, str); } } if (i_stricmp(isdn_switch_type, "bandwidth.com")==0) { ptr=strstr(call_info.local_info.ptr, "<sip:+1"); if (ptr) { strncpy(DNIS_str, ptr+strlen("<sip:+1"), 10); DNIS_str[10]='\0'; DNIS=1; i_strcpy(&sip_data[line].DNIS, DNIS_str); sprintf(str, "Get_DNIS(%d, %s)\n", line, DNIS_str); logit(line, str); } } else { ptr=strstr(call_info.local_info.ptr, "<sip:"); if (ptr) { strncpy(DNIS_str, ptr+strlen("<sip:"), 10); DNIS_str[10]='\0'; DNIS=1; i_strcpy(&sip_data[line].DNIS, DNIS_str); sprintf(str, "Get_DNIS(%d, %s)\n", line, DNIS_str); logit(line, str); } } if (DNIS==0) { sprintf(str, "on_incoming_call(%d): DNIS not in To message", line); write_logfile(line, str); } } // fire off inbound call thread here or otherwise notify the application of this. } At 02:34 PM 11/25/2008, Alexei Kuznetsov wrote: >Hi, > >I need to get the number of current calls in PJSIP_INV_STATE_INCOMING >state. Here is how I'm trying to achieve that: > >unsigned incoming_calls_count() >{ > pjsua_call_id call_ids[PJSUA_MAX_CALLS]; > > unsigned all_count; > pjsua_enum_calls(call_ids, &all_count); > > unsigned incoming_count = 0; > for (unsigned i = 0; i < all_count; ++i) { > pjsua_call_info call_info; > pjsua_call_get_info(call_ids[i], &call_info); > > if (call_info.state == PJSIP_INV_STATE_INCOMING) > ++incoming_count; > } > > return incoming_count; >} > >I call this function on the main thread when any call enters >disconnected state. But sometimes it doesn't return the actual number >of incoming calls. > >For example: >1. first incoiming call received (not answered) >2. second incoming call received (not answered) >3. the user hangs up the second call or the call is disconnected by >another party >4. incoming_calls_count() on the main thread sometimes returns 1 and >sometimes 0 >5. first call is disconnected, incoming_calls_count() always returns 0 > >But if inside incoming_calls_count() I add a function call to log >something to the console, incoming_calls_count() always returns >correct value! > >What am I missing? Any threading issues? Is there a better way to do >that? I'm using pjproject-1.0. > >Best regards, >Alexei Kuznetsov > >_______________________________________________ >Visit our blog: http://blog.pjsip.org > >pjsip mailing list >pjsip at lists.pjsip.org >http://lists.pjsip.org/mailman/listinfo/pjsip_lists.pjsip.org