rtp/rtpstack/tsrc/ut_rtpstack/src/UT_CRtpAPI.cpp
branchRCL_3
changeset 43 b5e99d8877c7
parent 0 307788aac0a8
child 44 0dcb073356a5
equal deleted inserted replaced
41:f54bfd820e04 43:b5e99d8877c7
    66 #define RTP_EUNIT_ASSERT_RTP_ID( val1 )
    66 #define RTP_EUNIT_ASSERT_RTP_ID( val1 )
    67 EUNIT_ASSERT( val1 != KNullId );
    67 EUNIT_ASSERT( val1 != KNullId );
    68 #endif
    68 #endif
    69 
    69 
    70 _LIT8(KHello, "hello...testing");
    70 _LIT8(KHello, "hello...testing");
       
    71 _LIT8(KNoCName, "");
       
    72 
    71 // CONSTRUCTION
    73 // CONSTRUCTION
    72 UT_CRtpAPI* UT_CRtpAPI::NewL()
    74 UT_CRtpAPI* UT_CRtpAPI::NewL()
    73     {
    75     {
    74     UT_CRtpAPI* self = UT_CRtpAPI::NewLC();
    76     UT_CRtpAPI* self = UT_CRtpAPI::NewLC();
    75     CleanupStack::Pop();
    77     CleanupStack::Pop();
   138 
   140 
   139 void UT_CRtpAPI::Teardown(  )
   141 void UT_CRtpAPI::Teardown(  )
   140     {
   142     {
   141     iRtpAPI->Close();
   143     iRtpAPI->Close();
   142     delete iRtpAPI;
   144     delete iRtpAPI;
       
   145 	iRtpAPI = NULL;
   143 
   146 
   144     iStpAPI->Close();
   147     iStpAPI->Close();
   145     delete iStpAPI;
   148     delete iStpAPI;
   146     }
   149     iStpAPI = NULL;
       
   150 	}
   147 
   151 
   148 void UT_CRtpAPI::UT_CRtpAPI_NewLL(  )
   152 void UT_CRtpAPI::UT_CRtpAPI_NewLL(  )
   149     {
   153     {
   150     EUNIT_ASSERT( ETrue );
   154     EUNIT_ASSERT( ETrue );
   151     }
   155     }
   192     // Close the connection =)
   196     // Close the connection =)
   193     //iRtpAPI->Close();
   197     //iRtpAPI->Close();
   194 	iRtpAPI->CancelStart();
   198 	iRtpAPI->CancelStart();
   195     }
   199     }
   196 
   200 
   197 void UT_CRtpAPI::UT_CRtpAPI_StartConnection_1L(  )
   201 void UT_CRtpAPI::UT_CRtpAPI_StartConnection_OneL(  )
   198     {
   202     {
   199     //Synchronize
   203     //Synchronize
   200     TInt result(KErrNone);
   204     TInt result(KErrNone);
   201     TRtpSdesParams params;
   205     TRtpSdesParams params;
   202     
   206     
   978     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
   982     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
   979     User::WaitForRequest( status );
   983     User::WaitForRequest( status );
   980     EUNIT_ASSERT( KErrNone == status.Int() );
   984     EUNIT_ASSERT( KErrNone == status.Int() );
   981 	}
   985 	}
   982 
   986 
   983 void UT_CRtpAPI::UT_CRtpAPI_SendRtpPacket_3L()
   987 void UT_CRtpAPI::UT_CRtpAPI_SendRtpPacket_ThreeL()
   984     {
   988     {
   985     TInt result(KErrNone);
   989     TInt result(KErrNone);
   986     TRtpSdesParams params;
   990     TRtpSdesParams params;
   987      
   991      
   988     
   992     
  1418 
  1422 
  1419 void UT_CRtpAPI::ErrorNotify( TInt aErrCode ) 
  1423 void UT_CRtpAPI::ErrorNotify( TInt aErrCode ) 
  1420 	{
  1424 	{
  1421 	iErr= aErrCode;
  1425 	iErr= aErrCode;
  1422 	}
  1426 	}
       
  1427 	
  1423 //from Obs	
  1428 //from Obs	
  1424 void UT_CRtpAPI::RtpPacketReceived( TRtpId /*aStreamId*/, 
  1429 void UT_CRtpAPI::RtpPacketReceived( TRtpId /*aStreamId*/, 
  1425                                         const TRtpRecvHeader& /*aHeaderInfo*/, 
  1430                                         const TRtpRecvHeader& /*aHeaderInfo*/, 
  1426                                         const TDesC8& /*aPayloadData*/ ) 
  1431                                         const TDesC8& /*aPayloadData*/ ) 
  1427 	{
  1432 	{
  1467 	}
  1472 	}
  1468 void UT_CRtpAPI::SRTPMasterKeyStaleEvent(const CSRTPStream&  /*aStream*/)
  1473 void UT_CRtpAPI::SRTPMasterKeyStaleEvent(const CSRTPStream&  /*aStream*/)
  1469 {
  1474 {
  1470 	
  1475 	
  1471 }
  1476 }
       
  1477 
       
  1478 void UT_CRtpAPI::ReadyToSendRtpPacket( TRtpId /*aTranStreamId*/, TPtr8 &/*aPacket*/ )
       
  1479     {
       
  1480     // RTP Packet Callback received
       
  1481     iIsCallBackReceived = ETrue;
       
  1482     }
       
  1483 
       
  1484 
       
  1485 void UT_CRtpAPI::UT_CRtpAPI_RegisterRtpPostProcessingObserverL(  )
       
  1486     {
       
  1487     TInt result(KErrNone);
       
  1488     TRtpSdesParams params;
       
  1489     
       
  1490     result = iRtpAPI->OpenL( params, NULL, NULL, NULL );
       
  1491     EUNIT_ASSERT(result==KErrNone);
       
  1492     
       
  1493     TRequestStatus status;
       
  1494     result = iRtpAPI->StartConnection( status, KDefaultIap2 ); // KDefaultIap
       
  1495     RTP_EUNIT_ASSERT_EQUALS ( result, KErrNone );
       
  1496  // Wait until the connection is really up
       
  1497     User::WaitForRequest( status );
       
  1498 
       
  1499     //create session
       
  1500     TCreateSessionParams sessionParams;
       
  1501     sessionParams.iPriority = TCreateSessionParams::EPriorityStandard;
       
  1502     sessionParams.iSocketBufSize = KSocketBufSize;
       
  1503     TUint port( 5000 );
       
  1504     TBool enableRtcp( EFalse );
       
  1505     TRtcpParams rtcpParams;
       
  1506     rtcpParams.iRtcpFraction = 0.10;
       
  1507     rtcpParams.iRtcpTimeOut = 0;
       
  1508     rtcpParams.iSessionBWidth = 32000;
       
  1509 
       
  1510     TRtpId error( KNullId );
       
  1511     error = iRtpAPI->CreateSessionL( sessionParams,
       
  1512                                     port,
       
  1513                                     enableRtcp,
       
  1514                                     &rtcpParams );
       
  1515     RTP_EUNIT_ASSERT_RTP_ID( error );
       
  1516     
       
  1517     TRcvStreamParams recvparams;
       
  1518     recvparams.iPayloadType = 0;
       
  1519 
       
  1520     TRtpId error2( KNullId );
       
  1521     TInt err( KErrNone );
       
  1522     error2 = iRtpAPI->CreateReceiveStreamL( error /*session id*/, recvparams );
       
  1523     RTP_EUNIT_ASSERT_RTP_ID ( error2 );
       
  1524         
       
  1525     
       
  1526     err = iRtpAPI->RegisterRtpPostProcessingObserver( error, *this );
       
  1527     EUNIT_ASSERT ( err == KErrNone )
       
  1528     }
       
  1529 
       
  1530 
       
  1531 void UT_CRtpAPI::UT_CRtpAPI_SendRtpPacketWithCSRCL()
       
  1532     {
       
  1533     TInt result(KErrNone);
       
  1534     TRtpSdesParams params;
       
  1535     
       
  1536     result = iRtpAPI->OpenL( params, NULL, NULL, NULL );
       
  1537     RTP_EUNIT_ASSERT_EQUALS(result, KErrNone);
       
  1538     
       
  1539     TRequestStatus status;
       
  1540     result = iRtpAPI->StartConnection( status, KDefaultIap ); // KDefaultIap
       
  1541     RTP_EUNIT_ASSERT_EQUALS ( result, KErrNone );
       
  1542  // Wait until the connection is really up
       
  1543     User::WaitForRequest( status );
       
  1544 
       
  1545     //create session
       
  1546     TCreateSessionParams sessionParams;
       
  1547     sessionParams.iPriority = TCreateSessionParams::EPriorityStandard;
       
  1548     sessionParams.iSocketBufSize = KSocketBufSize;
       
  1549     TUint port( 5000 );
       
  1550     TBool enableRtcp( EFalse );
       
  1551     TRtcpParams rtcpParams;
       
  1552     rtcpParams.iRtcpFraction = 0.10;
       
  1553     rtcpParams.iRtcpTimeOut = 0;
       
  1554     rtcpParams.iSessionBWidth = 32000;
       
  1555 
       
  1556     TRtpId error( KNullId );
       
  1557     error = iRtpAPI->CreateSessionL( sessionParams,
       
  1558                                     port,
       
  1559                                     enableRtcp,
       
  1560                                     &rtcpParams );
       
  1561     RTP_EUNIT_ASSERT_RTP_ID( error );
       
  1562     
       
  1563     TTranStreamParams transparams;
       
  1564     transparams.iPayloadType = 0;
       
  1565     TRtpSSRC ssrc( 0 );
       
  1566     
       
  1567     TInt err( KErrNone );
       
  1568     err = iRtpAPI->RegisterRtpPostProcessingObserver( error, *this );
       
  1569     EUNIT_ASSERT ( err == KErrNone )
       
  1570 
       
  1571 
       
  1572     err = iRtpAPI->CreateTransmitStreamL( error /*session id*/, transparams, ssrc );
       
  1573     RTP_EUNIT_ASSERT_RTP_ID ( err );
       
  1574     
       
  1575     
       
  1576     TRtpSendHeader header; 
       
  1577     header.iHeaderExtension = NULL;
       
  1578     header.iMarker = 0;
       
  1579     header.iPadding = 0;
       
  1580     header.iPayloadType = 0;
       
  1581     header.iTimestamp = 10;
       
  1582 
       
  1583     HBufC8* data = HBufC8::NewLC(KLength);
       
  1584     data->Des().Copy(KHello);
       
  1585     CleanupStack::Pop(data);
       
  1586 
       
  1587     TRtpSendPktParams *headerinfo = new(ELeave) TRtpSendPktParams(header);
       
  1588     headerinfo->iTranStreamId = err;
       
  1589     headerinfo->iPayloadData.Set(data->Des()); 
       
  1590     
       
  1591     const TUint KArrayGranularity = 15;
       
  1592     
       
  1593     CArrayFixFlat<TUint32>* fix;
       
  1594     fix = new(ELeave) CArrayFixFlat<TUint32>(KArrayGranularity);
       
  1595     
       
  1596     fix->AppendL(123456);
       
  1597     fix->AppendL(999999);
       
  1598      
       
  1599     TInt error2( KErrNone );
       
  1600     iIsCallBackReceived = EFalse;
       
  1601     // Try sending synchronously with Csrc
       
  1602     error2 = iRtpAPI->SendRtpPacket(*headerinfo, fix->Array());
       
  1603     RTP_EUNIT_ASSERT_EQUALS ( error2, KErrNone );
       
  1604     
       
  1605     CRtpSession* rtpSession = iRtpAPI->iManager->GetSession( err );
       
  1606     User::WaitForRequest( rtpSession->iCommNet->iSender[ERTPPort]->iStatus );
       
  1607     rtpSession->iCommNet->iSender[ERTPPort]->RunL();
       
  1608     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
       
  1609     EUNIT_ASSERT(iIsCallBackReceived == ETrue);
       
  1610     
       
  1611     iIsCallBackReceived = EFalse;
       
  1612     // Try sending asynchronously with CSRC
       
  1613     headerinfo->iStatus = &status;
       
  1614     error2 = iRtpAPI->SendRtpPacket(*headerinfo, fix->Array());
       
  1615     RTP_EUNIT_ASSERT_EQUALS ( error2, KErrNone );
       
  1616     EUNIT_ASSERT( KRequestPending == status.Int() );
       
  1617     User::WaitForRequest( rtpSession->iCommNet->iSender[ERTPPort]->iStatus );
       
  1618     rtpSession->iCommNet->iSender[ERTPPort]->RunL();
       
  1619     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
       
  1620     User::WaitForRequest( status );
       
  1621     EUNIT_ASSERT( KErrNone == status.Int() );
       
  1622     // Is call back received check
       
  1623     EUNIT_ASSERT(iIsCallBackReceived == ETrue);
       
  1624     
       
  1625     iIsCallBackReceived = EFalse;
       
  1626     // Try sending asynchronously, specifying the sequence number with CSRC
       
  1627 	TRtpSequence seqNum = 42;
       
  1628     headerinfo->iSequenceNum = &seqNum;
       
  1629     error2 = iRtpAPI->SendRtpPacket(*headerinfo, fix->Array());
       
  1630     RTP_EUNIT_ASSERT_EQUALS ( error2, KErrNone );
       
  1631     EUNIT_ASSERT( KRequestPending == status.Int() );
       
  1632     User::WaitForRequest( rtpSession->iCommNet->iSender[ERTPPort]->iStatus );
       
  1633     rtpSession->iCommNet->iSender[ERTPPort]->RunL();
       
  1634     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
       
  1635     User::WaitForRequest( status );
       
  1636     EUNIT_ASSERT( KErrNone == status.Int() );
       
  1637     EUNIT_ASSERT(iIsCallBackReceived == ETrue);
       
  1638     
       
  1639     delete fix;
       
  1640     delete headerinfo;
       
  1641     delete data;
       
  1642     }
       
  1643 
       
  1644 
       
  1645 void UT_CRtpAPI::UT_CRtpAPI_UnregisterRtpPostProcessingObserverL(  )
       
  1646     {
       
  1647     TInt result(KErrNone);
       
  1648     TRtpSdesParams params;
       
  1649     
       
  1650     result = iRtpAPI->OpenL( params, NULL, NULL, NULL );
       
  1651     EUNIT_ASSERT(result==KErrNone);
       
  1652     
       
  1653     TRequestStatus status;
       
  1654     result = iRtpAPI->StartConnection( status, KDefaultIap2 ); // KDefaultIap
       
  1655     RTP_EUNIT_ASSERT_EQUALS ( result, KErrNone );
       
  1656  // Wait until the connection is really up
       
  1657     User::WaitForRequest( status );
       
  1658 
       
  1659     //create session
       
  1660     TCreateSessionParams sessionParams;
       
  1661     sessionParams.iPriority = TCreateSessionParams::EPriorityStandard;
       
  1662     sessionParams.iSocketBufSize = KSocketBufSize;
       
  1663     TUint port( 5000 );
       
  1664     TBool enableRtcp( EFalse );
       
  1665     TRtcpParams rtcpParams;
       
  1666     rtcpParams.iRtcpFraction = 0.10;
       
  1667     rtcpParams.iRtcpTimeOut = 0;
       
  1668     rtcpParams.iSessionBWidth = 32000;
       
  1669 
       
  1670     TRtpId error( KNullId );
       
  1671     error = iRtpAPI->CreateSessionL( sessionParams,
       
  1672                                     port,
       
  1673                                     enableRtcp,
       
  1674                                     &rtcpParams );
       
  1675     RTP_EUNIT_ASSERT_RTP_ID( error );
       
  1676     
       
  1677     TRcvStreamParams recvparams;
       
  1678     recvparams.iPayloadType = 0;
       
  1679 
       
  1680     TRtpId error2( KNullId );
       
  1681     TInt err( KErrNone );
       
  1682     error2 = iRtpAPI->CreateReceiveStreamL( error /*session id*/, recvparams );
       
  1683     RTP_EUNIT_ASSERT_RTP_ID ( error2 );
       
  1684         
       
  1685     TTranStreamParams transparams;
       
  1686     transparams.iPayloadType = 0;
       
  1687     TRtpSSRC ssrc( 0 );
       
  1688     
       
  1689     err = iRtpAPI->RegisterRtpPostProcessingObserver( error, *this );
       
  1690     EUNIT_ASSERT ( err == KErrNone )
       
  1691     
       
  1692     err = iRtpAPI->CreateTransmitStreamL( error /*session id*/, transparams, ssrc );
       
  1693     RTP_EUNIT_ASSERT_RTP_ID ( err );
       
  1694     
       
  1695     
       
  1696     TRtpSendHeader header; 
       
  1697     header.iHeaderExtension = NULL;
       
  1698     header.iMarker = 0;
       
  1699     header.iPadding = 0;
       
  1700     header.iPayloadType = 0;
       
  1701     header.iTimestamp = 10;
       
  1702 
       
  1703     HBufC8* data = HBufC8::NewLC(KLength);
       
  1704     data->Des().Copy(KHello);
       
  1705     CleanupStack::Pop(data);
       
  1706 
       
  1707     TRtpSendPktParams *headerinfo = new(ELeave) TRtpSendPktParams(header);
       
  1708     headerinfo->iTranStreamId = err;
       
  1709     headerinfo->iPayloadData.Set(data->Des()); 
       
  1710     
       
  1711     const TUint KArrayGranularity = 15;
       
  1712     
       
  1713     CArrayFixFlat<TUint32>* fix;
       
  1714     fix = new(ELeave) CArrayFixFlat<TUint32>(KArrayGranularity);
       
  1715     
       
  1716     fix->AppendL(123456);
       
  1717     fix->AppendL(999999);
       
  1718      
       
  1719     TInt error3( KErrNone );
       
  1720     iIsCallBackReceived = EFalse;
       
  1721     // Try sending synchronously with Csrc
       
  1722     error3 = iRtpAPI->SendRtpPacket(*headerinfo, fix->Array());
       
  1723     RTP_EUNIT_ASSERT_EQUALS ( error3, KErrNone );
       
  1724     
       
  1725     CRtpSession* rtpSession = iRtpAPI->iManager->GetSession( err );
       
  1726     User::WaitForRequest( rtpSession->iCommNet->iSender[ERTPPort]->iStatus );
       
  1727     rtpSession->iCommNet->iSender[ERTPPort]->RunL();
       
  1728     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
       
  1729     EUNIT_ASSERT(iIsCallBackReceived == ETrue);
       
  1730     
       
  1731     // Unregister callback
       
  1732     iRtpAPI->UnregisterRtpPostProcessingObserver(error);
       
  1733     
       
  1734     iIsCallBackReceived = EFalse;
       
  1735     error3 = KErrNone;
       
  1736     // Try sending synchronously with Csrc
       
  1737     error3 = iRtpAPI->SendRtpPacket(*headerinfo, fix->Array());
       
  1738     RTP_EUNIT_ASSERT_EQUALS ( error3, KErrNone );
       
  1739     
       
  1740     User::WaitForRequest( rtpSession->iCommNet->iSender[ERTPPort]->iStatus );
       
  1741     rtpSession->iCommNet->iSender[ERTPPort]->RunL();
       
  1742     rtpSession->iCommNet->iSender[ERTPPort]->iStatus = TRequestStatus();
       
  1743     EUNIT_ASSERT(iIsCallBackReceived == EFalse);
       
  1744     
       
  1745     delete fix;
       
  1746     delete headerinfo;
       
  1747     delete data;
       
  1748     }
       
  1749 
  1472 //  TEST TABLE
  1750 //  TEST TABLE
  1473 
  1751 
  1474 EUNIT_BEGIN_TEST_TABLE(
  1752 EUNIT_BEGIN_TEST_TABLE(
  1475     UT_CRtpAPI,
  1753     UT_CRtpAPI,
  1476     "Test CRtpAPI.",
  1754     "Test CRtpAPI.",
  1500 EUNIT_TEST(
  1778 EUNIT_TEST(
  1501     "StartConnection - test ",
  1779     "StartConnection - test ",
  1502     "CRtpAPI",
  1780     "CRtpAPI",
  1503     "StartConnection",
  1781     "StartConnection",
  1504     "FUNCTIONALITY",
  1782     "FUNCTIONALITY",
  1505     SetupL, UT_CRtpAPI_StartConnection_1L, Teardown)
  1783     SetupL, UT_CRtpAPI_StartConnection_OneL, Teardown)
  1506 
  1784 
  1507 EUNIT_TEST(
  1785 EUNIT_TEST(
  1508     "CancelStart - test ",
  1786     "CancelStart - test ",
  1509     "CRtpAPI",
  1787     "CRtpAPI",
  1510     "CancelStart",
  1788     "CancelStart",
  1654 EUNIT_TEST(
  1932 EUNIT_TEST(
  1655     "SendRtpPacket3L - test ",
  1933     "SendRtpPacket3L - test ",
  1656     "CRtpAPI",
  1934     "CRtpAPI",
  1657     "SendRtpPacket",
  1935     "SendRtpPacket",
  1658     "FUNCTIONALITY",
  1936     "FUNCTIONALITY",
  1659     SetupL, UT_CRtpAPI_SendRtpPacket_3L, Teardown)
  1937     SetupL, UT_CRtpAPI_SendRtpPacket_ThreeL, Teardown)
  1660 
  1938 
  1661 EUNIT_TEST(
  1939 EUNIT_TEST(
  1662     "SendDataL - test ",
  1940     "SendDataL - test ",
  1663     "CRtpAPI",
  1941     "CRtpAPI",
  1664     "SendDataL",
  1942     "SendDataL",
  1795     "Version - test ",
  2073     "Version - test ",
  1796     "CRtpAPI",
  2074     "CRtpAPI",
  1797     "Version",
  2075     "Version",
  1798     "FUNCTIONALITY",
  2076     "FUNCTIONALITY",
  1799     SetupL, UT_CRtpAPI_VersionL, Teardown)
  2077     SetupL, UT_CRtpAPI_VersionL, Teardown)
  1800 
  2078     
  1801 
  2079 EUNIT_TEST(
       
  2080     "RegisterRtpPostProcessingObserver - test ",
       
  2081     "CRtpAPI",
       
  2082     "RegisterRtpPostProcessingObserver",
       
  2083     "FUNCTIONALITY",
       
  2084     SetupL, UT_CRtpAPI_RegisterRtpPostProcessingObserverL, Teardown)    
       
  2085 
       
  2086 
       
  2087 EUNIT_TEST(
       
  2088     "SendRtpPacketWithCSRC - test ",
       
  2089     "CRtpAPI",
       
  2090     "SendRtpPacket",
       
  2091     "FUNCTIONALITY",
       
  2092     SetupL, UT_CRtpAPI_SendRtpPacketWithCSRCL, Teardown)   
       
  2093     
       
  2094 EUNIT_TEST(
       
  2095     "UnregisterRtpPostProcessingObserver - test ",
       
  2096     "CRtpAPI",
       
  2097     "UnregisterRtpPostProcessingObserver",
       
  2098     "FUNCTIONALITY",
       
  2099     SetupL, UT_CRtpAPI_UnregisterRtpPostProcessingObserverL, Teardown)  
       
  2100 
       
  2101     
  1802 EUNIT_END_TEST_TABLE
  2102 EUNIT_END_TEST_TABLE
  1803 
  2103 
  1804 //  END OF FILE
  2104 //  END OF FILE