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
import org.jitsi.service.packetlogging.*;
/**
* RTPConnectorInputStream implementation for UDP protocol.
*
* @author Sebastien Vincent
*/
public class RTPConnectorUDPInputStream
extends RTPConnectorInputStream
{
/**
* UDP socket used to receive data.
*/
private final DatagramSocket socket;
/**
* Receive size configured flag.
*/
private boolean receivedSizeFlag = false;
/**
* Initializes a new <tt>RTPConnectorInputStream</tt> which is to receive
* packet data from a specific UDP socket.
*
* @param socket the UDP socket the new instance is to receive data from
*/
public RTPConnectorUDPInputStream(DatagramSocket socket)
{
this.socket = socket;
if(socket != null)
{
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)
{
socket.close();
}
}
/**
* 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 MultiplexingDatagramSocket)
return;
PacketLoggingService packetLogging = LibJitsi.getPacketLoggingService();
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
if (packetLogging != null)
packetLogging.logPacket(
PacketLoggingService.ProtocolName.RTP,
p.getAddress().getAddress(),
p.getPort(),
socket.getLocalAddress().getAddress(),
socket.getLocalPort(),
PacketLoggingService.TransportName.UDP,
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
{
if(!receivedSizeFlag)
{
receivedSizeFlag = true;
try
{
socket.setReceiveBufferSize(65535);
}
catch(Throwable t)
{
}
}
socket.receive(p);
}
}