Newer
Older
/*
* Jitsi, the OpenSource Java VoIP and Instant Messaging client.
*
* Distributable under LGPL license.
* See terms of license at gnu.org.
*/
package org.jitsi.impl.neomedia;
import java.io.*;
import java.net.*;

Lyubomir Marinov
committed
import org.ice4j.socket.*;
import org.jitsi.service.libjitsi.*;
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import org.jitsi.service.packetlogging.*;
import org.jitsi.util.*;
/**
* RTPConnectorInputStream implementation for TCP protocol.
*
* @author Sebastien Vincent
*/
public class RTPConnectorTCPInputStream
extends RTPConnectorInputStream
{
/**
* The <tt>Logger</tt> used by instances for logging output.
*/
private static final Logger logger
= Logger.getLogger(RTPConnectorTCPInputStream.class);
/**
* TCP socket used to receive data.
*/
private final Socket socket;
/**
* Initializes a new <tt>RTPConnectorInputStream</tt> which is to receive
* packet data from a specific TCP socket.
*
* @param socket the TCP socket the new instance is to receive data from
*/
public RTPConnectorTCPInputStream(Socket socket)
{
this.socket = socket;
if(socket != null)
{
try
{
socket.setReceiveBufferSize(65535);
}
catch(Throwable t)
{
}
closed = false;
receiverThread = new Thread(this);
receiverThread.start();
}
}
/**
* Close this stream, stops the worker thread.
*/
@Override
public synchronized void close()
{
closed = true;
if(socket != null)
{
try
{
socket.close();
}
catch(IOException e)
{
}
}
}
/**
* Log the packet.
*
* @param p packet to log
*/
protected void doLogPacket(DatagramPacket p)
{
if(socket.getLocalAddress() == null)
return;

Lyubomir Marinov
committed
// Do not log the packet if this one has been processed (and already
// logged) by the ice4j stack.
if(socket instanceof MultiplexingSocket)
return;
PacketLoggingService packetLogging = LibJitsi.getPacketLoggingService();
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
if (packetLogging != null)
packetLogging.logPacket(
PacketLoggingService.ProtocolName.RTP,
(p.getAddress() != null)
? p.getAddress().getAddress()
: new byte[] { 0,0,0,0 },
p.getPort(),
socket.getLocalAddress().getAddress(),
socket.getLocalPort(),
PacketLoggingService.TransportName.TCP,
false,
p.getData(),
p.getOffset(),
p.getLength());
}
/**
* Receive packet.
*
* @param p packet for receiving
* @throws IOException if something goes wrong during receiving
*/
protected void receivePacket(DatagramPacket p)
throws IOException
{
int len = -1;
byte data[] = null;
try
{
data = p.getData();
len = socket.getInputStream().read(data);
}
catch(Exception e)
{
logger.info("problem read: " + e);
}
if(len > 0)
{
p.setData(data);
p.setLength(len);
p.setAddress(socket.getInetAddress());
p.setPort(socket.getPort());
}
else
{
throw new IOException("Failed to read on TCP socket");
}
}
}