コード例 #1
0
 /** {@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);
     }
   }
 }
コード例 #2
0
 /**
  * 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;
     int 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);
       }
     }
   }
 }
コード例 #3
0
 /** {@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) {
         sendNSFailed(
             streamConn,
             StatusCodes.NS_SEEK_FAILED,
             "The stream doesn't support seeking.",
             stream.getName(),
             streamId);
       }
     }
   }
 }
コード例 #4
0
 /** {@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;
     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<IStreamPlaybackSecurity> handlers = security.getStreamPlaybackSecurity();
       for (IStreamPlaybackSecurity handler : handlers) {
         if (!handler.isPlaybackAllowed(scope, name, start, length, flushPlaylist)) {
           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 (streamId <= 0) {
         streamId = streamConn.reserveStreamId();
       }
       stream = streamConn.newPlaylistSubscriberStream(streamId);
       stream.setBroadcastStreamPublishName(name);
       stream.start();
       created = true;
     }
     if (stream != null && 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);
         }
         sendNSFailed(streamConn, StatusCodes.NS_FAILED, err.getMessage(), name, streamId);
       }
     }
   } else {
     log.debug("Connection was not stream capable");
   }
 }
コード例 #5
0
 public void streamSubscriberStart(ISubscriberStream stream) {
   loginfo("Red5SIP Stream subscribe start: " + stream.getName());
 }
コード例 #6
0
 public void streamSubscriberClose(ISubscriberStream stream) {
   loginfo("Red5SIP Stream subscribe close: " + stream.getName());
 }