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