
org.jitsi.impl.neomedia.RTPConnectorUDPOutputStream Maven / Gradle / Ivy
/*
* Copyright @ 2015 Atlassian Pty Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jitsi.impl.neomedia;
import java.io.*;
import java.net.*;
import org.jitsi.service.neomedia.*;
import org.jitsi.service.packetlogging.*;
/**
* RTPConnectorOutputStream implementation for UDP protocol.
*
* @author Sebastien Vincent
*/
public class RTPConnectorUDPOutputStream
extends RTPConnectorOutputStream
{
/**
* UDP socket used to send packet data
*/
private final DatagramSocket socket;
/**
* Initializes a new RTPConnectorUDPOutputStream.
*
* @param socket a DatagramSocket
*/
public RTPConnectorUDPOutputStream(DatagramSocket socket)
{
this.socket = socket;
}
/**
* Sends a specific RawPacket through this
* OutputDataStream to a specific InetSocketAddress.
*
* @param packet the RawPacket to send through this
* OutputDataStream to the specified target
* @param target the InetSocketAddress to which the specified
* packet is to be sent through this OutputDataStream
* @throws IOException if anything goes wrong while sending the specified
* packet through this OutputDataStream to the specified
* target
*/
@Override
protected void sendToTarget(RawPacket packet, InetSocketAddress target)
throws IOException
{
socket.send(
new DatagramPacket(
packet.getBuffer(),
packet.getOffset(),
packet.getLength(),
target.getAddress(),
target.getPort()));
}
/**
* Log the packet.
*
* @param packet packet to log
*/
@Override
protected void doLogPacket(RawPacket packet, InetSocketAddress target)
{
if (socket == null || packet == null || target == null)
return;
PacketLoggingService pktLogging = getPacketLoggingService();
if (pktLogging != null)
{
pktLogging.logPacket(
PacketLoggingService.ProtocolName.RTP,
socket.getLocalAddress().getAddress(),
socket.getLocalPort(),
target.getAddress().getAddress(),
target.getPort(),
PacketLoggingService.TransportName.UDP,
true,
packet.getBuffer(),
packet.getOffset(),
packet.getLength());
}
}
/**
* Returns whether or not this RTPConnectorOutputStream has a valid
* socket.
*
* @return true if this RTPConnectorOutputStream has a valid
* socket, false otherwise
*/
@Override
protected boolean isSocketValid()
{
return (socket != null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy