src/org/sipdroid/net/RtpSocket.java
changeset 835 4e40f3481f23
parent 834 e8d6255306f8
equal deleted inserted replaced
834:e8d6255306f8 835:4e40f3481f23
    17  * You should have received a copy of the GNU General Public License
    17  * You should have received a copy of the GNU General Public License
    18  * along with this source code; if not, write to the Free Software
    18  * along with this source code; if not, write to the Free Software
    19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    20  */
    20  */
    21 
    21 
    22 package src.org.sipdroid.net;
    22 package org.sipdroid.net;
    23 
    23 
    24 import java.net.InetAddress;
    24 import java.net.InetAddress;
    25 import java.net.DatagramPacket;
    25 import java.net.DatagramPacket;
    26 import java.io.IOException;
    26 import java.io.IOException;
    27 
    27 
    32  * <p>
    32  * <p>
    33  * RtpSocket is associated to a DatagramSocket that is used to send and/or
    33  * RtpSocket is associated to a DatagramSocket that is used to send and/or
    34  * receive RtpPackets.
    34  * receive RtpPackets.
    35  */
    35  */
    36 public class RtpSocket {
    36 public class RtpSocket {
    37 	/** UDP socket */
    37     /** UDP socket */
    38 	SipdroidSocket socket;
    38     SipdroidSocket socket;
    39 	DatagramPacket datagram;
    39     DatagramPacket datagram;
    40 	
       
    41 	/** Remote address */
       
    42 	InetAddress r_addr;
       
    43 
    40 
    44 	/** Remote port */
    41     /** Remote address */
    45 	int r_port;
    42     InetAddress r_addr;
    46 
    43 
    47 	/** Creates a new RTP socket (only receiver) */
    44     /** Remote port */
    48 	public RtpSocket(SipdroidSocket datagram_socket) {
    45     int r_port;
    49 		socket = datagram_socket;
       
    50 		r_addr = null;
       
    51 		r_port = 0;
       
    52 		datagram = new DatagramPacket(new byte[1],1);
       
    53 	}
       
    54 
    46 
    55 	/** Creates a new RTP socket (sender and receiver) */
    47     /** Creates a new RTP socket (only receiver) */
    56 	public RtpSocket(SipdroidSocket datagram_socket,
    48     public RtpSocket(SipdroidSocket datagram_socket) {
    57 			InetAddress remote_address, int remote_port) {
    49 	socket = datagram_socket;
    58 		socket = datagram_socket;
    50 	r_addr = null;
    59 		r_addr = remote_address;
    51 	r_port = 0;
    60 		r_port = remote_port;
    52 	datagram = new DatagramPacket(new byte[1],1);
    61 		datagram = new DatagramPacket(new byte[1],1);
    53     }
    62 	}
       
    63 
    54 
    64 	/** Returns the RTP SipdroidSocket */
    55     /** Creates a new RTP socket (sender and receiver) */
    65 	public SipdroidSocket getDatagramSocket() {
    56     public RtpSocket(SipdroidSocket datagram_socket,
    66 		return socket;
    57 	InetAddress remote_address, int remote_port) {
    67 	}
    58 	socket = datagram_socket;
       
    59 	r_addr = remote_address;
       
    60 	r_port = remote_port;
       
    61 	datagram = new DatagramPacket(new byte[1],1);
       
    62     }
    68 
    63 
    69 	/** Receives a RTP packet from this socket */
    64     /** Returns the RTP SipdroidSocket */
    70 	public void receive(RtpPacket rtpp) throws IOException {
    65     public SipdroidSocket getDatagramSocket() {
    71 		datagram.setData(rtpp.packet);
    66 	return socket;
    72 		datagram.setLength(rtpp.packet.length);
    67     }
    73 		socket.receive(datagram);
       
    74 		if (!socket.isConnected())
       
    75 			socket.connect(datagram.getAddress(),datagram.getPort());
       
    76 		rtpp.packet_len = datagram.getLength();
       
    77 	}
       
    78 
    68 
    79 	/** Sends a RTP packet from this socket */
    69     /** Receives a RTP packet from this socket */
    80 	public void send(RtpPacket rtpp) throws IOException {
    70     public void receive(RtpPacket rtpp) throws IOException {
    81 		datagram.setData(rtpp.packet);
    71 	datagram.setData(rtpp.packet);
    82 		datagram.setLength(rtpp.packet_len);
    72 	datagram.setLength(rtpp.packet.length);
    83 		datagram.setAddress(r_addr);
    73 	socket.receive(datagram);
    84 		datagram.setPort(r_port);
    74 	if (!socket.isConnected())
    85 		socket.send(datagram);
    75 	    socket.connect(datagram.getAddress(),datagram.getPort());
    86 	}
    76 	rtpp.packet_len = datagram.getLength();
       
    77     }
    87 
    78 
    88 	/** Closes this socket */
    79     /** Sends a RTP packet from this socket */
    89 	public void close() { // socket.close();
    80     public void send(RtpPacket rtpp) throws IOException {
    90 	}
    81 	datagram.setData(rtpp.packet);
       
    82 	datagram.setLength(rtpp.packet_len);
       
    83 	datagram.setAddress(r_addr);
       
    84 	datagram.setPort(r_port);
       
    85 	socket.send(datagram);
       
    86     }
       
    87 
       
    88     /** Closes this socket */
       
    89     public void close() { // socket.close();
       
    90     }
    91 
    91 
    92 }
    92 }