|
1 /* |
|
2 * Copyright (c) 2002-2004 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: RTP Datasource |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #ifndef MCCRTPDATASOURCE_H |
|
22 #define MCCRTPDATASOURCE_H |
|
23 |
|
24 // INCLUDES |
|
25 #include "rtpheader.h" |
|
26 #include "mccdatasource.h" |
|
27 #include "mccrtpinterface.h" |
|
28 #include "mccdef.h" |
|
29 #include "mccjittercalculator.h" |
|
30 |
|
31 // CONSTANTS |
|
32 |
|
33 // UIDs |
|
34 |
|
35 // MACROS |
|
36 |
|
37 // DATA TYPES |
|
38 |
|
39 // FUNCTION PROTOTYPES |
|
40 |
|
41 // FORWARD DECLARATIONS |
|
42 class MDataSink; |
|
43 class CMccTimerManager; |
|
44 |
|
45 // CLASS DECLARATION |
|
46 |
|
47 |
|
48 /** |
|
49 * ECom-plugin which receives and forwards RTP/RTCP packets. |
|
50 * |
|
51 * @lib MccRtpSourceSink.dll |
|
52 * @since Series 60 3.0 |
|
53 */ |
|
54 class CMccRtpDataSource : public CMccDataSource, |
|
55 public MMccRtpInterface, |
|
56 public MRtpObserver, |
|
57 public MRtpJitterObserver, |
|
58 public MMccExpirationHandler |
|
59 { |
|
60 |
|
61 public: // Constructors and destructor |
|
62 |
|
63 /** |
|
64 * Two-phased constructor. |
|
65 */ |
|
66 static MDataSource* NewSourceL( TUid aImplementationUid, |
|
67 const TDesC8& aInitData ); |
|
68 |
|
69 /** |
|
70 * Destructor. |
|
71 */ |
|
72 virtual ~CMccRtpDataSource(); |
|
73 |
|
74 public: // New functions |
|
75 |
|
76 /** |
|
77 * Registers payload types, which should pass RTP-source validation. |
|
78 * |
|
79 * @since Series 60 3.2 |
|
80 * @param aPayloadTypes Payload types to accept in validation |
|
81 * @return void |
|
82 */ |
|
83 virtual void RegisterPayloadTypesL( const RArray<TUint>& aPayloadTypes ); |
|
84 |
|
85 /** |
|
86 * Unregisters payload types to be accepted. |
|
87 * |
|
88 * @since Series 60 3.2 |
|
89 * @param aPayloadTypes Payload types to unregister |
|
90 * @return void |
|
91 */ |
|
92 virtual void UnRegisterPayloadTypes( const RArray<TUint>& aPayloadTypes ); |
|
93 |
|
94 public: // From MRtpObserver |
|
95 |
|
96 /** |
|
97 * From MRtpObserver. |
|
98 */ |
|
99 void RtpPacketReceived( TRtpId aStreamId, |
|
100 const TRtpRecvHeader& aHeaderInfo, |
|
101 const TDesC8& aPayloadData ); |
|
102 |
|
103 public: // From MMccRtpInterface |
|
104 |
|
105 /** |
|
106 * Starts inactivity timer for a stream in a given session. |
|
107 * @param aTimeoutTime - [input] timeout value in milliseconds |
|
108 * @return One of the standard system-wide error codes. |
|
109 */ |
|
110 void StartInactivityTimerL( TUint32 aTimeoutTime ); |
|
111 |
|
112 /** |
|
113 * Stops inactivity timer for a stream in a given session. |
|
114 * @return One of the standard system-wide error codes. |
|
115 */ |
|
116 void StopInactivityTimerL( ); |
|
117 |
|
118 TInt StandBy( TMccStandbyActionType aActionType, TUint aPayloadType ); |
|
119 |
|
120 void SendMediaSignallingL( const TMccEvent& aEvent ); |
|
121 |
|
122 TRtpId RtpStreamId(); |
|
123 |
|
124 void DoCreateSrtpStreamL(); |
|
125 |
|
126 public: // From MDataSource |
|
127 |
|
128 /** |
|
129 * From MDataSource. Returns the data type as a fourCC code of the data source. |
|
130 * |
|
131 * @since Series 60 3.0 |
|
132 * @param "aMediaId" |
|
133 * This identifies the type of media eg audio or video and the stream id. |
|
134 * Only KUidMediaTypeAudio -mediatype is supported. |
|
135 * @return The fourCC code identifying the source datatype for the specified aMediaId. |
|
136 */ |
|
137 TFourCC SourceDataTypeCode( TMediaId /*aMediaId*/ ); |
|
138 |
|
139 /** |
|
140 * From MDataSource. Sets the data type as a fourCC code for the data source |
|
141 * |
|
142 * @since Series 60 3.0 |
|
143 * @param "aSourceFourCC" |
|
144 * This specifies the data type as a fourCC code to set the source to. |
|
145 * |
|
146 * @param "aMediaId" |
|
147 * This identifies the type of media eg audio or video and the stream id. |
|
148 * Only KUidMediaTypeAudio -mediatype is supported. |
|
149 * |
|
150 * @return KErrNone if successful, KErrNotSupported if the source does not support having |
|
151 * it's data type set, otherwise a system wide error code. |
|
152 */ |
|
153 TInt SetSourceDataTypeCode( TFourCC aCodec, |
|
154 TMediaId aMedia ); |
|
155 |
|
156 /** |
|
157 * From MDataSource. Not used. Leaves with KErrNotSupported. |
|
158 * |
|
159 * @since Series 60 3.0 |
|
160 * @param "aBuffer" |
|
161 * The buffer that has been emptied by a data sink and is now available for reuse |
|
162 * @return None |
|
163 */ |
|
164 void BufferEmptiedL( CMMFBuffer* aBuffer ); |
|
165 |
|
166 /** |
|
167 * From MDataSource. Method to indicate whether the data source can create a buffer. |
|
168 * |
|
169 * @since Series 60 3.0 |
|
170 * |
|
171 * @return EFalse |
|
172 */ |
|
173 TBool CanCreateSourceBuffer(); |
|
174 |
|
175 /** |
|
176 * From MDataSource. Not used. Leaves with KErrNotSupported. |
|
177 * |
|
178 * @since Series 60 3.0 |
|
179 * @param "aMediaId" |
|
180 * This identifies the type of media eg audio or video and the stream id. |
|
181 * This parameter is required in cases where the source can supply data |
|
182 * of more than one media type and/or multiple strams of data eg a multimedia file. |
|
183 * |
|
184 * @param "aReference" |
|
185 * This must be written to by the method to indicate whether the created buffer is |
|
186 * a 'reference' buffer. A 'reference' buffer is a buffer that is owned by the source |
|
187 * and should be used in preference to the sink buffer provided the sink buffer |
|
188 * is also not a reference buffer. |
|
189 * . |
|
190 * @return The created buffer |
|
191 */ |
|
192 CMMFBuffer* CreateSourceBufferL( TMediaId, |
|
193 TBool& aReference ); |
|
194 |
|
195 /** |
|
196 * From MDataSource. Method to 'logon' the data source to the same thread that source will be supplying data in. |
|
197 * |
|
198 * Jitterbuffer for incoming packets and downlink timeout timer are created here. |
|
199 * |
|
200 * @param "aEventHandler" |
|
201 * This is an MAsyncEventHandler to handle asynchronous events that occur during the |
|
202 * transfer of multimedia data. The event handler must be in the same thread as the data transfer |
|
203 * thread - hence the reason it is passed in the SourceThreadLogon as opposed to say the constructor. |
|
204 * |
|
205 * |
|
206 * @return KErrNone if successful, otherwise a system wide error code. |
|
207 */ |
|
208 TInt SourceThreadLogon( MAsyncEventHandler& aEventHandler ); |
|
209 |
|
210 /** |
|
211 * From MDataSource. Method to 'logoff' the data source from the same thread that source supplies data in. |
|
212 * |
|
213 * Jitterbuffer for incoming packets and downlink timeout timer are deleted. Datasource deletes the |
|
214 * stream(s) and unregisters itself as an observer for the RTP session for incoming RTP and RTCP packets. |
|
215 * |
|
216 * @return None |
|
217 */ |
|
218 void SourceThreadLogoff(); |
|
219 |
|
220 /** |
|
221 * From MDataSource. Method to 'prime' the data source. |
|
222 * |
|
223 * Datasource is set to primed state. |
|
224 * |
|
225 * @since Series 60 3.0 |
|
226 * @return None |
|
227 */ |
|
228 void SourcePrimeL(); |
|
229 |
|
230 /** |
|
231 * From MDataSource. Method to 'play' the data source. |
|
232 * |
|
233 * Downlink timeout timer is started and datasource is set to playing state. |
|
234 * |
|
235 * @since Series 60 3.0 |
|
236 * @return None |
|
237 */ |
|
238 void SourcePlayL(); |
|
239 |
|
240 /** |
|
241 * From MDataSource. Method to 'pause' the data source. |
|
242 * |
|
243 * Downlink timeout timer is stopped and datasource is set to paused state. |
|
244 * |
|
245 * @since Series 60 3.0 |
|
246 * @return None |
|
247 */ |
|
248 void SourcePauseL(); |
|
249 |
|
250 /** |
|
251 * From MDataSource. Method to 'stop' the data source. |
|
252 * |
|
253 * Downlink timeout timer is stopped and datasource is set to stopped state. |
|
254 * |
|
255 * @since Series 60 3.0 |
|
256 * @return None |
|
257 */ |
|
258 void SourceStopL(); |
|
259 |
|
260 /** |
|
261 * From MDataSource. Method called by a MDataSink to request the data source to fill aBuffer with data. |
|
262 * |
|
263 * Datasource gets packet from jitterbuffer and forwards it to the payloadformatdecoder |
|
264 * for further processing. Datasource works synchronously; consumers BufferFilledL |
|
265 * is called when RTP packet is got succesfully from jitterbuffer. |
|
266 * |
|
267 * @since Series 60 3.0 |
|
268 * @param "aBuffer" |
|
269 * The buffer that needs filling with data |
|
270 * |
|
271 * @param "aConsumer" |
|
272 * The data sink that consumes the data. The data source needs this to make the BufferFilledL |
|
273 * callback on aConsumer when the data source has completed filling the aBuffer. |
|
274 * |
|
275 * @param "aMediaId" |
|
276 * This identifies the type of media eg audio or video and the stream id. |
|
277 * This parameter is required in cases where the source can supply data |
|
278 * of more than one media type and/or multiple strams of data eg a multimedia file. |
|
279 * @return None |
|
280 */ |
|
281 void FillBufferL( CMMFBuffer* aBuffer, |
|
282 MDataSink* aConsumer, |
|
283 TMediaId aMediaId ); |
|
284 |
|
285 /** |
|
286 * From MDataSource |
|
287 */ |
|
288 void NegotiateSourceL( MDataSink& aDataSink ); |
|
289 |
|
290 /** |
|
291 * From MDataSource |
|
292 * Used for custom command receiving. |
|
293 * @since Series 60 3.2 |
|
294 * @param aMessage The message specifying the custom command |
|
295 * @return void |
|
296 */ |
|
297 void SourceCustomCommand( TMMFMessage& aMessage ); |
|
298 |
|
299 public: // From MRtpJitterObserver |
|
300 /** |
|
301 * @since Series 60 3.2 |
|
302 * Send jitter event through mcc rtp interface |
|
303 */ |
|
304 void SendJitterEvent( TMccRtpEventData aEvent, TInt aError ); |
|
305 |
|
306 |
|
307 protected: // Functions from base classes |
|
308 |
|
309 /** |
|
310 * From MDataSource. Method to perform any source construction dependant on the source construction |
|
311 * initialisation data aInitData. |
|
312 * |
|
313 * @since Series 60 3.0 |
|
314 * @param "aInitData" |
|
315 * Source specific initialisation data required for source construction |
|
316 * @return None |
|
317 */ |
|
318 void ConstructSourceL( const TDesC8& aInitData ); |
|
319 |
|
320 protected: // From CMccRtpInterface |
|
321 |
|
322 /** |
|
323 * From CMccRtpInterface |
|
324 */ |
|
325 void DoCreateStreamL(); |
|
326 |
|
327 /** |
|
328 * FROM SRTP API |
|
329 * |
|
330 * This function is called by SRTP when a master key is stale and |
|
331 * needs to be refreshed. |
|
332 */ |
|
333 void SRTPMasterKeyStaleEvent(const CSRTPStream& aStream); |
|
334 |
|
335 /** |
|
336 * FROM SRTP API |
|
337 * |
|
338 * This function is called by SRTP Stream initiated with |
|
339 * CSRTPSession when a master key is stale and |
|
340 * needs to be refreshed. |
|
341 */ |
|
342 void SRTPMasterKeyStaleEvent(const CSRTPSession& aSession ); |
|
343 |
|
344 private: // From MMccExpirationHandler |
|
345 |
|
346 void TimerExpiredL( TMccTimerId aTimerId, TAny* aTimerParam ); |
|
347 |
|
348 private: |
|
349 |
|
350 /** |
|
351 * C++ default constructor. |
|
352 */ |
|
353 CMccRtpDataSource(); |
|
354 |
|
355 /** |
|
356 * @since Series 60 3.0 |
|
357 * |
|
358 * @param aHeaderInfo RTP header |
|
359 * @param aPayloadData RTP packet data |
|
360 * @return void |
|
361 */ |
|
362 void PlayoutRtpPacketL( const TRtpRecvHeader& aHeaderInfo, |
|
363 const TDesC8& aPayloadData ); |
|
364 |
|
365 /** |
|
366 * Validates the received RTP packet that it is not a hostile packet. |
|
367 * @since Series 60 3.0 |
|
368 * @param aStreamId ID of the RTP stream |
|
369 * @param aHeader RTP header |
|
370 * @param aData RTP packet data |
|
371 * @return User entry for currently received payload type |
|
372 */ |
|
373 TMccRtpUser* ValidatePacketL( const TRtpId aStreamId, |
|
374 const TRtpRecvHeader& aHeader, const TDesC8& aData ); |
|
375 |
|
376 void SendStreamEventToClient( TMccEventType aEventType, |
|
377 TInt aError = KErrNone, |
|
378 TUint32 aTargetPayloadType = KMccPTNotDefined ); |
|
379 |
|
380 void RtpPacketReceivedL( TRtpId aStreamId, |
|
381 const TRtpRecvHeader& aHeaderInfo, |
|
382 const TDesC8& aPayloadData ); |
|
383 |
|
384 /** |
|
385 * Handler method for custom commands. |
|
386 * @since Series 60 3.2 |
|
387 * @param aMessage The message specifying the custom command |
|
388 * @return void |
|
389 */ |
|
390 void SourceCustomCommandL( TMMFMessage& aMessage ); |
|
391 |
|
392 TBool InactivityTimerActive() const; |
|
393 |
|
394 TBool StandbyEnabled( TMccRtpUser* aUser ) const; |
|
395 |
|
396 void StandByL( TMccStandbyActionType aActionType, TUint aPayloadType ); |
|
397 |
|
398 void StartRtpStandByTimerL( TMccRtpUser* aUser ); |
|
399 |
|
400 void StopRtpStandByTimers(); |
|
401 |
|
402 void ResetStandBy(); |
|
403 |
|
404 void HandleStandByL( TMccRtpUser* aUser ); |
|
405 |
|
406 void DoStandByDecision( TMccRtpUser* aUser ); |
|
407 |
|
408 TMccRtpUser* FindUserEntryByPayloadType( TUint aPayloadType ); |
|
409 |
|
410 TMccRtpUser* FindUserEntryByTimerId( TMccTimerId aTimerId ); |
|
411 |
|
412 TInt FindUserEntryIndex( TMccRtpUser* aUser ); |
|
413 |
|
414 static TBool RtpUserMatch( const TMccRtpUser& aUser1, |
|
415 const TMccRtpUser& aUser2 ); |
|
416 |
|
417 |
|
418 private: // Data |
|
419 |
|
420 // The client who requested "FillBuffer" |
|
421 MDataSink* iFillBufferRequester; |
|
422 |
|
423 // Buffer received from RTP stack |
|
424 CMMFDataBuffer* iBufferToFill; |
|
425 |
|
426 // Indicates that first audio packet has been received |
|
427 TBool iDlStreamStarted; |
|
428 |
|
429 // Number of packets received |
|
430 TUint32 iPacketsReceived; |
|
431 |
|
432 // Timeout interval of the inactivity timer |
|
433 TUint32 iTimeoutTime; |
|
434 |
|
435 TUint32 iStandByTimerValue; |
|
436 |
|
437 // Stream ID for media packets |
|
438 TRtpId iRtpStreamId; |
|
439 |
|
440 /** |
|
441 * Tracks encoding changes for unknown media report logic. |
|
442 */ |
|
443 TUint8 iCurRecvPayloadType; |
|
444 |
|
445 /** |
|
446 * Instance of jitter calculator |
|
447 * Own. |
|
448 */ |
|
449 CMccJitterCalculator* iJitCalc; |
|
450 |
|
451 TMccTimerId iInactivityTimerId; |
|
452 |
|
453 CMccTimerManager* iTimer; |
|
454 |
|
455 // Registered users for source |
|
456 RArray<TMccRtpUser> iUsers; |
|
457 |
|
458 //flag for secure key expired |
|
459 TBool iSecureKeyExpired; |
|
460 |
|
461 private: // Friend classes |
|
462 |
|
463 #ifdef TEST_EUNIT |
|
464 public: |
|
465 friend class UT_CMccRtpDataSource; |
|
466 #endif |
|
467 |
|
468 }; |
|
469 |
|
470 #endif // MCCRTPDATASOURCE_H |
|
471 |
|
472 // End of File |