示例#1
0
ACDCallManager::~ACDCallManager()
{
   sipxEventListenerRemove(mAcdCallManagerHandle, ACDCallManager_EventCallback, static_cast<void*>(this));
   sipxUnInitialize(mAcdCallManagerHandle);
}
示例#2
0
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 ;
}
示例#3
0
void sipXtapiTestSuite::tearDown()
{
    printf("sipXtapiTestSuite::tearDown line: %d\n", __LINE__);
#ifdef _WIN32
#ifdef SIPX_TEST_FOR_MEMORY_LEAKS
    static bool bFirstRun = true ;
#endif
#endif
    SIPX_RESULT rc ;

    suiteLock.acquire();
    
#ifdef PURIFY
    Sleep(250000);
    PurifyNewLeaks();
#endif
        
    if (g_hInst != NULL)
    {
        rc = sipxUnInitialize(g_hInst);
        if (rc != SIPX_RESULT_SUCCESS)
        {
            printf("\nERROR: sipxTapiTest -- Forcing shutdown of g_hInst (0x%08X)\n", g_hInst) ;
            rc = sipxUnInitialize(g_hInst, true);
        }        
        g_hInst = NULL;
    }

    if (g_hInst2 != NULL)
    {
        rc = sipxUnInitialize(g_hInst2);
        if (rc != SIPX_RESULT_SUCCESS)
        {
            printf("\nERROR: sipxTapiTest -- Forcing shutdown of g_hInst2 (0x%08X)\n", g_hInst2) ;
            rc = sipxUnInitialize(g_hInst2, true);
        }        
        g_hInst2 = NULL;
    }

    if (g_hInst3 != NULL)
    {
        rc = sipxUnInitialize(g_hInst3);
        if (rc != SIPX_RESULT_SUCCESS)
        {
            printf("\nERROR: sipxTapiTest -- Forcing shutdown of g_hInst3 (0x%08X)\n", g_hInst3) ;
            rc = sipxUnInitialize(g_hInst3, true);
        }        
        g_hInst3 = NULL;
    }

    if (g_hInst4 != NULL)
    {
        rc = sipxUnInitialize(g_hInst4);
        if (rc != SIPX_RESULT_SUCCESS)
        {
            printf("\nERROR: sipxTapiTest -- Forcing shutdown of g_hInst4 (0x%08X)\n", g_hInst4) ;
            rc = sipxUnInitialize(g_hInst4, true);
        }                
        g_hInst4 = NULL;
    }

    if (g_hInst5 != NULL)
    {
        rc = sipxUnInitialize(g_hInst5);
        if (rc != SIPX_RESULT_SUCCESS)
        {
            printf("\nERROR: sipxTapiTest -- Forcing shutdown of g_hInst5 (0x%08X)\n", g_hInst5) ;
            rc = sipxUnInitialize(g_hInst5, true);
        }                        
        g_hInst5 = NULL;
    }

    sipxFlushHandles() ;

    suiteLock.release();



#ifdef _WIN32
#ifdef SIPX_TEST_FOR_MEMORY_LEAKS
    if (bFirstRun == false)
    {   
        _CrtMemCheckpoint( &msAfterTest );
        _CrtMemState diff ;

        if (_CrtMemDifference( &diff, &msBeforeTest, &msAfterTest))
        {
            _CrtMemDumpStatistics( &diff );
            _CrtMemDumpAllObjectsSince(&msBeforeTest) ;
        }        
    }
    else
    {
        bFirstRun = false ;
    }
#endif
#endif
    printf("sipXtapiTestSuite::tearDown line: %d\n", __LINE__);
}
示例#4
0
int local_main(int argc, char* argv[])
{
    bool bError = true ;
    int iDuration, iSipPort, iRtpPort ;
    char* szBindAddr;
    bool bLoopback ;
    char* szIdentity ;
    char* szUsername ;
    char* szPassword ;
    char* szRealm ;
    char* szStunServer ;
    char* szProxy ;
    SIPX_INST hInst ;
    SIPX_LINE hLine ;

    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, &szBindAddr,
                  &g_szPlayTones, &g_szFile, &bLoopback, &gbOneCallMode,
                  &szIdentity, &szUsername, &szPassword, &szRealm, &szStunServer,
                  &szProxy) &&
        (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort)))
    {
        if (bLoopback)
        {
            initLoopback() ;
        }

        // Initialize sipX TAPI-like API
        sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ;
        sipxConfigSetLogFile("ReceiveCall.log");
        if (sipxInitialize(&hInst, iSipPort, iSipPort, 5061, iRtpPort, 16, szIdentity, szBindAddr) == SIPX_RESULT_SUCCESS)
        {            
            g_hInst = hInst;
            if (szProxy)
            {
                sipxConfigSetOutboundProxy(hInst, szProxy);
            }
            sipxConfigEnableRport(hInst, true) ;
            if (szStunServer)
            {
                sipxConfigEnableStun(hInst, szStunServer, DEFAULT_STUN_PORT, 28) ;
            }
            sipxEventListenerAdd(hInst, EventCallBack, NULL) ;
                
#if defined(_WIN32) && defined(VIDEO)
            if (bVideo)
            {
                gPreviewDisplay.type = SIPX_WINDOW_HANDLE_TYPE;
                gPreviewDisplay.handle = ghPreview;
                sipxConfigSetVideoPreviewDisplay(hInst, &gPreviewDisplay);
            }
#endif

            // get first contact
            size_t numAddresses = 0;
            SIPX_CONTACT_ADDRESS address;
            sipxConfigGetLocalContacts(hInst, 
                                    &address,
                                    1,
                                    numAddresses);

            if (bUseCustomTransportReliable)
            {
                sipxConfigExternalTransportAdd(hInst,
                                            ghTransport,
                                            true,
                                            "tribble",
                                            address.cIpAddress,
                                            -1,                                            
                                            tribbleProc,
                                            "tribble");
                startTribbleListener(address.cIpAddress);
            }
            
            if (bUseCustomTransportUnreliable)
            {
                startFlibbleListener(address.cIpAddress);
                sipxConfigExternalTransportAdd(hInst,
                                            ghTransport,
                                            false,
                                            "flibble",
                                            address.cIpAddress,
                                            -1,                                            
                                            flibbleProc,
                                            address.cIpAddress);
                                                       
                gContactId = lookupContactId(address.cIpAddress, "flibble", ghTransport);
            }

            hLine = lineInit(hInst, szIdentity, szUsername, szPassword, szRealm) ;

            dumpLocalContacts(hInst) ;

            while (!gbShutdown)
            {
                SLEEP(200) ;
            }

            sipxUnInitialize(hInst, true);
        }
        else
        {
            printf("unable to initialize sipXtapi layer\n") ;
        }
    }
    else
    {
        usage(argv[0]) ;
    }

#if defined(_WIN32) && defined(VIDEO)
    PostMessage(hMain, WM_CLOSE, 0, 0L);
#endif
    return (int) bError ;
}