|
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: Writes RTP payload format containing ILBC data. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef ILBCPAYLOADFORMATWRITE_H |
|
21 #define ILBCPAYLOADFORMATWRITE_H |
|
22 |
|
23 // INCLUDES |
|
24 #include <e32base.h> |
|
25 #include <mmf/server/mmfformat.h> |
|
26 #include <mmf/server/mmfdatabuffer.h> |
|
27 #include "rtpheader.h" |
|
28 #include "formatstatemachine.h" |
|
29 #include "mccinternalcodecs.h" |
|
30 |
|
31 // FORWARD DECLARATIONS |
|
32 class MMccRtpDataSink; |
|
33 class CMccRtpMediaClock; |
|
34 |
|
35 // CLASS DECLARATION |
|
36 /** |
|
37 * Packetizes RTP payload containing ILBC data. |
|
38 * |
|
39 * @lib Mccilbcplformat.dll |
|
40 * @since Series 60 3.0 |
|
41 */ |
|
42 class CIlbcPayloadFormatWrite : public CPayloadFormatWrite, |
|
43 public MAsyncEventHandler, |
|
44 public MPayloadFormatWrite |
|
45 { |
|
46 public: // Constructors and destructor |
|
47 /** |
|
48 * Two-phased constructor. |
|
49 * @param aSource Data source configuration parameters |
|
50 */ |
|
51 static CIlbcPayloadFormatWrite* NewL( MDataSink* aSink ); |
|
52 |
|
53 /** |
|
54 * Destructor. |
|
55 */ |
|
56 virtual ~CIlbcPayloadFormatWrite(); |
|
57 |
|
58 public: // New functions |
|
59 |
|
60 /** |
|
61 * Configures payload format with format spesific parameters. |
|
62 * Leaves with KErrArgument if parameters are invalid. |
|
63 * |
|
64 * @since Series 60 3.0 |
|
65 * @param aConfigParams Configuration parameters |
|
66 * @return void |
|
67 */ |
|
68 virtual void ConfigurePayloadFormatL( const TDesC8& aConfigParams, |
|
69 CMccRtpMediaClock& aClock ); |
|
70 |
|
71 public: // From MPayloadFormatWrite |
|
72 |
|
73 /** |
|
74 * Empty the source buffer by formatting the iLBC frames into RTP payload. |
|
75 * Source buffer is given in "iBuffer". |
|
76 * Called by the state machine. |
|
77 * |
|
78 * @since Series 60 3.0 |
|
79 * @param None |
|
80 * @return void |
|
81 */ |
|
82 void EmptySourceBufferL(); |
|
83 |
|
84 /** |
|
85 * Handle the event that source buffer has been emptied. |
|
86 * Source buffer is given in "iBuffer". |
|
87 * Called by the state machine. |
|
88 * |
|
89 * @since Series 60 3.0 |
|
90 * @param None |
|
91 * @return void |
|
92 */ |
|
93 void SourceBufferEmptiedL(); |
|
94 |
|
95 public: // From CMMFFormatEncode |
|
96 |
|
97 /** |
|
98 * Funtion to return time interval for the complete frame |
|
99 * |
|
100 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
101 * |
|
102 * @return time interval in micro seconds |
|
103 */ |
|
104 TTimeIntervalMicroSeconds FrameTimeInterval( TMediaId aMediaType ) const; |
|
105 |
|
106 /** *** NOT SUPPORTED *** |
|
107 * Function to return the clip duration |
|
108 * |
|
109 * @param aMediaType KUidMediaTypeAudio or KUidMediaTypeVideo |
|
110 * |
|
111 * @return clip duration in micro seconds |
|
112 */ |
|
113 TTimeIntervalMicroSeconds Duration( TMediaId aMediaType ) const; |
|
114 |
|
115 /** |
|
116 * Create a sink buffer for the given media |
|
117 * |
|
118 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
119 * KUidMediaTypeVideo |
|
120 * @param aReference value of False is returned to caller if sink |
|
121 * buffer is created |
|
122 * @return Pointer to sink buffer created |
|
123 */ |
|
124 CMMFBuffer* CreateSinkBufferL( TMediaId aMediaId, |
|
125 TBool& aReference ); |
|
126 |
|
127 /** |
|
128 * Return the sink four CC code for the given media |
|
129 * |
|
130 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
131 * KUidMediaTypeVideo |
|
132 * @return FourCC code for the mediaId |
|
133 */ |
|
134 TFourCC SinkDataTypeCode( TMediaId aMediaId ); |
|
135 |
|
136 /** |
|
137 * Set the sink data type to the given four CC code for the given media |
|
138 * |
|
139 * @param aSourceFourCC fourCC code |
|
140 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
141 * KUidMediaTypeVideo |
|
142 * @return error code KErrNotSupported if invalid media |
|
143 * ID, else return KErrNone |
|
144 */ |
|
145 TInt SetSinkDataTypeCode( TFourCC aSinkFourCC, |
|
146 TMediaId aMediaId ); |
|
147 |
|
148 /** |
|
149 * Log in to the sink thread - this funtion merely passes the command to |
|
150 * its sink clip data source object. The sink clip object will handle |
|
151 * the thread log on procedures. |
|
152 * |
|
153 * @param aEventHandler address of event handler |
|
154 * |
|
155 * @return error code returned by source clip |
|
156 */ |
|
157 TInt SinkThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
158 |
|
159 /** |
|
160 * Log out of the sink thread - this funtion merely passes the command to |
|
161 * its sink clip data source object. The sink clip object will handle |
|
162 * the thread log off procedures. |
|
163 * |
|
164 * @param |
|
165 * |
|
166 * @return |
|
167 */ |
|
168 void SinkThreadLogoff(); |
|
169 |
|
170 /** |
|
171 * Empty the given source buffer. |
|
172 * |
|
173 * @param aBuffer data buffer containing G.711 frames |
|
174 * @param aSupplier data source pointer |
|
175 * @param aMediaId contains the media type KUidMediaTypeAudio or |
|
176 * KUidMediaTypeVideo |
|
177 * @return |
|
178 */ |
|
179 void EmptyBufferL( CMMFBuffer* aBuffer, |
|
180 MDataSource* aSupplier, |
|
181 TMediaId aMediaId ); |
|
182 |
|
183 /** |
|
184 * Called after the data buffer is written. Update the number of bytes |
|
185 * written and the current write position for the next write operation. |
|
186 * |
|
187 * @param aBuffer data buffer emptied |
|
188 * |
|
189 * @return |
|
190 */ |
|
191 void BufferEmptiedL( CMMFBuffer* aBuffer ); |
|
192 |
|
193 /** |
|
194 * Accessor funtion to return the number of channels |
|
195 * |
|
196 * @param |
|
197 * |
|
198 * @return Number of channels |
|
199 */ |
|
200 TUint NumChannels(); |
|
201 |
|
202 /** |
|
203 * Accessor funtion to return the sampling rate |
|
204 * |
|
205 * @param |
|
206 * |
|
207 * @return Sampling rate |
|
208 */ |
|
209 TUint SampleRate(); |
|
210 |
|
211 /** |
|
212 * Set the samplerate to the given value. |
|
213 * |
|
214 * @param aSampleRate |
|
215 * |
|
216 * @return error code KErrNotSupported if invalid samplerate, else |
|
217 * return KErrNone |
|
218 */ |
|
219 TInt SetSampleRate( TUint aSampleRate ); |
|
220 |
|
221 /** |
|
222 * No implementation required for encoder. |
|
223 * |
|
224 * @param Not used |
|
225 * |
|
226 * @return KErrNone |
|
227 */ |
|
228 virtual TInt SendEventToClient( const TMMFEvent& /*aEvent*/ ) |
|
229 {return KErrNone;} |
|
230 |
|
231 |
|
232 public: // From MDataSink |
|
233 |
|
234 /** |
|
235 * From MDataSink Primes the source. |
|
236 * @since |
|
237 * @param |
|
238 * @return |
|
239 */ |
|
240 void SinkPrimeL(); |
|
241 |
|
242 /** |
|
243 * From MDataSink Plays the source. |
|
244 * @since |
|
245 * @param |
|
246 * @return |
|
247 */ |
|
248 void SinkPlayL(); |
|
249 |
|
250 /** |
|
251 * From MDataSink Pauses the source. |
|
252 * @since |
|
253 * @param |
|
254 * @return |
|
255 */ |
|
256 void SinkPauseL(); |
|
257 |
|
258 /** |
|
259 * From MDataSink Stops the source. |
|
260 * @since |
|
261 * @param |
|
262 * @return |
|
263 */ |
|
264 void SinkStopL(); |
|
265 |
|
266 |
|
267 private: // New functions |
|
268 |
|
269 /** |
|
270 * Prepare packet header and deliver the packet to the datasink. |
|
271 * @since Series 60 3.0 |
|
272 * @param aPayload Payload to deliver to the datasink. |
|
273 * @return |
|
274 */ |
|
275 void DeliverPacketL( CMMFDataBuffer& aPayload ); |
|
276 |
|
277 /** |
|
278 * Create a sink buffer of the given size. |
|
279 * |
|
280 * @param aSize size of sink buffer to create |
|
281 * |
|
282 * @return Pointer to sink buffer created |
|
283 */ |
|
284 CMMFDataBuffer* CreateSinkBufferOfSizeL( TUint aSize ); |
|
285 |
|
286 /** |
|
287 * Update payload format with format spesific parameters. |
|
288 * |
|
289 * @since Series 60 3.0 |
|
290 * @param aCodecInfo Codec info |
|
291 * @return void |
|
292 */ |
|
293 void UpdateConfigurationL( const TMccCodecInfo& aCodecInfo ); |
|
294 |
|
295 /** |
|
296 * Configures the formatter based on input parameters. |
|
297 * |
|
298 * @since Series 60 3.0 |
|
299 * @param aCodecInfo Codec info |
|
300 * @return void |
|
301 */ |
|
302 void DoConfigurePayloadFormatL( const TMccCodecInfo& aCodecInfo ); |
|
303 |
|
304 private: |
|
305 /** |
|
306 * C++ default constructor. |
|
307 */ |
|
308 CIlbcPayloadFormatWrite(); |
|
309 |
|
310 /** |
|
311 * By default Symbian 2nd phase constructor is private. |
|
312 * |
|
313 * @param aConf Decoder Configuration params |
|
314 */ |
|
315 void ConstructL( MDataSink* aSource ); |
|
316 |
|
317 private: // Data |
|
318 |
|
319 // FourCC |
|
320 TFourCC iFourCC; |
|
321 |
|
322 // Format encoding state machine |
|
323 CFormatEncodeStateMachine* iStateMachine; |
|
324 |
|
325 // Pointer to source data buffer, passed from MCPDataPath |
|
326 CMMFDataBuffer* iSourceBuffer; |
|
327 |
|
328 // Sink buffer to hold Ilbc/RTP payload |
|
329 CMMFDataBuffer* iSinkBuffer; |
|
330 |
|
331 // RTP header used for sending RTP packet |
|
332 TRtpSendHeader iRtpSendHeader; |
|
333 |
|
334 // Frames per RTP packet (packetization rate) |
|
335 TInt iFramesPerPacket; |
|
336 |
|
337 // Counter for determining are all frames/samples got for RTP packet |
|
338 TInt iFrameIndex; |
|
339 |
|
340 // Frame time interval in micro seconds |
|
341 TTimeIntervalMicroSeconds iFrameTimeInterval; |
|
342 |
|
343 // Current media type |
|
344 TMediaId iMediaId; |
|
345 |
|
346 // Flag to indicate whether to set MARK field to be 1 (the first |
|
347 // packet in a talk spurt should have MARK field set) |
|
348 TBool iFirstPacketFinished; |
|
349 |
|
350 // Indicates are we sending comfort noise payload |
|
351 TBool iCNModeON; |
|
352 |
|
353 // Data sink capable to receive RTP data |
|
354 MMccRtpDataSink* iRtpDataSink; |
|
355 |
|
356 // Parameters relating to RTP data encoding |
|
357 TMccCodecInfo iCInfo; |
|
358 |
|
359 // Boolen for rtp sink |
|
360 TBool iIsRtpSink; |
|
361 |
|
362 // Key for Rtp media clock |
|
363 TUint32 iKey; |
|
364 |
|
365 /** |
|
366 * Rtp media clock instance |
|
367 * Not own. |
|
368 */ |
|
369 CMccRtpMediaClock* iRtpMediaClock; |
|
370 |
|
371 // Friend class for testing |
|
372 #ifdef TEST_EUNIT |
|
373 friend class UT_CIlbcPayloadFormatWrite; |
|
374 #endif |
|
375 }; |
|
376 |
|
377 #endif //ILBCPAYLOADFORMATWRITE_H |