diff -r 2a9601315dfc -r 98ccebc37403 javauis/mmapi_qt/baseline/javasrc/com/nokia/microedition/media/animation/VideoControl.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javauis/mmapi_qt/baseline/javasrc/com/nokia/microedition/media/animation/VideoControl.java Fri May 14 15:47:24 2010 +0300 @@ -0,0 +1,548 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ +/** + * + */ +package com.nokia.microedition.media.animation; + +import javax.microedition.lcdui.Item; +import javax.microedition.media.MediaException; +import javax.microedition.media.Player; +import javax.microedition.media.PlayerListener; + +import org.eclipse.ercp.swt.mobile.MobileShell; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +//import com.nokia.microedition.media.control.ApplicationUtils; +import com.nokia.microedition.media.control.ControlImpl; +import com.nokia.microedition.media.control.MMAGUIFactory; +import com.nokia.mj.impl.rt.support.Finalizer; +import com.nokia.mj.impl.media.PlayerPermission; +import com.nokia.mj.impl.nokialcdui.ItemControlStateChangeListener; +import com.nokia.mj.impl.nokialcdui.LCDUIInvoker; + +//import com.nokia.mj.impl.media.PlayerPermission; +import com.nokia.mj.impl.rt.support.ApplicationUtils; + +/** + * @author d35kumar + * + */ +public class VideoControl extends ControlImpl implements + javax.microedition.media.control.VideoControl , ItemControlStateChangeListener{ + + // Following variable has been taken from VideoControl class + private static final String GUI_OBJECT_CLASS_NAME = + "javax.microedition.lcdui.Item"; + // lcdui package used with UiToolkitRegister + private static String LCDUI_PACKAGE = + "javax.microedition.lcdui"; + // eswt package used with UiToolkitRegister + private static String ESWT_PACKAGE = "org.eclipse.swt.widgets"; + // ToolkitRegister class name used with eswt and lcdui + private static String DISPLAY = ".Display"; + + // class name used to check if eswt is included + private static String LISTENER = ".Listener"; + + // class name used to check if eswt is included + private static String ESWT_CONTROL = ".control"; + // class name used with dynamic display mode initialization + private static String GUI_FACTORY_CLASS_NAME = ".Factory"; + + private static final int NOT_INITIALIZED = -1; + protected int iStatus = NOT_INITIALIZED; + private static final int UNDEFINED_RETURN_VALUE=0; + // For integrating with eSWT API + private Display iDisplay; +// private Shell iShell; + + private Control iControl; + + // Global??? yes because we need to remove it from player listener, while finalizer will be called + private VideoItem iVideoItem; + + private Finalizer mFinalizer = new Finalizer(){ + public void finalizeImpl(){ + doFinalize(); + } + }; + + /** + * Constructor of VideoControl + * @param player + */ + public VideoControl(Player player){ + this.iPlayer=player; + } + + /** + * + */ + private void doFinalize() { + if (mFinalizer != null) { + registeredFinalize(); + mFinalizer = null; + } + } + + /** + * + */ + final void registeredFinalize() { + if (iVideoItem != null) { + iPlayer.removePlayerListener(iVideoItem); + } + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#getDisplayHeight() + */ + public int getDisplayHeight() { + checkState(); + if (iStatus == NOT_INITIALIZED) { + throw new IllegalStateException( + "VideoControl.initDisplayMode() not called yet"); + } + return ((AnimationPlayer)iPlayer).getImageDimension().x; + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#getDisplayWidth() + */ + public int getDisplayWidth() { + checkState(); + if (iStatus == NOT_INITIALIZED) { + throw new IllegalStateException( + "VideoControl.initDisplayMode() not called yet"); + } + return ((AnimationPlayer)iPlayer).getImageDimension().x; + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#getDisplayX() + */ + public int getDisplayX() { + checkState(); + if (iStatus == NOT_INITIALIZED) + { + return UNDEFINED_RETURN_VALUE; + } + return ((AnimationPlayer)iPlayer).getiDisplayLocation().x; + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#getDisplayY() + */ + public int getDisplayY() { + checkState(); + if (iStatus == NOT_INITIALIZED) + { + return UNDEFINED_RETURN_VALUE; + } + return ((AnimationPlayer)iPlayer).getiDisplayLocation().y; + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#getSnapshot(java.lang.String) + */ + public byte[] getSnapshot(String aImageType) throws MediaException { + final String DEBUG_STR="VideoControl::getSnapshot(String aImageType)"; + System.out.println(DEBUG_STR+"+"); + checkState(); + if (iStatus == NOT_INITIALIZED) { + throw new IllegalStateException( + "VideoControl.initDisplayMode() not called yet"); + } + int imageData[]=((AnimationPlayer)iPlayer).getCurrentFrame(aImageType); + byte bytArry[]= new byte[imageData.length]; + int pixelCount=bytArry.length; + System.out.println(DEBUG_STR+"imageData receved is "+imageData); + for(int i=0;i>>>>>> Control is "+iControl); + // in case of customItem, we are getting canvasExtension as control + // and in this case we need to ignore the setDisplayLocation call. + // it is also possible that iControl may be null( it will be null until and unless + // notifyControlAvailable function is not get called) + if(iControl==null || (iControl instanceof org.eclipse.swt.internal.extension.CanvasExtension)) + return ; + ((AnimationPlayer)iPlayer).setDisplayLocation(aX, aY); + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#setDisplaySize(int, int) + */ + public void setDisplaySize(int aWidth, int aHeight) throws MediaException { + final String DEBUG_STR="VideoControl::setDisplaySize(int aWidth, int aHeight)"; + System.out.println(DEBUG_STR+"width "+aWidth+" aHeight "+aHeight); + if (iStatus == NOT_INITIALIZED) + { + throw new IllegalStateException( + "VideoControl.initDisplayMode() not called yet"); + } + if (aWidth <= 0 || aHeight <= 0) + { + throw new IllegalArgumentException( + "Width and height must be positive"); + } + ((AnimationPlayer) iPlayer).updateImageData(aWidth,aHeight); + // Since the DisplaySize is being changed, we need to change the + // size of VideoItem as well + // if the videoItem is not null, it means currently we are playing animation on form + if(iVideoItem!=null)// means it is for customItem + iVideoItem.setPreferredSize(aWidth, aHeight); + // Notify to all player listener that video Size has been changed + ((AnimationPlayer) iPlayer).getiPlayerListenerImpl().postEvent(PlayerListener.SIZE_CHANGED, this); + System.out.println(DEBUG_STR+"-"); + } + + /* (non-Javadoc) + * @see javax.microedition.media.control.VideoControl#setVisible(boolean) + */ + public void setVisible(final boolean aVisible) { + if (iControl != null) { + iDisplay.syncExec(new Runnable() { + public void run() { + iControl.setVisible(aVisible); + System.out.println("VideoControl::setVisible()"+aVisible); + } + }); + } + } + /** + * + * @return Display object retrieved from ESWT + */ + public Display getiDisplay() { + return iDisplay; + } + + /** + * + * @return + */ + public Control getControl() { + return iControl; + } + /** + * Function of ItemStateChangeListener + * @param ctrl + * @param item + */ + public void notifyControlAvailable(Control ctrl,Item item){ + final String DEBUG_STR= "VideoControl::notifyControlAvailable(Control ctrl,Item item)"; + System.out.println(DEBUG_STR+"+"); + iControl=ctrl; + System.out.println(DEBUG_STR+"Control is "+ctrl.hashCode()+ " Item is "+item); + //TODO is it proper here to put the below line in try/catch?, remove if we can + // otherwise it may deteriorate the performance, as in case of CustomItem on each + // repaint, eSWT control is getting destroyed, and reconstructed + try { + ((AnimationPlayer)iPlayer).addPaintListener(iControl); + } catch (MediaException e) { + // TODO What to do here + e.printStackTrace(); + } + System.out.println(DEBUG_STR+"-"); + } + /** + * Function of ItemStateChangeListener + * We don't need to do anything in this function + * @param item + */ + public void notifyControlDisposed(Item item){ + final String DEBUG_STR= "VideoControl::notifyControlDisposed(Item item)"; + System.out.println(DEBUG_STR+"+"); +// System.out.println(DEBUG_STR+"Item Disposed is "+item); +// System.out.println(DEBUG_STR+"-"); + } + +}