use of org.apache.mina.core.buffer.IoBuffer in project bigbluebutton by bigbluebutton.
the class SpeexToSpeexTranscoder method pushAudio.
private void pushAudio(byte[] audio) {
timestamp = timestamp + audio.length;
IoBuffer buffer = IoBuffer.allocate(1024);
buffer.setAutoExpand(true);
buffer.clear();
buffer.put((byte) SPEEX_CODEC);
byte[] copy = new byte[audio.length];
System.arraycopy(audio, 0, copy, 0, audio.length);
buffer.put(copy);
buffer.flip();
AudioData audioData = new AudioData(buffer);
audioData.setTimestamp((int) timestamp);
listener.handleTranscodedAudioData(audioData);
}
use of org.apache.mina.core.buffer.IoBuffer in project bigbluebutton by bigbluebutton.
the class VideoStreamListener method packetReceived.
@Override
public void packetReceived(IBroadcastStream stream, IStreamPacket packet) {
IoBuffer buf = packet.getData();
if (buf != null) {
buf.rewind();
}
if (buf == null || buf.remaining() == 0) {
return;
}
if (packet instanceof VideoData) {
// keep track of last time video was received
lastVideoTime = System.currentTimeMillis();
packetCount++;
if (!firstPacketReceived) {
firstPacketReceived = true;
publishing = true;
firstPacketTime = lastVideoTime;
// start the worker to monitor if we are still receiving video packets
timeoutJobName = scheduler.addScheduledJob(videoTimeout, new TimeoutJob());
if (record) {
Map<String, String> event = new HashMap<String, String>();
event.put("module", "WEBCAM");
event.put("timestamp", genTimestamp().toString());
event.put("meetingId", scope.getName());
event.put("stream", stream.getPublishedName());
event.put("eventName", "StartWebRTCDeskShareEvent");
recordingService.record(scope.getName(), event);
}
}
if (streamPaused) {
streamPaused = false;
long now = System.currentTimeMillis();
long numSeconds = (now - lastVideoTime) / 1000;
Map<String, Object> logData = new HashMap<String, Object>();
logData.put("meetingId", scope.getName());
logData.put("userId", userId);
logData.put("stream", stream.getPublishedName());
logData.put("packetCount", packetCount);
logData.put("publishing", publishing);
logData.put("pausedFor (sec)", numSeconds);
Gson gson = new Gson();
String logStr = gson.toJson(logData);
log.warn("Video stream restarted. data={}", logStr);
}
}
}
use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.
the class Mina2ConverterTest method testToByteArray.
public void testToByteArray() {
byte[] in = "Hello World".getBytes();
IoBuffer bb = IoBuffer.wrap(in);
byte[] out = Mina2Converter.toByteArray(bb);
for (int i = 0; i < out.length; i++) {
assertEquals(in[i], out[i]);
}
}
use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.
the class Mina2ConverterTest method testToString.
public void testToString() throws UnsupportedEncodingException {
String in = "Hello World 你好";
IoBuffer bb = IoBuffer.wrap(in.getBytes("UTF-8"));
Exchange exchange = new DefaultExchange(new DefaultCamelContext());
exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
String out = Mina2Converter.toString(bb, exchange);
assertEquals("Hello World 你好", out);
}
use of org.apache.mina.core.buffer.IoBuffer in project camel by apache.
the class HL7MLLPEncoder method encode.
public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws Exception {
if (message == null) {
throw new IllegalArgumentException("Message to be encoded is null");
} else if (message instanceof Exception) {
// we cannot handle exceptions
throw (Exception) message;
}
byte[] body;
if (message instanceof Message) {
body = ((Message) message).encode().getBytes(config.getCharset());
} else if (message instanceof String) {
body = ((String) message).getBytes(config.getCharset());
} else if (message instanceof byte[]) {
body = (byte[]) message;
} else {
throw new IllegalArgumentException("The message to encode is not a supported type: " + message.getClass().getCanonicalName());
}
// put the data into the byte buffer
IoBuffer buf = IoBuffer.allocate(body.length + 3).setAutoExpand(true);
buf.put((byte) config.getStartByte());
buf.put(body);
buf.put((byte) config.getEndByte1());
buf.put((byte) config.getEndByte2());
// flip the buffer so we can use it to write to the out stream
buf.flip();
LOG.debug("Encoded HL7 from {} to byte stream", message.getClass().getCanonicalName());
out.write(buf);
}
Aggregations