FileDocCategorySizeDatePackage
ExportWizard.javaAPI DocJMF 2.1.1e24713Mon May 12 12:20:32 BST 2003jmapps.export

ExportWizard

public class ExportWizard extends WizardDialog implements ControllerListener, DataSinkListener

Fields Summary
protected PanelMediaSource
panelSource
protected PanelMediaTargetType
panelTargetType
protected PanelMediaTargetFormat
panelTargetFormat
protected PanelMediaTargetFile
panelTargetFile
protected PanelMediaTargetNetwork
panelTargetNetwork
protected String
strTitle
protected Processor
processor
protected String
strTargetType
protected boolean
boolChangedProcessor
protected boolean
boolChangedTargetType
protected String
strFailMessage
protected DataSink
dataSinkSave
protected ProgressDialog
dlgProgressSave
protected ProgressThread
threadProgressSave
protected TransmitPlayerWindow
playerTransmit
protected CaptureControlsDialog
dlgCaptureControls
protected Vector
vectorWindowsLeft
private JMAppsCfg
cfgJMApps
Object
stateLock
boolean
stateFailed
Constructors Summary
public ExportWizard(String strTitle, Frame frame, String strSourceUrl, JMAppsCfg cfgJMApps)



                
    	super ( frame, strTitle, true, "logo.gif" );

        this.strTitle = strTitle;
        this.setTitle ( strTitle );

        this.cfgJMApps = cfgJMApps;
        panelSource.setJMStudioCfg ( cfgJMApps );
        panelSource.setSourceUrl ( strSourceUrl );
        panelTargetNetwork.setJMStudioCfg ( cfgJMApps );
    
public ExportWizard(Frame frame, String strSourceUrl, JMAppsCfg cfgJMApps)

    	this ( JMFI18N.getResource("jmstudio.export.title"), frame, strSourceUrl, cfgJMApps );
    
Methods Summary
public voidactionPerformed(java.awt.event.ActionEvent event)

        String        strCmd;
        Object        objectSource;

        strCmd = event.getActionCommand ();
        if ( (strCmd.equals(ProgressDialog.ACTION_ABORT)
                        ||  strCmd.equals(ProgressDialog.ACTION_STOP))
                        &&  dataSinkSave != null ) {
            stopSaving ();
        }
        else if ( strCmd.equals(ProgressDialog.ACTION_PAUSE) &&  dataSinkSave != null ) {
            processor.stop ();
            dlgProgressSave.setPauseButtonText ( ProgressDialog.ACTION_RESUME );
            threadProgressSave.pauseThread ();
        }
        else if ( strCmd.equals(ProgressDialog.ACTION_RESUME) &&  dataSinkSave != null ) {
            processor.start ();
            dlgProgressSave.setPauseButtonText ( ProgressDialog.ACTION_PAUSE );
            threadProgressSave.resumeThread ();
        }
        else
            super.actionPerformed ( event );
    
protected voidaddTransmitSessionManager(javax.media.rtp.SessionManager mngrSession, javax.media.rtp.SendStream streamSend, java.lang.String strStreamLabel)


        if ( playerTransmit == null )
            return;

        playerTransmit.addSessionManager ( mngrSession, streamSend, strStreamLabel );
    
private synchronized voidcloseDataSink()

        if (dataSinkSave != null) {
            dataSinkSave.close ();
            dataSinkSave = null;
        }
    
private voidconfigureProcessor()

        boolean         boolResult;

        if ( processor == null )
            return;

        // wait for processor to be configured
        boolResult = waitForState ( processor, Processor.Configured );
        if ( boolResult == false ) {
//            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.configure") + " " + strFailMessage );
            MessageDialog.createErrorDialog ( frameOwner, strFailMessage );
            destroyProcessor ();
        }
    
public voidcontrollerUpdate(javax.media.ControllerEvent event)

        if ( event instanceof ControllerErrorEvent ) {
            strFailMessage = JMFI18N.getResource ( "jmstudio.error.controller" )
                    + "\n" + ((ControllerErrorEvent)event).getMessage ();
//            MessageDialog.createErrorDialogModeless ( frameOwner, strFailMessage );
        }
        else if (event instanceof EndOfMediaEvent) {
            if ( strTargetType.equals(PanelMediaTargetType.TYPE_FILE) )
                stopSaving();
        }
    
