mmserv/voipaudioservices/JitterBufferUtility/inc/JitterBufferImpl.h
changeset 55 e267340986c9
parent 0 71ca22bcf22a
equal deleted inserted replaced
52:4ce423f34688 55:e267340986c9
     1 /*
     1 /*
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). 
     2  * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:  Jitter buffer for Audio frames.
    14  * Description:  Jitter buffer for Audio frames.
    15 *  Interface   : VoIPJitterBuffer.lib
    15  *  Interface   : VoIPJitterBuffer.lib
    16 *
    16  *
    17 */
    17  */
    18 
    18 
    19 
    19 #ifndef VOIPJITTERBUFFERIMPL_H
    20 
    20 #define VOIPJITTERBUFFERIMPL_H
    21 #ifndef __VOIPJITTERBUFFERIMPL_H
       
    22 #define __VOIPJITTERBUFFERIMPL_H
       
    23 
    21 
    24 //  INCLUDES
    22 //  INCLUDES
    25 #include <voipjitterbufferintfc.h>
    23 #include <voipjitterbufferintfc.h>
    26 
    24 
    27 // FORWARD DECLARATIONS
    25 // FORWARD DECLARATIONS
    32 
    30 
    33 /**
    31 /**
    34  *  Jitter buffer element including packet received.
    32  *  Jitter buffer element including packet received.
    35  *
    33  *
    36  *  @lib VoIPJitterBuffer.lib
    34  *  @lib VoIPJitterBuffer.lib
    37  *  @since Series 60 5.0
       
    38  */
    35  */
    39 class TJitterBufferElement
    36 class TJitterBufferElement
    40     {
    37     {
    41 public: // Constructor
    38 public:
    42     inline TJitterBufferElement() : iDataFrame(NULL),
    39     // Constructor
    43                                     iSequenceNumber(-1),
    40     inline TJitterBufferElement() :
    44                                     iTimeStamp(-1) {}
    41         iDataFrame(NULL),
    45 
    42         iSequenceNumber(-1),
    46 public: // Methods
    43         iTimeStamp(-1) {}
       
    44 
       
    45 public:
       
    46     // Methods
    47 
    47 
    48     /**
    48     /**
    49      * Compares two elements based on their sequence number
    49      * Compares two elements based on their sequence number
    50      * @since Series 60 5.0
    50      *
    51      * @param aElem1 First element
    51      * @param aElem1 First element
    52      * @param aElem2 Second element
    52      * @param aElem2 Second element
    53      * @return TInt
    53      * @return TInt
    54      */
    54      */
    55     static TInt CompareSeqNum(const TJitterBufferElement& aElem1,
    55     static TInt CompareSeqNum(const TJitterBufferElement& aElem1,
    56                               const TJitterBufferElement& aElem2);
    56             const TJitterBufferElement& aElem2);
    57 
    57 
    58     /**
    58     /**
    59      * Compares two elements based on their stamps
    59      * Compares two elements based on their stamps
    60      * @since Series 60 5.0
    60      *
    61      * @param aElem1 First element
    61      * @param aElem1 First element
    62      * @param aElem2 Second element
    62      * @param aElem2 Second element
    63      * @return TInt
    63      * @return TInt
    64      */
    64      */
    65     static TInt CompareStamp(const TJitterBufferElement& aElem1,
    65     static TInt CompareStamp(const TJitterBufferElement& aElem1,
    66                              const TJitterBufferElement& aElem2);
    66             const TJitterBufferElement& aElem2);
    67 
    67 
    68 public: // Data members
    68 public:
    69     // Data
    69     // Data members
       
    70 
       
    71     // Data buffer
    70     CMMFDataBuffer* iDataFrame;
    72     CMMFDataBuffer* iDataFrame;
    71 
    73 
    72     // Data packet number
    74     // Data packet number
    73     TInt64 iSequenceNumber;
    75     TInt64 iSequenceNumber;
    74 
    76 
    75     // Time stamp
    77     // Time stamp
    76     TInt64 iTimeStamp;
    78     TInt64 iTimeStamp;
    77 
       
    78     };
    79     };
    79 
       
    80 
    80 
    81 /**
    81 /**
    82  *  Jitter buffer.
    82  *  Jitter buffer.
    83  *
    83  *
    84  *  @lib VoIPJitterBuffer.lib
    84  *  @lib VoIPJitterBuffer.lib
    85  *  @since Series 60 5.0
       
    86  */
    85  */
    87 class CVoIPJitterBufferImpl : public CBase
    86 class CVoIPJitterBufferImpl : public CBase
    88     {
    87     {
    89 public: // Constructors and destructor
    88 public:
       
    89     // Constructors and destructor
    90 
    90 
    91     /**
    91     /**
    92      * Two-phased constructor.
    92      * Two-phased constructor.
    93      */
    93      */
    94     static CVoIPJitterBufferImpl* NewL(MJitterBufferObserver* aObserver);
    94     static CVoIPJitterBufferImpl* NewL(MJitterBufferObserver* aObserver);
    96     /**
    96     /**
    97      * Destructor.
    97      * Destructor.
    98      */
    98      */
    99     virtual ~CVoIPJitterBufferImpl();
    99     virtual ~CVoIPJitterBufferImpl();
   100 
   100 
   101 public: // Methods
   101 public:
       
   102     // Methods
   102 
   103 
   103     /**
   104     /**
   104      * Setup jitterbuffer
   105      * Setup jitterbuffer
   105      * @since Series 60 5.0
   106      *
   106      * @param parameters
   107      * @param parameters
   107      * @return void
   108      * @return void
   108      */
   109      */
   109     void SetupL(const TFourCC aCodec, const TVoIPJBConfig& aJBConfig);
   110     void SetupL(const TFourCC aCodec, const TVoIPJBConfig& aJBConfig);
   110 
   111 
   111     /**
   112     /**
   112      * Reset buffer
   113      * Reset buffer
   113      * @since Series 60 5.0
   114      *
   114      * @param aPlayTone ETrue, if tone is to played
   115      * @param aPlayTone ETrue, if tone is to played
   115      * @return void
   116      * @return void
   116      */
   117      */
   117     void ResetBuffer(TBool aPlayTone = ETrue);
   118     void ResetBuffer(TBool aPlayTone = ETrue);
   118 
   119 
   119     /**
   120     /**
   120      * Add DataFrame to buffer
   121      * Add DataFrame to buffer
   121      * @since Series 60 5.0
   122      *
   122      * @param aBuffer Buffer to read data from
   123      * @param aBuffer Buffer to read data from
   123      * @return void
   124      * @return void
   124      */
   125      */
   125     TInt AddDataFrame(CMMFBuffer* aDataBuffer);
   126     TInt AddDataFrame(CMMFBuffer* aDataBuffer);
   126 
   127 
   127     /**
   128     /**
   128      * Get DataFrame from buffer
   129      * Get DataFrame from buffer
   129      * @since Series 60 5.0
   130      *
   130      * @param aBuffer Buffer to write data to
   131      * @param aBuffer Buffer to write data to
   131      * @return TInt
   132      * @return TInt
   132      */
   133      */
   133     TInt GetDataFrame(CMMFBuffer* aBuffer);
   134     TInt GetDataFrame(CMMFBuffer* aBuffer);
   134 
   135 
   135     /**
   136     /**
   136      * Get Current Codec
   137      * Get Current Codec
   137      * @since Series 60 5.0
   138      *
   138      * @param None
   139      * @param None
   139      * @return TFourCC
   140      * @return TFourCC
   140      */
   141      */
   141     TFourCC CurrentCodec() const;
   142     TFourCC CurrentCodec() const;
   142 
   143 
   143     /**
   144     /**
   144      * Delay Up
   145      * Delay Up
   145      * @since Series 60 5.0
   146      *
   146      * @param None
   147      * @param None
   147      * @return void
   148      * @return void
   148      */
   149      */
   149     void DelayUpL();
   150     void DelayUpL();
   150 
   151 
   151     /**
   152     /**
   152      * Decreases jitter buffer delay
   153      * Decreases jitter buffer delay
   153      * @since Series 60 5.0
   154      *
   154      * @param None
   155      * @param None
   155      * @return void
   156      * @return void
   156      */
   157      */
   157     void DelayDownL();
   158     void DelayDownL();
   158 
   159 
       
   160 #ifdef __FEATURE_NOT_SUPPORTED__
   159     /**
   161     /**
   160      * ?Description
   162      * ?Description
   161      * @since Series 60 5.0
   163      *
   162      * @param None
   164      * @param None
   163      * @return TTimeIntervalMicroSeconds32
   165      * @return TTimeIntervalMicroSeconds32
   164      */
   166      */
   165     TTimeIntervalMicroSeconds32 CalculateDelay() const;
   167     TTimeIntervalMicroSeconds32 CalculateDelay() const;
       
   168 #endif //__FEATURE_NOT_SUPPORTED__
   166 
   169 
   167     /**
   170     /**
   168      * Get the length of jitter buffer, in terms of number of packets.
   171      * Get the length of jitter buffer, in terms of number of packets.
   169      * @since Series 60 5.0
   172      *
   170      * @param none
   173      * @param none
   171      * @return buffer lenght.
   174      * @return buffer lenght.
   172      */
   175      */
   173     TInt BufferLength() const;
   176     TInt BufferLength() const;
   174 
   177 
       
   178 #ifdef __FEATURE_NOT_SUPPORTED__
   175     /**
   179     /**
   176      * Get number of packets that are currently inside the buffer.
   180      * Get number of packets that are currently inside the buffer.
   177      * @since Series 60 5.0
   181      *
   178      * @param none
   182      * @param none
   179      * @return Number of packet in buffer.
   183      * @return Number of packet in buffer.
   180      */
   184      */
   181     TInt PacketCount() const;
   185     TInt PacketCount() const;
       
   186 #endif //__FEATURE_NOT_SUPPORTED__
   182 
   187 
   183     /**
   188     /**
   184      * Fills the given event with statistics of the jitterbuffer
   189      * Fills the given event with statistics of the jitterbuffer
   185      * @since Series 60 5.0
   190      *
   186      * @param aEvent Event into which set the statistics
   191      * @param aEvent Event into which set the statistics
   187      * @return void
   192      * @return void
   188      */
   193      */
   189     void GenerateStatistics(/*TJBStats& aStats*/) const;
   194     void GenerateStatistics(/*TJBStats& aStats*/) const;
   190 
   195 
   198     /**
   203     /**
   199      * By default Symbian 2nd phase constructor is private.
   204      * By default Symbian 2nd phase constructor is private.
   200      */
   205      */
   201     void ConstructL();
   206     void ConstructL();
   202 
   207 
   203 private: // New functions
   208 private:
       
   209     // New functions
   204 
   210 
   205     /**
   211     /**
   206      * Is sequence number wrapped around TUint16 65535->0
   212      * Is sequence number wrapped around TUint16 65535->0
   207      * @since Series 60 5.0
   213      *
   208      * @param TInt aSeqNum1 is oldest packet sequence number in buffer
   214      * @param TInt aSeqNum1 is oldest packet sequence number in buffer
   209      * @param TInt aSeqNum2 is new element sequence number to buffer
   215      * @param TInt aSeqNum2 is new element sequence number to buffer
   210      * @return detect the wrap-around condition.
   216      * @return detect the wrap-around condition.
   211      */
   217      */
   212     TBool IsSeqNumWrappedAround(TInt64 aSeqNum1, TInt64 aSeqNum2) const;
   218     TBool IsSeqNumWrappedAround(TInt64 aSeqNum1, TInt64 aSeqNum2) const;
   213 
   219 
   214     /**
   220     /**
   215      * Find Largest SequenceNumber
   221      * Find Largest SequenceNumber
   216      * @since Series 60 5.0
   222      *
   217      * @param None
   223      * @param None
   218      * @return TUint Largest sequence number
   224      * @return TUint Largest sequence number
   219      */
   225      */
   220     TUint FindLargestSeqNum();
   226     TUint FindLargestSeqNum();
   221 
   227 
   222     /**
   228     /**
   223      * Inserts a databuffer into the jitter buffer
   229      * Inserts a databuffer into the jitter buffer
   224      * @since Series 60 5.0
   230      *
   225      * @param aBuffer Buffer containing the data
   231      * @param aBuffer Buffer containing the data
   226      * @param aLargestSeqNum Largest sequence number returned by
   232      * @param aLargestSeqNum Largest sequence number returned by
   227      *                       FindLargestSeqNum()
   233      *                       FindLargestSeqNum()
   228      * @return void
   234      * @return void
   229      */
   235      */
   230     void InsertBufferElement(const TDesC8& aBuffer, TInt64 aLargestSeqNum);
   236     void InsertBufferElement(const TDesC8& aBuffer, TInt64 aLargestSeqNum);
   231 
   237 
   232     /**
   238     /**
   233      * Is jitter buffer full?
   239      * Is jitter buffer full?
   234      * @since Series 60 5.0
   240      *
   235      * @param none
   241      * @param none
   236      * @return True if full.
   242      * @return True if full.
   237      */
   243      */
   238     TBool IsFull() const;
   244     TBool IsFull() const;
   239 
   245 
   240     /**
   246     /**
   241      * Is jitter buffer empty?
   247      * Is jitter buffer empty?
   242      * @since Series 60 5.0
   248      *
   243      * @param none
   249      * @param none
   244      * @return True if empty.
   250      * @return True if empty.
   245      */
   251      */
   246     TBool IsEmpty() const;
   252     TBool IsEmpty() const;
   247 
   253 
   248     /**
   254     /**
   249      * CheckThresholdBufferLength
   255      * CheckThresholdBufferLength
   250      * @since Series 60 5.0
   256      *
   251      * @param none
   257      * @param none
   252      * @return void
   258      * @return void
   253      */
   259      */
   254     void CheckThresholdBufferLength(TInt& aBufferLength,
   260     void CheckThresholdBufferLength(TInt& aBufferLength,
   255                                     const TInt aTreshhold) const;
   261             const TInt aTreshhold) const;
   256 
   262 
   257 private: // Data
   263 private:
       
   264     // Data
   258 
   265 
   259     // Playout thresholds
   266     // Playout thresholds
   260     TInt iCurrentPlayThreshold;
   267     TInt iCurrentPlayThreshold;
   261     TInt iOriginalPlayThreshold;
   268     TInt iOriginalPlayThreshold;
   262 
   269 
   282 
   289 
   283     // JB configuration parameters
   290     // JB configuration parameters
   284     TVoIPJBConfig iJBConfig;
   291     TVoIPJBConfig iJBConfig;
   285 
   292 
   286     // Codec frame size
   293     // Codec frame size
   287     TInt  iFrameSize;
   294     TInt iFrameSize;
   288 
   295 
   289     // Encoded frame sample interval
   296     // Encoded frame sample interval
   290     TInt  iSampleInterval;
   297     TInt iSampleInterval;
   291 
   298 
   292     // Increment in frame sequence number
   299     // Increment in frame sequence number
   293     TUint iSeqNumIncrement;
   300     TUint iSeqNumIncrement;
   294     
   301 
   295     TBool iIsWrappedAround;
   302     TBool iIsWrappedAround;
   296 
   303 
   297     MJitterBufferObserver* iObserver;
   304     MJitterBufferObserver* iObserver;
   298     CMMFDataBuffer* iDataBuffer;
   305     CMMFDataBuffer* iDataBuffer;
   299 
   306 
   300 // These are mainly for statistical purpose
   307     // These are mainly for statistical purpose
   301 
   308 
   302     // Number of frames totally lost
   309     // Number of frames totally lost
   303     TUint iFramesLost;
   310     TUint iFramesLost;
   304 
   311 
   305     // Number of frames received
   312     // Number of frames received
   319 
   326 
   320     // Buffer overflow counter
   327     // Buffer overflow counter
   321     TUint iOverflowCounter;
   328     TUint iOverflowCounter;
   322 
   329 
   323     // Jitter buffer inctivity time
   330     // Jitter buffer inctivity time
   324     TInt  iInactivityTime;
   331     TInt iInactivityTime;
   325 
   332 
   326 // These are for tone playback
   333     // These are for tone playback
   327     TInt  iPlayToneInterval;
   334     TInt iPlayToneInterval;
   328     TTime iTonePlayTime;
   335     TTime iTonePlayTime;
   329     TInt  iSampleRate;
   336     TInt iSampleRate;
   330     TBool iPlay;
   337     TBool iPlay;
   331 
       
   332     };
   338     };
   333 
   339 
   334 #endif  //__VOIPJITTERBUFFERIMPL_H
   340 #endif  //VOIPJITTERBUFFERIMPL_H
   335 
   341 
   336 // End of file
   342 // End of file