org.red5.server.api.stream.IBroadcastStream Java Examples

The following examples show how to use org.red5.server.api.stream.IBroadcastStream. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SegmenterService.java    From red5-hls-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * Creates and starts a facade and adds an audio mux for the given scope.
 * 
 * @param scope
 * @param stream
 * @param useRTMPReader
 */
public void start(IScope scope, IBroadcastStream stream, boolean useRTMPReader) {
	log.debug("start - scope: {} stream: {} rtmp reader: {}", scope.getName(), stream.getPublishedName(), useRTMPReader);
	String streamName = stream.getPublishedName();
	start(streamName, useRTMPReader);
	// add the mux associated with the given scope
	AudioMux mux = muxService.getAudioMux(scope.getName());
	if (mux != null) {
		// get the facade for this stream
		segmentMap.get(streamName).setAudioMux(mux);
		// add the streams audio track to the muxer
		mux.addTrack(2, streamName); // TODO create a better way to know what our output channels are (defaulting to 2 / stereo)
	} else {
		log.warn("Audio mux service was not found");
	}
}
 
Example #2
Source File: RecordingListener.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void packetReceived(IBroadcastStream stream, IStreamPacket packet) {
    if (recording.get()) {
        // store everything we would need to perform a write of the stream data
        CachedEvent event = new CachedEvent();
        event.setData(packet.getData().duplicate());
        event.setDataType(packet.getDataType());
        event.setReceivedTime(System.currentTimeMillis());
        event.setTimestamp(packet.getTimestamp());
        // queue the event
        if (!queue.add(event)) {
            log.debug("Event packet not added to recording queue");
        }
    } else {
        log.info("A packet was received by recording listener, but it's not recording anymore. {}", stream.getPublishedName());
    }
}
 
Example #3
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void publish(Boolean dontStop) {
    // null is as good as false according to Boolean.valueOf() so if null, interpret as false
    if (dontStop == null || !dontStop) {
        IConnection conn = Red5.getConnectionLocal();
        if (conn instanceof IStreamCapableConnection) {
            IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
            Number streamId = conn.getStreamId();
            IClientStream stream = streamConn.getStreamById(streamId);
            if (stream instanceof IBroadcastStream) {
                IBroadcastStream bs = (IBroadcastStream) stream;
                if (bs.getPublishedName() != null) {
                    IBroadcastScope bsScope = getBroadcastScope(conn.getScope(), bs.getPublishedName());
                    if (bsScope != null) {
                        bsScope.unsubscribe(bs.getProvider());
                        if (conn instanceof BaseConnection) {
                            ((BaseConnection) conn).unregisterBasicScope(bsScope);
                        }
                    }
                    bs.close();
                    streamConn.deleteStreamById(streamId);
                }
            }
        }
    }
}
 
Example #4
Source File: Application.java    From red5-rtsp-restreamer with Apache License 2.0 6 votes vote down vote up
@Override
public void packetReceived(IBroadcastStream stream, IStreamPacket packet) {

	RTMPMessage m = RTMPMessage.build((IRTMPEvent) packet, packet.getTimestamp());

	try {

		limiter--;
		if (limiter > 1) {
			streamer.pushMessage(null, m);
		} else {
			if (streamer != null) {
				stream.removeStreamListener(this);
				streamer.stop();
				streamer = null;
			}
		}

	} catch (IOException e) {

		e.printStackTrace();
	}

}
 
Example #5
Source File: BandwidthChecker.java    From red5-rtsp-restreamer with Apache License 2.0 6 votes vote down vote up
public void packetReceived(IBroadcastStream arg0, IStreamPacket packet) {

		if (done) {
			arg0.removeStreamListener(this);
			return;
		}

		messages = Red5.getConnectionLocal().getWrittenMessages() + Red5.getConnectionLocal().getReadMessages();

		bytesUp = Red5.getConnectionLocal().getReadBytes();

		bytesDown = Red5.getConnectionLocal().getWrittenBytes();

		if (packet instanceof Notify) {

			endpoint().invoke("onBWChunk", new Object[] { chunk });
			chunks++;
			//  Input reader = new Input(((Notify)packet).getData()); 
			//  reader.readDataType();//string
			//  String  method=reader.readString(null);
			//  reader.readDataType();//object
			//  Map invokeData=  (Map) reader.readMap(new Deserializer(), null);            
			//  System.out.println(method+""+invokeData.get("data").toString());	
		}
	}
 
