OPAL Version 3.10.4

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

- File List
- Globals

frame.h
Go to the documentation of this file.
1 /*
2 *
3 * Inter Asterisk Exchange 2
4 *
5 * Open Phone Abstraction Library (OPAL)
6 *
7 * Define the classes that carry information over the ethernet.
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: 24606 $
28 * $Author: dereksmithies $
29 * $Date: 2010-07-28 22:51:05 -0500 (Wed, 28 Jul 2010) $
30 */
31
32 #ifndef OPAL_IAX2_FRAME_H
33 #define OPAL_IAX2_FRAME_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 <iax2/ies.h>
44 #include <iax2/remote.h>
45
46 #include <ptlib/sockets.h>
47
48 #ifdef P_USE_PRAGMA
49 #pragma interface
50 #endif
51
52 class IAX2Frame;
53 class IAX2FrameList;
54 class IAX2FullFrame;
55 class IAX2FullFrameCng;
56 class IAX2FullFrameDtmf;
57 class IAX2FullFrameHtml;
58 class IAX2FullFrameImage;
59 class IAX2FullFrameNull;
60 class IAX2FullFrameProtocol;
61 class IAX2FullFrameSessionControl;
62 class IAX2FullFrameText;
63 class IAX2FullFrameVideo;
64 class IAX2FullFrameVoice;
65 class IAX2EndPoint;
66 class IAX2Processor;
67 class IAX2CallProcessor;
68 class IAX2IeList;
69 class IAX2MiniFrame;
70 class IAX2Transmitter;
71
72
73
75 class IAX2Frame : public PObject
76 {
77 PCLASSINFO(IAX2Frame, PObject);
78 public:
80 IAX2Frame(IAX2EndPoint &_endpoint);
81
83 virtual ~IAX2Frame();
84
87 PBoolean ReadNetworkPacket(PUDPSocket &sock);
88
90 virtual PBoolean ProcessNetworkPacket();
91
93 virtual PBoolean IsFullFrame() { return isFullFrame; }
94
96 PBoolean IsVideo() const { return isVideo; }
97
99 PBoolean IsAudio() const { return isAudio; }
100
104 virtual BYTE *GetMediaDataPointer() { return data.GetPointer(); }
105
109 virtual PINDEX GetMediaDataSize() { return DataSize();}
110
112 PINDEX DataSize() { return data.GetSize(); }
113
115 IAX2Remote & GetRemoteInfo() { return remote; }
116
118 const BYTE * GetDataPointer() { return data + currentReadIndex; }
119
126 IAX2Frame * BuildAppropriateFrameType(IAX2Encryption &encryptionInfo);
127
129 IAX2Frame * BuildAppropriateFrameType();
130
132 PINDEX GetUnReadBytes() { return data.GetSize() - currentReadIndex; }
133
135 virtual PBoolean WriteHeader() { return false; }
136
139 virtual PBoolean TransmitPacket(PUDPSocket &sock);
140
142 virtual void PrintOn(ostream & strm) const;
143
145 static DWORD CalcTimeStamp(const PTimeInterval & callStartTick);
146
150 virtual void BuildTimeStamp(const PTimeInterval & callStartTick);
151
153 IAX2EndPoint & GetEndpoint() { return endpoint; }
154
157 PString IdString() const;
158
160 DWORD GetTimeStamp() { return timeStamp; }
161
163 void SetTimeStamp(DWORD newValue);
164
166 virtual PBoolean CallMustBeActive() { return true; }
167
169 enum IAX2FrameType {
170 undefType = 0,
171 dtmfType = 1,
172 voiceType = 2,
173 videoType = 3,
174 controlType = 4,
175 nullType = 5,
176 iax2ProtocolType = 6,
177 textType = 7,
178 imageType = 8,
179 htmlType = 9,
180 cngType = 10,
181 numFrameTypes = 11
182 };
183
186 IAX2FrameType GetFrameType() { return frameType; }
187
191 virtual void InitialiseHeader(IAX2Processor * /*processor*/) { }
192
195 PBoolean CanRetransmitFrame() const {return canRetransmitFrame; }
196
199 PString GetConnectionToken() const { return connectionToken; }
200
203 void SetConnectionToken(PString newToken) { connectionToken = newToken; }
204
207 void BuildConnectionToken();
208
211 PBoolean EncryptContents(IAX2Encryption &encData);
212
214 virtual PINDEX GetEncryptionOffset();
215
216 protected:
217
221 PBoolean DecryptContents(IAX2Encryption & encryption);
222
225 IAX2Remote remote;
226
229 IAX2FrameType frameType;
230
233 PBoolean Read1Byte(BYTE & res);
234
237 PBoolean Read2Bytes(PINDEX & res);
238
241 PBoolean Read2Bytes(WORD & res);
242
245 PBoolean Read4Bytes(DWORD & res);
246
249 void Write1Byte(BYTE newVal);
250
253 void Write1Byte(PINDEX newVal);
254
257 void Write2Bytes(PINDEX newVal);
258
261 void Write4Bytes(unsigned int newVal);
262
264 void ZeroAllValues();
265
267 IAX2EndPoint & endpoint;
268
271 PBYTEArray data;
272
274 PBoolean isFullFrame;
275
277 PBoolean isVideo;
278
280 PBoolean isAudio;
281
283 PINDEX currentReadIndex;
284
286 PINDEX currentWriteIndex;
287
289 DWORD timeStamp;
290
292 PBoolean canRetransmitFrame;
293
298 PString connectionToken;
299
302 DWORD presetTimeStamp;
303 };
304
306
307 class IAX2MiniFrame : public IAX2Frame
308 {
309 PCLASSINFO(IAX2MiniFrame, IAX2Frame);
310 public:
313 IAX2MiniFrame(const IAX2Frame & srcFrame);
314
316 IAX2MiniFrame(IAX2EndPoint & _endpoint);
317
326 IAX2MiniFrame(IAX2Processor * con, PBYTEArray &sound, PBoolean isAudio, DWORD usersTimeStamp = 0);
327
329 virtual ~IAX2MiniFrame();
330
333 virtual PBoolean ProcessNetworkPacket();
334
336 virtual PBoolean WriteHeader();
337
339 virtual void PrintOn(ostream & strm) const;
340
343 virtual BYTE *GetMediaDataPointer();
344
346 virtual PINDEX GetMediaDataSize();
347
349 void AlterTimeStamp(PINDEX newValue);
350
356 virtual void InitialiseHeader(IAX2Processor *processor);
357
359 virtual PINDEX GetEncryptionOffset();
360
361 protected:
363 void ZeroAllValues();
364 };
365
368
369 class IAX2FullFrame : public IAX2Frame
370 {
371 PCLASSINFO(IAX2FullFrame, IAX2Frame);
372 public:
375 IAX2FullFrame(const IAX2Frame & srcFrame);
376
379 IAX2FullFrame(IAX2EndPoint &_endpoint);
380
383 virtual ~IAX2FullFrame();
384
386 PBoolean IsAckFrame() { return isAckFrame; }
387
389 PBoolean IsPingFrame();
390
392 PBoolean IsNewFrame();
393
395 PBoolean IsLagRqFrame();
396
398 PBoolean IsLagRpFrame();
399
401 PBoolean IsPongFrame();
402
404 PBoolean IsAuthReqFrame();
405
407 PBoolean IsVnakFrame();
408
410 PBoolean IsRegReqFrame();
411
413 PBoolean IsRegAuthFrame();
414
416 PBoolean IsRegAckFrame();
417
419 PBoolean IsRegRelFrame();
420
422 PBoolean IsRegRejFrame();
423
425 PBoolean IsCallTokenFrame();
426
429 PBoolean FrameIncrementsInSeqNo();
430
433 virtual PBoolean IsFullFrame() { return true; }
434
438 PBoolean IsHangupFrame();
439
441 void ZeroAllValues();
442
445 virtual PBoolean ProcessNetworkPacket();
446
449 virtual PBoolean TransmitPacket(PUDPSocket &sock);
450
452 PString GetFullFrameName() const;
453
455 virtual PString GetSubClassName() const
456 { return PString(" subclass=") + PString(subClass); }
457
461 void MarkDeleteNow();
462
467 void MarkVnakSendNow();
468
471 virtual BYTE *GetMediaDataPointer();
472
474 virtual PINDEX GetMediaDataSize();
475
477 PINDEX GetSubClass() const { return subClass; }
478
480 void SetSubClass(PINDEX newValue) { subClass = newValue;}
481
485 virtual PBoolean WriteHeader();
486
489 void ModifyFrameHeaderSequenceNumbers(PINDEX inNo, PINDEX outNo);
490
495 void ModifyFrameTimeStamp(PINDEX newTimeStamp);
496
498 virtual PBoolean InformationElementsPresent() { return false; }
499
502 PBoolean SendFrameNow() { return sendFrameNow; }
503
506 PBoolean DeleteFrameNow() { return deleteFrameNow; }
507
509 IAX2SequenceNumbers & GetSequenceInfo() { return sequence; }
510
512 virtual void PrintOn(ostream & strm) const;
513
515 void MarkAsResent();
516
519 PBoolean operator *= (IAX2FullFrame & other);
520
523 enum ConnectionRequired {
524 callActive,
525 callIrrelevant
526 };
527
529 virtual BYTE GetFullFrameType() { return 0; }
530
532 virtual PINDEX GetEncryptionOffset() { return 4; }
533
534 protected:
536 virtual PBoolean CallMustBeActive() { return callMustBeActive; }
537
539 void UnCompressSubClass(BYTE a);
540
542 int CompressSubClass();
543
545 void ClearListFlags();
546
552 virtual void InitialiseHeader(IAX2Processor *processor);
553
554 #ifdef DOC_PLUS_PLUS
555
558 void OnTransmissionTimeout(PTimer &, INT);
559 #else
560 PDECLARE_NOTIFIER(PTimer, IAX2FullFrame, OnTransmissionTimeout);
561 #endif
562
563 PTimer transmissionTimer;
564
566 PINDEX subClass;
567
569 PTimeInterval retryDelta;
570
572 PTimeInterval timeOffset;
573
575 PINDEX retries;
576
578 enum RetryTime {
579 minRetryTime = 1000,
580 maxRetryTime = 010000,
581 maxRetries = 3
582 };
583
585 IAX2SequenceNumbers sequence;
586
588 PBoolean sendFrameNow;
589
591 PBoolean deleteFrameNow;
592
594 PBoolean packetResent;
595
597 PBoolean callMustBeActive;
598
600 PBoolean isAckFrame;
601 };
602
604
609 class IAX2FullFrameDtmf : public IAX2FullFrame
610 {
611 PCLASSINFO(IAX2FullFrameDtmf, IAX2FullFrame);
612 public:
615 IAX2FullFrameDtmf(const IAX2Frame & srcFrame);
616
619 IAX2FullFrameDtmf(const IAX2FullFrame & srcFrame);
620
623 IAX2FullFrameDtmf(IAX2Processor *processor,
624 char subClassValue
625 );
626
629 IAX2FullFrameDtmf(IAX2Processor *processor,
630 PString subClassValue
631 );
632
633
635 virtual PString GetSubClassName() const;
636
638 enum DtmfSc {
639 dtmf0 = 48,
640 dtmf1 = 49,
641 dtmf2 = 50,
642 dtmf3 = 51,
643 dtmf4 = 52,
644 dtmf5 = 53,
645 dtmf6 = 54,
646 dtmf7 = 55,
647 dtmf8 = 56,
648 dtmf9 = 57,
649 dtmfA = 65,
650 dtmfB = 66,
651 dtmfC = 67,
652 dtmfD = 68,
653 dtmfStar = 42,
654 dtmfHash = 35
655 };
656
658 virtual BYTE GetFullFrameType() { return dtmfType; }
659
660 protected:
661 };
662
664
671 class IAX2FullFrameVoice : public IAX2FullFrame
672 {
673 PCLASSINFO(IAX2FullFrameVoice, IAX2FullFrame);
674 public:
675
678 IAX2FullFrameVoice(const IAX2Frame & srcFrame);
679
682 IAX2FullFrameVoice(const IAX2FullFrame & srcFrame);
683
692 IAX2FullFrameVoice(IAX2CallProcessor *processor, PBYTEArray &sound,
693 PINDEX usersTimeStamp = 0);
694
696 virtual ~IAX2FullFrameVoice();
697
699 virtual PString GetSubClassName() const;
700
703 static PString GetSubClassName(unsigned short testValue)
704 { return GetSubClassName((unsigned int) testValue); }
705
708 static PString GetSubClassName(unsigned int testValue);
709
713 static PString GetOpalNameOfCodec(PINDEX testValue);
714
716 static PString GetSubClassName(int testValue)
717 { return GetSubClassName((unsigned short) testValue); }
718
721 static unsigned short OpalNameToIax2Value(const PString opalName);
722
724 enum AudioSc {
725 g7231 = 1,
726 gsm = 2,
727 g711ulaw = 4,
728 g711alaw = 8,
729 mp3 = 0x10,
730 adpcm = 0x20,
731 pcm = 0x40,
732 lpc10 = 0x80,
733 g729 = 0x100,
734 speex = 0x200,
735 ilbc = 0x400,
736 supportedCodecs = 11
737 };
738
740 virtual BYTE GetFullFrameType() { return voiceType; }
741 };
743
748 class IAX2FullFrameVideo : public IAX2FullFrame
749 {
750 PCLASSINFO(IAX2FullFrameVideo, IAX2FullFrame);
751 public:
752
755 IAX2FullFrameVideo(const IAX2Frame & srcFrame);
756
759 IAX2FullFrameVideo(const IAX2FullFrame & srcFrame);
760
762 virtual PString GetSubClassName() const;
763
765 enum VideoSc {
766 jpeg = 0x10000,
767 png = 0x20000,
768 h261 = 0x40000,
769 h263 = 0x80000
770 };
771
773 virtual BYTE GetFullFrameType() { return videoType; }
774 protected:
775 };
776
778
783 class IAX2FullFrameSessionControl : public IAX2FullFrame
784 {
785 PCLASSINFO(IAX2FullFrameSessionControl, IAX2FullFrame);
786 public:
787
789 enum SessionSc {
790 hangup = 1,
791 ring = 2,
792 ringing = 3,
793 answer = 4,
794 busy = 5,
795 tkoffhk = 6,
796 offhook = 7,
797 congestion = 8,
798 flashhook = 9,
799 wink = 10,
800 option = 11,
801 keyRadio = 12,
802 unkeyRadio = 13,
803 callProgress = 14,
804 callProceeding = 15,
805 callOnHold = 16,
806 callHoldRelease = 17,
807 stopSounds = 255
808 };
809
810
811
814 IAX2FullFrameSessionControl(const IAX2Frame & srcFrame);
815
818 IAX2FullFrameSessionControl(const IAX2FullFrame & srcFrame);
819
822 IAX2FullFrameSessionControl(IAX2Processor *processor,
823 PINDEX subClassValue
824 );
825
828 IAX2FullFrameSessionControl(IAX2Processor *processor,
829 SessionSc subClassValue
830 );
831
833 virtual ~IAX2FullFrameSessionControl() { }
834
836 virtual PString GetSubClassName() const;
837
839 virtual BYTE GetFullFrameType() { return controlType; }
840
841 protected:
842 };
843
845
851 class IAX2FullFrameNull : public IAX2FullFrame
852 {
853 PCLASSINFO(IAX2FullFrameNull, IAX2FullFrame);
854 public:
857 IAX2FullFrameNull(IAX2EndPoint & endpoint) : IAX2FullFrame(endpoint) { }
858
862 IAX2FullFrameNull(const IAX2Frame & srcFrame);
863
867 IAX2FullFrameNull(const IAX2FullFrame & srcFrame);
868
870 virtual PString GetSubClassName() const { return PString(""); }
871
873 virtual BYTE GetFullFrameType() { return nullType; }
874
875 protected:
876 };
877
879
885 class IAX2FullFrameProtocol : public IAX2FullFrame
886 {
887 PCLASSINFO(IAX2FullFrameProtocol, IAX2FullFrame);
888 public:
889
891 enum ProtocolSc {
892 cmdNew = 1,
893 cmdPing = 2,
894 cmdPong = 3,
895 cmdAck = 4,
896 cmdHangup = 5,
897 cmdReject = 6,
898 cmdAccept = 7,
899 cmdAuthReq = 8,
900 cmdAuthRep = 9,
901 cmdInval = 10,
902 cmdLagRq = 11,
903 cmdLagRp = 12,
904 cmdRegReq = 13,
905 cmdRegAuth = 14,
906 cmdRegAck = 15,
907 cmdRegRej = 16,
908 cmdRegRel = 17,
909 cmdVnak = 18,
910 cmdDpReq = 19,
911 cmdDpRep = 20,
912 cmdDial = 21,
913 cmdTxreq = 22,
914 cmdTxcnt = 23,
915 cmdTxacc = 24,
916 cmdTxready = 25,
917 cmdTxrel = 26,
918 cmdTxrej = 27,
919 cmdQuelch = 28,
920 cmdUnquelch = 29,
921 cmdPoke = 30,
922 cmdPage = 31,
923 cmdMwi = 32,
924 cmdUnsupport = 33,
925 cmdTransfer = 34,
926 cmdProvision = 35,
927 cmdFwDownl = 36,
928 cmdFwData = 37,
929 cmdTxMedia = 38,
930 cmdRtKey = 39,
931 cmdCallToken = 40
932 };
933
937 IAX2FullFrameProtocol(const IAX2Frame & srcFrame);
938
942 IAX2FullFrameProtocol(const IAX2FullFrame & srcFrame);
943
946 IAX2FullFrameProtocol(IAX2Processor *processor,
947 PINDEX subClassValue,
948 ConnectionRequired needCon = IAX2FullFrame::callActive
950 );
951
954 IAX2FullFrameProtocol(IAX2Processor *processor,
955 ProtocolSc subClassValue,
956 ConnectionRequired needCon=IAX2FullFrame::callActive
958 );
959
965 IAX2FullFrameProtocol(IAX2Processor *processor,
966 ProtocolSc subClassValue,
967 IAX2FullFrame *inReplyTo,
968 ConnectionRequired needCon = IAX2FullFrame::callActive
970 );
971
973 virtual ~IAX2FullFrameProtocol();
974
976 void SetRetransmissionRequired();
977
979 virtual PBoolean InformationElementsPresent() { return !ieElements.IsEmpty(); }
980
982 ProtocolSc GetSubClass() const { return (ProtocolSc) subClass; }
983
985 virtual PString GetSubClassName() const;
986
988 static PString GetSubClassName(PINDEX t);
989
992 IAX2Ie *GetIeAt(PINDEX i) { return ieElements.GetIeAt(i); }
993
995 void AppendIe(IAX2Ie *newElement) { ieElements.AppendIe(newElement); }
996
999 void WriteIeAsBinaryData();
1000
1004 void CopyDataFromIeListTo(IAX2IeData &res);
1005
1008 void GetRemoteCapability(unsigned int & capability,
1009 unsigned int & preferred);
1010
1013 virtual BYTE GetFullFrameType() { return iax2ProtocolType; }
1014
1016 virtual void PrintOn(ostream & strm) const;
1017
1020 PBoolean GetCallTokenIe(IAX2IeCallToken & callToken);
1021
1022 protected:
1023
1026 PBoolean ReadInformationElements();
1027
1028
1031 IAX2IeList ieElements;
1032
1034 #if PTRACING
1035 friend ostream & operator<<(ostream & o, ProtocolSc t);
1036 #endif
1037 };
1038
1040
1045 class IAX2FullFrameText : public IAX2FullFrame
1046 {
1047 PCLASSINFO(IAX2FullFrameText, IAX2FullFrame);
1048 public:
1049
1052 IAX2FullFrameText(IAX2Processor *processor,
1053 const PString& textValue
1054 );
1055
1058 IAX2FullFrameText(const IAX2Frame & srcFrame);
1059
1062 IAX2FullFrameText(const IAX2FullFrame & srcFrame);
1063
1065 virtual PString GetSubClassName() const;
1066
1068 virtual BYTE GetFullFrameType() { return textType; }
1069
1071 PString GetTextString() const;
1072
1073 protected:
1074
1076 PString internalText;
1077 };
1079
1084 class IAX2FullFrameImage : public IAX2FullFrame
1085 {
1086 PCLASSINFO(IAX2FullFrameImage, IAX2FullFrame);
1087 public:
1088
1091 IAX2FullFrameImage(const IAX2Frame & srcFrame);
1092
1095 IAX2FullFrameImage(const IAX2FullFrame & srcFrame);
1096
1098 virtual PString GetSubClassName() const;
1099
1101 virtual BYTE GetFullFrameType() { return imageType; }
1102 protected:
1103 };
1104
1106
1111 class IAX2FullFrameHtml : public IAX2FullFrame
1112 {
1113 PCLASSINFO(IAX2FullFrameHtml, IAX2FullFrame);
1114 public:
1115
1118 IAX2FullFrameHtml(const IAX2Frame & srcFrame);
1119
1122 IAX2FullFrameHtml(const IAX2FullFrame & srcFrame);
1123
1125 virtual PString GetSubClassName() const;
1126
1128 virtual BYTE GetFullFrameType() { return htmlType; }
1129 protected:
1130 };
1131
1133
1137 class IAX2FullFrameCng : public IAX2FullFrame
1138 {
1139 PCLASSINFO(IAX2FullFrameCng, IAX2FullFrame);
1140 public:
1141
1144 IAX2FullFrameCng(const IAX2Frame & srcFrame);
1145
1148 IAX2FullFrameCng(const IAX2FullFrame & srcFrame);
1149
1151 virtual PString GetSubClassName() const;
1152
1154 virtual BYTE GetFullFrameType() { return cngType; }
1155 protected:
1156 };
1157
1159
1160 PDECLARE_LIST (IAX2FrameList, IAX2Frame *)
1161 #ifdef DOC_PLUS_PLUS //This makes emacs bracket matching code happy.
1162
1168 class IAX2FrameList : public IAX2Frame *
1169 {
1170 #endif
1171 public:
1172 ~IAX2FrameList();
1173
1175 void ReportList(PString & answer);
1176
1178 IAX2Frame *GetLastFrame();
1179
1181 void Initialise();
1182
1184 PBoolean Empty() { return GetSize() == 0; }
1185
1187 void GrabContents(IAX2FrameList &src);
1188
1191 void DeleteMatchingSendFrame(IAX2FullFrame *reply);
1192
1196 void SendVnakRequestedFrames(IAX2FullFrameProtocol &src);
1197
1199 void AddNewFrame(IAX2Frame *src);
1200
1202 void GetResendFramesDeleteOldFrames(IAX2FrameList & framesToSend);
1203
1205 virtual PINDEX GetSize() { PWaitAndSignal m(mutex); return PAbstractList::GetSize(); }
1206
1208 void MarkAllAsResent();
1209
1210 protected:
1212 virtual PINDEX GetEntries() { return PAbstractList::GetSize(); }
1213
1215 PMutex mutex;
1216 };
1217
1219
1223 class IAX2ActiveFrameList : public IAX2FrameList
1224 {
1225 PCLASSINFO(IAX2ActiveFrameList, IAX2FrameList);
1226 public:
1227 IAX2ActiveFrameList() { Initialise(); }
1228 };
1230
1231
1232 #endif // OPAL_IAX2
1233
1234 #endif // OPAL_IAX2_FRAME_H
1235
1236 /* The comment below is magic for those who use emacs to edit this file.
1237 * With the comment below, the tab key does auto indent to 2 spaces.
1238 *
1239 * Local Variables:
1240 * mode:c
1241 * c-basic-offset:2
1242 * End:
1243 */