?? placecall.cpp
字號(hào):
//// Copyright (C) 2004, 2005 Pingtel Corp.// //// $$//////////////////////////////////////////////////////////////////////////////#include "os/OsDefs.h"#include <assert.h>#if defined(_WIN32)# include <windows.h># define SLEEP(milliseconds) Sleep(milliseconds)#else# include <unistd.h># define SLEEP(milliseconds) usleep((milliseconds)*1000)#endif#include "os/OsDefs.h"#include "tapi/sipXtapi.h"#include "tapi/sipXtapiEvents.h"#define MAX_RECORD_EVENTS 16SIPX_INST g_hInst = NULL ; // Handle to the sipXtapi instananceSIPX_LINE g_hLine = 0 ; // Line Instance (id, auth, etc)SIPX_CALL g_hCall = 0 ; // Handle to a callSIPX_CALLSTATE_EVENT g_eRecordEvents[MAX_RECORD_EVENTS] ; // List of last N eventsint g_iNextEvent ; // Index for g_eRecordEvents ringer buffer// Print usage messagevoid usage(const char* szExecutable){ char szBuffer[64]; sipxConfigGetVersion(szBuffer, 64); printf("\nUsage:\n") ; printf(" %s <options> [URL]\n", szExecutable) ; printf(" using %s\n", szBuffer); printf("\n") ; printf("Options:\n") ; printf(" -d durationInSeconds (default=30 seconds)\n") ; printf(" -t play tones (default = none)\n") ; printf(" -f play file (default = none)\n") ; printf(" -p SIP port (default = 5060)\n") ; printf(" -r RTP port start (default = 9000)\n") ; printf(" -R use rport as part of via (disabled by default)\n") ; printf(" -u username (for authentication)\n") ; printf(" -a password (for authentication)\n") ; printf(" -m realm (for authentication)\n") ; printf(" -i from identity\n") ; printf(" -S stun server\n") ; printf(" -x proxy (outbound proxy)\n"); printf(" -v show sipXtapi version\n"); printf(" -c repeat count/Prank mode (call end point N times)\n") ; printf(" -I call input device name\n"); printf(" -O call output device name\n"); printf(" -C codec name\n"); printf(" -L list all supported codecs\n"); printf("\n") ;}// Parse argumentsbool parseArgs(int argc, char* argv[], int* pDuration, int* pSipPort, int* pRtpPort, char** pszPlayTones, char** pszFile, char** pszUrl, bool* bUseRport, char** pszUsername, char** pszPassword, char** pszRealm, char** pszFromIdentity, char** pszStunServer, char** pszProxy, int* pRepeatCount, char** pszInputDevice, char** pszOutputDevice, char** pszCodecName, bool* bCodecList){ bool bRC = false ; char szBuffer[64]; assert(pDuration && pszPlayTones && pszUrl) ; *pDuration = 30 ; *pSipPort = 5060 ; *pRtpPort = 9000 ; *pRepeatCount = 1 ; *pszPlayTones = NULL ; *pszFile = NULL ; *pszUrl = NULL ; *bUseRport = false ; *pszUsername = NULL ; *pszPassword = NULL ; *pszRealm = NULL ; *pszFromIdentity = NULL ; *pszStunServer = NULL ; *pszProxy = NULL; *pszInputDevice = NULL; *pszOutputDevice = NULL; *pszCodecName = NULL; *bCodecList = false; for (int i=1; i<argc; i++) { if (strcmp(argv[i], "-d") == 0) { if ((i+1) < argc) { *pDuration = atoi(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-t") == 0) { if ((i+1) < argc) { *pszPlayTones = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-p") == 0) { if ((i+1) < argc) { *pSipPort = atoi(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-r") == 0) { if ((i+1) < argc) { *pRtpPort = atoi(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-f") == 0) { if ((i+1) < argc) { *pszFile = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-u") == 0) { if ((i+1) < argc) { *pszUsername = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-a") == 0) { if ((i+1) < argc) { *pszPassword = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-m") == 0) { if ((i+1) < argc) { *pszRealm = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-i") == 0) { if ((i+1) < argc) { *pszFromIdentity = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-x") == 0) { if ((i+1) < argc) { *pszProxy = strdup(argv[++i]) ; } else { bRC = false ; break ; // Error } } else if (strcmp(argv[i], "-S") == 0) { if ((i+1) < argc) { *pszStunServer = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-R") == 0) { *bUseRport = true ; } else if (strcmp(argv[i], "-L") == 0) { *bCodecList = true ; bRC = true ; } else if (strcmp(argv[i], "-v") == 0) { sipxConfigGetVersion(szBuffer, 64); printf("%s\n", szBuffer); exit(0); } else if (strcmp(argv[i], "-c") == 0) { if ((i+1) < argc) { *pRepeatCount = atoi(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-I") == 0) { if ((i+1) < argc) { *pszInputDevice = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-O") == 0) { if ((i+1) < argc) { *pszOutputDevice = strdup(argv[++i]) ; } else { break ; // Error } } else if (strcmp(argv[i], "-C") == 0) if ((i+1) < argc) { *pszCodecName = strdup(argv[++i]) ; } else { break ; // Error } } else { if ((i+1) == argc) { *pszUrl = strdup(argv[i]) ; bRC = true ; } else { break ; // Error } } } return bRC ;}bool EventCallBack(SIPX_EVENT_CATEGORY category, void* pInfo, void* pUserData){ char cBuf[1024] ; printf("%s\n", sipxEventToString(category, pInfo, cBuf, sizeof(cBuf))) ; if (category == EVENT_CATEGORY_CALLSTATE) { SIPX_CALLSTATE_INFO* pCallInfo = static_cast<SIPX_CALLSTATE_INFO*>(pInfo); printf(" hCall=%d, hAssociatedCall=%d\n", pCallInfo->hCall, pCallInfo->hAssociatedCall) ; if (pCallInfo->cause == CALLSTATE_AUDIO_START) { printf("* Negotiated codec: %s, payload type %d\n", pCallInfo->codecs.audioCodec.cName, pCallInfo->codecs.audioCodec.iPayloadType); } g_eRecordEvents[g_iNextEvent] = pCallInfo->event; g_iNextEvent = (g_iNextEvent + 1) % MAX_RECORD_EVENTS ; } return true;}// Wait for the designated event for at worst ~iTimeoutInSecs secondsbool WaitForSipXEvent(SIPX_CALLSTATE_MAJOR eMajor, int iTimeoutInSecs){ bool bFound = false ; int tries = 0; // Kids, don't try this at home -- This method of waiting for events is // not recommended. Generally, most UAs are asynchronous and event // driven -- if you need to want for an event, build something that is // thread safe and doesn't use sleeps. while (!bFound) { for (int i=0;i<MAX_RECORD_EVENTS; i++) { if (g_eRecordEvents[i] == eMajor) { bFound = true ; break ; } } if (!bFound) { SLEEP(1000) ; if (++tries > (iTimeoutInSecs)) { break ; } } } return bFound ;}// Clear the event log
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -