⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsfactory.java

📁 this is the media streaming project
💻 JAVA
字号:
/****************************************************************************************/
/* 2001-Spring: Java Network-Programming Term-Project					*/
/* Title: Streaming media generation, capture and store.				*/
/* Team Member: Yumin Yuan(yuany@rpi.edu), Rui Mu(mur@rpi.edu), Yining Hu(huyn@rpi.edu) */
/* DSFacotory.java: This class does all the dirty work regarding the media format and   */
/* creat buffer and copy of the media for saving and playing 				*/
/* Complile: javac DSFactory.java							*/
/****************************************************************************************/

import javax.media.*;
import java.util.*;
import java.io.*;
import javax.media.protocol.*;
import javax.media.format.*;
import java.net.*;
import javax.media.control.TrackControl;
	    
public class DSFactory {

    private DataSource cloneableLocalVideoDS=null;
    private int localvideocount=0;

    private DataSource cloneableRemoteVideoDS=null;
    private int remotevideocount=0;
    
    private String ds=null;
    private String ip=null;
    private String sendPort=null;
    private String receivePort=null;

    //this constructor is for real-time communictions
    public DSFactory(String _ip,String _sendport, String _receiveport, String _datasource )     {
	ip=_ip;
	sendPort=_sendport;
	receivePort=_receiveport;
	ds = _datasource;
        createLocalVideoDS();
	
    }
    //this constructor is for timing-recording function
    public DSFactory(String _ip, String _receiveport)     {
	ip=_ip;
	receivePort=_receiveport;
    }

    public void createRemote(){
	createRemoteVideoDS();
    }

    private void createLocalVideoDS(){
        try{
            MediaLocator locator=new MediaLocator(ds);
            cloneableLocalVideoDS = Manager.createDataSource(locator);
            cloneableLocalVideoDS=Manager.createCloneableDataSource (cloneableLocalVideoDS);
        }
        catch (NoDataSourceException e){
            System.out.println(e);
        }
        catch (IOException e){
            System.out.println(e);
        }
    }

     private void createRemoteVideoDS(){
	try{
	    MediaLocator locator=new MediaLocator("rtp://"+InetAddress.getLocalHost().getHostAddress()+":"+receivePort+"/video/1");
	 
	    Processor processor=Manager.createProcessor(locator);
	    StateHelper sh=new StateHelper(processor);
	    sh.waitForState(Processor.Configured);

	    if (true) {
		 boolean result = sh.waitForState(Processor.Realized);
		 if (result == false)
		     cloneableRemoteVideoDS = null;
		 cloneableRemoteVideoDS = processor.getDataOutput();
	    }	  

	    processor.start();
	    cloneableRemoteVideoDS=Manager.createCloneableDataSource(cloneableRemoteVideoDS);
	}
	 catch (Exception e){
            System.out.println(e);
	 }
       
    }

     public DataSource getRemoteVideoDS(){
        
	if (remotevideocount++==0)
	    return cloneableRemoteVideoDS;
	else
	    return ((SourceCloneable)cloneableRemoteVideoDS).createClone();
	
    }

    public DataSource getLocalCloneVideoDS(){
        
	if (localvideocount++==0)
	    return cloneableLocalVideoDS;
	else
	    return ((SourceCloneable)cloneableLocalVideoDS).createClone();
    }

    public String getReceiveVideoURL(){
	try{
	    return "rtp://"+InetAddress.getLocalHost().getHostAddress()+":"+receivePort+"/video/1";
	}
	catch (UnknownHostException e){
	    System.out.println(e);
	    return "";
	}
    }

    public String getSendVideoURL(){
	return "rtp://"+ip+":"+sendPort+"/video/1";
    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -