ratlauncher.java

来自「结构非常清晰的SIP协议栈」· Java 代码 · 共 88 行

JAVA
88
字号
package local.ua;


import local.net.UdpRelay;
import org.zoolu.sip.provider.SipStack;
import org.zoolu.tools.Log;
import org.zoolu.tools.LogLevel;
//import tools.Parser;

//import java.util.Iterator;
//import java.util.Vector;
//import java.io.*;


/** RAT launcher */
public class RATLauncher implements MediaLauncher
{
   /** Event logger. */
   Log log=null;

   /** Runtime media process (RAT application) */
   Process media_process=null;
   
   int localport;
   int remoteport;
   String remoteaddr;
   
   /** Media application command */
   String command;

   /** Costructs the RAT launcher 
     * <p> <i>attributes</i> is a Vector of the sdp media attributes */
   public  RATLauncher(String rat_comm, int local_port, String remote_addr, int remote_port, Log logger)
   {  log=logger;
      command=rat_comm;
      localport=local_port;
      remoteport=remote_port;
      remoteaddr=remote_addr;
   }

   /** Starts media application */
   public boolean startMedia()
   {  // udp flow adaptation for RAT application
      if (localport!=remoteport) 
      {  printLog("UDP local relay: src_port="+localport+", dest_port="+remoteport);
         printLog("UDP local relay: src_port="+(localport+1)+", dest_port="+(remoteport+1));
         new UdpRelay(localport,"127.0.0.1",remoteport,null);
         new UdpRelay(localport+1,"127.0.0.1",remoteport+1,null);  
      }
      else
      {  printLog("local_port==remote_port --> no UDP relay is needed");
      }

      //debug...
      printLog("launching RAT-Audio...");

      String cmds[] = {"","",""};
      cmds[0] = command;
      cmds[1] = remoteaddr+"/"+remoteport;

      // try to start the RAT
      try
      {  media_process=Runtime.getRuntime().exec(cmds);
         return true;
      }
      catch (Exception e)
      {  e.printStackTrace();
         return false;
      }          
   }

   /** Stops media application */
   public boolean stopMedia()
   {  if (media_process!=null) media_process.destroy();
      return true;
   }


   // ****************************** Logs *****************************

   /** Adds a new string to the default Log */
   private void printLog(String str)
   {  if (log!=null) log.println("RATLauncher: "+str,SipStack.LOG_LEVEL_UA+LogLevel.HIGH);  
      //if (LOG_LEVEL<=LogLevel.HIGH) System.out.println("RATLauncher: "+str);
      System.out.println("RATLauncher: "+str);
   }
      
}

⌨️ 快捷键说明

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