OPAL Version 3.10.4

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files

- File List
- Globals

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: 24722 $
28 * $Author: dereksmithies $
29 * $Date: 2010-09-23 23:32:35 -0500 (Thu, 23 Sep 2010) $
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
57 class IAX2CallProcessor : public IAX2Processor
58 {
59 PCLASSINFO(IAX2CallProcessor, IAX2Processor);
60
61 public:
62
64 IAX2CallProcessor(IAX2EndPoint & ep);
65
67 virtual ~IAX2CallProcessor();
68
70 void AssignConnection(IAX2Connection * _con);
71
74 void PutSoundPacketToNetwork(PBYTEArray *sund);
75
77 IAX2Encryption & GetEncryptionInfo() { return encryption; }
78
80 virtual void Release(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
81
83 void ClearCall(OpalConnection::CallEndReason releaseReason = OpalConnection::EndedByLocalUser);
84
89 virtual void OnReleased();
90
94 void SendDtmf(const PString & dtmfs);
95
99 void SendText(const PString & text);
100
107 virtual PBoolean SetUpConnection();
108
111 PBoolean Matches(IAX2Frame *frame) { return remote == (frame->GetRemoteInfo()); }
112
115 virtual void PrintOn(ostream & strm) const;
116
119 void ReportStatistics();
120
122 PBoolean MatchingLocalCallNumber(PINDEX compare) { return (compare == remote.SourceCallNumber()); }
123
125 unsigned short GetSelectedCodec() { return (unsigned short) selectedCodec; }
126
131 void AcceptIncomingCall();
132
143 virtual PBoolean SetAlerting(
144 const PString & calleeName,
145 PBoolean withMedia
146 ) ;
147
151 void Hangup(PString messageToSend);
152
155 PBoolean IsCallTerminating() { return callStatus & callTerminating; }
156
158 void SendHold();
159
161 void SendHoldRelease();
162
169 void SetUserName(PString & inUserName) { userName = inUserName; };
170
172 PString GetUserName() const;
173
176 PString GetCallingName() const { return callingName; }
177
184 void SetPassword(PString & inPassword) { password = inPassword; };
185
187 PString GetPassword() const { return password; };
188
191 void SendTransfer(
192 const PString & calledNumber,
193 const PString & calledContext = PString::Empty());
194
197 void StartStatusCheckTimer(PINDEX msToWait = 10000 );
199
206 virtual PBoolean IncomingMessageOutOfOrder(IAX2FullFrame *ff);
207
211 void SendAnswerMessageToRemoteNode();
212
213 protected:
214
216 IAX2Connection * con;
217
222 PBoolean RemoteSelectedCodecOk();
223
227 void CheckForHangupMessages();
228
230 void ProcessNetworkFrame(IAX2Frame * src);
231
234 void ProcessNetworkFrame(IAX2MiniFrame * src);
235
238 void ProcessNetworkFrame(IAX2FullFrame * src);
239
242 void ProcessNetworkFrame(IAX2FullFrameDtmf * src);
243
246 void ProcessNetworkFrame(IAX2FullFrameVoice * src);
247
250 void ProcessNetworkFrame(IAX2FullFrameVideo * src);
251
254 void ProcessNetworkFrame(IAX2FullFrameSessionControl * src);
255
258 void ProcessNetworkFrame(IAX2FullFrameNull * src);
259
266 virtual PBoolean ProcessNetworkFrame(IAX2FullFrameProtocol * src);
267
270 void ProcessNetworkFrame(IAX2FullFrameText * src);
271
274 void ProcessNetworkFrame(IAX2FullFrameImage * src);
275
278 void ProcessNetworkFrame(IAX2FullFrameHtml * src);
279
282 void ProcessNetworkFrame(IAX2FullFrameCng * src);
283
286 virtual void ProcessLists();
287
289 void ConnectToRemoteNode(PString & destination);
290
292 void SendDtmfMessage(char message);
293
295 void SendTextMessage(PString & message);
296
299 void SendSoundMessage(PBYTEArray *sound);
300
302 void SendTransferMessage();
303
305 void SendQuelchMessage();
306
308 void SendUnQuelchMessage();
309
311 void IncAudioFramesSent() { ++audioFramesSent; }
312
314 void IncAudioFramesRcvd() { ++audioFramesRcvd; }
315
317 void IncVideoFramesSent() { ++videoFramesSent; }
318
320 void IncVideoFramesRcvd() { ++videoFramesRcvd; }
321
324 void RemoteNodeHasAnswered();
325
329 void CallStopSounds();
330
333 void ReceivedHookFlash();
334
337 void RemoteNodeIsBusy();
338
341 void ProcessIncomingAudioFrame(IAX2Frame *newFrame);
342
345 void ProcessIncomingVideoFrame(IAX2Frame *newFrame);
346
349 void ProcessIaxCmdNew(IAX2FullFrameProtocol *src);
350
353 void ProcessIaxCmdAck(IAX2FullFrameProtocol *src);
354
357 void ProcessIaxCmdHangup(IAX2FullFrameProtocol *src);
358
361 void ProcessIaxCmdReject(IAX2FullFrameProtocol *src);
362
365 void ProcessIaxCmdAccept(IAX2FullFrameProtocol *src);
366
369 void ProcessIaxCmdAuthReq(IAX2FullFrameProtocol *src);
370
373 void ProcessIaxCmdAuthRep(IAX2FullFrameProtocol *src);
374
377 void ProcessIaxCmdInval(IAX2FullFrameProtocol *src);
378
381 void ProcessIaxCmdDpReq(IAX2FullFrameProtocol *src);
382
385 void ProcessIaxCmdDpRep(IAX2FullFrameProtocol *src);
386
389 void ProcessIaxCmdDial(IAX2FullFrameProtocol *src);
390
393 void ProcessIaxCmdTxreq(IAX2FullFrameProtocol *src);
394
397 void ProcessIaxCmdTxcnt(IAX2FullFrameProtocol *src);
398
401 void ProcessIaxCmdTxacc(IAX2FullFrameProtocol *src);
402
405 void ProcessIaxCmdTxready(IAX2FullFrameProtocol *src);
406
409 void ProcessIaxCmdTxrel(IAX2FullFrameProtocol *src);
410
413 void ProcessIaxCmdTxrej(IAX2FullFrameProtocol *src);
414
417 void ProcessIaxCmdQuelch(IAX2FullFrameProtocol *src);
418
421 void ProcessIaxCmdUnquelch(IAX2FullFrameProtocol *src);
422
425 void ProcessIaxCmdPage(IAX2FullFrameProtocol *src);
426
429 void ProcessIaxCmdMwi(IAX2FullFrameProtocol *src);
430
433 void ProcessIaxCmdUnsupport(IAX2FullFrameProtocol *src);
434
437 void ProcessIaxCmdTransfer(IAX2FullFrameProtocol *src);
438
441 void ProcessIaxCmdProvision(IAX2FullFrameProtocol *src);
442
445 void ProcessIaxCmdFwDownl(IAX2FullFrameProtocol *src);
446
449 void ProcessIaxCmdFwData(IAX2FullFrameProtocol *src);
450
457 void ProcessIaxCmdCallToken(IAX2FullFrameProtocol *src);
458
464 IAX2FullFrameProtocol *BuildNewFrameForSending(IAX2FullFrameProtocol *inReplyTo = NULL);
465
467 PAtomicInteger audioFramesSent;
468
470 PAtomicInteger audioFramesRcvd;
471
473 PAtomicInteger videoFramesSent;
474
476 PAtomicInteger videoFramesRcvd;
477
479 SafeString remotePhoneNumber;
480
482 SafeStrings callList;
483
487 SafeString dtmfText;
488
491 SafeStrings textList;
492
494 SafeStrings dtmfNetworkList;
495
497 SafeStrings hangList;
498
500 PBoolean holdCall;
501
503 PBoolean holdReleaseCall;
504
507 IAX2SoundList soundWaitingForTransmission;
508
514 enum SoundBufferState {
515 BufferToSmall,
516 Normal,
517 BufferToBig
518 };
519
521 SoundBufferState soundBufferState;
522
525 PINDEX lastFullFrameTimeStamp;
526
528 PBoolean audioCanFlow;
529
532 unsigned int selectedCodec;
533
535 enum CallStatus {
536 callNewed = 1 << 0,
537 callSentRinging = 1 << 1,
538 callRegistered = 1 << 2,
539 callAuthorised = 1 << 3,
540 callAccepted = 1 << 4,
541 callRinging = 1 << 5,
542 callAnswered = 1 << 6,
543 callTerminating = 1 << 7
544 };
545
547 unsigned short callStatus;
548
550 void SetCallSentRinging(PBoolean newValue = true)
551 { if (newValue) callStatus |= callSentRinging; else callStatus &= ~callSentRinging; }
552
554 void SetCallNewed(PBoolean newValue = true)
555 { if (newValue) callStatus |= callNewed; else callStatus &= ~callNewed; }
556
558 void SetCallRegistered(PBoolean newValue = true)
559 { if (newValue) callStatus |= callRegistered; else callStatus &= ~callRegistered; }
560
562 void SetCallAuthorised(PBoolean newValue = true)
563 { if (newValue) callStatus |= callAuthorised; else callStatus &= ~callAuthorised; }
564
566 void SetCallAccepted(PBoolean newValue = true)
567 { if (newValue) callStatus |= callAccepted; else callStatus &= ~callAccepted; }
568
570 void SetCallRinging(PBoolean newValue = true)
571 { if (newValue) callStatus |= callRinging; else callStatus &= ~callRinging; }
572
574 void SetCallAnswered(PBoolean newValue = true)
575 { if (newValue) callStatus |= callAnswered; else callStatus &= ~callAnswered; }
576
578 void SetCallTerminating(PBoolean newValue = true)
579 { if (newValue) callStatus |= callTerminating; else callStatus &= ~callTerminating; }
580
582 PBoolean IsCallHappening() { return callStatus > 0; }
583
586 PBoolean IsCallNewed() { return callStatus & callNewed; }
587
590 PBoolean IsCallSentRinging() { return callStatus & callSentRinging; }
591
593 PBoolean IsCallRegistered() { return callStatus & callRegistered; }
594
596 PBoolean IsCallAuthorised() { return callStatus & callAuthorised; }
597
599 PBoolean IsCallAccepted() { return callStatus & callAccepted; }
600
602 PBoolean IsCallRinging() { return callStatus & callRinging; }
603
605 PBoolean IsCallAnswered() { return callStatus & callAnswered; }
606
607 #ifdef DOC_PLUS_PLUS
608
614 void OnStatusCheck(PTimer &, INT);
615 #else
616 PDECLARE_NOTIFIER(PTimer, IAX2CallProcessor, OnStatusCheck);
617 #endif
618
620 void DoStatusCheck();
621
624 void RemoteNodeIsRinging();
625
629 void RingingWasAcked();
630
635 void AnswerWasAcked();
636
640 PBoolean firstMediaFrame;
641
644 PBoolean answerCallNow;
645
650 PBoolean statusCheckOtherEnd;
651
653 PTimer statusCheckTimer;
654
657 PINDEX audioFrameDuration;
658
660 PINDEX audioCompressedBytes;
661
665 PBoolean audioFramesNotStarted;
666
669 void CheckForRemoteCapabilities(IAX2FullFrameProtocol *src);
670
673 virtual void OnNoResponseTimeout();
674
676 virtual void ProcessFullFrame(IAX2FullFrame & fullFrame);
677
680 PString callingName;
681
684 PString callingExtension;
685
687 PString callingDnid;
688
691 PString callingContext;
692
696 PString userName;
697
701 PString password;
702
704 PMutex transferMutex;
705
707 PBoolean doTransfer;
708
710 PString transferCalledNumber;
711
713 PString transferCalledContext;
714
719 PBoolean suppressHangupFrame;
720 };
721
723
724 /* The comment below is magic for those who use emacs to edit this file.
725 * With the comment below, the tab key does auto indent to 2 spaces.
726 *
727 * Local Variables:
728 * mode:c
729 * c-basic-offset:2
730 * End:
731 */
732
733
734 #endif // OPAL_IAX2
735
736 #endif // OPAL_IAX2_CALLPROCESSOR_H