亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? mediamanager.java

?? 是一個用java實現(xiàn)的
?? JAVA
?? 第 1 頁 / 共 2 頁
字號:
/*
 * MediaManager.java
 *
 * Created on December 2, 2003, 8:56 AM
 */

package gov.nist.applet.phone.media;

import javax.sdp.SessionDescription;
import javax.sdp.SdpFactory;
import javax.sdp.SdpException;
import javax.sdp.SdpParseException;
import javax.sdp.Origin;
import javax.sdp.Connection;
import javax.sdp.SdpConstants;
import javax.sdp.MediaDescription;
import javax.sdp.Media;

import javax.media.*;
import javax.media.protocol.*;
import javax.media.protocol.DataSource;
import javax.media.format.*;
import javax.media.control.TrackControl;

import gov.nist.applet.phone.ua.MessageListener;
import gov.nist.applet.phone.media.receiver.Receiver;
import gov.nist.applet.phone.media.transmitter.Transmit;
import gov.nist.applet.phone.media.transmitter.StateListener;

import java.util.List;
import java.util.Iterator;
import java.util.Vector;
import java.util.Random;
import java.io.IOException;

/**
 * This class will handle the media part of a call
 * Opening the receiver and transmitter, close them,...
 * 
 * @author Jean Deruelle <jean.deruelle@nist.gov>
 *
 * <a href="{@docRoot}/uncopyright.html">This code is in the public domain.</a>
 */
public class MediaManager {
	//Media transmitter
	private Transmit transmit;
	//Media receiver
	private Receiver receiver;
	//Codec supported by the user agent
	public static List audioCodecSupportedList = null;
	public static List videoCodecSupportedList = null;
	//Remote Address to connect to
	private String remoteAddress;
	//Ports chosen
	private int remoteAudioPort;
	private int localAudioPort = -1;
	private int remoteVideoPort;
	private int localVideoPort = -1;
	//Codecs chosen
	private String negotiatedAudioCodec;
	private String negotiatedVideoCodec;
	//SdpFactory to create or parse Sdp Content 
	private SdpFactory sdpFactory;
	//callListener
	private MessageListener callListener;
	//flag to know if the session has been started
	private boolean started;
	//flag to know if the media session is going through the proxy
	private boolean proxyEnabled;

	/** 
	 * Creates a new instance of MediaManager 
	 * @param callListener - the sipListener of the application
	 */
	public MediaManager(MessageListener callListener) {
		try {
			sdpFactory = SdpFactory.getInstance();
		} catch (SdpException se) {
			se.printStackTrace();
		}
		this.callListener = callListener;
		started = false;
		proxyEnabled = false;
	}

	/**
	 * get the supported audio codecs in the sdp format
	 * @return array of the audio supported codecs
	 */
	public static String[] getSdpAudioSupportedCodecs() {
		Vector sdpSupportedCodecsList = new Vector();
		for (int i = 0; i < audioCodecSupportedList.size(); i++) {
			String sdpFormat =
				findCorrespondingSdpFormat(
					((Format) audioCodecSupportedList.get(i)).getEncoding());
			boolean redundant = false;
			for (int j = 0; j < sdpSupportedCodecsList.size(); j++) {
				if (sdpFormat == null){
					redundant = true;
					break;
				}					
				else if (sdpFormat
					.equalsIgnoreCase((String) sdpSupportedCodecsList.get(j))){
					redundant = true;
					break;
				}
					
			}
			if (!redundant)
				sdpSupportedCodecsList.addElement(sdpFormat);
		}
		for (int i = 0; i < sdpSupportedCodecsList.size(); i++)
			System.out.println(sdpSupportedCodecsList.get(i));
		return (String[]) sdpSupportedCodecsList.toArray(
			new String[sdpSupportedCodecsList.size()]);
	}

	/**
	 * get the supported video codecs in the sdp format
	 * @return array of the video supported codecs
	 */
	public static String[] getSdpVideoSupportedCodecs() {
		Vector sdpSupportedCodecsList = new Vector();
		for (int i = 0; i < videoCodecSupportedList.size(); i++) {
			String sdpFormat =
				findCorrespondingSdpFormat(
					((Format) videoCodecSupportedList.get(i)).getEncoding());
			boolean redundant = false;
			for (int j = 0; j < sdpSupportedCodecsList.size(); j++) {
				if (sdpFormat == null){
					redundant = true;
					break;
				}					
				else if (sdpFormat
					.equalsIgnoreCase((String) sdpSupportedCodecsList.get(j))){
					redundant = true;
					break;
				}
					
			}
			if (!redundant)
				sdpSupportedCodecsList.addElement(sdpFormat);
		}
		return (String[]) sdpSupportedCodecsList.toArray(
			new String[sdpSupportedCodecsList.size()]);
	}

