@Override
 public void messageReceived(IoSession session, Object message) throws Exception {
   MRTMPPacket mrtmpPacket = (MRTMPPacket) message;
   int clientId = mrtmpPacket.getHeader().getClientId();
   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:
       conn.setStateCode(RTMP.STATE_EDGE_DISCONNECTING);
       conn.close();
       break;
     case MRTMPPacket.RTMP:
       RTMPHeader rtmpHeader = (RTMPHeader) mrtmpPacket.getHeader();
       RTMPBody rtmpBody = (RTMPBody) mrtmpPacket.getBody();
       boolean toDisconnect = false;
       // conn.getWriteLock().lock();
       try {
         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;
             }
           }
         }
       } finally {
         //	conn.getWriteLock().unlock();
       }
       log.debug("Forward packet to client: {}", rtmpBody.getRtmpPacket().getMessage());
       // send the packet back to client
       conn.write(rtmpBody.getRtmpPacket());
       if (toDisconnect) {
         conn.close();
       }
       //	conn.getWriteLock().lock();
       try {
         if (rtmpState.getState() == RTMP.STATE_CONNECTED) {
           conn.startRoundTripMeasurement();
         }
       } finally {
         //	conn.getWriteLock().unlock();
       }
       break;
     default:
       break;
   }
 }
 /** {@inheritDoc} */
 @Override
 protected void onChunkSize(
     RTMPConnection conn, Channel channel, Header source, ChunkSize chunkSize) {
   log.debug("onChunkSize");
   // set read and write chunk sizes
   RTMP state = conn.getState();
   state.setReadChunkSize(chunkSize.getSize());
   state.setWriteChunkSize(chunkSize.getSize());
   log.info("ChunkSize is not fully implemented: {}", chunkSize);
 }
Esempio n. 3
0
  protected void handleConnect(
      RTMPConnection conn, Channel channel, Header header, Invoke invoke, RTMP rtmp) {
    final IPendingServiceCall call = invoke.getCall();
    // Get parameters passed from client to NetConnection#connection
    final Map<String, Object> params = invoke.getConnectionParams();

    // Get hostname
    String host = getHostname((String) params.get("tcUrl"));

    // App name as path, but without query string if there is one
    String path = (String) params.get("app");
    if (path.indexOf("?") != -1) {
      int idx = path.indexOf("?");
      params.put("queryString", path.substring(idx));
      path = path.substring(0, idx);
    }
    params.put("path", path);

    final String sessionId = null;

    conn.setup(host, path, sessionId, params);

    // check the security constraints
    // send back "ConnectionRejected" if fails.
    if (!checkPermission(conn)) {
      call.setStatus(Call.STATUS_ACCESS_DENIED);
      call.setResult(getStatus(NC_CONNECT_REJECTED));
      Invoke reply = new Invoke();
      reply.setCall(call);
      reply.setInvokeId(invoke.getInvokeId());
      channel.write(reply);
      conn.close();
    } 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"))) {
          rtmp.setEncoding(Encoding.AMF3);
        }
      }
    }
  }
Esempio n. 4
0
 public void setStateCode(byte code) {
   getWriteLock().lock();
   try {
     state.setState(code);
   } finally {
     getWriteLock().unlock();
   }
 }
Esempio n. 5
0
 public byte getStateCode() {
   getReadLock().lock();
   try {
     return state.getState();
   } finally {
     getReadLock().unlock();
   }
 }
Esempio n. 6
0
 public void setStateCode(byte code) {
   state.setState(code);
 }
Esempio n. 7
0
 public byte getStateCode() {
   return state.getState();
 }