~ubuntu-branches/ubuntu/saucy/sflphone/saucy

« back to all changes in this revision

Viewing changes to sflphone-common/src/iax/iaxvoiplink.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Francois Marier
  • Date: 2010-12-24 16:33:55 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20101224163355-tkvvikqxbrbav6up
Tags: 0.9.11-1
* New upstream release
* Add new build dependencies on libwebkit-dev and libyaml-dev

* Bump Standards-Version up to 3.9.1
* Bump debhelper compatibility to 8
* Patch another typo in the upstream code (lintian notice)

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
#define CHK_VALID_CALL   if (call == NULL) { _debug("IAX: Call doesn't exists"); \
52
52
        return false; }
53
53
 
54
 
IAXVoIPLink::IAXVoIPLink (const AccountID& accountID)
55
 
        : VoIPLink (accountID)
 
54
IAXVoIPLink::IAXVoIPLink (const AccountID& accountID) : VoIPLink (accountID)
 
55
    , _evThread (NULL)
 
56
    , _regSession (NULL)
 
57
    , _nextRefreshStamp (0)
 
58
    , audiolayer (NULL)
 
59
    , micData (NULL)
 
60
    , micDataConverted (NULL)
 
61
    , micDataEncoded (NULL)
 
62
    , spkrDataDecoded (NULL)
 
63
    , spkrDataConverted (NULL)
 
64
    , converter (NULL)
 
65
    , converterSamplingRate (NULL)
 
66
    , urlhook (NULL)
 
67
    , countTime (0)
