} catch (FileNotFoundException e) {
logger.error("cannot create file", e);
return;
}
}
RtpPacket rtpPacket = new RtpPacket();
rtpPacket.setVersion(2);
rtpPacket.setPadding(false);
rtpPacket.setExtension(false);
rtpPacket.setCsrcCount(0);
rtpPacket.setMarker(false);
rtpPacket.setPayloadType(codec.getPayloadType());
Random random = new Random();
int sequenceNumber = random.nextInt();
rtpPacket.setSequenceNumber(sequenceNumber);
rtpPacket.setSsrc(random.nextInt());
int buf_size = Capture.BUFFER_SIZE / 2;
byte[] buffer = new byte[buf_size];
long counter = 0;
while (!isStopped) {
int numBytesRead;
try {
numBytesRead = encodedData.read(buffer, 0, buf_size);
} catch (IOException e) {
logger.error("input/output error", e);
return;
}
byte[] trimmedBuffer;
if (numBytesRead < buffer.length) {
trimmedBuffer = new byte[numBytesRead];
System.arraycopy(buffer, 0, trimmedBuffer, 0, numBytesRead);
} else {
trimmedBuffer = buffer;
}
if (mediaDebug) {
try {
rtpSenderInput.write(trimmedBuffer);
} catch (IOException e) {
logger.error("cannot write to file", e);
break;
}
}
if (pushedPackets.size() > 0) {
RtpPacket pushedPacket = pushedPackets.remove(0);
rtpPacket.setMarker(pushedPacket.isMarker());
rtpPacket.setPayloadType(pushedPacket.getPayloadType());
byte[] data = pushedPacket.getData();
rtpPacket.setData(data);
} else {
if (rtpPacket.getPayloadType() != codec.getPayloadType()) {
rtpPacket.setPayloadType(codec.getPayloadType());
rtpPacket.setMarker(false);