|
1 /* |
|
2 * Copyright (c) 2004-2005 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 "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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __RTPSESSION_H |
|
22 #define __RTPSESSION_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <e32base.h> |
|
26 #include <rtpheader.h> |
|
27 #include "rtputil.h" |
|
28 #include "rtptimer.h" |
|
29 #include "rtpsdes.h" |
|
30 #include "rtpsessiondef.h" |
|
31 |
|
32 //Packet |
|
33 #include "rtppacket.h" |
|
34 #include "rtppacketext.h" |
|
35 #include "rtppacketparam.h" |
|
36 |
|
37 //Stream |
|
38 #include "rtpstreamdef.h" |
|
39 #include "rtptranstream.h" |
|
40 #include "rtprecvstream.h" |
|
41 #include "rtpasignuniqueid.h" |
|
42 |
|
43 //Comm |
|
44 #include "rtpcomm.h" |
|
45 #include "rtpcommdef.h" |
|
46 |
|
47 |
|
48 /** |
|
49 * class for rtp session. |
|
50 * |
|
51 * @lib RtpService.dll |
|
52 */ |
|
53 class CRtpSession : |
|
54 public CBase, |
|
55 public MReceivedNotify, |
|
56 public MTimeOutNotify, |
|
57 public MSsrcCheckCallback |
|
58 { |
|
59 |
|
60 public: |
|
61 |
|
62 enum TStreamType |
|
63 { |
|
64 ETxStream = 0, |
|
65 ERxStream |
|
66 }; |
|
67 |
|
68 enum |
|
69 { |
|
70 ECallBack, |
|
71 ETimeOut |
|
72 }; |
|
73 |
|
74 public: // new functions |
|
75 static CRtpSession* NewL( const TCreateSessionParams& aParams, |
|
76 TUint& aPort, |
|
77 TBool aEnableRtcp, |
|
78 const TRtcpParams* aRtcpParams, |
|
79 RSocketServ& aSocketServ, |
|
80 RConnection& aRConn, |
|
81 const TRtpId aSessionId, |
|
82 const CRtpSDES* aSdes, |
|
83 const TUint32* aProfileRTPTimeRates, |
|
84 const TBool aStandardRtp, |
|
85 const RLibrary& aLibrary, |
|
86 MRtpErrNotify& aErrNotify, |
|
87 MRtpAsignUniqueID& aAssignUniqueID ); |
|
88 |
|
89 ~CRtpSession(); |
|
90 |
|
91 TRtpSSRC SSRC() const; |
|
92 |
|
93 TInt StartSession(); |
|
94 |
|
95 TInt SetRemoteAddress( TInetAddr& aRemoteAddr ); |
|
96 TInt SetRemoteRtcpAddress( TInetAddr& aRemoteAddr ); |
|
97 |
|
98 TInt CreateReceiveStreamL( TRtpId aStreamId, const TRtpPayloadType aPayloadType ); |
|
99 |
|
100 TInt CreateTransmitStreamL( TRtpId aStreamId, const TRtpPayloadType aPayloadType, TUint32& aSSRC ); |
|
101 |
|
102 TInt CreateTransmitStreamExtL( TRtpId aStreamId, const TRtpPayloadType aPayloadType, const TUint32 aSSRC ); |
|
103 |
|
104 void CloseStream( TRtpId aStreamId ); |
|
105 |
|
106 void ResetTxStreamStats(); |
|
107 void ResetRxStreamStats(); |
|
108 |
|
109 TInt RegisterRtpObserver( MRtpObserver& aObserver ); |
|
110 void UnregisterRtpObserver(); |
|
111 |
|
112 TInt SetNonRTPDataObserver( MNonRTPDataObserver* aNonRTPDataObserver ); |
|
113 |
|
114 TInt SendRtpPacket( TRtpId aTranStreamId, const TRtpSendHeader& aHeaderInfo, |
|
115 const TDesC8& aPayloadData ); |
|
116 |
|
117 TInt SendRtpPacket( TRtpId aTranStreamId, |
|
118 const TRtpSendHeader& aHeaderInfo, |
|
119 const TDesC8& aPayloadData, |
|
120 TRequestStatus& aStatus ); |
|
121 |
|
122 TInt SendRtpPacket( const TRtpSendHeader& aHeaderInfo, const TDesC8& aPayloadData ); |
|
123 |
|
124 TInt SendRtpPacket( const TRtpSendHeader& aHeaderInfo, const TDesC8& aPayloadData, |
|
125 TRequestStatus& aStatus ); |
|
126 |
|
127 TInt SendRtpPacket( TRtpId aTranStreamId, |
|
128 TRtpSequence aSequenceNum, |
|
129 const TRtpSendHeader& aHeaderInfo, |
|
130 const TDesC8& aPayloadData, |
|
131 TRequestStatus& aStatus ); |
|
132 |
|
133 void SendData( TBool aUseRTPSocket, |
|
134 const TDesC8& aData, |
|
135 TRequestStatus& aStatus ); |
|
136 |
|
137 void CancelSend(); |
|
138 |
|
139 TInt RegisterRtcpObserver( MRtcpObserver& aObserver ); |
|
140 void UnregisterRtcpObserver(); |
|
141 TInt SendRtcpByePacketL( TRtpId aTranStreamId, const TDesC8& aReason ); |
|
142 TInt SendRtcpAppPacketL( TRtpId aTranStreamId, const TRtcpApp& aApp ); |
|
143 TInt SendRtcpSrPacketL( TRtpId aTranStreamId ); |
|
144 TInt SendRtcpRrPacketL( TRtpId aRecvStreamId ); |
|
145 |
|
146 RSocket* GetRtpSocket(); |
|
147 RSocket* GetRtcpSocket(); |
|
148 |
|
149 TInt GetStreamStatistics( TRtpId aStreamId, TRtpPeerStat& aStat ); |
|
150 TInt SetRtcpParameters( const TRtcpParams& aRtcpParams ); |
|
151 |
|
152 TRtpId GetSessionId(); |
|
153 |
|
154 TInt StopRtcpSending(); |
|
155 TInt ResumeRtcpSending(); |
|
156 |
|
157 /** |
|
158 * Gets the status of automatic RTCP sending. |
|
159 * @param TBool& aAutoSending - ETrue: RTCP atuo sending is on |
|
160 * EFalse: RTCP auto sending is off |
|
161 * @return TInt - KErrNone if successful; KErrNotSupported if RTCP |
|
162 * disabled; system wide error code otherwise |
|
163 */ |
|
164 TInt IsRtcpSendingSuspended( TBool& aAutoSending ); |
|
165 |
|
166 public: // from MSsrcCheckCallback |
|
167 /** |
|
168 * Checks if a newly received SSRC collides with the SSRC's of the |
|
169 * existing Tx streams in this session, and reacts appropriately. |
|
170 * This is SSRC collision handling. |
|
171 * @param aSSRC a newly received SSRC |
|
172 */ |
|
173 TInt CheckRemoteSsrcL( TRtpSSRC& aSSRC ); |
|
174 TBool CheckRemoteAddr(); |
|
175 |
|
176 public: // from MTimeOutNotify |
|
177 void OnExpiredL( TInt aStatus ); |
|
178 |
|
179 public: // from MReceivedNotify |
|
180 void OnRtpReceivedL(); |
|
181 void OnRtcpReceivedL(); |
|
182 void OnReceptionError( TPortType aPort, TInt aError ); |
|
183 void OnPacketRejected(TPortType aPort); |
|
184 TBool IsSrtp(); |
|
185 protected: // construction |
|
186 CRtpSession( const TRtpId aSessionId, |
|
187 const TUint32* aProfileRTPTimeRates, |
|
188 const TBool aStandardRtp, |
|
189 MRtpErrNotify& aErrNotify, |
|
190 const CRtpSDES* aSdesInfo, |
|
191 MRtpAsignUniqueID& aAssignUniqueID ); |
|
192 |
|
193 void ConstructL( const TCreateSessionParams& aParams, |
|
194 TUint& aPort, |
|
195 TBool aEnableRtcp, |
|
196 const TRtcpParams* aRtcpParams, |
|
197 RSocketServ& aSocketServ, |
|
198 RConnection& aRConn, |
|
199 const RLibrary& aLibrary, |
|
200 MRtpErrNotify& aErrNotify ); |
|
201 void FindRtpRxStreamSSRC(TRtpSSRC& aSSRC); |
|
202 TInt FindStream( const TRtpId aMagicKey, TUint& aStreamAddress ); |
|
203 TInt IssueRtpRecv(); |
|
204 virtual void SendSRTCPReportL(TRtpSSRC aSSRC); |
|
205 void AverageRtcpSize( TUint aRtcpReportSize ); |
|
206 TInt IssueRtcpRecv(); |
|
207 |
|
208 private: |
|
209 TInt InitialiseRtcp( const TRtcpParams* aParams ); |
|
210 |
|
211 |
|
212 |
|
213 void ScheduleRtcpSendL(); |
|
214 void StartReceiveRtcpPacket(); |
|
215 void StopReceiveRtcpPacket(); |
|
216 |
|
217 TBool DoBuildSendRTCPReportIfNotSentL(); |
|
218 void DoBuildSendRTCPReportL(); |
|
219 TBool ShouldBuildEmptyRR( CRtpTranStream* aTempTranStream ); |
|
220 |
|
221 /** |
|
222 * Determines the source count and length before an RTCP report is sent |
|
223 * @param aSourceCount reference to the source count variable to update |
|
224 * @param aLength reference to the packet length variable to update |
|
225 * @param aRxActive a list of active/not active streams |
|
226 * @return None |
|
227 */ |
|
228 void DetermineSourceCountAndLength( TInt& aSourceCount, |
|
229 TInt& aLength, |
|
230 TBool aRxActive[] ); |
|
231 |
|
232 /** |
|
233 * Determines parameters before an RTCP report with SR (RR) and SDES |
|
234 * sections is sent. |
|
235 * @param aTranStream The stream that will send the RTCP report |
|
236 * @param aStreamParam pointer to the stream parameters |
|
237 * @param aInitParam pointer to the initialisation parameters |
|
238 * @param aRxActive a list of active/not active streams |
|
239 * @return None |
|
240 */ |
|
241 void SetParamsForFullRTCPReport( CRtpTranStream* aTranStream, |
|
242 TRtpPacketStreamParam* aStreamParam, |
|
243 TRtpPacketIOParam* aInitParam, |
|
244 TBool aRxActive[] ); |
|
245 void BuildSendRTCPReportL(); |
|
246 TInt BuildRTCPReport( CRtpTranStream* tempStream, TInt aLastReport ); |
|
247 void BuildSrSection( CRtpTranStream* aTempTranStream ); |
|
248 void BuildRrSection( TInt aNumRcvStreams, |
|
249 TBool aRxActive[KMaxNumActiveRcvStreams], |
|
250 TInt aLastReport ); |
|
251 void BuildEmptyRr( CRtpTranStream* aTempTranStream ); |
|
252 void BuildSdesSection( CRtpTranStream* aTempTranStream ); |
|
253 void SendRTCPReport(); |
|
254 void CreateSDES( TInt aFCNameOnly, TRtpSSRC aSSRC ); |
|
255 |
|
256 |
|
257 /** |
|
258 * Launches the processing of individual sections of RTCP reports. |
|
259 * @param extractParam pointer to the stream parameters |
|
260 * @param aSourceSSRC The synchronisation source value of the sender |
|
261 * @return Symbian OS error code |
|
262 */ |
|
263 TRtpRtcpEnum ProcessOneRTCPReportSectionL( |
|
264 const TRtpPacketIOParam& aExtractParam, |
|
265 TRtpSSRC aSourceSSRC ); |
|
266 /** |
|
267 * Processes an RTCP report. |
|
268 * @return An RTP-specific error code |
|
269 */ |
|
270 TRtpRtcpEnum ProcessRTCPReportL(); |
|
271 |
|
272 /** |
|
273 * Processes the SR section of an RTCP report. |
|
274 * @return An RTP-specific error code |
|
275 */ |
|
276 TRtpRtcpEnum ProcessSRSectionL( TInt aSourceCount ); |
|
277 |
|
278 /** |
|
279 * Processes the RR section of an RTCP report. |
|
280 * @return An RTP-specific error code |
|
281 */ |
|
282 TRtpRtcpEnum ProcessRRSectionL( TInt aSourceCount ); |
|
283 |
|
284 /** |
|
285 * Processes the SDES section of an RTCP report. |
|
286 * @return An RTP-specific error code |
|
287 */ |
|
288 TRtpRtcpEnum ProcessSDESSectionL( TRtpSSRC aSourceSSRC ); |
|
289 |
|
290 /** |
|
291 * Processes the BYE section of an RTCP report. |
|
292 * @return An RTP-specific error code |
|
293 */ |
|
294 TRtpRtcpEnum ProcessBYESectionL(); |
|
295 |
|
296 /** |
|
297 * Processes the APP section of an RTCP report. |
|
298 * @return An RTP-specific error code |
|
299 */ |
|
300 TRtpRtcpEnum ProcessAPPSectionL( TInt aTotalPacketLen, TInt aSubType ); |
|
301 |
|
302 /** |
|
303 * Processes the data contained in an SDES section. |
|
304 * @return An RTP-specific error code |
|
305 */ |
|
306 TRtpRtcpEnum ProcessSDESDataL( TRtpPacketStreamParam& aStreamParam, |
|
307 TRtpPacketIOParam& aExtractParam, |
|
308 TRtpSSRC aSourceSSRC ); |
|
309 |
|
310 /** |
|
311 * Gets the SDES values from the data contained in an SDES section. |
|
312 * Either aRecvStream or aSourceSdes is always NULL. |
|
313 * @param aTargetSdes the SDES in which the data will be stored |
|
314 * @param aRecvStream the stream that contains the SDES |
|
315 * @param aSourceSdes the SDES in which the data resides |
|
316 * @return KErrNone if successful, a system-wide error code otherwise |
|
317 */ |
|
318 TInt GetSDESFromSDESData( TRtpSdesParams* aTargetSdes, |
|
319 const CRtpRecvStream* aRecvStream, |
|
320 CRtpSDES* aSourceSdes ); |
|
321 |
|
322 /** |
|
323 * Logs the SDES data from the data contained in an SDES section. |
|
324 * @param aStreamParam stream parameters |
|
325 * @param aRecvStream the receiving stream |
|
326 * @param aSdes the new SDES |
|
327 * @param aSdesSession indicates whether the SDES was assigned to the |
|
328 * session |
|
329 */ |
|
330 #ifdef _DEBUG |
|
331 void LogSDESData( const TRtpPacketStreamParam& aStreamParam, |
|
332 const CRtpRecvStream* aRecvStream, |
|
333 const CRtpSDES* aSdes, |
|
334 const TBool aSdesSession ); |
|
335 #endif |
|
336 TRtpSSRC GetUniqueSSRC(); |
|
337 TRtpSSRC GenerateSSRC(); |
|
338 TInt AddStream( const TStream aArrayID, TStreamType aStreamType ); |
|
339 |
|
340 TInt FindStream( const TRtpId aMagicKey, TUint& aStreamAddress, |
|
341 TStreamType& aStreamType ); |
|
342 TInt RemoveStream( const TRtpId aMagicKey, TStreamType& aStreamType ); |
|
343 void RemoveAllStreams(); |
|
344 TInt MatchSSRCToStream( TUint& aRcvStreamAddress, TRtpSSRC aSSRC, |
|
345 TStreamType& aStreamType ); |
|
346 TInt FindRtpRxStreamL(); |
|
347 TInt AssignRtpRxStreamL(); |
|
348 |
|
349 TInt StreamSendBYEPacket(); |
|
350 TInt StreamSendAPPPacket(); |
|
351 TBool FindStreamForSSRC( TRtpSSRC aSSRC ); |
|
352 /** |
|
353 * Finds if a send stream is already using the given SSRC |
|
354 * @param aSSRC the synchronisation source value |
|
355 * @param a pointer to a stream pointer. If a Tx stream is found for |
|
356 * the specified SSRC, the stream pointer contains the address of the |
|
357 * Tx stream when this function returns. |
|
358 */ |
|
359 TBool FindTxStreamForSSRC( TRtpSSRC aSSRC, |
|
360 CRtpTranStream** streamPointerPointer ); |
|
361 |
|
362 TBool RcvStreamActive( TInt aIndex ); |
|
363 TBool AnyRcvStreamReceivedRtpPacket(); |
|
364 TBool RcvStreamReceivedRtpPacket( TInt aIndex ); |
|
365 CRtpRecvStream* GetRcvStreamByIndex( TInt aIndex ); |
|
366 |
|
367 void RedistributeBandwidth(); |
|
368 |
|
369 CRtpSDES* DoAddSdesToArrayL( TRtpPacketIOParam* aExtractParam ); |
|
370 TBool AddSdesToArrayL( TUint& aSdesAddress, TRtpPacketIOParam* extractParam ); |
|
371 |
|
372 /** |
|
373 * Compares the specified SDES values with the ones in the parameters |
|
374 * and updates the SDES where the values differ |
|
375 * @param aTempSdes the target SDES |
|
376 * @param aExtractParam the parameters to compare with |
|
377 * @param aUpdateCName indicates whether to include the CName |
|
378 * @return ETrue if the SDES was updated |
|
379 */ |
|
380 TBool CompareAndUpdateSdes( CRtpSDES* aTempSdes, |
|
381 TRtpPacketIOParam* aExtractParam, |
|
382 TBool aUpdateCName ); |
|
383 TInt RemoveSdesFromArray( TRtpSSRC aSSRC ); |
|
384 |
|
385 void NextRtcpInterval(); |
|
386 |
|
387 void DeallocateMemoryForSdes( TRtpPacketIOParam* aParam ); |
|
388 |
|
389 // Methods for getting random numbers |
|
390 TInt Random(); |
|
391 TReal Random64(); |
|
392 void SendRTCPByewithBanedSSRCL(); |
|
393 TBool CheckifBanded(); |
|
394 void CreateNewRecvStreamL(); |
|
395 |
|
396 |
|
397 private: |
|
398 TBool iStandardRtp; |
|
399 TRtpId iSessionId; // session ID value |
|
400 |
|
401 |
|
402 TInetAddr iRemoteAddr[KMaxPorts]; // store here remote addresses |
|
403 TBool iRemoteAddrSet; |
|
404 |
|
405 // default values for this session when no transmit stream has been created. |
|
406 TRtpSSRC iDefaultSSRC; // default SSRC value |
|
407 |
|
408 const CRtpSDES* iLocalSdes; // iManager->GetSdes(); |
|
409 TRtpSdesParams* iNewSdes; // Sdes to send to observer |
|
410 TInt iSendSdesCounter; // keeps track of SDES packets sent |
|
411 |
|
412 protected: |
|
413 CRtpPacket* iPktSnd; |
|
414 CRtpPacket* iPktRcv; |
|
415 TPtr8 iRtpRecvBuf; // receive buf of iPktRtpRcv; |
|
416 TPtr8 iRtcpRecvBuf; // receive buf of iPktRtcpRcv; |
|
417 CRtpComm* iCommNet; |
|
418 MRtpPacketExt* iPktExtSnd; |
|
419 TBool iIsSrtp; |
|
420 TBool iRtcpEnabled; |
|
421 CRtpTimer* iSndRtcpTimer; // timer for period sending RTCP packets |
|
422 |
|
423 // packets allocated for reporting, sending, receiving |
|
424 CRtpPacket* iPktRtcpSnd; |
|
425 CRtpPacket* iPktRtcpRcv; |
|
426 |
|
427 |
|
428 |
|
429 |
|
430 // packets allocated for extended rtp packet |
|
431 |
|
432 MRtpPacketExt* iPktExtRcv; |
|
433 |
|
434 // Flags |
|
435 TBool iFirstRTCPSent; // flag that indicates if the first RTCP Packet has been sent |
|
436 TBool iFPortsInit; // indicates if the local port has been initialized |
|
437 |
|
438 TUint16 iNumOfTxStreams; // total number of send streams |
|
439 TUint16 iNumOfRxStreams; // total number of receive streams |
|
440 CArrayFixFlat<TStream>* iStreamTxArray; //array to keep Transmit stream objects |
|
441 CArrayFixFlat<TStream>* iStreamRxArray; //array to keep Receive stream objects |
|
442 CArrayPtrFlat<CRtpSDES>* iSdesArray; //array to keep remote participants SDES object |
|
443 RArray<TRtpSSRC> iRxSSRCArray; //array to keep ReceiveStreamSSRC Array |
|
444 |
|
445 const TUint32* iProfileRTPTimeRates; |
|
446 TReal iAverageRtcpSize; // average RTCP report size updated everytime a RTCP report is send or/and received |
|
447 TUint iBandWidth; // session bandwidth |
|
448 TReal iFraction; // fraction of the session bandwidth to be used for RTCP report |
|
449 TUint iRtcpTimeInterval; // RTCP report interval (milliseconds) |
|
450 TUint iTotalParticipantsSession;// keeps track of total participants in session |
|
451 |
|
452 MRtpObserver* iRtpObserver; |
|
453 MRtcpObserver* iRtcpObserver; |
|
454 MNonRTPDataObserver* iNonRTPDataObserver; |
|
455 MRtpErrNotify& iErrNotify; |
|
456 MRtpAsignUniqueID& iAssignUniqueID; |
|
457 |
|
458 |
|
459 TBool iSessionStarted; |
|
460 TInt iSSRCJumps; |
|
461 TInt iRtcpErrors; |
|
462 |
|
463 TBool iRtcpSendingSuspended; |
|
464 TInt64 iSeed; |
|
465 |
|
466 private: |
|
467 #ifdef EUNIT_TESTING |
|
468 friend class UT_CRtpAPI; |
|
469 friend class UT_CRtpSession; |
|
470 friend class UT_CRtpSessionSrtp; |
|
471 #endif |
|
472 #if defined( _DEBUG ) && defined( RTP_UNIT_TEST ) |
|
473 friend class CRtpUtRtpSession; |
|
474 #endif |
|
475 }; |
|
476 |
|
477 #endif // __RTPSESSION_H |
|
478 |
|
479 // End of File |