Search in sources :

Example 1 with IStreamListener

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

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

the class VideoApplication method streamBroadcastClose.

@Override
public void streamBroadcastClose(IBroadcastStream stream) {
    super.streamBroadcastClose(stream);
    IConnection conn = Red5.getConnectionLocal();
    String scopeName;
    if (conn != null) {
        scopeName = conn.getScope().getName();
    } else {
        log.info("Connection local was null, using scope name from the stream: {}", stream);
        scopeName = stream.getScope().getName();
    }
    log.info("Stream broadcast closed for stream=[{}] meeting=[{}]", stream.getPublishedName(), scopeName);
    String userId = getUserId();
    String meetingId = conn.getScope().getName();
    String streamId = stream.getPublishedName();
    Matcher matcher = RECORD_STREAM_ID_PATTERN.matcher(stream.getPublishedName());
    if (matcher.matches()) {
        IStreamListener listener = streamListeners.remove(scopeName + "-" + stream.getPublishedName());
        if (listener != null) {
            ((VideoStreamListener) listener).streamStopped();
            stream.removeStreamListener(listener);
        }
        long publishDuration = (System.currentTimeMillis() - stream.getCreationTime()) / 1000;
        log.info("Stop recording event for stream=[{}] meeting=[{}]", stream.getPublishedName(), scopeName);
        Map<String, String> event = new HashMap<String, String>();
        event.put("module", "WEBCAM");
        event.put("timestamp", genTimestamp().toString());
        event.put("meetingId", scopeName);
        event.put("stream", stream.getPublishedName());
        event.put("duration", new Long(publishDuration).toString());
        event.put("eventName", "StopWebcamShareEvent");
        recordingService.record(scopeName, event);
    }
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) IConnection(org.red5.server.api.IConnection)

Example 3 with IStreamListener

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

the class Red5AppAdapter method streamBroadcastClose.

@Override
public void streamBroadcastClose(IBroadcastStream stream) {
    super.streamBroadcastClose(stream);
    log.info("streamBroadcastStop " + stream.getPublishedName() + "]");
    String streamId = stream.getPublishedName();
    Matcher matcher = STREAM_ID_PATTERN.matcher(stream.getPublishedName());
    if (matcher.matches()) {
        String meetingId = matcher.group(1).trim();
        app.streamStopped(meetingId, streamId);
        boolean recordVideoStream = app.recordStream(meetingId, streamId);
        if (recordVideoStream) {
            IConnection conn = Red5.getConnectionLocal();
            String scopeName;
            if (conn != null) {
                scopeName = conn.getScope().getName();
            } else {
                log.info("Connection local was null, using scope name from the stream: {}", stream);
                scopeName = stream.getScope().getName();
            }
            IStreamListener listener = streamListeners.remove(scopeName + "-" + stream.getPublishedName());
            if (listener != null) {
                stream.removeStreamListener(listener);
            }
            String filename = recordingDirectory;
            if (!filename.endsWith("/")) {
                filename.concat("/");
            }
            filename = filename.concat(meetingId).concat("/").concat(stream.getPublishedName()).concat(".flv");
            long publishDuration = (System.currentTimeMillis() - stream.getCreationTime()) / 1000;
            Map<String, String> event = new HashMap<String, String>();
            event.put("module", "Deskshare");
            event.put("timestamp", genTimestamp().toString());
            event.put("meetingId", scopeName);
            event.put("stream", stream.getPublishedName());
            event.put("file", filename);
            event.put("duration", new Long(publishDuration).toString());
            event.put("eventName", "DeskshareStoppedEvent");
            recordingService.record(scopeName, event);
        }
        Map<String, Object> logData = new HashMap<String, Object>();
        logData.put("meetingId", meetingId);
        logData.put("streamId", streamId);
        logData.put("recorded", recordVideoStream);
        Gson gson = new Gson();
        String logStr = gson.toJson(logData);
        log.info("ScreenShare broadcast stopped: data={}", logStr);
    } else {
        log.error("Invalid streamid format [{}]", streamId);
    }
}
Also used : IStreamListener(org.red5.server.api.stream.IStreamListener) Matcher(java.util.regex.Matcher) HashMap(java.util.HashMap) Gson(com.google.gson.Gson) IConnection(org.red5.server.api.IConnection)

Example 4 with IStreamListener

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

Aggregations

IStreamListener (org.red5.server.api.stream.IStreamListener)4 HashMap (java.util.HashMap)2 Matcher (java.util.regex.Matcher)2 IConnection (org.red5.server.api.IConnection)2 IStreamPacket (org.red5.server.api.stream.IStreamPacket)2 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 IoBuffer (org.apache.mina.core.buffer.IoBuffer)1 IVideoStreamCodec (org.red5.codec.IVideoStreamCodec)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