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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? mediamanager.java

?? 是一個用java實現的
?? 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) {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
亚洲一区二区三区激情| 欧美激情在线看| 欧美一区二区三区男人的天堂| 欧美疯狂性受xxxxx喷水图片| 51精品国自产在线| 26uuu久久天堂性欧美| 国产三区在线成人av| 综合在线观看色| 丝袜脚交一区二区| 极品尤物av久久免费看| 久久99国产精品久久99果冻传媒| 国产麻豆精品视频| 男男成人高潮片免费网站| 国产精品少妇自拍| 国产精品乱人伦中文| 日韩av不卡一区二区| 韩国精品在线观看| 不卡的av在线播放| 欧美性色黄大片| 亚洲主播在线观看| 精品久久久久久久久久久久久久久| 欧美中文字幕不卡| 6080亚洲精品一区二区| 精品不卡在线视频| 亚洲欧美成人一区二区三区| 丝袜美腿亚洲综合| 国产精品一区二区久久不卡| 99国产麻豆精品| 日韩视频一区二区| 中文字幕一区二区三区精华液| 亚洲一卡二卡三卡四卡| 国产成人综合亚洲91猫咪| 色噜噜狠狠色综合欧洲selulu| 欧美mv和日韩mv的网站| 亚洲男人天堂av网| 久久99精品久久久久久久久久久久| 色婷婷国产精品久久包臀| 精品国产三级a在线观看| 亚洲美女一区二区三区| 亚洲chinese男男1069| 粉嫩绯色av一区二区在线观看| 欧美日韩视频专区在线播放| 亚洲欧洲日本在线| 国产麻豆91精品| 欧美疯狂性受xxxxx喷水图片| 亚洲欧美日韩国产中文在线| 欧美一区二区三区免费| 亚洲人123区| 成人福利视频在线| www日韩大片| 亚洲日本va在线观看| 国产传媒欧美日韩成人| 91精品福利在线一区二区三区| 国产偷v国产偷v亚洲高清| 男人的j进女人的j一区| 欧美亚洲高清一区二区三区不卡| 久久精品视频在线免费观看| 免费xxxx性欧美18vr| 在线免费不卡视频| 有码一区二区三区| 成av人片一区二区| 国产女人水真多18毛片18精品视频 | 欧美色图一区二区三区| 国产欧美精品日韩区二区麻豆天美| 秋霞午夜av一区二区三区| 91福利社在线观看| 国产精品国模大尺度视频| 国产精品一二三四| 精品国产乱码久久久久久久久| 日韩综合小视频| 欧美日韩精品三区| 亚洲成人在线网站| 在线看国产日韩| 亚洲成人av在线电影| 在线免费观看一区| 亚洲免费观看视频| 在线精品视频一区二区| 一区av在线播放| 97国产一区二区| 国产精品女主播av| 成人永久看片免费视频天堂| 精品av久久707| 久久国产人妖系列| 精品久久久久99| 精品无人码麻豆乱码1区2区| 日韩免费高清av| 蜜臀av性久久久久蜜臀aⅴ| 制服丝袜亚洲色图| 亚洲综合在线电影| 88在线观看91蜜桃国自产| 五月综合激情网| 欧美亚洲图片小说| 视频在线观看一区| 日韩欧美在线不卡| 午夜精品一区二区三区电影天堂| 欧美色图在线观看| 三级欧美韩日大片在线看| 日韩欧美国产成人一区二区| 久久成人精品无人区| 国产亚洲欧美激情| 91小视频在线免费看| 一片黄亚洲嫩模| 91麻豆精品国产无毒不卡在线观看| 激情久久久久久久久久久久久久久久| 日韩欧美另类在线| 国产最新精品免费| 久久精品一区八戒影视| 成人黄色在线视频| 亚洲综合网站在线观看| 4hu四虎永久在线影院成人| 国产成人av福利| 亚洲人午夜精品天堂一二香蕉| 在线看国产一区| 狠狠色狠狠色综合系列| 国产精品欧美久久久久无广告 | 777色狠狠一区二区三区| 久久国产精品第一页| 国产日韩欧美精品电影三级在线| 99久久综合精品| 日韩高清在线电影| 国产亚洲欧美中文| 91传媒视频在线播放| 久久丁香综合五月国产三级网站| 国产精品午夜春色av| 91成人看片片| 激情六月婷婷综合| 亚洲精品中文在线观看| 8x8x8国产精品| 成人毛片视频在线观看| 亚洲国产美国国产综合一区二区| 欧美午夜精品久久久久久孕妇| 亚洲mv在线观看| 国产日产欧美一区二区视频| 欧美亚洲免费在线一区| 国产在线乱码一区二区三区| 综合欧美一区二区三区| 欧美高清激情brazzers| 极品尤物av久久免费看| 国产精品久久久久久久久快鸭| 精品久久99ma| 久久精品国产秦先生| 一区二区在线免费观看| 久久嫩草精品久久久精品| 欧美电影在线免费观看| 91国偷自产一区二区开放时间| 国产成都精品91一区二区三| 另类综合日韩欧美亚洲| 亚洲大片一区二区三区| 亚洲美女在线一区| 国产精品久久久久久亚洲毛片| 精品久久五月天| 欧美精三区欧美精三区| 色欧美片视频在线观看在线视频| 国产乱码精品一区二区三区五月婷| 日韩vs国产vs欧美| 一区二区国产视频| 最新国产の精品合集bt伙计| 久久五月婷婷丁香社区| 日韩午夜激情视频| 精品视频999| 欧美中文一区二区三区| 色婷婷av一区二区三区gif| 99视频精品在线| 成人高清免费观看| 国产91清纯白嫩初高中在线观看| 精品一区二区精品| 热久久久久久久| 日韩电影网1区2区| 亚洲gay无套男同| 亚洲电影一区二区三区| 夜夜嗨av一区二区三区中文字幕 | 国产成人在线观看免费网站| 久久精品国产成人一区二区三区| 午夜不卡在线视频| 午夜亚洲福利老司机| 亚洲18影院在线观看| 亚洲一二三区在线观看| 午夜视频久久久久久| 香蕉成人啪国产精品视频综合网| 亚洲国产一区在线观看| 亚洲国产一二三| 亚洲午夜激情av| 婷婷夜色潮精品综合在线| 午夜精品在线视频一区| 日韩国产一区二| 日本va欧美va瓶| 精品亚洲成a人在线观看| 国产一区二区三区四区五区美女 | 国产欧美日韩在线观看| 欧美国产一区视频在线观看| 中文字幕av不卡| 中文字幕一区二区三区在线不卡| 国产精品久久99| 亚洲精品视频一区| 亚洲资源在线观看| 日欧美一区二区| 国产尤物一区二区在线| 粉嫩蜜臀av国产精品网站| 91免费看视频| 欧美精品v国产精品v日韩精品 |