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