summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2006-03-06 13:35:47 +0000
committerBenny Prijono <bennylp@teluu.com>2006-03-06 13:35:47 +0000
commit6f267e7ec63eb8bcec2fd978b5e4b94985969adc (patch)
treec9fbd2c4190b54f4fe215abe765cc5483b968e20
parentd3cc2c0befa4dee3a9b95314203b6c66497d83a0 (diff)
Added to pjsua: write new media settings, modify call stat output, fixed general bug
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@293 74dad513-b988-da41-8d7b-12977e46ad98
-rw-r--r--pjsip/include/pjsua-lib/pjsua.h1
-rw-r--r--pjsip/src/pjsua-lib/pjsua_call.c29
-rw-r--r--pjsip/src/pjsua-lib/pjsua_core.c3
-rw-r--r--pjsip/src/pjsua-lib/pjsua_settings.c72
4 files changed, 87 insertions, 18 deletions
diff --git a/pjsip/include/pjsua-lib/pjsua.h b/pjsip/include/pjsua-lib/pjsua.h
index 978af96f..c3fb92a7 100644
--- a/pjsip/include/pjsua-lib/pjsua.h
+++ b/pjsip/include/pjsua-lib/pjsua.h
@@ -198,6 +198,7 @@ struct pjsua
int auto_answer; /**< Automatically answer in calls. */
/* Account: */
+ pj_bool_t has_acc; /**< Any --id cmdline? */
int acc_cnt; /**< Number of client registrations */
pjsua_acc acc[PJSUA_MAX_ACC]; /** Client regs array. */
diff --git a/pjsip/src/pjsua-lib/pjsua_call.c b/pjsip/src/pjsua-lib/pjsua_call.c
index 1fc80604..b245a491 100644
--- a/pjsip/src/pjsua-lib/pjsua_call.c
+++ b/pjsip/src/pjsua-lib/pjsua_call.c
@@ -283,14 +283,27 @@ pj_bool_t pjsua_call_on_incoming(pjsip_rx_data *rdata)
*/
status = pjsip_inv_initial_answer(inv, rdata,
- (pjsua.auto_answer ? 200 : 100),
+ (pjsua.auto_answer ? pjsua.auto_answer
+ : 100),
NULL, NULL, &response);
if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Unable to create 100 response", status);
+ int st_code;
- pjsip_dlg_respond(dlg, rdata, 500, NULL, NULL, NULL);
- pjsip_inv_terminate(inv, 500, PJ_FALSE);
+ pjsua_perror(THIS_FILE, "Unable to send answer to incoming INVITE",
+ status);
+
+ /* If failed to send 2xx response, there's a good chance that it is
+ * because SDP negotiation has failed.
+ */
+ if (pjsua.auto_answer/100 == 2)
+ st_code = PJSIP_SC_UNSUPPORTED_MEDIA_TYPE;
+ else
+ st_code = 500;
+
+ pjsip_dlg_respond(dlg, rdata, st_code, NULL, NULL, NULL);
+ pjsip_inv_terminate(inv, st_code, PJ_FALSE);
+ return PJ_TRUE;
} else {
status = pjsip_inv_send_msg(inv, response, NULL);
@@ -762,8 +775,12 @@ static void pjsua_call_on_media_update(pjsip_inv_session *inv,
pjsua_perror(THIS_FILE, "SDP negotiation has failed", status);
- /* Disconnect call if this is not a re-INVITE */
- if (inv->state != PJSIP_INV_STATE_CONFIRMED) {
+ /* Disconnect call if we're not in the middle of initializing an
+ * UAS dialog and if this is not a re-INVITE
+ */
+ if (inv->state != PJSIP_INV_STATE_NULL &&
+ inv->state != PJSIP_INV_STATE_CONFIRMED)
+ {
call_disconnect(inv, PJSIP_SC_UNSUPPORTED_MEDIA_TYPE);
}
return;
diff --git a/pjsip/src/pjsua-lib/pjsua_core.c b/pjsip/src/pjsua-lib/pjsua_core.c
index 2744f4eb..aaf5601a 100644
--- a/pjsip/src/pjsua-lib/pjsua_core.c
+++ b/pjsip/src/pjsua-lib/pjsua_core.c
@@ -74,7 +74,7 @@ void pjsua_default(void)
/* Default for media: */
pjsua.clock_rate = 8000;
- pjsua.complexity = 4;
+ pjsua.complexity = -1;
pjsua.quality = 4;
@@ -84,6 +84,7 @@ void pjsua_default(void)
pjsua.acc[i].index = i;
pjsua.acc[i].local_uri = pj_str(PJSUA_LOCAL_URI);
pjsua.acc[i].reg_timeout = 55;
+ pjsua.acc[i].online_status = PJ_TRUE;
pj_list_init(&pjsua.acc[i].route_set);
pj_list_init(&pjsua.acc[i].pres_srv_list);
}
diff --git a/pjsip/src/pjsua-lib/pjsua_settings.c b/pjsip/src/pjsua-lib/pjsua_settings.c
index 18aec9af..4f02c23b 100644
--- a/pjsip/src/pjsua-lib/pjsua_settings.c
+++ b/pjsip/src/pjsua-lib/pjsua_settings.c
@@ -92,7 +92,7 @@ static void usage(void)
puts (" --auto-conf Automatically put incoming calls to conference");
puts (" --rtp-port=N Base port to try for RTP (default=4000)");
puts (" --add-codec=name Specify alternate codec order");
- puts (" --complexity=N Specify encoding complexity (0-10, default=4)");
+ puts (" --complexity=N Specify encoding complexity (0-10, default=none(-1))");
puts (" --quality=N Specify encoding quality (0-10, default=4)");
puts ("");
puts ("Buddy List (can be more than one):");
@@ -393,6 +393,7 @@ pj_status_t pjsua_parse_args(int argc, char *argv[])
return PJ_EINVAL;
}
cur_acc->local_uri = pj_str(optarg);
+ pjsua.has_acc = 1;
break;
case OPT_CONTACT: /* contact */
@@ -576,6 +577,23 @@ static void print_call(const char *title,
buf[len] = '\0';
}
+static const char *good_number(char *buf, pj_int32_t val)
+{
+ if (val < 1000) {
+ pj_ansi_sprintf(buf, "%d", val);
+ } else if (val < 1000000) {
+ pj_ansi_sprintf(buf, "%d.%dK",
+ val / 1000,
+ (val % 1000) / 100);
+ } else {
+ pj_ansi_sprintf(buf, "%d.%02dM",
+ val / 1000000,
+ (val % 1000000) / 10000);
+ }
+
+ return buf;
+}
+
static void dump_media_session(pjmedia_session *session)
{
unsigned i;
@@ -588,6 +606,7 @@ static void dump_media_session(pjmedia_session *session)
const char *rem_addr;
int rem_port;
const char *dir;
+ char stxpkt[10], stxoct[10], srxpkt[10], srxoct[10];
pjmedia_session_get_stream_stat(session, i, &strm_stat);
rem_addr = pj_inet_ntoa(info.stream_info[i].rem_addr.sin_addr);
@@ -604,18 +623,23 @@ static void dump_media_session(pjmedia_session *session)
PJ_LOG(3,(THIS_FILE,
- "%s[Media strm#%d] %.*s, %s, peer=%s:%d",
+ "%s#%d %.*s @%dKHz, %s, peer=%s:%d",
" ",
i,
info.stream_info[i].fmt.encoding_name.slen,
info.stream_info[i].fmt.encoding_name.ptr,
+ info.stream_info[i].fmt.sample_rate / 1000,
dir,
rem_addr, rem_port));
PJ_LOG(3,(THIS_FILE,
- "%s tx {pkt=%u, bytes=%u} rx {pkt=%u, bytes=%u}",
- " ",
- strm_stat.enc.pkt, strm_stat.enc.bytes,
- strm_stat.dec.pkt, strm_stat.dec.bytes));
+ "%s tx{pt=%d,pkt=%s,oct=%s} rx{pt=%d,pkt=%s,oct=%s}",
+ " ",
+ info.stream_info[i].tx_pt,
+ good_number(stxpkt, strm_stat.enc.pkt),
+ good_number(stxoct, strm_stat.enc.bytes),
+ info.stream_info[i].fmt.pt,
+ good_number(srxpkt, strm_stat.dec.pkt),
+ good_number(srxoct, strm_stat.dec.bytes)));
}
}
@@ -762,12 +786,14 @@ int pjsua_dump_settings(char *buf, pj_size_t max)
/* Save account settings. */
- for (acc_index=0; acc_index < pjsua.acc_cnt; ++acc_index) {
-
- save_account_settings(acc_index, &cfg);
+ if (pjsua.has_acc) {
+ for (acc_index=0; acc_index < pjsua.acc_cnt; ++acc_index) {
+
+ save_account_settings(acc_index, &cfg);
- if (acc_index < pjsua.acc_cnt-1)
- pj_strcat2(&cfg, "--next-account\n");
+ if (acc_index < pjsua.acc_cnt-1)
+ pj_strcat2(&cfg, "--next-account\n");
+ }
}
/* Credentials. */
@@ -849,7 +875,31 @@ int pjsua_dump_settings(char *buf, pj_size_t max)
pjsua.wav_file);
pj_strcat2(&cfg, line);
}
+ /* Media clock rate. */
+ if (pjsua.clock_rate >= 32000)
+ pj_strcat2(&cfg, "--uwb\n");
+ else if (pjsua.clock_rate >= 16000)
+ pj_strcat2(&cfg, "--wb\n");
+
+ /* Encoding quality and complexity */
+ pj_ansi_sprintf(line, "--quality %d\n",
+ pjsua.quality);
+ pj_strcat2(&cfg, line);
+ pj_ansi_sprintf(line, "--complexity %d\n",
+ pjsua.complexity);
+ pj_strcat2(&cfg, line);
+ /* Start RTP port. */
+ pj_ansi_sprintf(line, "--rtp-port %d\n",
+ pjsua.start_rtp_port);
+ pj_strcat2(&cfg, line);
+
+ /* Add codec. */
+ for (i=0; i<pjsua.codec_cnt; ++i) {
+ pj_ansi_sprintf(line, "--add-codec %s\n",
+ pjsua.codec_arg[i].ptr);
+ pj_strcat2(&cfg, line);
+ }
pj_strcat2(&cfg, "#\n# User agent:\n#\n");