|
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 { |
|
133 |
|
134 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitL +"); |
|
135 |
|
136 aControl->iDeleteRefEvent = aDeleteRefEvent; |
|
137 |
|
138 CMMACanvasDisplay* canvasDisplay = |
|
139 CMMACanvasDisplay::NewLC(aEventSource,javaDisplayRef); |
|
140 aControl->iDisplay = canvasDisplay; |
|
141 CleanupStack::Pop(canvasDisplay); |
|
142 *aDisplayHandle = reinterpret_cast<TInt>(canvasDisplay); |
|
143 |
|
144 |
|
145 /* MMIDComponent::TType componentType = aComponent->Type(); |
|
146 switch (componentType) |
|
147 { |
|
148 case MMIDComponent::ECustomItem: |
|
149 { |
|
150 //MMIDCustomItem // end of // 3.x QT based UI |
|
151 // MMIDCustomItem* customItem = |
|
152 // reinterpret_cast< MMIDCustomItem* >(aComponent); |
|
153 |
|
154 CMMAItemDisplay* itemDisplay = |
|
155 CMMAItemDisplay::NewLC(customItem); |
|
156 |
|
157 aControl->iDisplay = itemDisplay; |
|
158 CleanupStack::Pop(itemDisplay); |
|
159 *aDisplayHandle = JavaMakeHandle(itemDisplay); |
|
160 break; |
|
161 } |
|
162 case MMIDComponent::ECanvas: |
|
163 { |
|
164 //MMIDCanvas |
|
165 MMIDCanvas* canvas = reinterpret_cast< MMIDCanvas* >(aComponent); |
|
166 |
|
167 CMMACanvasDisplay* canvasDisplay = |
|
168 CMMACanvasDisplay::NewLC(canvas); |
|
169 |
|
170 aControl->iDisplay = canvasDisplay; |
|
171 CleanupStack::Pop(canvasDisplay); |
|
172 *aDisplayHandle = JavaMakeHandle(canvasDisplay); |
|
173 break; |
|
174 } |
|
175 default: |
|
176 { |
|
177 // other component types are not supported |
|
178 User::Leave(KErrNotSupported); |
|
179 } |
|
180 |
|
181 }*/ |
|
182 |
|
183 aControl->iGuiPlayer->SetDisplayL(aControl->iDisplay); |
|
184 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitL - "); |
|
185 } |
|
186 |
|
187 |
|
188 void CMMAVideoControl::SetDisplayHandleToJavaPeer(MMAFunctionServer* eventSource ,jobject aJavaVideoControlPeer) |
|
189 { |
|
190 JNIEnv* validJNI = eventSource->getValidJniEnv(); |
|
191 |
|
192 jmethodID jmid = validJNI->GetMethodID( validJNI->GetObjectClass(aJavaVideoControlPeer), |
|
193 "setNativeDisplayHandleToJavaPeer", |
|
194 "(I)V"); |
|
195 // DEBUG_INT("CMMADisplay::GetCallbackInUiThread getCallBackMethodID = %d",getCallBackMethodID); |
|
196 TInt handle = reinterpret_cast<TInt>(iDisplay); |
|
197 validJNI->CallVoidMethod(aJavaVideoControlPeer,jmid,handle); |
|
198 iGuiPlayer->SetDisplayL(iDisplay); |
|
199 } |
|
200 |
|
201 void CMMAVideoControl::StaticInitDynamicModeL( |
|
202 CMMAVideoControl* aVideoControl, |
|
203 TInt* aContentHandle, |
|
204 MMAFunctionServer* aEventSource, |
|
205 jobject aGUIObject, |
|
206 CMMAEvent* aDeleteRefEvent) |
|
207 { |
|
208 LOG(EJavaMMAPI,EInfo,"MMA::CMMAVideoControl::StaticInitDynamicModeL+"); |
|
209 aVideoControl->iDeleteRefEvent = aDeleteRefEvent; |
|
210 |
|
211 CMMADCDisplay* dcDisplay = CMMADCDisplay::NewLC(aVideoControl->iGuiPlayer, |
|
212 aEventSource, |
|
213 aGUIObject); |
|
214 |
|
215 MMMADirectContent* content = dcDisplay; |
|
216 *aContentHandle = reinterpret_cast< TInt >(content); |
|
217 aVideoControl->iDisplay = dcDisplay; |
|
218 aVideoControl->iGuiPlayer->SetDisplayL(aVideoControl->iDisplay); |
|
219 CleanupStack::Pop(dcDisplay); |
|
220 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticInitDynamicModeL-"); |
|
221 } |
|
222 |
|
223 void CMMAVideoControl::StaticGetPropertyL(CMMAVideoControl* aControl, |
|
224 TInt aPropertyType, |
|
225 TInt* aReturnValue) |
|
226 { |
|
227 LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL property %d", |
|
228 aPropertyType); |
|
229 |
|
230 // MMAPI UI 3.x req. |
|
231 // remove the below return; once display is implemented in java |
|
232 return; |
|
233 |
|
234 |
|
235 MMMADisplay* display = aControl->iDisplay; |
|
236 |
|
237 if (aPropertyType != com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_WIDTH && |
|
238 aPropertyType != com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_HEIGHT && |
|
239 !display) |
|
240 { |
|
241 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL not initialized yet"); |
|
242 // init is not done yet, returning 0 |
|
243 *aReturnValue = 0; |
|
244 return; |
|
245 } |
|
246 |
|
247 switch (aPropertyType) |
|
248 { |
|
249 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_WIDTH: |
|
250 { |
|
251 *aReturnValue = display->DisplaySize().iWidth; |
|
252 break; |
|
253 } |
|
254 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_HEIGHT: |
|
255 { |
|
256 *aReturnValue = display->DisplaySize().iHeight; |
|
257 break; |
|
258 } |
|
259 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_X: |
|
260 { |
|
261 *aReturnValue = display->DisplayLocation().iX; |
|
262 break; |
|
263 } |
|
264 case com_nokia_microedition_media_control_VideoControl_PROPERTY_DISPLAY_Y: |
|
265 { |
|
266 *aReturnValue = display->DisplayLocation().iY; |
|
267 break; |
|
268 } |
|
269 case com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_WIDTH: |
|
270 { |
|
271 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL get source width"); |
|
272 *aReturnValue = aControl->iGuiPlayer->SourceSize().iWidth; |
|
273 break; |
|
274 } |
|
275 case com_nokia_microedition_media_control_VideoControl_PROPERTY_SOURCE_HEIGHT: |
|
276 { |
|
277 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticGetPropertyL get source height"); |
|
278 *aReturnValue = aControl->iGuiPlayer->SourceSize().iHeight; |
|
279 break; |
|
280 } |
|
281 default: |
|
282 { |
|
283 *aReturnValue = KErrNotFound; |
|
284 User::Leave(KErrNotFound); |
|
285 break; |
|
286 } |
|
287 } |
|
288 } |
|
289 |
|
290 |
|
291 void CMMAVideoControl::StaticSetPropertyL(CMMAVideoControl* aControl, |
|
292 TInt aPropertyType, |
|
293 TInt aPropertyA, |
|
294 TInt aPropertyB) |
|
295 { |
|
296 LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL property type %d", |
|
297 aPropertyType); |
|
298 LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL a property %d", |
|
299 aPropertyA); |
|
300 LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetPropertyL b property %d", |
|
301 aPropertyB); |
|
302 // MMAPI UI 3.x req. |
|
303 // remove the below return; once display is implemented in java |
|
304 return; |
|
305 |
|
306 MMMADisplay* display = aControl->iDisplay; |
|
307 |
|
308 __ASSERT_DEBUG(display != NULL, |
|
309 User::Panic(_L("display not initialized"), KErrNotReady)); |
|
310 |
|
311 switch (aPropertyType) |
|
312 { |
|
313 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_SIZE: |
|
314 { |
|
315 TSize displaySize(aPropertyA, aPropertyB); |
|
316 display->SetDisplaySizeL(displaySize); |
|
317 |
|
318 // inform java side |
|
319 if (!display->IsFullScreen()) |
|
320 { |
|
321 aControl->iGuiPlayer->NotifyWithStringEvent( |
|
322 CMMAPlayerEvent::ESizeChanged, KControlName); |
|
323 } |
|
324 break; |
|
325 } |
|
326 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_LOCATION: |
|
327 { |
|
328 TPoint displayLocation(aPropertyA, aPropertyB); |
|
329 display->SetDisplayLocationL(displayLocation); |
|
330 break; |
|
331 } |
|
332 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_VISIBLE_TRUE: |
|
333 { |
|
334 display->SetVisible(ETrue); |
|
335 break; |
|
336 } |
|
337 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_VISIBLE_FALSE: |
|
338 { |
|
339 display->SetVisible(EFalse); |
|
340 break; |
|
341 } |
|
342 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_FULLSCREEN_TRUE: |
|
343 { |
|
344 // store old user rect to determine if SIZE_CHANGED event |
|
345 // has to be delivered when full screen mode is turned off. |
|
346 aControl->iOldDisplaySize = display->DisplaySize(); |
|
347 |
|
348 display->SetFullScreenL(ETrue); |
|
349 break; |
|
350 } |
|
351 case com_nokia_microedition_media_control_VideoControl_SET_DISPLAY_FULLSCREEN_FALSE: |
|
352 { |
|
353 display->SetFullScreenL(EFalse); |
|
354 |
|
355 // Send SIZE_CHANGED event when fullscreen is turned off if |
|
356 // size of the video display has changed. Possible position |
|
357 // change is however disregarded |
|
358 if (aControl->iOldDisplaySize != display->DisplaySize()) |
|
359 { |
|
360 aControl->iGuiPlayer->NotifyWithStringEvent( |
|
361 CMMAPlayerEvent::ESizeChanged, KControlName); |
|
362 } |
|
363 |
|
364 break; |
|
365 } |
|
366 default: |
|
367 { |
|
368 User::Leave(KErrNotFound); |
|
369 break; |
|
370 } |
|
371 } |
|
372 } |
|
373 |
|
374 |
|
375 void CMMAVideoControl::TakeSnapShotL(CMMAVideoControl* aControl, |
|
376 const TDesC* aProperties) |
|
377 { |
|
378 __ASSERT_DEBUG( |
|
379 aControl, |
|
380 User::Panic(_L("CMMAVideoControl::TakeSnapShotL CMMAVideoControl is NULL"), |
|
381 KErrArgument) |
|
382 ); |
|
383 |
|
384 ASSERT(aProperties); |
|
385 aControl->iSnapshot->TakeSnapShotL(*aProperties); |
|
386 } |
|
387 |
|
388 EXPORT_C void CMMAVideoControl::SnapshotReady() |
|
389 { |
|
390 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::SnapshotReady()"); |
|
391 |
|
392 // now this class owns the buffer |
|
393 HBufC8* imageBuffer = iSnapshot->ImageBuffer(); |
|
394 // Use standard new to avoid useless trap. |
|
395 CMMASnapshotEvent* event = |
|
396 new CMMASnapshotEvent(iListenerObject, |
|
397 iSnapshotReadyMethod, |
|
398 iSnapshot->iStatus.Int(), |
|
399 imageBuffer, |
|
400 CMMAEvent::EDisposableEvent); |
|
401 if (event) |
|
402 { |
|
403 // ok, ownership of buffer transfered to event |
|
404 |
|
405 // event poster takes the ownership of the event |
|
406 iEventPoster->PostEvent(event, CMMAEvent::ENotifyPriority); |
|
407 } |
|
408 else |
|
409 { |
|
410 // we own the buffer |
|
411 delete imageBuffer; |
|
412 } |
|
413 } |
|
414 |
|
415 EXPORT_C const TDesC& CMMAVideoControl::ClassName() const |
|
416 { |
|
417 return KControlName; |
|
418 } |
|
419 TBool CMMAVideoControl::IsForeground() |
|
420 { |
|
421 LOG1( EJavaMMAPI, EInfo, "CMMAVideoControl::IsForeground() %d",iIsForeground); |
|
422 |
|
423 return iIsForeground; |
|
424 } |
|
425 |
|
426 void CMMAVideoControl::StaticSetForegroundL(CMMAVideoControl* aControl, |
|
427 TInt aForeground) |
|
428 { |
|
429 LOG1( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetForegroundL + aForeground %d", |
|
430 aForeground); |
|
431 |
|
432 __ASSERT_DEBUG( |
|
433 aControl, |
|
434 User::Panic(_L("MMA::CMMAVideoControl::StaticSetForegroundL : CMMAVideoControl is NULL"), |
|
435 KErrArgument) |
|
436 ); |
|
437 |
|
438 if (aControl) |
|
439 { |
|
440 aControl->SetForeground(aForeground, EFalse); |
|
441 } |
|
442 |
|
443 LOG( EJavaMMAPI, EInfo, "MMA::CMMAVideoControl::StaticSetForegroundL - "); |
|
444 } |
|
445 |
|
446 /* // 3.x QT based UI |
|
447 // Implement MMIDEnvObserver |
|
448 |
|
449 void CMMAVideoControl::HandleSwitchOnL(TBool aSwitchOn) |
|
450 { |
|
451 // Dummy implementation, no intent to do anything |
|
452 } |
|
453 */ |
|
454 /** |
|
455 * Handles the case when the MIDlet is brought to the foreground. |
|
456 */ |
|
457 |
|
458 /* |
|
459 void CMMAVideoControl::HandleForegroundL(TBool aForeground) |
|
460 { |
|
461 |
|
462 SetForeground(aForeground, ETrue); |
|
463 |
|
464 } |
|
465 |
|
466 */ |
|
467 void CMMAVideoControl::SetForeground(TBool aForeground, TBool aUseEventServer) |
|
468 { |
|
469 iIsForeground = aForeground; |
|
470 if (iDisplay) |
|
471 { |
|
472 iDisplay->SetForeground(iIsForeground, aUseEventServer); |
|
473 } |
|
474 } |
|
475 |
|
476 |
|
477 /** |
|
478 * Handles a change to resources which are shared accross the environment. |
|
479 */ |
|
480 /* |
|
481 void CMMAVideoControl::HandleResourceChangeL(TInt aType) |
|
482 { |
|
483 // Dummy implementation, no intent to do anything |
|
484 } |
|
485 */ // end of // 3.x QT based UI |
|
486 // END OF FILE |