Examples of IStreamCapableConnection


Examples of org.red5.server.api.stream.IStreamCapableConnection

    // get the clients connection
    IConnection conn = Red5.getConnectionLocal();
    if (conn != null && conn instanceof IStreamCapableConnection) {
      // get the stream id
      int streamId = conn.getStreamId();
      IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
      if ("stop".equals(transition)) {
        play(Boolean.FALSE);
      } else if ("reset".equals(transition)) {
        // just reset the currently playing stream
        play(streamName);
      } else if ("switch".equals(transition)) {
        try {
          // set the playback type
          simplePlayback.set(Boolean.FALSE);
          // send the "start" of transition
          sendNSStatus(conn, StatusCodes.NS_PLAY_TRANSITION, String.format("Transitioning from %s to %s.", oldStreamName, streamName), streamName, streamId);
          // support offset?
          //playOptions.get("offset")
          play(streamName, start, length);
        } finally {
          // clean up
          simplePlayback.remove();
        }
      } else if ("append".equals(transition) || "appendAndWait".equals(transition)) {
        IPlaylistSubscriberStream playlistStream = (IPlaylistSubscriberStream) streamConn.getStreamById(streamId);
        IPlayItem item = SimplePlayItem.build(streamName);
        playlistStream.addItem(item);
        if ("append".equals(transition)) {
          play(streamName, start, length, false);
        }
      } else if ("swap".equals(transition)) {
        IPlaylistSubscriberStream playlistStream = (IPlaylistSubscriberStream) streamConn.getStreamById(streamId);
        IPlayItem item = SimplePlayItem.build(streamName);
        int itemCount = playlistStream.getItemSize();
        for (int i = 0; i < itemCount; i++) {
          IPlayItem tmpItem = playlistStream.getItem(i);
          if (tmpItem.getName().equals(oldStreamName)) {
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

  /** {@inheritDoc} */
  public void publish(Boolean dontStop) {
    if (!dontStop) {
      IConnection conn = Red5.getConnectionLocal();
      if (conn instanceof IStreamCapableConnection) {
        IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
        int 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);
          }
        }
      }
    }
  }
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

      name = name.substring(0, name.indexOf("?"));
    }
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
      IScope scope = conn.getScope();
      IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
      int streamId = conn.getStreamId();
      if (StringUtils.isEmpty(name)) {
        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<IStreamPublishSecurity> handlers = security.getStreamPublishSecurity();
        for (IStreamPublishSecurity handler : handlers) {
          if (!handler.isPublishAllowed(scope, name, mode)) {
            sendNSFailed(streamConn, StatusCodes.NS_PUBLISH_BADNAME, "You are not allowed to publish the stream.", name, streamId);
            return;
          }
        }
      }
      IBroadcastScope bsScope = getBroadcastScope(scope, name);
      if (bsScope != null && !bsScope.getProviders().isEmpty()) {
        // another stream with that name is already published     
        sendNSFailed(streamConn, StatusCodes.NS_PUBLISH_BADNAME, name, name, streamId);
        return;
      }
      IClientStream stream = streamConn.getStreamById(streamId);
      if (stream != null && !(stream instanceof IClientBroadcastStream)) {
        return;
      }
      boolean created = false;
      if (stream == null) {
        stream = streamConn.newBroadcastStream(streamId);
        created = true;
      }
      IClientBroadcastStream bs = (IClientBroadcastStream) stream;
      try {
        // set publish name
        bs.setPublishedName(name);
        // set stream parameters if they exist
        if (params != null) {
          bs.setParameters(params);
        }
        IContext context = conn.getScope().getContext();
        IProviderService providerService = (IProviderService) context.getBean(IProviderService.BEAN_NAME);
        // TODO handle registration failure
        if (providerService.registerBroadcastStream(conn.getScope(), name, bs)) {
          bsScope = getBroadcastScope(conn.getScope(), name);
          bsScope.setClientBroadcastStream(bs);
          if (conn instanceof BaseConnection) {
            ((BaseConnection) conn).registerBasicScope(bsScope);
          }
        }
        log.debug("Mode: {}", mode);
        if (IClientStream.MODE_RECORD.equals(mode)) {
          bs.start();
          bs.saveAs(name, false);
        } else if (IClientStream.MODE_APPEND.equals(mode)) {
          bs.start();
          bs.saveAs(name, true);
        } else {
          bs.start();
        }
        bs.startPublishing();
      } catch (IOException e) {
        log.warn("Stream I/O exception", e);
        sendNSFailed(streamConn, StatusCodes.NS_RECORD_NOACCESS, "The file could not be created/written to.", name, streamId);
        bs.close();
        if (created) {
          streamConn.deleteStreamById(streamId);
        }
      } catch (Exception e) {
        log.warn("Exception on publish", e);
      }
    }
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

  /** {@inheritDoc} */
  public void seek(int position) {
    log.trace("seek - position:{}", position);
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
      IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
      int 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) {
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

  /** {@inheritDoc} */
  public void receiveVideo(boolean receive) {
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
      IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
      int streamId = conn.getStreamId();
      IClientStream stream = streamConn.getStreamById(streamId);
      if (stream != null && stream instanceof ISubscriberStream) {
        ISubscriberStream subscriberStream = (ISubscriberStream) stream;
        subscriberStream.receiveVideo(receive);
      }
    }
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

  /** {@inheritDoc} */
  public void receiveAudio(boolean receive) {
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
      IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
      int streamId = conn.getStreamId();
      IClientStream stream = streamConn.getStreamById(streamId);
      if (stream != null && stream instanceof ISubscriberStream) {
        ISubscriberStream subscriberStream = (ISubscriberStream) stream;
        subscriberStream.receiveAudio(receive);
      }
    }
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

    public void deleteStream(int streamId) {
    IConnection conn = Red5.getConnectionLocal();
    if (!(conn instanceof IStreamCapableConnection)) {
      return;
    }
    IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
    deleteStream(streamConn, streamId);
  }
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

    public void pause(Boolean pausePlayback, int position) {
    IConnection conn = Red5.getConnectionLocal();
    if (!(conn instanceof IStreamCapableConnection)) {
      return;
    }
    IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
    int streamId = getCurrentStreamId();
    IClientStream stream = streamConn.getStreamById(streamId);
    if (stream == null || !(stream instanceof ISubscriberStream)) {
      return;
    }
    ISubscriberStream subscriberStream = (ISubscriberStream) stream;
    // pausePlayback can be "null" if "pause" is called without any parameters from flash
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

    IConnection conn = Red5.getConnectionLocal();
    if (!(conn instanceof IStreamCapableConnection)) {
      return;
    }
    IScope scope = conn.getScope();
    IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
    int streamId = getCurrentStreamId();
    if (name == null || "".equals(name)) {
      sendNSFailed((RTMPConnection) streamConn, "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)) {
          sendNSFailed((RTMPConnection) streamConn, "You are not allowed to play the stream.", name, streamId);
          return;
        }
      }
    }
   
    IClientStream stream = streamConn.getStreamById(streamId);
    boolean created = false;
    if (stream == null) {
      stream = streamConn.newPlaylistSubscriberStream(streamId);
      stream.start();
      created = true;
    }
    if (!(stream instanceof ISubscriberStream)) {
      return;
    }
    ISubscriberStream subscriberStream = (ISubscriberStream) stream;
    SimplePlayItem item = new SimplePlayItem();
    item.setName(name);
    item.setStart(start);
    item.setLength(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
      return;
    }
    try {
      subscriberStream.play();
    } catch (IOException err) {
      if (created) {
        stream.close();
        streamConn.deleteStreamById(streamId);
      }
      sendNSFailed((RTMPConnection) streamConn, err.getMessage(), name, streamId);
    }
  }
View Full Code Here

Examples of org.red5.server.api.stream.IStreamCapableConnection

    if (!dontStop) {
      IConnection conn = Red5.getConnectionLocal();
      if (!(conn instanceof IStreamCapableConnection)) {
        return;
      }
      IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
      int streamId = getCurrentStreamId();
      IClientStream stream = streamConn.getStreamById(streamId);
      if (stream != null) {
        stream.stop();
      }
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.