	/**
	 * Detects the supported codecs of the user agent depending of 
	 * the devices connected to the computer
	 */
	public static void detectSupportedCodecs() {
		audioCodecSupportedList = new Vector();
		videoCodecSupportedList = new Vector();
		MediaLocator audioLocator = null;
		MediaLocator videoLocator = null;
		CaptureDeviceInfo videoCDI = null;
		CaptureDeviceInfo audioCDI = null;
		Vector captureDevices = null;
		captureDevices = CaptureDeviceManager.getDeviceList(null);
		System.out.println(
			"- number of capture devices: " + captureDevices.size());
		CaptureDeviceInfo cdi = null;
		for (int i = 0; i < captureDevices.size(); i++) {
			cdi = (CaptureDeviceInfo) captureDevices.elementAt(i);
			System.out.println(
				"    - name of the capture device: " + cdi.getName());
			Format[] formatArray = cdi.getFormats();
			for (int j = 0; j < formatArray.length; j++) {
				Format format = formatArray[j];
				if (format instanceof VideoFormat) {
					System.out.println(
						"         - format accepted by this VIDEO device: "
							+ format.toString().trim());
					if (videoCDI == null) {
						videoCDI = cdi;
					}
				} else if (format instanceof AudioFormat) {
					System.out.println(
						"         - format accepted by this AUDIO device: "
							+ format.toString().trim());
					if (audioCDI == null) {
						audioCDI = cdi;
					}
				} else
					System.out.println("         - format of type UNKNOWN");
			}
		}
		if (videoCDI != null)
			videoLocator = videoCDI.getLocator();
		if (audioCDI != null)
			audioLocator = audioCDI.getLocator();

		DataSource audioDS = null;
		DataSource videoDS = null;
		DataSource mergeDS = null;
		StateListener stateListener = new StateListener();
		//create the DataSource
		//it can be a 'video' DataSource, an 'audio' DataSource
		//or a combination of audio and video by merging both
		if (videoLocator == null && audioLocator == null)
			return;
		if (audioLocator != null) {
			try {
				//create the 'audio' DataSource
				audioDS = javax.media.Manager.createDataSource(audioLocator);
			} catch (Exception e) {
				System.out.println(
					"-> Couldn't connect to audio capture device");
			}
		}
		if (videoLocator != null) {
			try {
				//create the 'video' DataSource
				videoDS = javax.media.Manager.createDataSource(videoLocator);
			} catch (Exception e) {
				System.out.println(
					"-> Couldn't connect to video capture device");
			}
		}
		Processor processor = null;
		if (videoDS != null && audioDS != null) {
			try {
				//create the 'audio' and 'video' DataSource
				mergeDS =
					javax.media.Manager.createMergingDataSource(
						new DataSource[] { audioDS, videoDS });
			} catch (Exception e) {
				System.out.println(
					"-> Couldn't connect to audio or video capture device");
			}
			try {
				//Create the processor from the merging DataSource
				processor = javax.media.Manager.createProcessor(mergeDS);
			} catch (NoProcessorException npe) {
				npe.printStackTrace();
				return;
			} catch (IOException ioe) {
				ioe.printStackTrace();
				return;
			}
		}
		//if the processor has not been created from the merging DataSource
		if (processor == null) {
			try {
				if (audioDS != null)
					//Create the processor from the 'audio' DataSource
					processor = javax.media.Manager.createProcessor(audioDS);
				else
					//Create the processor from the 'video' DataSource
					processor = javax.media.Manager.createProcessor(videoDS);
			} catch (NoProcessorException npe) {
				npe.printStackTrace();
				return;
			} catch (IOException ioe) {
				ioe.printStackTrace();
				return;
			}
		}
		// Wait for it to configure
		boolean result =
			stateListener.waitForState(processor, Processor.Configured);
		if (result == false) {
			System.out.println("Couldn't configure processor");
			return;
		}

		// Get the tracks from the processor
		TrackControl[] tracks = processor.getTrackControls();

		// Do we have atleast one track?
		if (tracks == null || tracks.length < 1) {
			System.out.println("Couldn't find tracks in processor");
			return;
		}
		// Set the output content descriptor to RAW_RTP
		// This will limit the supported formats reported from
		// Track.getSupportedFormats to only valid RTP formats.
		ContentDescriptor cd = new ContentDescriptor(ContentDescriptor.RAW_RTP);
		processor.setContentDescriptor(cd);

		Format supported[];
		Format chosen = null;
		boolean atLeastOneTrack = false;

		// Program the tracks.
		for (int i = 0; i < tracks.length; i++) {
			Format format = tracks[i].getFormat();
			if (tracks[i].isEnabled()) {
				supported = tracks[i].getSupportedFormats();
				// We've set the output content to the RAW_RTP.
				// So all the supported formats should work with RTP.            
				if (supported.length > 0) {
					for (int j = 0; j < supported.length; j++) {
						System.out.println(
							"Supported format : "
								+ supported[j].toString().toLowerCase());
						//Add to the list of video supported codec
						if (supported[j] instanceof VideoFormat) {
							videoCodecSupportedList.add(supported[j]);
						}
						//Add to the list of audio supported codec
						else {
							audioCodecSupportedList.add(supported[j]);
						}
					}
				}
			}
		}
		processor.stop();
		processor.close();
	}

