|
1 /* |
|
2 * Copyright (c) 2005-2006 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: Utilities to get and set profile used with SWIS. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // USER |
|
21 |
|
22 #include "musengmceutils.h" |
|
23 #include "muslogger.h" |
|
24 |
|
25 // SYSTEM |
|
26 |
|
27 #include <mcesession.h> |
|
28 #include <mcevideostream.h> |
|
29 #include <mceaudiostream.h> |
|
30 #include <mcertpsink.h> |
|
31 #include <mcemediasource.h> |
|
32 #include <mcertpsource.h> |
|
33 #include <mcecamerasource.h> |
|
34 #include <mcedisplaysink.h> |
|
35 #include <mcefilesource.h> |
|
36 #include <mcefilesink.h> |
|
37 #include <mcespeakersink.h> |
|
38 |
|
39 |
|
40 |
|
41 |
|
42 |
|
43 // ----------------------------------------------------------------------------- |
|
44 // Tells if parameter stream is a video stream with RTP source |
|
45 // ----------------------------------------------------------------------------- |
|
46 // |
|
47 TBool MusEngMceUtils::IsVideoInStream( CMceMediaStream& aStream ) |
|
48 { |
|
49 return ( aStream.Type() == KMceVideo && |
|
50 aStream.Source() && |
|
51 aStream.Source()->Type() == KMceRTPSource ); |
|
52 } |
|
53 |
|
54 |
|
55 // ----------------------------------------------------------------------------- |
|
56 // Tells if parameter stream is an audio stream with RTP source |
|
57 // ----------------------------------------------------------------------------- |
|
58 // |
|
59 TBool MusEngMceUtils::IsAudioInStream( CMceMediaStream& aStream ) |
|
60 { |
|
61 return ( aStream.Type() == KMceAudio && |
|
62 aStream.Source() && |
|
63 aStream.Source()->Type() == KMceRTPSource ); |
|
64 } |
|
65 |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // Gets handle to video stream with RTP sink. |
|
69 // ----------------------------------------------------------------------------- |
|
70 // |
|
71 CMceVideoStream* MusEngMceUtils::GetVideoOutStreamL( CMceSession& aSession ) |
|
72 { |
|
73 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetVideoOutStreamL()" ) |
|
74 |
|
75 const RPointerArray<CMceMediaStream>& streams = aSession.Streams(); |
|
76 |
|
77 CMceVideoStream* videoOut = NULL; |
|
78 |
|
79 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
80 { |
|
81 if ( streams[i]->Type() == KMceVideo ) |
|
82 { |
|
83 CMceMediaSink* rtpSink = MusEngMceUtils::GetMediaSink( |
|
84 *streams[i], |
|
85 KMceRTPSink ); |
|
86 if ( rtpSink ) |
|
87 { |
|
88 __ASSERT_ALWAYS( !videoOut, User::Leave( KErrOverflow ) ); |
|
89 |
|
90 videoOut = static_cast<CMceVideoStream*>( streams[i] ); |
|
91 } |
|
92 |
|
93 // There is no need to investigate bound stream since |
|
94 // outstream is always constructed by Mus instead of MCE |
|
95 } |
|
96 } |
|
97 |
|
98 __ASSERT_ALWAYS( videoOut, User::Leave( KErrNotFound ) ); |
|
99 |
|
100 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetVideoOutStreamL()" ) |
|
101 |
|
102 return videoOut; |
|
103 } |
|
104 |
|
105 |
|
106 // ----------------------------------------------------------------------------- |
|
107 // Gets handle to video stream with RTP source. |
|
108 // ----------------------------------------------------------------------------- |
|
109 // |
|
110 CMceVideoStream* MusEngMceUtils::GetVideoInStreamL( CMceSession& aSession ) |
|
111 { |
|
112 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetVideoInStreamL()" ) |
|
113 |
|
114 const RPointerArray<CMceMediaStream>& streams = aSession.Streams(); |
|
115 |
|
116 CMceVideoStream* videoIn = NULL; |
|
117 |
|
118 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
119 { |
|
120 if ( MusEngMceUtils::IsVideoInStream( *streams[i] ) ) |
|
121 |
|
122 { |
|
123 __ASSERT_ALWAYS( !videoIn, User::Leave( KErrOverflow ) ); |
|
124 |
|
125 videoIn = static_cast<CMceVideoStream*>( streams[i] ); |
|
126 } |
|
127 |
|
128 // Check if bound stream is a video stream with RTP souce. |
|
129 if ( streams[i]->BoundStream() && |
|
130 MusEngMceUtils::IsVideoInStream( streams[i]->BoundStreamL() ) ) |
|
131 { |
|
132 __ASSERT_ALWAYS( !videoIn, User::Leave( KErrOverflow ) ); |
|
133 |
|
134 videoIn = static_cast<CMceVideoStream*>( |
|
135 &streams[i]->BoundStreamL() ); |
|
136 } |
|
137 } |
|
138 |
|
139 __ASSERT_ALWAYS( videoIn, User::Leave( KErrNotFound ) ); |
|
140 |
|
141 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetVideoInStreamL()" ) |
|
142 |
|
143 return videoIn; |
|
144 } |
|
145 |
|
146 |
|
147 // ----------------------------------------------------------------------------- |
|
148 // Gets handle to video stream with file sink |
|
149 // ----------------------------------------------------------------------------- |
|
150 // |
|
151 CMceVideoStream* MusEngMceUtils::GetRecordingStream( CMceSession& aSession ) |
|
152 { |
|
153 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetRecordingStreamL()" ) |
|
154 |
|
155 const RPointerArray<CMceMediaStream>& streams = aSession.Streams(); |
|
156 |
|
157 CMceVideoStream* recordingStream = NULL; |
|
158 |
|
159 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
160 { |
|
161 if ( streams[i]->Type() == KMceVideo ) |
|
162 { |
|
163 if ( MusEngMceUtils::GetMediaSink( *streams[i], KMceFileSink ) ) |
|
164 { |
|
165 recordingStream = static_cast<CMceVideoStream*>( streams[i] ); |
|
166 } |
|
167 } |
|
168 } |
|
169 |
|
170 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetRecordingStreamL()" ) |
|
171 |
|
172 return recordingStream; |
|
173 } |
|
174 |
|
175 |
|
176 // ----------------------------------------------------------------------------- |
|
177 // Gets handle to a media sink of spesified type contained by a mediastream. |
|
178 // ----------------------------------------------------------------------------- |
|
179 // |
|
180 CMceMediaSink* MusEngMceUtils::GetMediaSink( CMceMediaStream& aStream, |
|
181 TMceSinkType aType ) |
|
182 { |
|
183 const RPointerArray<CMceMediaSink>& sinks = aStream.Sinks(); |
|
184 for ( TInt i = 0; i < sinks.Count(); ++i ) |
|
185 { |
|
186 if ( sinks[i]->Type() == aType ) |
|
187 { |
|
188 return sinks[i]; |
|
189 } |
|
190 } |
|
191 |
|
192 return NULL; |
|
193 } |
|
194 |
|
195 |
|
196 // ----------------------------------------------------------------------------- |
|
197 // Gets handle to a media sink of spesified type contained by a mediastream. |
|
198 // ----------------------------------------------------------------------------- |
|
199 // |
|
200 CMceMediaSink* MusEngMceUtils::GetMediaSinkL( CMceMediaStream& aStream, |
|
201 TMceSinkType aType ) |
|
202 { |
|
203 |
|
204 CMceMediaSink* sink = MusEngMceUtils::GetMediaSink( aStream, aType ); |
|
205 |
|
206 __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) ); |
|
207 |
|
208 return sink; |
|
209 } |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // Gets handle to a media sink of spesified type contained by a session. |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 CMceMediaSink* MusEngMceUtils::GetMediaSink( CMceSession& aSession, |
|
217 TMceSinkType aType ) |
|
218 { |
|
219 CMceMediaSink* sink = NULL; |
|
220 |
|
221 TRAP_IGNORE( sink = MusEngMceUtils::GetMediaSinkL( aSession, aType ) ) |
|
222 |
|
223 return sink; |
|
224 } |
|
225 |
|
226 |
|
227 // ----------------------------------------------------------------------------- |
|
228 // Gets handle to a media sink of spesified type contained by a session. |
|
229 // ----------------------------------------------------------------------------- |
|
230 // |
|
231 CMceMediaSink* MusEngMceUtils::GetMediaSinkL( CMceSession& aSession, |
|
232 TMceSinkType aType ) |
|
233 { |
|
234 CMceMediaSink* sink = NULL; |
|
235 |
|
236 const RPointerArray<CMceMediaStream>& streams = aSession.Streams(); |
|
237 |
|
238 for ( TInt i = 0; i < streams.Count(); ++i ) |
|
239 { |
|
240 sink = MusEngMceUtils::GetMediaSink( *streams[i], aType ); |
|
241 if ( sink ) |
|
242 { |
|
243 return sink; |
|
244 } |
|
245 |
|
246 if ( streams[i]->BoundStream() ) |
|
247 { |
|
248 sink = MusEngMceUtils::GetMediaSink( streams[i]->BoundStreamL(), |
|
249 aType ); |
|
250 if ( sink ) |
|
251 { |
|
252 return sink; |
|
253 } |
|
254 } |
|
255 } |
|
256 |
|
257 __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) ); |
|
258 |
|
259 return sink; |
|
260 } |
|
261 |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // Gets handle to a speaker sink contained by specified stream or bound stream. |
|
265 // ----------------------------------------------------------------------------- |
|
266 // |
|
267 CMceSpeakerSink* MusEngMceUtils::GetSpeaker( CMceMediaStream& aStream ) |
|
268 { |
|
269 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetSpeaker()" ) |
|
270 |
|
271 CMceSpeakerSink* speaker = NULL; |
|
272 |
|
273 if ( aStream.Type() == KMceAudio ) |
|
274 { |
|
275 speaker = static_cast<CMceSpeakerSink*>( |
|
276 MusEngMceUtils::GetMediaSink( aStream, KMceSpeakerSink ) ); |
|
277 |
|
278 if ( !speaker && aStream.BoundStream() ) |
|
279 { |
|
280 CMceMediaStream* boundStream = NULL; |
|
281 TRAPD( error, boundStream = &aStream.BoundStreamL() ) |
|
282 |
|
283 if ( error == KErrNone ) |
|
284 { |
|
285 speaker = static_cast<CMceSpeakerSink*>( |
|
286 MusEngMceUtils::GetMediaSink( *boundStream, |
|
287 KMceSpeakerSink ) ); |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetSpeaker()" ) |
|
293 |
|
294 return speaker; |
|
295 } |
|
296 |
|
297 |
|
298 // ----------------------------------------------------------------------------- |
|
299 // Gets handle to a camera source. |
|
300 // ----------------------------------------------------------------------------- |
|
301 // |
|
302 CMceCameraSource* MusEngMceUtils::GetCameraL( CMceSession& aSession ) |
|
303 { |
|
304 // Camera can be only in out stream |
|
305 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetCameraL()" ) |
|
306 |
|
307 CMceVideoStream* videoOut = MusEngMceUtils::GetVideoOutStreamL( aSession ); |
|
308 |
|
309 if ( !( videoOut->Source() && |
|
310 videoOut->Source()->Type() == KMceCameraSource ) ) |
|
311 { |
|
312 User::Leave( KErrNotFound ); |
|
313 } |
|
314 |
|
315 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetCameraL()" ) |
|
316 return static_cast<CMceCameraSource*>( videoOut->Source() ); |
|
317 } |
|
318 |
|
319 |
|
320 // ----------------------------------------------------------------------------- |
|
321 // Gets handle to a file source. |
|
322 // ----------------------------------------------------------------------------- |
|
323 // |
|
324 CMceFileSource* MusEngMceUtils::GetFileSourceL( CMceSession& aSession ) |
|
325 { |
|
326 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetFileSourceL()" ) |
|
327 |
|
328 CMceVideoStream* videoOut = MusEngMceUtils::GetVideoOutStreamL( aSession ); |
|
329 |
|
330 if ( !( videoOut->Source() && |
|
331 videoOut->Source()->Type() == KMceFileSource ) ) |
|
332 { |
|
333 User::Leave( KErrNotFound ); |
|
334 } |
|
335 |
|
336 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetFileSourceL()" ) |
|
337 return static_cast<CMceFileSource*>( videoOut->Source() ); |
|
338 } |
|
339 |
|
340 |
|
341 // ----------------------------------------------------------------------------- |
|
342 // Gets handle to a display sink. |
|
343 // ----------------------------------------------------------------------------- |
|
344 // |
|
345 CMceDisplaySink* MusEngMceUtils::GetDisplay( CMceSession& aSession ) |
|
346 { |
|
347 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetDisplay()" ) |
|
348 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetDisplay()" ) |
|
349 return static_cast<CMceDisplaySink*>( |
|
350 MusEngMceUtils::GetMediaSink( aSession, KMceDisplaySink ) ); |
|
351 |
|
352 } |
|
353 |
|
354 |
|
355 // ----------------------------------------------------------------------------- |
|
356 // Gets handle to a display sink. |
|
357 // ----------------------------------------------------------------------------- |
|
358 // |
|
359 CMceDisplaySink* MusEngMceUtils::GetDisplayL( CMceSession& aSession ) |
|
360 { |
|
361 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::GetDisplayL()" ) |
|
362 |
|
363 CMceDisplaySink* display = MusEngMceUtils::GetDisplay( aSession ); |
|
364 |
|
365 __ASSERT_ALWAYS( display, User::Leave( KErrNotFound ) ); |
|
366 |
|
367 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::GetDisplayL()" ) |
|
368 return display; |
|
369 } |
|
370 |
|
371 |
|
372 // ----------------------------------------------------------------------------- |
|
373 // Adds display sink to specified stream if one does not exist already. |
|
374 // Display rect is set in both cases. |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 void MusEngMceUtils::AddDisplayL( CMceMediaStream& aStream, |
|
378 CMceManager& aManager, |
|
379 const TRect& aDisplayRect ) |
|
380 { |
|
381 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::AddDisplayL()" ) |
|
382 |
|
383 __ASSERT_ALWAYS( aStream.Type() == KMceVideo, User::Leave( KErrArgument ) ); |
|
384 |
|
385 CMceDisplaySink* display = static_cast<CMceDisplaySink*>( |
|
386 MusEngMceUtils::GetMediaSink( |
|
387 aStream, |
|
388 KMceDisplaySink ) ); |
|
389 |
|
390 if ( !display ) |
|
391 { |
|
392 display = CMceDisplaySink::NewLC( aManager ); |
|
393 aStream.AddSinkL( display ); |
|
394 CleanupStack::Pop( display ); |
|
395 } |
|
396 |
|
397 display->SetDisplayRectL( aDisplayRect ); |
|
398 |
|
399 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::AddDisplayL()" ) |
|
400 } |
|
401 |
|
402 |
|
403 // ----------------------------------------------------------------------------- |
|
404 // Adds display sink to specified stream if one does not exist already. |
|
405 // ----------------------------------------------------------------------------- |
|
406 // |
|
407 void MusEngMceUtils::AddSpeakerL( CMceMediaStream& aStream ) |
|
408 { |
|
409 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::AddSpeakerL()" ) |
|
410 |
|
411 __ASSERT_ALWAYS( aStream.Type() == KMceAudio, User::Leave( KErrArgument ) ); |
|
412 |
|
413 CMceSpeakerSink* speaker = static_cast<CMceSpeakerSink*>( |
|
414 MusEngMceUtils::GetMediaSink( |
|
415 aStream, |
|
416 KMceSpeakerSink ) ); |
|
417 |
|
418 if ( !speaker ) |
|
419 { |
|
420 speaker = CMceSpeakerSink::NewLC(); |
|
421 aStream.AddSinkL( speaker ); |
|
422 CleanupStack::Pop( speaker ); |
|
423 } |
|
424 |
|
425 MUS_LOG( "mus: [ENGINE] <- MusEngMceUtils::AddSpeakerL()" ) |
|
426 } |
|
427 |
|
428 |
|
429 // ----------------------------------------------------------------------------- |
|
430 // Disables parameter stream, its' source and all the sinks. |
|
431 // ----------------------------------------------------------------------------- |
|
432 // |
|
433 void MusEngMceUtils::DisableStreamL( CMceMediaStream& aStream ) |
|
434 { |
|
435 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::DisableStreamL()" ) |
|
436 |
|
437 aStream.DisableL(); |
|
438 |
|
439 if ( aStream.Source() ) |
|
440 { |
|
441 aStream.Source()->DisableL(); |
|
442 } |
|
443 |
|
444 for ( TInt sinkIndex = 0; sinkIndex < aStream.Sinks().Count(); ++sinkIndex ) |
|
445 { |
|
446 aStream.Sinks()[ sinkIndex ]->DisableL(); |
|
447 } |
|
448 |
|
449 MUS_LOG( "mus: [ENGINE] -> MusEngMceUtils::DisableStreamL()" ) |
|
450 } |
|
451 |
|
452 |
|
453 |
|
454 |
|
455 |
|
456 |
|
457 |