|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 #include "mcestreamobserver.h" |
|
22 #include "mcesession.h" |
|
23 #include "mcemanager.h" |
|
24 #include "mcemediasink.h" |
|
25 #include "mcecommediasink.h" |
|
26 #include "mceitcsender.h" |
|
27 #include "mcefactory.h" |
|
28 #include "mceevents.h" |
|
29 #include "mceendpointproxy.h" |
|
30 #include "mceclilogs.h" |
|
31 |
|
32 #define _FLAT_DATA static_cast<CMceComMediaSink*>( iFlatData ) |
|
33 #define FLAT_DATA( data ) _FLAT_DATA->data |
|
34 |
|
35 // ============================ MEMBER FUNCTIONS =============================== |
|
36 |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CMceMediaSink::~CMceMediaSink |
|
40 // ----------------------------------------------------------------------------- |
|
41 // |
|
42 EXPORT_C CMceMediaSink::~CMceMediaSink() |
|
43 { |
|
44 delete iFlatData; |
|
45 iParents.Reset(); |
|
46 iParents.Close(); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CMceMediaSink::Type |
|
51 // ----------------------------------------------------------------------------- |
|
52 // |
|
53 EXPORT_C TMceSinkType CMceMediaSink::Type() const |
|
54 { |
|
55 return FLAT_DATA( Type() ); |
|
56 } |
|
57 |
|
58 |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CMceMediaSink::IsEnabled |
|
62 // ----------------------------------------------------------------------------- |
|
63 // |
|
64 EXPORT_C TBool CMceMediaSink::IsEnabled() const |
|
65 { |
|
66 return FLAT_DATA( IsEnabled() ); |
|
67 } |
|
68 |
|
69 |
|
70 // ----------------------------------------------------------------------------- |
|
71 // CMceMediaSink::Id |
|
72 // ----------------------------------------------------------------------------- |
|
73 // |
|
74 TMceMediaId CMceMediaSink::Id() const |
|
75 { |
|
76 return FLAT_DATA( iID ); |
|
77 } |
|
78 |
|
79 |
|
80 // ----------------------------------------------------------------------------- |
|
81 // CMceMediaSink::ConstructL |
|
82 // ----------------------------------------------------------------------------- |
|
83 // |
|
84 void CMceMediaSink::ConstructL( CMceComMediaSink* aFlatData ) |
|
85 { |
|
86 __ASSERT_ALWAYS( aFlatData , User::Leave( KErrArgument ) ); |
|
87 iFlatData = aFlatData; |
|
88 FLAT_DATA( iID ) = TMceMediaId();//as not assigned |
|
89 |
|
90 } |
|
91 |
|
92 |
|
93 // ----------------------------------------------------------------------------- |
|
94 // CMceMediaSink::CMceMediaSink |
|
95 // ----------------------------------------------------------------------------- |
|
96 // |
|
97 CMceMediaSink::CMceMediaSink() |
|
98 { |
|
99 } |
|
100 |
|
101 // ----------------------------------------------------------------------------- |
|
102 // CMceMediaSink::CreateEndpointProxyL |
|
103 // ----------------------------------------------------------------------------- |
|
104 // |
|
105 MMceEndPointProxy* CMceMediaSink::EndpointProxy() const |
|
106 { |
|
107 return iEndpointProxy; |
|
108 } |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CMceMediaSink::CreateEndpointProxyL |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 MMceEndPointProxy* CMceMediaSink::CreateEndpointProxyL() const |
|
115 { |
|
116 return NULL; |
|
117 } |
|
118 |
|
119 // ----------------------------------------------------------------------------- |
|
120 // CMceMediaSink::UsesEndpointProxy |
|
121 // ----------------------------------------------------------------------------- |
|
122 // |
|
123 TBool CMceMediaSink::UsesEndpointProxy() const |
|
124 { |
|
125 return EFalse; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CMceMediaSink::SetupEndpointProxyL |
|
130 // ----------------------------------------------------------------------------- |
|
131 // |
|
132 void CMceMediaSink::SetupEndpointProxyL( MMceEndPointProxy* aEndpointProxy ) |
|
133 { |
|
134 if ( !UsesEndpointProxy() ) |
|
135 { |
|
136 return; |
|
137 } |
|
138 |
|
139 if ( !aEndpointProxy && !iEndpointProxy ) |
|
140 { |
|
141 iEndpointProxy = CreateEndpointProxyL(); |
|
142 iEndpointProxy->AddProxyClientL( *this ); |
|
143 } |
|
144 else if ( aEndpointProxy && !iEndpointProxy ) |
|
145 { |
|
146 aEndpointProxy->AddProxyClientL( *this ); |
|
147 iEndpointProxy = aEndpointProxy; |
|
148 } |
|
149 else |
|
150 { |
|
151 iEndpointProxy->AddProxyClientL( *this ); |
|
152 } |
|
153 |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CMceMediaSink::SerializationId |
|
158 // ----------------------------------------------------------------------------- |
|
159 // |
|
160 TUint64 CMceMediaSink::SerializationId() const |
|
161 { |
|
162 return FLAT_DATA( SerializationId() ); |
|
163 } |
|
164 |
|
165 // ----------------------------------------------------------------------------- |
|
166 // CMceMediaSink::InternalizeFlatL |
|
167 // ----------------------------------------------------------------------------- |
|
168 // |
|
169 void CMceMediaSink::InternalizeFlatL( RReadStream& aReadStream ) |
|
170 { |
|
171 __ASSERT_ALWAYS( iFlatData , User::Leave( KErrNotReady ) ); |
|
172 _FLAT_DATA->InternalizeFlatL( aReadStream ); |
|
173 } |
|
174 |
|
175 // ----------------------------------------------------------------------------- |
|
176 // CMceMediaSink::ExternalizeFlatL |
|
177 // ----------------------------------------------------------------------------- |
|
178 // |
|
179 void CMceMediaSink::ExternalizeFlatL( RWriteStream& aWriteStream ) |
|
180 { |
|
181 __ASSERT_ALWAYS( iFlatData , User::Leave( KErrNotReady ) ); |
|
182 _FLAT_DATA->ExternalizeFlatL( aWriteStream ); |
|
183 } |
|
184 |
|
185 // ----------------------------------------------------------------------------- |
|
186 // CMceMediaSink::InternalizeL |
|
187 // ----------------------------------------------------------------------------- |
|
188 // |
|
189 void CMceMediaSink::InternalizeL( MMceComSerializationContext& aSerCtx ) |
|
190 { |
|
191 InternalizeFlatL( aSerCtx.ReadStream() ); |
|
192 } |
|
193 |
|
194 // ----------------------------------------------------------------------------- |
|
195 // CMceMediaSink::ExternalizeL |
|
196 // ----------------------------------------------------------------------------- |
|
197 // |
|
198 void CMceMediaSink::ExternalizeL( MMceComSerializationContext& aSerCtx ) |
|
199 { |
|
200 ExternalizeFlatL( aSerCtx.WriteStream() ); |
|
201 } |
|
202 |
|
203 |
|
204 // ----------------------------------------------------------------------------- |
|
205 // CMceMediaSink::Factory |
|
206 // ----------------------------------------------------------------------------- |
|
207 // |
|
208 TMceSinkFactory CMceMediaSink::Factory() |
|
209 { |
|
210 return TMceSinkFactory(); |
|
211 } |
|
212 |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CMceMediaSink::DoITCSendL |
|
216 // ----------------------------------------------------------------------------- |
|
217 // |
|
218 void CMceMediaSink::DoITCSendL(TUint8 aITCFunction, TBool aEnabled) |
|
219 { |
|
220 __ASSERT_ALWAYS( iStream, User::Leave( KErrNotReady ) ); |
|
221 CMceSession* session = iStream->Session(); |
|
222 __ASSERT_ALWAYS( session, User::Leave( KErrNotReady ) ); |
|
223 |
|
224 TMceIds ids; |
|
225 session->PrepareForITC( ids ); |
|
226 ids.iMediaID = iStream->Id(); |
|
227 ids.iSinkID = Id(); |
|
228 ids.iState = aEnabled; |
|
229 |
|
230 session->ITCSender().SendL( ids, static_cast<TMceItcFunctions>( aITCFunction ) ); |
|
231 |
|
232 Enabled( static_cast<TBool>( ids.iState ) ); |
|
233 } |
|
234 |
|
235 |
|
236 // ----------------------------------------------------------------------------- |
|
237 // CMceMediaSink::DoEnableL |
|
238 // ----------------------------------------------------------------------------- |
|
239 // |
|
240 void CMceMediaSink::DoEnableL() |
|
241 { |
|
242 if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) ) |
|
243 { |
|
244 DoITCSendL( EMceItcEnable, ETrue ); |
|
245 } |
|
246 else |
|
247 { |
|
248 MCECLI_DEBUG("CMceMediaSink::DoEnableL, done locally"); |
|
249 Enabled( ETrue ); |
|
250 } |
|
251 } |
|
252 |
|
253 |
|
254 // ----------------------------------------------------------------------------- |
|
255 // CMceMediaSink::DoDisableL |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CMceMediaSink::DoDisableL() |
|
259 { |
|
260 if ( MCE_ENDPOINT_ITC_ALLOWED( *this ) ) |
|
261 { |
|
262 __ASSERT_ALWAYS( iStream->State() != CMceMediaStream::ETranscodingRequired, |
|
263 User::Leave( KErrNotReady ) ); |
|
264 DoITCSendL( EMceItcDisable, EFalse ); |
|
265 } |
|
266 else |
|
267 { |
|
268 Enabled( EFalse ); |
|
269 MCECLI_DEBUG("CMceMediaSink::DoDisableL, done locally"); |
|
270 } |
|
271 } |
|
272 |
|
273 |
|
274 // ----------------------------------------------------------------------------- |
|
275 // CMceMediaSink::Enabled |
|
276 // ----------------------------------------------------------------------------- |
|
277 // |
|
278 void CMceMediaSink::Enabled( TBool aValue ) |
|
279 { |
|
280 _FLAT_DATA->Enabled( aValue ); |
|
281 } |
|
282 |
|
283 |
|
284 // ----------------------------------------------------------------------------- |
|
285 // CMceMediaSink::InitializeL |
|
286 // ----------------------------------------------------------------------------- |
|
287 // |
|
288 void CMceMediaSink::InitializeL( CMceManager* /*aManager*/ ) |
|
289 { |
|
290 // NOP |
|
291 } |
|
292 |
|
293 |
|
294 // ----------------------------------------------------------------------------- |
|
295 // CMceMediaSink::InitializeL |
|
296 // ----------------------------------------------------------------------------- |
|
297 // |
|
298 void CMceMediaSink::InitializeL( CMceMediaStream& aParent ) |
|
299 { |
|
300 |
|
301 if ( !Id().IsAssigned() ) |
|
302 { |
|
303 __ASSERT_ALWAYS( aParent.Session(), User::Leave( KErrNotFound ) ); |
|
304 FLAT_DATA( iID ) = aParent.Session()->Manager().NextMediaId(); |
|
305 MCECLI_DEBUG_DVALUES2("CMceMediaSink::InitializeL, this: type", Type(), |
|
306 "id", Id().iId, "enabled", IsEnabled() ); |
|
307 } |
|
308 } |
|
309 |
|
310 |
|
311 // ----------------------------------------------------------------------------- |
|
312 // CMceMediaSink::StreamAddedL |
|
313 // ----------------------------------------------------------------------------- |
|
314 // |
|
315 void CMceMediaSink::StreamAddedL( CMceMediaStream& aParent ) |
|
316 { |
|
317 |
|
318 if ( iParents.Find( &aParent ) == KErrNotFound ) |
|
319 { |
|
320 iParents.AppendL( &aParent ); |
|
321 } |
|
322 |
|
323 iStream = iParents[0]; |
|
324 |
|
325 } |
|
326 |
|
327 // ----------------------------------------------------------------------------- |
|
328 // CMceMediaSink::UnInitialize |
|
329 // ----------------------------------------------------------------------------- |
|
330 // |
|
331 void CMceMediaSink::UnInitialize( CMceMediaStream& aParent ) |
|
332 { |
|
333 TInt index = iParents.Find( &aParent ); |
|
334 if ( index >= 0 ) |
|
335 { |
|
336 iParents.Remove( index ); |
|
337 } |
|
338 iStream = NULL; |
|
339 |
|
340 if ( iParents.Count() > 0 ) |
|
341 { |
|
342 iStream = iParents[0]; |
|
343 } |
|
344 |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CMceMediaSink::EventReceivedL |
|
349 // ----------------------------------------------------------------------------- |
|
350 // |
|
351 TInt CMceMediaSink::EventReceivedL( TMceEvent& aEvent ) |
|
352 { |
|
353 TInt status = KMceEventNotOwner; |
|
354 TBool idMatch = aEvent.Id().iSinkID == Id(); |
|
355 if ( !idMatch ) |
|
356 { |
|
357 return KMceEventNotOwner; |
|
358 } |
|
359 |
|
360 if ( aEvent.Id().IsSinkId() ) |
|
361 { |
|
362 status = HandleEvent( aEvent ); |
|
363 } |
|
364 else |
|
365 { |
|
366 status = KMceEventNotConsumed; |
|
367 } |
|
368 |
|
369 return status; |
|
370 |
|
371 } |
|
372 |
|
373 // ----------------------------------------------------------------------------- |
|
374 // CMceMediaSink::UpdateL |
|
375 // ----------------------------------------------------------------------------- |
|
376 // |
|
377 void CMceMediaSink::UpdateL( CMceMediaSink& aUpdate ) |
|
378 { |
|
379 MCECLI_DEBUG("CMceMediaSink::UpdateL, Entry"); |
|
380 MCECLI_DEBUG_DVALUES("this: type", Type(), "id", Id().iId ); |
|
381 |
|
382 iFlatData->UpdateL( *aUpdate.iFlatData ); |
|
383 |
|
384 MCECLI_DEBUG_DVALUE("CMceMediaSink::UpdateL, before exit. enabled", IsEnabled() ); |
|
385 MCECLI_DEBUG("CMceMediaSink::UpdateL, Exit"); |
|
386 |
|
387 } |
|
388 |
|
389 // ----------------------------------------------------------------------------- |
|
390 // CMceMediaSink::ReferenceCount |
|
391 // ----------------------------------------------------------------------------- |
|
392 // |
|
393 TInt& CMceMediaSink::ReferenceCount() |
|
394 { |
|
395 return FLAT_DATA( ReferenceCount() ); |
|
396 } |
|
397 |
|
398 // ----------------------------------------------------------------------------- |
|
399 // CMceMediaSink::Updated |
|
400 // ----------------------------------------------------------------------------- |
|
401 // |
|
402 void CMceMediaSink::Updated() |
|
403 { |
|
404 MMceStreamObserver* observer = iStream->Session()->Manager().MediaObserver(); |
|
405 |
|
406 if ( observer ) |
|
407 { |
|
408 observer->StreamStateChanged( *iStream, *this ); |
|
409 } |
|
410 |
|
411 } |
|
412 |
|
413 |
|
414 // ----------------------------------------------------------------------------- |
|
415 // CMceMediaSink::HandleEvent |
|
416 // ----------------------------------------------------------------------------- |
|
417 // |
|
418 TInt CMceMediaSink::HandleEvent( TMceEvent& aEvent ) |
|
419 { |
|
420 MCECLI_DEBUG("CMceMediaSink::HandleEvent, Entry"); |
|
421 MCECLI_DEBUG_DVALUES("this: type", Type(), "id", Id().iId ); |
|
422 |
|
423 TInt status = KMceEventNotConsumed; |
|
424 |
|
425 if ( aEvent.MessageType() == EMceItcMsgTypeSink ) |
|
426 { |
|
427 MCECLI_DEBUG("CMceMediaSink::HandleEvent, content of sink changed"); |
|
428 status = KMceEventUpdate; |
|
429 } |
|
430 else if ( aEvent.Action() == EMceItcStateChanged ) |
|
431 { |
|
432 MCECLI_DEBUG("CMceMediaSink::HandleEvent, state changed"); |
|
433 Enabled( static_cast<TBool>( aEvent.ActionData() ) ); |
|
434 if ( IsEnabled() ) |
|
435 { |
|
436 iStream->SetState( CMceMediaStream::EStreaming ); |
|
437 } |
|
438 else |
|
439 { |
|
440 iStream->SetState( CMceMediaStream::EDisabled ); |
|
441 } |
|
442 Updated(); |
|
443 status = KMceEventConsumed; |
|
444 } |
|
445 else if ( aEvent.Action() == EMceItcInProgress ) |
|
446 { |
|
447 MCECLI_DEBUG("CMceMediaSink::HandleEvent, stream state changed"); |
|
448 |
|
449 TInt stateContent( 0 ); |
|
450 TBool isEnabled( EFalse ); |
|
451 TUint32 actionData = aEvent.ActionData(); |
|
452 MCE_DECODE_DOUBLE_STATE( actionData, stateContent, isEnabled ); |
|
453 CMceMediaStream::TState state = static_cast<CMceMediaStream::TState>( stateContent ); |
|
454 |
|
455 MCECLI_DEBUG_DVALUE("CMceMediaSink::HandleEvent, state:", state ); |
|
456 MCECLI_DEBUG_DVALUE("CMceMediaSink::HandleEvent, enabled:", isEnabled ); |
|
457 |
|
458 Enabled( isEnabled ); |
|
459 |
|
460 TBool stateChanged = iStream->SetState( state ); |
|
461 |
|
462 if ( !iStream->HandleMediaError( state, isEnabled, aEvent.Id().iStatus ) && |
|
463 stateChanged ) |
|
464 { |
|
465 Updated(); |
|
466 } |
|
467 |
|
468 status = KMceEventConsumed; |
|
469 } |
|
470 else |
|
471 { |
|
472 //NOP |
|
473 MCECLI_DEBUG("CMceMediaSink::HandleEvent, not consumed"); |
|
474 } |
|
475 |
|
476 MCECLI_DEBUG_DVALUE("CMceMediaSink::HandleEvent, before exit. enabled", IsEnabled() ); |
|
477 MCECLI_DEBUG_DVALUE("CMceMediaSink::HandleEvent, Exit. status", status ); |
|
478 |
|
479 return status; |
|
480 |
|
481 } |