3 * Inter Asterisk Exchange 2
5 * Class to implement the transmitter, which sends all packets for all calls.
7 * Open Phone Abstraction Library (OPAL)
9 * Copyright (c) 2005 Indranet Technologies Ltd.
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/
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
21 * The Original Code is Open Phone Abstraction Library.
23 * The Initial Developer of the Original Code is Indranet Technologies Ltd.
25 * The author of this code is Derek J Smithies
29 * Revision 1.7 2007/08/07 03:10:18 dereksmithies
30 * Modify comments. Reduce some of the verbosity of the PTRACE messages.
32 * Revision 1.6 2007/01/23 02:10:39 dereksmithies
33 * Handle Vnak frames correctly. Handle iseqno and oseqno correctly.
35 * Revision 1.5 2007/01/11 03:02:16 dereksmithies
36 * Remove the previous audio buffering code, and switch to using the jitter
37 * buffer provided in Opal. Reduce the verbosity of the log mesasges.
39 * Revision 1.4 2007/01/09 03:32:23 dereksmithies
40 * Tidy up and improve the close down process - make it more robust.
41 * Alter level of several PTRACE statements. Add Terminate() method to transmitter and receiver.
43 * Revision 1.3 2006/08/09 03:46:39 dereksmithies
44 * Add ability to register to a remote Asterisk box. The iaxProcessor class is split
45 * into a callProcessor and a regProcessor class.
46 * Big thanks to Stephen Cook, (sitiveni@gmail.com) for this work.
48 * Revision 1.2 2005/08/26 03:07:38 dereksmithies
49 * Change naming convention, so all class names contain the string "IAX2"
51 * Revision 1.1 2005/07/30 07:01:33 csoutheren
52 * Added implementation of IAX2 (Inter Asterisk Exchange 2) protocol
53 * Thanks to Derek Smithies of Indranet Technologies Ltd. for
54 * writing and contributing this code
64 #pragma implementation "transmit.h"
67 #include <iax2/transmit.h>
71 IAX2Transmit::IAX2Transmit(IAX2EndPoint
& _newEndpoint
, PUDPSocket
& _newSocket
)
72 : PThread(1000, NoAutoDeleteThread
),
76 sendNowFrames
.Initialise();
77 ackingFrames
.Initialise();
81 PTRACE(6,"Constructor - IAX2 Transmitter");
85 IAX2Transmit::~IAX2Transmit()
87 sendNowFrames
.AllowDeleteObjects();
88 ackingFrames
.AllowDeleteObjects();
89 PTRACE(5, "IAX2Transmit\tDestructor finished");
92 void IAX2Transmit::Terminate()
98 void IAX2Transmit::SendFrame(IAX2Frame
*newFrame
)
100 PTRACE(5,"Process request to send frame " << newFrame
->IdString());
102 sendNowFrames
.AddNewFrame(newFrame
);
107 void IAX2Transmit::PurgeMatchingFullFrames(IAX2Frame
*newFrame
)
109 if (!PIsDescendant(newFrame
, IAX2FullFrame
))
112 PTRACE(4, "Purge frames matching received " << newFrame
->IdString());
113 ackingFrames
.DeleteMatchingSendFrame((IAX2FullFrame
*)newFrame
);
116 void IAX2Transmit::SendVnakRequestedFrames(IAX2FullFrameProtocol
&src
)
118 ackingFrames
.SendVnakRequestedFrames(src
);
122 void IAX2Transmit::Main()
124 SetThreadName("IAX2Transmit");
136 PTRACE(3, " End of the Transmit thread.");
139 void IAX2Transmit::ProcessAckingList()
141 IAX2FrameList framesToSend
;
142 framesToSend
.Initialise();
144 ackingFrames
.GetResendFramesDeleteOldFrames(framesToSend
);
146 framesToSend
.MarkAllAsResent();
148 sendNowFrames
.GrabContents(framesToSend
);
151 void IAX2Transmit::ReportLists()
153 PTRACE(5, "IAX2Transmit\tSend now frames is: ");
154 sendNowFrames
.ReportList();
155 PTRACE(5, "IAX2Transmit\tAckingFrames is:");
156 ackingFrames
.ReportList();
159 void IAX2Transmit::ProcessSendList()
162 IAX2Frame
* active
= sendNowFrames
.GetLastFrame();
166 BOOL isFullFrame
= FALSE
;
167 if (PIsDescendant(active
, IAX2FullFrame
)) {
169 IAX2FullFrame
*f
= (IAX2FullFrame
*)active
;
170 if (f
->DeleteFrameNow()) {
171 PTRACE(6, "This frame has timed out, so do not transmit" << f
->IdString());
177 if (!active
->TransmitPacket(sock
)) {
178 PTRACE(4, "Delete " << active
->IdString() << " as transmit failed.");
184 PTRACE(4, "Delete this frame as it is a mini frame, and continue" << active
->IdString());
189 IAX2FullFrame
*f
= (IAX2FullFrame
*)active
;
190 if (f
->IsAckFrame() || f
->IsVnakFrame()) {
195 if (!active
->CanRetransmitFrame()) {
200 ackingFrames
.AddNewFrame(active
);
204 /* The comment below is magic for those who use emacs to edit this file. */
205 /* With the comment below, the tab key does auto indent to 2 spaces. */