Package org.red5.server.net.rtmp

Examples of org.red5.server.net.rtmp.RTMPConnection$KeepAliveTask


          buf.putInt(timer);
          header.setExtendedTimestamp(timer);
        }
        header.setTimerBase(timer);
        header.setTimerDelta(0);
        RTMPConnection conn = (RTMPConnection) Red5.getConnectionLocal();
        if (conn != null) {
          conn.getState().setLastFullTimestampWritten(header.getChannelId(), timer);
        }
        break;
      case HEADER_SAME_SOURCE:
        timer = (int) RTMPUtils.diffTimestamps(header.getTimer(), lastHeader.getTimer());
        if (timer < 0 || timer >= 0xffffff) {
View Full Code Here


  /** {@inheritDoc} */
    public IMessageOutput getConsumerOutput(IClientStream stream) {
    IStreamCapableConnection streamConn = stream.getConnection();
    if (streamConn != null && streamConn instanceof RTMPConnection) {
      RTMPConnection conn = (RTMPConnection) streamConn;
      // TODO Better manage channels.
      // now we use OutputStream as a channel wrapper.
      OutputStream o = conn.createOutputStream(stream.getStreamId());
      IPipe pipe = new InMemoryPushPushPipe();
      pipe.subscribe(new ConnectionConsumer(conn, o.getVideo(), o.getAudio(), o.getData()), null);
      return pipe;
    }
    return null;
View Full Code Here

        events.addAll(ownerEvents);
        ownerEvents.removeAll(events);
      }
      // send update to "owner" of this update request
      if (source != null) {
        final RTMPConnection con = (RTMPConnection) source;
        // create a worker
        SharedObjectService.submitTask(new Runnable() {
          public void run() {
            Red5.setConnectionLocal(con);
            con.sendSharedObjectMessage(name, currentVersion, persistent, events);
            Red5.setConnectionLocal(null);
          }
        });
      }
    }
    // tell all the listeners
    if (!syncEvents.isEmpty()) {
      // get all current sync events
      final ConcurrentLinkedQueue<ISharedObjectEvent> events = new ConcurrentLinkedQueue<ISharedObjectEvent>();
      if (syncEvents.size() > SharedObjectService.MAXIMUM_EVENTS_PER_UPDATE) {
        log.debug("Sync events exceed max: {}", syncEvents.size());
        for (int i = 0; i < SharedObjectService.MAXIMUM_EVENTS_PER_UPDATE; i++) {
          events.add(syncEvents.poll());
        }
      } else {
        events.addAll(syncEvents);
        syncEvents.removeAll(events);
      }
      // get the listeners
      Set<IEventListener> listeners = getListeners();
      if (log.isDebugEnabled()) {
        log.debug("Listeners: {}", listeners);
      }
      // updates all registered clients of this shared object
      for (IEventListener listener : listeners) {
        if (listener != source) {
          if (listener instanceof RTMPConnection) {
            final RTMPConnection con = (RTMPConnection) listener;
            if (con.getStateCode() == RTMP.STATE_CONNECTED) {
                // create a worker
                SharedObjectService.submitTask(new Runnable() {
                  public void run() {
                    Red5.setConnectionLocal(con);
                    con.sendSharedObjectMessage(name, currentVersion, persistent, events);
                    Red5.setConnectionLocal(null);
                  }
                });
            } else {
              log.debug("Skipping unconnected connection");
View Full Code Here

  /** {@inheritDoc} */
  public void encode(IoSession session, Object message, ProtocolEncoderOutput out) throws ProtocolCodecException {
    // get the connection from the session
    String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
    log.trace("Session id: {}", sessionId);
    RTMPConnection conn = (RTMPConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId);   
    if (conn != null) {
      // look for and compare the connection local; set it from the session
      if (!conn.equals((RTMPConnection) Red5.getConnectionLocal())) {
        log.debug("Connection local ({}) didn't match io session ({})", (Red5.getConnectionLocal() != null ? Red5.getConnectionLocal().getSessionId() : "null"), sessionId);
        Red5.setConnectionLocal(conn);
      }
      final Semaphore lock = conn.getEncoderLock();
      try {
        // acquire the decoder lock
        log.trace("Encoder lock acquiring.. {}", conn.getSessionId());
        lock.acquire();
        log.trace("Encoder lock acquired {}", conn.getSessionId());
        // get the buffer
        final IoBuffer buf = message instanceof IoBuffer ? (IoBuffer) message : encoder.encode(message);
        if (buf != null) {
          int requestedWriteChunkSize = conn.getState().getWriteChunkSize();
          log.trace("Requested chunk size: {} target chunk size: {}", requestedWriteChunkSize, targetChunkSize);
          if (buf.remaining() <= targetChunkSize * 2) {
            log.trace("Writing output data");
            out.write(buf);
          } else {
            /*
            LinkedList<IoBuffer> chunks = Chunker.chunk(buf, requestedWriteChunkSize, targetChunkSize);
            log.trace("Writing output data in {} chunks", chunks.size());
            for (IoBuffer chunk : chunks) {
              out.write(chunk);
            }
            chunks.clear();
            chunks = null;
            */
            int sentChunks = Chunker.chunkAndWrite(out, buf, requestedWriteChunkSize, targetChunkSize);
            log.trace("Wrote {} chunks", sentChunks);
          }
        } else {
          log.trace("Response buffer was null after encoding");
        }
        //      WriteFuture future = out.flush();
        //      if (future != null) {
        //        future.addListener(new IoFutureListener<WriteFuture>() {
        //          @Override
        //          public void operationComplete(WriteFuture future) {
        //            //log.debug("Buffer freed");
        //            buf.free();
        //          }
        //        });
        //      }
      } catch (Exception ex) {
        log.error("Exception during encode", ex);
      } finally {
        log.trace("Encoder lock releasing.. {}", conn.getSessionId());
        lock.release();
      }
    } else {
      log.debug("Connection is no longer available for encoding, may have been closed already");
    }
View Full Code Here

    buf.flip();
    // get the connection from the session
    String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
    log.trace("Session id: {}", sessionId);
    // connection verification routine
    RTMPConnection conn = (RTMPConnection) RTMPConnManager.getInstance().getConnectionBySessionId(sessionId);   
    RTMPConnection connLocal = (RTMPConnection) Red5.getConnectionLocal();
    if (connLocal == null || !conn.getSessionId().equals(connLocal.getSessionId())) {
      if (log.isDebugEnabled() && connLocal != null) {
        log.debug("Connection local didn't match session");
      }
    }
    // set the connection to local if its referred to by this session
View Full Code Here

    event.setCall(call);
    Header header = new Header();
    Packet packet = new Packet(header, event);
    header.setDataType(event.getDataType());
    // create dummy connection if local is empty
    RTMPConnection conn = (RTMPConnection) Red5.getConnectionLocal();
    if (conn == null) {
      try {
        conn = ((RTMPConnManager) manager).createConnectionInstance(RTMPTConnection.class);
        Red5.setConnectionLocal(conn);
      } catch (Exception e) {
View Full Code Here

    public IMessageOutput getConsumerOutput(IClientStream stream) {
    IStreamCapableConnection streamConn = stream.getConnection();
    if (streamConn == null || !(streamConn instanceof RTMPConnection)) {
      return null;
    }
    RTMPConnection conn = (RTMPConnection) streamConn;
    // TODO Better manage channels.
    // now we use OutputStream as a channel wrapper.
    OutputStream o = conn.createOutputStream(stream.getStreamId());
    IPipe pipe = new InMemoryPushPushPipe();
    pipe.subscribe(new ConnectionConsumer(conn, o.getVideo().getId(), o
        .getAudio().getId(), o.getData().getId()), null);
    return pipe;
  }
View Full Code Here

  public boolean unregisterConnection(IMRTMPConnection conn) {
    boolean ret = connList.remove(conn);
    if (ret) {
      Collection<RTMPConnection> rtmpConns = rtmpConnManager.removeConnections();
      for (Iterator<RTMPConnection> iter = rtmpConns.iterator(); iter.hasNext(); ) {
        RTMPConnection rtmpConn = iter.next();
        rtmpConn.close();
      }
    }
    return ret;
  }
View Full Code Here

  @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:
        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:
        break;
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.RTMPConnection$KeepAliveTask

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.