	/**
	 * Start the media Session i.e. transmitting and receiving RTP stream
	 * TODO : handle the sendonly, recvonly, sendrcv attributes of the SDP session
	 */
	public void startMediaSession(boolean transmitFirst) {
		if (!started) {
			startReceiving();
			startTransmitting();
			started = true;
		}
	}

	/**
	 * Stop the media Session i.e. transmitting and receiving RTP stream
	 * TODO : handle the sendonly, recvonly, sendrcv attributes of the SDP session
	 */
	public void stopMediaSession() {
		stopReceiving();
		stopTransmitting();
		started = false;
	}

	/**
	 * Start receiving RTP stream
	 */
	protected void startReceiving() {
		gov.nist.applet.phone.media.util.SessionDescription sessionDescription =
			new gov.nist.applet.phone.media.util.SessionDescription();
		sessionDescription.setAddress(remoteAddress);
		sessionDescription.setDestinationPort(remoteAudioPort);
		sessionDescription.setLocalPort(localAudioPort);
		sessionDescription.setTransportProtocol("udp");
		sessionDescription.setAudioFormat(negotiatedAudioCodec);
		sessionDescription.setVideoFormat(negotiatedVideoCodec);
		receiver = new Receiver(sessionDescription, transmit);
		receiver.receive(callListener.getConfiguration().contactIPAddress);
	}

	/**
	 * start transmitting RTP stream
	 */
	protected void startTransmitting() {
		gov.nist.applet.phone.media.util.SessionDescription sessionDescription =
			new gov.nist.applet.phone.media.util.SessionDescription();
		sessionDescription.setAddress(remoteAddress);
		sessionDescription.setLocalPort(remoteAudioPort);
		sessionDescription.setDestinationPort(remoteAudioPort);
		sessionDescription.setTransportProtocol("udp");
		/*if(mediaTransport.equalsIgnoreCase("tcp"))
		    sessionDescription.setAudioFormat("99");        
		else*/
		sessionDescription.setAudioFormat(negotiatedAudioCodec);
		sessionDescription.setVideoFormat(negotiatedVideoCodec);
		transmit = new Transmit(sessionDescription, receiver);
		// Start the media transmission
		String result =
			transmit.start(callListener.getConfiguration().contactIPAddress);
		System.out.println("Media Transmission started!!!");
		// result will be non-null if there was an error. The return
		// value is a String describing the possible error. Print it.
		if (result != null) {
			System.err.println("Error : " + result);
			//System.exit(0);
		}
	}

	/**
	 * Stop transmitting RTP stream
	 */
	protected void stopTransmitting() {
		if (transmit != null) {
			System.out.println("Media Transmitter stopped!!!");
			transmit.stop();
		}
	}

