void HiRes5Engine::animateLights() const { int index; byte color = 0x2a; for (index = 4; index >= 0; --index) drawLight(index, color); index = 4; while (!g_engine->shouldQuit()) { drawLight(index, color ^ 0x7f); // There's a delay here in the original engine. We leave it out as // we're already slower than the original without any delay. const uint kLoopCycles = 25; const byte period = (index + 1) << 4; const double freq = kClock / 2.0 / (period * kLoopCycles); const double len = 128 * period * kLoopCycles * 1000 / (double)kClock; Tones tone; tone.push_back(Tone(freq, len)); if (playTones(tone, false, true)) break; drawLight(index, color ^ 0xff); if (--index < 0) { index = 4; color ^= 0xff; } } }
int HiRes5Engine::o_winGame(ScriptEnv &e) { OP_DEBUG_0("\tWIN_GAME()"); showRoom(); playTones(_song, true); return o1_quit(e); }
bool EventCallBack(SIPX_EVENT_CATEGORY category, void* pInfo, void* pUserData) { assert (pInfo != NULL); // Dump event char cBuf[1024] ; sipxEventToString(category, pInfo, cBuf, sizeof(cBuf)); printf("%s\n", 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) ; SIPX_CALL hTmpCall = pCallInfo->hCall; switch (pCallInfo->event) { case CALLSTATE_OFFERING: #if defined(_WIN32) && defined(VIDEO) gDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gDisplay.handle = ghVideo; if (bVideo) { sipxCallAccept(pCallInfo->hCall, &gDisplay) ; } else #endif { sipxCallAccept(pCallInfo->hCall); } break ; case CALLSTATE_ALERTING: sipxCallAnswer(pCallInfo->hCall) ; break ; case CALLSTATE_CONNECTED: SLEEP(1000) ; // BAD: Do not block the callback thread // Play file if provided if (g_szFile) { if (!playFile(g_szFile, pCallInfo->hCall)) { printf("Failed to play file: %s\n", g_szFile) ; } } // Play tones if provided if (g_szPlayTones) { if (!playTones(g_szPlayTones, pCallInfo->hCall)) { printf("Failed to play tones: %s\n", g_szPlayTones) ; } } break ; case CALLSTATE_DISCONNECTED: sipxCallDestroy(&hTmpCall) ; break ; // ::TODO:: Fix me with new media event // case CALLSTATE_AUDIO_EVENT: // if (pCallInfo->cause == CALLSTATE_CAUSE_AUDIO_START) // { // printf("* Negotiated codec: %s, payload type %d\n", pCallInfo->codecs.audioCodec.cName, pCallInfo->codecs.audioCodec.iPayloadType); // } // break; case CALLSTATE_DESTROYED: break ; } } return true; }
bool EventCallBack(SIPX_EVENT_CATEGORY category, void* pInfo, void* pUserData) { assert (pInfo != NULL); // Dump event char cBuf[1024] ; // Print the timestamp if requested. if (g_timestamp) { OsDateTime d; OsDateTime::getCurTime(d); UtlString s; d.getIsoTimeStringZ(s); printf("%s ", s.data()); } 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) ; switch (pCallInfo->event) { case CALLSTATE_OFFERING: // Get and print the From: URI. { char remote[200]; sipxCallGetRemoteID(pCallInfo->hCall, remote, sizeof (remote)); printf(" From: %s\n", remote); } sipxCallAccept(pCallInfo->hCall) ; break ; case CALLSTATE_ALERTING: clearLoopback() ; { // Determine the answering delay. int delay; if (g_callAnswerDelay == NULL || g_callAnswerDelay[0] == '\0') { // No answer string is active, so delay is 0. delay = 0; } else { // Get the delay to be used from the delay string. delay = atoi(g_callAnswerDelay); // Remove the first number, if there is a comma. char* p = strchr(g_callAnswerDelay, ','); if (p != NULL) { g_callAnswerDelay = p + 1; } } if (delay == 0) { // If the delay is 0, answer immediately. sipxCallAnswer(pCallInfo->hCall); } else { // The delay is non-0, so set the timer to answer. // Stop the timer in case it is running. callAnswerTimer.stop(); // Record the call to be answered. callAnswerNotification.setHCall(pCallInfo->hCall); // Construct the delay to be used. OsTime d(delay, 0); // Start the timer. callAnswerTimer.oneshotAfter(d); } } break ; case CALLSTATE_CONNECTED: // Per conversation with Bob A., commented this sleep out // to prevent trouble with processing re-INVITEs that come // just after INVITEs. This should be replaced with a proper // timer-wait event. But that leads to the open question // of whether to use the sipX OsTimer system, or the underlying // OS mechanisms (to avoid dependency on sipXportLib). Ugh. //SLEEP(1000) ; // BAD: Do not block the callback thread // Start the timer that limits the length of the call. { // Stop the timer in case it is running. callHangupTimer.stop(); // Record the call to be answered. callHangupNotification.setHCall(pCallInfo->hCall); // Start the timer, scaled to seconds. OsTime delay(iDuration, 0); callHangupTimer.oneshotAfter(delay); } // Play file if provided if (g_szFile) { if (!playFile(g_szFile, pCallInfo->hCall)) { printf("Failed to play file: %s\n", g_szFile) ; } } // Play tones if provided if (g_szPlayTones) { if (!playTones(g_szPlayTones, pCallInfo->hCall)) { printf("Failed to play tones: %s\n", g_szPlayTones) ; } } break ; case CALLSTATE_DISCONNECTED: // Stop the timers in case they are running. callAnswerTimer.stop(); callHangupTimer.stop(); // Destroy the call. sipxCallDestroy(pCallInfo->hCall) ; break ; case CALLSTATE_AUDIO_EVENT: if (pCallInfo->cause == CALLSTATE_AUDIO_START) { printf("* Negotiated codec: %s, payload type %d\n", pCallInfo->codecs.audioCodec.cName, pCallInfo->codecs.audioCodec.iPayloadType); } break; case CALLSTATE_DESTROYED: // Stop the timer in case it is running. callAnswerTimer.stop(); break ; default: // There are many other events which we ignore. break; } } // Ensure the output is not delayed by buffering. fflush(stdout); return true; }
int local_main(int argc, char* argv[]) { bool bError = false ; int iDuration, iSipPort, iRtpPort, iRepeatCount ; char* szPlayTones; char* szSipUrl; char* szFile; char* szFileBuffer; char* szUsername; char* szPassword; char* szRealm; char* szFromIdentity; char* szStunServer; char* szProxy; char* szBindAddr; char* szOutDevice; char* szInDevice; char* szCodec; bool bUseRport; bool bCList; bool bAEC; bool bAGC; bool bDenoise; if ( signal( SIGINT, ctrlCHandler ) == SIG_ERR ) { printf("Couldn't install signal handler for SIGINT\n"); exit(1); } if ( signal( SIGTERM, ctrlCHandler ) == SIG_ERR ) { printf("Couldn't install signal handler for SIGTERM\n"); exit(1); } // Parse Arguments if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &szPlayTones, &szFile, &szFileBuffer, &szSipUrl, &bUseRport, &szUsername, &szPassword, &szRealm, &szFromIdentity, &szStunServer, &szProxy, &szBindAddr, &iRepeatCount, &szInDevice, &szOutDevice, &szCodec, &bCList, &bAEC, &bAGC, &bDenoise, &bUseCustomTransportReliable, &bUseCustomTransportUnreliable) && (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort))) { // initialize sipx TAPI-like API sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ; sipxConfigSetLogFile("PlaceCall.log"); int mediaEngineSampleRate = 16000; sipxInitialize(&g_hInst, iSipPort, iSipPort, -1, iRtpPort, DEFAULT_CONNECTIONS, DEFAULT_IDENTITY, szBindAddr, false, // use sequential RTP/RTCP ports NULL, // cert. nickname NULL, // cert. password NULL, // DB location true, // Enable local audio mediaEngineSampleRate, 48000); // Audio device sample rate sipxConfigEnableRport(g_hInst, bUseRport) ; dumpInputOutputDevices() ; sipxEventListenerAdd(g_hInst, EventCallBack, NULL) ; // Enable/disable AEC. if (bAEC) sipxAudioSetAECMode(g_hInst, SIPX_AEC_CANCEL_AUTO) ; else sipxAudioSetAECMode(g_hInst, SIPX_AEC_DISABLED) ; // Enable/disable AGC sipxAudioSetAGCMode(g_hInst, bAGC); if (bDenoise) sipxAudioSetNoiseReductionMode(g_hInst, SIPX_NOISE_REDUCTION_HIGH); else sipxAudioSetNoiseReductionMode(g_hInst, SIPX_NOISE_REDUCTION_DISABLED); if (bCList) { int numAudioCodecs; int numVideoCodecs; int index; SIPX_AUDIO_CODEC audioCodec; SIPX_VIDEO_CODEC videoCodec; printf("Audio codecs:\n"); if (sipxConfigGetNumAudioCodecs(g_hInst, &numAudioCodecs) == SIPX_RESULT_SUCCESS) { for (index=0; index<numAudioCodecs; ++index) { if (sipxConfigGetAudioCodec(g_hInst, index, &audioCodec) == SIPX_RESULT_SUCCESS) { printf(" audio %02d : %s\n", index, audioCodec.cName); } else { printf("Error in retrieving audio codec #%d\n", index); } } } else { printf("Error in retrieving number of audio codecs\n"); } #ifdef VIDEO printf("Video codecs:\n"); if (sipxConfigGetNumVideoCodecs(g_hInst, &numVideoCodecs) == SIPX_RESULT_SUCCESS) { for (index=0; index<numVideoCodecs; ++index) { if (sipxConfigGetVideoCodec(g_hInst, index, &videoCodec) == SIPX_RESULT_SUCCESS) { printf(" video %02d : %s\n", index, videoCodec.cName); } else { printf("Error in retrieving video codec #%d\n"); } } } else { printf("Error in retrieving number of video codecs\n"); } #endif // VIDEO sipxUnInitialize(g_hInst, true); exit(0); } if (szProxy) { sipxConfigSetOutboundProxy(g_hInst, szProxy); } if (szStunServer) { sipxConfigEnableStun(g_hInst, szStunServer, DEFAULT_STUN_PORT, 28) ; } if (szOutDevice) { if (sipxAudioSetCallOutputDevice(g_hInst, szOutDevice) != SIPX_RESULT_SUCCESS) { printf("!! Setting output device %s failed !!\n", szOutDevice); } } if (szInDevice) { if (sipxAudioSetCallInputDevice(g_hInst, szInDevice) != SIPX_RESULT_SUCCESS) { printf("!! Setting input device %s failed !!\n", szOutDevice); } } if (szCodec) { if (sipxConfigSetAudioCodecByName(g_hInst, szCodec) == SIPX_RESULT_FAILURE) { printf("!! Setting audio codec to %s failed !!\n", szCodec); }; } // Wait for a STUN response (should actually look for the STUN event status // (config event) ; SLEEP(1500) ; for (int i=0; i<iRepeatCount; i++) { ClearSipXEvents() ; printf("<-> Attempt %d of %d\n", i+1, iRepeatCount) ; // Place a call to designed URL if (placeCall(szSipUrl, szFromIdentity, szUsername, szPassword, szRealm)) { bError = false ; // Play tones if provided if (szPlayTones) { if (!playTones(szPlayTones)) { printf("%s: Failed to play tones: %s\n", argv[0], szPlayTones) ; } else { bError = true ; } } // Play file if provided if (szFile) { if (!playFile(szFile)) { printf("%s: Failed to play file: %s\n", argv[0], szFile) ; } else { bError = true ; } } // Play file from buffer if provided if (szFileBuffer) { if (!playFileBuffer(szFileBuffer)) { printf("%s: Failed to play file from buffer: %s\n", argv[0], szFileBuffer) ; } else { bError = true ; } } // Leave the call up for specified time period (or wait for hangup) WaitForSipXEvent(CALLSTATE_DISCONNECTED, iDuration) ; // Shutdown / cleanup if (!shutdownCall()) { printf("%s: Failed to shutdown call\n", argv[0]) ; bError = true ; } } else { printf("%s: Unable to complete call\n", argv[0]) ; shutdownCall() ; bError = true ; } if (bError) { break ; } } sipxEventListenerRemove(g_hInst, EventCallBack, NULL) ; sipxUnInitialize(g_hInst, true); } else { usage(argv[0]) ; } #if defined(_WIN32) && defined(VIDEO) PostMessage(hMain, WM_CLOSE, 0, 0L); #endif return (int) bError ; }
bool EventCallBack(SIPX_EVENT_CATEGORY category, void* pInfo, void* pUserData) { assert (pInfo != NULL); // Dump event 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) ; switch (pCallInfo->event) { case CALLSTATE_OFFERING: #if defined(_WIN32) && defined(VIDEO) gDisplay.type = SIPX_WINDOW_HANDLE_TYPE; gDisplay.handle = ghVideo; if (bVideo) { sipxCallAccept(pCallInfo->hCall, &gDisplay) ; } else #endif { sipxCallAccept(pCallInfo->hCall); } break ; case CALLSTATE_ALERTING: clearLoopback() ; sipxCallAnswer(pCallInfo->hCall) ; break ; case CALLSTATE_CONNECTED: SLEEP(1000) ; // BAD: Do not block the callback thread // Play file if provided if (g_szFile) { if (!playFile(g_szFile, pCallInfo->hCall)) { printf("Failed to play file: %s\n", g_szFile) ; } } // Play tones if provided if (g_szPlayTones) { if (!playTones(g_szPlayTones, pCallInfo->hCall)) { printf("Failed to play tones: %s\n", g_szPlayTones) ; } } break ; case CALLSTATE_DISCONNECTED: sipxCallDestroy(pCallInfo->hCall) ; break ; case CALLSTATE_DESTROYED: if (gbOneCallMode) { gbShutdown = true; } break ; } } else if (category == EVENT_CATEGORY_MEDIA) { SIPX_MEDIA_INFO* pMediaInfo = static_cast<SIPX_MEDIA_INFO*>(pInfo); switch(pMediaInfo->event) { case MEDIA_LOCAL_START: printf("* Negotiated codec: %s, payload type %d\n", pMediaInfo->codec.audioCodec.cName, pMediaInfo->codec.audioCodec.iPayloadType); break; } } return true; }