Examples of IRTMPEvent


Examples of org.red5.server.net.rtmp.event.IRTMPEvent

   * @param message          RTMP message
   * @return <tt>true</tt> indicates success and <tt>false</tt>
   * indicates buffer is full.
   */
  public boolean putMessage(RTMPMessage message) {
    IRTMPEvent body = message.getBody();
    if (!(body instanceof IStreamData)) {
      throw new RuntimeException("Expected IStreamData but got " + body);
    }
    int size = ((IStreamData<?>) body).getData().limit();
    if (messageSize + size > capacity) {
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

   * @return <tt>null</tt> if buffer is empty.
   */
  public RTMPMessage takeMessage() {
    RTMPMessage message = messageQueue.poll();
    if (message != null) {
      IRTMPEvent body = message.getBody();
      if (!(body instanceof IStreamData)) {
        throw new RuntimeException("Expected IStreamData but got " + body);
      }
      messageSize -= ((IStreamData<?>) body).getData().limit();
    }
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

                log.error("Error while pulling message", err);
                msg = null;
              }
              if (msg instanceof RTMPMessage) {
                RTMPMessage rtmpMessage = (RTMPMessage) msg;
                IRTMPEvent body = rtmpMessage.getBody();
                if (body instanceof VideoData && ((VideoData) body).getFrameType() == FrameType.KEYFRAME) {
                  //body.setTimestamp(seekPos);
                  doPushMessage(rtmpMessage);
                  rtmpMessage.getBody().release();
                  messageSent = true;
                  lastMessageTs = body.getTimestamp();
                  break;
                }
              }
            } while (msg != null);
          }
      }
      // seeked past end of stream
      if (currentItem.getLength() >= 0 && (position - streamOffset) >= currentItem.getLength()) {
        stop();
      }
      // if no message has been sent by this point send an audio packet
      if (!messageSent) {
        // Send blank audio packet to notify client about new position
        log.debug("Sending blank audio packet");
        AudioData audio = new AudioData();
        audio.setTimestamp(seekPos);
        audio.setHeader(new Header());
        audio.getHeader().setTimer(seekPos);
        RTMPMessage audioMessage = RTMPMessage.build(audio);
        lastMessageTs = seekPos;
        doPushMessage(audioMessage);
        audioMessage.getBody().release();
      }

      if (!messageSent && subscriberStream.getState() == StreamState.PLAYING) {
        boolean isRTMPTPlayback = subscriberStream.getConnection() instanceof RTMPTConnection;

        // send all frames from last keyframe up to requested position and fill client buffer
        if (sendCheckVideoCM(msgIn)) {
          final long clientBuffer = subscriberStream.getClientBufferDuration();
          IMessage msg = null;
          int msgSent = 0;

          do {
            try {
              msg = msgIn != null ? msgIn.pullMessage() : null;
              if (msg instanceof RTMPMessage) {
                RTMPMessage rtmpMessage = (RTMPMessage) msg;
                IRTMPEvent body = rtmpMessage.getBody();
                if (body.getTimestamp() >= position + (clientBuffer * 2)) {
                  // client buffer should be full by now, continue regular pull/push
                  releasePendingMessage();
                  if (checkSendMessageEnabled(rtmpMessage)) {
                    pendingMessage = rtmpMessage;
                  }
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

            }
          }
          // receive then send if message is data (not audio or video)
          if (subscriberStream.getState() == StreamState.PLAYING && pullMode) {
            if (pendingMessage != null) {
              IRTMPEvent body = pendingMessage.getBody();
              if (okayToSendMessage(body)) {
                sendMessage(pendingMessage);
                releasePendingMessage();
              } else {
                return;
              }
            } else {
              IMessage msg = null;
              do {
                msg = msgIn.pullMessage();
                if (msg != null) {
                  if (msg instanceof RTMPMessage) {
                    RTMPMessage rtmpMessage = (RTMPMessage) msg;
                    if (checkSendMessageEnabled(rtmpMessage)) {
                      // Adjust timestamp when playing lists
                      IRTMPEvent body = rtmpMessage.getBody();
                      body.setTimestamp(body.getTimestamp() + timestampOffset);
                      if (okayToSendMessage(body)) {
                        log.trace("ts: {}", rtmpMessage.getBody().getTimestamp());
                        sendMessage(rtmpMessage);
                        ((IStreamData<?>) body).getData().free();
                      } else {
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

      if (!chunkSizeSent) {
        sendChunkSize();
      }
      // cast to rtmp message
      RTMPMessage rtmpMsg = (RTMPMessage) message;
      IRTMPEvent msg = rtmpMsg.getBody();
      // get timestamp
      int eventTime = msg.getTimestamp();
      log.debug("Message timestamp: {}", eventTime);
      if (eventTime < 0) {
        log.debug("Message has negative timestamp: {}", eventTime);
        return;
      }
      // get the data type
      byte dataType = msg.getDataType();
      log.trace("Data type: {}", dataType);
      //create a new header for the consumer
      final Header header = new Header();
      header.setTimerBase(eventTime);
      //data buffer
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

   * Process the queued items.
   */
  private void processQueue() {
    CachedEvent cachedEvent;
    try {
      IRTMPEvent event = null;
      RTMPMessage message = null;
      // get first event in the queue
      cachedEvent = queue.poll();
      if (cachedEvent != null) {
        // get the data type
        final byte dataType = cachedEvent.getDataType();
        // get the data
        IoBuffer buffer = cachedEvent.getData();
        // get the current size of the buffer / data
        int bufferLimit = buffer.limit();
        if (bufferLimit > 0) {
          // create new RTMP message and push to the consumer
          switch (dataType) {
            case Constants.TYPE_AGGREGATE:
              event = new Aggregate(buffer);
              event.setTimestamp(cachedEvent.getTimestamp());
              message = RTMPMessage.build(event);
              break;
            case Constants.TYPE_AUDIO_DATA:
              event = new AudioData(buffer);
              event.setTimestamp(cachedEvent.getTimestamp());
              message = RTMPMessage.build(event);
              break;
            case Constants.TYPE_VIDEO_DATA:
              event = new VideoData(buffer);
              event.setTimestamp(cachedEvent.getTimestamp());
              message = RTMPMessage.build(event);
              break;
            default:
              event = new Notify(buffer);
              event.setTimestamp(cachedEvent.getTimestamp());
              message = RTMPMessage.build(event);
              break;
          }
          // push it down to the recorder
          recordingConsumer.pushMessage(null, message);
        } else if (bufferLimit == 0 && dataType == Constants.TYPE_AUDIO_DATA) {
          log.debug("Stream data size was 0, sending empty audio message");
          // allow for 0 byte audio packets
          event = new AudioData(IoBuffer.allocate(0));
          event.setTimestamp(cachedEvent.getTimestamp());
          message = RTMPMessage.build(event);
          // push it down to the recorder
          recordingConsumer.pushMessage(null, message);
        } else {
          log.debug("Stream data size was 0, recording pipe will not be notified");
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

    this.state = state;
  }

  /** {@inheritDoc} */
  public boolean canSendPacket(RTMPMessage message, long pending) {
    IRTMPEvent packet = message.getBody();
    boolean result = true;
    // We currently only drop video packets.
    if (packet instanceof VideoData) {
      VideoData video = (VideoData) packet;
      FrameType type = video.getFrameType();
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

    return result;
  }

  /** {@inheritDoc} */
  public void dropPacket(RTMPMessage message) {
    IRTMPEvent packet = message.getBody();
    // Only check video packets.
    if (packet instanceof VideoData) {
      VideoData video = (VideoData) packet;
      FrameType type = video.getFrameType();
      switch (state) {
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

      }
    }
    msg = msgIn.pullMessage();
    if (msg instanceof RTMPMessage) {
      // Only send first video frame
      IRTMPEvent body = ((RTMPMessage) msg).getBody();
      if (itemLength == 0) {
        while (body != null && !(body instanceof VideoData)) {
          msg = msgIn.pullMessage();
          if (msg != null && msg instanceof RTMPMessage) {
            body = ((RTMPMessage) msg).getBody();
          } else {
            break;
          }
        }
      }
      if (body != null) {
        // Adjust timestamp when playing lists
        body.setTimestamp(body.getTimestamp() + timestampOffset);
      }
    }
    return msg;
  }
View Full Code Here

Examples of org.red5.server.net.rtmp.event.IRTMPEvent

    log.trace("doPushMessage: {}", message.getMessageType());
    if (msgOut != null) {
      try {
        msgOut.pushMessage(message);
        if (message instanceof RTMPMessage) {
          IRTMPEvent body = ((RTMPMessage) message).getBody();
          //update the last message sent's timestamp
          lastMessageTs = body.getTimestamp();
          IoBuffer streamData = null;
          if (body instanceof IStreamData && (streamData = ((IStreamData<?>) body).getData()) != null) {
            bytesSent.addAndGet(streamData.limit());
          }
        }
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.