OPAL  Version 3.10.10
callprocessor.h
Go to the documentation of this file.
1 /*
2  *
3  * Inter Asterisk Exchange 2
4  *
5  * The core routine which determines the processing of packets for one call.
6  *
7  * Open Phone Abstraction Library (OPAL)
8  *
9  * Copyright (c) 2005 Indranet Technologies Ltd.
10  *
11  * The contents of this file are subject to the Mozilla Public License
12  * Version 1.0 (the "License"); you may not use this file except in
13  * compliance with the License. You may obtain a copy of the License at
14  * http://www.mozilla.org/MPL/
15  *
16  * Software distributed under the License is distributed on an "AS IS"
17  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
18  * the License for the specific language governing rights and limitations
19  * under the License.
20  *
21  * The Original Code is Open Phone Abstraction Library.
22  *
23  * The Initial Developer of the Original Code is Indranet Technologies Ltd.
24  *
25  * The author of this code is Derek J Smithies
26  *
27  * $Revision: 27078 $
28  * $Author: rjongbloed $
29  * $Date: 2012-02-29 22:40:38 -0600 (Wed, 29 Feb 2012) $
30  */
31 
32 #ifndef OPAL_IAX2_CALLPROCESSOR_H
33 #define OPAL_IAX2_CALLPROCESSOR_H
34 
35 #ifndef _PTLIB_H
36 #include <ptlib.h>
37 #endif
38 
39 #include <opal/buildopts.h>
40 
41 #if OPAL_IAX2
42 
43 #include <opal/connection.h>
44 
45 #include <iax2/processor.h>
46 #include <iax2/frame.h>
47 #include <iax2/iedata.h>
48 #include <iax2/remote.h>
49 #include <iax2/safestrings.h>
50 #include <iax2/sound.h>
51 
52 class IAX2Connection;
53 
58 {
59  PCLASSINFO(IAX2CallProcessor, IAX2Processor);
60 
61  public:
62 
65 
67  virtual ~IAX2CallProcessor();
68 
70  void AssignConnection(IAX2Connection * _con);
71 
74  void PutSoundPacketToNetwork(PBYTEArray *sund);
75 
78 
81 
86  virtual void OnReleased();
87 
91  void SendDtmf(const PString & dtmfs);
92 
96  void SendText(const PString & text);
97 
104  virtual PBoolean SetUpConnection();
105 
108  PBoolean Matches(IAX2Frame *frame) { return remote == (frame->GetRemoteInfo()); }
109 
112  virtual void PrintOn(ostream & strm) const;
113 
116  void ReportStatistics();
117 
119  PBoolean MatchingLocalCallNumber(PINDEX compare) { return (compare == remote.SourceCallNumber()); }
120 
122  unsigned short GetSelectedCodec() { return (unsigned short) selectedCodec; }
123 
128  void AcceptIncomingCall();
129 
140  virtual PBoolean SetAlerting(
141  const PString & calleeName,
142  PBoolean withMedia
143  ) ;
144 
148  void Hangup(PString messageToSend);
149 
153 
155  void SendHold();
156 
158  void SendHoldRelease();
159 
166  void SetUserName(PString & inUserName) { userName = inUserName; };
167 
169  PString GetUserName() const;
170 
173  PString GetCallingName() const { return callingName; }
174 
181  void SetPassword(PString & inPassword) { password = inPassword; };
182 
184  PString GetPassword() const { return password; };
185 
188  void SendTransfer(
189  const PString & calledNumber,
190  const PString & calledContext = PString::Empty());
191 
194  void StartStatusCheckTimer(PINDEX msToWait = 10000 );
196 
203  virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff);
204 
209 
210  protected:
211 
214 
219  PBoolean RemoteSelectedCodecOk();
220 
224  void CheckForHangupMessages();
225 
227  void ProcessNetworkFrame(IAX2Frame * src);
228 
232 
236 
240 
244 
248 
252 
256 
263  virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
264 
268 
272 
276 
280 
283  virtual void ProcessLists();
284 
286  void ConnectToRemoteNode(PString & destination);
287 
289  void SendDtmfMessage(char message);
290 
292  void SendTextMessage(PString & message);
293 
296  void SendSoundMessage(PBYTEArray *sound);
297 
299  void SendTransferMessage();
300 
302  void SendQuelchMessage();
303 
305  void SendUnQuelchMessage();
306 
309 
312 
315 
318 
321  void RemoteNodeHasAnswered();
322 
326  void CallStopSounds();
327 
330  void ReceivedHookFlash();
331 
334  void RemoteNodeIsBusy();
335 
338  void ProcessIncomingAudioFrame(IAX2Frame *newFrame);
339 
342  void ProcessIncomingVideoFrame(IAX2Frame *newFrame);
343 
347 
351 
355 
359 
363 
367 
371 
375 
379 
383 
387 
391 
395 
399 
403 
407 
411 
415 
419 
423 
427 
431 
435 
439 
443 
447 
455 
462 
464  PAtomicInteger audioFramesSent;
465 
467  PAtomicInteger audioFramesRcvd;
468 
470  PAtomicInteger videoFramesSent;
471 
473  PAtomicInteger videoFramesRcvd;
474 
477 
480 
485 
489 
492 
495 
497  PBoolean holdCall;
498 
500  PBoolean holdReleaseCall;
501 
505 
515  };
516 
519 
523 
525  PBoolean audioCanFlow;
526 
529  unsigned int selectedCodec;
530 
532  enum CallStatus {
533  callNewed = 1 << 0,
534  callSentRinging = 1 << 1,
535  callRegistered = 1 << 2,
536  callAuthorised = 1 << 3,
537  callAccepted = 1 << 4,
538  callRinging = 1 << 5,
539  callAnswered = 1 << 6,
540  callTerminating = 1 << 7
541  };
542 
544  unsigned short callStatus;
545 
547  void SetCallSentRinging(PBoolean newValue = true)
548  { if (newValue) callStatus |= callSentRinging; else callStatus &= ~callSentRinging; }
549 
551  void SetCallNewed(PBoolean newValue = true)
552  { if (newValue) callStatus |= callNewed; else callStatus &= ~callNewed; }
553 
555  void SetCallRegistered(PBoolean newValue = true)
556  { if (newValue) callStatus |= callRegistered; else callStatus &= ~callRegistered; }
557 
559  void SetCallAuthorised(PBoolean newValue = true)
560  { if (newValue) callStatus |= callAuthorised; else callStatus &= ~callAuthorised; }
561 
563  void SetCallAccepted(PBoolean newValue = true)
564  { if (newValue) callStatus |= callAccepted; else callStatus &= ~callAccepted; }
565 
567  void SetCallRinging(PBoolean newValue = true)
568  { if (newValue) callStatus |= callRinging; else callStatus &= ~callRinging; }
569 
571  void SetCallAnswered(PBoolean newValue = true)
572  { if (newValue) callStatus |= callAnswered; else callStatus &= ~callAnswered; }
573 
575  void SetCallTerminating(PBoolean newValue = true)
576  { if (newValue) callStatus |= callTerminating; else callStatus &= ~callTerminating; }
577 
579  PBoolean IsCallHappening() { return callStatus > 0; }
580 
583  PBoolean IsCallNewed() { return callStatus & callNewed; }
584 
587  PBoolean IsCallSentRinging() { return callStatus & callSentRinging; }
588 
590  PBoolean IsCallRegistered() { return callStatus & callRegistered; }
591 
593  PBoolean IsCallAuthorised() { return callStatus & callAuthorised; }
594 
596  PBoolean IsCallAccepted() { return callStatus & callAccepted; }
597 
599  PBoolean IsCallRinging() { return callStatus & callRinging; }
600 
602  PBoolean IsCallAnswered() { return callStatus & callAnswered; }
603 
604 #ifdef DOC_PLUS_PLUS
605 
611  void OnStatusCheck(PTimer &, INT);
612 #else
613  PDECLARE_NOTIFIER(PTimer, IAX2CallProcessor, OnStatusCheck);
614 #endif
615 
617  void DoStatusCheck();
618 
621  void RemoteNodeIsRinging();
622 
626  void RingingWasAcked();
627 
632  void AnswerWasAcked();
633 
637  PBoolean firstMediaFrame;
638 
641  PBoolean answerCallNow;
642 
648 
651 
655 
658 
663 
667 
670  virtual void OnNoResponseTimeout();
671 
673  virtual void ProcessFullFrame(IAX2FullFrame & fullFrame);
674 
677  PString callingName;
678 
682 
684  PString callingDnid;
685 
688  PString callingContext;
689 
693  PString userName;
694 
698  PString password;
699 
702 
704  PBoolean doTransfer;
705 
708 
711 
717 };
718 
720 
721 /* The comment below is magic for those who use emacs to edit this file.
722  * With the comment below, the tab key does auto indent to 2 spaces.
723  *
724  * Local Variables:
725  * mode:c
726  * c-basic-offset:2
727  * End:
728  */
729 
730 
731 #endif // OPAL_IAX2
732 
733 #endif // OPAL_IAX2_CALLPROCESSOR_H
unsigned short GetSelectedCodec()
Definition: callprocessor.h:122
void SendTransfer(const PString &calledNumber, const PString &calledContext=PString::Empty())
void SetPassword(PString &inPassword)
Definition: callprocessor.h:181
PString callingContext
Definition: callprocessor.h:688
void SendSoundMessage(PBYTEArray *sound)
Definition: callprocessor.h:534
PBoolean holdReleaseCall
Definition: callprocessor.h:500
void ProcessIaxCmdFwDownl(IAX2FullFrameProtocol *src)
virtual void ProcessFullFrame(IAX2FullFrame &fullFrame)
PBoolean IsCallAccepted()
Definition: callprocessor.h:596
void ProcessIaxCmdHangup(IAX2FullFrameProtocol *src)
void ProcessIaxCmdTxreq(IAX2FullFrameProtocol *src)
PString transferCalledContext
Definition: callprocessor.h:710
void SendText(const PString &text)
SoundBufferState
Definition: callprocessor.h:511
void ProcessIaxCmdAck(IAX2FullFrameProtocol *src)
Definition: frame.h:851
Definition: frame.h:671
PString transferCalledNumber
Definition: callprocessor.h:707
SafeString remotePhoneNumber
Definition: callprocessor.h:476
Definition: iax2ep.h:104
PAtomicInteger videoFramesRcvd
Definition: callprocessor.h:473
void IncAudioFramesSent()
Definition: callprocessor.h:308
void SetCallNewed(PBoolean newValue=true)
Definition: callprocessor.h:551
void SetCallAnswered(PBoolean newValue=true)
Definition: callprocessor.h:571
Definition: callprocessor.h:538
PBoolean audioCanFlow
Definition: callprocessor.h:525
Definition: callprocessor.h:512
PBoolean holdCall
Definition: callprocessor.h:497
Definition: iax2con.h:63
SafeStrings hangList
Definition: callprocessor.h:494
void SendUnQuelchMessage()
void ReceivedHookFlash()
PBoolean statusCheckOtherEnd
Definition: callprocessor.h:647
IAX2CallProcessor(IAX2EndPoint &ep)
void ProcessIaxCmdUnsupport(IAX2FullFrameProtocol *src)
Definition: callprocessor.h:533
void SendDtmfMessage(char message)
SafeStrings textList
Definition: callprocessor.h:488
Definition: frame.h:369
void RemoteNodeIsRinging()
void OnStatusCheck(PTimer &, INT)
void ProcessIaxCmdAccept(IAX2FullFrameProtocol *src)
void ConnectToRemoteNode(PString &destination)
Definition: safestrings.h:107
void IncVideoFramesSent()
Definition: callprocessor.h:314
Definition: frame.h:307
PString password
Definition: callprocessor.h:698
void SetCallAuthorised(PBoolean newValue=true)
Definition: callprocessor.h:559
void ProcessIaxCmdTxready(IAX2FullFrameProtocol *src)
void Hangup(PString messageToSend)
PBoolean IsCallTerminating()
Definition: callprocessor.h:152
PINDEX audioCompressedBytes
Definition: callprocessor.h:657
IAX2Remote remote
Definition: processor.h:227
PBoolean IsCallRegistered()
Definition: callprocessor.h:590
Definition: frame.h:1111
Definition: callprocessor.h:57
void ProcessIaxCmdAuthRep(IAX2FullFrameProtocol *src)
virtual void OnNoResponseTimeout()
void ProcessIaxCmdUnquelch(IAX2FullFrameProtocol *src)
void ProcessIaxCmdFwData(IAX2FullFrameProtocol *src)
void SendTextMessage(PString &message)
SoundBufferState soundBufferState
Definition: callprocessor.h:518
PBoolean MatchingLocalCallNumber(PINDEX compare)
Definition: callprocessor.h:119
Definition: callprocessor.h:539
PString callingExtension
Definition: callprocessor.h:681
void SetCallTerminating(PBoolean newValue=true)
Definition: callprocessor.h:575
void ProcessIaxCmdDpRep(IAX2FullFrameProtocol *src)
Definition: callprocessor.h:535
void CheckForHangupMessages()
Definition: callprocessor.h:540
PBoolean RemoteSelectedCodecOk()
Definition: callprocessor.h:537
PString userName
Definition: callprocessor.h:693
Definition: frame.h:885
PBoolean doTransfer
Definition: callprocessor.h:704
void ProcessIaxCmdTxrel(IAX2FullFrameProtocol *src)
PAtomicInteger audioFramesSent
Definition: callprocessor.h:464
Definition: safestrings.h:53
void CheckForRemoteCapabilities(IAX2FullFrameProtocol *src)
void SetCallSentRinging(PBoolean newValue=true)
Definition: callprocessor.h:547
Definition: frame.h:1137
IAX2SoundList soundWaitingForTransmission
Definition: callprocessor.h:504
PString GetPassword() const
Definition: callprocessor.h:184
IAX2Connection * con
Definition: callprocessor.h:213
Definition: frame.h:1045
virtual PBoolean SetUpConnection()
void ProcessIaxCmdTxcnt(IAX2FullFrameProtocol *src)
PString callingName
Definition: callprocessor.h:677
void ProcessIaxCmdDial(IAX2FullFrameProtocol *src)
void ProcessIaxCmdNew(IAX2FullFrameProtocol *src)
void ProcessIaxCmdReject(IAX2FullFrameProtocol *src)
PAtomicInteger videoFramesSent
Definition: callprocessor.h:470
Definition: remote.h:345
Everything is functioning ok.
Definition: callprocessor.h:514
PTimer statusCheckTimer
Definition: callprocessor.h:650
PINDEX SourceCallNumber()
Definition: remote.h:77
void SetCallRegistered(PBoolean newValue=true)
Definition: callprocessor.h:555
void ProcessIaxCmdMwi(IAX2FullFrameProtocol *src)
Definition: frame.h:748
void ProcessIaxCmdQuelch(IAX2FullFrameProtocol *src)
PBoolean IsCallNewed()
Definition: callprocessor.h:583
Definition: processor.h:136
void SendDtmf(const PString &dtmfs)
Definition: frame.h:1084
void SendQuelchMessage()
void RemoteNodeHasAnswered()
void ProcessIaxCmdPage(IAX2FullFrameProtocol *src)
Definition: sound.h:65
void StartStatusCheckTimer(PINDEX msToWait=10000)
void ClearCall(OpalConnection::CallEndReason releaseReason=OpalConnection::EndedByLocalUser)
Definition: connection.h:396
Definition: frame.h:609
PBoolean IsCallAuthorised()
Definition: callprocessor.h:593
PINDEX lastFullFrameTimeStamp
Definition: callprocessor.h:522
unsigned int selectedCodec
Definition: callprocessor.h:529
void AssignConnection(IAX2Connection *_con)
void IncAudioFramesRcvd()
Definition: callprocessor.h:311
IAX2Remote & GetRemoteInfo()
Definition: frame.h:115
virtual void ProcessLists()
unsigned short callStatus
Definition: callprocessor.h:544
void ProcessNetworkFrame(IAX2Frame *src)
PINDEX audioFrameDuration
Definition: callprocessor.h:654
void AcceptIncomingCall()
void ProcessIaxCmdAuthReq(IAX2FullFrameProtocol *src)
SafeStrings callList
Definition: callprocessor.h:479
virtual void PrintOn(ostream &strm) const
PBoolean audioFramesNotStarted
Definition: callprocessor.h:662
PString GetCallingName() const
Definition: callprocessor.h:173
IAX2Encryption encryption
Definition: processor.h:253
virtual PBoolean SetAlerting(const PString &calleeName, PBoolean withMedia)
PAtomicInteger audioFramesRcvd
Definition: callprocessor.h:467
virtual void OnReleased()
PBoolean firstMediaFrame
Definition: callprocessor.h:637
PBoolean suppressHangupFrame
Definition: callprocessor.h:716
virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff)
void ProcessIaxCmdTxrej(IAX2FullFrameProtocol *src)
We need more sound packets to come in.
Definition: callprocessor.h:513
PBoolean IsCallHappening()
Definition: callprocessor.h:579
void ProcessIncomingAudioFrame(IAX2Frame *newFrame)
void ProcessIaxCmdTransfer(IAX2FullFrameProtocol *src)
PBoolean answerCallNow
Definition: callprocessor.h:641
PBoolean IsCallAnswered()
Definition: callprocessor.h:602
void ProcessIaxCmdTxacc(IAX2FullFrameProtocol *src)
Definition: callprocessor.h:536
Definition: frame.h:75
void ProcessIaxCmdInval(IAX2FullFrameProtocol *src)
PString GetUserName() const
PString callingDnid
Definition: callprocessor.h:684
void ProcessIncomingVideoFrame(IAX2Frame *newFrame)
void SetUserName(PString &inUserName)
Definition: callprocessor.h:166
PBoolean IsCallRinging()
Definition: callprocessor.h:599
void SetCallRinging(PBoolean newValue=true)
Definition: callprocessor.h:567
void PutSoundPacketToNetwork(PBYTEArray *sund)
PMutex transferMutex
Definition: callprocessor.h:701
void ProcessIaxCmdProvision(IAX2FullFrameProtocol *src)
IAX2Encryption & GetEncryptionInfo()
Definition: callprocessor.h:77
void SendAnswerMessageToRemoteNode()
void IncVideoFramesRcvd()
Definition: callprocessor.h:317
void ProcessIaxCmdDpReq(IAX2FullFrameProtocol *src)
PBoolean IsCallSentRinging()
Definition: callprocessor.h:587
SafeString dtmfText
Definition: callprocessor.h:484
PBoolean Matches(IAX2Frame *frame)
Definition: callprocessor.h:108
Definition: connection.h:362
Definition: frame.h:783
SafeStrings dtmfNetworkList
Definition: callprocessor.h:491
void SetCallAccepted(PBoolean newValue=true)
Definition: callprocessor.h:563
void SendTransferMessage()
IAX2FullFrameProtocol * BuildNewFrameForSending(IAX2FullFrameProtocol *inReplyTo=NULL)
CallStatus
Definition: callprocessor.h:532
virtual ~IAX2CallProcessor()
void ProcessIaxCmdCallToken(IAX2FullFrameProtocol *src)