|
1 /* |
|
2 * Copyright (c) 2007 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Firewall/nat box puncher* |
|
15 */ |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "CCRPunchPacketSender.h" |
|
22 #include "CCRRtspPacketSource.h" |
|
23 #include "videoserviceutilsLogger.h" |
|
24 |
|
25 // CONSTANTS |
|
26 // None. |
|
27 |
|
28 // ============================ MEMBER FUNCTIONS =============================== |
|
29 |
|
30 // ----------------------------------------------------------------------------- |
|
31 // CCRPunchPacketSender::NewL |
|
32 // Two-phased constructor. |
|
33 // ----------------------------------------------------------------------------- |
|
34 // |
|
35 CCRPunchPacketSender* CCRPunchPacketSender::NewL( |
|
36 RConnection& aConnection, |
|
37 RSocketServ& aSockServer, |
|
38 TInetAddr& aFromAddr, |
|
39 TInetAddr& aRemoteAddr , |
|
40 TUint32 aMySSRC, |
|
41 CCRRtspPacketSource& aOwner ) |
|
42 { |
|
43 CCRPunchPacketSender* self = new( ELeave ) CCRPunchPacketSender( |
|
44 aConnection, aSockServer, aFromAddr, aRemoteAddr, aMySSRC, aOwner ); |
|
45 CleanupStack::PushL( self ); |
|
46 self->ConstructL(); |
|
47 CleanupStack::Pop( self ); |
|
48 return self; |
|
49 } |
|
50 |
|
51 // ----------------------------------------------------------------------------- |
|
52 // CCRPunchPacketSender::CCRPunchPacketSender |
|
53 // C++ default constructor can NOT contain any code, that might leave. |
|
54 // ----------------------------------------------------------------------------- |
|
55 // |
|
56 CCRPunchPacketSender::CCRPunchPacketSender( |
|
57 RConnection& aConnection, |
|
58 RSocketServ& aSockServer, |
|
59 TInetAddr& aFromAddr, |
|
60 TInetAddr& aRemoteAddr , |
|
61 TUint32 aMySSRC, |
|
62 CCRRtspPacketSource& aOwner ) |
|
63 : iConnection( aConnection ), |
|
64 iSockServer( aSockServer ), |
|
65 iFromAddr( aFromAddr ), |
|
66 iRemoteAddr( aRemoteAddr ), |
|
67 iMySSRC( aMySSRC ), |
|
68 iOwner( aOwner ) |
|
69 { |
|
70 // None |
|
71 } |
|
72 |
|
73 // ----------------------------------------------------------------------------- |
|
74 // CCRPunchPacketSender::ConstructL |
|
75 // Symbian 2nd phase constructor can leave. |
|
76 // ----------------------------------------------------------------------------- |
|
77 // |
|
78 void CCRPunchPacketSender::ConstructL() |
|
79 { |
|
80 iSock1 = CCRSock::NewL( *this, 1, iConnection, iSockServer, EFalse, EFalse ); |
|
81 User::LeaveIfError( iSock1->ConnectSock( iRemoteAddr, iFromAddr.Port() ) ); |
|
82 iSock2 = CCRSock::NewL( *this, 2, iConnection, iSockServer, EFalse, EFalse ); |
|
83 TInetAddr remoteAddr2 = iRemoteAddr; |
|
84 remoteAddr2.SetPort ( iRemoteAddr.Port() + 1 ); |
|
85 User::LeaveIfError( iSock2->ConnectSock( remoteAddr2, iFromAddr.Port() + 1 ) ); |
|
86 iCleanUp = new ( ELeave ) CAsyncCallBack( CActive::EPriorityStandard ) ; |
|
87 } |
|
88 |
|
89 // ----------------------------------------------------------------------------- |
|
90 // CCRPunchPacketSender::~CCRPunchPacketSender |
|
91 // Destructor. |
|
92 // ----------------------------------------------------------------------------- |
|
93 // |
|
94 CCRPunchPacketSender::~CCRPunchPacketSender() |
|
95 { |
|
96 LOG( "CCRPunchPacketSender::~CCRPunchPacketSender" ); |
|
97 |
|
98 delete iSock1; |
|
99 delete iSock2; |
|
100 delete iCleanUp; |
|
101 } |
|
102 |
|
103 // ----------------------------------------------------------------------------- |
|
104 // CCRPunchPacketSender::DataReceived |
|
105 // |
|
106 // This is called when data is received from socket. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 void CCRPunchPacketSender::DataReceived( TInt /*aSockId*/, const TDesC8& /*aData*/ ) |
|
110 { |
|
111 // None |
|
112 } |
|
113 |
|
114 // ----------------------------------------------------------------------------- |
|
115 // CCRPunchPacketSender::SockStatusChange |
|
116 // |
|
117 // This is called when socket status changes. |
|
118 // ----------------------------------------------------------------------------- |
|
119 // |
|
120 void CCRPunchPacketSender::SockStatusChange( |
|
121 TInt aSockId, |
|
122 CCRSock::TCRSockStatus aStatus, |
|
123 TInt aError ) |
|
124 { |
|
125 if ( aStatus == CCRSock::EFailed ) |
|
126 { |
|
127 LOG3( "CCRPunchPacketSender::SockStatusChange(), aSockId: id: %d, aStatus: %d, aError: %d", |
|
128 aSockId, ( TInt )aStatus, aError ); |
|
129 iOwner.SockStatusChange( aSockId, aStatus, aError ); |
|
130 } |
|
131 else if ( aStatus == CCRSock::EIdle ) |
|
132 { |
|
133 if ( iSentViaSock2 && iSentViaSock1 ) |
|
134 { |
|
135 |
|
136 if ( !iCleanUp->IsActive() ) |
|
137 { |
|
138 TCallBack cb( CleanupCallBack, this ); |
|
139 iCleanUp->Set( cb ); |
|
140 iCleanUp->CallBack(); |
|
141 } |
|
142 } |
|
143 else |
|
144 { |
|
145 // here send |
|
146 TDesC8* packet = NULL; |
|
147 if ( iMySSRC ) |
|
148 { |
|
149 // construct valid packet only if we have SSRC |
|
150 TBuf8<8> receiverReport; |
|
151 receiverReport.Zero(); |
|
152 receiverReport.AppendFill( 0x0, 7 ); |
|
153 TUint8 *rrPtr = const_cast<TUint8 *>( receiverReport.PtrZ() ); |
|
154 rrPtr[0] = 0x80; // version and count |
|
155 rrPtr[1] = 0xC9; // packet type 201 = rr |
|
156 rrPtr[2] = 0x00; // packet len high bits = 0 |
|
157 rrPtr[3] = 0x01; // packet len low bits = 1 e.g. len = 1 |
|
158 BigEndian::Put32( ( TUint8* )( &rrPtr[4] ), iMySSRC ); |
|
159 packet = &receiverReport; |
|
160 } |
|
161 else |
|
162 { |
|
163 // Atleast construct a kind-of valid packet. |
|
164 TBuf8<12> appPacket; |
|
165 appPacket.Zero(); |
|
166 appPacket.AppendFill( 0x0, 11 ); |
|
167 TUint8 *rrPtr = const_cast<TUint8 *>( appPacket.PtrZ() ); |
|
168 rrPtr[0] = 0x80; // version and subtype |
|
169 rrPtr[1] = 0xCC; // packet type 204 = APP |
|
170 rrPtr[2] = 0x00; // packet len high bits = 0 |
|
171 rrPtr[3] = 0x01; // packet len low bits = 1 e.g. len = 1 |
|
172 // this is not a valid SSRC |
|
173 BigEndian::Put32( ( TUint8* )( &rrPtr[4] ), iMySSRC ); |
|
174 rrPtr[8] = 0x44; // ASCII: D |
|
175 rrPtr[9] = 0x56; // ASCII: V |
|
176 rrPtr[10] = 0x52; // ASCII: R |
|
177 rrPtr[11] = 0x45; // ASCII: E |
|
178 packet = &appPacket; |
|
179 } |
|
180 if ( aSockId == 1 && iSock1 && !iSentViaSock1 ) |
|
181 { |
|
182 iSock1->SendData( *packet ); |
|
183 iSentViaSock1 = ETrue; |
|
184 } |
|
185 else if ( aSockId == 2 && iSock2 && !iSentViaSock2 ) |
|
186 { |
|
187 iSock2->SendData( *packet ); |
|
188 iSentViaSock2 = ETrue; |
|
189 } |
|
190 else |
|
191 { |
|
192 // None |
|
193 } |
|
194 } |
|
195 } |
|
196 } |
|
197 |
|
198 //----------------------------------------------------------------------------- |
|
199 // CCRPunchPacketSender::CleanupCallBack() |
|
200 //----------------------------------------------------------------------------- |
|
201 TInt CCRPunchPacketSender::CleanupCallBack( TAny* aSelf ) |
|
202 { |
|
203 LOG( "CCRPunchPacketSender::CleanupCallBack()" ); |
|
204 |
|
205 CCRPunchPacketSender* self = static_cast<CCRPunchPacketSender*>( aSelf ); |
|
206 delete self->iSock1; self->iSock1 = NULL; |
|
207 delete self->iSock2; self->iSock2 = NULL; |
|
208 self->iOwner.PunchPacketsSent( self ); |
|
209 return KErrNone; |
|
210 } |
|
211 |
|
212 // End of File |