OPAL  Version 3.14.3
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: 29536 $
28  * $Author: rjongbloed $
29  * $Date: 2013-04-19 18:55:15 +1000 (Fri, 19 Apr 2013) $
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_config.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 
80  void ClearCall(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
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 
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