protected voidcreateTransmitWindow()


        if ( processor == null )
            return;

        playerTransmit = new TransmitPlayerWindow ( processor );
        playerTransmit.addWindowListener ( this );
        vectorWindowsLeft.addElement ( playerTransmit );
    
public voiddataSinkUpdate(javax.media.datasink.DataSinkEvent event)

        if ( event instanceof EndOfStreamEvent ) {
            closeDataSink();
//            MessageDialog.createInfoDialog ( frameOwner, "File has been saved." );
        } else if ( event instanceof DataSinkErrorEvent ) {
            stopSaving();
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.writefile") );
        }
    
private voiddestroyProcessor()

        if ( processor == null )
            return;
	processor.removeControllerListener(this);
        processor.close ();
        processor = null;
        panelSource.setDataSource ( null );
    
private booleandoPreview()

        DataSource    dsOutput;
        Player        player;
        PlayerWindow  windowPlayer;

        if ( processor == null )
            return ( false );

        panelTargetFormat.updateProcessorFormat ();
        realizeProcessor ();
        if ( processor == null )
            return ( false );

        dsOutput = processor.getDataOutput ();
        if ( dsOutput == null ) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.creatednooutput") );
            destroyProcessor ();
            return ( false );
        }

        // Create a Player with the data source
        // Create a PlayerWindow for the Player (this will start the player)
        // Start the processor
        try {
            player = javax.media.Manager.createPlayer ( dsOutput );
            if ( player != null ) {
                windowPlayer = new PlayerWindow ( player, JMFI18N.getResource("jmstudio.playerwindow.preview") );
                vectorWindowsLeft.addElement ( windowPlayer );
                windowPlayer = new PlayerWindow ( processor, JMFI18N.getResource("jmstudio.playerwindow.transcoding") );
                vectorWindowsLeft.addElement ( windowPlayer );
            }
            else {
                MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.player.create") );
                destroyProcessor ();
                return ( false );
            }
        }
        catch ( Exception exception ) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.player.create"), exception );
            destroyProcessor ();
            return ( false );
        }

        return ( true );
    
private booleandoSaveFile()

        int                 i;
        DataSource          dsOutput;
        MediaLocator        mediaDest;
        Object              arrControls[];
        int                 nMediaDuration;
        String              strFileName;
        MonitorControl      monitorControl = null;
        Component           monitor = null;

        if ( processor == null )
            return ( false );

        panelTargetFormat.updateProcessorFormat ();
        realizeProcessor ();
        if ( processor == null )
            return ( false );

        dsOutput = processor.getDataOutput ();
        if ( dsOutput == null ) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.creatednooutput") );
            destroyProcessor ();
            return ( false );
        }

        try {
            strFileName = panelTargetFile.getFileName ();
            mediaDest = new MediaLocator ( "file:" + strFileName );
            dataSinkSave = javax.media.Manager.createDataSink ( dsOutput, mediaDest );
        }
        catch ( Exception exception ) {
            stopSaving ();
            MessageDialog.createErrorDialog ( frameOwner, exception );
            return ( false );
        }

        try {
            dataSinkSave.addDataSinkListener( this );
            monitorControl = (MonitorControl)
            processor.getControl("javax.media.control.MonitorControl");
            if (monitorControl != null)
                monitor = monitorControl.getControlComponent();

            Time duration = processor.getDuration();
            nMediaDuration = (int)duration.getSeconds();

            dataSinkSave.open ();
            dataSinkSave.start ();
            processor.start ();
            //dataSource.start ();

            if ( nMediaDuration > 0
                    &&  duration != Duration.DURATION_UNBOUNDED
                    &&  duration != Duration.DURATION_UNKNOWN )
                dlgProgressSave = new ProgressDialog ( frameOwner,
						       JMFI18N.getResource("jmstudio.saveprogress.title"),
						       0, nMediaDuration, this );
            else
                dlgProgressSave = new ProgressDialog ( frameOwner,
						       JMFI18N.getResource("jmstudio.saveprogress.title"),
						       JMFI18N.getResource("jmstudio.saveprogress.label"),
						       monitor, this );

            dlgProgressSave.setVisible ( true );

            threadProgressSave = new ProgressThread ( processor, dlgProgressSave );
            threadProgressSave.start ();

            vectorWindowsLeft.addElement ( dlgProgressSave );
        }
        catch ( Exception exception ) {
            stopSaving ();
            MessageDialog.createErrorDialog ( frameOwner, exception );
        }

        return ( true );
    
