multimediacommscontroller/mmccvideosourcesink/inc/mccvideosinkuser.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 MCCVIDEOSINKUSER_H
       
    22 #define MCCVIDEOSINKUSER_H
       
    23 
       
    24 // INCLUDES
       
    25 #include <e32base.h>
       
    26 #include "rtpdef.h"
       
    27 #include "mccinternalcodecs.h"
       
    28 #include "mccvideojitterbuffer.h"
       
    29 
       
    30 // N times average timestamp difference in timestamps between subsequent packets
       
    31 // is allowed
       
    32 const TInt KMccTimeStampDifferenceTreshold = 20;
       
    33 
       
    34 // Number of subsequent timestamps stored
       
    35 const TInt KMccTimeStampArraySize = 4;
       
    36 
       
    37 // Minimum size for Helix PacketSink queue
       
    38 const TInt KMccMinXPSQueueSize = 1000;
       
    39 
       
    40 // Limits for sequence number based timestamp difference threshold
       
    41 const TInt KMccSeqNumDifferenceThresholdMin = 10;
       
    42 const TInt KMccSeqNumDifferenceThresholdMax = 100;
       
    43 
       
    44 // Mininum payload buffer size
       
    45 const TInt KMccVideoSinkMinPayloadBufSize = 4096;
       
    46 
       
    47 // MACROS
       
    48 
       
    49 // DATA TYPES
       
    50 
       
    51 // FUNCTION PROTOTYPES
       
    52 
       
    53 // FORWARD DECLARATIONS
       
    54 class CXPSPacketSink;
       
    55 
       
    56 // CLASS DECLARATION
       
    57 
       
    58 class TMccTimeStampEntry
       
    59     {
       
    60 public:
       
    61 
       
    62     inline TMccTimeStampEntry();
       
    63     
       
    64     inline TMccTimeStampEntry( TInt64 aTime, TUint16 aSeq );
       
    65         
       
    66     TInt64 iTime;
       
    67     TUint16 iSeq;
       
    68     };
       
    69 
       
    70 /**
       
    71 * Stores details of single videosink user. Is used also to detect
       
    72 * incorrect RTP timestamp usage. If other end is detected
       
    73 * to be misbehaving, timestamps are tried to be corrected as otherwise
       
    74 * video player is not able to playback the stream. 
       
    75 *
       
    76 *  @lib 
       
    77 *  @since 
       
    78 */
       
    79 class CMccVideoSinkUser : public CBase, public MMccVideoJitterBufferObserver
       
    80     {
       
    81     public: // Enumerations
       
    82     
       
    83         enum TMccPacketOverflowState
       
    84             {
       
    85             ENormal,
       
    86             EOccured,
       
    87             ERecovered
       
    88             };
       
    89             
       
    90         enum TMccTimeStampModifyMode
       
    91             {
       
    92             EModifyInit,
       
    93             EModifyRequiredMonitoring,
       
    94             EModifyRequired,
       
    95             EModifyNotRequiredMonitoring,
       
    96             EModifyNotRequired
       
    97             };
       
    98     
       
    99     public: // Functions
       
   100 
       
   101         /**
       
   102         * Constructor
       
   103         */
       
   104         static CMccVideoSinkUser* NewL( MAsyncEventHandler* aAsyncEventHandler, 
       
   105                                         TUid aMediaType,
       
   106                                         TUint aStreamId,
       
   107                                         TReal aFrameRate,
       
   108                                         CXPSPacketSink& aPacketSink );
       
   109                                          
       
   110         /**
       
   111         * Constructor
       
   112         */
       
   113         static CMccVideoSinkUser* NewLC( MAsyncEventHandler* aAsyncEventHandler, 
       
   114                                          TUid aMediaType,
       
   115                                          TUint aStreamId,
       
   116                                          TReal aFrameRate,
       
   117                                          CXPSPacketSink& aPacketSink );
       
   118         
       
   119         ~CMccVideoSinkUser();
       
   120         
       
   121         /**
       
   122         * Enqueue packet
       
   123         * @param aHeader
       
   124         * @param aPayloadData
       
   125         */
       
   126         CMccVideoJitterBuffer::TMccPacketBufferingStatus 
       
   127             EnqueueL( const TRtpRecvHeader& aHeaderInfo, 
       
   128                       const TDesC8& aPayloadData );
       
   129     
       
   130         /**
       
   131         * Set identifier values. E.g. can be used if this class is used
       
   132         * as dummy search parameter.
       
   133         * @param aAsyncEventHandler
       
   134         * @param aMediaType
       
   135         * @param aStreamId
       
   136         */
       
   137         void Set( MAsyncEventHandler* aAsyncEventHandler, 
       
   138                   TUid aMediaType,
       
   139                   TUint aStreamId );
       
   140         
       
   141         /**
       
   142         * Set framerate for the user
       
   143         * @param aFrameRate
       
   144         */
       
   145         void SetFrameRateL( TReal aFrameRate );
       
   146         
       
   147         /**
       
   148         * Get preroll value for the user
       
   149         * @return preroll value
       
   150         */
       
   151         TInt GetPreroll();
       
   152         
       
   153         /**
       
   154         * Get actual preroll value for the user
       
   155         * @return preroll value
       
   156         */
       
   157         TInt GetActualPreroll();
       
   158         
       
   159         /**
       
   160         * User play
       
   161         */
       
   162         void Play();
       
   163         
       
   164         /**
       
   165         * User pause
       
   166         */
       
   167         void Pause();
       
   168                            
       
   169         TBool IsQueueSizeDefined() const;
       
   170             
       
   171         TUint QueueSize() const;
       
   172             
       
   173         TMccPacketOverflowState PacketOverflowState() const;
       
   174 
       
   175         void SetPacketOverflow( TMccPacketOverflowState aState );
       
   176             
       
   177         void AddTimeStamp( TInt64 aTimeStamp, TUint16 aSeq ); 
       
   178         
       
   179         void Reset( TBool aFullReset );
       
   180         
       
   181         void CalculateAverageTimeStampDifference();
       
   182         
       
   183         TBool IsResetNeeded( TRtpRecvHeader& aHeaderInfo );
       
   184         
       
   185         TBool IsResetNeeded() const;
       
   186         
       
   187         TBool IsModifyNeeded( TRtpRecvHeader& aHeaderInfo );
       
   188     
       
   189         void SetAllowFrame( TBool aAllowFrame );
       
   190             
       
   191         TBool AllowFrame() const;
       
   192         
       
   193         /**
       
   194         * Let user know whether there's other users
       
   195         * @param aMultipleMediaTypes
       
   196         */
       
   197         void SetMultipleMediaTypesL( TBool aMultipleMediaTypes );
       
   198         
       
   199         /**
       
   200         * Set codec info for the user
       
   201         * @param aCodecInfo
       
   202         */
       
   203         void SetCodecInfoL( const TMccCodecInfo& aCodecInfo );
       
   204 
       
   205         TMccCodecInfo& CodecInfo();
       
   206         
       
   207         TInt GetPayloadSize();
       
   208     
       
   209     public: // From MMccVideoJitterBufferObserver
       
   210     
       
   211         void ErrorOccured( TInt aError );
       
   212         
       
   213     private:
       
   214     
       
   215         TInt NumTimeStamps() const;
       
   216         
       
   217         void RemoveFirstTimeStamp();
       
   218         
       
   219         void RemoveAllTimeStamps();
       
   220         
       
   221         TBool DoModify( TRtpRecvHeader& aHeaderInfo );
       
   222         
       
   223         TInt SeqNumDifToLastSeqNum( TUint16 aSeq );
       
   224         
       
   225        
       
   226         void DoModifyCheckInit( const TRtpRecvHeader& aHeaderInfo );
       
   227         
       
   228         void DoModifyCheckMonitoring( const TRtpRecvHeader& aHeaderInfo );
       
   229         
       
   230         void SetModifyingState( TMccTimeStampModifyMode aModifyMode );
       
   231         
       
   232         TBool MonitoringModify();
       
   233         
       
   234         TBool ModifyRequired();
       
   235         
       
   236         TUint32 GetTimestampDifferenceToPrevious( TUint32 aCurrentTimestamp );
       
   237         
       
   238         void UpdateFirstTimestamp( TUint32 aTimestamp );
       
   239         
       
   240         TUint32 DifferenceThreshold( TInt aSeqNumDif ) const;
       
   241         
       
   242         void CheckDenyFramesMaxPeriod();
       
   243         
       
   244         void DecideMonitoringContinuation( TMccTimeStampModifyMode aNextState );
       
   245         
       
   246         TBool IsResetNeededNormalMode( TRtpRecvHeader& aHeaderInfo );
       
   247     
       
   248         TBool IsResetNeededRealTimeMode( TRtpRecvHeader& aHeaderInfo );
       
   249         
       
   250         TBool RealTimeUser();
       
   251         
       
   252         void CheckErrorL( TInt aError );
       
   253         
       
   254         TBool CodecSpecificDataHandling( const TDesC8& aPayloadData );
       
   255     
       
   256     private:
       
   257     
       
   258         CMccVideoSinkUser( MAsyncEventHandler* aAsyncEventHandler, 
       
   259                            TUid aMediaType,
       
   260                            TUint aStreamId,
       
   261                            TReal aFrameRate,
       
   262                            CXPSPacketSink& aPacketSink );
       
   263                                                    
       
   264     public: // Data
       
   265     
       
   266         MAsyncEventHandler* iAsyncEventHandler;
       
   267         TUid iMediaType;
       
   268         TUint iStreamId;
       
   269         TMccTimeStampEntry iTimeStamps[ KMccTimeStampArraySize ];
       
   270         TBool iStartedOnce;
       
   271         TReal iFrameRate;
       
   272         TMccCodecInfo iCodecInfo;
       
   273         
       
   274     private:
       
   275     
       
   276         CXPSPacketSink& iPacketSink;  
       
   277         
       
   278         TMccPacketOverflowState iPacketOverflowState;
       
   279         TInt iNumTimeStamps;
       
   280         TUint32 iAverageTimeStampDifference;
       
   281         TBool iResetNeeded;
       
   282         TMccTimeStampModifyMode iModifyMode;
       
   283         
       
   284         TTime iFirstModifyCheck;
       
   285         TUint32 iFirstModifyCheckTimestamp;
       
   286         TUint32 iFirstTimestamp;
       
   287         
       
   288         TBool iAllowFrame;
       
   289         TTime iDenyFramesStarted;
       
   290         
       
   291         TBool iMultipleMediaTypes;
       
   292         
       
   293         TUint32 iPreviousPacketOriginalTimeStamp;
       
   294         TUint32 iPreviousPacketModifiedTimeStamp;
       
   295         TTime iPreviousPacketTime;
       
   296         
       
   297         TUint32 iCurrentMonitoringPeriod;
       
   298         
       
   299         TReal iTimestampIncreaseFactorDown;
       
   300         TReal iTimestampIncreaseFactorUp;
       
   301         
       
   302         CMccVideoJitterBuffer* iJitterBuf;
       
   303         
       
   304         TInt iPayloadSize;
       
   305     
       
   306     private:
       
   307     	#ifdef TEST_EUNIT
       
   308 			friend class UT_CMccVideoSinkImpl;
       
   309 			friend class UT_CMccVideoSinkUser;	
       
   310    		#endif    
       
   311     };
       
   312 
       
   313 #endif  // MCCVIDEOSINKUSER_H
       
   314