|
1 /* |
|
2 * Copyright (c) 2002-2007 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: This class is a VideoControl. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <logger.h> |
|
21 //#include <lcdui.h> |
|
22 |
|
23 #include <JniEnvWrapper.h> |
|
24 |
|
25 #include "com_nokia_microedition_media_control_VideoControl.h" |
|
26 |
|
27 #include "cmmavideocontrol.h" |
|
28 #include "cmmacameraplayer.h" |
|
29 #include "mmmaeventposter.h" |
|
30 #include "cmmacanvasdisplay.h" |
|
31 #include "cmmaitemdisplay.h" |
|
32 #include "cmmasnapshotevent.h" |
|
33 #include "mmmaguiplayer.h" |
|
34 #include "cmmasnapshot.h" |
|
35 #include "mmmadisplaywindow.h" |
|
36 #include "cmmaplayerproperties.h" |
|
37 #include "cmmadcdisplay.h" |
|
38 #include "cmmavideocontrol.h" |
|
39 |
|
40 _LIT(KControlName, "VideoControl"); |
|
41 |
|
42 EXPORT_C CMMAVideoControl::CMMAVideoControl(MMMAGuiPlayer* aGuiPlayer): |
|
43 CMMAControl() |
|
44 { |
|
45 iGuiPlayer = aGuiPlayer; |
|
46 iIsForeground = 1; |
|
47 |
|
48 iDisplay = 0; |
|
49 } |
|
50 |
|
51 EXPORT_C CMMAVideoControl::~CMMAVideoControl() |
|
52 { |
|
53 delete iDisplay; |
|
54 |
|
55 // Event server takes event ownership |
|
56 if (iEventPoster) |
|
57 { |
|
58 if (iDeleteRefEvent) |
|
59 { |
|
60 iEventPoster->PostEvent(iDeleteRefEvent); |
|
61 } |
|
62 } |
|
63 if (iSnapshot) |
|
64 { |
|
65 iSnapshot->Cancel(); |
|
66 delete iSnapshot; |
|
67 } |
|
68 } |
|
69 |
|
70 |
|
71 void CMMAVideoControl::ConstructL(CMMAVideoControl* aControl, |
|
72 jobject aControlObject, |
|
73 MMAFunctionServer* aEventSource, |
|
74 JNIEnv* aJni, |
|
75 MMMAEventPoster* aEventPoster/*, |
|
76 CMIDToolkit* aToolkit*/) // mobitv fix // 3.x QT based UI |
|
77 { |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 |
|
83 aControl->iListenerObject = aControlObject; |
|
84 aControl->iJni = aEventSource->getValidJniEnv(); |
|
85 aControl->iEventPoster = aEventPoster; |
|
86 |
|
87 // snapshot ready method. Created here because jni cannot be used later. |
|
88 aControl->iSnapshotReadyMethod = aJni->GetMethodID( |
|
89 aJni->GetObjectClass(aControlObject), |
|
90 "snapshotReady", |
|
91 "(I[B)V"); |
|
92 |
|
93 aControl->iSnapshot = CMMASnapshot::NewL(aControl->iGuiPlayer, |
|
94 *aControl); |
|
95 // aControl->RegisterForegroundListenerL(aToolkit); // 3.x QT based UI |
|
96 } |
|
97 /* // 3.x QT based UI |
|
98 // mobitv fix` |
|
99 void CMMAVideoControl::RegisterForegroundListenerL(CMIDToolkit* aToolkit) |
|
100 { |
|
101 LOG(EJavaMMAPI,EInfo,"CMMAVideoControl::RegisterForegroundListener + "); |
|
102 |
|
103 // Initialize IsForeground to true, we might have already missed the event (HandleForegroundL), events before observer registration |
|
104 iIsForeground = ETrue; |
|
105 |
|
106 |
|
107 iToolkit = aToolkit; |
|
108 |
|
109 if (iToolkit) |
|
110 { |
|
111 LOG(EJavaMMAPI,EInfo,"CMMAVideoControl::RegisterForegroundListenerL : iToolkit->Env(); +"); |
|
112 iMidEnv = iToolkit->Env(); |
|
113 LOG(EJavaMMAPI,EInfo,"CMMAVideoControl::RegisterForegroundListenerL : iToolkit->Env(); -"); |
|
114 } |
|
115 |
|
116 if (iMidEnv) |
|
117 { |
|
118 LOG(EJavaMMAPI,EInfo,"CMMAVideoControl::RegisterForegroundListenerL : iMidEnv->AddObserverL + "); |
|
119 // register for getting the foreground change event |
|
120 iMidEnv->AddObserverL(*this); |
|
121 LOG(EJavaMMAPI,EInfo,"CMMAVideoControl::RegisterForegroundListenerL : iMidEnv->AddObserverL - "); |
|
122 } |
|
123 |
|
124 LOG(EJavaMMAPI,EInfo,"CMMAVideoControl::RegisterForegroundListenerL - "); |
|
125 } |
|
126 */ |
|
127 void CMMAVideoControl::StaticInitL(CMMAVideoControl* aControl, |
|
128 jobject javaDisplayRef, |
|
129 MMAFunctionServer* aEventSource, |
|
130 TInt* aDisplayHandle, |
|
131 CMMAEvent* aDeleteRefEvent, |
|
132 TInt aGuiType) |
|
133 { |
|
134 |
|
135 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitL +"); |
|
136 |
|
137 if (aGuiType == CMMAVideoControl::EDISPLAY_VIDEOITEM) |
|
138 { |
|
139 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitL - aGuiType is customitem "); |
|
140 aControl->iDeleteRefEvent = aDeleteRefEvent; |
|
141 |
|
142 CMMAItemDisplay* itemDisplay = |
|
143 CMMAItemDisplay::NewLC(aEventSource,javaDisplayRef); |
|
144 aControl->iDisplay = itemDisplay; |
|
145 CleanupStack::Pop(itemDisplay); |
|
146 *aDisplayHandle = reinterpret_cast<TInt>(itemDisplay); |
|
147 } |
|
148 else if (aGuiType == CMMAVideoControl::EDISPLAY_CANVAS) |
|
149 { |
|
150 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitL - aGuiType is canvas "); |
|
151 aControl->iDeleteRefEvent = aDeleteRefEvent; |
|
152 |
|
153 CMMACanvasDisplay* canvasDisplay = |
|
154 CMMACanvasDisplay::NewLC(aEventSource,javaDisplayRef); |
|
155 aControl->iDisplay = canvasDisplay; |
|
156 CleanupStack::Pop(canvasDisplay); |
|
157 *aDisplayHandle = reinterpret_cast<TInt>(canvasDisplay); |
|
158 } |
|
159 |
|
160 /* MMIDComponent::TType componentType = aComponent->Type(); |
|
161 switch (componentType) |
|
162 { |
|
163 case MMIDComponent::ECustomItem: |
|
164 { |
|
165 //MMIDCustomItem // end of // 3.x QT based UI |
|
166 // MMIDCustomItem* customItem = |
|
167 // reinterpret_cast< MMIDCustomItem* >(aComponent); |
|
168 |
|
169 CMMAItemDisplay* itemDisplay = |
|
170 CMMAItemDisplay::NewLC(customItem); |
|
171 |
|
172 aControl->iDisplay = itemDisplay; |
|
173 CleanupStack::Pop(itemDisplay); |
|
174 *aDisplayHandle = JavaMakeHandle(itemDisplay); |
|
175 break; |
|
176 } |
|
177 case MMIDComponent::ECanvas: |
|
178 { |
|
179 //MMIDCanvas |
|
180 MMIDCanvas* canvas = reinterpret_cast< MMIDCanvas* >(aComponent); |
|
181 |
|
182 CMMACanvasDisplay* canvasDisplay = |
|
183 CMMACanvasDisplay::NewLC(canvas); |
|
184 |
|
185 aControl->iDisplay = canvasDisplay; |
|
186 CleanupStack::Pop(canvasDisplay); |
|
187 *aDisplayHandle = JavaMakeHandle(canvasDisplay); |
|
188 break; |
|
189 } |
|
190 default: |
|
191 { |
|
192 // other component types are not supported |
|
193 User::Leave(KErrNotSupported); |
|
194 } |
|
195 |
|
196 }*/ |
|
197 |
|
198 aControl->iGuiPlayer->SetDisplayL(aControl->iDisplay); |
|
199 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitL - "); |
|
200 } |
|
201 |
|
202 |
|
203 void CMMAVideoControl::SetDisplayHandleToJavaPeer(MMAFunctionServer* eventSource ,jobject aJavaVideoControlPeer) |
|
204 { |
|
205 JNIEnv* validJNI = eventSource->getValidJniEnv(); |
|
206 |
|
207 jmethodID jmid = validJNI->GetMethodID(validJNI->GetObjectClass(aJavaVideoControlPeer), |
|
208 "setNativeDisplayHandleToJavaPeer", |
|
209 "(I)V"); |
|
210 // DEBUG_INT("CMMADisplay::GetCallbackInUiThread getCallBackMethodID = %d",getCallBackMethodID); |
|
211 TInt handle = reinterpret_cast<TInt>(iDisplay); |
|
212 validJNI->CallVoidMethod(aJavaVideoControlPeer,jmid,handle); |
|
213 TRAP_IGNORE(iGuiPlayer->SetDisplayL(iDisplay)); |
|
214 } |
|
215 |
|
216 void CMMAVideoControl::StaticInitDynamicModeL( |
|
217 CMMAVideoControl* aVideoControl, |
|
218 JNIEnv* aJni, |
|
219 TInt* aContentHandle, |
|
220 MMAFunctionServer* aEventSource, |
|
221 jobject aGUIObject, |
|
222 CMMAEvent* aDeleteRefEvent) |
|
223 { |
|
224 LOG(EJavaMMAPI,EInfo,"MMA::CMMAVideoControl::StaticInitDynamicModeL+"); |
|
225 aVideoControl->iDeleteRefEvent = aDeleteRefEvent; |
|
226 |
|
227 CMMADCDisplay* dcDisplay = CMMADCDisplay::NewLC(aVideoControl->iGuiPlayer, |
|
228 aEventSource, |
|
229 aJni, |
|
230 aGUIObject); |
|
231 |
|
232 //MMMADirectContent* content = dcDisplay; |
|
233 *aContentHandle = reinterpret_cast< TInt >(dcDisplay); |
|
234 aVideoControl->iDisplay = dcDisplay; |
|
235 aVideoControl->iGuiPlayer->SetDisplayL(aVideoControl->iDisplay); |
|
236 CleanupStack::Pop(dcDisplay); |
|
237 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitDynamicModeL-"); |
|
238 } |
|
239 |
|
240 void CMMAVideoControl::StaticGetPropertyL(CMMAVideoControl* aControl, |
|
241 TInt aPropertyType, |
|
242 TInt* aReturnValue) |
|
243 { |
|
244 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL property %d", |
|
245 aPropertyType); |
|
246 |
|
247 // MMAPI UI 3.x req. |
|
248 // remove the below return and uncomment the below code once display is implemented in java |
|
249 // return; |
|
250 |
|
251 |
|
252 MMMADisplay* display = aControl->iDisplay; |
|
253 |
|
254 if (aPropertyType != com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_WIDTH && |
|
255 aPropertyType != com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_HEIGHT && |
|
256 !display) |
|
257 { |
|
258 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL not initialized yet"); |
|
259 // init is not done yet, returning 0 |
|
260 *aReturnValue = 0; |
|
261 return; |
|
262 } |
|
263 |
|
264 switch (aPropertyType) |
|
265 { |
|
266 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_WIDTH: |
|
267 { |
|
268 *aReturnValue = display->DisplaySize().iWidth; |
|
269 break; |
|
270 } |
|
271 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_HEIGHT: |
|
272 { |
|
273 *aReturnValue = display->DisplaySize().iHeight; |
|
274 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL aReturnValue %d", |
|
275 *aReturnValue); |
|
276 break; |
|
277 } |
|
278 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_X: |
|
279 { |
|
280 *aReturnValue = display->DisplayLocation().iX; |
|
281 break; |
|
282 } |
|
283 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_Y: |
|
284 { |
|
285 *aReturnValue = display->DisplayLocation().iY; |
|
286 break; |
|
287 } |
|
288 case com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_WIDTH: |
|
289 { |
|
290 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL get source width"); |
|
291 *aReturnValue = aControl->iGuiPlayer->SourceSize().iWidth; |
|
292 break; |
|
293 } |
|
294 case com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_HEIGHT: |
|
295 { |
|
296 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL get source height"); |
|
297 *aReturnValue = aControl->iGuiPlayer->SourceSize().iHeight; |
|
298 break; |
|
299 } |
|
300 default: |
|
301 { |
|
302 *aReturnValue = KErrNotFound; |
|
303 User::Leave(KErrNotFound); |
|
304 break; |
|
305 } |
|
306 } |
|
307 |
|
308 } |
|
309 |
|
310 |
|
311 void CMMAVideoControl::StaticSetPropertyL(CMMAVideoControl* aControl, |
|
312 TInt aPropertyType, |
|
313 TInt aPropertyA, |
|
314 TInt aPropertyB) |
|
315 { |
|
316 //LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL property type %d", |
|
317 // aPropertyType); |
|
318 //LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL a property %d", |
|
319 // aPropertyA); |
|
320 // LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL b property %d", |
|
321 // aPropertyB); |
|
322 // MMAPI UI 3.x req. |
|
323 // remove the below return and uncomment the below code; once display is implemented in java |
|
324 // return; |
|
325 |
|
326 |
|
327 MMMADisplay* display = aControl->iDisplay; |
|
328 |
|
329 __ASSERT_DEBUG(display != NULL, |
|
330 User::Panic(_L("display not initialized"), KErrNotReady)); |
|
331 |
|
332 switch (aPropertyType) |
|
333 { |
|
334 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_SIZE: |
|
335 { |
|
336 TSize displaySize(aPropertyA, aPropertyB); |
|
337 LOG1(EJavaMMAPI, EInfo, "CMMAVideoControl::statepropertyl %d",displaySize); |
|
338 display->SetDisplaySizeL(displaySize); |
|
339 LOG(EJavaMMAPI, EInfo, "CMMAVideoControl::SetDisplayProperty:: setDisplaySizeL Completed"); |
|
340 // inform java side |
|
341 if (!display->IsFullScreen()) |
|
342 { |
|
343 aControl->iGuiPlayer->NotifyWithStringEvent( |
|
344 CMMAPlayerEvent::ESizeChanged, KControlName); |
|
345 } |
|
346 break; |
|
347 } |
|
348 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_LOCATION: |
|
349 { |
|
350 TPoint displayLocation(aPropertyA, aPropertyB); |
|
351 display->SetDisplayLocationL(displayLocation); |
|
352 break; |
|
353 } |
|
354 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_VISIBLE_TRUE: |
|
355 { |
|
356 display->SetVisible(ETrue); |
|
357 break; |
|
358 } |
|
359 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_VISIBLE_FALSE: |
|
360 { |
|
361 display->SetVisible(EFalse); |
|
362 break; |
|
363 } |
|
364 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_FULLSCREEN_TRUE: |
|
365 { |
|
366 // store old user rect to determine if SIZE_CHANGED event |
|
367 // has to be delivered when full screen mode is turned off. |
|
368 aControl->iOldDisplaySize = display->DisplaySize(); |
|
369 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL a property %d", |
|
370 aPropertyA); |
|
371 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL b property %d", |
|
372 aPropertyB); |
|
373 TSize fullscreenSize(aPropertyA, aPropertyB); |
|
374 display->SetFullscreenSize(fullscreenSize); |
|
375 //display->SetDisplaySizeL(fullsclreenSize); |
|
376 display->SetFullScreenL(ETrue); |
|
377 //display->SourceSizeChanged(aPropertyA, aPropertyB,0,0,TRect(0,0,0,0)); |
|
378 break; |
|
379 } |
|
380 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_FULLSCREEN_FALSE: |
|
381 { |
|
382 display->SetFullScreenL(EFalse); |
|
383 |
|
384 // Send SIZE_CHANGED event when fullscreen is turned off if |
|
385 // size of the video display has changed. Possible position |
|
386 // change is however disregarded |
|
387 if (aControl->iOldDisplaySize != display->DisplaySize()) |
|
388 { |
|
389 aControl->iGuiPlayer->NotifyWithStringEvent( |
|
390 CMMAPlayerEvent::ESizeChanged, KControlName); |
|
391 } |
|
392 |
|
393 break; |
|
394 } |
|
395 default: |
|
396 { |
|
397 User::Leave(KErrNotFound); |
|
398 break; |
|
399 } |
|
400 } |
|
401 |
|
402 } |
|
403 |
|
404 |
|
405 void CMMAVideoControl::TakeSnapShotL(CMMAVideoControl* aControl, |
|
406 const TDesC* aProperties) |
|
407 { |
|
408 __ASSERT_DEBUG( |
|
409 aControl, |
|
410 User::Panic(_L("CMMAVideoControl::TakeSnapShotL CMMAVideoControl is NULL"), |
|
411 KErrArgument) |
|
412 ); |
|
413 |
|
414 ASSERT(aProperties); |
|
415 aControl->iSnapshot->TakeSnapShotL(*aProperties); |
|
416 } |
|
417 |
|
418 EXPORT_C void CMMAVideoControl::SnapshotReady() |
|
419 { |
|
420 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::SnapshotReady()"); |
|
421 |
|
422 // now this class owns the buffer |
|
423 HBufC8* imageBuffer = iSnapshot->ImageBuffer(); |
|
424 // Use standard new to avoid useless trap. |
|
425 CMMASnapshotEvent* event = |
|
426 new CMMASnapshotEvent(iListenerObject, |
|
427 iSnapshotReadyMethod, |
|
428 iSnapshot->iStatus.Int(), |
|
429 imageBuffer, |
|
430 CMMAEvent::EDisposableEvent); |
|
431 if (event) |
|
432 { |
|
433 // ok, ownership of buffer transfered to event |
|
434 |
|
435 // event poster takes the ownership of the event |
|
436 iEventPoster->PostEvent(event, CMMAEvent::ENotifyPriority); |
|
437 } |
|
438 else |
|
439 { |
|
440 // we own the buffer |
|
441 delete imageBuffer; |
|
442 } |
|
443 } |
|
444 |
|
445 EXPORT_C const TDesC& CMMAVideoControl::ClassName() const |
|
446 { |
|
447 return KControlName; |
|
448 } |
|
449 TBool CMMAVideoControl::IsForeground() |
|
450 { |
|
451 LOG1(EJavaMMAPI, EInfo, "CMMAVideoControl::IsForeground() %d",iIsForeground); |
|
452 |
|
453 return iIsForeground; |
|
454 } |
|
455 |
|
456 void CMMAVideoControl::StaticSetForegroundL(CMMAVideoControl* aControl, |
|
457 TInt aForeground) |
|
458 { |
|
459 LOG1(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetForegroundL + aForeground %d", |
|
460 aForeground); |
|
461 |
|
462 __ASSERT_DEBUG( |
|
463 aControl, |
|
464 User::Panic(_L("MMA::CMMAVideoControl::StaticSetForegroundL : CMMAVideoControl is NULL"), |
|
465 KErrArgument) |
|
466 ); |
|
467 |
|
468 if (aControl) |
|
469 { |
|
470 aControl->SetForeground(aForeground, EFalse); |
|
471 } |
|
472 |
|
473 LOG(EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetForegroundL - "); |
|
474 } |
|
475 |
|
476 /* // 3.x QT based UI |
|
477 // Implement MMIDEnvObserver |
|
478 |
|
479 void CMMAVideoControl::HandleSwitchOnL(TBool aSwitchOn) |
|
480 { |
|
481 // Dummy implementation, no intent to do anything |
|
482 } |
|
483 */ |
|
484 /** |
|
485 * Handles the case when the MIDlet is brought to the foreground. |
|
486 */ |
|
487 |
|
488 /* |
|
489 void CMMAVideoControl::HandleForegroundL(TBool aForeground) |
|
490 { |
|
491 |
|
492 SetForeground(aForeground, ETrue); |
|
493 |
|
494 } |
|
495 |
|
496 */ |
|
497 void CMMAVideoControl::SetForeground(TBool aForeground, TBool aUseEventServer) |
|
498 { |
|
499 iIsForeground = aForeground; |
|
500 if (iDisplay) |
|
501 { |
|
502 iDisplay->SetForeground(iIsForeground, aUseEventServer); |
|
503 } |
|
504 } |
|
505 |
|
506 /* |
|
507 MMMAGuiPlayer* CMMAVideoControl::GuiPlayer() |
|
508 { |
|
509 return iGuiPlayer; |
|
510 } |
|
511 */ |
|
512 /** |
|
513 * Handles a change to resources which are shared accross the environment. |
|
514 */ |
|
515 /* |
|
516 void CMMAVideoControl::HandleResourceChangeL(TInt aType) |
|
517 { |
|
518 // Dummy implementation, no intent to do anything |
|
519 } |
|
520 */ // end of // 3.x QT based UI |
|
521 // END OF FILE |