예제 #1
0
int local_main(int argc, char* argv[])
{
    bool bError = true ;
    int iDuration, iSipPort, iRtpPort ;
    char* szIdentity ;
    char* szUsername ;
    char* szPassword ;
    char* szRealm ;
    char* szStunServer ;
    char* szProxy ;
    SIPX_INST hInst ;
    SIPX_LINE hLine ;


    // Parse Arguments
    if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &g_szPlayTones,
        &g_szFile, &szIdentity, &szUsername, &szPassword, &szRealm, &szStunServer, &szProxy) &&
        (iDuration > 0) && (portIsValid(iSipPort)) && (portIsValid(iRtpPort)))
    {
        // Initialize sipX TAPI-like API
        sipxConfigSetLogLevel(LOG_LEVEL_DEBUG) ;
        sipxConfigSetLogFile("ReceiveCall.log");
        if (sipxInitialize(&hInst, iSipPort, iSipPort, 5061, iRtpPort, 16, szIdentity) == SIPX_RESULT_SUCCESS)
        {            
            g_hInst1 = hInst;
            if (szProxy)
            {
                sipxConfigSetOutboundProxy(hInst, szProxy);
            }
            sipxConfigEnableRport(hInst, true) ;
            if (szStunServer)
            {
                sipxConfigEnableStun(hInst, szStunServer, DEFAULT_STUN_PORT, 28) ;
            }
            sipxEventListenerAdd(hInst, EventCallBack, NULL) ;
            if (sipxConfigSelectAudioCodecByName(g_hInst1, "PCMU PCMA") == SIPX_RESULT_FAILURE)
            {
               printf("!! Setting audio codecs to PCMU PCMA failed !!\n");
            };
                
#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);

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

            dumpLocalContacts(hInst) ;

            while (true)
            {
                SLEEP(1000) ;
            }
        }
        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 ;
}
예제 #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
int main(int argc, char* argv[])
{
    bool bError = true ;
    int iSipPort, iRtpPort ;
    bool bLoopback ;
    char* szIdentity ;
    char* szUsername ;
    char* szPassword ;
    char* szRealm ;
    char* szStunServer ;
    char* szProxy ;
    bool bDialogEvents ;
    // The default run time is 2^31-1 seconds, which is over 68 years.
    long int runTime = LONG_MAX;
    SIPX_INST hInst ;
    SIPX_LINE hLine ;
    // Support for the dialog event notifier.
    // Component for holding the subscription data
    SipSubscriptionMgr* pSubscriptionMgr;
    // Component for granting the subscription rights
    SipSubscribeServerEventHandler* pPolicyHolder;
    // Component for publishing the event contents
    SipPublishContentMgr* pPublisher;
    SipSubscribeServer* pSubscribeServer;
    // The dialog event publisher
    DialogEventPublisher* pDialogEvents;

    // Parse Arguments
    if (parseArgs(argc, argv, &iDuration, &iSipPort, &iRtpPort, &g_szPlayTones,
                  &g_szFile, &bLoopback, &szIdentity, &szUsername, &szPassword,
                  &szRealm, &szStunServer, &szProxy, &bDialogEvents,
                  &g_callAnswerDelay, &g_timestamp, &runTime) &&
        (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) == SIPX_RESULT_SUCCESS)
        {
           // Start dialog event notifier if requested.
           if (bDialogEvents)
           {
              // Get pointer to the call manager.
              CallManager* pCallManager =
                 ((SIPX_INSTANCE_DATA*) hInst)->pCallManager;
              SipUserAgent* pUserAgent =
                 ((SIPX_INSTANCE_DATA*) hInst)->pSipUserAgent;

              // Start the SIP Subscribe Server
              pSubscriptionMgr = new SipSubscriptionMgr();
              pPolicyHolder = new SipSubscribeServerEventHandler;
              pPublisher = new SipPublishContentMgr;
              pSubscribeServer = new SipSubscribeServer(*pUserAgent,
                                                        *pPublisher,
                                                        *pSubscriptionMgr,
                                                        *pPolicyHolder);
              pSubscribeServer->enableEventType(DIALOG_EVENT_TYPE,
                                                NULL,
                                                NULL,
                                                NULL,
                                                NULL,
                                                SipSubscribeServer::standardVersionCallback);
              pSubscribeServer->start();

              // Create the dialog event publisher
              pDialogEvents = new DialogEventPublisher(pCallManager,
                                                       pPublisher);
              pCallManager->addTaoListener(pDialogEvents);
              pDialogEvents->start();
           }

            if (szProxy)
            {
                sipxConfigSetOutboundProxy(hInst, szProxy);
            }
            sipxConfigEnableRport(hInst, true) ;
            if (szStunServer)
            {
                sipxConfigEnableStun(hInst, szStunServer, 28) ;
            }
            sipxEventListenerAdd(hInst, EventCallBack, NULL) ;
            hLine = lineInit(hInst, szIdentity, szUsername, szPassword, szRealm) ;

            dumpLocalContacts(hInst) ;

            // Run as long as requested.
            for (long int i = 0; i < runTime; i++)
            {
                SLEEP(1000) ;
            }

            lineShutdown(hInst, hLine);
            // Wait a bit, so that we can re-send the REGISTER if it needs
            // authorization.
            SLEEP(5000);
        }
        else
        {
            printf("unable to initialize sipXtapi layer\n") ;
        }
    }
    else
    {
        usage(argv[0]) ;
    }

    return (int) bError ;
}
예제 #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 ;
}