1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131 |
- /*
- * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
- * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- */
- #include <pjsua-lib/pjsua.h>
- #include "pjsua_app_common.h"
- #define THIS_FILE "pjsua_app_legacy.c"
- /* An attempt to avoid stdout buffering for python tests:
- * - call 'fflush(stdout)' after each call to 'printf()/puts()'
- * - apply 'setbuf(stdout, 0)', but it is not guaranteed by the standard:
- * http://stackoverflow.com/questions/1716296
- */
- #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \
- (defined (_MSC_VER) && _MSC_VER >= 1400)
- /* Variadic macro is introduced in C99; MSVC supports it in since 2005. */
- # define printf(...) {printf(__VA_ARGS__);fflush(stdout);}
- # define puts(s) {puts(s);fflush(stdout);}
- #endif
- static pj_bool_t cmd_echo;
- /*
- * Print buddy list.
- */
- static void print_buddy_list()
- {
- pjsua_buddy_id ids[64];
- int i;
- unsigned count = PJ_ARRAY_SIZE(ids);
- puts("Buddy list:");
- pjsua_enum_buddies(ids, &count);
- if (count == 0) {
- puts(" -none-");
- } else {
- for (i=0; i<(int)count; ++i) {
- pjsua_buddy_info info;
- if (pjsua_buddy_get_info(ids[i], &info) != PJ_SUCCESS)
- continue;
- printf(" [%2d] <%.*s> %.*s\n",
- ids[i]+1,
- (int)info.status_text.slen,
- info.status_text.ptr,
- (int)info.uri.slen,
- info.uri.ptr);
- }
- }
- puts("");
- }
- /*
- * Input URL.
- */
- static void ui_input_url(const char *title, char *buf, pj_size_t len,
- input_result *result, pj_bool_t allow_all)
- {
- result->nb_result = PJSUA_APP_NO_NB;
- result->uri_result = NULL;
- print_buddy_list();
- printf("Choices:\n"
- " 0 For current dialog.\n");
- if (pjsua_get_buddy_count() > 0) {
- if (allow_all) {
- printf(" -1 All %d buddies in buddy list\n",
- pjsua_get_buddy_count());
- }
- printf(" [1 -%2d] Select from buddy list\n",
- pjsua_get_buddy_count());
- }
- printf(" URL An URL\n"
- " <Enter> Empty input (or 'q') to cancel\n");
- printf("%s: ", title);
- fflush(stdout);
- if (fgets(buf, (int)len, stdin) == NULL)
- return;
- len = strlen(buf);
- /* Left trim */
- while (pj_isspace(*buf)) {
- ++buf;
- --len;
- }
- /* Remove trailing newlines */
- while (len && (buf[len-1] == '\r' || buf[len-1] == '\n'))
- buf[--len] = '\0';
- if (len == 0 || buf[0]=='q')
- return;
- if (pj_isdigit(*buf) || *buf=='-') {
- unsigned i;
- if (*buf=='-')
- i = 1;
- else
- i = 0;
- for (; i<len; ++i) {
- if (!pj_isdigit(buf[i])) {
- puts("Invalid input");
- return;
- }
- }
- result->nb_result = my_atoi(buf);
- if (result->nb_result >= 0 &&
- result->nb_result <= (int)pjsua_get_buddy_count())
- {
- return;
- }
- if (result->nb_result == -1)
- return;
- puts("Invalid input");
- result->nb_result = PJSUA_APP_NO_NB;
- return;
- } else {
- pj_status_t status;
- if ((status=pjsua_verify_url(buf)) != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Invalid URL", status);
- return;
- }
- result->uri_result = buf;
- }
- }
- static pj_bool_t simple_input(const char *title, char *buf, pj_size_t len)
- {
- char *p;
- printf("%s (empty to cancel): ", title); fflush(stdout);
- if (fgets(buf, (int)len, stdin) == NULL)
- return PJ_FALSE;
- /* Remove trailing newlines. */
- for (p=buf; ; ++p) {
- if (*p=='\r' || *p=='\n') *p='\0';
- else if (!*p) break;
- }
- if (!*buf)
- return PJ_FALSE;
- return PJ_TRUE;
- }
- /*
- * Print account status.
- */
- static void print_acc_status(int acc_id)
- {
- char buf[80];
- pjsua_acc_info info;
- pjsua_acc_get_info(acc_id, &info);
- if (!info.has_registration) {
- pj_ansi_snprintf(buf, sizeof(buf), "%.*s",
- (int)info.status_text.slen,
- info.status_text.ptr);
- } else {
- pj_ansi_snprintf(buf, sizeof(buf),
- "%d/%.*s (expires=%d)",
- info.status,
- (int)info.status_text.slen,
- info.status_text.ptr,
- info.expires);
- }
- printf(" %c[%2d] %.*s: %s\n", (acc_id==current_acc?'*':' '),
- acc_id, (int)info.acc_uri.slen, info.acc_uri.ptr, buf);
- printf(" Online status: %.*s\n",
- (int)info.online_status_text.slen,
- info.online_status_text.ptr);
- }
- /*
- * Show a bit of help.
- */
- static void keystroke_help()
- {
- pjsua_acc_id acc_ids[16];
- unsigned count = PJ_ARRAY_SIZE(acc_ids);
- int i;
- printf(">>>>\n");
- pjsua_enum_accs(acc_ids, &count);
- printf("Account list:\n");
- for (i=0; i<(int)count; ++i)
- print_acc_status(acc_ids[i]);
- print_buddy_list();
- //puts("Commands:");
- puts("+=============================================================================+");
- puts("| Call Commands: | Buddy, IM & Presence: | Account: |");
- puts("| | | |");
- puts("| m Make new call | +b Add new buddy | +a Add new accnt.|");
- puts("| M Make multiple calls | -b Delete buddy | -a Delete accnt. |");
- puts("| a Answer call | i Send IM | !a Modify accnt. |");
- puts("| h Hangup call (ha=all) | s Subscribe presence | rr (Re-)register |");
- puts("| H Hold call | u Unsubscribe presence | ru Unregister |");
- puts("| o Toggle call SDP offer | D Subscribe dlg event | |");
- puts("| | Du Unsub dlg event | |");
- puts("| v re-inVite (release hold) | t Toggle online status | > Cycle next ac.|");
- 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 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 | |");
- puts("+-----------------------------------------------------------------------------+");
- #if PJSUA_HAS_VIDEO
- puts("| Video: \"vid help\" for more info |");
- puts("+-----------------------------------------------------------------------------+");
- #endif
- puts("| q QUIT L ReLoad I IP change n detect NAT type |");
- puts("| sleep MS echo [0|1|txt] |");
- puts("+=============================================================================+");
- i = pjsua_call_get_count();
- printf("You have %d active call%s\n", i, (i>1?"s":""));
- if (current_call != PJSUA_INVALID_ID) {
- pjsua_call_info ci;
- if (pjsua_call_get_info(current_call, &ci)==PJ_SUCCESS)
- printf("Current call id=%d to %.*s [%.*s]\n", current_call,
- (int)ci.remote_info.slen, ci.remote_info.ptr,
- (int)ci.state_text.slen, ci.state_text.ptr);
- }
- }
- /* Help screen for video */
- #if PJSUA_HAS_VIDEO
- static void vid_show_help()
- {
- pj_bool_t vid_enabled = (app_config.vid.vid_cnt > 0);
- puts("+=============================================================================+");
- puts("| Video commands: |");
- puts("| |");
- puts("| vid help Show this help screen |");
- puts("| vid enable|disable Enable or disable video in next offer/answer |");
- puts("| vid acc show Show current account video settings |");
- puts("| vid acc autorx on|off Automatically show incoming video on/off |");
- puts("| vid acc autotx on|off Automatically offer video on/off |");
- puts("| vid acc cap ID Set default capture device for current acc |");
- puts("| vid acc rend ID Set default renderer device for current acc |");
- puts("| vid call rx on|off N Enable/disable video RX for stream N in curr call |");
- puts("| vid call tx on|off N Enable/disable video TX for stream N in curr call |");
- puts("| vid call add Add video stream for current call |");
- puts("| vid call enable|disable N Enable/disable stream #N in current call |");
- puts("| vid call cap N ID Set capture dev ID for stream #N in current call |");
- puts("| vid dev list List all video devices |");
- puts("| vid dev refresh Refresh video device list |");
- puts("| vid dev prev on|off ID Enable/disable preview for specified device ID |");
- puts("| vid codec list List video codecs |");
- puts("| vid codec prio ID PRIO Set codec ID priority to PRIO |");
- puts("| vid codec fps ID NUM DEN Set codec ID framerate to (NUM/DEN) fps |");
- puts("| vid codec bw ID AVG MAX Set codec ID bitrate to AVG & MAX kbps |");
- puts("| vid codec size ID W H Set codec ID size/resolution to W x H |");
- puts("| vid win list List all active video windows |");
- puts("| vid win arrange Auto arrange windows |");
- puts("| vid win show|hide ID Show/hide the specified video window ID |");
- puts("| vid win move ID X Y Move window ID to position X,Y |");
- puts("| vid win resize ID w h Resize window ID to the specified width, height |");
- puts("| vid win full off|on|dt ID Set fullscreen off/on/desktop for window ID |");
- puts("| vid conf list List all video ports in video conference bridge |");
- puts("| vid conf cc P Q Connect port P to Q in the video conf bridge |");
- puts("| vid conf cd P Q Disconnect port P to Q in the video conf bridge |");
- puts("+=============================================================================+");
- printf("| Video will be %s in the next offer/answer %s |\n",
- (vid_enabled? "enabled" : "disabled"), (vid_enabled? " " : ""));
- puts("+=============================================================================+");
- }
- static void vid_handle_menu(char *menuin)
- {
- char *argv[8] = {NULL};
- int argc = 0;
- /* Tokenize */
- argv[argc] = strtok(menuin, " \t\r\n");
- while (argv[argc] && *argv[argc]) {
- argc++;
- argv[argc] = strtok(NULL, " \t\r\n");
- }
- if (argc == 1 || strcmp(argv[1], "help")==0) {
- vid_show_help();
- } else if (argc == 2 && (strcmp(argv[1], "enable")==0 ||
- strcmp(argv[1], "disable")==0))
- {
- pj_bool_t enabled = (strcmp(argv[1], "enable")==0);
- app_config.vid.vid_cnt = (enabled ? 1 : 0);
- PJ_LOG(3,(THIS_FILE, "Video will be %s in next offer/answer",
- (enabled?"enabled":"disabled")));
- } else if (strcmp(argv[1], "acc")==0) {
- pjsua_acc_config acc_cfg;
- pj_bool_t changed = PJ_FALSE;
- pj_pool_t *tmp_pool = pjsua_pool_create("tmp-pjsua", 1000, 1000);
- pjsua_acc_get_config(current_acc, tmp_pool, &acc_cfg);
- if (argc == 3 && strcmp(argv[2], "show")==0) {
- app_config_show_video(current_acc, &acc_cfg);
- } else if (argc == 4 && strcmp(argv[2], "autorx")==0) {
- int on = (strcmp(argv[3], "on")==0);
- acc_cfg.vid_in_auto_show = on;
- changed = PJ_TRUE;
- } else if (argc == 4 && strcmp(argv[2], "autotx")==0) {
- int on = (strcmp(argv[3], "on")==0);
- acc_cfg.vid_out_auto_transmit = on;
- changed = PJ_TRUE;
- } else if (argc == 4 && strcmp(argv[2], "cap")==0) {
- int dev = atoi(argv[3]);
- acc_cfg.vid_cap_dev = dev;
- changed = PJ_TRUE;
- } else if (argc == 4 && strcmp(argv[2], "rend")==0) {
- int dev = atoi(argv[3]);
- acc_cfg.vid_rend_dev = dev;
- changed = PJ_TRUE;
- } else {
- pj_pool_release(tmp_pool);
- goto on_error;
- }
- if (changed) {
- pj_status_t status = pjsua_acc_modify(current_acc, &acc_cfg);
- if (status != PJ_SUCCESS)
- PJ_PERROR(1,(THIS_FILE, status, "Error modifying account %d",
- current_acc));
- }
- pj_pool_release(tmp_pool);
- } else if (strcmp(argv[1], "call")==0) {
- pjsua_call_vid_strm_op_param param;
- pj_status_t status = PJ_SUCCESS;
- pjsua_call_vid_strm_op_param_default(¶m);
- if (argc == 5 && strcmp(argv[2], "rx")==0) {
- pjsua_stream_info si;
- pj_bool_t on = (strcmp(argv[3], "on") == 0);
- param.med_idx = atoi(argv[4]);
- if (pjsua_call_get_stream_info(current_call, param.med_idx, &si) ||
- si.type != PJMEDIA_TYPE_VIDEO)
- {
- PJ_PERROR(1,(THIS_FILE, PJ_EINVAL, "Invalid stream"));
- return;
- }
- if (on) param.dir = (si.info.vid.dir | PJMEDIA_DIR_DECODING);
- else param.dir = (si.info.vid.dir & PJMEDIA_DIR_ENCODING);
- status = pjsua_call_set_vid_strm(current_call,
- PJSUA_CALL_VID_STRM_CHANGE_DIR,
- ¶m);
- }
- else if (argc == 5 && strcmp(argv[2], "tx")==0) {
- pj_bool_t on = (strcmp(argv[3], "on") == 0);
- pjsua_call_vid_strm_op op = on? PJSUA_CALL_VID_STRM_START_TRANSMIT :
- PJSUA_CALL_VID_STRM_STOP_TRANSMIT;
- param.med_idx = atoi(argv[4]);
- status = pjsua_call_set_vid_strm(current_call, op, ¶m);
- }
- else if (argc == 3 && strcmp(argv[2], "add")==0) {
- status = pjsua_call_set_vid_strm(current_call,
- PJSUA_CALL_VID_STRM_ADD, NULL);
- }
- else if (argc >= 3 &&
- (strcmp(argv[2], "disable")==0 || strcmp(argv[2], "enable")==0))
- {
- pj_bool_t enable = (strcmp(argv[2], "enable") == 0);
- pjsua_call_vid_strm_op op = enable? PJSUA_CALL_VID_STRM_CHANGE_DIR :
- PJSUA_CALL_VID_STRM_REMOVE;
- param.med_idx = argc >= 4? atoi(argv[3]) : -1;
- param.dir = PJMEDIA_DIR_ENCODING_DECODING;
- status = pjsua_call_set_vid_strm(current_call, op, ¶m);
- }
- else if (argc >= 3 && strcmp(argv[2], "cap")==0) {
- param.med_idx = argc >= 4? atoi(argv[3]) : -1;
- param.cap_dev = argc >= 5? atoi(argv[4]) : PJMEDIA_VID_DEFAULT_CAPTURE_DEV;
- status = pjsua_call_set_vid_strm(current_call,
- PJSUA_CALL_VID_STRM_CHANGE_CAP_DEV,
- ¶m);
- } else
- goto on_error;
- if (status != PJ_SUCCESS) {
- PJ_PERROR(1,(THIS_FILE, status, "Error modifying video stream"));
- }
- } else if (argc >= 3 && strcmp(argv[1], "dev")==0) {
- if (strcmp(argv[2], "list")==0) {
- vid_list_devs();
- } else if (strcmp(argv[2], "refresh")==0) {
- pjmedia_vid_dev_refresh();
- } else if (strcmp(argv[2], "prev")==0) {
- if (argc != 5) {
- goto on_error;
- } else {
- pj_bool_t on = (strcmp(argv[3], "on") == 0);
- int dev_id = atoi(argv[4]);
- if (on) {
- pjsua_vid_preview_param param;
- pjsua_vid_preview_param_default(¶m);
- param.wnd_flags = PJMEDIA_VID_DEV_WND_BORDER |
- PJMEDIA_VID_DEV_WND_RESIZABLE;
- pjsua_vid_preview_start(dev_id, ¶m);
- arrange_window(pjsua_vid_preview_get_win(dev_id));
- } else {
- pjsua_vid_win_id wid;
- wid = pjsua_vid_preview_get_win(dev_id);
- if (wid != PJSUA_INVALID_ID) {
- /* Preview window hiding once it is stopped is
- * responsibility of app */
- pjsua_vid_win_set_show(wid, PJ_FALSE);
- pjsua_vid_preview_stop(dev_id);
- }
- }
- }
- } else
- goto on_error;
- } else if (strcmp(argv[1], "win")==0) {
- pj_status_t status = PJ_SUCCESS;
- if (argc==3 && strcmp(argv[2], "list")==0) {
- pjsua_vid_win_id wids[PJSUA_MAX_VID_WINS];
- unsigned i, cnt = PJ_ARRAY_SIZE(wids);
- pjsua_vid_enum_wins(wids, &cnt);
- PJ_LOG(3,(THIS_FILE, "Found %d video windows:", cnt));
- PJ_LOG(3,(THIS_FILE, "WID show pos size"));
- PJ_LOG(3,(THIS_FILE, "------------------------------"));
- for (i = 0; i < cnt; ++i) {
- pjsua_vid_win_info wi;
- pjsua_vid_win_get_info(wids[i], &wi);
- PJ_LOG(3,(THIS_FILE, "%3d %c (%d,%d) %dx%d",
- wids[i], (wi.show?'Y':'N'), wi.pos.x, wi.pos.y,
- wi.size.w, wi.size.h));
- }
- } else if (argc==4 && (strcmp(argv[2], "show")==0 ||
- strcmp(argv[2], "hide")==0))
- {
- pj_bool_t show = (strcmp(argv[2], "show")==0);
- pjsua_vid_win_id wid = atoi(argv[3]);
- status = pjsua_vid_win_set_show(wid, show);
- } else if (argc==6 && strcmp(argv[2], "move")==0) {
- pjsua_vid_win_id wid = atoi(argv[3]);
- pjmedia_coord pos;
- pos.x = atoi(argv[4]);
- pos.y = atoi(argv[5]);
- status = pjsua_vid_win_set_pos(wid, &pos);
- } else if (argc==6 && strcmp(argv[2], "resize")==0) {
- pjsua_vid_win_id wid = atoi(argv[3]);
- pjmedia_rect_size size;
- size.w = atoi(argv[4]);
- size.h = atoi(argv[5]);
- status = pjsua_vid_win_set_size(wid, &size);
- } else if (argc==3 && strcmp(argv[2], "arrange")==0) {
- arrange_window(PJSUA_INVALID_ID);
- } else if (argc==5 && (strcmp(argv[2], "full")==0))
- {
- pjsua_vid_win_id wid = atoi(argv[4]);
- pjmedia_vid_dev_fullscreen_flag mode = PJMEDIA_VID_DEV_WINDOWED;
- if (strcmp(argv[3], "on")==0)
- mode = PJMEDIA_VID_DEV_FULLSCREEN;
- else if (strcmp(argv[3], "dt")==0)
- mode = PJMEDIA_VID_DEV_FULLSCREEN_DESKTOP;
- status = pjsua_vid_win_set_fullscreen(wid, mode);
- } else
- goto on_error;
- if (status != PJ_SUCCESS) {
- PJ_PERROR(1,(THIS_FILE, status, "Window operation error"));
- }
- } else if (strcmp(argv[1], "codec")==0) {
- pjsua_codec_info ci[PJMEDIA_CODEC_MGR_MAX_CODECS];
- unsigned count = PJ_ARRAY_SIZE(ci);
- pj_status_t status;
- if (argc==3 && strcmp(argv[2], "list")==0) {
- status = pjsua_vid_enum_codecs(ci, &count);
- if (status != PJ_SUCCESS) {
- PJ_PERROR(1,(THIS_FILE, status, "Error enumerating codecs"));
- } else {
- unsigned i;
- PJ_LOG(3,(THIS_FILE, "Found %d video codecs:", count));
- PJ_LOG(3,(THIS_FILE, "codec id prio fps bw(kbps) size"));
- PJ_LOG(3,(THIS_FILE, "------------------------------------------"));
- for (i=0; i<count; ++i) {
- pjmedia_vid_codec_param cp;
- pjmedia_video_format_detail *vfd;
- status = pjsua_vid_codec_get_param(&ci[i].codec_id, &cp);
- if (status != PJ_SUCCESS)
- continue;
- vfd = pjmedia_format_get_video_format_detail(&cp.enc_fmt,
- PJ_TRUE);
- PJ_LOG(3,(THIS_FILE, "%.*s%.*s %3d %7.2f %4d/%4d %dx%d",
- (int)ci[i].codec_id.slen, ci[i].codec_id.ptr,
- 13-(int)ci[i].codec_id.slen, " ",
- ci[i].priority,
- (vfd->fps.num*1.0/vfd->fps.denum),
- vfd->avg_bps/1000, vfd->max_bps/1000,
- vfd->size.w, vfd->size.h));
- }
- }
- } else if (argc==5 && strcmp(argv[2], "prio")==0) {
- pj_str_t cid;
- int prio;
- cid = pj_str(argv[3]);
- prio = atoi(argv[4]);
- status = pjsua_vid_codec_set_priority(&cid, (pj_uint8_t)prio);
- if (status != PJ_SUCCESS)
- PJ_PERROR(1,(THIS_FILE, status, "Set codec priority error"));
- } else if (argc==6 && strcmp(argv[2], "fps")==0) {
- pjmedia_vid_codec_param cp;
- pj_str_t cid;
- int M, N;
- cid = pj_str(argv[3]);
- M = atoi(argv[4]);
- N = atoi(argv[5]);
- status = pjsua_vid_codec_get_param(&cid, &cp);
- if (status == PJ_SUCCESS) {
- cp.enc_fmt.det.vid.fps.num = M;
- cp.enc_fmt.det.vid.fps.denum = N;
- status = pjsua_vid_codec_set_param(&cid, &cp);
- }
- if (status != PJ_SUCCESS)
- PJ_PERROR(1,(THIS_FILE, status, "Set codec framerate error"));
- } else if (argc==6 && strcmp(argv[2], "bw")==0) {
- pjmedia_vid_codec_param cp;
- pj_str_t cid;
- int M, N;
- cid = pj_str(argv[3]);
- M = atoi(argv[4]);
- N = atoi(argv[5]);
- status = pjsua_vid_codec_get_param(&cid, &cp);
- if (status == PJ_SUCCESS) {
- cp.enc_fmt.det.vid.avg_bps = M * 1000;
- cp.enc_fmt.det.vid.max_bps = N * 1000;
- status = pjsua_vid_codec_set_param(&cid, &cp);
- }
- if (status != PJ_SUCCESS)
- PJ_PERROR(1,(THIS_FILE, status, "Set codec bitrate error"));
- } else if (argc==6 && strcmp(argv[2], "size")==0) {
- pjmedia_vid_codec_param cp;
- pj_str_t cid;
- int M, N;
- cid = pj_str(argv[3]);
- M = atoi(argv[4]);
- N = atoi(argv[5]);
- status = pjsua_vid_codec_get_param(&cid, &cp);
- if (status == PJ_SUCCESS) {
- cp.enc_fmt.det.vid.size.w = M;
- cp.enc_fmt.det.vid.size.h = N;
- status = pjsua_vid_codec_set_param(&cid, &cp);
- }
- if (status != PJ_SUCCESS)
- PJ_PERROR(1,(THIS_FILE, status, "Set codec size error"));
- } else
- goto on_error;
- } else if (strcmp(argv[1], "conf")==0) {
- pj_status_t status;
- if (argc==3 && strcmp(argv[2], "list")==0) {
- pjsua_conf_port_id id[100];
- unsigned count = PJ_ARRAY_SIZE(id);
- status = pjsua_vid_conf_enum_ports(id, &count);
- if (status != PJ_SUCCESS) {
- PJ_PERROR(1,(THIS_FILE, status,
- "Failed enumerating video conf bridge ports"));
- } else {
- unsigned i;
- printf(" Video conference has %d ports:\n", count);
- printf(" id name format rx-from tx-to \n");
- printf(" ------------------------------------------------------------------\n");
- for (i=0; i<count; ++i) {
- char li_list[PJSUA_MAX_CALLS*4];
- char tr_list[PJSUA_MAX_CALLS*4];
- char s[32];
- unsigned j;
- pjsua_vid_conf_port_info info;
- pjmedia_rect_size *size;
- pjmedia_ratio *fps;
- pjsua_vid_conf_get_port_info(id[i], &info);
- size = &info.format.det.vid.size;
- fps = &info.format.det.vid.fps;
- li_list[0] = '\0';
- for (j=0; j<info.listener_cnt; ++j) {
- char str_info[10];
- pj_ansi_snprintf(str_info, sizeof(str_info), "%d%s",
- info.listeners[j],
- (j==info.listener_cnt-1)?"":",");
- pj_ansi_strxcat(li_list, str_info, sizeof(li_list));
- }
- tr_list[0] = '\0';
- for (j=0; j<info.transmitter_cnt; ++j) {
- char str_info[10];
- pj_ansi_snprintf(str_info, sizeof(str_info), "%d%s",
- info.transmitters[j],
- (j==info.transmitter_cnt-1)?"":",");
- pj_ansi_strxcat(tr_list, str_info, sizeof(tr_list));
- }
- pjmedia_fourcc_name(info.format.id, s);
- s[4] = ' ';
- pj_ansi_snprintf(s+5, sizeof(s)-5, "%dx%d@%.1f",
- size->w, size->h,
- (float)(fps->num*1.0/fps->denum));
- printf("%3d %.*s%.*s %s%.*s %s%.*s %s\n",
- id[i],
- (int)info.name.slen, info.name.ptr,
- 22-(int)info.name.slen, " ",
- s,
- 20-(int)pj_ansi_strlen(s), " ",
- tr_list,
- 12-(int)pj_ansi_strlen(tr_list), " ",
- li_list);
- }
- }
- } else if (argc==5 && strcmp(argv[2], "cc")==0) {
- int P, Q;
- P = atoi(argv[3]);
- Q = atoi(argv[4]);
- pjsua_vid_conf_connect(P, Q, NULL);
- } else if (argc==5 && strcmp(argv[2], "cd")==0) {
- int P, Q;
- P = atoi(argv[3]);
- Q = atoi(argv[4]);
- pjsua_vid_conf_disconnect(P, Q);
- } else {
- goto on_error;
- }
- } else
- goto on_error;
- return;
- on_error:
- PJ_LOG(1,(THIS_FILE, "Invalid command, use 'vid help'"));
- }
- #endif /* PJSUA_HAS_VIDEO */
- /** UI Command **/
- static void ui_make_new_call()
- {
- char buf[128];
- pjsua_msg_data msg_data_;
- input_result result;
- pj_str_t tmp;
- pj_bool_t loop = PJ_FALSE;
- printf("(You currently have %d calls)\n", pjsua_call_get_count());
- ui_input_url("Make call", buf, sizeof(buf), &result, PJ_TRUE);
- do {
- if (result.nb_result != PJSUA_APP_NO_NB) {
- if (result.nb_result == -1) {
- loop = PJ_TRUE;
- result.nb_result = 1;
- }
- if (result.nb_result > (int)pjsua_get_buddy_count()) break;
- if (result.nb_result == 0) {
- puts("You can't do that with make call!");
- return;
- } else {
- pjsua_buddy_info binfo;
- pjsua_buddy_get_info(result.nb_result-1, &binfo);
- tmp.ptr = buf;
- pj_strncpy(&tmp, &binfo.uri, sizeof(buf));
- }
- } else if (result.uri_result) {
- tmp = pj_str(result.uri_result);
- } else {
- tmp.slen = 0;
- }
- pjsua_msg_data_init(&msg_data_);
- TEST_MULTIPART(&msg_data_);
- if (app_config.enable_loam) {
- call_opt.flag |= PJSUA_CALL_NO_SDP_OFFER;
- }
- pjsua_call_make_call(current_acc, &tmp, &call_opt, NULL,
- &msg_data_, ¤t_call);
- result.nb_result++;
- } while (loop);
- }
- static void ui_make_multi_call()
- {
- char menuin[32];
- int count;
- char buf[128];
- input_result result;
- pj_str_t tmp;
- int i;
- printf("(You currently have %d calls)\n", pjsua_call_get_count());
- if (!simple_input("Number of calls", menuin, sizeof(menuin)))
- return;
- count = my_atoi(menuin);
- if (count < 1)
- return;
- ui_input_url("Make call", buf, sizeof(buf), &result, PJ_FALSE);
- if (result.nb_result != PJSUA_APP_NO_NB) {
- pjsua_buddy_info binfo;
- if (result.nb_result == -1 || result.nb_result == 0) {
- puts("You can't do that with make call!");
- return;
- }
- pjsua_buddy_get_info(result.nb_result-1, &binfo);
- tmp.ptr = buf;
- pj_strncpy(&tmp, &binfo.uri, sizeof(buf));
- } else {
- tmp = pj_str(result.uri_result);
- }
- if (app_config.enable_loam) {
- call_opt.flag |= PJSUA_CALL_NO_SDP_OFFER;
- }
- for (i=0; i<my_atoi(menuin); ++i) {
- pj_status_t status;
- status = pjsua_call_make_call(current_acc, &tmp, &call_opt, NULL,
- NULL, NULL);
- if (status != PJ_SUCCESS)
- break;
- }
- }
- static void ui_detect_nat_type()
- {
- int i = pjsua_detect_nat_type();
- if (i != PJ_SUCCESS)
- pjsua_perror(THIS_FILE, "Error", i);
- }
- static void ui_send_instant_message()
- {
- char *uri = NULL;
- /* i is for call index to send message, if any */
- int i = -1;
- input_result result;
- char buf[128];
- char text[128];
- pj_str_t tmp;
- /* Input destination. */
- ui_input_url("Send IM to", buf, sizeof(buf), &result, PJ_FALSE);
- if (result.nb_result != PJSUA_APP_NO_NB) {
- if (result.nb_result == -1) {
- puts("You can't send broadcast IM like that!");
- return;
- } else if (result.nb_result == 0) {
- i = current_call;
- } else {
- pjsua_buddy_info binfo;
- pjsua_buddy_get_info(result.nb_result-1, &binfo);
- tmp.ptr = buf;
- pj_strncpy_with_null(&tmp, &binfo.uri, sizeof(buf));
- uri = buf;
- }
- } else if (result.uri_result) {
- uri = result.uri_result;
- }
- /* Send typing indication. */
- if (!app_config.no_mci) {
- if (i != -1)
- pjsua_call_send_typing_ind(i, PJ_TRUE, NULL);
- else {
- pj_str_t tmp_uri = pj_str(uri);
- pjsua_im_typing(current_acc, &tmp_uri, PJ_TRUE, NULL);
- }
- }
- /* Input the IM . */
- if (!simple_input("Message", text, sizeof(text))) {
- if (!app_config.no_mci) {
- /*
- * Cancelled.
- * Send typing notification too, saying we're not typing.
- */
- if (i != -1)
- pjsua_call_send_typing_ind(i, PJ_FALSE, NULL);
- else {
- pj_str_t tmp_uri = pj_str(uri);
- pjsua_im_typing(current_acc, &tmp_uri, PJ_FALSE, NULL);
- }
- return;
- }
- }
- tmp = pj_str(text);
- /* Send the IM */
- if (i != -1)
- pjsua_call_send_im(i, NULL, &tmp, NULL, NULL);
- else {
- pj_str_t tmp_uri = pj_str(uri);
- pjsua_im_send(current_acc, &tmp_uri, NULL, &tmp, NULL, NULL);
- }
- }
- static void ui_answer_call()
- {
- pjsua_call_info call_info;
- char buf[128];
- pjsua_msg_data msg_data_;
- if (current_call != -1) {
- pjsua_call_get_info(current_call, &call_info);
- } else {
- /* Make compiler happy */
- call_info.role = PJSIP_ROLE_UAC;
- call_info.state = PJSIP_INV_STATE_DISCONNECTED;
- }
- if (current_call == -1 ||
- call_info.role != PJSIP_ROLE_UAS ||
- call_info.state >= PJSIP_INV_STATE_CONNECTING)
- {
- puts("No pending incoming call");
- fflush(stdout);
- return;
- } else {
- int st_code;
- char contact[120];
- pj_str_t hname = { "Contact", 7 };
- pj_str_t hvalue;
- pjsip_generic_string_hdr hcontact;
- if (!simple_input("Answer with code (100-699)", buf, sizeof(buf)))
- return;
- st_code = my_atoi(buf);
- if (st_code < 100)
- return;
- pjsua_msg_data_init(&msg_data_);
- if (st_code/100 == 3) {
- if (!simple_input("Enter URL to be put in Contact",
- contact, sizeof(contact)))
- return;
- hvalue = pj_str(contact);
- pjsip_generic_string_hdr_init2(&hcontact, &hname, &hvalue);
- pj_list_push_back(&msg_data_.hdr_list, &hcontact);
- }
- /*
- * Must check again!
- * Call may have been disconnected while we're waiting for
- * keyboard input.
- */
- if (current_call == -1) {
- puts("Call has been disconnected");
- fflush(stdout);
- return;
- }
- pjsua_call_answer2(current_call, &call_opt, st_code, NULL, &msg_data_);
- }
- }
- static void ui_hangup_call(char menuin[])
- {
- if (current_call == -1) {
- puts("No current call");
- fflush(stdout);
- return;
- } else if (menuin[1] == 'a') {
- /* Hangup all calls */
- pjsua_call_hangup_all();
- } else {
- /* Hangup current calls */
- pjsua_call_hangup(current_call, 0, NULL, NULL);
- }
- }
- static void ui_cycle_dialog(char menuin[])
- {
- if (menuin[0] == ']') {
- find_next_call();
- } else {
- find_prev_call();
- }
- if (current_call != -1) {
- pjsua_call_info call_info;
- pjsua_call_get_info(current_call, &call_info);
- PJ_LOG(3,(THIS_FILE,"Current dialog: %.*s",
- (int)call_info.remote_info.slen,
- call_info.remote_info.ptr));
- } else {
- PJ_LOG(3,(THIS_FILE,"No current dialog"));
- }
- }
- static void ui_cycle_account()
- {
- int i;
- char buf[128];
- if (!simple_input("Enter account ID to select", buf, sizeof(buf)))
- return;
- i = my_atoi(buf);
- if (pjsua_acc_is_valid(i)) {
- pjsua_acc_set_default(i);
- PJ_LOG(3,(THIS_FILE, "Current account changed to %d", i));
- } else {
- PJ_LOG(3,(THIS_FILE, "Invalid account id %d", i));
- }
- }
- static void ui_add_buddy()
- {
- char buf[128];
- pjsua_buddy_config buddy_cfg;
- pjsua_buddy_id buddy_id;
- pj_status_t status;
- if (!simple_input("Enter buddy's URI:", buf, sizeof(buf)))
- return;
- if (pjsua_verify_url(buf) != PJ_SUCCESS) {
- printf("Invalid URI '%s'\n", buf);
- return;
- }
- pj_bzero(&buddy_cfg, sizeof(pjsua_buddy_config));
- buddy_cfg.uri = pj_str(buf);
- /* Only one subscription can be active, so we need to disable this
- * to allow user to choose between presence or dialog event.
- */
- // buddy_cfg.subscribe = PJ_TRUE;
- status = pjsua_buddy_add(&buddy_cfg, &buddy_id);
- if (status == PJ_SUCCESS) {
- printf("New buddy '%s' added at index %d\n",
- buf, buddy_id+1);
- }
- }
- static void ui_add_account(pjsua_transport_config *rtp_cfg)
- {
- char id[80], registrar[80], realm[80], uname[80], passwd[30];
- pjsua_acc_config acc_cfg;
- pj_status_t status;
- if (!simple_input("Your SIP URL:", id, sizeof(id)))
- return;
- if (!simple_input("URL of the registrar:", registrar, sizeof(registrar)))
- return;
- if (!simple_input("Auth Realm:", realm, sizeof(realm)))
- return;
- if (!simple_input("Auth Username:", uname, sizeof(uname)))
- return;
- if (!simple_input("Auth Password:", passwd, sizeof(passwd)))
- return;
- pjsua_acc_config_default(&acc_cfg);
- acc_cfg.id = pj_str(id);
- acc_cfg.reg_uri = pj_str(registrar);
- acc_cfg.cred_count = 1;
- acc_cfg.cred_info[0].scheme = pjsip_DIGEST_STR;
- acc_cfg.cred_info[0].realm = pj_str(realm);
- acc_cfg.cred_info[0].username = pj_str(uname);
- acc_cfg.cred_info[0].data_type = 0;
- acc_cfg.cred_info[0].data = pj_str(passwd);
- acc_cfg.rtp_cfg = *rtp_cfg;
- app_config_init_video(&acc_cfg);
- status = pjsua_acc_add(&acc_cfg, PJ_TRUE, NULL);
- if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Error adding new account", status);
- }
- }
- static void ui_delete_buddy()
- {
- char buf[128];
- int i;
- if (!simple_input("Enter buddy ID to delete", buf, sizeof(buf)))
- return;
- i = my_atoi(buf) - 1;
- if (!pjsua_buddy_is_valid(i)) {
- printf("Invalid buddy id %d\n", i);
- } else {
- pjsua_buddy_del(i);
- printf("Buddy %d deleted\n", i);
- }
- }
- static void ui_delete_account()
- {
- char buf[128];
- int i;
- if (!simple_input("Enter account ID to delete", buf, sizeof(buf)))
- return;
- i = my_atoi(buf);
- if (!pjsua_acc_is_valid(i)) {
- printf("Invalid account id %d\n", i);
- } else {
- pjsua_acc_del(i);
- printf("Account %d deleted\n", i);
- }
- }
- static void ui_unset_loam_mode()
- {
- app_config.enable_loam = PJ_FALSE;
- }
- static void ui_call_hold()
- {
- if (current_call != -1) {
- pjsua_call_set_hold(current_call, NULL);
- } else {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- }
- }
- static void ui_call_reinvite()
- {
- call_opt.flag |= PJSUA_CALL_UNHOLD;
- pjsua_call_reinvite2(current_call, &call_opt, NULL);
- }
- static void ui_send_update()
- {
- if (current_call != -1) {
- if (app_config.enable_loam) {
- call_opt.flag |= PJSUA_CALL_NO_SDP_OFFER;
- }
- pjsua_call_update2(current_call, &call_opt, NULL);
- } else {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- }
- }
- /*
- * Change codec priorities.
- */
- static void ui_manage_codec_prio()
- {
- 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 audio 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);
- }
- #if PJSUA_HAS_VIDEO
- puts("");
- printf("List of video codecs:\n");
- pjsua_vid_enum_codecs(c, &count);
- for (i=0; i<count; ++i) {
- printf(" %d\t%.*s%s%.*s\n", c[i].priority,
- (int)c[i].codec_id.slen,
- c[i].codec_id.ptr,
- c[i].desc.slen? " - ":"",
- (int)c[i].desc.slen,
- c[i].desc.ptr);
- }
- #endif
- puts("");
- puts("Enter codec id and its new priority (e.g. \"speex/16000 200\", "
- """\"H263 200\"),");
- puts("or empty to cancel.");
- printf("Codec name (\"*\" for all) and priority: ");
- if (fgets(input, sizeof(input), stdin) == NULL)
- return;
- 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 PJSUA_HAS_VIDEO
- if (status != PJ_SUCCESS) {
- status = pjsua_vid_codec_set_priority(pj_cstr(&id, codec),
- (pj_uint8_t)new_prio);
- }
- #endif
- if (status != PJ_SUCCESS)
- pjsua_perror(THIS_FILE, "Error setting codec priority", status);
- }
- static void ui_call_transfer(pj_bool_t no_refersub)
- {
- if (current_call == -1) {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- } else {
- int call = current_call;
- char buf[128];
- pjsip_generic_string_hdr refer_sub;
- pj_str_t STR_REFER_SUB = { "Refer-Sub", 9 };
- pj_str_t STR_FALSE = { "false", 5 };
- pjsua_call_info ci;
- input_result result;
- pjsua_msg_data msg_data_;
- pjsua_call_get_info(current_call, &ci);
- printf("Transferring current call [%d] %.*s\n", current_call,
- (int)ci.remote_info.slen, ci.remote_info.ptr);
- ui_input_url("Transfer to URL", buf, sizeof(buf), &result, PJ_FALSE);
- /* Check if call is still there. */
- if (call != current_call) {
- puts("Call has been disconnected");
- return;
- }
- pjsua_msg_data_init(&msg_data_);
- if (no_refersub) {
- /* Add Refer-Sub: false in outgoing REFER request */
- pjsip_generic_string_hdr_init2(&refer_sub, &STR_REFER_SUB,
- &STR_FALSE);
- pj_list_push_back(&msg_data_.hdr_list, &refer_sub);
- }
- if (result.nb_result != PJSUA_APP_NO_NB) {
- if (result.nb_result == -1 || result.nb_result == 0) {
- puts("You can't do that with transfer call!");
- } else {
- pjsua_buddy_info binfo;
- pjsua_buddy_get_info(result.nb_result-1, &binfo);
- pjsua_call_xfer( current_call, &binfo.uri, &msg_data_);
- }
- } else if (result.uri_result) {
- pj_str_t tmp;
- tmp = pj_str(result.uri_result);
- pjsua_call_xfer( current_call, &tmp, &msg_data_);
- }
- }
- }
- static void ui_call_transfer_replaces(pj_bool_t no_refersub)
- {
- if (current_call == -1) {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- } else {
- int call = current_call;
- int dst_call;
- pjsip_generic_string_hdr refer_sub;
- pj_str_t STR_REFER_SUB = { "Refer-Sub", 9 };
- pj_str_t STR_FALSE = { "false", 5 };
- pjsua_call_id ids[PJSUA_MAX_CALLS];
- pjsua_call_info ci;
- pjsua_msg_data msg_data_;
- char buf[128];
- unsigned i, count;
- count = PJ_ARRAY_SIZE(ids);
- pjsua_enum_calls(ids, &count);
- if (count <= 1) {
- puts("There are no other calls");
- return;
- }
- pjsua_call_get_info(current_call, &ci);
- printf("Transfer call [%d] %.*s to one of the following:\n",
- current_call,
- (int)ci.remote_info.slen, ci.remote_info.ptr);
- for (i=0; i<count; ++i) {
- pjsua_call_info call_info;
- if (ids[i] == call)
- continue;
- pjsua_call_get_info(ids[i], &call_info);
- printf("%d %.*s [%.*s]\n",
- ids[i],
- (int)call_info.remote_info.slen,
- call_info.remote_info.ptr,
- (int)call_info.state_text.slen,
- call_info.state_text.ptr);
- }
- if (!simple_input("Enter call number to be replaced", buf, sizeof(buf)))
- return;
- dst_call = my_atoi(buf);
- /* Check if call is still there. */
- if (call != current_call) {
- puts("Call has been disconnected");
- return;
- }
- /* Check that destination call is valid. */
- if (dst_call == call) {
- puts("Destination call number must not be the same "
- "as the call being transferred");
- return;
- }
- if (dst_call >= PJSUA_MAX_CALLS) {
- puts("Invalid destination call number");
- return;
- }
- if (!pjsua_call_is_active(dst_call)) {
- puts("Invalid destination call number");
- return;
- }
- pjsua_msg_data_init(&msg_data_);
- if (no_refersub) {
- /* Add Refer-Sub: false in outgoing REFER request */
- pjsip_generic_string_hdr_init2(&refer_sub, &STR_REFER_SUB,
- &STR_FALSE);
- pj_list_push_back(&msg_data_.hdr_list, &refer_sub);
- }
- pjsua_call_xfer_replaces(call, dst_call,
- PJSUA_XFER_NO_REQUIRE_REPLACES,
- &msg_data_);
- }
- }
- static void ui_send_dtmf_2833()
- {
- if (current_call == -1) {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- } else if (!pjsua_call_has_media(current_call)) {
- PJ_LOG(3,(THIS_FILE, "Media is not established yet!"));
- } else {
- pj_str_t digits;
- int call = current_call;
- pj_status_t status;
- char buf[128];
- #if defined(PJMEDIA_HAS_DTMF_FLASH) && PJMEDIA_HAS_DTMF_FLASH!= 0
- if (!simple_input("DTMF strings to send (0-9*R#A-B)", buf,
- sizeof(buf)))
- #else
- if (!simple_input("DTMF strings to send (0-9*#A-B)", buf,
- sizeof(buf)))
- #endif
- {
- return;
- }
- if (call != current_call) {
- puts("Call has been disconnected");
- return;
- }
- digits = pj_str(buf);
- status = pjsua_call_dial_dtmf(current_call, &digits);
- if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Unable to send DTMF", status);
- } else {
- puts("DTMF digits enqueued for transmission");
- }
- }
- }
- static void ui_send_dtmf_info()
- {
- if (current_call == -1) {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- } else {
- int call = current_call;
- pj_status_t status;
- char buf[128];
- pjsua_call_send_dtmf_param param;
- if (!simple_input("DTMF strings to send (0-9*#A-B)", buf,
- sizeof(buf)))
- {
- return;
- }
- if (call != current_call) {
- puts("Call has been disconnected");
- return;
- }
- pjsua_call_send_dtmf_param_default(¶m);
- param.digits = pj_str(buf);
- param.method = PJSUA_DTMF_METHOD_SIP_INFO;
- status = pjsua_call_send_dtmf(current_call, ¶m);
- if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Error sending DTMF", status);
- }
- }
- }
- static void ui_send_arbitrary_request()
- {
- char text[128];
- char buf[128];
- char *uri;
- input_result result;
- pj_str_t tmp;
- if (pjsua_acc_get_count() == 0) {
- puts("Sorry, need at least one account configured");
- return;
- }
- puts("Send arbitrary request to remote host");
- /* Input METHOD */
- if (!simple_input("Request method:",text,sizeof(text)))
- return;
- /* Input destination URI */
- uri = NULL;
- ui_input_url("Destination URI", buf, sizeof(buf), &result, PJ_FALSE);
- if (result.nb_result != PJSUA_APP_NO_NB) {
- if (result.nb_result == -1) {
- puts("Sorry you can't do that!");
- return;
- } else if (result.nb_result == 0) {
- uri = NULL;
- if (current_call == PJSUA_INVALID_ID) {
- puts("No current call");
- return;
- }
- } else {
- pjsua_buddy_info binfo;
- pjsua_buddy_get_info(result.nb_result-1, &binfo);
- tmp.ptr = buf;
- pj_strncpy_with_null(&tmp, &binfo.uri, sizeof(buf));
- uri = buf;
- }
- } else if (result.uri_result) {
- uri = result.uri_result;
- } else {
- return;
- }
- if (uri) {
- tmp = pj_str(uri);
- send_request(text, &tmp);
- } else {
- /* If you send call control request using this method
- * (such requests includes BYE, CANCEL, etc.), it will
- * not go well with the call state, so don't do it
- * unless it's for testing.
- */
- pj_str_t method = pj_str(text);
- pjsua_call_send_request(current_call, &method, NULL);
- }
- }
- static void ui_toggle_call_sdp_offer()
- {
- app_config.enable_loam = !app_config.enable_loam;
- printf("Subsequent calls and UPDATEs will contain SDP offer: ");
- if (app_config.enable_loam) {
- printf("NO.\n");
- } else {
- printf("YES.\n");
- }
- }
- static void ui_echo(char menuin[])
- {
- if (pj_ansi_strnicmp(menuin, "echo", 4)==0) {
- pj_str_t tmp;
- tmp.ptr = menuin+5;
- tmp.slen = pj_ansi_strlen(menuin)-6;
- if (tmp.slen < 1) {
- puts("Usage: echo [0|1]");
- return;
- }
- cmd_echo = *tmp.ptr != '0' || tmp.slen!=1;
- }
- }
- static void ui_sleep(char menuin[])
- {
- if (pj_ansi_strnicmp(menuin, "sleep", 5)==0) {
- pj_str_t tmp;
- int delay;
- tmp.ptr = menuin+6;
- tmp.slen = pj_ansi_strlen(menuin)-7;
- if (tmp.slen < 1) {
- puts("Usage: sleep MSEC");
- return;
- }
- delay = (int)pj_strtoul(&tmp);
- if (delay < 0) delay = 0;
- pj_thread_sleep(delay);
- }
- }
- static void ui_subscribe(char menuin[])
- {
- char buf[128];
- input_result result;
- ui_input_url("(un)Subscribe presence of", buf, sizeof(buf), &result,
- PJ_TRUE);
- if (result.nb_result != PJSUA_APP_NO_NB) {
- if (result.nb_result == -1) {
- int i, count;
- count = pjsua_get_buddy_count();
- for (i=0; i<count; ++i)
- pjsua_buddy_subscribe_pres(i, menuin[0]=='s');
- } else if (result.nb_result == 0) {
- puts("Sorry, can only subscribe to buddy's presence, "
- "not from existing call");
- } else {
- pjsua_buddy_subscribe_pres(result.nb_result-1, (menuin[0]=='s'));
- }
- } else if (result.uri_result) {
- puts("Sorry, can only subscribe to buddy's presence, "
- "not arbitrary URL (for now)");
- }
- }
- static void ui_subscribe_dlg_event(pj_bool_t sub)
- {
- char buf[128];
- input_result result;
- ui_input_url("(un)Subscribe dialog event of", buf, sizeof(buf), &result,
- PJ_TRUE);
- if (result.nb_result != PJSUA_APP_NO_NB) {
- if (result.nb_result == -1) {
- int i, count;
- count = pjsua_get_buddy_count();
- for (i=0; i<count; ++i)
- pjsua_buddy_subscribe_dlg_event(i, sub);
- } else if (result.nb_result == 0) {
- puts("Sorry, can only subscribe to buddy's dialog event, "
- "not from existing call");
- } else {
- pjsua_buddy_subscribe_dlg_event(result.nb_result-1, sub);
- }
- } else if (result.uri_result) {
- puts("Sorry, can only subscribe to buddy's dialog event, "
- "not arbitrary URL (for now)");
- }
- }
- static void ui_register(char menuin[])
- {
- switch (menuin[1]) {
- case 'r':
- /*
- * Re-Register.
- */
- pjsua_acc_set_registration(current_acc, PJ_TRUE);
- break;
- case 'u':
- /*
- * Unregister
- */
- pjsua_acc_set_registration(current_acc, PJ_FALSE);
- break;
- }
- }
- static void ui_toggle_state()
- {
- pjsua_acc_info acc_info;
- pjsua_acc_get_info(current_acc, &acc_info);
- acc_info.online_status = !acc_info.online_status;
- pjsua_acc_set_online_status(current_acc, acc_info.online_status);
- printf("Setting %s online status to %s\n",
- acc_info.acc_uri.ptr,
- (acc_info.online_status?"online":"offline"));
- }
- /*
- * Change extended online status.
- */
- static void ui_change_online_status()
- {
- char menuin[32];
- pj_bool_t online_status;
- pjrpid_element elem;
- int choice;
- unsigned i;
- enum {
- AVAILABLE, BUSY, OTP, IDLE, AWAY, BRB, OFFLINE, OPT_MAX
- };
- struct opt {
- int id;
- char *name;
- } opts[] = {
- { AVAILABLE, "Available" },
- { BUSY, "Busy"},
- { OTP, "On the phone"},
- { IDLE, "Idle"},
- { AWAY, "Away"},
- { BRB, "Be right back"},
- { OFFLINE, "Offline"}
- };
- printf("\n"
- "Choices:\n");
- for (i=0; i<(unsigned)PJ_ARRAY_SIZE(opts); ++i) {
- printf(" %d %s\n", opts[i].id+1, opts[i].name);
- }
- if (!simple_input("Select status", menuin, sizeof(menuin)))
- return;
- choice = atoi(menuin) - 1;
- if (choice < 0 || choice >= OPT_MAX) {
- puts("Invalid selection");
- return;
- }
- pj_bzero(&elem, sizeof(elem));
- elem.type = PJRPID_ELEMENT_TYPE_PERSON;
- online_status = PJ_TRUE;
- switch (choice) {
- case AVAILABLE:
- break;
- case BUSY:
- elem.activity = PJRPID_ACTIVITY_BUSY;
- elem.note = pj_str("Busy");
- break;
- case OTP:
- elem.activity = PJRPID_ACTIVITY_BUSY;
- elem.note = pj_str("On the phone");
- break;
- case IDLE:
- elem.activity = PJRPID_ACTIVITY_UNKNOWN;
- elem.note = pj_str("Idle");
- break;
- case AWAY:
- elem.activity = PJRPID_ACTIVITY_AWAY;
- elem.note = pj_str("Away");
- break;
- case BRB:
- elem.activity = PJRPID_ACTIVITY_UNKNOWN;
- elem.note = pj_str("Be right back");
- break;
- case OFFLINE:
- online_status = PJ_FALSE;
- break;
- }
- pjsua_acc_set_online_status2(current_acc, online_status, &elem);
- }
- /*
- * List the ports in conference bridge
- */
- static void ui_conf_list()
- {
- unsigned i, count;
- pjsua_conf_port_id id[PJSUA_MAX_CONF_PORTS];
- printf("Conference ports:\n");
- count = PJ_ARRAY_SIZE(id);
- pjsua_enum_conf_ports(id, &count);
- for (i=0; i<count; ++i) {
- char txlist[PJSUA_MAX_CALLS*4+10];
- unsigned j;
- pjsua_conf_port_info info;
- pjsua_conf_get_port_info(id[i], &info);
- txlist[0] = '\0';
- for (j=0; j<info.listener_cnt; ++j) {
- char s[10];
- pj_ansi_snprintf(s, sizeof(s), "#%d ", info.listeners[j]);
- pj_ansi_strxcat(txlist, s, sizeof(txlist));
- }
- printf("Port #%02d[%2dKHz/%dms/%d] %20.*s transmitting to: %s\n",
- info.slot_id,
- info.clock_rate/1000,
- info.samples_per_frame*1000/info.channel_count/info.clock_rate,
- info.channel_count,
- (int)info.name.slen,
- info.name.ptr,
- txlist);
- }
- puts("");
- }
- static void ui_conf_connect(char menuin[])
- {
- char tmp[10], src_port[10], dst_port[10];
- pj_status_t status;
- int cnt;
- const char *src_title, *dst_title;
- cnt = sscanf(menuin, "%s %s %s", tmp, src_port, dst_port);
- if (cnt != 3) {
- ui_conf_list();
- src_title = (menuin[1]=='c'? "Connect src port #":
- "Disconnect src port #");
- dst_title = (menuin[1]=='c'? "To dst port #":"From dst port #");
- if (!simple_input(src_title, src_port, sizeof(src_port)))
- return;
- if (!simple_input(dst_title, dst_port, sizeof(dst_port)))
- return;
- }
- if (menuin[1]=='c') {
- status = pjsua_conf_connect(my_atoi(src_port), my_atoi(dst_port));
- } else {
- status = pjsua_conf_disconnect(my_atoi(src_port), my_atoi(dst_port));
- }
- if (status == PJ_SUCCESS) {
- puts("Success");
- } else {
- puts("ERROR!!");
- }
- }
- static void ui_adjust_volume()
- {
- char buf[128];
- char text[128];
- snprintf(buf, sizeof(buf), "Adjust mic level: [%4.1fx] ",
- app_config.mic_level);
- if (simple_input(buf,text,sizeof(text))) {
- char *err;
- app_config.mic_level = (float)strtod(text, &err);
- pjsua_conf_adjust_rx_level(0, app_config.mic_level);
- }
- snprintf(buf, sizeof(buf), "Adjust speaker level: [%4.1fx] ",
- app_config.speaker_level);
- if (simple_input(buf,text,sizeof(text))) {
- char *err;
- app_config.speaker_level = (float)strtod(text, &err);
- pjsua_conf_adjust_tx_level(0, app_config.speaker_level);
- }
- }
- static void ui_dump_call_quality()
- {
- if (current_call != PJSUA_INVALID_ID) {
- log_call_dump(current_call);
- } else {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- }
- }
- static void ui_dump_configuration()
- {
- char settings[2000];
- int len;
- len = write_settings(&app_config, settings, sizeof(settings));
- if (len < 1)
- PJ_LOG(1,(THIS_FILE, "Error: not enough buffer"));
- else
- PJ_LOG(3,(THIS_FILE, "Dumping configuration (%d bytes):\n%s\n",
- len, settings));
- }
- static void ui_write_settings(const char *filename)
- {
- char settings[2000];
- int len;
- len = write_settings(&app_config, settings, sizeof(settings));
- if (len < 1)
- PJ_LOG(1,(THIS_FILE, "Error: not enough buffer"));
- else {
- pj_oshandle_t fd;
- pj_status_t status;
- status = pj_file_open(app_config.pool, filename, PJ_O_WRONLY, &fd);
- if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "Unable to open file", status);
- } else {
- pj_ssize_t size = len;
- pj_file_write(fd, settings, &size);
- pj_file_close(fd);
- printf("Settings successfully written to '%s'\n", filename);
- }
- }
- }
- /*
- * Dump application states.
- */
- static void ui_app_dump(pj_bool_t detail)
- {
- pjsua_dump(detail);
- }
- static void ui_call_redirect(char menuin[])
- {
- if (current_call == PJSUA_INVALID_ID) {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- } else {
- if (!pjsua_call_is_active(current_call)) {
- PJ_LOG(1,(THIS_FILE, "Call %d has gone", current_call));
- } else if (menuin[1] == 'a') {
- pjsua_call_process_redirect(current_call,
- PJSIP_REDIRECT_ACCEPT_REPLACE);
- } else if (menuin[1] == 'A') {
- pjsua_call_process_redirect(current_call,
- PJSIP_REDIRECT_ACCEPT);
- } else if (menuin[1] == 'r') {
- pjsua_call_process_redirect(current_call,
- PJSIP_REDIRECT_REJECT);
- } else {
- pjsua_call_process_redirect(current_call,
- PJSIP_REDIRECT_STOP);
- }
- }
- }
- static void ui_handle_ip_change()
- {
- pjsua_ip_change_param param;
- pj_status_t status;
- pjsua_ip_change_param_default(¶m);
- status = pjsua_handle_ip_change(¶m);
- if (status != PJ_SUCCESS) {
- pjsua_perror(THIS_FILE, "IP change failed", status);
- }
- }
- /*
- * Main "user interface" loop.
- */
- void legacy_main(void)
- {
- char menuin[80];
- char buf[128];
- keystroke_help();
- for (;;) {
- printf(">>> ");
- fflush(stdout);
- if (fgets(menuin, sizeof(menuin), stdin) == NULL) {
- /*
- * Be friendly to users who redirect commands into
- * program, when file ends, resume with kbd.
- * If exit is desired end script with q for quit
- */
- /* Reopen stdin/stdout/stderr to /dev/console */
- #if ((defined(PJ_WIN32) && PJ_WIN32!=0) || \
- (defined(PJ_WIN64) && PJ_WIN64!=0)) && \
- (!defined(PJ_WIN32_WINCE) || PJ_WIN32_WINCE==0)
- if (freopen ("CONIN$", "r", stdin) == NULL) {
- #else
- if (1) {
- #endif
- puts("Cannot switch back to console from file redirection");
- menuin[0] = 'q';
- menuin[1] = '\0';
- } else {
- puts("Switched back to console from file redirection");
- continue;
- }
- }
- if (cmd_echo) {
- printf("%s", menuin);
- }
- /* Update call setting */
- pjsua_call_setting_default(&call_opt);
- call_opt.aud_cnt = app_config.aud_cnt;
- call_opt.vid_cnt = app_config.vid.vid_cnt;
- switch (menuin[0]) {
- case 'm':
- /* Make call! : */
- ui_make_new_call();
- break;
- case 'M':
- /* Make multiple calls! : */
- ui_make_multi_call();
- break;
- case 'n':
- ui_detect_nat_type();
- break;
- case 'i':
- /* Send instant messaeg */
- ui_send_instant_message();
- break;
- case 'a':
- ui_answer_call();
- break;
- case 'h':
- ui_hangup_call(menuin);
- break;
- case ']':
- case '[':
- /*
- * Cycle next/prev dialog.
- */
- ui_cycle_dialog(menuin);
- break;
- case '>':
- case '<':
- ui_cycle_account();
- break;
- case '+':
- if (menuin[1] == 'b') {
- ui_add_buddy();
- } else if (menuin[1] == 'a') {
- ui_add_account(&app_config.rtp_cfg);
- } else {
- printf("Invalid input %s\n", menuin);
- }
- break;
- case '-':
- if (menuin[1] == 'b') {
- ui_delete_buddy();
- } else if (menuin[1] == 'a') {
- ui_delete_account();
- } else {
- printf("Invalid input %s\n", menuin);
- }
- break;
- case 'H':
- /*
- * Hold call.
- */
- ui_call_hold();
- break;
- case 'o':
- /*
- * Toggle call SDP offer
- */
- ui_toggle_call_sdp_offer();
- break;
- case 'v':
- #if PJSUA_HAS_VIDEO
- if (menuin[1]=='i' && menuin[2]=='d' && menuin[3]==' ') {
- vid_handle_menu(menuin);
- } else
- #endif
- if (current_call != -1) {
- /*
- * re-INVITE
- */
- ui_call_reinvite();
- } else {
- PJ_LOG(3,(THIS_FILE, "No current call"));
- }
- break;
- case 'U':
- /*
- * Send UPDATE
- */
- ui_send_update();
- break;
- case 'C':
- if (menuin[1] == 'p') {
- ui_manage_codec_prio();
- }
- break;
- case 'x':
- /*
- * Transfer call.
- */
- ui_call_transfer(app_config.no_refersub);
- break;
- case 'X':
- /*
- * Transfer call with replaces.
- */
- ui_call_transfer_replaces(app_config.no_refersub);
- break;
- case '#':
- /*
- * Send DTMF strings.
- */
- ui_send_dtmf_2833();
- break;
- case '*':
- /* Send DTMF with INFO */
- ui_send_dtmf_info();
- break;
- case 'S':
- /*
- * Send arbitrary request
- */
- ui_send_arbitrary_request();
- break;
- case 'e':
- ui_echo(menuin);
- break;
- case 's':
- if (pj_ansi_strnicmp(menuin, "sleep", 5)==0) {
- ui_sleep(menuin);
- break;
- }
- /* Continue below */
- case 'u':
- /*
- * Subscribe/unsubscribe presence.
- */
- ui_subscribe(menuin);
- break;
- case 'D':
- /* Subscribe/unsubscribe dialog event */
- ui_subscribe_dlg_event(menuin[1] != 'u');
- break;
- case 'r':
- ui_register(menuin);
- break;
- case 't':
- ui_toggle_state();
- break;
- case 'T':
- ui_change_online_status();
- break;
- case 'c':
- switch (menuin[1]) {
- case 'l':
- ui_conf_list();
- break;
- case 'c':
- case 'd':
- ui_conf_connect(menuin);
- break;
- }
- break;
- case 'V':
- /* Adjust audio volume */
- ui_adjust_volume();
- break;
- case 'd':
- if (menuin[1] == 'c') {
- ui_dump_configuration();
- } else if (menuin[1] == 'q') {
- ui_dump_call_quality();
- } else {
- ui_app_dump(menuin[1]=='d');
- }
- break;
- case 'f':
- if (simple_input("Enter output filename", buf, sizeof(buf))) {
- ui_write_settings(buf);
- }
- break;
- case 'L': /* Restart */
- case 'q':
- legacy_on_stopped(menuin[0]=='L');
- goto on_exit;
- case 'R':
- ui_call_redirect(menuin);
- break;
- case 'I': /* Handle IP change. */
- ui_handle_ip_change();
- break;
- default:
- if (menuin[0] != '\n' && menuin[0] != '\r') {
- printf("Invalid input %s", menuin);
- }
- keystroke_help();
- break;
- }
- }
- on_exit:
- ;
- }
|