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