Package org.red5.server.net.rtmp.codec

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


  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

  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

  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

    //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

  }

  @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

     * @param state       Protocol state
     * @param in          Byte buffer with input raw data
     */
    private void rawBufferRecieved(RTMPConnection conn, ProtocolState state,
      ByteBuffer in) {
    final RTMP rtmp = (RTMP) state;

    if (rtmp.getState() != RTMP.STATE_HANDSHAKE) {
      log.warn("Raw buffer after handshake, something odd going on");
    }

    ByteBuffer out = ByteBuffer
        .allocate((Constants.HANDSHAKE_SIZE * 2) + 1);

    if (log.isDebugEnabled()) {
      log.debug("Writing handshake reply");
      log.debug("handskake size:" + in.remaining());
    }

    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).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);

    conn.rawWrite(out);
  }
View Full Code Here

     * Setter for RTMP events handler
     *
     * @param handler  Handler
     */
    void setRTMPTHandle(RTMPTHandler handler) {
    this.state = new RTMP(RTMP.MODE_SERVER);
    this.buffer = ByteBuffer.allocate(2048);
    this.buffer.setAutoExpand(true);
    this.handler = handler;
    this.decoder = handler.getCodecFactory().getSimpleDecoder();
    this.encoder = handler.getCodecFactory().getSimpleEncoder();
View Full Code Here

    RTMPConnection conn = rtmpConnManager.getConnection(clientId);
    if (conn == null) {
      log.debug("Client " + clientId + " is already closed.");
      return;
    }
    RTMP rtmpState = conn.getState();
    switch (mrtmpPacket.getHeader().getType()) {
      case MRTMPPacket.CLOSE:
        synchronized (rtmpState) {
          rtmpState.setState(RTMP.STATE_EDGE_DISCONNECTING);
        }
        conn.close();
        break;
      case MRTMPPacket.RTMP:
        RTMPHeader rtmpHeader = (RTMPHeader) mrtmpPacket.getHeader();
        RTMPBody rtmpBody = (RTMPBody) mrtmpPacket.getBody();
        boolean toDisconnect = false;
        synchronized (rtmpState) {
          if (rtmpState.getState() == RTMP.STATE_ORIGIN_CONNECT_FORWARDED &&
              rtmpHeader.getRtmpType() == TYPE_INVOKE) {
            // we got the connect invocation result from Origin
            // parse the result
            Invoke invoke = (Invoke) rtmpBody.getRtmpPacket().getMessage();
            if ("connect".equals(invoke.getCall().getServiceMethodName())) {
              if (invoke.getCall().getStatus() == Call.STATUS_SUCCESS_RESULT) {
                rtmpState.setState(RTMP.STATE_CONNECTED);
              } else {
                // TODO set EdgeRTMP state to closing ?
                toDisconnect = true;
              }
            }
          }
        }
        log.debug("Forward packet to client: {}", rtmpBody.getRtmpPacket().getMessage());
        // send the packet back to client
        conn.write(rtmpBody.getRtmpPacket());
        if (toDisconnect) {
          conn.close();
        }
        synchronized (rtmpState) {
          if (rtmpState.getState() == RTMP.STATE_CONNECTED) {
            conn.startRoundTripMeasurement();
          }
        }
        break;
      default:
View Full Code Here

            if ( !( event instanceof IRTMPEvent ) ) {
                logger.debug( "skipping non rtmp event: " + event );
                return;
            }

            IRTMPEvent rtmpEvent = (IRTMPEvent) event;

            if ( logger.isDebugEnabled() ) {
                // logger.debug("rtmp event: " + rtmpEvent.getHeader() + ", " +
                // rtmpEvent.getClass().getSimpleName());
            }

            if ( !( rtmpEvent instanceof IStreamData ) ) {
                logger.debug( "skipping non stream data" );
                return;
            }

            if ( rtmpEvent.getHeader().getSize() == 0 ) {
                logger.debug( "skipping event where size == 0" );
                return;
            }

            if ( rtmpEvent instanceof VideoData ) {
View Full Code Here

TOP

Related Classes of org.red5.server.net.rtmp.codec.RTMP

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.