Examples of RTMP


Examples of org.red5.server.net.rtmp.codec.RTMP

  @Override
  public void messageReceived(NextFilter nextFilter, IoSession session, Object obj) throws Exception {
    String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
    log.trace("Session id: {}", sessionId);
    RTMPMinaConnection conn = (RTMPMinaConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId);   
    RTMP rtmp = conn.getState();
    //if there is a handshake on the session, ensure the type has been set
    if (session.containsAttribute(RTMPConnection.RTMP_HANDSHAKE)) {
      log.trace("Handshake exists on the session");
      //get the handshake from the session
      RTMPHandshake handshake = (RTMPHandshake) session.getAttribute(RTMPConnection.RTMP_HANDSHAKE);
      int handshakeType = handshake.getHandshakeType();
      if (handshakeType == 0) {
        log.trace("Handshake type is not currently set");
        // holds the handshake type, default is un-encrypted
        byte handshakeByte = RTMPConnection.RTMP_NON_ENCRYPTED;
        //get the current message
        if (obj instanceof IoBuffer) {
          IoBuffer message = (IoBuffer) obj;
          message.mark();
          handshakeByte = message.get();
          message.reset();
        }
        //set the type
        handshake.setHandshakeType(handshakeByte);
        //set on the rtmp state
        rtmp.setEncrypted(handshakeByte == RTMPConnection.RTMP_ENCRYPTED ? true : false);
      } else if (handshakeType == 3) {
        if (rtmp.getState() == RTMP.STATE_CONNECTED) {
          log.debug("In connected state");
          // remove handshake from session now that we are connected
          session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE);
          log.debug("Using non-encrypted communications");
        }
      } else if (handshakeType == 6) {
        // ensure we have received enough bytes to be encrypted
        long readBytesCount = conn.getReadBytes();
        long writeBytesCount = conn.getWrittenBytes();
        log.trace("Bytes read: {} written: {}", readBytesCount, writeBytesCount);
        // don't remove the handshake when using RTMPE until we've written all the handshake data
        if (writeBytesCount >= (Constants.HANDSHAKE_SIZE * 2)) {
          //if we are connected and doing encryption, add the ciphers
          log.debug("Assumed to be in a connected state");
          // remove handshake from session now that we are connected
          session.removeAttribute(RTMPConnection.RTMP_HANDSHAKE);
          log.debug("Using encrypted communications");
          //make sure they are not already on the session
          if (session.containsAttribute(RTMPConnection.RTMPE_CIPHER_IN)) {
            log.debug("Ciphers already exist on the session");
          } else {
            log.debug("Adding ciphers to the session");
            session.setAttribute(RTMPConnection.RTMPE_CIPHER_IN, handshake.getCipherIn());
            session.setAttribute(RTMPConnection.RTMPE_CIPHER_OUT, handshake.getCipherOut());
          }         
        }
      }
    }
    Cipher cipher = (Cipher) session.getAttribute(RTMPConnection.RTMPE_CIPHER_IN);
    if (cipher != null) { //may want to verify handshake is complete as well
      // assume message is an IoBuffer
      IoBuffer message = (IoBuffer) obj;
      if (rtmp.getState() == RTMP.STATE_HANDSHAKE) {
        // ensure there are enough bytes to skip
        if (message.limit() > Constants.HANDSHAKE_SIZE) {
            //skip the first 1536
            byte[] handshakeReply = new byte[Constants.HANDSHAKE_SIZE];
            message.get(handshakeReply);
            // TODO verify reply, for now just set to connected
            rtmp.setState(RTMP.STATE_CONNECTED);
        } else {
          log.warn("There may be a network issue on this RTMPE connection: {}", conn);
          return;
        }
      }
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

  @Override
  protected void onChunkSize(RTMPConnection conn, Channel channel, Header source, ChunkSize chunkSize) {
    int requestedChunkSize = chunkSize.getSize();
    log.debug("Chunk size: {}", requestedChunkSize);
    // set chunk size on the connection
    RTMP state = conn.getState();
    // set only the read chunk size since it came from the client
    state.setReadChunkSize(requestedChunkSize);
    //state.setWriteChunkSize(requestedChunkSize);
    // set on each of the streams
    for (IClientStream stream : conn.getStreams()) {
      if (stream instanceof IClientBroadcastStream) {
        IClientBroadcastStream bs = (IClientBroadcastStream) stream;
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

      ByteBuffer cap = ByteBuffer.wrap(capMappedFile);
      ByteBuffer in = ByteBuffer.wrap(rawMappedFile);

      boolean serverMode = (cap.get() == (byte) 0x01);
      out.write("Mode: " + (serverMode ? "UPSTREAM" : "DOWNSTREAM"));
      RTMP state = new RTMP(serverMode);
      int id = 0;
      try {

        int nextTimePos = 0;
        long time = 0;
        long offset = -1;
        long read = 0;

        try {
          while (true) {

            while (in.position() >= nextTimePos) {

              if (cap.remaining() >= 12) {

                time = cap.getLong();
                if (offset == -1) {
                  offset = time;
                }
                time -= offset;

                read = cap.getInt();
                nextTimePos += read;

                out.write("<div class=\"time\">TIME: " + time
                    + " READ: " + read + "</div>");
              }

            }

            final int remaining = in.remaining();
            if (state.canStartDecoding(remaining)) {
              state.startDecoding();
            } else {
              break;
            }

            final Object decodedObject = decoder.decode(state, in);

            if (state.hasDecodedObject()) {
              // log.debug(decodedObject);

              if (decodedObject instanceof Packet) {
                out.write(formatHTML((Packet) decodedObject,
                    id++, 0));
              } else if (decodedObject instanceof ByteBuffer) {
                ByteBuffer buf = (ByteBuffer) decodedObject;
                out
                    .write("<div class=\"handshake\"><pre>"
                        + HexDump.formatHexDump(buf
                            .getHexDump())
                        + "</pre></div>");
              }
            } else if (state.canContinueDecoding()) {
              continue;
            } else {
              break;
            }
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

     * @param session      I/O session, that is, connection between two endpoints
     */
    protected void rawBufferRecieved(ProtocolState state, ByteBuffer in,
      IoSession session) {

    final RTMP rtmp = (RTMP) state;
    if (rtmp.getMode() == RTMP.MODE_SERVER) {
      if (rtmp.getState() != RTMP.STATE_HANDSHAKE) {
        log.warn("Raw buffer after handshake, something odd going on");
      }
      log.debug("Handshake 2nd phase - size: {}", in.remaining());
      ByteBuffer out = ByteBuffer.allocate((Constants.HANDSHAKE_SIZE*2)+1);
      out.put((byte)0x03);
      // TODO: the first four bytes of the handshake reply seem to be the
      //       server uptime - send something better here...
      out.putInt(0x01);
      out.fill((byte)0x00,Constants.HANDSHAKE_SIZE-4);
      out.put(in);
      out.flip();
      // Skip first 8 bytes when comparing the handshake, they seem to
      // be changed when connecting from a Mac client.
      rtmp.setHandshake(out, 9, Constants.HANDSHAKE_SIZE-8);
      //in.release();
      session.write(out);
    } else {
      log.debug("Handshake 3d phase - size: {}", in.remaining());
      in.skip(1);
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

  /** {@inheritDoc} */
    @Override
  public void sessionOpened(IoSession session) throws Exception {    
    super.sessionOpened(session);

    RTMP rtmp=(RTMP)session.getAttribute(ProtocolState.SESSION_KEY);
    if (rtmp.getMode()==RTMP.MODE_CLIENT) {
      if (log.isDebugEnabled()){
        log.debug("Handshake 1st phase");
      }
      ByteBuffer out = ByteBuffer.allocate(Constants.HANDSHAKE_SIZE+1);
      out.put((byte)0x03);
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

  public void sessionClosed(IoSession session) throws Exception {
    ByteBuffer buf = (ByteBuffer) session.getAttribute("buffer");
    if (buf != null) {
      buf.release();
    }
    final RTMP rtmp = (RTMP) session
        .getAttribute(ProtocolState.SESSION_KEY);
    final RTMPMinaConnection conn = (RTMPMinaConnection) session
        .getAttachment();
    this.handler.connectionClosed(conn, rtmp);
    session.removeAttribute(ProtocolState.SESSION_KEY);
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

  public void sessionCreated(IoSession session) throws Exception {
    if (log.isDebugEnabled()) {
      log.debug("Session created");
    }
    // moved protocol state from connection object to RTMP object
    RTMP rtmp = new RTMP(mode);
    session.setAttribute(ProtocolState.SESSION_KEY, rtmp);
    session.getFilterChain().addFirst("protocolFilter",
        new ProtocolCodecFilter(this.codecFactory));
    if (log.isDebugEnabled()) {
      session.getFilterChain().addLast("logger", new LoggingFilter());
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

  public RTMPOriginConnection(String type, int clientId, int ioSessionId) {
    super(type);
    setId(clientId);
    this.ioSessionId = ioSessionId;
    state = new RTMP(RTMP.MODE_SERVER);
    state.setState(RTMP.STATE_CONNECTED);
  }
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

    //session.getConfig();

    if (log.isDebugEnabled()) {
      log.debug("Is downstream: " + isClient);

      session.setAttribute(ProtocolState.SESSION_KEY, new RTMP(isClient));

      session.getFilterChain().addFirst("protocol",
          new ProtocolCodecFilter(codecFactory));
    }
View Full Code Here

Examples of org.red5.server.net.rtmp.codec.RTMP

  }

  @Override
  public void close() {
    boolean needNotifyOrigin = false;
    RTMP state = getState();
    synchronized (state) {
      if (state.getState() == RTMP.STATE_CONNECTED) {
        needNotifyOrigin = true;
        // now we are disconnecting ourselves
        state.setState(RTMP.STATE_EDGE_DISCONNECTING);
      }
    }
    if (needNotifyOrigin) {
      IMRTMPConnection conn = mrtmpManager.lookupMRTMPConnection(this);
      if (conn != null) {
        conn.disconnect(getId());
      }
    }
    synchronized (state) {
      if (state.getState() == RTMP.STATE_DISCONNECTED) {
        return;
      } else {
        state.setState(RTMP.STATE_DISCONNECTED);
      }
    }
    super.close();
  }
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.