FileDocCategorySizeDatePackage
RTPSocketPlayer.javaAPI DocJMF 2.1.1e9396Mon May 12 12:20:28 BST 2003None

RTPSocketPlayer

public class RTPSocketPlayer extends Object implements ControllerListener

Fields Summary
String
address
int
port
String
media
RTPSocket
rtpsocket
RTPPushDataSource
rtcpsource
Player
player
private int
maxsize
UDPHandler
rtp
UDPHandler
rtcp
Constructors Summary
public RTPSocketPlayer()

      
      
        // create the RTPSocket
        rtpsocket = new RTPSocket();
       
        // set its content type : 
        // rtpraw/video for a video session 
        // rtpraw/audio for an audio session
        String content = "rtpraw/" + media;
        rtpsocket.setContentType(content);
        
        // set the RTP Session address and port of the RTP data
        rtp = new UDPHandler(address, port);
        
        // set the above UDP Handler to be the 
        // sourcestream of the rtpsocket
        rtpsocket.setOutputStream(rtp);
        
        // set the RTP Session address and port of the RTCP data
        rtcp = new UDPHandler(address, port +1);
        
        // get a handle over the RTCP Datasource so that we can 
        // set the sourcestream and deststream of this source 
        // to the rtcp udp handler we created above.
        rtcpsource = rtpsocket.getControlChannel();
        
        // Since we intend to send RTCP packets from the         
        // network to the session manager and vice-versa, we need
        // to set the RTCP UDP handler as both the input and output 
        // stream of the rtcpsource.
        rtcpsource.setOutputStream(rtcp);
        rtcpsource.setInputStream(rtcp);
        
        // connect the RTP socket data source before 
        // creating the player
        try {
            rtpsocket.connect();
            player = Manager.createPlayer(rtpsocket);
            // rtpsocket.start();
        } catch (NoPlayerException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            return;
        }
        catch (IOException e) {
            System.err.println(e.getMessage());
            e.printStackTrace();
            return;
        }

        if (player != null) {
            player.addControllerListener(this);
            // send this player to out playerwindow
            // playerWindow = new PlayerWindow(player);
        }
    
Methods Summary
private java.net.DatagramSocketInitSocket(java.lang.String sockaddress, int sockport)

        InetAddress addr = null;
        DatagramSocket sock = null;

        try {
            addr = InetAddress.getByName(sockaddress);
            
            if (addr.isMulticastAddress()) {
                MulticastSocket msock = new MulticastSocket(sockport);
                msock.joinGroup(addr);
                sock = (DatagramSocket)msock;           
            } 
            else {              
                sock = new DatagramSocket(sockport,addr);
            }
            
            return sock;
        }
        catch (SocketException e) {
            e.printStackTrace();
            return null;
        }
        catch (UnknownHostException e) {
            e.printStackTrace();
            return null;
        }
        catch (IOException e) {
            e.printStackTrace();
            return null;
        }
    
public synchronized voidcontrollerUpdate(javax.media.ControllerEvent ce)

        if ((ce instanceof DeallocateEvent) ||
            (ce instanceof ControllerErrorEvent)) {
        
            // stop udp handlers
            if (rtp != null) rtp.close();
            
            if (rtcp != null) rtcp.close();
        }
    
public static voidmain(java.lang.String[] args)

        new RTPSocketPlayer();