dvrengine/CommonRecordingEngine/inc/CCRRtspSink.h
branchRCL_3
changeset 23 13a33d82ad98
parent 0 822a42b6c3f1
equal deleted inserted replaced
22:826cea16efd9 23: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:    Packet sink where real one player gets media stream.*
       
    15 */
       
    16 
       
    17 
       
    18 
       
    19 
       
    20 #ifndef CCRRTSPSINK_H
       
    21 #define CCRRTSPSINK_H
       
    22 
       
    23 // INCLUDES
       
    24 #include "CCRSock.h"
       
    25 #include "CCRRtspCommand.h"
       
    26 #include "CCRRtspResponse.h"
       
    27 #include "CCRPacketBuffer.h"
       
    28 #include "CCRStreamingSession.h"
       
    29 #include "CCRPacketSinkBase.h"
       
    30 #include <e32base.h>
       
    31 
       
    32 // CONSTANTS
       
    33 // None.
       
    34 
       
    35 // MACROS
       
    36 // None
       
    37 
       
    38 // DATA TYPES
       
    39 // None
       
    40 
       
    41 // FORWARD DECLARATIONS
       
    42 class CDvrSdpParser; 
       
    43 class CCRConnection; 
       
    44 class RSocketServ; 
       
    45 class CCRStreamingSession; 
       
    46 
       
    47 // CLASS DECLARATION
       
    48 /**
       
    49 *  Packet sink that forwards stream to rop plugin via rtsp.
       
    50 *  Implements rtsp server. 
       
    51 *
       
    52 *  @lib CommonRecordingEngine.lib
       
    53 *  @since Series 60 3.0
       
    54  */
       
    55 class CCRRtspSink : public CCRPacketSinkBase,
       
    56                     public MCRSockObserver
       
    57     {
       
    58 
       
    59 public:
       
    60 
       
    61     /**
       
    62     * Enum for 5 socket to use to play to rop plugin.
       
    63     */
       
    64     enum TCRROPSockId
       
    65         {
       
    66         EROPControl = 0, /**< control sock, rtsp in tcp spoken here */
       
    67         EROPVideoSend1,  /**< RTP video payload */
       
    68         EROPVideoSend2,  /**< RTCP video */
       
    69         EROPAudioSend1,  /**< RTP audio payload */
       
    70         EROPAudioSend2,  /**< RTCP audio */
       
    71         EROPMaxSockets   /**< Just max value, no real socket assigned for this */   
       
    72         };
       
    73 
       
    74 public: // Constructors and destructors   
       
    75 
       
    76     /**
       
    77     * Two-phased constructor.
       
    78     * @param aConnection a connection rerefrence.
       
    79     * @param aSockServer a socket server refrence.
       
    80     * @param aSinkId a id of this sink.
       
    81     * @param aOwningSession a reference to owning session.
       
    82     * @param aLoopbackPort a RTSP port for loopback socket.
       
    83     * @return CCRRtspSink pointer.
       
    84     */
       
    85     static CCRRtspSink* NewL( CCRConnection& aConnection,
       
    86                               RSocketServ& aSockServer,
       
    87                               CCRStreamingSession::TCRSinkId aSinkId,
       
    88                               const TInt& aLoopbackPort,
       
    89                               CCRStreamingSession& aOwningSession );
       
    90     
       
    91     /**
       
    92      * Destructor 
       
    93      */
       
    94     virtual ~CCRRtspSink();
       
    95     
       
    96 private: // Methods from base classes
       
    97 
       
    98     /**
       
    99     * From CCRPacketSinkBase.
       
   100     * Connects the given buffer with this sink.
       
   101     * @since Series 60 3.0
       
   102     * @param aBuffer is the buffer to connect with.
       
   103     * @return none.
       
   104     */
       
   105     void SetBuffer( CCRPacketBuffer* aBuffer );
       
   106     
       
   107     /**
       
   108     * From CCRPacketSinkBase.
       
   109     * Adds packet to the sink.
       
   110     * @since Series 60 3.0
       
   111     * @return none.
       
   112     */
       
   113     void NewPacketAvailable();
       
   114     
       
   115     /**
       
   116     * From CCRPacketSinkBase.
       
   117     * Method for setting the sdp in use
       
   118     * @since Series 60 3.0
       
   119     * @param aSdp is the new sdp
       
   120     * @return none
       
   121     */
       
   122     void SetSdpL( const TDesC8& aSdp );
       
   123     
       
   124     /**
       
   125     * From CCRPacketSinkBase.
       
   126     * Method for setting initial seq+ts _before_ the stream is played.
       
   127     * @since Series 60 3.0
       
   128     * @param aAudioSeq is the initial rtp seq number for audio packets.
       
   129     * @param aAudioTS  is the initial rtp timestamp number for audio packets.
       
   130     * @param aVideoSeq is the initial rtp seq number for video packets.
       
   131     * @param aVideoTS  is the initial rtp timestamp number for video packets.
       
   132     * @return none.
       
   133     */
       
   134     void SetSeqAndTS( TUint& aAudioSeq,
       
   135                       TUint& aAudioTS,
       
   136                       TUint& aVideoSeq,
       
   137                       TUint& aVideoTS );
       
   138 
       
   139     /**
       
   140     * From CCRPacketSinkBase.
       
   141     * method for setting play range before the stream is played.
       
   142     * @since Series 60 3.0
       
   143     * @param aLower is where clip range begins, in seconds.
       
   144     * @param aUpper is where clip range ends, usually clip end, in seconds.
       
   145     * @return none.
       
   146     */
       
   147     void SetRange( TReal aLower,
       
   148                    TReal aUpper );    
       
   149     
       
   150     /**
       
   151     * From CCRPacketSinkBase.
       
   152     * Method that source uses to communicate its status.
       
   153     * @since Series 60 3.0
       
   154     * @param aNewState is the new state of the source.
       
   155     * @return none.
       
   156     */
       
   157     void StatusChanged( MCRPacketSource::TCRPacketSourceState aNewState );
       
   158     
       
   159     /**
       
   160     * From MCRSockObserver.
       
   161     * This method is called after some data has been received from socket.
       
   162     * @since Series 60 3.0
       
   163     * @param aData is descriptor containing the data received. 
       
   164     *        ownership of data is not passed via this call. 
       
   165     * @return none.
       
   166     */
       
   167     void DataReceived( TInt aSockId, const TDesC8 &aData );
       
   168 
       
   169     /**
       
   170     * From MCRSockObserver.
       
   171     * This method is called after status of socket changes.
       
   172     * @param aSockId 
       
   173     * @param aStatus is sock status.
       
   174     * @param aError
       
   175     * @return none.
       
   176     */
       
   177     void SockStatusChange( TInt aSockId,
       
   178                            CCRSock::TCRSockStatus aStatus,
       
   179                            TInt aError );
       
   180     
       
   181 public: // Constructors and destructors   
       
   182 
       
   183     /**
       
   184     * By default default constructor is private
       
   185     * @param aConnection is the IAP representative that we need to use
       
   186     * @param aSockServer is the socketserver to use when opening socks
       
   187     * @param aSinkId that this class needs to use when reporting progress back to owner
       
   188     * @param aOwningSession is the streaming session that owns this instance
       
   189     */
       
   190     CCRRtspSink( CCRConnection& aConnection,
       
   191                  RSocketServ& aSockServer,
       
   192                  CCRStreamingSession::TCRSinkId aSinkId,
       
   193                  CCRStreamingSession& aOwningSession );
       
   194 
       
   195     /**
       
   196     * second phase of 2-phased construction
       
   197     * @param aLoopbackPort a RTSP port for loopback socket.
       
   198     */
       
   199     void ConstructL( const TInt& aLoopbackPort ); 
       
   200 
       
   201 protected: // New methods
       
   202 
       
   203     /**
       
   204     * Method that produces sdp for rop plugin consumption. 
       
   205     * Needs to have iSDP and parser. 
       
   206     * @since Series 60 3.0
       
   207     * @param none.
       
   208     * @return none.
       
   209     */
       
   210     void ProduceSDPForRopL(); 
       
   211 
       
   212     /**
       
   213     * Method for doing something with commands rop has sent to us
       
   214     * @since Series 60 3.0
       
   215     * @param none.
       
   216     * @return none.
       
   217     */
       
   218     void ProcessRtspCommandL();  
       
   219 
       
   220     /**
       
   221     * Method for doing something after rop has said something to use.
       
   222     * @since Series 60 3.0
       
   223     * @param aLastCommand is the last command rop has sent
       
   224     * @return none.
       
   225     */
       
   226     void ProduceRtspReplyL( CCRRtspCommand::TCommand aLastCommand );  
       
   227     
       
   228     /**
       
   229     * Method for replying to "options" command.
       
   230     * @since Series 60 3.0
       
   231     * @param none.
       
   232     * @return none.
       
   233     */
       
   234     void ReplyToOptionsL();
       
   235 
       
   236     /**
       
   237     * Method for replying to "describe" command.
       
   238     * @since Series 60 3.0
       
   239     * @param none.
       
   240     * @return none.
       
   241     */
       
   242     void ReplyToDescribeL();
       
   243 
       
   244     /**
       
   245     * Method for replying to "setup" command
       
   246     * @since Series 60 3.0
       
   247     * @param none.
       
   248     * @return none.
       
   249     */
       
   250     void ReplyToSetupL();
       
   251 
       
   252     /**
       
   253     * Method for replying to "play" command, reply is sent to rop.
       
   254     * @since Series 60 3.0
       
   255     * @param none.
       
   256     * @return none.
       
   257     */
       
   258     void ReplyToPlayL();
       
   259 
       
   260     /**
       
   261     * Method for replying to "pause" command.
       
   262     * @since Series 60 3.0
       
   263     * @param symbian error code telling if pausing was ok.
       
   264     * @return none.
       
   265     */
       
   266     void ReplyToPauseL( TInt aErrorCode );
       
   267 
       
   268     /**
       
   269     * Method for replying to "teardown" command.
       
   270     * @since Series 60 3.0
       
   271     * @param none.
       
   272     * @return none.
       
   273     */
       
   274     void ReplyToTearDownL();
       
   275 
       
   276 private: // New methods
       
   277 
       
   278     /**
       
   279     * Getter for socket sink id basing on stream.
       
   280     * @since Series 60 3.0
       
   281     * @param aStreamId a stream id of packet.
       
   282     * @return a socket sink id.
       
   283     */
       
   284     TCRROPSockId SocketFromStream( MCRPacketSource::TCRPacketStreamId aStreamId );
       
   285     
       
   286     /**
       
   287     * Appends string to the buffer.
       
   288     * @since Series 60 3.0
       
   289     * @param aBuffer a buffer where to add text.
       
   290     * @param aTxt a string to append.
       
   291     * @return none.
       
   292     */
       
   293     void AppendL( HBufC8*& aBuffer,
       
   294                   const TDesC8& aTxt );
       
   295 
       
   296     /**
       
   297     * Appends integer value as text to the buffer.
       
   298     * @since Series 60 3.0
       
   299     * @param aBuffer a buffer where to add text.
       
   300     * @param aNum a numerical value to append.
       
   301     * @return none.
       
   302     */
       
   303     void AppendNumL( HBufC8*& aBuffer,
       
   304                      const TInt aNum );
       
   305 
       
   306     /**
       
   307     * Appends formatted text to the buffer.
       
   308     * @since Series 60 3.0
       
   309     * @param aBuffer a buffer where to add text.
       
   310     * @param aFmt a format string to use.
       
   311     * @return none.
       
   312     */
       
   313     void AppendFormatL( HBufC8*& aBuffer,
       
   314                         TRefByValue<const TDesC8> aFmt, ... );
       
   315 
       
   316     /**
       
   317     * Sends control data to the player.
       
   318     * @since Series 60 3.0
       
   319     * @param none. 
       
   320     * @return none.
       
   321     */
       
   322     void SendControlData();
       
   323 
       
   324     /**
       
   325     * This meyhod is called after received data from EROPControl socket.
       
   326     * @since Series 60 3.1
       
   327     * @param aData is descriptor containing the data received. 
       
   328     */
       
   329     void HandleReceivedEROPControlL( const TDesC8& aData );
       
   330 
       
   331 private: // Data
       
   332 
       
   333     /**
       
   334     * RConnection wrapper we use for sockets. no ownership. 
       
   335     */
       
   336     CCRConnection& iConnection;
       
   337 
       
   338     /**
       
   339     * Socket server we use for sockets. no ownership. 
       
   340     */
       
   341     RSocketServ& iSockServer;
       
   342 
       
   343     /**
       
   344     * When TBool in iPacketPendingInBuffer is ETrue it means that the buffer
       
   345     * in iBuffers having same array index. As said TBool has a packet 
       
   346     * waiting to be sent to rop.
       
   347     */ 
       
   348     TBool iPacketPendingInBuffer;
       
   349     
       
   350     /**
       
   351     * Have our own sdp parser for parsing the sdp.
       
   352     */
       
   353     CDvrSdpParser* iSdpParser;
       
   354 
       
   355     /**
       
   356     * SDP to give to rop.
       
   357     */
       
   358     HBufC8* iSdpForRop;
       
   359 
       
   360     /**
       
   361     * Sockets for speaking with rop.
       
   362     */
       
   363     CCRSock* iSockArr[EROPMaxSockets]; 
       
   364     
       
   365     /** 
       
   366     * Stage in rtsp discussions with rop plugin.
       
   367     */
       
   368     TCRRTSPStage iStage; 
       
   369     
       
   370     /** 
       
   371     * Stage for setup repply received.
       
   372     */
       
   373     TInt iSetupReceived;
       
   374     
       
   375     /**
       
   376     * Pointer to data sent to us via socket from rop.
       
   377     */
       
   378     HBufC8* iReceivedData;
       
   379     
       
   380     /** 
       
   381     * Pointers to commands sent by rop in various stages.
       
   382     */
       
   383     CCRRtspCommand *iCommands[CCRRtspCommand::ERTSPCommandNOCOMMAND];
       
   384     
       
   385     /** 
       
   386     * Pointer to string sent to rop.
       
   387     */
       
   388     HBufC8* iRopResponse; 
       
   389 
       
   390     /** 
       
   391     * Audio seq to begin with.
       
   392     */
       
   393     TUint32 iAudioSeq;
       
   394     
       
   395     /**
       
   396     * Audio TS to begin with.
       
   397     */
       
   398     TUint32 iAudioTS;
       
   399     
       
   400     /**
       
   401     * Video seq to begin with.
       
   402     */  
       
   403     TUint32 iVideoSeq;
       
   404     
       
   405     /**
       
   406     * Video TS to begin with
       
   407     */
       
   408     TUint32 iVideoTS;
       
   409     
       
   410     /**
       
   411     * TBool telling if above 4 things (seq+ts*2) has been seen.
       
   412     */
       
   413     TBool iSeqAndTSSet;
       
   414     
       
   415     /**
       
   416     * Range begin pos in play command header.
       
   417     */
       
   418     TReal iLowerRange; 
       
   419     
       
   420     /**
       
   421     * Range end pos in play command header.
       
   422     */
       
   423     TReal iUpperRange; 
       
   424     
       
   425     };
       
   426 
       
   427 #endif // CCRRTSPSINK_H