private booleandoTransmit()

        int                     i;
        DataSource              dsOutput;
        MediaLocator            mediaDest;
        Object                  arrControls[];
        int                     nMediaDuration;
        String                  strFileName;
        PushBufferStream        arrStreams [];
        boolean                 boolSucceeded;
        boolean                 arrAudioEnabled [];
        boolean                 arrVideoEnabled [];
        String                  arrVideoAddresses [];
        String                  arrAudioAddresses [];
        String                  arrVideoPorts [];
        String                  arrAudioPorts [];
        String                  arrVideoTtls [];
        String                  arrAudioTtls [];
        SessionManager          managerSession;
        SendStream              streamSend;
        TrackControl            arrTrackControls [];
        Format                  format;
        int                     nVideoIndex;
        int                     nAudioIndex;
        String                  strAddress;
        String                  strPort;
        String                  strTtl;
        String                  strStreamLabel;
        String                  strAudio = JMFI18N.getResource("jmstudio.export.targetnw.audio");
        String                  strVideo = JMFI18N.getResource("jmstudio.export.targetnw.video");


        if ( processor == null )
            return ( false );

	panelSource.setCaptureDlg(null);

        panelTargetFormat.updateProcessorFormat ();
        realizeProcessor ();
        if ( processor == null )
            return ( false );

        dsOutput = processor.getDataOutput ();
        if ( dsOutput == null ) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.creatednooutput") );
            destroyProcessor ();
            return ( false );
        }
        if ( !(dsOutput instanceof PushBufferDataSource) ) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.outputincorrect") );
            destroyProcessor ();
            return ( false );
        }

        arrStreams = ((PushBufferDataSource)dsOutput).getStreams ();
        if (arrStreams == null) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.outputempty") );
            destroyProcessor ();
            return ( false );
        }

        arrVideoEnabled = panelTargetFormat.getEnabledVideoTracks ();
        arrAudioEnabled = panelTargetFormat.getEnabledAudioTracks ();

        arrVideoAddresses = panelTargetNetwork.getVideoAddresses ();
        arrAudioAddresses = panelTargetNetwork.getAudioAddresses ();
        arrVideoPorts = panelTargetNetwork.getVideoPorts ();
        arrAudioPorts = panelTargetNetwork.getAudioPorts ();
        arrVideoTtls = panelTargetNetwork.getVideoTtls ();
        arrAudioTtls = panelTargetNetwork.getAudioTtls ();

        arrTrackControls = processor.getTrackControls ();
        nVideoIndex = 0;
        nAudioIndex = 0;

        boolSucceeded = false;

        for ( i = 0;  i < arrStreams.length;  i++ ) {
            format = arrStreams[i].getFormat ();
            if ( format instanceof VideoFormat ) {
                while ( (nVideoIndex < arrVideoEnabled.length) &&
			arrVideoEnabled[nVideoIndex] == false )
                    nVideoIndex++;

		if (nVideoIndex >= arrVideoEnabled.length)
		    continue;


                strAddress = arrVideoAddresses[nVideoIndex];
                strPort = arrVideoPorts[nVideoIndex];
                strTtl = arrVideoTtls[nVideoIndex];
                nVideoIndex++;
                strStreamLabel = strVideo + " " + nVideoIndex;
            } else if ( format instanceof AudioFormat ) {
                while ( (nAudioIndex < arrAudioEnabled.length) &&
			arrAudioEnabled[nAudioIndex] == false )
                    nAudioIndex++;

		if (nAudioIndex >= arrAudioEnabled.length)
		    continue;

                strAddress = arrAudioAddresses[nAudioIndex];
                strPort = arrAudioPorts[nAudioIndex];
                strTtl = arrAudioTtls[nAudioIndex];
                nAudioIndex++;
                strStreamLabel = strAudio + " " + nAudioIndex;
            } else
                continue;

            try {
                if ( strAddress.equals("...")  ||  strPort.equals("") )
                    continue;
                managerSession = JMFUtils.createSessionManager ( strAddress, strPort, strTtl, null );
                if ( managerSession == null ) {
                    MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.createsessionmanager") );
                    destroyProcessor ();
                    return ( false );
                }
                streamSend = managerSession.createSendStream ( dsOutput, i );
                streamSend.start();
                if ( !boolSucceeded ) {
                    createTransmitWindow ();
                }
                boolSucceeded = true;
                addTransmitSessionManager ( managerSession, streamSend, strStreamLabel );
            } catch ( Exception exception ) {
                MessageDialog.createErrorDialog ( frameOwner, exception );
                destroyProcessor ();
                return ( false );
            }
        }

        dlgCaptureControls = panelSource.getCaptureControlsDialog ();
        if ( dlgCaptureControls != null  &&  !dlgCaptureControls.isEmpty() ) {
            dlgCaptureControls.setVisible ( true );
        }

        if ( !boolSucceeded ) {
            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.transmittracks") );
            destroyProcessor ();
        }

        return ( boolSucceeded );
    
