|
1 /* |
|
2 * Copyright (c) 2008 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 : VoIPJitterBuffer.lib |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 |
|
21 #ifndef __VOIPJITTERBUFFERIMPL_H |
|
22 #define __VOIPJITTERBUFFERIMPL_H |
|
23 |
|
24 // INCLUDES |
|
25 #include <voipjitterbufferintfc.h> |
|
26 |
|
27 // FORWARD DECLARATIONS |
|
28 class CVoIPCNGenerator; |
|
29 class MJitterBufferObserver; |
|
30 |
|
31 // CLASS DECLARATION |
|
32 |
|
33 /** |
|
34 * Jitter buffer element including packet received. |
|
35 * |
|
36 * @lib VoIPJitterBuffer.lib |
|
37 * @since Series 60 5.0 |
|
38 */ |
|
39 class TJitterBufferElement |
|
40 { |
|
41 public: // Constructor |
|
42 inline TJitterBufferElement() : iDataFrame(NULL), |
|
43 iSequenceNumber(-1), |
|
44 iTimeStamp(-1) {} |
|
45 |
|
46 public: // Methods |
|
47 |
|
48 /** |
|
49 * Compares two elements based on their sequence number |
|
50 * @since Series 60 5.0 |
|
51 * @param aElem1 First element |
|
52 * @param aElem2 Second element |
|
53 * @return TInt |
|
54 */ |
|
55 static TInt CompareSeqNum(const TJitterBufferElement& aElem1, |
|
56 const TJitterBufferElement& aElem2); |
|
57 |
|
58 /** |
|
59 * Compares two elements based on their stamps |
|
60 * @since Series 60 5.0 |
|
61 * @param aElem1 First element |
|
62 * @param aElem2 Second element |
|
63 * @return TInt |
|
64 */ |
|
65 static TInt CompareStamp(const TJitterBufferElement& aElem1, |
|
66 const TJitterBufferElement& aElem2); |
|
67 |
|
68 public: // Data members |
|
69 // Data |
|
70 CMMFDataBuffer* iDataFrame; |
|
71 |
|
72 // Data packet number |
|
73 TInt64 iSequenceNumber; |
|
74 |
|
75 // Time stamp |
|
76 TInt64 iTimeStamp; |
|
77 |
|
78 }; |
|
79 |
|
80 |
|
81 /** |
|
82 * Jitter buffer. |
|
83 * |
|
84 * @lib VoIPJitterBuffer.lib |
|
85 * @since Series 60 5.0 |
|
86 */ |
|
87 class CVoIPJitterBufferImpl : public CBase |
|
88 { |
|
89 public: // Constructors and destructor |
|
90 |
|
91 /** |
|
92 * Two-phased constructor. |
|
93 */ |
|
94 static CVoIPJitterBufferImpl* NewL(MJitterBufferObserver* aObserver); |
|
95 |
|
96 /** |
|
97 * Destructor. |
|
98 */ |
|
99 virtual ~CVoIPJitterBufferImpl(); |
|
100 |
|
101 public: // Methods |
|
102 |
|
103 /** |
|
104 * Setup jitterbuffer |
|
105 * @since Series 60 5.0 |
|
106 * @param parameters |
|
107 * @return void |
|
108 */ |
|
109 void SetupL(const TFourCC aCodec, const TVoIPJBConfig& aJBConfig); |
|
110 |
|
111 /** |
|
112 * Reset buffer |
|
113 * @since Series 60 5.0 |
|
114 * @param aPlayTone ETrue, if tone is to played |
|
115 * @return void |
|
116 */ |
|
117 void ResetBuffer(TBool aPlayTone = ETrue); |
|
118 |
|
119 /** |
|
120 * Add DataFrame to buffer |
|
121 * @since Series 60 5.0 |
|
122 * @param aBuffer Buffer to read data from |
|
123 * @return void |
|
124 */ |
|
125 TInt AddDataFrame(CMMFBuffer* aDataBuffer); |
|
126 |
|
127 /** |
|
128 * Get DataFrame from buffer |
|
129 * @since Series 60 5.0 |
|
130 * @param aBuffer Buffer to write data to |
|
131 * @return TInt |
|
132 */ |
|
133 TInt GetDataFrame(CMMFBuffer* aBuffer); |
|
134 |
|
135 /** |
|
136 * Get Current Codec |
|
137 * @since Series 60 5.0 |
|
138 * @param None |
|
139 * @return TFourCC |
|
140 */ |
|
141 TFourCC CurrentCodec() const; |
|
142 |
|
143 /** |
|
144 * Delay Up |
|
145 * @since Series 60 5.0 |
|
146 * @param None |
|
147 * @return void |
|
148 */ |
|
149 void DelayUpL(); |
|
150 |
|
151 /** |
|
152 * Decreases jitter buffer delay |
|
153 * @since Series 60 5.0 |
|
154 * @param None |
|
155 * @return void |
|
156 */ |
|
157 void DelayDownL(); |
|
158 |
|
159 /** |
|
160 * ?Description |
|
161 * @since Series 60 5.0 |
|
162 * @param None |
|
163 * @return TTimeIntervalMicroSeconds32 |
|
164 */ |
|
165 TTimeIntervalMicroSeconds32 CalculateDelay() const; |
|
166 |
|
167 /** |
|
168 * Get the length of jitter buffer, in terms of number of packets. |
|
169 * @since Series 60 5.0 |
|
170 * @param none |
|
171 * @return buffer lenght. |
|
172 */ |
|
173 TInt BufferLength() const; |
|
174 |
|
175 /** |
|
176 * Get number of packets that are currently inside the buffer. |
|
177 * @since Series 60 5.0 |
|
178 * @param none |
|
179 * @return Number of packet in buffer. |
|
180 */ |
|
181 TInt PacketCount() const; |
|
182 |
|
183 /** |
|
184 * Fills the given event with statistics of the jitterbuffer |
|
185 * @since Series 60 5.0 |
|
186 * @param aEvent Event into which set the statistics |
|
187 * @return void |
|
188 */ |
|
189 void GenerateStatistics(/*TJBStats& aStats*/) const; |
|
190 |
|
191 private: |
|
192 |
|
193 /** |
|
194 * C++ default constructor. |
|
195 */ |
|
196 CVoIPJitterBufferImpl(MJitterBufferObserver* aObserver); |
|
197 |
|
198 /** |
|
199 * By default Symbian 2nd phase constructor is private. |
|
200 */ |
|
201 void ConstructL(); |
|
202 |
|
203 private: // New functions |
|
204 |
|
205 /** |
|
206 * Is sequence number wrapped around TUint16 65535->0 |
|
207 * @since Series 60 5.0 |
|
208 * @param TInt aSeqNum1 is oldest packet sequence number in buffer |
|
209 * @param TInt aSeqNum2 is new element sequence number to buffer |
|
210 * @return detect the wrap-around condition. |
|
211 */ |
|
212 TBool IsSeqNumWrappedAround(TInt64 aSeqNum1, TInt64 aSeqNum2) const; |
|
213 |
|
214 /** |
|
215 * Find Largest SequenceNumber |
|
216 * @since Series 60 5.0 |
|
217 * @param None |
|
218 * @return TUint Largest sequence number |
|
219 */ |
|
220 TUint FindLargestSeqNum(); |
|
221 |
|
222 /** |
|
223 * Inserts a databuffer into the jitter buffer |
|
224 * @since Series 60 5.0 |
|
225 * @param aBuffer Buffer containing the data |
|
226 * @param aLargestSeqNum Largest sequence number returned by |
|
227 * FindLargestSeqNum() |
|
228 * @return void |
|
229 */ |
|
230 void InsertBufferElement(const TDesC8& aBuffer, TInt64 aLargestSeqNum); |
|
231 |
|
232 /** |
|
233 * Is jitter buffer full? |
|
234 * @since Series 60 5.0 |
|
235 * @param none |
|
236 * @return True if full. |
|
237 */ |
|
238 TBool IsFull() const; |
|
239 |
|
240 /** |
|
241 * Is jitter buffer empty? |
|
242 * @since Series 60 5.0 |
|
243 * @param none |
|
244 * @return True if empty. |
|
245 */ |
|
246 TBool IsEmpty() const; |
|
247 |
|
248 /** |
|
249 * CheckThresholdBufferLength |
|
250 * @since Series 60 5.0 |
|
251 * @param none |
|
252 * @return void |
|
253 */ |
|
254 void CheckThresholdBufferLength(TInt& aBufferLength, |
|
255 const TInt aTreshhold) const; |
|
256 |
|
257 private: // Data |
|
258 |
|
259 // Playout thresholds |
|
260 TInt iCurrentPlayThreshold; |
|
261 TInt iOriginalPlayThreshold; |
|
262 |
|
263 // Buffer length |
|
264 TInt iBufferLength; |
|
265 |
|
266 // Jitter buffer array (queue) |
|
267 RArray<TJitterBufferElement> iBuffer; |
|
268 |
|
269 // Instance of comfort noise generator |
|
270 CVoIPCNGenerator* iCNGenerator; |
|
271 |
|
272 // Frame SequenceNumber |
|
273 TInt64 iCurrentSeqNum; |
|
274 |
|
275 // Sequence number of previously played frame |
|
276 TInt64 iLastPlayedSeqNum; |
|
277 TInt64 iLargestSeqNum; |
|
278 |
|
279 // Jitter buffer sorting objects |
|
280 TLinearOrder<TJitterBufferElement> iBufStampSorter; |
|
281 TLinearOrder<TJitterBufferElement> iBufSequenceSorter; |
|
282 |
|
283 // JB configuration parameters |
|
284 TVoIPJBConfig iJBConfig; |
|
285 |
|
286 // Codec frame size |
|
287 TInt iFrameSize; |
|
288 |
|
289 // Encoded frame sample interval |
|
290 TInt iSampleInterval; |
|
291 |
|
292 // Increment in frame sequence number |
|
293 TUint iSeqNumIncrement; |
|
294 |
|
295 TBool iIsWrappedAround; |
|
296 |
|
297 MJitterBufferObserver* iObserver; |
|
298 CMMFDataBuffer* iDataBuffer; |
|
299 |
|
300 // These are mainly for statistical purpose |
|
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 // Number of frames arrived late |
|
315 TUint iNumOfLateFrames; |
|
316 |
|
317 // Number of packets in buffer |
|
318 TInt iPacketsInBuffer; |
|
319 |
|
320 // Buffer overflow counter |
|
321 TUint iOverflowCounter; |
|
322 |
|
323 // Jitter buffer inctivity time |
|
324 TInt iInactivityTime; |
|
325 |
|
326 // These are for tone playback |
|
327 TInt iPlayToneInterval; |
|
328 TTime iTonePlayTime; |
|
329 TInt iSampleRate; |
|
330 TBool iPlay; |
|
331 |
|
332 }; |
|
333 |
|
334 #endif //__VOIPJITTERBUFFERIMPL_H |
|
335 |
|
336 // End of file |