use of local.net.RtpPacket in project bigbluebutton by bigbluebutton.
the class RtpStreamSender method run.
/** Runs it in a new Thread. */
public void run() {
if (rtp_socket == null || input_stream == null)
return;
//else
byte[] buffer = new byte[frame_size + 12];
RtpPacket rtp_packet = new RtpPacket(buffer, 0);
rtp_packet.setPayloadType(p_type);
int seqn = 0;
long time = 0;
//long start_time=System.currentTimeMillis();
long byte_rate = frame_rate * frame_size;
running = true;
if (DEBUG)
println("Reading blocks of " + (buffer.length - 12) + " bytes");
try {
while (running) {
//if (DEBUG) System.out.print("o");
int num = input_stream.read(buffer, 12, buffer.length - 12);
//if (DEBUG) System.out.print("*");
if (num > 0) {
rtp_packet.setSequenceNumber(seqn++);
rtp_packet.setTimestamp(time);
rtp_packet.setPayloadLength(num);
rtp_socket.send(rtp_packet);
// update rtp timestamp (in milliseconds)
long frame_time = (num * 1000) / byte_rate;
time += frame_time;
// wait fo next departure
if (do_sync) {
// wait before next departure..
//long frame_time=start_time+time-System.currentTimeMillis();
// accellerate in order to compensate possible program latency.. ;)
frame_time -= sync_adj;
try {
Thread.sleep(frame_time);
} catch (Exception e) {
}
}
} else if (num < 0) {
running = false;
if (DEBUG)
println("Error reading from InputStream");
}
}
} catch (Exception e) {
running = false;
e.printStackTrace();
}
//if (DEBUG) println("rtp time: "+time);
//if (DEBUG) println("real time: "+(System.currentTimeMillis()-start_time));
// close RtpSocket and local DatagramSocket
DatagramSocket socket = rtp_socket.getDatagramSocket();
rtp_socket.close();
if (socket_is_local && socket != null)
socket.close();
// free all
input_stream = null;
rtp_socket = null;
if (DEBUG)
println("rtp sender terminated");
}
Aggregations