|
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 #ifndef __VOIPJITTERBUFFER_H |
|
20 #define __VOIPJITTERBUFFER_H |
|
21 |
|
22 // DATA TYPES |
|
23 |
|
24 // FORWARD DECLARATIONS |
|
25 class CMccCnGenerator; |
|
26 class CVoIPJitterBufferImpl; |
|
27 class TVoIPJBConfig; |
|
28 class MJitterBufferObserver; |
|
29 |
|
30 // CLASS DECLARATION |
|
31 |
|
32 /** |
|
33 * Jitter buffer. |
|
34 * |
|
35 * @lib VoIPJitterBuffer.lib |
|
36 * @since Series 60 5.0 |
|
37 */ |
|
38 class CVoIPJitterBuffer : public CActive |
|
39 { |
|
40 private: |
|
41 /** |
|
42 * Jitter buffer states |
|
43 */ |
|
44 enum TJBState |
|
45 { |
|
46 EJBufStopped, |
|
47 EJBufPlaying, |
|
48 EJBufPaused |
|
49 }; |
|
50 |
|
51 /** |
|
52 * Transition states during JB playback |
|
53 */ |
|
54 enum TJBTransitionState |
|
55 { |
|
56 EWait, |
|
57 // ENeedData, |
|
58 EEmptyData |
|
59 }; |
|
60 |
|
61 public: |
|
62 // Constructors and destructor |
|
63 |
|
64 /** |
|
65 * Two-phased constructor. |
|
66 */ |
|
67 IMPORT_C static CVoIPJitterBuffer* NewL(MJitterBufferObserver* aObserver); |
|
68 |
|
69 /** |
|
70 * Destructor. |
|
71 */ |
|
72 virtual ~CVoIPJitterBuffer(); |
|
73 |
|
74 public: |
|
75 // Methods |
|
76 |
|
77 /** |
|
78 * SetupL |
|
79 * Sets codec information and initializes JB. |
|
80 * @since Series 60 5.0 |
|
81 * @param TFourCC - codec's fourcc |
|
82 * @param TVoIPJBConfig& - JB configuraion parameters |
|
83 * @return void |
|
84 */ |
|
85 IMPORT_C void SetupL(const TFourCC aCodec, const TVoIPJBConfig& aJBConfig); |
|
86 |
|
87 /** |
|
88 * ResetBuffer |
|
89 * Resets JB to its original state with no data. |
|
90 * @since Series 60 5.0 |
|
91 * @param TBool - ETrue == tone is to be played |
|
92 * @return void |
|
93 */ |
|
94 IMPORT_C void ResetBuffer(TBool aPlayTone = ETrue); |
|
95 |
|
96 /** |
|
97 * Delay Down |
|
98 * |
|
99 * @since Series 60 5.0 |
|
100 * @param none |
|
101 * @return void |
|
102 */ |
|
103 IMPORT_C void DelayDown(); |
|
104 |
|
105 /** |
|
106 * Delay Up |
|
107 * |
|
108 * @since Series 60 5.0 |
|
109 * @param none |
|
110 * @return void |
|
111 */ |
|
112 IMPORT_C void DelayUp(); |
|
113 |
|
114 /** |
|
115 * Play |
|
116 * |
|
117 * @since Series 60 5.0 |
|
118 * @param none |
|
119 * @return void |
|
120 */ |
|
121 IMPORT_C void Play(); |
|
122 |
|
123 /** |
|
124 * Pause |
|
125 * |
|
126 * @since Series 60 5.0 |
|
127 * @param none |
|
128 * @return void |
|
129 */ |
|
130 IMPORT_C void Pause(); |
|
131 |
|
132 /** |
|
133 * Stop |
|
134 * |
|
135 * @since Series 60 5.0 |
|
136 * @param none |
|
137 * @return void |
|
138 */ |
|
139 IMPORT_C void Stop(); |
|
140 |
|
141 /** |
|
142 * FillBuffer |
|
143 * Retrieves next frame from JB queue. |
|
144 * @since Series 60 5.0 |
|
145 * @param CMMFBuffer* - buffer to be filled with data from the JB |
|
146 * @return TInt |
|
147 */ |
|
148 IMPORT_C TInt FillBuffer(CMMFBuffer* aBuffer); |
|
149 |
|
150 /** |
|
151 * EmptyBufferL |
|
152 * Queues received frame in JB. |
|
153 * @since Series 60 5.0 |
|
154 * @param CMMFBuffer* - buffer to be queued in the JB |
|
155 * @return TInt |
|
156 */ |
|
157 IMPORT_C TInt EmptyBuffer(CMMFBuffer* aBuffer); |
|
158 |
|
159 private: |
|
160 |
|
161 /** |
|
162 * C++ default constructor. |
|
163 */ |
|
164 CVoIPJitterBuffer(MJitterBufferObserver* aObserver); |
|
165 |
|
166 /** |
|
167 * Symbian 2nd phase constructor. |
|
168 */ |
|
169 void ConstructL(); |
|
170 |
|
171 /** |
|
172 * from CActive |
|
173 */ |
|
174 void DoCancel(); |
|
175 |
|
176 /** |
|
177 * from CActive |
|
178 */ |
|
179 void RunL(); |
|
180 |
|
181 /** |
|
182 * from CActive |
|
183 */ |
|
184 TInt RunError(TInt aError); |
|
185 |
|
186 private: |
|
187 // Internal helper methods |
|
188 |
|
189 /** |
|
190 * Play current frame from JB. |
|
191 * @since Series 60 5.0 |
|
192 * @param none |
|
193 * @return void |
|
194 */ |
|
195 void PlayBuffer(); |
|
196 |
|
197 /** |
|
198 * TransitionState |
|
199 * @since Series 60 5.0 |
|
200 * @param TJBTransitionState |
|
201 * @param TUint32 |
|
202 * @return void |
|
203 */ |
|
204 void TransitionState(TJBTransitionState aTransitionState, |
|
205 TUint32 aStateChangeDelay = 0); |
|
206 |
|
207 /** |
|
208 * Calculates the time interval at which data rate should be slowed down |
|
209 * when subsequent EmptyBufferL calls are coming too fast. |
|
210 * @since Series 60 5.0 |
|
211 * @param none |
|
212 * @return Suggested delay in microseconds. |
|
213 */ |
|
214 TUint32 DetermineEmptyBufferDelay(); |
|
215 |
|
216 private: |
|
217 // Data |
|
218 |
|
219 // Jitter buffer Implementation |
|
220 CVoIPJitterBufferImpl* iJitterBufferImpl; |
|
221 |
|
222 // Pointer to databuffer |
|
223 CMMFBuffer* iPlayBuffer; |
|
224 |
|
225 // Jitterbuffer state |
|
226 TJBState iState; |
|
227 |
|
228 // JB Transition State |
|
229 TJBTransitionState iTransitionState; |
|
230 |
|
231 MJitterBufferObserver* iObserver; |
|
232 TFourCC iCodec; |
|
233 |
|
234 RTimer iTimer; |
|
235 TTime iTmCurrentEmptyBuffer; |
|
236 TTime iTmPreviousEmptyBuffer; |
|
237 |
|
238 TUint32 iSampleInterval; |
|
239 TUint32 iEmptyBufferDelayThreshold; |
|
240 |
|
241 // Current request size of the buffer |
|
242 TInt iRequestSize; |
|
243 |
|
244 }; |
|
245 |
|
246 #endif //__VOIPJITTERBUFFER_H |
|
247 |
|
248 // End of file |