	/**
	 * Stop receiving RTP stream
	 */
	protected void stopReceiving() {
		if (transmit != null) {
			System.out.println("Media Receiver stopped!!!");
			receiver.stop();
		}
	}

	/**
	 * Extracts from the sdp all the information to initiate the media session
	 * @param incomingSdpBody - the sdp Body of the incoming call to negotiate the media session
	 */
	public void prepareMediaSession(String incomingSdpBody) {
		SessionDescription sessionDescription = null;
		try {
			sessionDescription =
				sdpFactory.createSessionDescription(incomingSdpBody);
			//Get the remote address where the user agent has to connect to
			Connection remoteConnection = sessionDescription.getConnection();
			remoteAddress = remoteConnection.getAddress();
		} catch (SdpParseException spe) {
			spe.printStackTrace();
		}
		localAudioPort = getAudioPort();
		localVideoPort = getVideoPort();
		System.out.println("Local listening audio port : " + localAudioPort);
		//Extract the codecs from the sdp session description
		List audioCodecList = extractAudioCodecs(sessionDescription);
		remoteAudioPort = getAudioPort(sessionDescription);
		//printCodecs(audioCodecList);        
		System.out.println("Remote listening audio port : " + remoteAudioPort);
		List videoCodecList = extractVideoCodecs(sessionDescription);
		remoteVideoPort = getVideoPort(sessionDescription);
		//printCodecs(videoCodecList);
		//System.out.println("Remote listening video port : "+remoteVideoPort);
		negotiatedAudioCodec = negotiateAudioCodec(audioCodecList);
		negotiatedVideoCodec = negotiateVideoCodec(videoCodecList);
	}

