2012-09-28 57 views
8

我是使用RTP進行SIP呼叫的新手,現在我嘗試使用RTP爲sip呼叫發送和接收 語音流。我完成了連接 兩個模擬器,並能夠使用jain sip發送INVITE和INVITE-ACK。如何使用RTP發送和接收語音流

我得到了一個確認我要開始RTP媒體流之後,我用的是RtpPacket 函數來發送和接收

我用RtpFunction與所有RTP報頭這樣的發送媒體:

byte Version; 
boolean Padding; 
boolean Extension; 
byte CC; 
boolean Marker; 
byte PayloadType; 
short SequenceNumber; 
int TimeStamp; 

請給我一些想法和實際的鏈接,我可以找到答案。

+1

嘿,夥計們,請給我一些想法如何可能發送語音流使用RTP SIP SIP,我正在嘗試與Sipdroid RTPsender和接收機類,但沒有成功.. – Satyam

回答

2
*We send and receive RTP data using RTPpacket. 

    import javax.media.rtp.*; 
    import javax.media.rtp.rtcp.*; 
    import javax.media.rtp.event.*; 
    import javax.media.*; 
    import javax.media.protocol.*; 
    import java.net.InetAddress; 
    import javax.media.format.AudioFormat; 
    import com.sun.media.ui.*; 
    import java.util.Vector; 
    public class RTPSourceStream<RTPPlayerWindow> implements ReceiveStreamListener, 
    ControllerListener 
    { 
@SuppressWarnings("rawtypes") 
Vector playerlist = new Vector(); 
@SuppressWarnings("deprecation") 
SessionManager mgr = null; 
boolean terminatedbyClose = false; 

@SuppressWarnings("deprecation") 
public SessionManager createManager(String address, 
     String sport, 
     String sttl, 
     boolean listener, 
     boolean sendlistener) 
{ 
    return createManager(address, 
      new Integer(sport).intValue(), 
      new Integer(sttl).intValue(), 
      listener, 
      sendlistener); 
} 
@SuppressWarnings("deprecation") 
public SessionManager createManager(String address, 
     int port, 
     int ttl, 
     boolean listener, 
     boolean sendlistener) 
{ 
    mgr = (SessionManager)new com.sun.media.rtp.RTPSessionMgr(); 
    if (mgr == null) return null; 
    mgr.addFormat(new AudioFormat(AudioFormat.DVI_RTP,44100, 4,1),18); 
    if (listener) mgr.addReceiveStreamListener(this); 
    // if (sendlistener) new RTPSendStreamWindow(mgr); 
    // ask RTPSM to generate the local participants CNAME 
    String cname = mgr.generateCNAME(); 
    String username = null; 
    try { 
     username = System.getProperty("user.name"); 
    } catch (SecurityException e){ 
     username = "jmf-user"; 
    } 
     // create our local Session Address 
    SessionAddress localaddr = new SessionAddress(); 
    try{ 
     InetAddress destaddr = InetAddress.getByName(address); 
     SessionAddress sessaddr = new SessionAddress(destaddr, 
       port, 
       destaddr, 
       port + 1); 
     SourceDescription[] userdesclist= new SourceDescription[] 
                   { 
       new SourceDescription(SourceDescription 
         .SOURCE_DESC_EMAIL, 
         "[email protected]", 
         1, 
         false), 
         new SourceDescription(SourceDescription 
           .SOURCE_DESC_CNAME, 
           cname, 
           1, 
           false), 
           new 
      SourceDescription(SourceDescription.SOURCE_DESC_TOOL,"JMF RTP Player v2.0", 
             1, 
             false) }; 
     mgr.initSession(localaddr, 
       userdesclist, 
       0.05, 
       0.25); 
     mgr.startSession(sessaddr,ttl,null); 
    } catch (Exception e) { 
     System.err.println(e.getMessage()); 
     return null; 
    } 
    return mgr; 
    } 
public void update(ReceiveStreamEvent event) 
    { 
    Player newplayer = null; 
    RTPPacket playerWindow = null; 
     // find the sourceRTPSM for this event 
    SessionManager source = (SessionManager)event.getSource(); 
    // create a new player if a new recvstream is detected 
    if (event instanceof NewReceiveStreamEvent) 
    { 
     String cname = "Java Media Player"; 
     ReceiveStream stream = null; 
     try 
     { 
      // get a handle over the ReceiveStream 
      stream =((NewReceiveStreamEvent)event) 
      .getReceiveStream(); 
      Participant part = stream.getParticipant(); 
      if (part != null) cname = part.getCNAME(); 
      // get a handle over the ReceiveStream datasource 
      DataSource dsource = stream.getDataSource(); 
       // create a player by passing datasource to the 
       // Media Manager 
      newplayer = Manager.createPlayer(dsource); 
      System.out.println("created player " + newplayer); 
      } catch (Exception e) { 
      System.err.println("NewReceiveStreamEvent exception " 
        + e.getMessage()); 
      return; 
     } 
     if (newplayer == null) return; 
     playerlist.addElement(newplayer); 
     newplayer.addControllerListener(this); 
     // send this player to player GUI 
     playerWindow = new RTPPacket(newplayer, cname); 
    } 
    } 
    public void controllerUpdate(ControllerEvent evt) 
    { 
    // get a handle over controller, remove it from the player 
    // list. 
    // if player list is empty, close the sesssion manager. 
    if ((evt instanceof ControllerClosedEvent) || 
      (evt instanceof ControllerErrorEvent) || 
      (evt instanceof DeallocateEvent)){ 
     Player p = (Player)evt.getSourceController(); 
     if (!terminatedbyClose){ 
      if (playerlist.contains(p)) 
       playerlist.removeElement(p); 
      if ((playerlist.size() == 0) && (mgr != null)) 
       mgr.closeSession("All players are closed"); 
     } 
    } 
    } 
     public void closeManager() 
     { 
    terminatedbyClose = true; 
     // first close all the players 
    for (int i = 0; i < playerlist.size(); i++) { 
     ((Player)playerlist.elementAt(i)).close(); 
    } 
    if (mgr != null) { 
     mgr.closeSession("RTP Session Terminated"); 
     mgr = null; 
    } 
} 
class RTPPacket extends RTPSourceStream 
{ 
    public RTPPacket(Player newplayer, String cname) { 
     // TODO Auto-generated constructor stub 
    } 
    } 
    }* 
+1

一點點的解釋將是有益的 – totten

3

這可以以簡單的方式來實現

AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE); 
audio.setMode(AudioManager.MODE_IN_COMMUNICATION); 

audioGroup = new AudioGroup(); 
audioGroup.setMode(AudioGroup.MODE_ECHO_SUPPRESSION); 

audioStream = new AudioStream(InetAddress.getByAddress(getLocalIPAddress())); 
audioStream.setCodec(AudioCodec.PCMU); 
audioStream.setMode(RtpStream.MODE_NORMAL); 
audioStream.associate(InetAddress.getByName(SipStackAndroid.getRemoteIp()), REMOTE_PORT); 
audioStream.join(audioGroup); 

它採用JAIN SIP作爲一種信令協議,一個簡單的SIP電話的項目可以在這裏找到https://github.com/Mobicents/restcomm-android-sdk/tree/master/Examples/JAIN%20SIP