|
1 /* |
|
2 * Copyright (c) 2004-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 "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: Jitter buffer for Audio frames. |
|
15 * Interface : |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 #ifndef MCCJITTERBUFFERIMPL_H |
|
23 #define MCCJITTERBUFFERIMPL_H |
|
24 |
|
25 // INCLUDES |
|
26 #include <e32base.h> |
|
27 #include "mccinternalcodecs.h" |
|
28 #include "mmccevents.h" |
|
29 |
|
30 // FORWARD DECLARATIONS |
|
31 class CMccCnGenerator; |
|
32 class CMMFDevSound; |
|
33 class TMccJitterBufferEventData; |
|
34 class MAsyncEventHandler; |
|
35 class MDataSink; |
|
36 class MJitterBufferObserver; |
|
37 |
|
38 // CLASS DECLARATION |
|
39 |
|
40 /** |
|
41 * Jitter buffer element including packet received. |
|
42 * |
|
43 * @lib MMccJitterBuffer.lib |
|
44 * @since Series 60 3.0 |
|
45 */ |
|
46 NONSHARABLE_CLASS( TJitterBufferElement ) |
|
47 { |
|
48 public: // Constructor |
|
49 inline TJitterBufferElement() : iDataFrame( NULL ), |
|
50 iSequenceNumber( -1 ), iStamp( -1 ) |
|
51 { }; |
|
52 |
|
53 public: // Data members |
|
54 // Data |
|
55 CMMFDataBuffer* iDataFrame; |
|
56 |
|
57 // Data packet number |
|
58 TInt64 iSequenceNumber; |
|
59 |
|
60 TInt64 iStamp; |
|
61 |
|
62 /** |
|
63 * Compares two elements based on their sequence number |
|
64 * @since Series 60 3.0 |
|
65 * @param aElem1 First element |
|
66 * @param aElem2 Second element |
|
67 * @return TInt |
|
68 */ |
|
69 static TInt CompareSeqNum( const TJitterBufferElement& aElem1, |
|
70 const TJitterBufferElement& aElem2 ); |
|
71 |
|
72 /** |
|
73 * Compares two elements based on their stamps |
|
74 * @since Series 60 3.0 |
|
75 * @param aElem1 First element |
|
76 * @param aElem2 Second element |
|
77 * @return TInt |
|
78 */ |
|
79 static TInt CompareStamp( const TJitterBufferElement& aElem1, |
|
80 const TJitterBufferElement& aElem2 ); |
|
81 }; |
|
82 |
|
83 /** |
|
84 * Jitter buffer. |
|
85 * |
|
86 * @lib MMccJitterBuffer.lib |
|
87 * @since Series 60 3.0 |
|
88 */ |
|
89 NONSHARABLE_CLASS( CMccJitterBufferImpl ) : public CBase |
|
90 { |
|
91 public: // Enumerations |
|
92 |
|
93 enum TMccJitterBufferImplState |
|
94 { |
|
95 EUnknown, |
|
96 EIdle, |
|
97 EPlaying, |
|
98 EBuffering, |
|
99 EDetermining |
|
100 }; |
|
101 |
|
102 public: // Constructors and destructor |
|
103 |
|
104 /** |
|
105 * Two-phased constructor. |
|
106 */ |
|
107 static CMccJitterBufferImpl* NewL( MJitterBufferObserver* aObserver = NULL ); |
|
108 |
|
109 /** |
|
110 * Destructor. |
|
111 */ |
|
112 virtual ~CMccJitterBufferImpl(); |
|
113 |
|
114 public: // Methods |
|
115 |
|
116 /** |
|
117 * Setup jitterbuffer |
|
118 * @since Series 60 3.0 |
|
119 * @param parameters |
|
120 * @return void |
|
121 */ |
|
122 void SetupL( TInt aPlayoutThreshold, |
|
123 const TMccCodecInfo& aCInfo, |
|
124 CMMFDevSound& aDevSound, |
|
125 MAsyncEventHandler* aEventHandler, |
|
126 TUint32 aEndpointId ); |
|
127 |
|
128 /** |
|
129 * Reset buffer |
|
130 * @since Series 60 3.0 |
|
131 * @param aPlayTone ETrue, if tone is to played |
|
132 * @param aNotifyUser ETrue, if state change should be notified |
|
133 * @return void |
|
134 */ |
|
135 void ResetBuffer( TBool aPlayTone = ETrue, TBool aNotifyUser = ETrue ); |
|
136 |
|
137 /** |
|
138 * Add DataFrame to buffer |
|
139 * @since Series 60 3.0 |
|
140 * @param aBuffer Buffer to read data from |
|
141 * @return void |
|
142 */ |
|
143 void AddDataFrameL( CMMFBuffer* aDataBuffer ); |
|
144 |
|
145 /** |
|
146 * Get DataFrame from buffer |
|
147 * @since Series 60 3.0 |
|
148 * @param aBuffer Buffer to write data to |
|
149 * @return void |
|
150 */ |
|
151 void GetDataFrameL( CMMFBuffer* aBuffer ); |
|
152 |
|
153 /** |
|
154 * Get Current Codec |
|
155 * @since Series 60 3.0 |
|
156 * @param None |
|
157 * @return TFourCC |
|
158 */ |
|
159 TFourCC CurrentCodec() const; |
|
160 |
|
161 /** |
|
162 * Delay Up |
|
163 * @since Series 60 3.0 |
|
164 * @param None |
|
165 * @return void |
|
166 */ |
|
167 void DelayUpL(); |
|
168 |
|
169 /** |
|
170 * Decreases jitter buffer delay |
|
171 * @since Series 60 3.0 |
|
172 * @param None |
|
173 * @return void |
|
174 */ |
|
175 void DelayDownL(); |
|
176 |
|
177 /** |
|
178 * ?Description |
|
179 * @since Series 60 3.0 |
|
180 * @param None |
|
181 * @return TTimeIntervalMicroSeconds32 |
|
182 */ |
|
183 TTimeIntervalMicroSeconds32 CalculateDelay() const; |
|
184 |
|
185 /** |
|
186 * Get the length of jitter buffer, in terms of number of packets. |
|
187 * @since Series 60 3.0 |
|
188 * @param none |
|
189 * @return buffer lenght. |
|
190 */ |
|
191 TInt BufferLength() const; |
|
192 |
|
193 /** |
|
194 * Fills the given event with statistics of the jitterbuffer |
|
195 * @since Series 60 3.0 |
|
196 * @param aEvent Event into which set the statistics |
|
197 * @return void |
|
198 */ |
|
199 void GenerateStatistics( TMccJitterBufferEventData& aEvent ) const; |
|
200 |
|
201 private: |
|
202 |
|
203 /** |
|
204 * C++ default constructor. |
|
205 */ |
|
206 CMccJitterBufferImpl( MJitterBufferObserver* aObserver ); |
|
207 |
|
208 /** |
|
209 * By default Symbian 2nd phase constructor is private. |
|
210 */ |
|
211 void ConstructL(); |
|
212 |
|
213 private: // New functions |
|
214 |
|
215 /** |
|
216 * Is sequence number wrapped around TUint16 65535->0 |
|
217 * @since Series 60 3.0 |
|
218 * @param TInt aSeqNum1 is oldest packet sequence numper in buffer |
|
219 * @param TInt aSeqNum2 is new element sequence numper to buffer |
|
220 * @return detect the wrap-around condition. |
|
221 */ |
|
222 TBool IsSeqNumWrappedAround( TInt64 aSeqNum1, TInt64 aSeqNum2 ) const; |
|
223 |
|
224 /** |
|
225 * Find Largest SequenceNumber |
|
226 * @since Series 60 3.0 |
|
227 * @param None |
|
228 * @return TInt Largest sequence number |
|
229 */ |
|
230 TInt FindLargestSeqNum() const; |
|
231 |
|
232 /** |
|
233 * Inserts a databuffer into the jitter buffer |
|
234 * @since Series 60 3.0 |
|
235 * @param aBuffer Buffer containing the data |
|
236 * @param aLargestSeqNum Largest sequence number returned by |
|
237 * FindLargestSeqNum() |
|
238 * @param aFrameNumber Sequence number of frame to be inserted. |
|
239 * @return void |
|
240 */ |
|
241 void InsertBufferElement( const TDesC8& aBuffer, TInt64 aLargestSeqNum, |
|
242 TInt64 aFrameNumber ); |
|
243 |
|
244 /** |
|
245 * Is jitter buffer full? |
|
246 * @since Series 60 3.0 |
|
247 * @param none |
|
248 * @return True if full. |
|
249 */ |
|
250 TBool IsFull() const; |
|
251 |
|
252 /** |
|
253 * Is jitter buffer empty? |
|
254 * @since Series 60 3.0 |
|
255 * @param none |
|
256 * @return True if empty. |
|
257 */ |
|
258 TBool IsEmpty() const; |
|
259 |
|
260 void HandleNotifications( TBool aBuffering ); |
|
261 |
|
262 void CheckThresholdBufferLength( TInt& aBufferLength, const TInt aTreshhold ) const; |
|
263 |
|
264 void SendStreamEventToClient( TMccEventType aEventType, |
|
265 TBool aAllEndpoints = EFalse ); |
|
266 |
|
267 void SetBufferState( TMccJitterBufferImplState aState ); |
|
268 |
|
269 TMccJitterBufferImplState BufferState() const; |
|
270 |
|
271 private: // Data |
|
272 |
|
273 // Playout thresholds for storing the original threshold and current |
|
274 // threshold |
|
275 TInt iCurrentPlayThreshold; |
|
276 TInt iOriginalPlayThreshold; |
|
277 |
|
278 // Number of packets in buffer |
|
279 TInt iPacketsInBuffer; |
|
280 |
|
281 // Jitterbuffer RArray. |
|
282 RArray<TJitterBufferElement> iBuffer; |
|
283 |
|
284 // instance of comfortnoise generator. |
|
285 CMccCnGenerator* iCnGenerator; |
|
286 |
|
287 // Sequence number of packet that is played out last time |
|
288 TInt64 iLastGetSeqNum; |
|
289 |
|
290 // Function object for jitterbuffer sorting |
|
291 TLinearOrder<TJitterBufferElement> iBufStampSorter; |
|
292 |
|
293 // Function object for jitterbuffer sorting |
|
294 TLinearOrder<TJitterBufferElement> iBufSequenceSorter; |
|
295 |
|
296 // Number of frames arrived late |
|
297 TUint iNumOfLateFrames; |
|
298 |
|
299 // Count of sequential late frames |
|
300 TUint iNumOfSequentialLateFrames; |
|
301 |
|
302 // Number of frames totally lost |
|
303 TUint iFramesLost; |
|
304 |
|
305 // Number of frames received |
|
306 TUint iFramesReceived; |
|
307 |
|
308 // Number of frames removed by adaptation or because of overflows |
|
309 TUint iFramesRemoved; |
|
310 |
|
311 // Number of frames played |
|
312 TUint iFramesPlayed; |
|
313 |
|
314 // Codec information |
|
315 TMccCodecInfo iCInfo; |
|
316 |
|
317 // Codec frame size |
|
318 TInt iFrameSize; |
|
319 |
|
320 // Codec frame time |
|
321 TInt iFrameTime; |
|
322 |
|
323 // Increment in frame sequence number |
|
324 TUint iSeqNumIncrement; |
|
325 |
|
326 TBool iPlay; |
|
327 |
|
328 TInt iInactivityTime; |
|
329 |
|
330 MJitterBufferObserver* iObserver; |
|
331 |
|
332 TUint iOverflowCounter; |
|
333 |
|
334 TInt iPlayToneInterval; |
|
335 TTime iTonePlayTime; |
|
336 |
|
337 MAsyncEventHandler* iEventHandler; |
|
338 |
|
339 // Endpoint identifier |
|
340 TUint32 iEndpointId; |
|
341 |
|
342 TMccEvent iMccEvent; |
|
343 |
|
344 TBool iNotifyUser; |
|
345 |
|
346 TMccJitterBufferImplState iBufferState; |
|
347 |
|
348 TMccEventType iLatestNotifiedEvent; |
|
349 |
|
350 TInt iSampleRate; |
|
351 |
|
352 /** |
|
353 * Flag to determine whether frame removal or frame drop should be done in |
|
354 * overflow situation. |
|
355 */ |
|
356 TBool iDropNextFrame; |
|
357 |
|
358 private: |
|
359 #ifdef TEST_EUNIT |
|
360 friend class UT_CMccJitterBufferImpl; |
|
361 #endif |
|
362 }; |
|
363 |
|
364 #endif //MCCJITTERBUFFERIMPL_H |
|
365 |
|
366 // End of File |
|
367 |