protected java.awt.PanelgetFirstPage()

    	return ( panelSource );
    
protected java.awt.PanelgetLastPage()

    	String	strTargetType;
    	Panel	panel = null;

    	strTargetType = panelTargetType.getType ();
    	if ( strTargetType.equals(PanelMediaTargetType.TYPE_FILE) )
            panel = panelTargetFile;
    	else if ( strTargetType.equals(PanelMediaTargetType.TYPE_NETWORK) )
    	    panel = panelTargetNetwork;
    	else if ( strTargetType.equals(PanelMediaTargetType.TYPE_SCREEN) )
    	    panel = panelTargetFormat;

    	return ( panel );
    
protected java.awt.PanelgetNextPage(java.awt.Panel panelPage)

    	Panel	panelPageNext = null;
    	String	strTargetType;

    	if ( panelPage == null ) {
    	    panelPageNext = getFirstPage ();
    	}
    	else if ( panelPage == panelSource ) {
    	    panelPageNext = panelTargetType;
    	}
    	else if ( panelPage == panelTargetType ) {
    	    panelPageNext = panelTargetFormat;
    	}
    	else if ( panelPage == panelTargetFormat ) {
    	    strTargetType = panelTargetType.getType ();
    	    if ( strTargetType.equals(PanelMediaTargetType.TYPE_FILE) )
    	    	panelPageNext = panelTargetFile;
    	    else if ( strTargetType.equals(PanelMediaTargetType.TYPE_NETWORK) )
    	    	panelPageNext = panelTargetNetwork;
    	    else if ( strTargetType.equals(PanelMediaTargetType.TYPE_SCREEN) )
    	    	panelPageNext = null;
    	}
    	else {
    	    panelPageNext = null;
    	}

    	return ( panelPageNext );
    
protected java.awt.PanelgetPrevPage(java.awt.Panel panelPage)

    	Panel	panelPagePrev = null;

    	if ( panelPage == null )
    	    panelPagePrev = getLastPage ();
    	else if ( panelPage == panelTargetNetwork )
    	    panelPagePrev = panelTargetFormat;
    	else if ( panelPage == panelTargetFile )
    	    panelPagePrev = panelTargetFormat;
    	else if ( panelPage == panelTargetFile )
    	    panelPagePrev = panelTargetFormat;
    	else if ( panelPage == panelTargetFormat )
    	    panelPagePrev = panelTargetType;
    	else if ( panelPage == panelTargetType )
    	    panelPagePrev = panelSource;
    	else
    	    panelPagePrev = null;

    	return ( panelPagePrev );
    
public java.util.VectorgetWindowsLeft()

        return ( vectorWindowsLeft );
    
protected voidinit()

    	super.init ();

    	panelSource = new PanelMediaSource ( cfgJMApps );
    	panelTargetType = new PanelMediaTargetType ();
    	panelTargetFormat = new PanelMediaTargetFormat ();
    	panelTargetFile = new PanelMediaTargetFile ();
    	panelTargetNetwork = new PanelMediaTargetNetwork ( cfgJMApps );
    	this.setSize ( 480, 480 );
    	this.setLocation ( 100, 100 );
    
protected booleanonFinish()

        boolean    boolResult;

        setCursor ( new Cursor(Cursor.WAIT_CURSOR) );
        if ( strTargetType == null )
            boolResult = false;
        else if ( strTargetType.equals(PanelMediaTargetType.TYPE_FILE) )
            boolResult = doSaveFile ();
        else if ( strTargetType.equals(PanelMediaTargetType.TYPE_NETWORK) )
            boolResult = doTransmit ();
        else if ( strTargetType.equals(PanelMediaTargetType.TYPE_SCREEN) )
            boolResult = doPreview ();
        else
            boolResult = false;
        setCursor ( Cursor.getDefaultCursor() );

        return ( boolResult );
    
