multimediacommscontroller/mmccvideosourcesink/inc/mccvideojitterbuffer.h
changeset 0 1bce908db942
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #ifndef MCCVIDEOJITTERBUFFER_H
       
    22 #define MCCVIDEOJITTERBUFFER_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "rtpdef.h"
       
    27 #include "rtpheader.h"
       
    28 
       
    29 // MACROS
       
    30 
       
    31 // DATA TYPES
       
    32 
       
    33 // FUNCTION PROTOTYPES
       
    34 
       
    35 // FORWARD DECLARATIONS
       
    36 class CXPSPacketSink;
       
    37 
       
    38 // CONSTANTS
       
    39 
       
    40 const TInt KMccJitterBufferDefaultMaxSize = 1200;
       
    41 const TInt KMccJitterBufferDefaultPlayThreshold = 600;
       
    42 const TInt KMccJitterBufferDefaultLowLimit = 200;
       
    43 const TInt KMccJitterBufferDefaultHighLimit = 900;
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 /**
       
    48 * Callback interface for buffer user.
       
    49 */ 
       
    50 class MMccVideoJitterBufferObserver
       
    51     {
       
    52     public:
       
    53         virtual void ErrorOccured( TInt aError ) = 0;
       
    54     };
       
    55     
       
    56 /**
       
    57 * Buffer for queueuing video packets before posting them towards Helix.
       
    58 * Buffer is used to fight against network abnormalities (e.g. bursts).
       
    59 *
       
    60 */
       
    61 class CMccVideoJitterBuffer : public CTimer
       
    62     {
       
    63 
       
    64 public:
       
    65 
       
    66     /**
       
    67     * Buffering status
       
    68     */        
       
    69     enum TMccPacketBufferingStatus
       
    70             {
       
    71             EBuffering,
       
    72             EPlayingStarted,
       
    73             EPlaying
       
    74             };
       
    75             
       
    76 
       
    77     /**
       
    78     * Storing data of single packet
       
    79     */
       
    80     class CMccVideoPacket : public CBase
       
    81         {
       
    82         public:
       
    83         
       
    84             static CMccVideoPacket* NewLC( TUint aStreamId, 
       
    85                                            const TRtpRecvHeader& aHeaderInfo, 
       
    86                                            const TDesC8& aPayloadData,
       
    87                                            TBool aImportantData );
       
    88             ~CMccVideoPacket();
       
    89             
       
    90             TUint StreamId();
       
    91             
       
    92             TRtpRecvHeader& HeaderInfo();
       
    93     
       
    94             const TDesC8& PayloadData();
       
    95             
       
    96             static TInt InsertInSeqNumOrder( const CMccVideoPacket& aPacket1, 
       
    97                                              const CMccVideoPacket& aPacket2 );
       
    98             
       
    99             TBool DroppingAllowed() const;
       
   100             
       
   101         private:
       
   102         
       
   103             CMccVideoPacket( TUint aStreamId, 
       
   104                              const TRtpRecvHeader& aHeaderInfo,
       
   105                              TBool aImportantData );
       
   106             
       
   107             void ConstructL( const TDesC8& aPayloadData );
       
   108             
       
   109         private:
       
   110         
       
   111             TUint iStreamId;
       
   112             
       
   113             TRtpRecvHeader iHeaderInfo;
       
   114             
       
   115             TBool iImportantData;
       
   116             
       
   117             HBufC8* iPayloadData;
       
   118             
       
   119         };
       
   120         
       
   121     /**
       
   122      * Two-phased constructor.
       
   123      * @param aObserver
       
   124      * @param aPacketSink
       
   125      * @param aInactivityTimeout in milliseconds
       
   126      */
       
   127     static CMccVideoJitterBuffer* NewL( MMccVideoJitterBufferObserver& aObserver, 
       
   128                                         CXPSPacketSink& aPacketSink,
       
   129                                         TUint aInactivityTimeoutInMs );
       
   130 
       
   131     /**
       
   132      * Two-phased constructor.
       
   133      * @param aObserver
       
   134      * @param aPacketSink
       
   135      * @param aInactivityTimeout in milliseconds
       
   136      */
       
   137     static CMccVideoJitterBuffer* NewLC( MMccVideoJitterBufferObserver& aObserver,
       
   138                                          CXPSPacketSink& aPacketSink,
       
   139                                          TUint aInactivityTimeoutInMs );
       
   140 
       
   141     /**
       
   142      * Destructor.
       
   143      */
       
   144     ~CMccVideoJitterBuffer();
       
   145     
       
   146     /**
       
   147     * Configure behavior of jitter buffer
       
   148     * @param aLowLimitMs
       
   149     * @param aHighLimitMs
       
   150     * @param aPlayThresholdMs
       
   151     * @param aMaxSizeMs
       
   152     * @param aFrameRateFps
       
   153     */
       
   154     void ConfigureL( TUint aLowLimitMs, 
       
   155                      TUint aHighLimitMs, 
       
   156                      TUint aPlayThresholdMs, 
       
   157                      TUint aMaxSizeMs, 
       
   158                      TUint aFrameRateFps );
       
   159     
       
   160     /**
       
   161     * Enqueu packet
       
   162     * @param aStreamId
       
   163     * @param aHeaderInfo
       
   164     * @param aPayloadData
       
   165     * @param aImportantData, ETrue if packet cannot be dropped
       
   166     * @return buffering status
       
   167     */
       
   168     TMccPacketBufferingStatus EnqueueL( TUint aStreamId, 
       
   169                     const TRtpRecvHeader& aHeaderInfo, 
       
   170                     const TDesC8& aPayloadData,
       
   171                     TBool aImportantData );
       
   172     
       
   173     /**
       
   174     * Start/resume packet posting
       
   175     */               
       
   176     void Play();
       
   177     
       
   178     /**
       
   179     * Pause packet posting
       
   180     */
       
   181     void Pause();
       
   182     
       
   183     /**
       
   184     * Get play threshold in milliseconds
       
   185     * @return play threshold in milliseconds
       
   186     */
       
   187     TInt PlayThresholdInMs();
       
   188 
       
   189 protected: // from base class CActive
       
   190 
       
   191     void RunL();
       
   192 
       
   193 private:
       
   194 
       
   195     CMccVideoJitterBuffer( MMccVideoJitterBufferObserver& aObserver,
       
   196                            CXPSPacketSink& aPacketSink,
       
   197                            TUint aInactivityTimeoutInMs );
       
   198 
       
   199     void ConstructL();
       
   200     
       
   201     void Start();
       
   202     
       
   203     TBool PlayThresholdExceeded();
       
   204     
       
   205     TTimeIntervalMicroSeconds32 CheckCurrentInterval();
       
   206     
       
   207     void UpdateFrameCount( CMccVideoPacket& aPacket, TBool aIsAdded );
       
   208     
       
   209     TBool PostFirstFrame();
       
   210     
       
   211     void MakeRoom();
       
   212     
       
   213     TBool MaxSizeExceeded();
       
   214     
       
   215     void CheckPostingInactivity( TInt64 aTimeFromPreviousFrame );
       
   216     
       
   217     CMccVideoJitterBuffer::TMccPacketBufferingStatus PlayingStatus();
       
   218     
       
   219     void DoRtpHeaderModify( TRtpRecvHeader& aRecvHeader );
       
   220     
       
   221 private: // data
       
   222 
       
   223     MMccVideoJitterBufferObserver& iObserver;
       
   224     CXPSPacketSink& iPacketSink;
       
   225     TUint iInactivityTimeoutInMicroSecs;
       
   226     
       
   227     RPointerArray<CMccVideoPacket> iQueue;
       
   228 
       
   229 	TUint iLowLimitMicroSecs;
       
   230     TUint iHighLimitMicroSecs;
       
   231     TUint iPlayThresholdMicroSecs;
       
   232     TUint iMaxSizeMicroSecs;
       
   233     TUint iFrameRate;
       
   234     
       
   235     TTimeIntervalMicroSeconds32 iCurrentInterval;
       
   236     TTimeIntervalMicroSeconds32 iNormalInterval;
       
   237     TTimeIntervalMicroSeconds32 iLowLimitInterval;
       
   238     TTimeIntervalMicroSeconds32 iHighLimitInterval;
       
   239     
       
   240     TUint iFrameCount;
       
   241     
       
   242     TBool iPlayThresholdExeeced;
       
   243     
       
   244     TBool iPlaybackStarted;
       
   245     
       
   246     TUint16 iSeqNum;
       
   247     
       
   248     TUint32 iCurrentRealtimeTimestamp;
       
   249     TUint32 iPreviousReceivedTimestamp;
       
   250     TTime iPreviousTime;
       
   251     
       
   252     private:
       
   253     	#ifdef TEST_EUNIT
       
   254 			friend class UT_CMccVideoJitterBuffer;
       
   255 			friend class UT_CMccVideoSinkUser;
       
   256    		#endif   	
       
   257     };
       
   258     
       
   259 
       
   260 
       
   261 #endif  // MCCVIDEOJITTERBUFFER_H
       
   262