Package org.red5.server.stream.message

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


          // note this timestamp is set in event/body but not in the associated header
          try {
            // route to live
            if (livePipe != null) {
              // create new RTMP message, initialize it and push through pipe
              RTMPMessage msg = RTMPMessage.build(rtmpEvent, eventTime);
              livePipe.pushMessage(msg);
            } else {
              log.debug("Live pipe was null, message was not pushed");
            }
          } catch (IOException err) {
View Full Code Here


   * Take a message from this buffer. The message count decreases.
   *
   * @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

      if (stream != null) {
        Notify metaData = stream.getMetaData();
        //check for metadata to send
        if (metaData != null) {
          log.debug("Metadata is available");
          RTMPMessage metaMsg = RTMPMessage.build(metaData, 0);
          try {
            msgOut.pushMessage(metaMsg);
          } catch (IOException e) {
            log.warn("Error sending metadata", e);
          }
        } else {
          log.debug("No metadata available");
        }

        IStreamCodecInfo codecInfo = stream.getCodecInfo();
        log.debug("Codec info: {}", codecInfo);
        if (codecInfo instanceof StreamCodecInfo) {
          StreamCodecInfo info = (StreamCodecInfo) codecInfo;
          IVideoStreamCodec videoCodec = info.getVideoCodec();
          log.debug("Video codec: {}", videoCodec);
          if (videoCodec != null) {
            //check for decoder configuration to send
            IoBuffer config = videoCodec.getDecoderConfiguration();
            if (config != null) {
              log.debug("Decoder configuration is available for {}", videoCodec.getName());
              //log.debug("Dump:\n{}", Hex.encodeHex(config.array()));
              VideoData conf = new VideoData(config.asReadOnlyBuffer());
              log.trace("Configuration ts: {}", conf.getTimestamp());
              RTMPMessage confMsg = RTMPMessage.build(conf);
              try {
                log.debug("Pushing decoder configuration");
                msgOut.pushMessage(confMsg);
              } finally {
                conf.release();
              }
            }
            //check for a keyframe to send
            IoBuffer keyFrame = videoCodec.getKeyframe();
            if (keyFrame != null) {
              log.debug("Keyframe is available");
              VideoData video = new VideoData(keyFrame.asReadOnlyBuffer());
              log.trace("Keyframe ts: {}", video.getTimestamp());
              //log.debug("Dump:\n{}", Hex.encodeHex(keyFrame.array()));
              RTMPMessage videoMsg = RTMPMessage.build(video);
              try {
                log.debug("Pushing keyframe");
                msgOut.pushMessage(videoMsg);
              } finally {
                video.release();
              }
            }
          } else {
            log.debug("Could not initialize stream output, videoCodec is null");
          }
          // SplitmediaLabs - begin AAC fix
          IAudioStreamCodec audioCodec = info.getAudioCodec();
          log.debug("Audio codec: {}", audioCodec);
          if (audioCodec != null) {
            // check for decoder configuration to send
            IoBuffer config = audioCodec.getDecoderConfiguration();
            if (config != null) {
              log.debug("Decoder configuration is available for {}", audioCodec.getName());
              //log.debug("Dump:\n{}", Hex.encodeHex(config.array()));
              AudioData conf = new AudioData(config.asReadOnlyBuffer());
              log.trace("Configuration ts: {}", conf.getTimestamp());
              RTMPMessage confMsg = RTMPMessage.build(conf);
              try {
                log.debug("Pushing decoder configuration");
                msgOut.pushMessage(confMsg);
              } finally {
                conf.release();
View Full Code Here

        dataReference = ((Notify) messageIn.getBody()).getData();
        event = new Notify(dataReference);
        event.setTimestamp(messageIn.getBody().getTimestamp());
        break;
    }
    RTMPMessage messageOut = RTMPMessage.build(event);
    //get the current timestamp from the message
    int ts = messageOut.getBody().getTimestamp();
    if (log.isTraceEnabled()) {
      log.trace("sendMessage: streamStartTS={}, length={}, streamOffset={}, timestamp={}", new Object[] { streamStartTS, currentItem.getLength(), streamOffset, ts });
      final long delta = System.currentTimeMillis() - playbackStart;
      log.trace("clientBufferDetails: timestamp {} delta {} buffered {}", new Object[] { lastMessageTs, delta, lastMessageTs - delta });
    }
    // don't reset streamStartTS to 0 for live streams
    if ((streamStartTS == -1 && (ts > 0 || playDecision != 0)) || streamStartTS > ts) {
      log.debug("sendMessage: resetting streamStartTS");
      streamStartTS = ts;
      messageOut.getBody().setTimestamp(0);
    }
    //relative timestamp adjustment for live streams
    if (playDecision == 0 && streamStartTS > 0) {
      //subtract the offset time of when the stream started playing for the client
      ts -= streamStartTS;
      messageOut.getBody().setTimestamp(ts);
      if (log.isTraceEnabled()) {
        log.trace("sendMessage (updated): streamStartTS={}, length={}, streamOffset={}, timestamp={}", new Object[] { streamStartTS, currentItem.getLength(), streamOffset,
            ts });
      }
    }
View Full Code Here

  private void sendClearPing() {
    Ping eof = new Ping();
    eof.setEventType(Ping.STREAM_PLAYBUFFER_CLEAR);
    eof.setValue2(streamId);
    // eos
    RTMPMessage eofMsg = RTMPMessage.build(eof);
    doPushMessage(eofMsg);
  }
View Full Code Here

    if (pullMode) {
      Ping recorded = new Ping();
      recorded.setEventType(Ping.RECORDED_STREAM);
      recorded.setValue2(streamId);
      // recorded
      RTMPMessage recordedMsg = RTMPMessage.build(recorded);
      doPushMessage(recordedMsg);
    }

    Ping begin = new Ping();
    begin.setEventType(Ping.STREAM_BEGIN);
    begin.setValue2(streamId);
    // begin
    RTMPMessage beginMsg = RTMPMessage.build(begin);
    doPushMessage(beginMsg);
    // reset
    ResetMessage reset = new ResetMessage();
    doPushMessage(reset);
  }
View Full Code Here

    if (lastMessageTs > 0) {
      event.setTimestamp(lastMessageTs);
    } else {
      event.setTimestamp(0);
    }
    RTMPMessage msg = RTMPMessage.build(event);
    doPushMessage(msg);
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  public void pushMessage(IPipe pipe, IMessage message) throws IOException {
    if (message instanceof RTMPMessage) {
      RTMPMessage rtmpMessage = (RTMPMessage) message;
      IRTMPEvent body = rtmpMessage.getBody();
      if (body instanceof IStreamData) {
        // the subscriber paused
        if (subscriberStream.getState() == StreamState.PAUSED) {
          log.debug("Dropping packet because we are paused");
          videoFrameDropper.dropPacket(rtmpMessage);
View Full Code Here

              } catch (Throwable err) {
                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

              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 {
                        pendingMessage = rtmpMessage;
                      }
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.