protected booleanonPageActivate(java.awt.Panel panelPage)

        String    strContentType;

    	if ( panelPage == panelSource ) {
            this.setTitle ( strTitle );
        }
    	else if ( panelPage == panelTargetFormat ) {
            if ( boolChangedProcessor == true  ||  boolChangedTargetType == true ) {
                setCursor ( new Cursor(Cursor.WAIT_CURSOR) );
                strContentType = panelSource.getDefaultContentType ();
                panelTargetFormat.setProcessor ( processor, strContentType, strTargetType );
                boolChangedProcessor = false;
                boolChangedTargetType = false;
                setCursor ( Cursor.getDefaultCursor() );
            }
    	}
    	else if ( panelPage == panelTargetFile ) {
    	    // ...
    	}
    	else if ( panelPage == panelTargetNetwork ) {
            panelTargetNetwork.setTracks ( panelTargetFormat.getEnabledVideoTracks(),
                                           panelTargetFormat.getEnabledAudioTracks() );
    	}
        return ( true );
    
protected booleanonPageDone(java.awt.Panel panelPage)

    	if ( panelPage == panelSource ) {
            setCursor ( new Cursor(Cursor.WAIT_CURSOR) );
            processor = panelSource.createProcessor ();
            if ( processor != null ) {
                processor.addControllerListener ( this );
                configureProcessor ();
            }
            setCursor ( Cursor.getDefaultCursor() );

            if ( processor == null ) {
                panelSource.setDataSource ( null );
                this.setTitle ( strTitle );
                return ( false );
            }
            boolChangedProcessor = true;
            this.setTitle ( strTitle + " " + panelSource.getSourceUrl() );
            panelSource.SaveData ();
    	}
    	else if ( panelPage == panelTargetType ) {
            if ( strTargetType == null  ||  !panelTargetType.getType().equals(strTargetType) ) {
                strTargetType = panelTargetType.getType ();
                boolChangedTargetType = true;
            }
    	}
    	else if ( panelPage == panelTargetNetwork ) {
            if ( panelTargetNetwork.checkValidFields(true) == false )
                return ( false );
            else
                panelTargetNetwork.saveData ();
    	}
        return ( true );
    
private voidrealizeProcessor()

        boolean         boolResult;

        if ( processor == null )
            return;

        // wait for processor to be configured
        boolResult = waitForState ( processor, Processor.Realized );
        if ( boolResult == false ) {
//            MessageDialog.createErrorDialog ( frameOwner, JMFI18N.getResource("jmstudio.error.processor.realize") + " " + strFailMessage );
            MessageDialog.createErrorDialog ( frameOwner, strFailMessage );
            destroyProcessor ();
        }
    
private voidstopSaving()

        if ( threadProgressSave != null ) {
            threadProgressSave.terminateNormaly ();
            threadProgressSave = null;
        }
        if ( processor != null ) {
            processor.stop ();
            destroyProcessor ();
        }
        if ( dlgProgressSave != null ) {
            dlgProgressSave.dispose ();
            dlgProgressSave = null;
        }
    
private synchronized booleanwaitForState(javax.media.Processor p, int state)


           
	StateListener sl;
	p.addControllerListener(sl = new StateListener());
        stateFailed = false;

        if (state == Processor.Configured) {
            p.configure();
        }
        else if (state == Processor.Realized) {
            p.realize();
        }

        while (p.getState() < state && !stateFailed) {
            synchronized (stateLock) {
                try {
                    stateLock.wait();
                }
                catch (InterruptedException ie) {
                    return false;
                }
            }
        }
	p.removeControllerListener(sl);
        return ( !stateFailed );
    
public voidwindowClosed(java.awt.event.WindowEvent event)

        Object          objSource;

        objSource = event.getSource ();
        if ( objSource == playerTransmit ) {
            if ( dlgCaptureControls != null ) {
                dlgCaptureControls.dispose ();
                dlgCaptureControls = null;
            }
            playerTransmit = null;
        }
        if ( getAction().equals(WizardDialog.ACTION_CANCEL) )
            destroyProcessor ();