00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 #ifndef CALLPROCESSOR_H
00098 #define CALLPROCESSOR_H
00099
00100 #ifndef _PTLIB_H
00101 #include <ptlib.h>
00102 #endif
00103
00104 #include <opal/connection.h>
00105
00106 #include <iax2/processor.h>
00107 #include <iax2/frame.h>
00108 #include <iax2/iedata.h>
00109 #include <iax2/remote.h>
00110 #include <iax2/safestrings.h>
00111 #include <iax2/sound.h>
00112
00113 class IAX2Connection;
00114
00118 class IAX2CallProcessor : public IAX2Processor
00119 {
00120 PCLASSINFO(IAX2CallProcessor, IAX2Processor);
00121
00122 public:
00123
00125 IAX2CallProcessor(IAX2EndPoint & ep);
00126
00128 virtual ~IAX2CallProcessor();
00129
00131 void AssignConnection(IAX2Connection * _con);
00132
00135 void PutSoundPacketToNetwork(PBYTEArray *sund);
00136
00138 IAX2Encryption & GetEncryptionInfo() { return encryption; }
00139
00141 virtual void Release(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
00142
00144 void ClearCall(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
00145
00150 virtual void OnReleased();
00151
00155 void SendDtmf(const PString & dtmfs);
00156
00160 void SendText(const PString & text);
00161
00168 virtual PBoolean SetUpConnection();
00169
00172 PBoolean Matches(IAX2Frame *frame) { return remote == (frame->GetRemoteInfo()); }
00173
00176 virtual void PrintOn(ostream & strm) const;
00177
00180 void ReportStatistics();
00181
00183 PBoolean MatchingLocalCallNumber(PINDEX compare) { return (compare == remote.SourceCallNumber()); }
00184
00186 unsigned short GetSelectedCodec() { return (unsigned short) selectedCodec; }
00187
00192 void AcceptIncomingCall();
00193
00204 virtual PBoolean SetAlerting(
00205 const PString & calleeName,
00206 PBoolean withMedia
00207 ) ;
00208
00212 void Hangup(PString messageToSend);
00213
00216 PBoolean IsCallTerminating() { return callStatus & callTerminating; }
00217
00219 void SendHold();
00220
00222 void SendHoldRelease();
00223
00230 void SetUserName(PString & inUserName) { userName = inUserName; };
00231
00233 PString GetUserName() const;
00234
00241 void SetPassword(PString & inPassword) { password = inPassword; };
00242
00244 PString GetPassword() const { return password; };
00245
00248 void SendTransfer(
00249 const PString & calledNumber,
00250 const PString & calledContext = PString::Empty());
00251
00254 void StartStatusCheckTimer(PINDEX msToWait = 10000 );
00256
00263 virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff);
00264
00268 void SendAnswerMessageToRemoteNode();
00269
00270 protected:
00271
00273 IAX2Connection * con;
00274
00279 PBoolean RemoteSelectedCodecOk();
00280
00284 void CheckForHangupMessages();
00285
00287 void ProcessNetworkFrame(IAX2Frame * src);
00288
00291 void ProcessNetworkFrame(IAX2MiniFrame * src);
00292
00295 void ProcessNetworkFrame(IAX2FullFrame * src);
00296
00299 void ProcessNetworkFrame(IAX2FullFrameDtmf * src);
00300
00303 void ProcessNetworkFrame(IAX2FullFrameVoice * src);
00304
00307 void ProcessNetworkFrame(IAX2FullFrameVideo * src);
00308
00311 void ProcessNetworkFrame(IAX2FullFrameSessionControl * src);
00312
00315 void ProcessNetworkFrame(IAX2FullFrameNull * src);
00316
00322 virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
00323
00326 void ProcessNetworkFrame(IAX2FullFrameText * src);
00327
00330 void ProcessNetworkFrame(IAX2FullFrameImage * src);
00331
00334 void ProcessNetworkFrame(IAX2FullFrameHtml * src);
00335
00338 void ProcessNetworkFrame(IAX2FullFrameCng * src);
00339
00342 virtual void ProcessLists();
00343
00345 void ConnectToRemoteNode(PString & destination);
00346
00348 void SendDtmfMessage(char message);
00349
00351 void SendTextMessage(PString & message);
00352
00355 void SendSoundMessage(PBYTEArray *sound);
00356
00358 void SendTransferMessage();
00359
00361 void SendQuelchMessage();
00362
00364 void SendUnQuelchMessage();
00365
00367 void IncAudioFramesSent() { ++audioFramesSent; }
00368
00370 void IncAudioFramesRcvd() { ++audioFramesRcvd; }
00371
00373 void IncVideoFramesSent() { ++videoFramesSent; }
00374
00376 void IncVideoFramesRcvd() { ++videoFramesRcvd; }
00377
00380 void RemoteNodeHasAnswered();
00381
00385 void CallStopSounds();
00386
00389 void ReceivedHookFlash();
00390
00393 void RemoteNodeIsBusy();
00394
00397 void ProcessIncomingAudioFrame(IAX2Frame *newFrame);
00398
00401 void ProcessIncomingVideoFrame(IAX2Frame *newFrame);
00402
00405 void ProcessIaxCmdNew(IAX2FullFrameProtocol *src);
00406
00409 void ProcessIaxCmdAck(IAX2FullFrameProtocol *src);
00410
00413 void ProcessIaxCmdHangup(IAX2FullFrameProtocol *src);
00414
00417 void ProcessIaxCmdReject(IAX2FullFrameProtocol *src);
00418
00421 void ProcessIaxCmdAccept(IAX2FullFrameProtocol *src);
00422
00425 void ProcessIaxCmdAuthReq(IAX2FullFrameProtocol *src);
00426
00429 void ProcessIaxCmdAuthRep(IAX2FullFrameProtocol *src);
00430
00433 void ProcessIaxCmdInval(IAX2FullFrameProtocol *src);
00434
00437 void ProcessIaxCmdDpReq(IAX2FullFrameProtocol *src);
00438
00441 void ProcessIaxCmdDpRep(IAX2FullFrameProtocol *src);
00442
00445 void ProcessIaxCmdDial(IAX2FullFrameProtocol *src);
00446
00449 void ProcessIaxCmdTxreq(IAX2FullFrameProtocol *src);
00450
00453 void ProcessIaxCmdTxcnt(IAX2FullFrameProtocol *src);
00454
00457 void ProcessIaxCmdTxacc(IAX2FullFrameProtocol *src);
00458
00461 void ProcessIaxCmdTxready(IAX2FullFrameProtocol *src);
00462
00465 void ProcessIaxCmdTxrel(IAX2FullFrameProtocol *src);
00466
00469 void ProcessIaxCmdTxrej(IAX2FullFrameProtocol *src);
00470
00473 void ProcessIaxCmdQuelch(IAX2FullFrameProtocol *src);
00474
00477 void ProcessIaxCmdUnquelch(IAX2FullFrameProtocol *src);
00478
00481 void ProcessIaxCmdPage(IAX2FullFrameProtocol *src);
00482
00485 void ProcessIaxCmdMwi(IAX2FullFrameProtocol *src);
00486
00489 void ProcessIaxCmdUnsupport(IAX2FullFrameProtocol *src);
00490
00493 void ProcessIaxCmdTransfer(IAX2FullFrameProtocol *src);
00494
00497 void ProcessIaxCmdProvision(IAX2FullFrameProtocol *src);
00498
00501 void ProcessIaxCmdFwDownl(IAX2FullFrameProtocol *src);
00502
00505 void ProcessIaxCmdFwData(IAX2FullFrameProtocol *src);
00506
00508 PAtomicInteger audioFramesSent;
00509
00511 PAtomicInteger audioFramesRcvd;
00512
00514 PAtomicInteger videoFramesSent;
00515
00517 PAtomicInteger videoFramesRcvd;
00518
00520 SafeString remotePhoneNumber;
00521
00523 SafeStrings callList;
00524
00528 SafeString dtmfText;
00529
00532 SafeStrings textList;
00533
00535 SafeStrings dtmfNetworkList;
00536
00538 SafeStrings hangList;
00539
00541 PBoolean holdCall;
00542
00544 PBoolean holdReleaseCall;
00545
00548 IAX2SoundList soundWaitingForTransmission;
00549
00555 enum SoundBufferState {
00556 BufferToSmall,
00557 Normal,
00558 BufferToBig
00559 };
00560
00562 SoundBufferState soundBufferState;
00563
00566 PINDEX lastFullFrameTimeStamp;
00567
00569 PBoolean audioCanFlow;
00570
00573 unsigned int selectedCodec;
00574
00576 enum CallStatus {
00577 callNewed = 1 << 0,
00578 callSentRinging = 1 << 1,
00579 callRegistered = 1 << 2,
00580 callAuthorised = 1 << 3,
00581 callAccepted = 1 << 4,
00582 callRinging = 1 << 5,
00583 callAnswered = 1 << 6,
00584 callTerminating = 1 << 7
00585 };
00586
00588 unsigned short callStatus;
00589
00591 void SetCallSentRinging(PBoolean newValue = PTrue)
00592 { if (newValue) callStatus |= callSentRinging; else callStatus &= ~callSentRinging; }
00593
00595 void SetCallNewed(PBoolean newValue = PTrue)
00596 { if (newValue) callStatus |= callNewed; else callStatus &= ~callNewed; }
00597
00599 void SetCallRegistered(PBoolean newValue = PTrue)
00600 { if (newValue) callStatus |= callRegistered; else callStatus &= ~callRegistered; }
00601
00603 void SetCallAuthorised(PBoolean newValue = PTrue)
00604 { if (newValue) callStatus |= callAuthorised; else callStatus &= ~callAuthorised; }
00605
00607 void SetCallAccepted(PBoolean newValue = PTrue)
00608 { if (newValue) callStatus |= callAccepted; else callStatus &= ~callAccepted; }
00609
00611 void SetCallRinging(PBoolean newValue = PTrue)
00612 { if (newValue) callStatus |= callRinging; else callStatus &= ~callRinging; }
00613
00615 void SetCallAnswered(PBoolean newValue = PTrue)
00616 { if (newValue) callStatus |= callAnswered; else callStatus &= ~callAnswered; }
00617
00619 void SetCallTerminating(PBoolean newValue = PTrue)
00620 { if (newValue) callStatus |= callTerminating; else callStatus &= ~callTerminating; }
00621
00623 PBoolean IsCallHappening() { return callStatus > 0; }
00624
00627 PBoolean IsCallNewed() { return callStatus & callNewed; }
00628
00631 PBoolean IsCallSentRinging() { return callStatus & callSentRinging; }
00632
00634 PBoolean IsCallRegistered() { return callStatus & callRegistered; }
00635
00637 PBoolean IsCallAuthorised() { return callStatus & callAuthorised; }
00638
00640 PBoolean IsCallAccepted() { return callStatus & callAccepted; }
00641
00643 PBoolean IsCallRinging() { return callStatus & callRinging; }
00644
00646 PBoolean IsCallAnswered() { return callStatus & callAnswered; }
00647
00648 #ifdef DOC_PLUS_PLUS
00649
00655 void OnStatusCheck(PTimer &, INT);
00656 #else
00657 PDECLARE_NOTIFIER(PTimer, IAX2CallProcessor, OnStatusCheck);
00658 #endif
00659
00661 void DoStatusCheck();
00662
00665 void RemoteNodeIsRinging();
00666
00670 void RingingWasAcked();
00671
00676 void AnswerWasAcked();
00677
00681 PBoolean firstMediaFrame;
00682
00685 PBoolean answerCallNow;
00686
00691 PBoolean statusCheckOtherEnd;
00692
00694 PTimer statusCheckTimer;
00695
00698 PINDEX audioFrameDuration;
00699
00701 PINDEX audioCompressedBytes;
00702
00706 PBoolean audioFramesNotStarted;
00707
00710 void CheckForRemoteCapabilities(IAX2FullFrameProtocol *src);
00711
00714 virtual void OnNoResponseTimeout();
00715
00717 virtual void ProcessFullFrame(IAX2FullFrame & fullFrame);
00718
00722 PString userName;
00723
00727 PString password;
00728
00730 PMutex transferMutex;
00731
00733 PBoolean doTransfer;
00734
00736 PString transferCalledNumber;
00737
00739 PString transferCalledContext;
00740 };
00741
00743
00744
00745
00746
00747
00748
00749
00750
00751
00752
00753
00754
00755 #endif // CALLPROCESSOR_H