dvrengine/CommonRecordingEngine/inc/CCRRTSPPacketSource.h
branchRCL_3
changeset 48 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
47:826cea16efd9 48:13a33d82ad98
       
     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:    Class that negotiaties RTP stream using RTSP*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CCRRTSPPACKETSOURCE_H
       
    21 #define CCRRTSPPACKETSOURCE_H
       
    22 
       
    23 //  INCLUDES
       
    24 #include "CCRPacketSourceBase.h"
       
    25 #include "CCRStreamingSession.h"
       
    26 #include "CCRConnection.h"
       
    27 #include "CCRRtspResponse.h"
       
    28 #include "CCRRtpTcpObserver.h"
       
    29 #include "CCRSock.h"
       
    30 #include "MCRTimerObserver.h"
       
    31 #include <rtp.h>
       
    32 
       
    33 // CONSTANTS
       
    34 // None
       
    35 
       
    36 // MACROS
       
    37 // None
       
    38 
       
    39 // DATA TYPES
       
    40 // None
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 class CCRRtspCommand;
       
    44 class CDvrSdpParser;
       
    45 class RRtpSession;
       
    46 class RRtpReceiveSource;
       
    47 class TRtpEvent;
       
    48 class CCRTimer;
       
    49 class CCRPunchPacketSender;
       
    50 class CCRRtpTcpStreamer;
       
    51 
       
    52 // CLASS DECLARATION
       
    53 
       
    54 /**
       
    55 *  Class that negotiaties RTP stream using RTSP.
       
    56 *
       
    57 *  @lib CommonRecordingEngine.lib
       
    58 *  @since Series 60 3.0
       
    59 */
       
    60 class CCRRtspPacketSource : public CCRPacketSourceBase,
       
    61                             public MCRSockObserver,
       
    62                             public MCRRtpTcpObserver,
       
    63                             public MCRConnectionObserver,
       
    64                             public MCRTimerObserver
       
    65     {
       
    66 
       
    67 public: // Data types
       
    68 
       
    69     /**
       
    70     * RTP packet memory layout structure
       
    71     */
       
    72     struct TCRRtpMessageHeader
       
    73         {
       
    74         TUint iVersion:2;
       
    75         TUint iPadding:1;
       
    76         TUint iExtension:1;
       
    77         TUint iCsrcCount:4;
       
    78         TUint iMarker:1;
       
    79         TUint iPayloadType:7;
       
    80         TUint iSeq:16;
       
    81         TUint32 iTimestamp;
       
    82         TUint32 iSSRC;
       
    83         };
       
    84 
       
    85     /**
       
    86     * RTCP sender report memory layout 
       
    87     */
       
    88     struct TCRRtpSRReportHeader
       
    89         {
       
    90         // Note the order of first 3 items:
       
    91         unsigned char iReportCount:5; // this and
       
    92         unsigned char iPadding:1;     // this and
       
    93         unsigned char iVersion:2;     // this are first 8 bits. 
       
    94         // Note that above order is reversed from spec.
       
    95         unsigned char iPacketType;
       
    96         TUint16 iLength;
       
    97         TUint32 iSenderSSRC;
       
    98         TUint32 iMSWTimestamp;
       
    99         TUint32 iLSWTimestamp;
       
   100         TUint32 iRTPTimestamp;
       
   101         TUint32 iSenderPacketCount;
       
   102         TUint32 iSenderOctetCount;
       
   103         };
       
   104 
       
   105     /**
       
   106     * Enum for identifying sockets. Sockets return this via Id()
       
   107     * and this is also used as an array index. 
       
   108     */
       
   109     enum TCRRTPSockId
       
   110         {
       
   111         ERTPControl=0,     /**< placeholder for RTSP sock */
       
   112         ERTPVideoSend1,    /**< RTP video payload */
       
   113         ERTPVideoSend2,    /**< RTCP video */
       
   114         ERTPAudioSend1,    /**< RTP audio payload */
       
   115         ERTPAudioSend2,    /**< RTCP audio */
       
   116         ERTPMaxSockets     /**< Just max value, no real socket assigned for this */
       
   117         };
       
   118 
       
   119 public: // Constructors and destructor
       
   120 
       
   121     /**
       
   122     * Two-phased constructor.
       
   123     * Calling this method will finally cause a call to DoConnectL() so
       
   124     * this class will start connecting as soon as it is constructed, 
       
   125     * address where to connect to is in aParams. 
       
   126     * @param aParams is the stream address
       
   127     * @param aConnection is handle to RConnection wrapper to use
       
   128     * @param aSessionObs is pointer to our observer
       
   129     * @aOwningSession is the streaming session that owns this packet source
       
   130     * @return CCRRtspPacketSource pointer to CCRRtspPacketSource class
       
   131     */
       
   132     static CCRRtspPacketSource* NewL( const SCRRtspParams& aParams,
       
   133                                       CCRConnection& aConnection,
       
   134                                       RSocketServ& aSockServer,
       
   135                                       MCRStreamObserver& aSessionObs,
       
   136                                       CCRStreamingSession& aOwningSession );
       
   137 
       
   138     /**
       
   139     * Destructor.
       
   140     */
       
   141     virtual ~CCRRtspPacketSource();
       
   142 
       
   143 public: // New functions
       
   144 
       
   145     /**
       
   146     * Method for aquiring the URI being streamed here
       
   147     * @since Series 60 3.0
       
   148     * @param none.
       
   149     * @return URI.
       
   150     */
       
   151     TPtr URI();
       
   152 
       
   153     /**
       
   154     * Method that packet puncher calls to tell
       
   155     * it has finished punching the firewall.
       
   156     * @since Series 60 3.0
       
   157     * @param aPuncher tells the number of the port 
       
   158     * where the punch packet was sent to.
       
   159     * @return none.
       
   160     */
       
   161     void PunchPacketsSent( CCRPunchPacketSender* aPuncher );
       
   162 
       
   163     /**
       
   164     * Method for setting observer that this source will report its status to.
       
   165     * @since Series 60 3.0
       
   166     * @param aObserver is the observer instance implementing MCRConnectionObserver.
       
   167     * @return none.
       
   168     */
       
   169     void RegisterConnectionObs( MCRConnectionObserver* aObserver );
       
   170 
       
   171     /**
       
   172     * Method for removing status observer
       
   173     * @since Series 60 3.0
       
   174     * @param none.
       
   175     * @return none.
       
   176     */
       
   177     void UnregisterConnectionObs();
       
   178 
       
   179 public: // Methods from base classes
       
   180 
       
   181     /**
       
   182     * From CCRPacketSourceBase.
       
   183     * Method for acquiring sdp.
       
   184     * @since Series 60 3.0
       
   185     * @param aSdp is string pointer that will be .Set() to contain the sdp.
       
   186     *        If no sdp is available no .Set() will occur.
       
   187     * @return KErrNotReady if no sdp available.
       
   188     */
       
   189     TInt GetSdp( TPtrC8& aSdp );
       
   190 
       
   191     /**
       
   192     * From CCRPacketSourceBase.
       
   193     * Method for acquiring (almost) up-to-date sequence and ts numbers.
       
   194     * @since Series 60 3.0
       
   195     * @param aAudioSeq is reference to TUint that will be set by this
       
   196     *        method to contain latest available sequence number for
       
   197     *        audio stream being received via this packet source.
       
   198     * @param aAudioTS rtp timestamp for audio.
       
   199     * @param aVideoSeq rtp seq for video. If no video, value will not be touched.
       
   200     * @param aVideoTS rtp ts for video.
       
   201     * @return KErrNone if data available.
       
   202     */
       
   203     TInt SeqAndTS( TUint& aAudioSeq,
       
   204                    TUint& aAudioTS,
       
   205                    TUint& aVideoSeq,
       
   206                    TUint& aVideoTS );
       
   207 
       
   208     /**
       
   209     * From CCRPacketSourceBase.
       
   210     * Post action after source initialized.
       
   211     * @since Series 60 3.0
       
   212     * @param none.
       
   213     * @return none.
       
   214     */
       
   215     void PostActionL();
       
   216 
       
   217     /**
       
   218     * From CCRPacketSourceBase.
       
   219     * Method for ordering "play" for packet source.
       
   220     * @since Series 60 3.0
       
   221     * @param aStartPos is start position in seconds.
       
   222     * @param aEndPos is end position in seconds.
       
   223     * @return a system wide error code.
       
   224     */
       
   225     TInt Play( const TReal& aStartPos,
       
   226                const TReal& aEndPos );
       
   227 
       
   228     /**
       
   229     * From CCRPacketSourceBase.
       
   230     * Method for pausing play from source.
       
   231     * @since Series 60 3.0
       
   232     * @param none.
       
   233     * @return a system wide error code.
       
   234     */
       
   235     TInt Pause();
       
   236 
       
   237     /**
       
   238     * From CCRPacketSourceBase.
       
   239     * Method for stopping play from source.
       
   240     * @since Series 60 3.0
       
   241     * @param none.
       
   242     * @return a system wide error code.
       
   243     */
       
   244     TInt Stop();
       
   245 
       
   246     /**
       
   247     * From CCRPacketSourceBase.
       
   248     * Method for getting range of stream. If no range/duration
       
   249     * is available this method will set the return values to
       
   250     * 0.0,-1.0 and that may be quite normal state live streams.
       
   251     * @since Series 60 3.0
       
   252     * @param aLower is where to start from. If no value available,
       
   253     *        value of aLower must be set to 0
       
   254     * @param aUpper is where to stop. Negative values mean eternity.
       
   255     * @return none.
       
   256     */
       
   257     void GetRange( TReal& aLower,
       
   258                    TReal& aUpper );
       
   259 
       
   260     /**
       
   261     * From CCRPacketSourceBase.
       
   262     * Setter for current position.
       
   263     * @since Series 60 3.0
       
   264     * @param aPosition a postion of playback.
       
   265     * @return a system wide error code.
       
   266     */
       
   267     virtual TInt SetPosition( const TInt64 aPosition ) ;
       
   268 
       
   269     /**
       
   270     * From MCRSockObserver.
       
   271     * This method is called after some data has been received from socket.
       
   272     * @since Series 60 3.0
       
   273     * @param aSockId identifies the socket where the data came from. 
       
   274     * @param aData is descriptor containing the data received.
       
   275     *        ownership of data is not passed via this call.
       
   276     * @return none.
       
   277     */
       
   278     void DataReceived( TInt aSockId,
       
   279                        const TDesC8& aData );
       
   280 
       
   281     /**
       
   282     * From MCRSockObserver.
       
   283     * This method is called after status of socket changes.
       
   284     * @since Series 60 3.0
       
   285     * @param aSockId Identifies the socket that had the status change
       
   286     * @param aStatus is the new status of the sock
       
   287     * @param aError if aStatus was an error-status, this may contain error code
       
   288     * @return none.
       
   289     */
       
   290     void SockStatusChange( TInt aSockId, 
       
   291                            CCRSock::TCRSockStatus aStatus,
       
   292                            TInt aError );
       
   293 
       
   294     /**
       
   295     * From MCRRtpTcpObserver.
       
   296     * Signals an available incoming RTSP control message
       
   297     * @since Series 60 3.0
       
   298     * @param aData a RTSP meaage data.
       
   299     * @return none.
       
   300     */
       
   301     void RtspMsgAvailable( const TDesC8& aData );
       
   302 
       
   303     /**
       
   304     * From MCRRtpTcpObserver.
       
   305     * Receives a RTP/RTCP packet available from TCP streamer and
       
   306     * forwards to streaming sessions (buffers).
       
   307     * @since Series 60 3.0
       
   308     * @param aChannel specifies channel if in TCP streaming case, in practice
       
   309     *        tells if it is a video/audio packet and if it is RTP or RTCP.
       
   310     * @param aPacket is the payload of the  packet
       
   311     * @return none.
       
   312     */
       
   313     void RtpTcpPacketAvailable( TInt aChannel,
       
   314                                 const TDesC8& aPacket );
       
   315 
       
   316     /**
       
   317     * From MCRRtpTcpObserver.
       
   318     * Receives a RTP/RTCP packet and forward to streaming server
       
   319     * @since Series 60 3.0
       
   320     * @param aChunk contains RTP packet with headers suitable to be sent to remote
       
   321     *        via RTSP control socket.
       
   322     * @return none.
       
   323     */
       
   324     void ForwardRtpTcpChunck( const TDesC8& aChunk );
       
   325     
       
   326     /**
       
   327     * From MCRConnectionObserver.
       
   328     * receives notifications of connection status changes,
       
   329     * used to clear heuristics on streaming capabilities.
       
   330     * @since Series 60 3.0
       
   331     * @param aSessionId a session id.
       
   332     * @param aStatus is the new status of the connection.
       
   333     * @param aErr contains error code if new status is failure status.
       
   334     * @return none.
       
   335     */
       
   336     void ConnectionStatusChange( TInt aSessionId,
       
   337                                  TCRConnectionStatus aStatus,
       
   338                                  TInt aErr );
       
   339 
       
   340     /**
       
   341     * From MCRTimerObserver.
       
   342     * The function to be called when a timeout occurs.
       
   343     * @since Series 60 3.0
       
   344     * @param aTimer is pointer to timer instance that caused call to this method.
       
   345     * @return none.
       
   346     */
       
   347     void TimerExpired( CCRTimer* aTimer );
       
   348 
       
   349 private: // Constructors and destructor
       
   350 
       
   351     /**
       
   352     * C++ default constructor.
       
   353     * @param aConnection is RConnection wrapper to use.
       
   354     * @param aSockServer is socket server to use when opening sockets.
       
   355     * @param aSessionObs is pointer to our observer.
       
   356     * @param aOwningSession is pointer to session that owns this source.
       
   357     */
       
   358     CCRRtspPacketSource( CCRConnection& aConnection,
       
   359                          RSocketServ& aSockServer,
       
   360                          MCRStreamObserver& aSessionObs,
       
   361                          CCRStreamingSession& aOwningSession );
       
   362 
       
   363     /**
       
   364     * By default Symbian 2nd phase constructor is private.
       
   365     * @aParams aParams contains stream address parameters that this packet source
       
   366     *          will try to use to obtain the stream.
       
   367     * @return none
       
   368     */
       
   369     void ConstructL( const SCRRtspParams& aParams );
       
   370 
       
   371 private: // New methods
       
   372 
       
   373     /**
       
   374     * Method for connecting.
       
   375     * @since Series 60 3.0
       
   376     * @param none.
       
   377     * @return none.
       
   378     */
       
   379     void DoConnectL();
       
   380 
       
   381     /**
       
   382     * Method for cleaning up.
       
   383     * @since Series 60 3.0
       
   384     * @param none.
       
   385     * @return none.
       
   386     */
       
   387     void CleanUp();
       
   388 
       
   389     /**
       
   390     * Method for initiating cleanup.
       
   391     * @since Series 60 3.0
       
   392     * @param aSelfPtr is pointer to "this".
       
   393     * @return none.
       
   394     */
       
   395     static TInt CleanUpCallback( TAny* aSelfPtr );
       
   396 
       
   397     /**
       
   398     * Method for asking for cleanup in async way.
       
   399     * @since Series 60 3.0
       
   400     * @param none.
       
   401     * @return none.
       
   402     */
       
   403     void DoCleanup();
       
   404 
       
   405     /**
       
   406     * Method for sending RTSP command. Command in question depends on state.
       
   407     * @since Series 60 3.0
       
   408     * @param none.
       
   409     * @return none.
       
   410     */
       
   411     void SendRtspCommandL();
       
   412 
       
   413     /**
       
   414     * Method for parsing and reacting to RTSP reply.
       
   415     * @since Series 60 3.0
       
   416     * @param aData a RTSP response data.
       
   417     * @return none.
       
   418     */
       
   419     void ProcessRtspResponseL( const TDesC8& aData );
       
   420 
       
   421     /**
       
   422     * Method for parsing and reacting to RTSP command that
       
   423     * remote server may send to us
       
   424     * @since Series 60 3.0
       
   425     * @param aData a RTSP response data.
       
   426     * @return none.
       
   427     */
       
   428     void ProcessRTSPCommandL( const TDesC8& aData );
       
   429 
       
   430     /**
       
   431     * Method for sending error indication to client side
       
   432     * if rtsp response was something errorneous.
       
   433     * @since Series 60 3.0
       
   434     * @param aErrorCode is RTSP response code,something else than 200 OK.
       
   435     * @return none.
       
   436     */
       
   437     void ProcessRtspErrorResponseL( CCRRtspResponse::TResponseCode aErrorCode );
       
   438 
       
   439     /**
       
   440     * Method for doing SETUP.
       
   441     * @since Series 60 3.0
       
   442     * @param aControlAddr is either absolute or relative controladdr for stream.
       
   443     * @param aForAudio is ETrue if control addr is for audio.
       
   444     * @return client port number.
       
   445     */
       
   446     TInt SendSetupCommandL( const TDesC8& aControlAddr,
       
   447                             TBool aForAudio );
       
   448 
       
   449     /**
       
   450     * Method for doing PLAY.
       
   451     * @since Series 60 3.0
       
   452     * @param none.
       
   453     * @return none.
       
   454     */
       
   455     void SendPlayCommandL();
       
   456 
       
   457     /**
       
   458     * Method for doing PAUSE that is sent to remote server.
       
   459     * @since Series 60 3.0
       
   460     * @param none.
       
   461     * @return none.
       
   462     */
       
   463     void SendPauseCommandL();
       
   464 
       
   465     /**
       
   466     * Method for doing OPTIONS ping that is sent to remote server.
       
   467     * @since Series 60 3.0
       
   468     * @param none.
       
   469     * @return none.
       
   470     */
       
   471     void SendOptionsCommandL();
       
   472 
       
   473     /**
       
   474     * Method for doing TEARDOWN.
       
   475     * @since Series 60 3.0
       
   476     * @param none.
       
   477     * @return none.
       
   478     */
       
   479     void SendTearDownCommandL();
       
   480 
       
   481     /**
       
   482     * Method that sets up rtp sessions. Must be called before play is issued.
       
   483     * @since Series 60 3.0
       
   484     * @param none.
       
   485     * @return none.
       
   486     */
       
   487     TInt SetupRTPSessions();
       
   488 
       
   489     /**
       
   490     * Method that starts RTSP command response timeout.
       
   491     * @since Series 60 3.0
       
   492     * @param aTime a timer interval.
       
   493     * @return none.
       
   494     */
       
   495     void StartRtspTimeout( TTimeIntervalMicroSeconds32 aTime );
       
   496 
       
   497     /**
       
   498     * Callback method from RTP session for audio.
       
   499     * @since Series 60 3.0
       
   500     * @param aPtr is pointer to "this".
       
   501     * @param aEvent is the event. In practice it contains RTP packet or RTCP packet.
       
   502     * @return none.
       
   503     */
       
   504     static void AudioRTPCallBack( CCRRtspPacketSource* aPtr,
       
   505                                   const TRtpEvent& aEvent );
       
   506 
       
   507     /**
       
   508     * Callback method from RTP session for video.
       
   509     * @since Series 60 3.0
       
   510     * @param aPtr is pointer to "this".
       
   511     * @param aEvent is the event. In practice it contains RTP packet or RTCP packet.
       
   512     * @return none.
       
   513     */
       
   514     static void VideoRTPCallBack( CCRRtspPacketSource* aPtr,
       
   515                                   const TRtpEvent& aEvent );
       
   516 
       
   517     /**
       
   518     * Callback for RTSP timeout. Just ask session to start cleanup.
       
   519     * @since Series 60 3.0
       
   520     * @param aPtr is pointer to "this".
       
   521     * @return none.
       
   522     */
       
   523     static TInt RtspTimeoutCallback( TAny* aPtr );
       
   524 
       
   525     /**
       
   526     * Method for creating sender report header.
       
   527     * @param aPtr is pointer to "this".
       
   528     * @param aEvent is the rtp packet event received.
       
   529     * @param aStreamId a stream id.
       
   530     * @return none
       
   531     */
       
   532     static void SenderReport( CCRRtspPacketSource* aPtr,
       
   533                               const TRtpEvent& aEvent,
       
   534                               MCRPacketSource::TCRPacketStreamId aStreamId );
       
   535 
       
   536     /**
       
   537     * Method for handling audio.
       
   538     * @param aPtr is pointer to "this".
       
   539     * @param aSource a receiver source.
       
   540     * @param aEvent is the rtp packet event received.
       
   541     * @return none
       
   542     */
       
   543     static void HandleNewSourceL( CCRRtspPacketSource* aPtr,
       
   544                                   RRtpReceiveSource& aSource,
       
   545                                   const TRtpEvent& aEvent,
       
   546                                   TRtpCallbackFunction aCallback );
       
   547 
       
   548     /**
       
   549     * Generate DESCRIBE message with authentication information.
       
   550     * used when server responses with 401 or 407.
       
   551     * @since Series 60 3.0
       
   552     * @param none.
       
   553     * @return none.
       
   554     */
       
   555     void SendAuthDescribeL();
       
   556 
       
   557     /**
       
   558     * Adds authentication info to given command.
       
   559     * @since Series 60 3.0
       
   560     * @param aCommand the command where to add authentication info.
       
   561     * @return none.
       
   562     */
       
   563     void AddAuthenticationL( TInt aCommand );
       
   564 
       
   565     /**
       
   566     * Setup sessions for RTP stack and issue play command
       
   567     * @since Series 60 3.0
       
   568     * @param none.
       
   569     * @return none.
       
   570     */
       
   571     void SetupSessionsAndPlay();
       
   572 
       
   573     /**
       
   574     * Initiates sending of punch packets
       
   575     * @since Series 60 3.0
       
   576     * @param none.
       
   577     * @return none.
       
   578     */
       
   579     void SendPunchPacketsL();
       
   580 
       
   581     /**
       
   582     * Creates a socket in iRTPSockArr for multicast streaming:
       
   583     * binds to local port and join multicast group
       
   584     *
       
   585     * @since Series 60 3.0
       
   586     * @param aSockId  id for RTP socket in iRTPSockArr
       
   587     * @param aGroupAddr multicast group address, in IPv6 or mapped IPv4
       
   588     * @param aPort local UDP port to listen
       
   589     * @return system error code
       
   590     */
       
   591     TInt CreateMulticastSocket( TCRRTPSockId aSockId,
       
   592                                 const TInetAddr& aGroupAddr,
       
   593                                 TInt aPort );
       
   594 
       
   595     /**
       
   596     * Creates a socket in iRTPSockArr for unicast streaming:
       
   597     * binds to local port and connects to remote address
       
   598     *
       
   599     * @since Series 60 3.0
       
   600     * @param aSockId  id for RTP socket in iRTPSockArr
       
   601     * @param aLocalAddr  local address and port to listen
       
   602     * @param aRemoteAddr remote address and port to connect to
       
   603     * @return system error code
       
   604     */
       
   605     TInt CreateUnicastSocket( TCRRTPSockId aSockId,
       
   606                               const TInetAddr& aLocalAddr,
       
   607                               const TInetAddr& aRemoteAddr );
       
   608 
       
   609     /**
       
   610     * Method that handles rtp payload packet to buffer.
       
   611     * @since Series 60 3.0
       
   612     * @param aEvent is the rtp packet event received.
       
   613     * @param aIsAudio indicates whether this is audio or video packet.
       
   614     * @return none.
       
   615     */
       
   616     void RTPPayloadProcessor ( const TRtpEvent& aEvent,
       
   617                                const TBool aIsAudio );
       
   618 
       
   619     /**
       
   620     * Method for setting session parameters.
       
   621     * @since Series 60 3.0
       
   622     * @param aSession is reference to either audio or video rtp session.
       
   623     *        from instance variables of this class ; the parameters will
       
   624     *        be set in similar way for both audio and video
       
   625     * @param aGranularity is number of clock ticks per second, usually found from SDP
       
   626     * @return none.
       
   627     */
       
   628     void SetRtpSession( RRtpSession& aSession ,
       
   629                         TReal aGranularity );
       
   630 
       
   631     /**
       
   632     * Method for initiating cleanup.
       
   633     * @since Series 60 3.0
       
   634     * @param aSelfPtr is pointer to "this".
       
   635     * @return symbian error code.
       
   636     */
       
   637     static TInt SendRtspPing( TAny* aSelfPtr );
       
   638 
       
   639     /**
       
   640     * Method for synchronizing of timestamps and notifying sinks.
       
   641     * This should be called after sender reports are received
       
   642     * and with normal packet reception in the beginning of the stream.
       
   643     * In practice this will be called for about every packet while
       
   644     * iNoRtpInfoHeader is on, when we know the seq+ts then 
       
   645     * iNoRtpInfoHeader will be turned off and this method will be no longer
       
   646     * used ; detection of no rtp info header in rtsp play reply will turn
       
   647     * iNoRtpInfoHeader on. 
       
   648     *
       
   649     * @param aStreamId identifies the stream
       
   650     * @param aMSWTimestamp more significant part of wall-clock. Seconds.
       
   651     * @param aLSWTimestamp less significant part of wall-clock. Fraction of seconds.
       
   652     * @param aRTPTimestamp rtptimestamp of aMSW+aLSWTimestamp
       
   653     * @param aSeq sequence number of aRTPTimestamp
       
   654     */
       
   655     void ConstructSeqAndTsForSink ( MCRPacketSource::TCRPacketStreamId aStreamId,
       
   656                                     TUint32 aMSWTimestamp,
       
   657                                     TUint32 aLSWTimestamp,
       
   658                                     TUint32 aRTPTimestamp,
       
   659                                     TUint aSeq );
       
   660     
       
   661     /**
       
   662     * Method for setting up multicast or tcp streaming from setup reply.
       
   663     * @param none
       
   664     * @return none
       
   665     */
       
   666     void ConditionallySetupMultiCastOrTcpStreamingL();
       
   667 
       
   668     /**
       
   669     * Method checks that we all receiveing from all streams, if not returns false.
       
   670     * @param none
       
   671     * @return ETrue if receiving from all streams.
       
   672     */
       
   673     TBool CheckReceiveOfStreams();
       
   674     
       
   675     /**
       
   676     * Method that flags given stream as receiving stream.
       
   677     * @param aStreamType stream that is receiving   
       
   678     * @return none
       
   679     */
       
   680     void StreamFound( TCRPacketStreamId aStreamType );
       
   681     
       
   682     /**
       
   683     * Method that resets all created receive streams as non receiving.  
       
   684     * @param none
       
   685     * @return none
       
   686     */
       
   687     void ResetStreamFlags();
       
   688 
       
   689 #if defined ( LIVE_TV_FILE_TRACE ) || defined ( LIVE_TV_RDEBUG_TRACE )
       
   690     /**                                        
       
   691     * Method for showing a packet header.
       
   692     * @since Series 60 3.0
       
   693     * @param aRtcpHeader a pointer to packet header.
       
   694     * @param aEvent is the rtp packet event received.
       
   695     * @return none.
       
   696     */
       
   697     static void ShowHeader( const TDesC8& aRtcpHeader,
       
   698                             const TCRRtpSRReportHeader& aSrReport );
       
   699 #endif // LIVE_TV_FILE_TRACE || LIVE_TV_RDEBUG_TRACE
       
   700 
       
   701 private: // Data
       
   702 
       
   703     /**
       
   704     * rtsp URL we're supposed to view.
       
   705     */
       
   706     HBufC* iRtspUri;
       
   707     
       
   708     /**
       
   709     * Hostname -part of iRTSPURI.
       
   710     */
       
   711     TPtrC iRtspUriHost;
       
   712     /**
       
   713     * rtsp URL in 8bit descriptor, only because there is no uri parser in 8 bit.
       
   714     */
       
   715     HBufC8* iRtspUri8;
       
   716     /**
       
   717     * possible username, if server requires.
       
   718     */
       
   719     HBufC* iUserName;
       
   720     
       
   721     /**
       
   722     * possible password, if server requires.
       
   723     */
       
   724     HBufC* iPassword;
       
   725     
       
   726     /**
       
   727     * Sequence number from rtp info header concerning audio.
       
   728     */
       
   729     TUint iSeqFromRtpInfoForAudio;
       
   730     
       
   731     /**
       
   732     * Sequence number from rtp info header concerning video.
       
   733     */
       
   734     TUint iSeqFromRtpInfoForVideo;
       
   735     
       
   736     /**
       
   737     * RTP Session for audio.
       
   738     */
       
   739     RRtpSession iAudioSession;
       
   740     
       
   741     /**
       
   742     * RTP Session for video.
       
   743     */
       
   744     RRtpSession iVideoSession;
       
   745     
       
   746     /**
       
   747     * Receive stream for audio.
       
   748     */
       
   749     RRtpReceiveSource iRtpRecvSrcAudio;
       
   750     
       
   751     /**
       
   752     * Receive stream for audio.
       
   753     */
       
   754     RRtpReceiveSource iRtpRecvSrcVideo;
       
   755     
       
   756     /*
       
   757     * Socket server reference ; all sockets we use must be via common sock serv. 
       
   758     */
       
   759     RSocketServ& iSockServer;
       
   760     
       
   761     /*
       
   762     * RConnection wrapper reference ; all sockets we use must share an RConnection.
       
   763     */
       
   764     CCRConnection& iConnection;
       
   765 
       
   766     /*
       
   767     * Socket to use to talk RTSP to remote server. 
       
   768     */
       
   769     CCRSock* iRtspSock;
       
   770 
       
   771     /**
       
   772     * Sockets for incoming multicast RTP data, to bypass RTP stack limitations.
       
   773     */
       
   774     CCRSock* iRTPSockArr[ERTPMaxSockets];
       
   775 
       
   776     /**
       
   777     * pointer to data sent by us via socket.
       
   778     */
       
   779     HBufC8* iSentData;
       
   780     
       
   781     /**
       
   782     * State of this rtsp client, or stage in discussion.
       
   783     */
       
   784     TCRRTSPStage iStage;
       
   785     
       
   786     /**
       
   787     * Pointers to previous commands sent in various stages.
       
   788     */
       
   789     CCRRtspCommand* iPrevCommands[ERTSPLastStage];
       
   790     
       
   791     /**
       
   792     * Pointers to responses of various commands.
       
   793     */
       
   794     CCRRtspResponse* iResponses[ERTSPLastStage];
       
   795     
       
   796     /** 
       
   797     * CSeq for rtsp negotiation.
       
   798     */
       
   799     TInt iCSeq;
       
   800     
       
   801     /**
       
   802     * SDP parser.
       
   803     */
       
   804     CDvrSdpParser* iSdpParser;
       
   805     
       
   806     /**
       
   807     * Client portbase. Value used for video, for audio it is this value + 2.
       
   808     */
       
   809     TInt iClientPort;
       
   810     
       
   811     /**
       
   812     * Transport method for RTP.
       
   813     */
       
   814     TCRRTPTransport iTransport;
       
   815     
       
   816     /**
       
   817     * Timer for UDP reception timeout, to fire TCP usage.
       
   818     */
       
   819     CCRTimer* iUdpReceptionTimer;
       
   820     
       
   821     /**
       
   822     * IP packet parser.
       
   823     */
       
   824     CCRRtpTcpStreamer* iRtpTcpStreamer;
       
   825     
       
   826     /**
       
   827     * Session id from server.
       
   828     */
       
   829     TPtrC8 iSessionId;
       
   830     
       
   831     /**
       
   832     * If sink is ready.
       
   833     */
       
   834     TBool iReadyToPlay;
       
   835     
       
   836     /**
       
   837     * RTP time initial value for audio.
       
   838     */
       
   839     TUint32 iRTPTimeStampAudio;
       
   840     
       
   841     /**
       
   842     * RTP time initial value for video.
       
   843     */
       
   844     TUint32 iRTPTimeStampVideo;
       
   845     
       
   846     /**
       
   847     * If authentication is needed.
       
   848     */
       
   849     TBool iAuthenticationNeeded;
       
   850     
       
   851     /**
       
   852     * Nonce of the authentication header.
       
   853     */
       
   854     HBufC8* iNonce;
       
   855     
       
   856     /**
       
   857     * Realm of the authentication header.
       
   858     */
       
   859     HBufC8* iRealm;
       
   860     
       
   861     /**
       
   862     * Authentication type ("Basic" or "Digest"). 
       
   863     */
       
   864     HBufC8* iAuthType;
       
   865     
       
   866     /** 
       
   867     * Opaque of the authentication header.
       
   868     */
       
   869     HBufC8* iOpaque;
       
   870     
       
   871     /**
       
   872     * User Agent header if present.
       
   873     */
       
   874     HBufC8* iUserAgent;
       
   875     
       
   876     /**
       
   877     * Connection bandwidth in bit/s for 'Bandwidth' header.
       
   878     */
       
   879     TInt iBandwidth;
       
   880     
       
   881     /**
       
   882     * x-wap-profile if present.
       
   883     */
       
   884     HBufC8* iWapProfile;
       
   885     
       
   886     /**
       
   887     * Number of times authentication has failed.
       
   888     */
       
   889     TInt iAuthFailedCount;
       
   890     
       
   891     /**
       
   892     * Our observer.
       
   893     */
       
   894     MCRStreamObserver& iSessionObs;
       
   895     
       
   896     /**
       
   897     * Number of bytes sent in audio rtp packets.
       
   898     */
       
   899     TUint32 iAudioBytes;
       
   900     
       
   901     /**
       
   902     * Number os audio rtp packets sent.
       
   903     */
       
   904     TUint32 iAudioPackets;
       
   905     
       
   906     /**
       
   907     * Number of bytes sent in video rtp packets.
       
   908     */
       
   909     TUint32 iVideoBytes;
       
   910     
       
   911     /**
       
   912     * Number of video packets sent.
       
   913     */
       
   914     TUint32 iVideoPackets;
       
   915     
       
   916     /**
       
   917     * Instance for punch packet sender ; lifetime will be from setup stage
       
   918     * to delivery of first audio packet.
       
   919     */
       
   920     CCRPunchPacketSender* iPunchPacketSenderAudio;
       
   921     
       
   922     /**
       
   923     * Instance for punch packet sender ; lifetime will be from setup stage
       
   924     * to delivery of first video packet.
       
   925     */
       
   926     CCRPunchPacketSender* iPunchPacketSenderVideo;
       
   927     
       
   928     /**
       
   929     * Flag for successful sending of punch packets for audio stream.
       
   930     */
       
   931     TBool iPunchPacketSentForAudio;
       
   932     
       
   933     /**
       
   934     * Flag for successful sending of punch packets for video stream.
       
   935     */
       
   936     TBool iPunchPacketSentForVideo;
       
   937     
       
   938     /**
       
   939     * Connection status observer.
       
   940     */
       
   941     MCRConnectionObserver* iObserver;
       
   942     
       
   943     /**
       
   944     * Position where playback will start. Usually will have value 0 but will
       
   945     * be changed if user seeks the clip.
       
   946     */
       
   947     TReal iStartPos;
       
   948     
       
   949     /**
       
   950     * Position where playback is supposed to end. Most streaming servers won't
       
   951     * obey this at all but rtsp gives possibility to specify end position so
       
   952     * we'll support that anyway.
       
   953     */
       
   954     TReal iEndPos;
       
   955     
       
   956     /**
       
   957     * Sends RTSP ping.
       
   958     */
       
   959     CPeriodic* iRtspPingTimer;
       
   960     
       
   961     /**
       
   962     * Timer started when RTSP message is sent and cancelled when reply is received. 
       
   963     * If this timer fires, it means that we didn't get reply in time that in turn
       
   964     * forces cleanup of this source.
       
   965     */
       
   966     CPeriodic* iRtspTimeout;
       
   967 
       
   968     /**
       
   969     * Sequence number of last rtsp reply received. 
       
   970     */    
       
   971     TInt iLastReceivedSeq;
       
   972 
       
   973     /**
       
   974     * We have a play-command pending, not yet sent. 
       
   975     */    
       
   976     TInt iPostPonedPlay;
       
   977 
       
   978     /**
       
   979     * Proxy server addr to use while streaming.
       
   980     */
       
   981     TName iProxyServerAddr; 
       
   982 
       
   983     /**
       
   984     * Proxy server port to use while streaming. 
       
   985     */
       
   986     TInt iProxyServerPort;     
       
   987 
       
   988     /**
       
   989     * Flag telling that there has been no rtp-info header.
       
   990     * in play-response 
       
   991     */
       
   992     TBool iNoRtpInfoHeader; 
       
   993     
       
   994     /**
       
   995     * Wall-clock timestamp MSW part for syncronizing.
       
   996     */
       
   997     TUint32 iMSWTimestamp; 
       
   998     
       
   999     /**
       
  1000     * Wall-clock timestamp LSW part for syncronizing.
       
  1001     */
       
  1002     TUint32 iLSWTimestamp;
       
  1003     
       
  1004     /**
       
  1005     * Flag set when we manage to get UDP traffic. If we some reason loose
       
  1006     * traffic completely (eg staying too long in PAUSE -state while streaming)
       
  1007     * we dont try TCP at first but after we have tried UDP again.
       
  1008     */  
       
  1009     TBool iUdpFound;
       
  1010     
       
  1011     /**
       
  1012     * Simple container class representing one receive stream.
       
  1013     */
       
  1014     class TReceiveStream
       
  1015         {
       
  1016         public:
       
  1017         
       
  1018         /**
       
  1019         * Default constructor setting default values.
       
  1020         */
       
  1021         TReceiveStream()
       
  1022             {
       
  1023             iStreamType = EStreamIdCount;
       
  1024             iDataReceived = EFalse;
       
  1025             };
       
  1026         
       
  1027         /**
       
  1028         * Stream type, defined in MCRPacketSource.
       
  1029         */
       
  1030         TCRPacketStreamId iStreamType;
       
  1031         
       
  1032         /**
       
  1033         * Boolean flagging if we have traffic from this stream.
       
  1034         */
       
  1035         TBool iDataReceived;
       
  1036         };
       
  1037     
       
  1038     /**
       
  1039     * Array of receive streams.
       
  1040     */    
       
  1041     RArray<TReceiveStream> iReceiveStreams;
       
  1042     
       
  1043     /**
       
  1044     * Boolean flagging if we have found traffic from all receive streams.
       
  1045     */
       
  1046     TBool iTrafficFound;
       
  1047     
       
  1048     };
       
  1049 
       
  1050 #endif // CCRRTSPPACKETSOURCE_H
       
  1051 
       
  1052 // End of file