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