org.red5.server.api.scope.IScope Java Examples
The following examples show how to use
org.red5.server.api.scope.IScope.
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 |
/** * 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: MuxService.java From red5-hls-plugin with Apache License 2.0 | 6 votes |
/** * Creates and starts a mux for the given scope. * * @param scope */ public void start(IScope scope) { String scopeName = scope.getName(); log.debug("Start mux for {} scope", scopeName); // if a different output sample rate is needed, add it to the scope attributes int outputSampleRate = 44100; if (scope.hasAttribute("outputSampleRate")) { outputSampleRate = (int) scope.getAttribute("outputSampleRate"); } // create an identifier that will be used as the stream name String name = String.format("%s-audio", scopeName); // store the stream name on the scope scope.setAttribute("audioStreamName", name); // create a facade SegmenterService segmenter = (SegmenterService) scope.getContext().getBean("segmenter.service"); SegmentFacade facade = segmenter.start(name, false); if (facade != null) { AudioMux mux = new AudioMux(outputSampleRate, true); muxMap.put(scopeName, mux); mux.setFacade(facade); // start the mux mux.start(scope.getName()); } else { log.warn("Facade creation failed for {}", name); } }
Example #3
Source File: RTMPMinaConnection.java From red5-server-common with Apache License 2.0 | 6 votes |
@Override public boolean connect(IScope newScope, Object[] params) { log.debug("Connect scope: {}", newScope); boolean success = super.connect(newScope, params); if (success) { final Channel two = getChannel(2); // tell the flash player how fast we want data and how fast we shall send it two.write(new ServerBW(defaultServerBandwidth)); // second param is the limit type (0=hard,1=soft,2=dynamic) two.write(new ClientBW(defaultClientBandwidth, (byte) limitType)); // if the client is null for some reason, skip the jmx registration if (client != null) { // perform bandwidth detection if (bandwidthDetection && !client.isBandwidthChecked()) { client.checkBandwidth(); } } else { log.warn("Client was null"); } registerJMX(); } else { log.debug("Connect failed"); } return success; }
Example #4
Source File: DemoService.java From red5-examples with Apache License 2.0 | 6 votes |
/** * Getter for property 'listOfAvailableFLVs'. * * @return Value for property 'listOfAvailableFLVs'. */ public Map<String, Map<String, Object>> getListOfAvailableFLVs() { IScope scope = Red5.getConnectionLocal().getScope(); Map<String, Map<String, Object>> filesMap = new HashMap<String, Map<String, Object>>(); try { log.debug("Getting the media files"); addToMap(filesMap, scope.getResources("streams/*.flv")); addToMap(filesMap, scope.getResources("streams/*.f4v")); addToMap(filesMap, scope.getResources("streams/*.mp3")); addToMap(filesMap, scope.getResources("streams/*.mp4")); addToMap(filesMap, scope.getResources("streams/*.m4a")); addToMap(filesMap, scope.getResources("streams/*.3g2")); addToMap(filesMap, scope.getResources("streams/*.3gp")); } catch (IOException e) { log.error("", e); } return filesMap; }
Example #5
Source File: RTMPHandler.java From red5-server-common with Apache License 2.0 | 6 votes |
/** * Remoting call invocation handler. * * @param conn * RTMP connection * @param call * Service call */ protected void invokeCall(RTMPConnection conn, IServiceCall call) { final IScope scope = conn.getScope(); if (scope != null) { if (scope.hasHandler()) { final IScopeHandler handler = scope.getHandler(); log.debug("Scope: {} handler: {}", scope, handler); if (!handler.serviceCall(conn, call)) { // XXX: What to do here? Return an error? log.warn("Scope: {} handler failed on service call", scope.getName(), new Exception("Service call failed")); return; } } final IContext context = scope.getContext(); log.debug("Context: {}", context); context.getServiceInvoker().invoke(call, scope); } else { log.warn("Scope was null for invoke: {} connection state: {}", call.getServiceMethodName(), conn.getStateCode()); } }
Example #6
Source File: SharedObjectService.java From red5-server-common with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ public boolean createSharedObject(IScope scope, String name, boolean persistent) { boolean added = hasSharedObject(scope, name); if (!added) { log.debug("Attempting to add shared object: {} to {}", name, scope.getName()); added = scope.addChildScope(new SharedObjectScope(scope, name, persistent, getStore(scope, persistent))); if (!added) { added = hasSharedObject(scope, name); log.debug("Add failed on create, shared object already exists: {}", added); } } else { // the shared object already exists log.trace("Shared object ({}) already exists. Persistent: {}", name, persistent); } // added or already existing will be true return added; }
Example #7
Source File: Client.java From red5-server-common with Apache License 2.0 | 6 votes |
/** * Associate connection with client * * @param conn * Connection object */ protected void register(IConnection conn) { if (log.isDebugEnabled()) { if (conn == null) { log.debug("Register null connection, client id: {}", id); } else { log.debug("Register connection ({}:{}) client id: {}", conn.getRemoteAddress(), conn.getRemotePort(), id); } } if (conn != null) { IScope scope = conn.getScope(); if (scope != null) { log.debug("Registering for scope: {}", scope); connections.add(conn); } else { log.warn("Clients scope is null. Id: {}", id); } } else { log.warn("Clients connection is null. Id: {}", id); } }
Example #8
Source File: Red5.java From red5-server-common with Apache License 2.0 | 6 votes |
/** * Setter for connection * * @param connection * Thread local connection */ public static void setConnectionLocal(IConnection connection) { if (log.isDebugEnabled()) { log.debug("Set connection: {} with thread: {}", (connection != null ? connection.getSessionId() : null), Thread.currentThread().getName()); try { StackTraceElement[] stackTraceElements = Thread.currentThread().getStackTrace(); StackTraceElement stackTraceElement = stackTraceElements[2]; log.debug("Caller: {}.{} #{}", stackTraceElement.getClassName(), stackTraceElement.getMethodName(), stackTraceElement.getLineNumber()); } catch (Exception e) { } } if (connection != null) { connThreadLocal.set(new WeakReference<IConnection>(connection)); IScope scope = connection.getScope(); if (scope != null) { Thread.currentThread().setContextClassLoader(scope.getClassLoader()); } } else { // use null to clear the value connThreadLocal.remove(); } }
Example #9
Source File: RTMPConnection.java From red5-server-common with Apache License 2.0 | 6 votes |
@Override public boolean connect(IScope newScope, Object[] params) { if (log.isDebugEnabled()) { log.debug("Connect scope: {}", newScope); } try { boolean success = super.connect(newScope, params); if (success) { stopWaitForHandshake(); // once the handshake has completed, start needed jobs start the ping / pong keep-alive startRoundTripMeasurement(); } else if (log.isDebugEnabled()) { log.debug("Connect failed"); } return success; } catch (ClientRejectedException e) { String reason = (String) e.getReason(); log.info("Client rejected, reason: " + ((reason != null) ? reason : "None")); stopWaitForHandshake(); throw e; } }
Example #10
Source File: ApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override public void leave(IClient client, IScope scope) { try { lock.tryAcquire(1, TimeUnit.SECONDS); super.leave(client, scope); } catch (InterruptedException e) { e.printStackTrace(); } finally { lock.release(); } }
Example #11
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * Returns connection result for given scope and parameters. Whether the scope is room or app level scope, this method distinguishes it * and acts accordingly. You override {@link ApplicationAdapter#appConnect(IConnection, Object[])} or * {@link ApplicationAdapter#roomConnect(IConnection, Object[])} in your application to make it act the way you want. * * @param conn * Connection object * @param scope * Scope * @param params * List of params passed to connection handler * @return <code> * true * </code> * * if connect is successful, * * <code> * false * </code> * * otherwise */ @Override public boolean connect(IConnection conn, IScope scope, Object[] params) { // ensure the log is not null at this point if (log == null) { log = Red5LoggerFactory.getLogger(this.getClass()); } log.debug("connect: {} > {}", conn, scope); boolean success = false; // hit the super class first if (super.connect(conn, scope, params)) { if (log.isInfoEnabled() && ScopeUtils.isApp(scope)) { // log w3c connect event IClient client = conn.getClient(); if (client == null) { log.info("W3C x-category:session x-event:connect c-ip:{}", conn.getRemoteAddress()); } else { log.info("W3C x-category:session x-event:connect c-ip:{} c-client-id:{}", conn.getRemoteAddress(), client.getId()); } } if (ScopeUtils.isApp(scope)) { success = appConnect(conn, params); } else if (ScopeUtils.isRoom(scope)) { success = roomConnect(conn, params); } else { log.warn("Scope was not of app or room type, connect failed"); } } return success; }
Example #12
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * Returns connection result for given scope and parameters. Whether the scope is room or app level scope, this method distinguishes it * and acts accordingly. You override {@link ApplicationAdapter#appConnect(IConnection, Object[])} or * {@link ApplicationAdapter#roomConnect(IConnection, Object[])} in your application to make it act the way you want. * * @param conn * Connection object * @return <code>true</code> if connect is successful, <code>false</code> otherwise */ public boolean connect(IConnection conn) { // ensure the log is not null at this point if (log == null) { log = Red5LoggerFactory.getLogger(this.getClass()); } // get the scope from the connection IScope scope = conn.getScope(); log.debug("connect: {} > {}", conn, scope); return connect(conn, scope, null); }
Example #13
Source File: ClientBroadcastStream.java From red5-server-common with Apache License 2.0 | 5 votes |
private void sendStartNotifications(IEventListener source) { if (sendStartNotification) { // notify handler that stream starts recording/publishing sendStartNotification = false; if (source instanceof IConnection) { IScope scope = ((IConnection) source).getScope(); if (scope.hasHandler()) { final Object handler = scope.getHandler(); if (handler instanceof IStreamAwareScopeHandler) { if (recordingListener != null && recordingListener.get().isRecording()) { // callback for record start ((IStreamAwareScopeHandler) handler).streamRecordStart(this); } else { // delete any previously recorded versions of this now "live" stream per // http://livedocs.adobe.com/flashmediaserver/3.0/hpdocs/help.html?content=00000186.html // try { // File file = getRecordFile(scope, publishedName); // if (file != null && file.exists()) { // if (!file.delete()) { // log.debug("File was not deleted: {}", file.getAbsoluteFile()); // } // } // } catch (Exception e) { // log.warn("Exception removing previously recorded file", e); // } // callback for publish start ((IStreamAwareScopeHandler) handler).streamPublishStart(this); } } } } // send start notifications sendPublishStartNotify(); if (recordingListener != null && recordingListener.get().isRecording()) { sendRecordStartNotify(); } notifyBroadcastStart(); } }
Example #14
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
public boolean roomJoin(IClient client, IScope room) { log.debug("roomJoin: {} >> {}", client, room); for (IApplication listener : listeners) { if (!listener.roomJoin(client, room)) { return false; } } return true; }
Example #15
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * Handler method. Called when room scope is stopped. * * @param room * Room scope. */ public void roomStop(IScope room) { log.debug("roomStop: {}", room); for (IApplication listener : listeners) { listener.roomStop(room); } }
Example #16
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
/** * Handler method. Called when room scope is started. * * @param room * Room scope * @return Boolean value */ public boolean roomStart(IScope room) { log.debug("roomStart: {}", room); // TODO : Get to know what does roomStart return mean for (IApplication listener : listeners) { if (!listener.roomStart(room)) { return false; } } return true; }
Example #17
Source File: Application.java From red5-hls-plugin with Apache License 2.0 | 5 votes |
@Override public void stop(IScope scope) { // stop the muxer MuxService muxer = (MuxService) applicationContext.getBean("mux.service"); muxer.stop(scope); super.stop(scope); }
Example #18
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 5 votes |
public boolean appJoin(IClient client, IScope app) { log.debug("appJoin: {} >> {}", client, app); for (IApplication listener : listeners) { if (!listener.appJoin(client, app)) { return false; } } return true; }
Example #19
Source File: Application.java From red5-hls-plugin with Apache License 2.0 | 5 votes |
@Override public boolean start(IScope scope) { // create and start a muxer MuxService muxer = (MuxService) applicationContext.getBean("mux.service"); muxer.start(scope); return super.start(scope); }
Example #20
Source File: AbstractScopeAdapter.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public boolean start(IScope scope) { return canStart; }
Example #21
Source File: DefaultStreamFilenameGenerator.java From red5-server-common with Apache License 2.0 | 4 votes |
/** * Generate stream directory based on relative scope path. The base directory is * * <pre> * streams * </pre> * * , e.g. a scope * * <pre> * /application/one/two/ * </pre> * * will generate a directory * * <pre> * /streams/one/two/ * </pre> * * inside the application. * * @param scope * Scope * @return Directory based on relative scope path */ private String getStreamDirectory(IScope scope) { final StringBuilder result = new StringBuilder(); final IScope app = ScopeUtils.findApplication(scope); final String prefix = "streams/"; while (scope != null && scope != app) { result.insert(0, scope.getName() + "/"); scope = scope.getParent(); } if (result.length() == 0) { return prefix; } else { result.insert(0, prefix).append('/'); return result.toString(); } }
Example #22
Source File: Application.java From red5-hls-plugin with Apache License 2.0 | 4 votes |
@Override public boolean appStart(IScope scope) { return super.appStart(scope); }
Example #23
Source File: MultiThreadedApplicationAdapter.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public boolean hasBroadcastStream(IScope scope, String name) { return (getProviderService().getLiveProviderInput(scope, name, false) != null); }
Example #24
Source File: Application.java From red5-examples with Apache License 2.0 | 4 votes |
@Override public boolean appStart(IScope app) { super.appStart(app); log.info("springmvc appStart"); return super.appStart(app); }
Example #25
Source File: ScopeUtils.java From red5-server-common with Apache License 2.0 | 4 votes |
public static Object getScopeService(IScope scope, Class<?> intf, Class<?> defaultClass, boolean checkHandler) { if (scope == null || intf == null) { return null; } // We expect an interface assert intf.isInterface(); String attr = String.format("%s%s%s", IPersistable.TRANSIENT_PREFIX, SERVICE_CACHE_PREFIX, intf.getCanonicalName()); if (scope.hasAttribute(attr)) { // return cached service return scope.getAttribute(attr); } Object handler = null; if (checkHandler) { IScope current = scope; while (current != null) { IScopeHandler scopeHandler = current.getHandler(); if (intf.isInstance(scopeHandler)) { handler = scopeHandler; break; } if (!current.hasParent()) { break; } current = current.getParent(); } } if (handler == null && IScopeService.class.isAssignableFrom(intf)) { // we've got an IScopeService, try to lookup bean Field key = null; Object serviceName = null; try { key = intf.getField("BEAN_NAME"); serviceName = key.get(null); //log.debug("serviceName {}", serviceName); handler = getScopeService(scope, serviceName.toString(), defaultClass); } catch (Exception e) { if (log.isDebugEnabled()) { if (key == null) { log.debug("No string field 'BEAN_NAME' in interface {}", intf.getName()); } else { log.warn("Exception getting scope service using {}", intf.getName(), e); } } } } if (handler == null && defaultClass != null) { try { handler = defaultClass.getDeclaredConstructor().newInstance(); } catch (Exception e) { log.error("", e); } } // cache service scope.setAttribute(attr, handler); return handler; }
Example #26
Source File: Server.java From red5-server-common with Apache License 2.0 | 4 votes |
ScopeCreatedJob(IScope scope) { this.scope = scope; }
Example #27
Source File: Application.java From red5-examples with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ @Override public boolean appConnect(IConnection conn, Object[] params) { log.info("oflaDemo appConnect"); IScope appScope = conn.getScope(); log.debug("App connect called for scope: {}", appScope.getName()); // getting client parameters Map<String, Object> properties = conn.getConnectParams(); if (log.isDebugEnabled()) { for (Map.Entry<String, Object> e : properties.entrySet()) { log.debug("Connection property: {} = {}", e.getKey(), e.getValue()); } } // Trigger calling of "onBWDone", required for some FLV players // commenting out the bandwidth code as it is replaced by the mina filters //measureBandwidth(conn); // if (conn instanceof IStreamCapableConnection) { // IStreamCapableConnection streamConn = (IStreamCapableConnection) conn; // SimpleConnectionBWConfig bwConfig = new SimpleConnectionBWConfig(); // bwConfig.getChannelBandwidth()[IBandwidthConfigure.OVERALL_CHANNEL] = // 1024 * 1024; // bwConfig.getChannelInitialBurst()[IBandwidthConfigure.OVERALL_CHANNEL] = // 128 * 1024; // streamConn.setBandwidthConfigure(bwConfig); // } // if (appScope == conn.getScope()) { // serverStream = StreamUtils.createServerStream(appScope, "live0"); // SimplePlayItem item = new SimplePlayItem(); // item.setStart(0); // item.setLength(10000); // item.setName("on2_flash8_w_audio"); // serverStream.addItem(item); // item = new SimplePlayItem(); // item.setStart(20000); // item.setLength(10000); // item.setName("on2_flash8_w_audio"); // serverStream.addItem(item); // serverStream.start(); // try { // serverStream.saveAs("aaa", false); // serverStream.saveAs("bbb", false); // } catch (Exception e) {} // } return super.appConnect(conn, params); }
Example #28
Source File: Scope.java From red5-server-common with Apache License 2.0 | 4 votes |
/** * Connect to scope with parameters. To successfully connect to scope it must have handler that will accept this connection with given * set of parameters. Client associated with connection is added to scope clients set, connection is registered as scope event listener. * * @param conn * Connection object * @param params * Parameters passed with connection * @return true on success, false otherwise */ public boolean connect(IConnection conn, Object[] params) { log.debug("Connect - scope: {} connection: {}", this, conn); if (enabled) { if (hasParent() && !parent.connect(conn, params)) { log.debug("Connection to parent failed"); return false; } if (hasHandler() && !getHandler().connect(conn, this, params)) { log.debug("Connection to handler failed"); return false; } if (!conn.isConnected()) { log.debug("Connection is not connected"); // timeout while connecting client return false; } final IClient client = conn.getClient(); // we would not get this far if there is no handler if (hasHandler() && !getHandler().join(client, this)) { return false; } // checking the connection again? why? if (!conn.isConnected()) { // timeout while connecting client return false; } // add the client and event listener if (clients.add(client) && addEventListener(conn)) { log.debug("Added client"); // increment conn stats connectionStats.increment(); // get connected scope IScope connScope = conn.getScope(); log.trace("Connection scope: {}", connScope); if (this.equals(connScope)) { final IServer server = getServer(); if (server instanceof Server) { ((Server) server).notifyConnected(conn); } } return true; } } else { log.debug("Connection failed, scope is disabled"); } return false; }
Example #29
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"); } }
Example #30
Source File: AbstractScopeAdapter.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public boolean connect(IConnection conn, IScope scope, Object[] params) { return canConnect; }