56
68
{
57
 
    // _debug("IAXVoIPLink::IAXVoIPLink : creating eventhread  ");
58
69
    _evThread = new EventThread (this);
59
 
    _regSession = NULL;
60
 
    _nextRefreshStamp = 0;
61
 
    countTime = 0;
62
70
 
63
71
    // to get random number for RANDOM_PORT
64
72
    srand (time (NULL));
65
73
 
66
 
    audiolayer = NULL;
67
 
 
68
74
    converter = new SamplerateConverter();
69
75
 
70
76
    int nbSamplesMax = (int) (converter->getFrequence() * converter->getFramesize() / 1000);
82
88
 
83
89
IAXVoIPLink::~IAXVoIPLink()
84
90
{
85
 
    delete _evThread;
86
 
    _evThread = NULL;
 
91
    if (_evThread) {
 
92
        delete _evThread;
 
93
        _evThread = NULL;
 
94
    }
 
95
 
87
96
    _regSession = NULL; // shall not delete it
88
97
    terminate();
89
98
 
90
99
    audiolayer = NULL;
91
100
 
92
 
    delete converter;
93
 
 
94
 
    delete [] micData;
95
 
    micData = NULL;
96
 
    delete [] micDataConverted;
97
 
    micDataConverted = NULL;
98
 
    delete [] micDataEncoded;
99
 
    micDataEncoded = NULL;
100
 
 
101
 
    delete [] spkrDataDecoded;
102
 
    spkrDataDecoded = NULL;
103
 
    delete [] spkrDataConverted;
104
 
    spkrDataConverted = NULL;
 
101
    if (converter) {
 
102
        delete converter;
 
103
        converter = NULL;
 
104
    }
 
105
 
 
106
    if (micData) {
 
107
        delete [] micData;
 
108
        micData = NULL;
 
109
    }
 
110
 
 
111
    if (micDataConverted) {
 
112
        delete [] micDataConverted;
 
113
        micDataConverted = NULL;
 
114
    }
 
115
 
 
116
    if (micDataEncoded) {
 
117
        delete [] micDataEncoded;
 
118
        micDataEncoded = NULL;
 
119
    }
 
120
 
 
121
    if (spkrDataDecoded) {
 
122
        delete [] spkrDataDecoded;
 
123
        spkrDataDecoded = NULL;
 
124
    }
 
125
 
 
126
    if (spkrDataConverted) {
 
127
        delete [] spkrDataConverted;
 
128
        spkrDataConverted = NULL;
 
129
    }
 
130
 
105
131
}
106
132
 
107
133
bool
219
245
{
220
246
    IAXCall* call = NULL;
221
247
 
 
248
    Manager::instance().getAudioLayerMutex()->enter();
 
249
 
222
250
    // lock iax_ stuff..
223
251
    _mutexIAX.enterMutex();
224
252
    iax_event* event = NULL;
254
282
 
255
283
    sendAudioFromMic();
256
284
 
257
 
    if (call) {
258
 
        call->recAudio.recData (spkrDataDecoded, micData, nbSampleForRec_, nbSampleForRec_);
259
 
 
260
 
        // Do the doodle-moodle to send audio from the microphone to the IAX channel.
261
 
    }
 
285
    Manager::instance().getAudioLayerMutex()->leave();
262
286
 
263
287
    // Do the doodle-moodle to send audio from the microphone to the IAX channel.
264
288
    // sendAudioFromMic();
408
432
 
409
433
 
410
434
int
411
 
IAXVoIPLink::sendRegister (AccountID id)
 
435
IAXVoIPLink::sendRegister (AccountID id UNUSED)
412
436
{
413
437
    IAXAccount *account;
414
438
    bool result;
415
439
 
 
440
    _debug ("IAX: Sending registration");
 
441
 
416
442
    result = false;
417
443
    account = dynamic_cast<IAXAccount *> (getAccountPtr());
418
444
 
419
445
    if (account->getHostname().empty()) {
 
446
        _error ("IAX: Error: Account hostname is empty");
420
447
        return false;
421
448
    }
422
449
 
423
450
    if (account->getUsername().empty()) {
 
451
        _error ("IAX: Error: Account username is empty");
424
452
        return false;
425
453
    }
426
454
 
435
463
    _regSession = iax_session_new();
436
464
 
437
465
    if (!_regSession) {
438
 
        _debug ("Error when generating new session for register");
 
466
        _debug ("IAX: Error when generating new session for register");
439
467
    } else {
440
 
        _debug ("IAX Sending registration to %s with user %s", account->getHostname().c_str() , account->getUsername().c_str());
 
468
        _debug ("IAX: Sending registration to %s with user %s", account->getHostname().c_str() , account->getUsername().c_str());
441
469
        int val = iax_register (_regSession, account->getHostname().data(), account->getUsername().data(), account->getPassword().data(), 120);
442
 
        _debug ("Return value: %d", val);
 
470
        _debug ("IAX: Return value: %d", val);
443
471
        // set the time-out to 15 seconds, after that, resend a registration request.
444
472
        // until we unregister.
445
473
        _nextRefreshStamp = time (NULL) + 10;
455
483
}
456
484
 
457
485
int
458
 
IAXVoIPLink::sendUnregister (AccountID id)
 
486
IAXVoIPLink::sendUnregister (AccountID id UNUSED)
459
487
{
460
488
    IAXAccount *account;
461
489
 
491
519
 
492
520
    if (call) {
493
521
        call->setPeerNumber (toUrl);
494
 
        call->initRecFileName();
 
522
        call->initRecFileName (toUrl);
495
523
 
496
524
        if (iaxOutgoingInvite (call)) {
497
525
            call->setConnectionState (Call::Progressing);
533
561
bool
534
562
IAXVoIPLink::hangup (const CallID& id)
535
563
{
536
 
    _debug ("IAXVoIPLink::hangup() : function called once hangup ");
 
564
    _debug ("IAXVoIPLink: Hangup");
537
565
    IAXCall* call = getIAXCall (id);
538
566
    std::string reason = "Dumped Call";
539
567
    CHK_VALID_CALL;
561
589
bool
562
590
IAXVoIPLink::peerHungup (const CallID& id)
563
591
{
564
 
    _debug ("IAXVoIPLink::peerHangup() : function called once hangup ");
 
592
    _debug ("IAXVoIPLink: Peer hung up");
565
593
    IAXCall* call = getIAXCall (id);
566
594
    std::string reason = "Dumped Call";
567
595
    CHK_VALID_CALL;
677
705
    return true;
678
706
}
679
707
 
 
708
bool
 
709
IAXVoIPLink::sendTextMessage (sfl::InstantMessaging *module, const std::string& callID, const std::string& message, const std::string& from)
 
710
{
 
711
    IAXCall* call = getIAXCall (callID);
 
712
 
 
713
    CHK_VALID_CALL;
 
714
 
 
715
    // Must active the mutex for this session
 
716
    _mutexIAX.enterMutex();
 
717
 
 
718
    module->send_iax_message (call->getSession(), callID, message.c_str());
 
719
 
 
720
    // iax_send_text (call->getSession(), message.c_str());
 
721
    _mutexIAX.leaveMutex();
 
722
 
 
723
    return true;
 
724
}
 
725
 
680
726
 
681
727
std::string
682
728
IAXVoIPLink::getCurrentCodecName()
866
912
            break;
867
913
 
868
914
        case IAX_EVENT_TEXT:
 
915
            Manager::instance ().incomingMessage (call->getCallId (), call->getPeerNumber(), std::string ( (const char*) event->data));
869
916
            break;
870
917
 
871
918
        case IAX_EVENT_RINGA:
894
941
            break;
895
942
 
896
943
        case IAX_EVENT_TRANSFER:
 
944
            _debug ("IAX_EVENT_TRANSFER");
 
945
 
 
946
            if (call->getConnectionState() != Call::Connected) {
 
947
 
 
948
                Manager::instance().addStream (call->getCallId());
 
949
 
 
950
                call->setConnectionState (Call::Connected);
 
951
                call->setState (Call::Active);
 
952
                // audiolayer->startStream();
 
953
 
 
954
                _debug ("IAX_EVENT_ANSWER: codec format: ");
 
955
 
 
956
                if (event->ies.format) {
 
957
                    // Should not get here, should have been set in EVENT_ACCEPT
 
958
                    printf ("%i", event->ies.format);
 
959
                    call->setFormat (event->ies.format);
 
960
                }
 
961
 
 
962
                {
 
963
                    printf ("no codec format");
 
964
                }
 
965
 
 
966
                Manager::instance().peerAnsweredCall (id);
 
967
 
 
968
                // start audio here?
 
969
                audiolayer->startStream();
 
970
                audiolayer->flushMain();
 
971
            } else {
 
972
                // deja connecté ?
 
973
            }
 
974
 
897
975
            break;
898
976
 
899
977
        default:
1113
1191
                call->setPeerName (std::string (event->ies.calling_name));
1114
1192
 
1115
1193
            // if peerNumber exist append it to the name string
1116
 
            call->initRecFileName();
 
1194
            call->initRecFileName (std::string (event->ies.calling_number));
1117
1195
 
1118
1196
            if (Manager::instance().incomingCall (call, getAccountID())) {
1119
1197
                /** @todo Faudra considérer éventuellement le champ CODEC PREFS pour