Examples of IRTMPEvent


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

         * Recieve then send if message is data (not audio or video)
         */
        private synchronized void pullAndPush() throws IOException {
      if (state == State.PLAYING && isPullMode && !isWaitingForToken) {
        if (pendingMessage != null) {
          IRTMPEvent body = pendingMessage.getBody();
          if (!okayToSendMessage(body)) {
            return;
          }
         
          sendMessage(pendingMessage);
          releasePendingMessage();
        } else {
          while (true) {
            IMessage msg = msgIn.pullMessage();
            if (msg == null) {
              // No more packets to send
              stop();
              break;
            } else {
              if (msg instanceof RTMPMessage) {
                RTMPMessage rtmpMessage = (RTMPMessage) msg;
                IRTMPEvent body = rtmpMessage.getBody();
                if (!receiveAudio && body instanceof AudioData) {
                  // The user doesn't want to get audio packets
                  ((IStreamData) body).getData().release();
                  if (sendBlankAudio) {
                    // Send reset audio packet
                    sendBlankAudio = false;
                    body = new AudioData();
                    // We need a zero timestamp
                    if (lastMessage != null) {
                      body.setTimestamp(lastMessage.getTimestamp()-timestampOffset);
                    } else {
                      body.setTimestamp(-timestampOffset);
                    }
                    rtmpMessage.setBody(body);
                  } else {
                    continue;
                  }
                } else if (!receiveVideo && body instanceof VideoData) {
                  // The user doesn't want to get video packets
                  ((IStreamData) body).getData().release();
                  continue;
                }
               
                // Adjust timestamp when playing lists
                body.setTimestamp(body.getTimestamp() + timestampOffset);
                if (okayToSendMessage(body)) {
                  //System.err.println("ts: " + rtmpMessage.getBody().getTimestamp());
                  sendMessage(rtmpMessage);
                  ((IStreamData) body).getData().release();
                } else {
View Full Code Here

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

     */
    private void doPushMessage(AbstractMessage message) {
      try {
        msgOut.pushMessage(message);
        if (message instanceof RTMPMessage) {
          IRTMPEvent body = ((RTMPMessage) message).getBody();
          if (body instanceof IStreamData && ((IStreamData) body).getData() != null) {
            bytesSent += ((IStreamData) body).getData().limit();
          }
        }
       
View Full Code Here

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

      props.put("duration", duration);
      props.put("bytes", bytes);
      out.writeMap(props, new Serializer());
      buf.flip();

      IRTMPEvent event = new Notify(buf);
      if (lastMessage != null) {
        int timestamp = lastMessage.getTimestamp();
        event.setTimestamp(timestamp);
      } else {
        event.setTimestamp(0);
      }
      RTMPMessage msg = new RTMPMessage();
      msg.setBody(event);
      doPushMessage(msg);
    }
View Full Code Here

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

        sendReset();
        return;
      }
      if (message instanceof RTMPMessage) {
        RTMPMessage rtmpMessage = (RTMPMessage) message;
        IRTMPEvent body = rtmpMessage.getBody();
        if (!(body instanceof IStreamData)) {
          throw new RuntimeException("expected IStreamData but got "
              + body.getClass() + " (type " + body.getDataType() + ")");
        }

        int size = ((IStreamData) body).getData().limit();
        if (body instanceof VideoData) {
          IVideoStreamCodec videoCodec = null;
          if (msgIn instanceof IBroadcastScope) {
            IClientBroadcastStream stream = (IClientBroadcastStream) ((IBroadcastScope) msgIn)
                .getAttribute(IBroadcastScope.STREAM_ATTRIBUTE);
            if (stream != null && stream.getCodecInfo() != null) {
              videoCodec = stream.getCodecInfo().getVideoCodec();
            }
          }

          if (videoCodec == null || videoCodec.canDropFrames()) {
            if (state == State.PAUSED) {
              // The subscriber paused the video
              videoFrameDropper.dropPacket(rtmpMessage);
              return;
            }
           
            // Only check for frame dropping if the codec supports it
            long pendingVideos = pendingVideoMessages();
            if (!videoFrameDropper.canSendPacket(rtmpMessage,
                pendingVideos)) {
              // Drop frame as it depends on other frames that were dropped before.
              return;
            }

            boolean drop = !videoBucket.acquireToken(size, 0);
            if (!receiveVideo || drop) {
              // The client disabled video or the app doesn't have enough bandwidth
              // allowed for this stream.
              videoFrameDropper.dropPacket(rtmpMessage);
              return;
            }

            Long[] writeDelta = getWriteDelta();
            if (pendingVideos > 1 /*|| writeDelta[0] > writeDelta[1]*/) {
              // We drop because the client has insufficient bandwidth.
              long now = System.currentTimeMillis();
              if (bufferCheckInterval > 0 && now >= nextCheckBufferUnderrun) {
                // Notify client about frame dropping (keyframe)
                sendInsufficientBandwidthStatus(currentItem);
                nextCheckBufferUnderrun = now + bufferCheckInterval;
              }
              videoFrameDropper.dropPacket(rtmpMessage);
              return;
            }
           
            videoFrameDropper.sendPacket(rtmpMessage);
          }
        } else if (body instanceof AudioData) {
          if (!receiveAudio && sendBlankAudio) {
            // Send blank audio packet to reset player
            sendBlankAudio = false;
            body = new AudioData();
            if (lastMessage != null) {
              body.setTimestamp(lastMessage.getTimestamp());
            } else {
              body.setTimestamp(0);
            }
            rtmpMessage.setBody(body);
          } else if (state == State.PAUSED || !receiveAudio || !audioBucket.acquireToken(size, 0)) {
            return;
          }
View Full Code Here

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

        /**
         * Releases pending message body, nullifies pending message object
         */
    private synchronized void releasePendingMessage() {
      if (pendingMessage != null) {
        IRTMPEvent body = pendingMessage.getBody();
        if (body instanceof IStreamData && ((IStreamData) body).getData() != null) {
          ((IStreamData) body).getData().release();
        }
        pendingMessage.setBody(null);
        pendingMessage = null;
View Full Code Here

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

    }
    if (writer == null) {
      init();
    }
    RTMPMessage rtmpMsg = (RTMPMessage) message;
    final IRTMPEvent msg = rtmpMsg.getBody();
    if (startTimestamp == -1) {
      startTimestamp = msg.getTimestamp();
    }
    int timestamp = msg.getTimestamp() - startTimestamp;
    if (timestamp < 0) {
      log.warn("Skipping message with negative timestamp.");
      return;
    }
    lastTimestamp = timestamp;

    ITag tag = new Tag();

    tag.setDataType(msg.getDataType());
    tag.setTimestamp(timestamp + offset);
    if (msg instanceof IStreamData) {
      ByteBuffer data = ((IStreamData) msg).getData().asReadOnlyBuffer();
      tag.setBodySize(data.limit());
      tag.setBody(data);
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();
    if (!(packet instanceof VideoData)) {
      // We currently only drop video packets.
      return true;
    }

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();
    if (!(packet instanceof VideoData)) {
      // Only check video packets.
      return;
    }

View Full Code Here

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

      return creationTime;
    }
   
    /** {@inheritDoc} */
    public int getCurrentTimestamp() {
      final IRTMPEvent msg = engine.lastMessage;
      if (msg == null) {
        return 0;
      }
     
      return msg.getTimestamp();
    }
View Full Code Here

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

      return bytesSent;
    }
   
    /** {@inheritDoc} */
    public double getEstimatedBufferFill() {
      final IRTMPEvent msg = engine.lastMessage;
      if (msg == null) {
        // Nothing has been sent yet
        return 0.0;
      }
     
    // Buffer size as requested by the client
    final long buffer = getClientBufferDuration();
    if (buffer == 0) {
      return 100.0;
    }
   
    // Duration the stream is playing
    final long delta = System.currentTimeMillis() - engine.playbackStart;
    // Expected amount of data present in client buffer
    final long buffered = msg.getTimestamp() - delta;
      return (buffered * 100.0) / buffer;
    }
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.