Java Code Examples for org.red5.server.api.IConnection#getStreamId()
The following examples show how to use
org.red5.server.api.IConnection#getStreamId() .
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: StreamService.java From red5-server-common with Apache License 2.0 | 6 votes |
/** * Pause at given position. Required as "pausePlayback" can be "null" if no flag is passed by the client * * @param pausePlayback * Pause playback or not * @param position * Pause position */ public void pause(Boolean pausePlayback, int position) { IConnection conn = Red5.getConnectionLocal(); if (conn instanceof IStreamCapableConnection) { IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; Number streamId = conn.getStreamId(); IClientStream stream = streamConn.getStreamById(streamId); if (stream != null && stream instanceof ISubscriberStream) { ISubscriberStream subscriberStream = (ISubscriberStream) stream; // pausePlayback can be "null" if "pause" is called without any parameters from flash if (pausePlayback == null) { pausePlayback = !subscriberStream.isPaused(); } if (pausePlayback) { subscriberStream.pause(position); } else { subscriberStream.resume(position); } } } }
Example 2
Source File: StreamService.java From red5-server-common with Apache License 2.0 | 6 votes |
/** {@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 3
Source File: StreamService.java From red5-server-common with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ public void seek(int position) { log.trace("seek - position:{}", position); IConnection conn = Red5.getConnectionLocal(); if (conn instanceof IStreamCapableConnection) { IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; Number streamId = conn.getStreamId(); IClientStream stream = streamConn.getStreamById(streamId); if (stream != null && stream instanceof ISubscriberStream) { ISubscriberStream subscriberStream = (ISubscriberStream) stream; try { subscriberStream.seek(position); } catch (OperationNotSupportedException err) { sendNSFailed(streamConn, StatusCodes.NS_SEEK_FAILED, "The stream doesn't support seeking.", stream.getName(), streamId); } } } }
Example 4
Source File: StreamService.java From red5-server-common with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ public void play(Boolean dontStop) { log.debug("Play without stop: {}", dontStop); if (!dontStop) { IConnection conn = Red5.getConnectionLocal(); if (conn instanceof IStreamCapableConnection) { IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; Number streamId = conn.getStreamId(); IClientStream stream = streamConn.getStreamById(streamId); if (stream != null) { stream.stop(); } } } }
Example 5
Source File: StreamService.java From red5-server-common with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ public void receiveVideo(boolean receive) { IConnection conn = Red5.getConnectionLocal(); if (conn instanceof IStreamCapableConnection) { IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; Number streamId = conn.getStreamId(); IClientStream stream = streamConn.getStreamById(streamId); if (stream != null && stream instanceof ISubscriberStream) { ISubscriberStream subscriberStream = (ISubscriberStream) stream; subscriberStream.receiveVideo(receive); } } }
Example 6
Source File: StreamService.java From red5-server-common with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ public void receiveAudio(boolean receive) { IConnection conn = Red5.getConnectionLocal(); if (conn instanceof IStreamCapableConnection) { IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; Number streamId = conn.getStreamId(); IClientStream stream = streamConn.getStreamById(streamId); if (stream != null && stream instanceof ISubscriberStream) { ISubscriberStream subscriberStream = (ISubscriberStream) stream; subscriberStream.receiveAudio(receive); } } }
Example 7
Source File: StreamService.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public void play(String name, int start, int length, boolean flushPlaylist) { log.debug("Play called - name: {} start: {} length: {} flush playlist: {}", new Object[] { name, start, length, flushPlaylist }); IConnection conn = Red5.getConnectionLocal(); if (conn instanceof IStreamCapableConnection) { IScope scope = conn.getScope(); IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; Number streamId = conn.getStreamId(); if (StringUtils.isEmpty(name)) { log.warn("The stream name may not be empty"); sendNSFailed(streamConn, StatusCodes.NS_FAILED, "The stream name may not be empty.", name, streamId); return; } IStreamSecurityService security = (IStreamSecurityService) ScopeUtils.getScopeService(scope, IStreamSecurityService.class); if (security != null) { Set<IStreamPlaybackSecurity> handlers = security.getStreamPlaybackSecurity(); for (IStreamPlaybackSecurity handler : handlers) { if (!handler.isPlaybackAllowed(scope, name, start, length, flushPlaylist)) { log.warn("You are not allowed to play stream {}", name); sendNSFailed(streamConn, StatusCodes.NS_FAILED, "You are not allowed to play the stream.", name, streamId); return; } } } boolean created = false; IClientStream stream = streamConn.getStreamById(streamId); if (stream == null) { if (log.isTraceEnabled()) { log.trace("Stream not found for stream id: {} streams: {}", streamId, streamConn.getStreamsMap()); } try { // if our current stream id is less than or equal to 0, reserve a new id if (streamId.doubleValue() <= 0.0d) { streamId = streamConn.reserveStreamId(); } // instance a new stream for the stream id stream = streamConn.newPlaylistSubscriberStream(streamId); if (stream != null) { if (log.isTraceEnabled()) { log.trace("Created stream: {} for stream id: {}", stream, streamId); } stream.setBroadcastStreamPublishName(name); stream.start(); created = true; } else { log.warn("Stream was null for id: {}", streamId); // throw the ex so the ns fail will go out throw new Exception("Stream creation failed for name: " + name + " id: " + streamId); } } catch (Exception e) { log.warn("Unable to start playing stream: {}", name, e); sendNSFailed(streamConn, StatusCodes.NS_FAILED, "Unable to start playing stream", name, streamId); return; } } if (stream instanceof ISubscriberStream) { ISubscriberStream subscriberStream = (ISubscriberStream) stream; IPlayItem item = simplePlayback.get() ? SimplePlayItem.build(name, start, length) : DynamicPlayItem.build(name, start, length); if (subscriberStream instanceof IPlaylistSubscriberStream) { IPlaylistSubscriberStream playlistStream = (IPlaylistSubscriberStream) subscriberStream; if (flushPlaylist) { playlistStream.removeAllItems(); } playlistStream.addItem(item); } else if (subscriberStream instanceof ISingleItemSubscriberStream) { ISingleItemSubscriberStream singleStream = (ISingleItemSubscriberStream) subscriberStream; singleStream.setPlayItem(item); } else { // not supported by this stream service log.warn("Stream instance type: {} is not supported", subscriberStream.getClass().getName()); return; } try { subscriberStream.play(); } catch (IOException err) { if (created) { stream.close(); streamConn.deleteStreamById(streamId); } log.warn("Unable to play stream " + name, err); sendNSFailed(streamConn, StatusCodes.NS_FAILED, err.getMessage(), name, streamId); } } } else { log.debug("Connection was not stream capable"); } }