realtimenetprots/rtp/rtpcore/test/trtpsocket/src/trtpcoreserver.h
changeset 0 307788aac0a8
child 15 8248b03a2669
equal deleted inserted replaced
-1:000000000000 0:307788aac0a8
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Header for class specific to rtp unit tests
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20  @internalComponent
       
    21 */
       
    22 
       
    23 #if (!defined T_RTPCORESERVER_H__)
       
    24 #define T_RTPCORESERVER_H__
       
    25 #include <testexecuteserverbase.h>
       
    26 
       
    27 #if (!defined __DATA_CAGING__)
       
    28 IMPORT_C TInt NewServer();
       
    29 #endif
       
    30 
       
    31 #include "rtpcontroller.h"
       
    32 #include "rtcppacket.h"
       
    33 #include "rtppacket.h"
       
    34 
       
    35 
       
    36 class CTRtpCoreStep;
       
    37 
       
    38 class CTRtpCoreServer : public CTestServer
       
    39 	{
       
    40 public:
       
    41 	static CTRtpCoreServer* NewL();
       
    42 	virtual CTestStep* CreateTestStep(const TDesC& aStepName);
       
    43 	~CTRtpCoreServer();
       
    44 
       
    45 	// Member functions used by test steps
       
    46 	/*
       
    47 	static void StopScheduler(CTrtpServer* aPtr, const TRtpEvent& aEvent);
       
    48 	*/
       
    49 	static TBool CompareRtpHeadersFromBuf(TDesC8& buf1,TDesC8& buf2);
       
    50 	static TBool CompareRtpHeaderWithBuf(TRtpFixedHdrMemLayout& aHeader,TDesC8& aBuf);
       
    51 	static TBool CompareRtcpHeadersFromBuf(TDesC8& buf1,TDesC8& buf2);
       
    52 	static TBool CompareRtcpHeaderWithBuf(TRtcpFixedHdrMemLayout& aHeader,TDesC8& aBuf);
       
    53 	// Members used by the steps
       
    54 	
       
    55 	TBool iOom;
       
    56 	CTRtpCoreStep* iCurrentStep;
       
    57 	TBool iStopping;
       
    58 	TInt iStopCount;
       
    59 	
       
    60 	RConnection iConnection;
       
    61 	RSubConnection iSubConnection;
       
    62 	
       
    63 	// generic socket, e..g send
       
    64 	RSocket iSocket;
       
    65 	// for connected/bind socket use cases
       
    66 	RSocket iRtpSocket;
       
    67 	RSocket iRtcpSocket;
       
    68 	TBool iUsingConnectedSocket;
       
    69 
       
    70 	CActiveScheduler* iScheduler;
       
    71 	RSocketServ iSocketServer;
       
    72 	CRtpControllerBase* iController;
       
    73 	CRtpControllerBase* iSendController;
       
    74  private:
       
    75 	CTRtpCoreServer();
       
    76 	};
       
    77 
       
    78 
       
    79 class CWaiter : public CBase, public MRtpDataObserver
       
    80 	{
       
    81  public:
       
    82 	static CWaiter* NewLC(CTRtpCoreServer* aServer);
       
    83 
       
    84 	~CWaiter();
       
    85 	
       
    86 	void DataAvailable(TInt aErrorCode);
       
    87 	
       
    88  private:
       
    89 	CWaiter(CTRtpCoreServer* aServer) : iServer(aServer) 
       
    90 			{
       
    91 			};
       
    92 
       
    93 	CTRtpCoreServer* iServer;
       
    94 	
       
    95  public:
       
    96     TRequestStatus iStatus;
       
    97 	};
       
    98 
       
    99 struct TRtpFixedHeader
       
   100   	{
       
   101   	TUint8 iVersion:2;		// protocol version
       
   102   	TUint8 iP:1;			// padding flag
       
   103   	TUint8 iX:1;			// header extension flag
       
   104   	TUint8 iCC:4;			// CSRC count
       
   105   	TUint8 iM:1;			// marker bit
       
   106   	TUint8 iPT:7;			// payload type
       
   107   	TUint16	iSequenceNo;	// sequence number
       
   108   	TUint32	iTimeStamp;		// timestamp
       
   109   	TUint32	iSSRC;			// synchronization source
       
   110   	//RArray<TUint32> iCSRC; // optional CSRC list
       
   111   	TRtpFixedHeader();
       
   112   	};
       
   113 
       
   114 inline TRtpFixedHeader::TRtpFixedHeader()
       
   115   	{
       
   116   	iVersion = KRtpVersion2;	// protocol version = 2
       
   117   	iP = 0;						// padding flag
       
   118   	iX = 0;						// header extension flag
       
   119   	iCC = 0;					// CSRC count
       
   120   	iM = 0;						// marker bit
       
   121   	iPT = 0;					// payload type
       
   122   	iSequenceNo = 0;			// sequence number
       
   123   	iTimeStamp = 0;				// timestamp
       
   124   	iSSRC = 0;					// synchronization source
       
   125   	}
       
   126 
       
   127 class CRtpFixedHeader
       
   128    	{
       
   129    public:
       
   130    	CRtpFixedHeader(TDes8& packet);
       
   131    	CRtpFixedHeader();
       
   132    	~CRtpFixedHeader();
       
   133    	void SetVersion(TUint aVersion);
       
   134    	void SetCSRCCount(TUint aCC);
       
   135    	void SetSequenceNumber(TUint16 aNo);
       
   136    	void SetSSRC(TUint32 aSSRC);
       
   137    	void SetPadding(TBool aPadding);
       
   138    	void SetExtension(TBool aExtension);
       
   139    	void SetTimeStamp(TUint32 aTime);
       
   140    
       
   141    	TUint32 SSRC();
       
   142    	TUint8 CC();
       
   143    	TBool IsMarker();
       
   144    	TBool IsPadding();
       
   145    	TBool IsExtension();
       
   146    	TUint8 PayloadType();
       
   147    	TUint8 Version();
       
   148    	TUint16 SequenceNumber();
       
   149    	TUint32 TimeStamp();
       
   150    	TUint32 CSRCs(TInt aIndex);
       
   151 private:
       
   152    	
       
   153    	TRtpFixedHeader iHeader;
       
   154    	};
       
   155 
       
   156 // RTCP //
       
   157 // Reception report block
       
   158 struct TRtcpRRBlock
       
   159 	{
       
   160 	TUint32 iSSRC;	// data source being reported
       
   161     TUint iFractionLost:8;	// fraction lost since last SR/RR
       
   162 	TInt iCumulLost:24;	// cumul. no. pkts lost (signed!)
       
   163 	TUint32 iExtendedLastSeq;	// extended last seq. no. received
       
   164     TUint32 iJitter;	// interarrival jitter
       
   165     TUint32 iLastSR;	// last SR packet from this source
       
   166     TUint32 iDSLR;	// delay since last SR packet
       
   167 	};
       
   168 
       
   169 // SDES item
       
   170 struct TRtcpSDESItem
       
   171 	{
       
   172 	TUint8 iType;		// type of item (rtcp_sdes_type_t)
       
   173 	TUint8 iLength;		// length of item (in octets)
       
   174 	HBufC8* iData;		// text, not null-terminated 
       
   175    };
       
   176 
       
   177 
       
   178 //One RTCP packet
       
   179 struct TRtcpPacketStruct
       
   180 	{
       
   181 	struct
       
   182 		{
       
   183 		// common part
       
   184 		// protocol version
       
   185 		TUint iVersion:2;
       
   186 		// padding flag
       
   187 		TUint iPadding:1;
       
   188 		// varies by packet type
       
   189 		TUint iCount:5;
       
   190 		// RTCP packet type
       
   191 		TUint iPacketType:8;
       
   192 		// pkt len in words, w/o this word
       
   193 		TUint16 iLength;
       
   194 		} common;
       
   195 	union 
       
   196 		{
       
   197 		// sender report (SR)
       
   198 		struct 
       
   199 			{
       
   200 			TUint32 iSSRC;     // sender generating this report
       
   201 			TUint32 iNtpSeconds;  // NTP timestamp
       
   202 			TUint32 iNtpFraction;
       
   203 			TUint32 iRtpTimeStamp;   // RTP timestamp
       
   204 			TUint32 iPacketsSent;    // packets sent
       
   205 			TUint32 iOctetsSent;    // octets sent
       
   206             TRtcpRRBlock iRR[1];  // variable-length list
       
   207 			} sr;
       
   208 
       
   209 		// reception report (RR)
       
   210 		struct 
       
   211 			{
       
   212 			TUint32 iSSRC;		// receiver generating this report
       
   213 			TRtcpRRBlock iRR[1];	// variable-length list
       
   214 			} rr;
       
   215 
       
   216 		// source description (SDES)
       
   217 		struct
       
   218 			{
       
   219 			TUint32 iSRC;			// first SSRC/CSRC
       
   220 			TRtcpSDESItem iItem[1];	// list of SDES items
       
   221 			} sdes;
       
   222 
       
   223 		// BYE
       
   224 		struct 
       
   225 			{
       
   226 			TUint32 iSRC[1];   // list of sources
       
   227                /* can't express trailing text for reason */
       
   228            } bye;
       
   229 
       
   230 		// App
       
   231 		struct
       
   232 			{
       
   233 			TUint32 iSRC;
       
   234 			HBufC8* iAppName;
       
   235 			HBufC8* iAppData;
       
   236 			} app;
       
   237 		
       
   238        } specific;
       
   239    };
       
   240 
       
   241 class CRtcpPacketTest
       
   242    	{
       
   243    public:
       
   244    	CRtcpPacketTest(TDes8& aPacket);
       
   245    	//CRtcpRRPacket();
       
   246    	~CRtcpPacketTest();
       
   247 	void Init(TDes8& aPacket);
       
   248 	TBool operator==(CRtcpPacketTest& aPacket);
       
   249 	TBool operator!=(CRtcpPacketTest& aPacket);
       
   250    	void SetVersion(TUint aVersion);
       
   251 	void SetPadding(TBool aPadding);
       
   252    	void SetCount(TUint8 aCount);
       
   253    	void SetPacketType(TRtcpPacketType aPacketType);
       
   254 	void SetLength(TUint16 aLength);
       
   255    	
       
   256 	TUint Version();
       
   257 	TBool IsPadding();
       
   258    	TUint8 Count();
       
   259 	TRtcpPacketType PacketType();
       
   260    	TUint16 Length();
       
   261    	
       
   262 protected:
       
   263    	
       
   264    	TRtcpPacketStruct iPacket;
       
   265    	};
       
   266 
       
   267 class CRtcpRRPacketTest : public CRtcpPacketTest
       
   268    	{
       
   269    public:
       
   270    	CRtcpRRPacketTest(TDes8& aPacket);
       
   271    	~CRtcpRRPacketTest();
       
   272 	TBool operator==(CRtcpRRPacketTest& aPacket);
       
   273 	TBool operator!=(CRtcpRRPacketTest& aPacket);
       
   274 	void SetSenderSSRC(TUint32 aSSRC);
       
   275 	void SetReportSSRC(TUint32 aSSRC);
       
   276 	void SetFraction(TUint8 aFraction);
       
   277 	void SetLost(TUint aLost);
       
   278 	void SetHighestSequence(TUint32 aSeq);
       
   279    	void SetJitter(TUint32 aJitter);
       
   280 	void SetLastSR(TUint32 aLastSR);
       
   281    	void SetDSLR(TUint32 aDSLR);
       
   282    
       
   283    	TUint32 SenderSSRC();
       
   284 	TUint32 ReportSSRC();
       
   285    	TUint8 Fraction();
       
   286 	TUint Lost();
       
   287 	TUint32 HighestSequence();
       
   288 	TUint32 Jitter();
       
   289 	TUint32 LastSR();
       
   290    	TUint32 DSLR();
       
   291    	};
       
   292 
       
   293 class CRtcpSRPacketTest : public CRtcpPacketTest
       
   294    	{
       
   295    public:
       
   296    	CRtcpSRPacketTest(TDes8& aPacket);
       
   297    	~CRtcpSRPacketTest();
       
   298 	TBool operator==(CRtcpSRPacketTest& aPacket);
       
   299 	TBool operator!=(CRtcpSRPacketTest& aPacket);
       
   300 	void SetSenderSSRC(TUint32 aSSRC);
       
   301 
       
   302 	void SetNtpMsb(TUint32 aNtpMsb);
       
   303 	void SetNtpLsb(TUint32 aNtpLsb);
       
   304 	void SetRtpTimeStamp(TUint32 aRtpTs);
       
   305 	void SetPacketCount(TUint32 aPacketCount);
       
   306 	void SetOctetCount(TUint32 aOctetCount);
       
   307 
       
   308 	void SetReportSSRC(TUint32 aSSRC);
       
   309 	void SetFraction(TUint8 aFraction);
       
   310 	void SetLost(TUint aLost);
       
   311 	void SetHighestSequence(TUint32 aSeq);
       
   312    	void SetJitter(TUint32 aJitter);
       
   313 	void SetLastSR(TUint32 aLastSR);
       
   314    	void SetDSLR(TUint32 aDSLR);
       
   315    
       
   316    	TUint32 SenderSSRC();
       
   317 
       
   318 	TUint32 NtpMsb();
       
   319 	TUint32 NtpLsb();
       
   320 	TUint32 RtpTimeStamp();
       
   321 	TUint32 PacketCount();
       
   322 	TUint32 OctetCount();
       
   323 
       
   324 	TUint32 ReportSSRC();
       
   325    	TUint8 Fraction();
       
   326 	TUint Lost();
       
   327 	TUint32 HighestSequence();
       
   328 	TUint32 Jitter();
       
   329 	TUint32 LastSR();
       
   330    	TUint32 DSLR();
       
   331    	};
       
   332 
       
   333 class CRtcpByePacketTest : public CRtcpPacketTest
       
   334    	{
       
   335    public:
       
   336    	CRtcpByePacketTest(TDes8& aPacket, TBool aIncreaseOffset = ETrue);
       
   337    	~CRtcpByePacketTest();
       
   338 	TBool operator==(CRtcpByePacketTest& aPacket);
       
   339 	TBool operator!=(CRtcpByePacketTest& aPacket);
       
   340 	void SetSSRC(TUint32 aSSRC);
       
   341 	void SetReasonTxt(TDesC8 aReason);
       
   342 
       
   343 	TInt ReadSROrRRAndSDESAndIncOffset(const TUint8** aPtr);
       
   344    
       
   345    	TUint32 SSRC();
       
   346 	TDesC8 ReasonTxt();
       
   347 
       
   348 	TInt iOffset;  
       
   349    	};
       
   350 
       
   351 class CRtcpAppPacketTest : public CRtcpPacketTest
       
   352    	{
       
   353    public:
       
   354 
       
   355 	static CRtcpAppPacketTest* NewL(TDes8& aPacket);
       
   356 	CRtcpAppPacketTest(TDes8& aPacket);
       
   357    	~CRtcpAppPacketTest();
       
   358 	TBool operator==(CRtcpAppPacketTest& aPacket);
       
   359 	TBool operator!=(CRtcpAppPacketTest& aPacket);
       
   360 	void SetSSRC(TUint32 aSSRC);
       
   361 	void SetAppData(const TDesC8& aAppData);
       
   362 	void SetAppName(const TDesC8& aAppName);
       
   363    
       
   364    	TUint32 SSRC();
       
   365 	const TDesC8& AppData();
       
   366 	const TDesC8& AppName();
       
   367 
       
   368    private :
       
   369  void ConstructL(TDes8& aPacket);
       
   370 
       
   371    	};
       
   372 
       
   373 
       
   374 
       
   375 class CItem : public CBase
       
   376 	{
       
   377 public:
       
   378 	static CItem* NewL( const TDesC8& aItem, TInt aType );
       
   379 	static TInt FlatCompare(const CItem& aItemOne, const CItem& aItemTwo ); //Assume that given CItem are a flat-data structures, compare 
       
   380 						//them byte by byte, and if all bytes are exactly same
       
   381 						//return true
       
   382 
       
   383 private:
       
   384 	void ConstructL( const TDesC8& aItem );
       
   385 	CItem( TUint8 aType );
       
   386 	~CItem();
       
   387 
       
   388 	TBool DoFlatCompare( const CItem& aItem ) const;
       
   389 
       
   390 private:
       
   391 	TUint8 iType;
       
   392 	HBufC8* iData;
       
   393 	};
       
   394 
       
   395 
       
   396 class CRtcpSDESPacketTest : public CRtcpPacketTest
       
   397    	{
       
   398 public:
       
   399 	static CRtcpSDESPacketTest* NewL(TDes8& aPacket);
       
   400 	CRtcpSDESPacketTest(TDes8& aPacket); //Should really be private
       
   401    
       
   402    	~CRtcpSDESPacketTest();
       
   403 	TBool operator==(CRtcpSDESPacketTest& aPacket);
       
   404 	TBool operator!=(CRtcpSDESPacketTest& aPacket);
       
   405 	
       
   406 	void SetSSRC(TUint32 aSSRC);
       
   407 	void SetType(TSDESType aType);
       
   408 	void SetData(const TDesC8& aData);
       
   409 
       
   410 	TInt SROrRRLength() const;
       
   411 	
       
   412 
       
   413 	TUint32 SSRC();
       
   414 	TSDESType Type();
       
   415 	const TDesC8& Data();
       
   416 
       
   417 	CItem* NextL();
       
   418 	CItem* First();
       
   419 
       
   420 private:   
       
   421    void ConstructL(TDes8& aPacket);
       
   422 
       
   423 private:
       
   424 	TInt iOffset;   
       
   425 	TInt iPktSize; //Assuming that there is no trailing BYE???
       
   426 	TInt iItemCount; 
       
   427 	CItem* iFirstItem;
       
   428 
       
   429 	const TUint8* iStartOfPkt;
       
   430 	TInt iCurrentOffset;
       
   431   	};
       
   432 
       
   433 
       
   434 class RSdesItemManager
       
   435 	{
       
   436 public:
       
   437 	RSdesItemManager();
       
   438 	~RSdesItemManager();
       
   439 
       
   440 	TInt Open();
       
   441 	void Close();
       
   442 
       
   443 	TInt StoreL( const TDesC8& aItem, TInt aItemType );
       
   444 	TInt SegregateItemsL();
       
   445 	TInt CompareSentAndReceivedValues();
       
   446 
       
   447 	void SetRecvBuffer( CRtcpSDESPacketTest * aSdesPkt ) { iSdesPkt = aSdesPkt; }
       
   448 
       
   449 private:
       
   450 	RPointerArray<CItem> iArray;//Sent items list
       
   451 	TInt iCurrentItem;
       
   452 
       
   453 	RPointerArray<CItem> iSegregatedItemsArray;//received items list
       
   454 	TInt iSegregatedItemsArrayID;
       
   455 
       
   456 	CRtcpSDESPacketTest * iSdesPkt;
       
   457 	};
       
   458 
       
   459 #endif