Search in sources :

Example 1 with IStreamPacket

use of org.red5.server.api.stream.IStreamPacket in project bigbluebutton by bigbluebutton.

the class ScreenshareStreamListener 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) {
        if (!firstPacketReceived) {
            firstPacketReceived = true;
            IConnection conn = Red5.getConnectionLocal();
            String meetingId = conn.getScope().getName();
            String filename = recordingDir;
            if (!filename.endsWith("/")) {
                filename.concat("/");
            }
            filename = filename.concat(meetingId).concat("/").concat(stream.getPublishedName()).concat(".flv");
            Map<String, String> event = new HashMap<String, String>();
            event.put("module", "Deskshare");
            event.put("timestamp", genTimestamp().toString());
            event.put("meetingId", meetingId);
            event.put("file", filename);
            event.put("stream", stream.getPublishedName());
            event.put("eventName", "DeskshareStartedEvent");
            recordingService.record(conn.getScope().getName(), event);
        }
    }
}
Also used : HashMap(java.util.HashMap) VideoData(org.red5.server.net.rtmp.event.VideoData) IConnection(org.red5.server.api.IConnection) IoBuffer(org.apache.mina.core.buffer.IoBuffer)

Example 2 with IStreamPacket

use of org.red5.server.api.stream.IStreamPacket in project bigbluebutton by bigbluebutton.

the class ScreenVideoBroadcastStream method dispatchEvent.

public void dispatchEvent(IEvent event) {
    try {
        //    	System.out.println("dispatchEvent(event:screenVideo)");
        if (event instanceof IRTMPEvent) {
            IRTMPEvent rtmpEvent = (IRTMPEvent) event;
            if (livePipe != null) {
                RTMPMessage msg = RTMPMessage.build(rtmpEvent, Constants.SOURCE_TYPE_LIVE);
                if (creationTime == null)
                    creationTime = (long) rtmpEvent.getTimestamp();
                try {
                    IVideoStreamCodec videoStreamCodec = new ScreenVideo();
                    streamCodecInfo.setHasVideo(true);
                    streamCodecInfo.setVideoCodec(videoStreamCodec);
                    videoStreamCodec.reset();
                    videoStreamCodec.addData(((VideoData) rtmpEvent).getData());
                    livePipe.pushMessage(msg);
                    // Notify listeners about received packet
                    if (rtmpEvent instanceof IStreamPacket) {
                        for (IStreamListener listener : getStreamListeners()) {
                            try {
                                listener.packetReceived(this, (IStreamPacket) rtmpEvent);
                            } catch (Exception e) {
                                log.error("Error while notifying listener " + listener, e);
                            }
                        }
                    }
                } catch (IOException ex) {
                    // ignore
                    log.error("Got exception: {}", ex);
                }
            }
        }
    } finally {
    }
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) RTMPMessage(org.red5.server.stream.message.RTMPMessage) IRTMPEvent(org.red5.server.net.rtmp.event.IRTMPEvent) IOException(java.io.IOException) IVideoStreamCodec(org.red5.codec.IVideoStreamCodec) IStreamPacket(org.red5.server.api.stream.IStreamPacket) ResourceExistException(org.red5.server.api.stream.ResourceExistException) ResourceNotFoundException(org.red5.server.api.stream.ResourceNotFoundException) IOException(java.io.IOException)

Example 3 with IStreamPacket

use of org.red5.server.api.stream.IStreamPacket 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 4 with IStreamPacket

use of org.red5.server.api.stream.IStreamPacket 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 5 with IStreamPacket

use of org.red5.server.api.stream.IStreamPacket 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);
        }
    }
}
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)

Aggregations

IoBuffer (org.apache.mina.core.buffer.IoBuffer)4 HashMap (java.util.HashMap)3 VideoData (org.red5.server.net.rtmp.event.VideoData)3 Gson (com.google.gson.Gson)2 IStreamListener (org.red5.server.api.stream.IStreamListener)2 IStreamPacket (org.red5.server.api.stream.IStreamPacket)2 IOException (java.io.IOException)1 IVideoStreamCodec (org.red5.codec.IVideoStreamCodec)1 IConnection (org.red5.server.api.IConnection)1 IBroadcastStream (org.red5.server.api.stream.IBroadcastStream)1 ResourceExistException (org.red5.server.api.stream.ResourceExistException)1 ResourceNotFoundException (org.red5.server.api.stream.ResourceNotFoundException)1 AudioData (org.red5.server.net.rtmp.event.AudioData)1 IRTMPEvent (org.red5.server.net.rtmp.event.IRTMPEvent)1 RTMPMessage (org.red5.server.stream.message.RTMPMessage)1