Package org.red5.server.net.rtmp.message

Examples of org.red5.server.net.rtmp.message.Packet


    if (header == null) {
      throw new ProtocolException("Header is null, check for error");
    }
    rtmp.setLastReadHeader(channelId, header);
    // check to see if this is a new packets or continue decoding an existing one
    Packet packet = rtmp.getLastReadPacket(channelId);
    if (packet == null) {
      packet = new Packet(header.clone());
      rtmp.setLastReadPacket(channelId, packet);
    }
    final IoBuffer buf = packet.getData();
    final int readRemaining = header.getSize() - buf.position();
    final int chunkSize = rtmp.getReadChunkSize();
    final int readAmount = (readRemaining > chunkSize) ? chunkSize : readRemaining;
    if (in.remaining() < readAmount) {
      log.debug("Chunk too small, buffering ({},{})", in.remaining(), readAmount);
      // skip the position back to the start
      in.position(position);
      state.bufferDecoding(headerLength + readAmount);
      return null;
    }
    BufferUtils.put(buf, in, readAmount);
    if (buf.position() < header.getSize()) {
      state.continueDecoding();
      return null;
    }
    if (buf.position() > header.getSize()) {
      log.warn("Packet size expanded from {} to {} ({})", new Object[] { (header.getSize()), buf.position(), header });
    }
    buf.flip();
    try {
      final IRTMPEvent message = decodeMessage(conn, packet.getHeader(), buf);
      message.setHeader(packet.getHeader());
      // Unfortunately flash will, especially when resetting a video stream with a new key frame, sometime
      // send an earlier time stamp.  To avoid dropping it, we just give it the minimal increment since the
      // last message.  But to avoid relative time stamps being mis-computed, we don't reset the header we stored.
      final Header lastReadHeader = rtmp.getLastReadPacketHeader(channelId);
      if (lastReadHeader != null && (message instanceof AudioData || message instanceof VideoData)
          && RTMPUtils.compareTimestamps(lastReadHeader.getTimer(), packet.getHeader().getTimer()) >= 0) {
        log.trace("Non-monotonically increasing timestamps; type: {}; adjusting to {}; ts: {}; last: {}", new Object[] { header.getDataType(),
            lastReadHeader.getTimer() + 1, header.getTimer(), lastReadHeader.getTimer() });
        message.setTimestamp(lastReadHeader.getTimer() + 1);
      } else {
        message.setTimestamp(header.getTimer());
      }
      rtmp.setLastReadPacketHeader(channelId, packet.getHeader());
      packet.setMessage(message);
      if (message instanceof ChunkSize) {
        ChunkSize chunkSizeMsg = (ChunkSize) message;
        rtmp.setReadChunkSize(chunkSizeMsg.getSize());
      } else if (message instanceof Abort) {
        log.debug("Abort packet detected");
View Full Code Here


    public void messageReceived(RTMPConnection conn, ProtocolState state, Object in) throws Exception {

    IRTMPEvent message = null;
    try {

      final Packet packet = (Packet) in;
      message = packet.getMessage();
      final Header header = packet.getHeader();
      final Channel channel = conn.getChannel(header.getChannelId());
      final IClientStream stream = conn.getStreamById(header
          .getStreamId());

      if (log.isDebugEnabled()) {
View Full Code Here

    }

    // Increase number of sent messages
    conn.messageSent((Packet) message);

    Packet sent = (Packet) message;
    final int channelId = sent.getHeader().getChannelId();
    final IClientStream stream = conn.getStreamByChannelId(channelId);
    // XXX we'd better use new event model for notification
    if (stream != null && (stream instanceof PlaylistSubscriberStream)) {
      ((PlaylistSubscriberStream) stream).written(sent.getMessage());
    }
  }
View Full Code Here

   *
     * @param channelId           Channel id
     * @param packet              Packet
     */
  public void setLastReadPacket(int channelId, Packet packet) {
    Packet prevPacket = readPackets.put(channelId, packet);
    if (prevPacket != null && prevPacket.getData() != null) {
      prevPacket.getData().release();
      prevPacket.setData(null);
    }
  }
View Full Code Here

 
  /** {@inheritDoc} */
    public void messageReceived(RTMPConnection conn, ProtocolState state, Object message) throws Exception {
    System.out.println("message received "+message);
    if(message instanceof Packet) {
      Packet p=(Packet)message;
      System.out.println("got packet "+p.getMessage());
    }
  }
View Full Code Here

      return;
    }

    try {

      final Packet packet = (Packet) in;
      final Object message = packet.getMessage();
      final Header source = packet.getHeader();

      log.debug("{}", source);
      log.debug("{}", message);

    } catch (RuntimeException e) {
View Full Code Here

     * @param streamId        Stream id
     */
    private void write(IRTMPEvent event, int streamId) {

    final Header header = new Header();
    final Packet packet = new Packet(header, event);

    header.setChannelId(id);
    header.setTimer(event.getTimestamp());
    header.setStreamId(streamId);
    header.setDataType(event.getDataType());
View Full Code Here

  }

  @Override
  public void messageReceived(RTMPConnection conn, ProtocolState state, Object in) throws Exception {
    IRTMPEvent message = null;
    final Packet packet = (Packet) in;
    message = packet.getMessage();
    final Header header = packet.getHeader();
    final Channel channel = conn.getChannel(header.getChannelId());

    // Increase number of received messages
    conn.messageReceived();
View Full Code Here

        // This is the response to an IConnection.ping request
        conn.pingReceived(ping);
        break;
      default:
        // forward other to origin
        Packet p = new Packet(source);
        p.setMessage(ping);
        forwardPacket(conn, p);
    }
  }
View Full Code Here

    } else {
      synchronized (rtmp) {
        // connect the origin
        sendConnectMessage(conn);
        rtmp.setState(RTMP.STATE_EDGE_CONNECT_ORIGIN_SENT);
        Packet packet = new Packet(header);
        packet.setMessage(invoke);
        forwardPacket(conn, packet);
        rtmp.setState(RTMP.STATE_ORIGIN_CONNECT_FORWARDED);
        // Evaluate request for AMF3 encoding
        if (Integer.valueOf(3).equals(params.get("objectEncoding"))
            && call instanceof IPendingServiceCall) {
View Full Code Here

TOP

Related Classes of org.red5.server.net.rtmp.message.Packet

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.