Skip to content

Commit

Permalink
Ticket #389: Added new commands in pjsua to change codec priorities a…
Browse files Browse the repository at this point in the history
…nd send UPDATE

git-svn-id: https://svn.pjsip.org/repos/pjproject/trunk@1471 74dad513-b988-da41-8d7b-12977e46ad98
  • Loading branch information
bennylp committed Oct 4, 2007
1 parent 7a686d0 commit c08682e
Show file tree
Hide file tree
Showing 3 changed files with 155 additions and 6 deletions.
84 changes: 78 additions & 6 deletions pjsip-apps/src/pjsua/pjsua_app.c
Original file line number Diff line number Diff line change
Expand Up @@ -1909,14 +1909,15 @@ static void keystroke_help(void)
puts("| h Hangup call (ha=all) | s Subscribe presence | rr (Re-)register |");
puts("| H Hold call | u Unsubscribe presence | ru Unregister |");
puts("| v re-inVite (release hold) | t ToGgle Online status | > Cycle next ac.|");
puts("| ] Select next dialog | T Set online status | < Cycle prev ac.|");
puts("| [ Select previous dialog +--------------------------+-------------------+");
puts("| U send UPDATE | T Set online status | < Cycle prev ac.|");
puts("| ],[ Select next/prev call +--------------------------+-------------------+");
puts("| x Xfer call | Media Commands: | Status & Config: |");
puts("| X Xfer with Replaces | | |");
puts("| # Send DTMF string | cl List ports | d Dump status |");
puts("| dq Dump curr. call quality | cc Connect port | dd Dump detailed |");
puts("| | cd Disconnect port | dc Dump config |");
puts("| S Send arbitrary REQUEST | V Adjust audio Volume | f Save config |");
puts("| # Send RFC 2833 DTMF | cl List ports | d Dump status |");
puts("| * Send DTMF with INFO | cc Connect port | dd Dump detailed |");
puts("| dq Dump curr. call quality | cd Disconnect port | dc Dump config |");
puts("| | V Adjust audio Volume | f Save config |");
puts("| S Send arbitrary REQUEST | Cp Codec priorities | f Save config |");
puts("+------------------------------+--------------------------+-------------------+");
puts("| q QUIT sleep N: console sleep for N ms |");
puts("+=============================================================================+");
Expand Down Expand Up @@ -2188,6 +2189,58 @@ static void change_online_status(void)
}


/*
* Change codec priorities.
*/
static void manage_codec_prio(void)
{
pjsua_codec_info c[32];
unsigned i, count = PJ_ARRAY_SIZE(c);
char input[32];
char *codec, *prio;
pj_str_t id;
int new_prio;
pj_status_t status;

printf("List of codecs:\n");

pjsua_enum_codecs(c, &count);
for (i=0; i<count; ++i) {
printf(" %d\t%.*s\n", c[i].priority, (int)c[i].codec_id.slen,
c[i].codec_id.ptr);
}

puts("");
puts("Enter codec name and its new priority (e.g. \"speex/16000 200\"), empty to cancel:");

printf("Codec name and priority: ");
fgets(input, sizeof(input), stdin);
if (input[0]=='\r' || input[0]=='\n') {
puts("Done");
return;
}

codec = strtok(input, " \t\r\n");
prio = strtok(NULL, " \r\n");

if (!codec || !prio) {
puts("Invalid input");
return;
}

new_prio = atoi(prio);
if (new_prio < 0)
new_prio = 0;
else if (new_prio > PJMEDIA_CODEC_PRIO_HIGHEST)
new_prio = PJMEDIA_CODEC_PRIO_HIGHEST;

status = pjsua_codec_set_priority(pj_cstr(&id, codec),
(pj_uint8_t)new_prio);
if (status != PJ_SUCCESS)
pjsua_perror(THIS_FILE, "Error setting codec priority", status);
}


/*
* Main "user interface" loop.
*/
Expand Down Expand Up @@ -2611,6 +2664,25 @@ void console_app_main(const pj_str_t *uri_to_call)
}
break;

case 'U':
/*
* Send UPDATE
*/
if (current_call != -1) {

pjsua_call_update(current_call, 0, NULL);

} else {
PJ_LOG(3,(THIS_FILE, "No current call"));
}
break;

case 'C':
if (menuin[1] == 'p') {
manage_codec_prio();
}
break;

case 'x':
/*
* Transfer call.
Expand Down
13 changes: 13 additions & 0 deletions pjsip/include/pjsua-lib/pjsua.h
Original file line number Diff line number Diff line change
Expand Up @@ -2765,6 +2765,19 @@ PJ_DECL(pj_status_t) pjsua_call_reinvite(pjsua_call_id call_id,
pj_bool_t unhold,
const pjsua_msg_data *msg_data);

/**
* Send UPDATE request.
*
* @param call_id Call identification.
* @param options Must be zero for now.
* @param msg_data Optional message components to be sent with
* the request.
*
* @return PJ_SUCCESS on success, or the appropriate error code.
*/
PJ_DECL(pj_status_t) pjsua_call_update(pjsua_call_id call_id,
unsigned options,
const pjsua_msg_data *msg_data);

/**
* Initiate call transfer to the specified address. This function will send
Expand Down
64 changes: 64 additions & 0 deletions pjsip/src/pjsua-lib/pjsua_call.c
Original file line number Diff line number Diff line change
Expand Up @@ -1281,6 +1281,70 @@ PJ_DEF(pj_status_t) pjsua_call_reinvite( pjsua_call_id call_id,
}


/*
* Send UPDATE request.
*/
PJ_DEF(pj_status_t) pjsua_call_update( pjsua_call_id call_id,
unsigned options,
const pjsua_msg_data *msg_data)
{
pjmedia_sdp_session *sdp;
pjsip_tx_data *tdata;
pjsua_call *call;
pjsip_dialog *dlg;
pj_status_t status;

PJ_UNUSED_ARG(options);

PJ_ASSERT_RETURN(call_id>=0 && call_id<(int)pjsua_var.ua_cfg.max_calls,
PJ_EINVAL);

status = acquire_call("pjsua_call_update()", call_id, &call, &dlg);
if (status != PJ_SUCCESS)
return status;

/* Init media channel */
status = pjsua_media_channel_init(call->index, PJSIP_ROLE_UAC);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "Error initializing media channel", status);
pjsip_dlg_dec_lock(dlg);
return PJSIP_ESESSIONSTATE;
}

/* Create SDP */
status = pjsua_media_channel_create_sdp(call->index, call->inv->pool, &sdp);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "Unable to get SDP from media endpoint",
status);
pjsip_dlg_dec_lock(dlg);
return status;
}

/* Create re-INVITE with new offer */
status = pjsip_inv_update(call->inv, NULL, sdp, &tdata);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "Unable to create UPDATE request", status);
pjsip_dlg_dec_lock(dlg);
return status;
}

/* Add additional headers etc */
pjsua_process_msg_data( tdata, msg_data);

/* Send the request */
status = pjsip_inv_send_msg( call->inv, tdata);
if (status != PJ_SUCCESS) {
pjsua_perror(THIS_FILE, "Unable to send UPDAT Erequest", status);
pjsip_dlg_dec_lock(dlg);
return status;
}

pjsip_dlg_dec_lock(dlg);

return PJ_SUCCESS;
}


/*
* Initiate call transfer to the specified address.
*/
Expand Down

0 comments on commit c08682e

Please sign in to comment.