Search in sources :

Example 26 with IoBuffer

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", "StartWebcamShareEvent");
                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);
        }
    }
}
Also used : HashMap(java.util.HashMap) VideoData(org.red5.server.net.rtmp.event.VideoData) Gson(com.google.gson.Gson) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 27 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project bigbluebutton by bigbluebutton.

the class ScreenVideoFrame method getVideoData.

public IoBuffer getVideoData() {
    byte[] data = (byte[]) encodedData.toByteArray();
    IoBuffer buffer = IoBuffer.allocate(data.length, false);
    buffer.put(data);
    /* Set the marker back to zero position so that "gets" start from the beginning.
		 * Otherwise, you get BufferUnderFlowException.
		 */
    buffer.rewind();
    return buffer;
}
Also used : IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 28 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project bigbluebutton by bigbluebutton.

the class BlockStreamProtocolDecoder method tryToParsePolicyRequest.

private boolean tryToParsePolicyRequest(IoSession session, IoBuffer in, ProtocolDecoderOutput out) {
    byte[] message = new byte[POLICY_REQUEST.length];
    if (in.remaining() >= POLICY_REQUEST.length) {
        in.get(message, 0, message.length);
        if (Arrays.equals(message, POLICY_REQUEST)) {
            log.debug("Sending cross domain policy to the user");
            IoBuffer buffer = IoBuffer.allocate(8);
            buffer.setAutoExpand(true);
            try {
                buffer.putString("<cross-domain-policy><allow-access-from domain=\"*\" to-ports=\"*\" /></cross-domain-policy>", Charset.forName("UTF-8").newEncoder());
                buffer.put((byte) 0);
            } catch (CharacterCodingException e) {
                e.printStackTrace();
                return false;
            }
            buffer.flip();
            session.write(buffer);
            return true;
        }
    }
    return false;
}
Also used : CharacterCodingException(java.nio.charset.CharacterCodingException) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 29 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project bigbluebutton by bigbluebutton.

the class FlashToSipAudioStream method start.

public void start(IBroadcastStream broadcastStream, IScope scope) throws StreamException {
    if (log.isDebugEnabled())
        log.debug("startTranscodingStream({},{})", broadcastStream.getPublishedName(), scope.getName());
    mInputListener = new IStreamListener() {

        public void packetReceived(IBroadcastStream broadcastStream, IStreamPacket packet) {
            IoBuffer buf = packet.getData();
            if (buf != null)
                buf.rewind();
            if (buf == null || buf.remaining() == 0) {
                log.debug("skipping empty packet with no data");
                return;
            }
            if (packet instanceof AudioData) {
                byte[] data = SerializeUtils.ByteBufferToByteArray(buf);
                // Remove the first byte as it is the codec id.
                transcoder.handlePacket(data, 1, data.length - 1);
            }
        }
    };
    broadcastStream.addStreamListener(mInputListener);
    rtpSender = new RtpStreamSender(srcSocket, connInfo);
    rtpSender.connect();
    transcoder.start();
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) AudioData(org.red5.server.net.rtmp.event.AudioData) IBroadcastStream(org.red5.server.api.stream.IBroadcastStream) IStreamPacket(org.red5.server.api.stream.IStreamPacket) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 30 with IoBuffer

use of org.apache.mina.core.buffer.IoBuffer in project bigbluebutton by bigbluebutton.

the class PcmToNellyTranscoder method pushAudio.

private void pushAudio(byte[] audio) {
    IoBuffer buffer = IoBuffer.allocate(1024);
    buffer.setAutoExpand(true);
    buffer.clear();
    buffer.put((byte) NELLYMOSER_CODEC_ID);
    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) (System.currentTimeMillis() - start));
    listener.handleTranscodedAudioData(audioData);
}
Also used : AudioData(org.red5.server.net.rtmp.event.AudioData) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Aggregations

IoBuffer (org.apache.mina.core.buffer.IoBuffer)49 Test (org.junit.Test)8 VideoData (org.red5.server.net.rtmp.event.VideoData)4 UnknownHostException (java.net.UnknownHostException)3 HashMap (java.util.HashMap)3 UnauthorizedException (org.jivesoftware.openfire.auth.UnauthorizedException)3 AudioData (org.red5.server.net.rtmp.event.AudioData)3 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 ByteBuffer (java.nio.ByteBuffer)2 CharacterCodingException (java.nio.charset.CharacterCodingException)2 Exchange (org.apache.camel.Exchange)2 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)2 DefaultExchange (org.apache.camel.impl.DefaultExchange)2 Message (ca.uhn.hl7v2.model.Message)1 AddressedEnvelope (io.netty.channel.AddressedEnvelope)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 DatagramPacket (io.netty.channel.socket.DatagramPacket)1