Example #6
Source File: Application.java    From red5-hls-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void streamPublishStart(final IBroadcastStream stream) {
	final String streamName = stream.getPublishedName();
	log.debug("streamPublishStart - stream name: {}", streamName);
	IConnection conn = Red5.getConnectionLocal();
	// save the record / stream name
	conn.setAttribute("streamName", streamName);
	super.streamPublishStart(stream);
	if (stream instanceof ClientBroadcastStream) {					
		Thread creator = new Thread(new Runnable() {
			public void run() {
				while (scope.getBroadcastScope(streamName) == null) {
					log.debug("Stream: {} is not available yet...", streamName);
					try {
						Thread.sleep(500L);
					} catch (InterruptedException e) {
					}
				}
				// get the segmenter
				SegmenterService segmenter = (SegmenterService) applicationContext.getBean("segmenter.service");
				// check that the stream is not already being segmented
				if (!segmenter.isAvailable(streamName)) {
					// start segmenting utilizing included RTMP reader
					segmenter.start(scope, stream, true);
				}					
			}
		});
		creator.setDaemon(true);
		creator.start();
	}		
}
 
Example #7
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public IBroadcastStream getBroadcastStream(IScope scope, String name) {
    IStreamService service = (IStreamService) ScopeUtils.getScopeService(scope, IStreamService.class, StreamService.class);
    if (service instanceof StreamService) {
        IBroadcastScope bs = ((StreamService) service).getBroadcastScope(scope, name);
        if (bs != null) {
            return bs.getClientBroadcastStream();
        }
    }
    return null;
}
 
Example #8
Source File: Application.java    From red5-hls-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void streamRecordStart(IBroadcastStream stream) {
	log.debug("streamRecordStart - stream name: {}", stream.getPublishedName());
	// save the record / stream name
	Red5.getConnectionLocal().setAttribute("streamName", stream.getPublishedName());
	super.streamRecordStart(stream);
}
 
Example #9
Source File: Application.java    From red5-examples with Apache License 2.0 5 votes vote down vote up
@Override
public void streamBroadcastClose(IBroadcastStream stream) {
	log.debug("Broadcast close called. Stream name: {}", stream.getName());
	super.streamBroadcastClose(stream);
	// TODO: call the process to move the flv to S3 because its not possible to stream the bytes directly to S3 during flv write
	if (persistToS3) {
   		// move the completed flv to S3
   		S3FilenameGenerator.upload("Session-" + System.currentTimeMillis(), stream.getPublishedName());
	}
}
 
Example #10
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
public void streamPublishStart(IBroadcastStream stream) {
    // log w3c connect event
    IConnection connection = Red5.getConnectionLocal();
    log.info("W3C x-category:stream x-event:publish c-ip:{} x-sname:{} x-name:{}", new Object[] { connection != null ? connection.getRemoteAddress() : "0.0.0.0", stream.getName(), stream.getPublishedName() });
}
 
Example #11
Source File: Application.java    From red5-hls-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void streamBroadcastClose(IBroadcastStream stream) {
	log.debug("streamBroadcastClose - stream name: {}", stream.getPublishedName());
	super.streamBroadcastClose(stream);
}
 
Example #12
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
public void streamRecordStop(IBroadcastStream stream) {
    // log w3c connect event
    IConnection connection = Red5.getConnectionLocal();
    log.info("W3C x-category:stream x-event:record-stop c-ip:{} x-sname:{} x-file-name:{}", new Object[] { connection != null ? connection.getRemoteAddress() : "0.0.0.0", stream.getName(), stream.getSaveFilename() });
}
 
