|
1 /* |
|
2 * Copyright (c) 2005 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: Implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #include "MCEConstants.h" |
|
21 #include "TCmdUpdateSession.h" |
|
22 #include "CTcMCEContext.h" |
|
23 |
|
24 #include <mcedefs.h> |
|
25 #include <MCESession.h> |
|
26 #include <MceMediaStream.h> |
|
27 #include <MceAudioStream.h> |
|
28 #include <MceVideoStream.h> |
|
29 |
|
30 #include <MCERtpSource.h> |
|
31 #include <MCEMicSource.h> |
|
32 #include <mcefilesource.h> |
|
33 #include <MceMediaSink.h> |
|
34 #include <MCESpeakerSink.h> |
|
35 #include <mcedisplaysink.h> |
|
36 #include <mcefilesink.h> |
|
37 #include <MCEAMRCodec.h> |
|
38 #include <MceCodec.h> |
|
39 #include <MceVideoCodec.h> |
|
40 #include <MceAvcCodec.h> |
|
41 |
|
42 void TCmdUpdateSession::ExecuteL() |
|
43 { |
|
44 // ---------- Setup -------------------------------------------------------- |
|
45 |
|
46 // Get session |
|
47 CMceSession* session = |
|
48 reinterpret_cast<CMceSession*>(GetObjectForIdL(KSessionId, ETrue)); |
|
49 const RPointerArray<CMceMediaStream>& streams = session->Streams(); |
|
50 |
|
51 TInt keepAliveTimer = ExtractIntegerL( KParamKeepAliveValue, 0, EFalse ); |
|
52 keepAliveTimer = Max( 0, keepAliveTimer ); |
|
53 keepAliveTimer = Min( KMaxTUint8, keepAliveTimer ); |
|
54 |
|
55 TBool setDtmfPri = ExtractBooleanL( KParamSetDtmfPri, EFalse ); |
|
56 |
|
57 _LIT8( DTMF, "telephone-event" ); |
|
58 //source path for audiofile |
|
59 TPtrC8 pathAudioFile = ExtractTextL( KParamAudioFileSource, EFalse ); |
|
60 |
|
61 //get path for media file sink |
|
62 TPtrC8 mediaFileSink = ExtractTextL( KParamMediaFileSink, EFalse ); |
|
63 |
|
64 TPtrC8 selectedCodec = ExtractTextL( KParamSelectCodec, EFalse ); |
|
65 |
|
66 //get the inactivity timer value for rtp source |
|
67 TInt rtpInactivityTimer = ExtractIntegerL(KParamRTPInactivityTimer, 0, EFalse); |
|
68 |
|
69 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
70 { |
|
71 CMceMediaStream* tmpStream; |
|
72 tmpStream = streams[i]; |
|
73 // Setting the Audio Stream |
|
74 if ( streams[i]->Type() == KMceAudio ) |
|
75 { |
|
76 |
|
77 CMceAudioStream* audioStream = |
|
78 static_cast<CMceAudioStream*>(streams[i]); |
|
79 |
|
80 //setting the media file source for the stream |
|
81 if (pathAudioFile.Compare( KNullDesC8 ) != 0) |
|
82 { |
|
83 //Setting FileSource if the parameter has been set |
|
84 if ( streams[i]->Source()->Type() == KMceMicSource) |
|
85 { |
|
86 iSessionHelper.SetMediaFileSourceL( iContext.MCEManager(), *tmpStream, pathAudioFile); |
|
87 } |
|
88 else if ( audioStream->BoundStream() ) |
|
89 { |
|
90 iSessionHelper.SetMediaFileSourceL( iContext.MCEManager(), tmpStream->BoundStreamL(), pathAudioFile); |
|
91 } |
|
92 else |
|
93 { |
|
94 // Keep pc-lint happy |
|
95 } |
|
96 } |
|
97 |
|
98 const RPointerArray<CMceAudioCodec>& codecsMain = audioStream->Codecs(); |
|
99 |
|
100 for (TInt j = codecsMain.Count()-1; j >= 0; j--) |
|
101 { |
|
102 if (setDtmfPri && codecsMain[j]->SdpName().Compare(DTMF)) |
|
103 { |
|
104 iSessionHelper.SetCodecPrioritiesL(*codecsMain[j], iSessionHelper.dtmf); |
|
105 } |
|
106 if ( audioStream->Source()->Type() == KMceRTPSource ) |
|
107 { |
|
108 // set priority for downlink |
|
109 iSessionHelper.SetCodecPrioritiesL(*codecsMain[j], iSessionHelper.downlink); |
|
110 } |
|
111 else |
|
112 { |
|
113 // set priority for uplink |
|
114 iSessionHelper.SetCodecPrioritiesL(*codecsMain[j], iSessionHelper.uplink); |
|
115 |
|
116 if ( keepAliveTimer ) |
|
117 { |
|
118 iSessionHelper.SetKeepaliveL(*codecsMain[j], keepAliveTimer ); |
|
119 } |
|
120 } |
|
121 } |
|
122 |
|
123 //setting priorities for bound stream |
|
124 if (audioStream->BoundStream()) |
|
125 { |
|
126 CMceAudioStream* audioStreamBound = |
|
127 static_cast<CMceAudioStream*> ( &audioStream->BoundStreamL()); |
|
128 |
|
129 const RPointerArray<CMceAudioCodec>& codecs = audioStreamBound->Codecs(); |
|
130 |
|
131 for (TInt j = codecs.Count()-1; j >= 0; j--) |
|
132 { |
|
133 if (setDtmfPri && codecs[j]->SdpName().Compare(DTMF)) |
|
134 { |
|
135 iSessionHelper.SetCodecPrioritiesL(*codecs[j], iSessionHelper.dtmf); |
|
136 } |
|
137 if ( audioStream->BoundStreamL().Source()->Type() == KMceRTPSource ) |
|
138 { |
|
139 // set priority for downlink |
|
140 iSessionHelper.SetCodecPrioritiesL(*codecs[j], iSessionHelper.downlink); |
|
141 } |
|
142 else |
|
143 { |
|
144 // set priority for uplink |
|
145 iSessionHelper.SetCodecPrioritiesL(*codecs[j], iSessionHelper.uplink); |
|
146 if ( keepAliveTimer ) |
|
147 { |
|
148 iSessionHelper.SetKeepaliveL(*codecs[j], keepAliveTimer ); |
|
149 } |
|
150 } |
|
151 } |
|
152 } |
|
153 |
|
154 } |
|
155 |
|
156 // Setting the Video Stream |
|
157 if ( streams[i]->Type() == KMceVideo ) |
|
158 { |
|
159 |
|
160 CMceVideoStream* videoStream = |
|
161 static_cast<CMceVideoStream*>(streams[i]); |
|
162 |
|
163 //Select specified codec |
|
164 if (selectedCodec.Compare( KNullDesC8 ) != 0) |
|
165 { |
|
166 DoVideoCodecSelectionL( *videoStream, &selectedCodec ); |
|
167 } |
|
168 |
|
169 const RPointerArray<CMceVideoCodec>& codecsMainVideo = videoStream->Codecs(); |
|
170 for (TInt j = codecsMainVideo.Count()-1; j >= 0; j--) |
|
171 { |
|
172 if ( videoStream->Source()->Type() == KMceRTPSource ) |
|
173 { |
|
174 // set priority for downlink |
|
175 iSessionHelper.SetCodecPrioritiesL(*codecsMainVideo[j], |
|
176 iSessionHelper.downlink); |
|
177 } |
|
178 else |
|
179 { |
|
180 // set priority for uplink |
|
181 iSessionHelper. SetCodecPrioritiesL(*codecsMainVideo[j], |
|
182 iSessionHelper.uplink); |
|
183 if ( keepAliveTimer ) |
|
184 { |
|
185 ((CMceCodec*)codecsMainVideo[j])->SetKeepAliveTimerL( |
|
186 keepAliveTimer ); |
|
187 } |
|
188 } |
|
189 } |
|
190 |
|
191 if(videoStream->BoundStream()) |
|
192 { |
|
193 CMceVideoStream* videoStreamBound = |
|
194 static_cast<CMceVideoStream*> ( &videoStream->BoundStreamL()); |
|
195 |
|
196 const RPointerArray<CMceVideoCodec>& codecsv = videoStreamBound->Codecs(); |
|
197 for (TInt j = codecsv.Count()-1; j >= 0; j--) |
|
198 { |
|
199 if ( videoStream->BoundStreamL().Source()->Type() == KMceRTPSource ) |
|
200 { |
|
201 // set priority for downlink |
|
202 iSessionHelper.SetCodecPrioritiesL(*codecsv[j], iSessionHelper.downlink); |
|
203 } |
|
204 else |
|
205 { |
|
206 // set priority for uplink |
|
207 iSessionHelper.SetCodecPrioritiesL(*codecsv[j], iSessionHelper.uplink); |
|
208 if ( keepAliveTimer ) |
|
209 { |
|
210 ((CMceCodec*)codecsv[j])->SetKeepAliveTimerL( keepAliveTimer ); |
|
211 } |
|
212 } |
|
213 } |
|
214 } |
|
215 } |
|
216 |
|
217 //set Inactivity timer for RTP source for each stream |
|
218 if( rtpInactivityTimer != 0 ) |
|
219 iSessionHelper.SetRtpInactivityTimerL(*tmpStream, rtpInactivityTimer); |
|
220 } |
|
221 |
|
222 // ---------- Execution ---------------------------------------------------- |
|
223 |
|
224 //setting the media file sink |
|
225 if (mediaFileSink.Compare( KNullDesC8 ) != 0) |
|
226 { |
|
227 SetMediaFileSinkL( *session, &mediaFileSink); |
|
228 } |
|
229 |
|
230 // Get timeout |
|
231 TInt timeout = ExtractIntegerL( KParamTimeout, 0, EFalse ); |
|
232 // Timeout is given to API in milliseconds, but is going to change to |
|
233 // seconds, so translate it here instead of TTCN |
|
234 //timeout = 1000 * timeout; |
|
235 |
|
236 // Get ContentType |
|
237 HBufC8* contentType = HBufCParameterL(ExtractTextL(KParamContentType, |
|
238 EFalse)); |
|
239 CleanupStack::PushL( contentType ); |
|
240 |
|
241 // Get Headers |
|
242 CDesC8Array* headers = ExtractHeadersL( EFalse ); |
|
243 if (!headers) |
|
244 { |
|
245 headers = new (ELeave) CDesC8ArrayFlat(1); |
|
246 } |
|
247 headers->AppendL(_L8("event: ttcn")); |
|
248 CleanupStack::PushL( headers ); |
|
249 // Get Content |
|
250 HBufC8* body = HBufCParameterL(ExtractTextL(KParamBody, EFalse)); |
|
251 CleanupStack::PushL( body ); |
|
252 |
|
253 // Get ContentHeaders |
|
254 CDesC8Array* contentHeaders = ExtractArrayL(KParamContentHeaders, EFalse ); |
|
255 CleanupStack::PushL(contentHeaders); |
|
256 |
|
257 if ( !headers && !body && !contentType &&contentHeaders->Count()<=0 && timeout == 0 ) |
|
258 { |
|
259 CleanupStack::PopAndDestroy( contentHeaders); contentHeaders = NULL; |
|
260 CleanupStack::PopAndDestroy( body ); body = NULL; |
|
261 CleanupStack::PopAndDestroy( headers ); headers = NULL; |
|
262 CleanupStack::PopAndDestroy( contentType ); contentType = NULL; |
|
263 session->UpdateL(); |
|
264 } |
|
265 else |
|
266 { |
|
267 session->UpdateL( timeout, headers, contentType, body, contentHeaders ); |
|
268 CleanupStack::Pop( contentHeaders); |
|
269 CleanupStack::Pop( body ); |
|
270 CleanupStack::Pop( headers ); |
|
271 CleanupStack::Pop( contentType ); |
|
272 } |
|
273 |
|
274 |
|
275 CMceSession::TState state = session->State(); |
|
276 |
|
277 // ---------- Response creation -------------------------------------------- |
|
278 |
|
279 |
|
280 AddIdResponseL( KSessionId, *session ); |
|
281 |
|
282 // Add Session state |
|
283 AddIntegerResponseL( KResponseState, state ); |
|
284 AddTextualSessionStateL( state ); |
|
285 |
|
286 } |
|
287 |
|
288 TBool TCmdUpdateSession::Match( const TTcIdentifier& aId ) |
|
289 { |
|
290 return TTcMceCommandBase::Match( aId, _L8("UpdateSession") ); |
|
291 } |
|
292 |
|
293 TTcCommandBase* TCmdUpdateSession::CreateL( MTcTestContext& aContext ) |
|
294 { |
|
295 return new( ELeave ) TCmdUpdateSession( aContext ); |
|
296 } |
|
297 |
|
298 void TCmdUpdateSession::DoVideoCodecSelectionL( CMceVideoStream& aVideoStream, TPtrC8* aCodec ) |
|
299 { |
|
300 const RPointerArray<CMceVideoCodec>& codecs = aVideoStream.Codecs(); |
|
301 |
|
302 if(aCodec->FindF(KMceSDPNameH264())!= KErrNotFound ) |
|
303 { |
|
304 //Select only the H264 codec |
|
305 const CMceVideoCodec* avcSingleNal = NULL; |
|
306 const CMceVideoCodec* avcNonInterleaved = NULL; |
|
307 |
|
308 for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex ) |
|
309 { |
|
310 if ( codecs[codecIndex]->SdpName() == KMceSDPNameH264() ) |
|
311 { |
|
312 if ( codecs[codecIndex]->CodecMode() == KMceAvcModeSingleNal ) |
|
313 { |
|
314 // Store a pointer to the Single NAL codec with best bitrate |
|
315 if ( !avcSingleNal || |
|
316 ( avcSingleNal && codecs[codecIndex]->MaxBitRate() > |
|
317 avcSingleNal->MaxBitRate() ) ) |
|
318 { |
|
319 avcSingleNal = codecs[codecIndex]; |
|
320 } |
|
321 } |
|
322 else if ( codecs[codecIndex]->CodecMode() == |
|
323 KMceAvcModeNonInterleaved ) |
|
324 { |
|
325 // Store a pointer to the Non-Interleaved codec with best bitrate |
|
326 if ( !avcNonInterleaved || |
|
327 ( avcNonInterleaved && codecs[codecIndex]->MaxBitRate() > |
|
328 avcNonInterleaved->MaxBitRate() ) ) |
|
329 { |
|
330 avcNonInterleaved = codecs[codecIndex]; |
|
331 } |
|
332 } |
|
333 else |
|
334 { |
|
335 // NOP, we do not care about interleaved AVC |
|
336 } |
|
337 } |
|
338 } |
|
339 |
|
340 const CMceVideoCodec* selectedCodec = NULL; |
|
341 |
|
342 if ( avcNonInterleaved ) |
|
343 { |
|
344 selectedCodec = avcNonInterleaved; |
|
345 } |
|
346 else |
|
347 { |
|
348 selectedCodec = avcSingleNal; |
|
349 } |
|
350 |
|
351 if ( selectedCodec ) |
|
352 { |
|
353 // Remove all other codecs |
|
354 for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex ) |
|
355 { |
|
356 if ( codecs[codecIndex] != selectedCodec ) |
|
357 { |
|
358 aVideoStream.RemoveCodecL( *codecs[codecIndex] ); |
|
359 // Since succesfull removal of a codec has decreased the amount |
|
360 // of codecs in array by one, we have to reset the index |
|
361 codecIndex = 0; |
|
362 } |
|
363 } |
|
364 } |
|
365 } |
|
366 else |
|
367 { |
|
368 //select others codecs |
|
369 TBool codecModeBasedRemovalNeeded( EFalse ); |
|
370 |
|
371 //check first if the codec is present |
|
372 for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex ) |
|
373 { |
|
374 const CMceVideoCodec& currentCodec = *codecs[codecIndex]; |
|
375 if ( aCodec->FindF( currentCodec.SdpName()) != KErrNotFound ) |
|
376 codecModeBasedRemovalNeeded = ETrue; |
|
377 } |
|
378 |
|
379 //remove codecs |
|
380 if( codecModeBasedRemovalNeeded ) |
|
381 { |
|
382 for ( TInt codecIndex = 0; codecIndex < codecs.Count(); ++codecIndex ) |
|
383 { |
|
384 const CMceVideoCodec& currentCodec = *codecs[codecIndex]; |
|
385 if ( aCodec->FindF( currentCodec.SdpName()) == KErrNotFound ) |
|
386 aVideoStream.RemoveCodecL( *codecs[codecIndex] ); |
|
387 } |
|
388 } |
|
389 } |
|
390 |
|
391 } |
|
392 |
|
393 |
|
394 void TCmdUpdateSession::SetMediaFileSinkL( CMceSession& aSession, TPtrC8* aFile ) |
|
395 { |
|
396 TBool video(EFalse); |
|
397 TBool audio(EFalse); |
|
398 if( aFile->Find(_L8(".mp4")) != KErrNotFound ) |
|
399 video = ETrue; |
|
400 if( aFile->Find(_L8(".3gp")) != KErrNotFound ) |
|
401 audio = ETrue; |
|
402 |
|
403 const RPointerArray<CMceMediaStream>& streams = aSession.Streams(); |
|
404 |
|
405 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
406 { |
|
407 CMceMediaStream* tmpStream; |
|
408 tmpStream = streams[i]; |
|
409 if( video ) |
|
410 { |
|
411 if ( tmpStream->Type() == KMceVideo ) |
|
412 { |
|
413 CMceVideoStream* videoOutStreamFile = CMceVideoStream::NewL(); |
|
414 CleanupStack::PushL( videoOutStreamFile ); |
|
415 |
|
416 //use the same source which was used for outgoing video stream |
|
417 if( tmpStream->Source()->Type() != KMceRTPSource ) |
|
418 { |
|
419 videoOutStreamFile->SetSourceL( tmpStream->Source() ); |
|
420 } |
|
421 else |
|
422 { |
|
423 if( tmpStream->BoundStream() ) |
|
424 if( tmpStream->BoundStreamL().Source()->Type() != KMceRTPSource ) |
|
425 videoOutStreamFile->SetSourceL(tmpStream->BoundStreamL().Source()); |
|
426 } |
|
427 |
|
428 iSessionHelper.SetMediaFileSinkL(*videoOutStreamFile, *aFile); |
|
429 aSession.AddStreamL( videoOutStreamFile ); |
|
430 CleanupStack::Pop( videoOutStreamFile ); |
|
431 break; //only one file sink can be added for testing |
|
432 } |
|
433 } |
|
434 if( audio ) |
|
435 { |
|
436 if ( tmpStream->Type() == KMceAudio ) |
|
437 { |
|
438 CMceAudioStream* audioOutStreamFile = CMceAudioStream::NewL(); |
|
439 CleanupStack::PushL( audioOutStreamFile ); |
|
440 |
|
441 //use the same source which was used for outgoing audio stream |
|
442 if( tmpStream->Source()->Type() != KMceRTPSource ) |
|
443 { |
|
444 audioOutStreamFile->SetSourceL( tmpStream->Source() ); |
|
445 } |
|
446 else |
|
447 { |
|
448 if(tmpStream->BoundStream()) |
|
449 if( tmpStream->BoundStreamL().Source()->Type() != KMceRTPSource ) |
|
450 audioOutStreamFile->SetSourceL(tmpStream->BoundStreamL().Source()); |
|
451 } |
|
452 |
|
453 iSessionHelper.SetMediaFileSinkL(*audioOutStreamFile, *aFile); |
|
454 aSession.AddStreamL( audioOutStreamFile ); |
|
455 CleanupStack::Pop( audioOutStreamFile ); |
|
456 break; |
|
457 } |
|
458 } |
|
459 } |
|
460 |
|
461 } |