📄 mediamanager.java
字号:
else if (jmfFormat.equals(AudioFormat.ULAW_RTP)) {
return Integer.toString(SdpConstants.PCMU);
}
else if (jmfFormat.equals(AudioFormat.GSM_RTP)) {
return Integer.toString(SdpConstants.GSM);
}
else if (jmfFormat.equals(AudioFormat.G723_RTP)) {
return Integer.toString(SdpConstants.G723);
}
else if (jmfFormat.equals(AudioFormat.DVI_RTP)) {
return Integer.toString(SdpConstants.DVI4_8000);
}
else if (jmfFormat.equals(AudioFormat.DVI_RTP)) {
return Integer.toString(SdpConstants.DVI4_16000);
}
else if (jmfFormat.equals(AudioFormat.ALAW)) {
return Integer.toString(SdpConstants.PCMA);
}
else if (jmfFormat.equals(AudioFormat.G728_RTP)) {
return Integer.toString(SdpConstants.G728);
}
else if (jmfFormat.equals(AudioFormat.G729_RTP)) {
return Integer.toString(SdpConstants.G729);
}
else if (jmfFormat.equals(VideoFormat.H263_RTP)) {
return Integer.toString(SdpConstants.H263);
}
else if (jmfFormat.equals(VideoFormat.JPEG_RTP)) {
return Integer.toString(SdpConstants.JPEG);
}
else if (jmfFormat.equals(VideoFormat.H261_RTP)) {
return Integer.toString(SdpConstants.H261);
}
else {
return null;
}
}
/**
* @param sdpFormats
* @return
* @throws MediaException
*/
protected ArrayList extractTransmittableJmfFormats(Vector sdpFormats) throws
MediaException
{
try {
ArrayList jmfFormats = new ArrayList();
for (int i = 0; i < sdpFormats.size(); i++) {
int sdpFormat = -1;
String jmfFormat =
findCorrespondingJmfFormat(sdpFormats.elementAt(i).toString());
if (jmfFormat != null) {
jmfFormats.add(jmfFormat);
}
}
if (jmfFormats.size() == 0) {
throw new MediaException(
"None of the supplied sdp formats for is supported by SIP COMMUNICATOR");
}
return jmfFormats;
}
finally {
}
}
//This is the data source that we'll be using to transmit
//let's see what can it do
protected void initProcessor(DataSource dataSource) throws MediaException
{
try {
try {
try {
dataSource.connect();
}
//Thrown when operation is not supported by the OS
catch (NullPointerException ex) {
throw new MediaException(
"An internal error occurred while"
+ " trying to connec to to datasource!", ex);
}
processor = Manager.createProcessor(dataSource);
procUtility.waitForState(processor, Processor.Configured);
}
catch (NoProcessorException ex) {
throw new MediaException(
"Media manager could not create a processor\n"
+ "for the specified data source", ex);
}
catch (IOException ex) {
throw new MediaException("Media manager could not connect "
+ "to the specified data source", ex);
}
processor.setContentDescriptor(new ContentDescriptor(
ContentDescriptor.RAW_RTP));
TrackControl[] trackControls = processor.getTrackControls();
for (int i = 0; i < trackControls.length; i++) {
Format[] formats = trackControls[i].getSupportedFormats();
for (int j = 0; j < formats.length; j++) {
Format format = formats[j];
String encoding = format.getEncoding();
if (format instanceof AudioFormat) {
String sdp = findCorrespondingSdpFormat(encoding);
if (sdp != null
&& !transmittableAudioFormats.contains(sdp)) {
transmittableAudioFormats.add(sdp);
}
}
if (format instanceof VideoFormat) {
String sdp = findCorrespondingSdpFormat(encoding);
if (sdp != null
&& !transmittableVideoFormats.contains(sdp)) {
transmittableVideoFormats.add(sdp);
}
}
}
}
}
finally {
}
}
/*
protected static MediaManager mman;
public static void main(String[] args)
throws Throwable
{
mman = new MediaManager();
System.setProperty("net.java.mais.media.MEDIA_SOURCE","file://home/emcho/lostinspace.mov");
System.setProperty("net.java.mais.media.VIDEO_PORT","44444");
System.setProperty("net.java.mais.media.AUDIO_PORT","44446");
System.setProperty("net.java.mais.media.IP_ADDRESS","2001:660:220:102:230:5ff:fe1a:805f");
mman.start();
String sdp =
"v=0" + "\r\n" +
"o=Emcho 0 0 IN IP4 130.79.90.142" + "\r\n" +
"s=-" + "\r\n" +
"c=IN IP4 2001:660:220:102:230:5ff:fe2a:77c1" + "\r\n" +
"t=2208988800 2208988800" + "\r\n" +
"m=video 22222 RTP/AVP 20 26 31" + "\r\n" +
"m=audio 22224 RTP/AVP 3 0 4 5 6 8 15 18" + "\r\n"
;
mman.openMediaStreams(sdp);
javax.swing.JFrame frame = new javax.swing.JFrame("Close & Exit");
frame.addWindowListener(new java.awt.event.WindowAdapter(){
public void windowClosing(java.awt.event.WindowEvent evt)
{
try {
mman.stop();
}
catch (MediaException ex) {
ex.printStackTrace();
}
System.exit(0);
}
});
frame.show();
}
protected void writeObject(ObjectOutputStream oos) throws IOException
{
oos.defaultWriteObject();
}
protected void readObject(ObjectInputStream ois) throws ClassNotFoundException, IOException
{
ois.defaultReadObject();
}
*/
/**
* Returns a cached instance of an RtpManager bound on the specified local
* address. If no such instance exists null is returned.
* @param localAddress the address where the rtp manager must be bound locally.
* @return an rtp manager bound on the specified address or null if such an
* instance was not found.
*/
synchronized RTPManager getRtpManager(SessionAddress localAddress)
{
return (RTPManager)activeRtpManagers.get(localAddress);
}
/**
* Maps the specified rtp manager against the specified local address so
* that it may be later retrieved in case someone wants to operate
* (transmit/receive) on the same port.
* @param localAddress the address where the rtp manager is bound
* @param rtpManager the rtp manager itself
*/
synchronized void putRtpManager(SessionAddress localAddress, RTPManager rtpManager)
{
activeRtpManagers.put(localAddress, rtpManager);
}
/**
* Removes all rtp managers from the rtp manager cache.
*/
synchronized void removeAllRtpManagers()
{
Enumeration rtpManages = activeRtpManagers.keys();
while (rtpManages.hasMoreElements()) {
SessionAddress item = (SessionAddress)rtpManages.nextElement();
activeRtpManagers.remove(item);
}
}
/**
* Moves formats with the specified encoding to the top of the array list
* so that they are the ones chosen for transmission (if supported by the
* remote party) (feature request by Vince Fourcade)
*/
protected void surfacePreferredEncodings(String[] formats)
{
try {
String preferredAudioEncoding =
Utils.getProperty(
"net.java.mais.media.PREFERRED_AUDIO_ENCODING");
String preferredVideoEncoding =
Utils.getProperty(
"net.java.mais.media.PREFERRED_VIDEO_ENCODING");
if (preferredAudioEncoding == null
&& preferredVideoEncoding == null) {
return;
}
for (int i = 0; i < formats.length; i++) {
String encoding = formats[i];
if ( (preferredAudioEncoding != null
&& encoding.equalsIgnoreCase(preferredAudioEncoding))
|| (preferredVideoEncoding != null
&& encoding.equalsIgnoreCase(preferredVideoEncoding))) {
formats[i] = formats[0];
formats[0] = encoding;
break;
}
}
}
finally {
}
}
/**
* Runs JMFInit the first time the application is started so that capture
* devices are properly detected and initialized by JMF.
* @throws MediaException if an exception occurs during the detection.
*/
public static void setupJMF()
throws MediaException
{
try
{
//.jmf is the place where we store the jmf.properties file used
//by JMF. if the directory does not exist or it does not contain
//a jmf.properties file. or if the jmf.properties file has 0 length
//then this is the first time we're running and should continue to
//with JMFInit
String homeDir = System.getProperty("user.home");
File jmfDir = new File(homeDir, ".jmf");
String classpath = System.getProperty("java.class.path");
classpath += System.getProperty("path.separator") +
jmfDir.getAbsolutePath();
System.setProperty("java.class.path", classpath);
if (!jmfDir.exists())
jmfDir.mkdir();
File jmfProperties = new File(jmfDir, "jmf.properties");
if (!jmfProperties.exists()) {
try {
jmfProperties.createNewFile();
}
catch (IOException ex) {
throw new MediaException(
"Failed to create jmf.properties - " +
jmfProperties.getAbsolutePath());
}
}
//if we're running on linux checkout that libjmutil.so is where it
//should be and put it there.
runLinuxPreInstall();
System.out.println("DETECT!!!");
boolean tmp = false;
if(PropertiesDepot.getProperty("net.java.mais.FIRST_LAUNCH")!=null)
if(PropertiesDepot.getProperty("net.java.mais.FIRST_LAUNCH").equals("true"))
tmp = true;
if (jmfProperties.length() == 0||tmp/*||true*/){
JMFInit.start();
}
}
finally
{
}
}
private static void runLinuxPreInstall()
{
try {
if( Utils.getProperty("os.name") == null
|| !Utils.getProperty("os.name").equalsIgnoreCase("Linux"))
return;
try {
System.loadLibrary("jmv4l");
}
catch (UnsatisfiedLinkError err) {
String destinationPathStr = Utils.getProperty("java.home")
+ File.separator + "lib"
+ File.separator + "i386";
String libjmutilFileStr = "libjmutil.so";
try {
InputStream libIS =
MediaManager.class.getClassLoader().
getResourceAsStream(libjmutilFileStr);
File outFile = new File(destinationPathStr
+File.separator + libjmutilFileStr);
//Check if file is already there - Ben Asselstine
if (outFile.exists()) {
//if we're here then libjmutil is already where it should be
// but yet we failed to load libjmv4l.
//so notify log and bail out
return;
}
outFile.createNewFile();
FileOutputStream fileOS = new FileOutputStream(outFile);
int available = libIS.available();
byte[] bytes = new byte[libIS.available()];
int read = 0;
int i = 0;
for (i = 0; i<available ; i++)
{
bytes[i] = (byte)libIS.read();
}
fileOS.write(bytes, 0, bytes.length);
bytes = null;
libIS.close();
fileOS.close();
}
catch (IOException exc) {
if( exc.getMessage() != null
&& exc.getMessage().toLowerCase().indexOf("permission denied") != -1)
exc.printStackTrace();
}
}
/** @todo check whether we have a permissions problem and alert the
* user that they should be running as root */
catch(Throwable t)
{
}
}
finally {
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -