/** {@inheritDoc} */ public IMessageInput getLiveProviderInput(IScope scope, String name, boolean needCreate) { log.debug("Get live provider input for {} scope: {}", name, scope); // make sure the create is actually needed IBroadcastScope broadcastScope = scope.getBroadcastScope(name); if (broadcastScope == null && needCreate) { synchronized (scope) { // re-check if another thread already created the scope broadcastScope = scope.getBroadcastScope(name); if (broadcastScope == null) { broadcastScope = new BroadcastScope(scope, name); scope.addChildScope(broadcastScope); } } } return broadcastScope; }
/** * Iterate through the scopes and their attributes. Used by JMX * * @return list of scope attributes */ public List<String> iterateScopeNameList() { log.debug("iterateScopeNameList called"); Collection<IScope> scopes = getScopes(); log.debug("Scopes: {}", scopes.size()); List<String> scopeNames = new ArrayList<String>(scopes.size()); for (IScope scope : scopes) { log.debug("Client scope: {}", scope); scopeNames.add(scope.getName()); if (log.isDebugEnabled()) { for (Map.Entry<String, Object> entry : scope.getAttributes().entrySet()) { log.debug("Client scope attr: {} = {}", entry.getKey(), entry.getValue()); } } } return scopeNames; }
private File getStreamFile(IScope scope, String name) { if (log.isDebugEnabled()) { log.debug("getStreamFile - name: {}", name); } IStreamableFileFactory factory = (IStreamableFileFactory) ScopeUtils.getScopeService(scope, IStreamableFileFactory.class); if (name.indexOf(':') == -1 && name.indexOf('.') == -1) { // Default to .flv files if no prefix and no extension is given. name = "flv:" + name; } // ams sends an asterisk at the start of the name on mp4, so remove it if (name.charAt(0) == '*') { name = name.substring(1); if (log.isTraceEnabled()) { log.trace("Removed star prefix: {}", name); } } for (IStreamableFileService service : factory.getServices()) { if (name.startsWith(service.getPrefix() + ':')) { name = service.prepareFilename(name); break; } } // look for a custom filename gen class IStreamFilenameGenerator filenameGenerator = (IStreamFilenameGenerator) ScopeUtils.getScopeService( scope, IStreamFilenameGenerator.class, DefaultStreamFilenameGenerator.class); // get the filename String filename = filenameGenerator.generateFilename(scope, name, GenerationType.PLAYBACK); File file; try { // most likely case first if (!filenameGenerator.resolvesToAbsolutePath()) { try { file = scope.getContext().getResource(filename).getFile(); } catch (FileNotFoundException e) { log.debug("File {} not found, nulling it", filename); file = null; } } else { file = new File(filename); } // check file existence if (file != null && !file.exists()) { // if it does not exist then null it out file = null; } } catch (IOException e) { log.info("Exception attempting to lookup file: {}", e.getMessage()); if (log.isDebugEnabled()) { log.warn("Exception attempting to lookup file: {}", name, e); } // null out the file (fix for issue #238) file = null; } return file; }
/** * Return stream aware scope handler or null if scope is null * * @return IStreamAwareScopeHandler implementation */ protected IStreamAwareScopeHandler getStreamAwareHandler() { if (scope != null) { IScopeHandler handler = scope.getHandler(); if (handler instanceof IStreamAwareScopeHandler) { return (IStreamAwareScopeHandler) handler; } } return null; }
/** {@inheritDoc} */ public boolean unregisterBroadcastStream(IScope scope, String name, IBroadcastStream bs) { if (log.isDebugEnabled()) { log.debug("Unregistering - name: {} stream: {} scope: {}", new Object[] {name, bs, scope}); ((Scope) scope).dump(); } IBroadcastScope broadcastScope = scope.getBroadcastScope(name); if (bs != null) { log.debug("Unsubscribing scope {} from provider {}", broadcastScope, bs.getProvider()); broadcastScope.unsubscribe(bs.getProvider()); } // if the scope has no listeners try to remove it if (!((BasicScope) broadcastScope).hasEventListeners()) { if (log.isDebugEnabled()) { log.debug("Scope has no event listeners attempting removal"); } scope.removeChildScope(broadcastScope); } // verify that scope was removed return scope.getBasicScope(ScopeType.BROADCAST, name) == null; }
/** * Return client connections to given scope * * @param scope Scope * @return Set of connections for that scope */ public Set<IConnection> getConnections(IScope scope) { if (scope == null) { return getConnections(); } Set<IClient> scopeClients = scope.getClients(); if (scopeClients.contains(this)) { for (IClient cli : scopeClients) { if (this.equals(cli)) { return cli.getConnections(); } } } return Collections.emptySet(); }
/** Start this server-side stream */ public void start() { if (state != StreamState.UNINIT) { throw new IllegalStateException("State " + state + " not valid to start"); } if (items.size() == 0) { throw new IllegalStateException("At least one item should be specified to start"); } if (publishedName == null) { throw new IllegalStateException("A published name is needed to start"); } try { IScope scope = getScope(); IContext context = scope.getContext(); providerService = (IProviderService) context.getBean(IProviderService.BEAN_NAME); // publish this server-side stream providerService.registerBroadcastStream(scope, publishedName, this); scheduler = (ISchedulingService) context.getBean(ISchedulingService.BEAN_NAME); } catch (NullPointerException npe) { log.warn("Context beans were not available; this is ok during unit testing", npe); } setState(StreamState.STOPPED); currentItemIndex = -1; nextItem(); }
/** {@inheritDoc} */ public boolean registerBroadcastStream(IScope scope, String name, IBroadcastStream bs) { if (log.isDebugEnabled()) { log.debug("Registering - name: {} stream: {} scope: {}", new Object[] {name, bs, scope}); ((Scope) scope).dump(); } IBroadcastScope broadcastScope = scope.getBroadcastScope(name); if (broadcastScope == null) { log.debug("Creating a new scope"); broadcastScope = new BroadcastScope(scope, name); if (scope.addChildScope(broadcastScope)) { log.debug("Broadcast scope added"); } else { log.warn("Broadcast scope was not added to {}", scope); } } // set the client broadcast stream if we have a broadcast scope if (broadcastScope != null && bs instanceof IClientBroadcastStream) { broadcastScope.setClientBroadcastStream((IClientBroadcastStream) bs); } if (log.isDebugEnabled()) { log.debug("Subscribing scope {} to provider {}", broadcastScope, bs.getProvider()); } return broadcastScope.subscribe(bs.getProvider(), null); }
@Override public boolean appStart(IScope scope) { loginfo("Red5SIP starting in scope " + scope.getName() + " " + System.getProperty("user.dir")); loginfo( "Red5SIP using RTP port range " + startRTPPort + "-" + stopRTPPort + ", using SIP port range " + startSIPPort + "-" + stopSIPPort); sipPort = startSIPPort; rtpPort = startRTPPort; return true; }
/** {@inheritDoc} */ public INPUT_TYPE lookupProviderInput(IScope scope, String name, int type) { INPUT_TYPE result = INPUT_TYPE.NOT_FOUND; if (scope.getBasicScope(ScopeType.BROADCAST, name) != null) { // we have live input result = INPUT_TYPE.LIVE; } else { // "default" to VOD as a missing file will be picked up later on result = INPUT_TYPE.VOD; File file = getStreamFile(scope, name); if (file == null) { if (type == -2) { result = INPUT_TYPE.LIVE_WAIT; } log.debug("Requested stream: {} does not appear to be of VOD type", name); } } return result; }
/** * Return broadcast scope object for given scope and child scope name. * * @param scope Scope object * @param name Child scope name * @return Broadcast scope */ public IBroadcastScope getBroadcastScope(IScope scope, String name) { return scope.getBroadcastScope(name); }
@Override public void appStop(IScope scope) { loginfo("Red5SIP stopping in scope " + scope.getName()); sipManager.destroyAllSessions(); }
@Override public boolean appStart(IScope scope) { log.debug("***** " + APP + " [ " + " appStart [ " + scope.getName() + "] *********"); return true; }
/** {@inheritDoc} */ public Set<String> getBroadcastStreamNames(IScope scope) { return scope.getBasicScopeNames(ScopeType.BROADCAST); }
@Override public void roomLeave(IClient client, IScope scope) { log.debug("***** " + APP + " [ " + " roomLeave [ " + scope.getName() + "] *********"); }
@Override public boolean roomJoin(IClient client, IScope scope) { log.debug("***** " + APP + " [ " + " roomJoin [ " + scope.getName() + "] *********"); return true; }
@Override public void appStop(IScope scope) { log.debug("***** " + APP + " [ " + " appStop [ " + scope.getName() + "] *********"); }