Package org.red5.server.stream.message

Examples of org.red5.server.stream.message.RTMPMessage


      //make sure chunk size has been sent
      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);
View Full Code Here


   */
  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();
View Full Code Here

                      sendStartStatus(item);
                    }

                    video.setTimestamp(0);

                    RTMPMessage videoMsg = new RTMPMessage();
                    videoMsg.setBody(video);
                    msgOut.pushMessage(videoMsg);
                    sendNotifications = false;
                    // Don't wait for keyframe
                    videoFrameDropper.reset();
                  } finally {
View Full Code Here

          log.error("Error while pulling message.", err);
          msg = null;
        }
        while (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;
              lastMessage = body;
              break;
            }
          }
         
          try {
            msg = msgIn.pullMessage();
          } catch (Throwable err) {
            log.error("Error while pulling message.", err);
            msg = null;
          }
        }
      } else {
        startPullPushThread = true;
      }
     
      if (!messageSent) {
        // Send blank audio packet to notify client about new position
        AudioData audio = new AudioData();
        audio.setTimestamp(seekPos);
        audio.setHeader(new Header());
        audio.getHeader().setTimer(seekPos);
        audio.getHeader().setTimerRelative(false);
        RTMPMessage audioMessage = new RTMPMessage();
        audioMessage.setBody(audio);
        lastMessage = audio;
        doPushMessage(audioMessage);
      }
     
      if (startPullPushThread) {
View Full Code Here

      return;
    }
    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) {
View Full Code Here

              // 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
View Full Code Here

    private void sendClearPing() {
      Ping ping1 = new Ping();
      ping1.setValue1((short) Ping.STREAM_PLAYBUFFER_CLEAR);
      ping1.setValue2(getStreamId());

      RTMPMessage ping1Msg = new RTMPMessage();
      ping1Msg.setBody(ping1);
      doPushMessage(ping1Msg);
    }
View Full Code Here

      if (isPullMode) {
        Ping ping1 = new Ping();
        ping1.setValue1((short) Ping.STREAM_RESET);
        ping1.setValue2(getStreamId());

        RTMPMessage ping1Msg = new RTMPMessage();
        ping1Msg.setBody(ping1);
        doPushMessage(ping1Msg);
      }

      Ping ping2 = new Ping();
      ping2.setValue1((short) Ping.STREAM_CLEAR);
      ping2.setValue2(getStreamId());

      RTMPMessage ping2Msg = new RTMPMessage();
      ping2Msg.setBody(ping2);
      doPushMessage(ping2Msg);

      ResetMessage reset = new ResetMessage();
      doPushMessage(reset);
    }
View Full Code Here

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

      if (message instanceof ResetMessage) {
        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;
          }
        }
        if (body instanceof IStreamData && ((IStreamData) body).getData() != null) {
View Full Code Here

TOP

Related Classes of org.red5.server.stream.message.RTMPMessage

Copyright © 2018 www.massapicom. 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.