use of local.net.RtpPacket in project bigbluebutton by bigbluebutton.
the class RtpStreamSender method start.
public void start() {
packetBuffer = new byte[transcoder.getOutgoingEncodedFrameSize() + RTP_HEADER_SIZE];
rtpPacket = new RtpPacket(packetBuffer, 0);
rtpPacket.setPayloadType(transcoder.getCodecId());
startPayloadPos = rtpPacket.getHeaderLength();
sequenceNum = 0;
timestamp = 0;
}
use of local.net.RtpPacket in project bigbluebutton by bigbluebutton.
the class RtpStreamReceiver method receiveRtpPackets.
public void receiveRtpPackets() {
int packetReceivedCounter = 0;
int internalBufferLength = payloadLength + RTP_HEADER_SIZE;
while (receivePackets) {
try {
byte[] internalBuffer = new byte[internalBufferLength];
RtpPacket rtpPacket = new RtpPacket(internalBuffer, 0);
rtpSocket.receive(rtpPacket);
packetReceivedCounter++;
processReceivedPacket(rtpPacket);
} catch (IOException e) {
log.error("IOException while receiving rtp packets.");
receivePackets = false;
}
}
closeSocket();
log.debug("Rtp Receiver stopped.");
log.debug("Packet Received = " + packetReceivedCounter + ".");
}
use of local.net.RtpPacket in project bigbluebutton by bigbluebutton.
the class RtpStreamSender method queueSipDtmfDigits.
public void queueSipDtmfDigits(String dtmfDigits) {
byte[] dtmfbuf = new byte[transcoder.getOutgoingEncodedFrameSize() + RTP_HEADER_SIZE];
RtpPacket dtmfpacket = new RtpPacket(dtmfbuf, 0);
dtmfpacket.setPayloadType(dtmf2833Type);
dtmfpacket.setPayloadLength(transcoder.getOutgoingEncodedFrameSize());
byte[] blankbuf = new byte[transcoder.getOutgoingEncodedFrameSize() + RTP_HEADER_SIZE];
RtpPacket blankpacket = new RtpPacket(blankbuf, 0);
blankpacket.setPayloadType(transcoder.getCodecId());
blankpacket.setPayloadLength(transcoder.getOutgoingEncodedFrameSize());
for (int d = 0; d < dtmfDigits.length(); d++) {
char digit = dtmfDigits.charAt(d);
if (digit == '*') {
dtmfbuf[startPayloadPos] = 10;
} else if (digit == '#') {
dtmfbuf[startPayloadPos] = 11;
} else if (digit >= 'A' && digit <= 'D') {
dtmfbuf[startPayloadPos] = (byte) (digit - 53);
} else {
dtmfbuf[startPayloadPos] = (byte) (digit - 48);
}
// notice we are bumping times/seqn just like audio packets
try {
// send start event packet 3 times
// start event flag
dtmfbuf[startPayloadPos + 1] = 0;
// and volume
// duration 8 bits
dtmfbuf[startPayloadPos + 2] = 1;
// duration 8 bits
dtmfbuf[startPayloadPos + 3] = -32;
for (int r = 0; r < 3; r++) {
dtmfpacket.setSequenceNumber(sequenceNum++);
dtmfpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize());
doRtpDelay();
rtpSocketSend(dtmfpacket);
}
// send end event packet 3 times
// end event flag
dtmfbuf[startPayloadPos + 1] = -128;
// duration 8 bits
dtmfbuf[startPayloadPos + 2] = 3;
// duration 8 bits
dtmfbuf[startPayloadPos + 3] = 116;
for (int r = 0; r < 3; r++) {
dtmfpacket.setSequenceNumber(sequenceNum++);
dtmfpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize());
doRtpDelay();
rtpSocketSend(dtmfpacket);
}
// send 200 ms of blank packets
for (int r = 0; r < 200 / transcoder.getOutgoingPacketization(); r++) {
blankpacket.setSequenceNumber(sequenceNum++);
blankpacket.setTimestamp(transcoder.getOutgoingEncodedFrameSize());
doRtpDelay();
rtpSocketSend(blankpacket);
}
} catch (Exception e) {
log.warn("queueSipDtmfDigits", e.getLocalizedMessage());
}
}
}
use of local.net.RtpPacket in project bigbluebutton by bigbluebutton.
the class RtpStreamTranslator method run.
/** Runs it in a new Thread. */
public void run() {
if (rtp_socket_in == null || rtp_socket_out == null) {
if (DEBUG)
println("ERROR: RTP socket_in or socket_out is null");
return;
}
//else
byte[] buffer_in = new byte[BUFFER_SIZE];
RtpPacket rtp_packet_in = new RtpPacket(buffer_in, 0);
byte[] buffer_out = new byte[BUFFER_SIZE];
RtpPacket rtp_packet_out = new RtpPacket(buffer_out, 0);
if (DEBUG)
println("Reading blocks of max " + BUFFER_SIZE + " bytes");
//File file=new File("audio.wav");
//javax.sound.sampled.AudioInputStream audio_input_stream=null;
//try { audio_input_stream=javax.sound.sampled.AudioSystem.getAudioInputStream(file); } catch (Exception e) { e.printStackTrace(); }
running = true;
try {
rtp_socket_in.getDatagramSocket().setSoTimeout(SO_TIMEOUT);
while (running) {
try {
// read a block of data from the rtp_socket_in
rtp_socket_in.receive(rtp_packet_in);
// send the block to the rtp_socket_out (if still running..)
if (running) {
byte[] pkt1 = rtp_packet_in.getPacket();
int offset1 = rtp_packet_in.getHeaderLength();
int len1 = rtp_packet_in.getPayloadLength();
byte[] pkt2 = rtp_packet_out.getPacket();
int offset2 = rtp_packet_out.getHeaderLength();
int pos2 = offset2;
for (int i = 0; i < len1; i++) {
int linear = G711.ulaw2linear(pkt1[offset1 + i]);
//aux[pos++]=(byte)(linear&0xFF);
//aux[pos++]=(byte)((linear&0xFF00)>>8);
//int linear2=G711.ulaw2linear(audio_input_stream.read());
//linear+=linear2;
pkt2[pos2++] = (byte) G711.linear2ulaw(linear);
}
rtp_packet_out.setPayloadType(rtp_packet_in.getPayloadType());
rtp_packet_out.setSequenceNumber(rtp_packet_in.getSequenceNumber());
rtp_packet_out.setTimestamp(rtp_packet_in.getTimestamp());
rtp_packet_out.setPayloadLength(pos2 - offset2);
rtp_socket_out.send(rtp_packet_out);
}
} catch (java.io.InterruptedIOException e) {
}
}
} catch (Exception e) {
running = false;
e.printStackTrace();
}
// close RtpSocket and local DatagramSocket
DatagramSocket socket_in = rtp_socket_in.getDatagramSocket();
rtp_socket_in.close();
if (socket_in_is_local && socket_in != null)
socket_in.close();
DatagramSocket socket_out = rtp_socket_out.getDatagramSocket();
rtp_socket_out.close();
if (socket_out_is_local && socket_out != null)
socket_out.close();
// free all
rtp_socket_in = null;
rtp_socket_out = null;
if (DEBUG)
println("rtp translator terminated");
}
use of local.net.RtpPacket in project bigbluebutton by bigbluebutton.
the class RtpStreamReceiver method run.
/** Runs it in a new Thread. */
public void run() {
if (rtp_socket == null) {
if (DEBUG)
println("ERROR: RTP socket is null");
return;
}
//else
byte[] buffer = new byte[BUFFER_SIZE];
RtpPacket rtp_packet = new RtpPacket(buffer, 0);
if (DEBUG)
println("Reading blocks of max " + buffer.length + " bytes");
//byte[] aux=new byte[BUFFER_SIZE];
running = true;
try {
rtp_socket.getDatagramSocket().setSoTimeout(SO_TIMEOUT);
while (running) {
try {
// read a block of data from the rtp socket
rtp_socket.receive(rtp_packet);
// write this block to the output_stream (only if still running..)
if (running)
output_stream.write(rtp_packet.getPacket(), rtp_packet.getHeaderLength(), rtp_packet.getPayloadLength());
/*if (running)
{ byte[] pkt=rtp_packet.getPacket();
int offset=rtp_packet.getHeaderLength();
int len=rtp_packet.getPayloadLength();
int pos=0;
for (int i=0; i<len; i++)
{ int linear=G711.ulaw2linear(pkt[offset+i]);
//aux[pos++]=(byte)(linear&0xFF);
//aux[pos++]=(byte)((linear&0xFF00)>>8);
aux[pos++]=(byte)G711.linear2ulaw(linear);
}
output_stream.write(aux,0,pos);
}*/
} catch (java.io.InterruptedIOException e) {
}
}
} catch (Exception e) {
running = false;
e.printStackTrace();
}
// close RtpSocket and local DatagramSocket
DatagramSocket socket = rtp_socket.getDatagramSocket();
rtp_socket.close();
if (socket_is_local && socket != null)
socket.close();
// free all
output_stream = null;
rtp_socket = null;
if (DEBUG)
println("rtp receiver terminated");
}
Aggregations