Example #13
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
public void streamRecordStart(IBroadcastStream stream) {
    // log w3c connect event
    IConnection connection = Red5.getConnectionLocal();
    log.info("W3C x-category:stream x-event:record-start c-ip:{} x-sname:{} x-file-name:{}", new Object[] { connection != null ? connection.getRemoteAddress() : "0.0.0.0", stream.getName(), stream.getSaveFilename() });
}
 
Example #14
Source File: IRecordingListener.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/** {@inheritDoc} */
public void packetReceived(IBroadcastStream stream, IStreamPacket packet);
 
Example #15
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
public void streamBroadcastStart(IBroadcastStream stream) {
}
 
Example #16
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 4 votes vote down vote up
/**
 * Notification that a broadcasting stream is closing.
 * 
 * @param stream
 *            stream
 */
public void streamBroadcastClose(IBroadcastStream stream) {
    // log w3c connect event
    IConnection conn = Red5.getConnectionLocal();
    // converted to seconds
    long now = System.currentTimeMillis();
    long startTime = stream.getStartTime() > 0 ? stream.getStartTime() : now;
    long publishDuration = Math.max((now - startTime) / 1000, 0L);
    if (conn != null) {
        log.info("W3C x-category:stream x-event:unpublish c-ip:{} cs-bytes:{} sc-bytes:{} x-sname:{} x-file-length:{} x-name:{}", new Object[] { conn.getRemoteAddress(), conn.getReadBytes(), conn.getWrittenBytes(), stream.getName(), publishDuration, stream.getPublishedName() });
    } else {
        log.info("W3C x-category:stream x-event:unpublish x-sname:{} x-file-length:{} x-name:{}", new Object[] { stream.getName(), publishDuration, stream.getPublishedName() });
    }
    String recordingName = stream.getSaveFilename();
    // if its not null then we did a recording
    if (recordingName != null) {
        if (conn != null) {
            // use cs-bytes for file size for now
            log.info("W3C x-category:stream x-event:recordstop c-ip:{} cs-bytes:{} sc-bytes:{} x-sname:{} x-file-name:{} x-file-length:{} x-file-size:{}", new Object[] { conn.getRemoteAddress(), conn.getReadBytes(), conn.getWrittenBytes(), stream.getName(), recordingName, publishDuration, conn.getReadBytes() });
        } else {
            log.info("W3C x-category:stream x-event:recordstop x-sname:{} x-file-name:{} x-file-length:{}", new Object[] { stream.getName(), recordingName, publishDuration });
        }
        // if the stream length is 0 bytes then delete it, this is a fix for SN-20
        // get the web root
        String webappsPath = System.getProperty("red5.webapp.root");
        // add context name
        File file = new File(webappsPath, getName() + '/' + recordingName);
        if (file != null) {
            log.debug("File path: {}", file.getAbsolutePath());
            if (file.exists()) {
                // if publish duration or length are zero
                if (publishDuration == 0 || file.length() == 0) {
                    if (file.delete()) {
                        log.info("File {} was deleted", file.getName());
                    } else {
                        log.info("File {} was not deleted, it will be deleted on exit", file.getName());
                        file.deleteOnExit();
                    }
                }
            }
            file = null;
        }
    }
}
 
Example #17
Source File: IBroadcastStreamService.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Get a broadcast stream by name
 * 
 * @param scope
 *            the scope to return the stream from
 * @param name
 *            the name of the broadcast
 * @return broadcast stream object
 */
public IBroadcastStream getBroadcastStream(IScope scope, String name);
 
Example #18
Source File: IProviderService.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Unregister a broadcast stream of a specific name from a scope.
 * 
 * @param scope
 *            Scope
 * @param name
 *            Stream name
 * @param stream
 *            Broadcast stream
 * @return true if unregister successfully.
 */
boolean unregisterBroadcastStream(IScope scope, String name, IBroadcastStream stream);
 
Example #19
Source File: IProviderService.java    From red5-server-common with Apache License 2.0 2 votes vote down vote up
/**
 * Register a broadcast stream to a scope.
 * 
 * @param scope
 *            Scope
 * @param name
 *            Name of stream
 * @param stream
 *            Broadcast stream to register
 * @return true if register successfully.
 */
boolean registerBroadcastStream(IScope scope, String name, IBroadcastStream stream);