	/**
	 * Getting the sdp body for creating the response to an incoming call
	 * @param incomingSdpBody - the sdp Body of the incoming call to negotiate the media session
	 * @return The sdp body that will present what codec has been chosen
	 * and on which port every media will be received
	 */
	public Object getResponseSdpBody(String incomingSdpBody) {

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩1区2区3区| 亚洲一区二区三区四区在线免费观看 | 日韩精品久久久久久| 久久精品一区四区| 欧美日韩国产免费一区二区 | 三级一区在线视频先锋 | 色一情一乱一乱一91av| 激情伊人五月天久久综合| 亚洲一区二区成人在线观看| 国产欧美日韩在线观看| 欧美一区二区三区在线电影| 日本高清不卡一区| 成人影视亚洲图片在线| 麻豆国产欧美一区二区三区| 亚洲一二三四区不卡| 亚洲欧洲精品一区二区三区| 国产日韩欧美高清在线| 欧美日韩一区二区三区四区五区 | 国产婷婷色一区二区三区| 欧美一级片在线| 欧美日韩免费观看一区三区| 91在线国内视频| heyzo一本久久综合| 国产成人啪午夜精品网站男同| 免费高清在线一区| 亚洲.国产.中文慕字在线| 亚洲美女区一区| 亚洲乱码日产精品bd | 日韩黄色免费电影| 亚洲国产一区二区在线播放| 亚洲欧美日韩小说| 亚洲女人的天堂| 日韩美女久久久| 国产精品久久久久久亚洲伦| 国产精品水嫩水嫩| 国产欧美一区在线| 国产精品午夜春色av| 中文av一区二区| 国产精品久久久久9999吃药| 国产精品美女视频| 中文字幕亚洲一区二区va在线| 国产精品高清亚洲| 最新高清无码专区| 一区二区三区四区乱视频| 亚洲精品国产精华液| 亚洲综合免费观看高清完整版| 亚洲激情图片一区| 亚洲成人免费在线观看| 亚洲国产日日夜夜| 全国精品久久少妇| 国产呦萝稀缺另类资源| 韩日av一区二区| 国产成人免费av在线| aaa欧美大片| 欧美日韩国产高清一区二区三区| 欧美日本在线观看| 精品国产一区二区亚洲人成毛片| 国产无人区一区二区三区| 日韩理论在线观看| 亚洲综合在线免费观看| 日产欧产美韩系列久久99| 国产美女精品人人做人人爽| 国产91高潮流白浆在线麻豆| 99国产一区二区三精品乱码| 欧美性一二三区| 91麻豆精品久久久久蜜臀| 久久综合久久99| 国产精品国产自产拍高清av王其| 亚洲精品一二三| 日本欧美在线观看| 国产suv精品一区二区883| 色狠狠综合天天综合综合| 日韩西西人体444www| 国产精品视频在线看| 亚洲va欧美va人人爽| 国产不卡视频在线播放| 欧美三电影在线| 久久久精品黄色| 亚洲在线成人精品| 国产精品911| 欧美精品在线观看播放| 中文字幕av免费专区久久| 丝瓜av网站精品一区二区| 成人一区二区三区视频在线观看| 欧美伊人精品成人久久综合97 | 成人免费观看视频| 欧美日韩一区成人| 日本一区二区三区久久久久久久久不 | 亚洲黄色av一区| 精品一区二区在线观看| 91捆绑美女网站| 精品国产91亚洲一区二区三区婷婷 | 精品一区二区三区免费视频| 色综合久久久网| 国产色婷婷亚洲99精品小说| 日韩av一区二区在线影视| 成人激情电影免费在线观看| 日韩午夜中文字幕| 亚洲国产精品天堂| 成人性色生活片| 精品日韩一区二区三区 | 成人一区在线观看| 日韩一本二本av| 亚洲福利视频一区| 成人国产精品免费网站| 精品国产一区二区三区忘忧草 | 91麻豆精品国产| 亚洲欧美激情插| 成人国产亚洲欧美成人综合网| 日韩精品中文字幕一区二区三区 | 亚洲欧洲日产国码二区| 国产一区二区三区在线观看免费视频 | 国产午夜精品久久| 久久99在线观看| 在线电影院国产精品| 一区二区三区四区不卡视频| 成人爱爱电影网址| 国产欧美日韩三区| 国产老女人精品毛片久久| 日韩免费看的电影| 日韩电影在线免费看| 欧美日韩精品一区二区天天拍小说| 中文字幕一区二区三区在线播放 | 国产精品18久久久久久久久| 欧美成人高清电影在线| 玖玖九九国产精品| 日韩欧美在线综合网| 日韩av不卡一区二区| 欧美一区二区三区的| 日韩国产精品大片| 91精品国产色综合久久ai换脸| 亚洲v日本v欧美v久久精品| 精品视频123区在线观看| 亚洲国产精品综合小说图片区| 日本国产一区二区| 亚洲午夜一区二区三区| 欧美性欧美巨大黑白大战| 亚洲成人动漫精品| 欧美年轻男男videosbes| 日韩激情av在线| 精品黑人一区二区三区久久| 国产一区二区在线看| 欧美激情一区不卡| eeuss鲁片一区二区三区在线看 | 韩国av一区二区三区四区 | 日韩理论片网站| 欧洲视频一区二区| 五月婷婷综合激情| 日韩欧美一区在线观看| 狠狠色丁香婷婷综合| 久久久国产精华| hitomi一区二区三区精品| 一区二区三区欧美视频| 宅男在线国产精品| 国产精品99久久久久久宅男| 国产精品久久久久久久久搜平片| 一本一道久久a久久精品 | 精品处破学生在线二十三| 高清视频一区二区| 亚洲免费在线看| 欧美日韩一区在线观看| 久久国产精品色婷婷| 国产欧美日韩精品一区| 欧洲国内综合视频| 美女精品自拍一二三四| 久久九九99视频| 色女孩综合影院| 免费观看成人av| 亚洲欧洲精品一区二区精品久久久 | 亚洲美女视频一区| 制服丝袜中文字幕亚洲| 国产精选一区二区三区| 亚洲视频在线观看三级| 欧美精品乱码久久久久久| 国产乱一区二区| 亚洲国产精品一区二区久久恐怖片 | 91理论电影在线观看| 免费观看久久久4p| 亚洲青青青在线视频| 欧美一区二区三区成人| 99视频有精品| 看片的网站亚洲| 亚洲激情网站免费观看| 久久理论电影网| 欧美挠脚心视频网站| 成人在线综合网| 久久超碰97人人做人人爱| 亚洲欧美综合在线精品| 日韩免费福利电影在线观看| 91在线精品秘密一区二区| 在线中文字幕一区| 国产一区二区不卡| 亚洲成人午夜影院| 国产精品国产成人国产三级| 欧美一级二级三级蜜桃| 91精彩视频在线| 国产99久久久精品| 秋霞午夜鲁丝一区二区老狼| 亚洲精品伦理在线| 欧美高清在线一区二区|