org.red5.server.api.Red5 Java Examples

The following examples show how to use org.red5.server.api.Red5. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ServerClientDetection.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
private void callBWCheck(Object payload) {
    if (log.isTraceEnabled()) {
        log.trace("callBWCheck: {}", payload);
    } else {
        log.debug("callBWCheck");
    }
    IConnection conn = Red5.getConnectionLocal();
    Map<String, Object> statsValues = new HashMap<String, Object>();
    statsValues.put("count", packetsReceived.get());
    statsValues.put("sent", packetsSent.get());
    statsValues.put("timePassed", timePassed);
    statsValues.put("latency", latency);
    statsValues.put("cumLatency", cumLatency);
    statsValues.put("payload", payload);
    if (conn instanceof IServiceCapableConnection) {
        log.debug("Invoking onBWCheck on the client");
        // increment sent counter
        packetsSent.incrementAndGet();
        // invoke on the client
        ((IServiceCapableConnection) conn).invoke("onBWCheck", new Object[] { statsValues }, this);
    }
}
 
Example #2
Source File: ReceivedMessageTask.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
public Packet call() throws Exception {
    //keep a ref for executor thread
    taskThread = Thread.currentThread();
    // set connection to thread local
    Red5.setConnectionLocal(conn);
    try {
        // pass message to the handler
        handler.messageReceived(conn, packet);
        // if we get this far, set done / completed flag
        packet.setProcessed(true);
    } finally {
        // clear thread local
        Red5.setConnectionLocal(null);
    }
    if (log.isDebugEnabled()) {
        log.debug("Processing message for {} is processed: {} packet #{}", sessionId, packet.isProcessed(), packetNumber);
    }
    return packet;
}
 
Example #3
Source File: DemoService.java    From red5-examples with Apache License 2.0 6 votes vote down vote up
/**
 * Getter for property 'listOfAvailableFLVs'.
 *
 * @return Value for property 'listOfAvailableFLVs'.
 */
public Map<String, Map<String, Object>> getListOfAvailableFLVs() {
    IScope scope = Red5.getConnectionLocal().getScope();
    Map<String, Map<String, Object>> filesMap = new HashMap<String, Map<String, Object>>();
    try {
        log.debug("Getting the media files");
        addToMap(filesMap, scope.getResources("streams/*.flv"));
        addToMap(filesMap, scope.getResources("streams/*.f4v"));
        addToMap(filesMap, scope.getResources("streams/*.mp3"));
        addToMap(filesMap, scope.getResources("streams/*.mp4"));
        addToMap(filesMap, scope.getResources("streams/*.m4a"));
        addToMap(filesMap, scope.getResources("streams/*.3g2"));
        addToMap(filesMap, scope.getResources("streams/*.3gp"));
    } catch (IOException e) {
        log.error("", e);
    }
    return filesMap;
}
 
Example #4
Source File: ServerClientDetection.java    From red5-examples with Apache License 2.0 6 votes vote down vote up
private void callBWCheck(Object payload)
{
	IConnection conn = Red5.getConnectionLocal();
	

	Map<String, Object> statsValues = new HashMap<String, Object>();
	statsValues.put("count", this.count);
	statsValues.put("sent", this.sent);
	statsValues.put("timePassed", this.timePassed);
	statsValues.put("latency", this.latency);
	statsValues.put("cumLatency", this.cumLatency);
	statsValues.put("payload", payload);
	
	if (conn instanceof IServiceCapableConnection) {
		((IServiceCapableConnection) conn).invoke("onBWCheck", new Object[]{statsValues}, this);
	}
}
 
Example #5
Source File: BandwidthChecker.java    From red5-rtsp-restreamer with Apache License 2.0 6 votes vote down vote up
public void packetReceived(IBroadcastStream arg0, IStreamPacket packet) {

		if (done) {
			arg0.removeStreamListener(this);
			return;
		}

		messages = Red5.getConnectionLocal().getWrittenMessages() + Red5.getConnectionLocal().getReadMessages();

		bytesUp = Red5.getConnectionLocal().getReadBytes();

		bytesDown = Red5.getConnectionLocal().getWrittenBytes();

		if (packet instanceof Notify) {

			endpoint().invoke("onBWChunk", new Object[] { chunk });
			chunks++;
			//  Input reader = new Input(((Notify)packet).getData()); 
			//  reader.readDataType();//string
			//  String  method=reader.readString(null);
			//  reader.readDataType();//object
			//  Map invokeData=  (Map) reader.readMap(new Deserializer(), null);            
			//  System.out.println(method+""+invokeData.get("data").toString());	
		}
	}
 
Example #6
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void seek(int position) {
    log.trace("seek - position:{}", position);
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
        IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
        Number streamId = conn.getStreamId();
        IClientStream stream = streamConn.getStreamById(streamId);
        if (stream != null && stream instanceof ISubscriberStream) {
            ISubscriberStream subscriberStream = (ISubscriberStream) stream;
            try {
                subscriberStream.seek(position);
            } catch (OperationNotSupportedException err) {
                sendNSFailed(streamConn, StatusCodes.NS_SEEK_FAILED, "The stream doesn't support seeking.", stream.getName(), streamId);
            }
        }
    }
}
 
Example #7
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void publish(Boolean dontStop) {
    // null is as good as false according to Boolean.valueOf() so if null, interpret as false
    if (dontStop == null || !dontStop) {
        IConnection conn = Red5.getConnectionLocal();
        if (conn instanceof IStreamCapableConnection) {
            IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
            Number streamId = conn.getStreamId();
            IClientStream stream = streamConn.getStreamById(streamId);
            if (stream instanceof IBroadcastStream) {
                IBroadcastStream bs = (IBroadcastStream) stream;
                if (bs.getPublishedName() != null) {
                    IBroadcastScope bsScope = getBroadcastScope(conn.getScope(), bs.getPublishedName());
                    if (bsScope != null) {
                        bsScope.unsubscribe(bs.getProvider());
                        if (conn instanceof BaseConnection) {
                            ((BaseConnection) conn).unregisterBasicScope(bsScope);
                        }
                    }
                    bs.close();
                    streamConn.deleteStreamById(streamId);
                }
            }
        }
    }
}
 
Example #8
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/**
 * Pause at given position. Required as "pausePlayback" can be "null" if no flag is passed by the client
 * 
 * @param pausePlayback
 *            Pause playback or not
 * @param position
 *            Pause position
 */
public void pause(Boolean pausePlayback, int position) {
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
        IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
        Number streamId = conn.getStreamId();
        IClientStream stream = streamConn.getStreamById(streamId);
        if (stream != null && stream instanceof ISubscriberStream) {
            ISubscriberStream subscriberStream = (ISubscriberStream) stream;
            // pausePlayback can be "null" if "pause" is called without any parameters from flash
            if (pausePlayback == null) {
                pausePlayback = !subscriberStream.isPaused();
            }
            if (pausePlayback) {
                subscriberStream.pause(position);
            } else {
                subscriberStream.resume(position);
            }
        }
    }
}
 
Example #9
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public Number createStream(Number streamId) {
    IConnection conn = Red5.getConnectionLocal();
    log.trace("createStream stream id: {} connection: {}", streamId, conn.getSessionId());
    if (conn instanceof IStreamCapableConnection) {
        try {
            if (streamId.intValue() > 0) {
                streamId = ((IStreamCapableConnection) conn).reserveStreamId(streamId);
            } else {
                streamId = ((IStreamCapableConnection) conn).reserveStreamId();
            }
            if (log.isTraceEnabled()) {
                log.trace("Stream id: {} created for {}", streamId, conn.getSessionId());
            }
            return streamId;
        } catch (IndexOutOfBoundsException e) {
            log.error("Unable to create stream", e);
        }
    }
    return -1;
}
 
Example #10
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public Number createStream() {
    IConnection conn = Red5.getConnectionLocal();
    log.trace("createStream connection: {}", conn.getSessionId());
    if (conn instanceof IStreamCapableConnection) {
        try {
            Number streamId = ((IStreamCapableConnection) conn).reserveStreamId();
            if (log.isTraceEnabled()) {
                log.trace("Stream id: {} created for {}", streamId, conn.getSessionId());
            }
            return streamId;
        } catch (IndexOutOfBoundsException e) {
            log.error("Unable to create stream", e);
        }
    }
    return -1;
}
 
Example #11
Source File: RTMPClientProtocolDecoderTest.java    From red5-client with Apache License 2.0 6 votes vote down vote up
@Test
public void testDecodeBufferExTS() {
    //log.debug("\testDecodeBufferExTS");
    RTMPProtocolDecoder dec = new RTMPProtocolDecoder();
    RTMPConnection conn = new RTMPMinaConnection();
    Red5.setConnectionLocal(conn);
    RTMP rtmp = conn.getState();
    rtmp.setState(RTMP.STATE_CONNECTED);
    // lastHeader: Header [streamId=1, channelId=4, dataType=18, timerBase=0, timerDelta=0, size=309, extended=false]
    // get the local decode state
    RTMPDecodeState state = conn.getDecoderState();
    // meta and audio 4x chunks
    IoBuffer in = IoBuffer.wrap(IOUtils.hexStringToByteArray(
            "04000000000135120100000002000d40736574446174614672616d6502000a6f6e4d65746144617461080000000d00086475726174696f6e0040d518000000000000057769647468004064000000000000000668656967687400405e000000000000000d766964656f64617461726174650040686a000000000000096672616d657261746500403900000000c40000000c766964656f636f6465636964004000000000000000000d617564696f6461746172617465000000000000000000000f617564696f73616d706c65726174650040d5888000000000000f617564696f73616d706c6573697a65004030000000000000000673746572656f0100000c617564696f636f6465636964004000c40000000000000007656e636f64657202000d4c61766635362e31352e313032000866696c6573697a650000000000000000000000090400000000006908010000002afff340c400104002e62d4110009080200830107ea04cfa810710e0987f820ec130fc401897c1c0c70ff502008020eea04c1f0fe7fcb9fc10ff90d107c1f82008021feb07c1c04010041c20f89c1fff6b6edad93d99d8da6cd42a08e459095589d4b5fb9a4e679a1f4400001a00006a082afff342c41a19c91f225d89300055a47640c62cee7ccc85c08c42cadb6b56daebe65989f78c3ef3cfbd694ac0c34aa855ee0598a031f0a0686212d43631a4c59a926383c2d5201c5e9b7377"));
    Packet packet = null;
    do {
        packet = dec.decodePacket(conn, state, in);
    } while (packet == null);
    assertNotNull(packet);
    assertTrue(packet.getMessage() instanceof Notify);
    do {
        packet = dec.decodePacket(conn, state, in);
    } while (packet == null);
    assertNotNull(packet);
    assertTrue(packet.getMessage() instanceof AudioData);
}
 
Example #12
Source File: StreamService.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
/** {@inheritDoc} */
public void initStream(Number streamId) {
    IConnection conn = Red5.getConnectionLocal();
    log.info("initStream stream id: {} current stream id: {} connection: {}", streamId, conn.getStreamId(), conn.getSessionId());
    if (conn instanceof IStreamCapableConnection) {
        ((IStreamCapableConnection) conn).reserveStreamId(streamId);
        IClientStream stream = ((IStreamCapableConnection) conn).getStreamById(streamId);
        if (stream != null) {
            if (stream instanceof IClientBroadcastStream) {
                IClientBroadcastStream bs = (IClientBroadcastStream) stream;
                IBroadcastScope bsScope = getBroadcastScope(conn.getScope(), bs.getPublishedName());
                if (bsScope != null && conn instanceof BaseConnection) {
                    ((BaseConnection) conn).unregisterBasicScope(bsScope);
                }
            }
            stream.close();
        }
        ((IStreamCapableConnection) conn).deleteStreamById(streamId);
    } else {
        log.warn("ERROR in initStream, connection is not stream capable");
    }
}
 
Example #13
Source File: ServerClientDetection.java    From red5-server-common with Apache License 2.0 6 votes vote down vote up
private void callBWDone() {
    log.debug("callBWDone");
    IConnection conn = Red5.getConnectionLocal();
    Map<String, Object> statsValues = new HashMap<String, Object>();
    statsValues.put("kbitDown", kbitDown);
    statsValues.put("deltaDown", deltaDown);
    statsValues.put("deltaTime", deltaTime);
    statsValues.put("latency", latency);
    if (conn instanceof IServiceCapableConnection) {
        log.debug("Invoking onBWDone on the client");
        // invoke on the client
        ((IServiceCapableConnection) conn).invoke("onBWDone", new Object[] { statsValues });
        // adjust bandwidth to mbit/s
        int mbits = (int) ((kbitDown / 1000d) * 1000000);
        log.debug("Setting bandwidth to {} mbit/s", mbits);
        // tell the flash player how fast we want data and how fast we shall send it
        conn.setBandwidth(mbits);
    }
}
 
Example #14
Source File: ServerClientDetection.java    From red5-examples with Apache License 2.0 5 votes vote down vote up
private IStreamCapableConnection getStats()
{
	IConnection conn = Red5.getConnectionLocal();
	if (conn instanceof IStreamCapableConnection) {
		return (IStreamCapableConnection) conn;
	}
	return null;
}
 
Example #15
Source File: AbstractScopeAdapter.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/**
 * Calls the checkBandwidthUp method on the current client.
 * 
 * @param params
 *            Object passed from Flash
 * @return bandwidth results map
 */
public Map<String, Object> checkBandwidthUp(Object[] params) {
    //Incoming object should be null
    IClient client = Red5.getConnectionLocal().getClient();
    if (client != null) {
        return client.checkBandwidthUp(params);
    }
    return null;
}
 
Example #16
Source File: StreamService.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void receiveVideo(boolean receive) {
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
        IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
        Number streamId = conn.getStreamId();
        IClientStream stream = streamConn.getStreamById(streamId);
        if (stream != null && stream instanceof ISubscriberStream) {
            ISubscriberStream subscriberStream = (ISubscriberStream) stream;
            subscriberStream.receiveVideo(receive);
        }
    }
}
 
Example #17
Source File: Client.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void checkBandwidth() {
    log.debug("Check bandwidth");
    bandwidthChecked = true;
    //do something to check the bandwidth, Dan what do you think?
    ServerClientDetection detection = new ServerClientDetection();
    detection.checkBandwidth(Red5.getConnectionLocal());
}
 
Example #18
Source File: StreamService.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void play(Boolean dontStop) {
    log.debug("Play without stop: {}", dontStop);
    if (!dontStop) {
        IConnection conn = Red5.getConnectionLocal();
        if (conn instanceof IStreamCapableConnection) {
            IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
            Number streamId = conn.getStreamId();
            IClientStream stream = streamConn.getStreamById(streamId);
            if (stream != null) {
                stream.stop();
            }
        }
    }
}
 
Example #19
Source File: StreamService.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
public void receiveAudio(boolean receive) {
    IConnection conn = Red5.getConnectionLocal();
    if (conn instanceof IStreamCapableConnection) {
        IStreamCapableConnection streamConn = (IStreamCapableConnection) conn;
        Number streamId = conn.getStreamId();
        IClientStream stream = streamConn.getStreamById(streamId);
        if (stream != null && stream instanceof ISubscriberStream) {
            ISubscriberStream subscriberStream = (ISubscriberStream) stream;
            subscriberStream.receiveAudio(receive);
        }
    }
}
 
Example #20
Source File: MultiThreadedApplicationAdapter.java    From red5-server-common with Apache License 2.0 5 votes vote down vote up
public void streamPlayItemStop(ISubscriberStream stream, IPlayItem item) {
    // since there is a fair amount of processing below we will check log
    // level prior to proceeding
    if (log.isInfoEnabled()) {
        // log w3c connect event
        String remoteAddress = "";
        long readBytes = -1;
        long writtenBytes = -1;
        IConnection conn = Red5.getConnectionLocal();
        if (conn != null) {
            remoteAddress = conn.getRemoteAddress();
            readBytes = conn.getReadBytes();
            writtenBytes = conn.getWrittenBytes();
        }
        long playDuration = -1;
        if (stream instanceof PlaylistSubscriberStream) {
            // converted to seconds
            playDuration = (System.currentTimeMillis() - ((PlaylistSubscriberStream) stream).getCreationTime()) / 1000;
        }
        long playItemSize = -1;
        String playItemName = "";
        if (item != null) {
            playItemName = item.getName();
            //get file size in bytes if available
            IProviderService providerService = (IProviderService) scope.getContext().getBean(IProviderService.BEAN_NAME);
            if (providerService != null) {
                File file = providerService.getVODProviderFile(scope, playItemName);
                if (file != null) {
                    playItemSize = file.length();
                } else {
                    log.debug("File was null, this is ok for live streams");
                }
            } else {
                log.debug("ProviderService was null");
            }
        }
        log.info("W3C x-category:stream x-event:stop c-ip:{} cs-bytes:{} sc-bytes:{} x-sname:{} x-file-length:{} x-file-size:{} x-name:{}", new Object[] { remoteAddress, readBytes, writtenBytes, stream.getName(), playDuration, playItemSize, playItemName });
    }
}
 
Example #21
Source File: Application.java    From red5-hls-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void streamPublishStart(final IBroadcastStream stream) {
	final String streamName = stream.getPublishedName();
	log.debug("streamPublishStart - stream name: {}", streamName);
	IConnection conn = Red5.getConnectionLocal();
	// save the record / stream name
	conn.setAttribute("streamName", streamName);
	super.streamPublishStart(stream);
	if (stream instanceof ClientBroadcastStream) {					
		Thread creator = new Thread(new Runnable() {
			public void run() {
				while (scope.getBroadcastScope(streamName) == null) {
					log.debug("Stream: {} is not available yet...", streamName);
					try {
						Thread.sleep(500L);
					} catch (InterruptedException e) {
					}
				}
				// get the segmenter
				SegmenterService segmenter = (SegmenterService) applicationContext.getBean("segmenter.service");
				// check that the stream is not already being segmented
				if (!segmenter.isAvailable(streamName)) {
					// start segmenting utilizing included RTMP reader
					segmenter.start(scope, stream, true);
				}					
			}
		});
		creator.setDaemon(true);
		creator.start();
	}		
}
 
Example #22
Source File: AbortTranscodeCommand.java    From poor-man-transcoder with GNU General Public License v2.0 5 votes vote down vote up
@Override
public boolean execute(Context context) throws Exception {
	// TODO Auto-generated method stub
	TranscoderContext ctx = (TranscoderContext) context;
	TranscodeSessionPool pool =  ctx.getPool();
	IConnection connnection = Red5.getConnectionLocal();
	
	String signature = (String) connnection.getAttribute(Constants.TRANSCODER_SESSION_ATTR);
	ISession session = pool.getSession(signature);
	session.stop();
	
	return true;
}
 
Example #23
Source File: ServerClientDetection.java    From red5-examples with Apache License 2.0 5 votes vote down vote up
private void callBWDone()
{
	IConnection conn = Red5.getConnectionLocal();
	
	Map<String, Object> statsValues = new HashMap<String, Object>();
	statsValues.put("kbitDown", this.kbitDown);
	statsValues.put("deltaDown", this.deltaDown);
	statsValues.put("deltaTime", this.deltaTime);
	statsValues.put("latency", this.latency);
	
	if (conn instanceof IServiceCapableConnection) {
		((IServiceCapableConnection) conn).invoke("onBWDone", new Object[]{statsValues});
	}
}
 
Example #24
Source File: ClientServerDetection.java    From red5-examples with Apache License 2.0 5 votes vote down vote up
private IStreamCapableConnection getStats() {
	IConnection conn = Red5.getConnectionLocal();
	if (conn instanceof IStreamCapableConnection) {
		return (IStreamCapableConnection) conn;
	}
	return null;
}
 
Example #25
Source File: Application.java    From red5-hls-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public void streamRecordStart(IBroadcastStream stream) {
	log.debug("streamRecordStart - stream name: {}", stream.getPublishedName());
	// save the record / stream name
	Red5.getConnectionLocal().setAttribute("streamName", stream.getPublishedName());
	super.streamRecordStart(stream);
}
 
Example #26
Source File: RTMPConnManager.java    From red5-client with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public RTMPConnection removeConnection(String sessionId) {
    log.debug("Removing connection with session id: {}", sessionId);
    if (log.isTraceEnabled()) {
        log.trace("Connections ({}) at pre-remove: {}", connMap.size(), connMap.values());
    }
    // remove from map
    RTMPConnection conn = connMap.remove(sessionId);
    if (conn != null) {
        log.trace("Connections: {}", conns.decrementAndGet());
        Red5.setConnectionLocal(null);
    }
    return conn;
}
 
Example #27
Source File: RTMPMinaCodecFactory.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
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) {
        Red5.setConnectionLocal(conn);
        final Semaphore lock = conn.getEncoderLock();
        try {
            // acquire the encoder lock
            lock.acquire();
            // get the buffer
            final IoBuffer buf = message instanceof IoBuffer ? (IoBuffer) message : getEncoder().encode(message);
            if (buf != null) {
                if (log.isTraceEnabled()) {
                    log.trace("Writing output data: {}", Hex.encodeHexString(buf.array()));
                }
                out.write(buf);
            } else {
                log.trace("Response buffer was null after encoding");
            }
        } catch (Exception ex) {
            log.error("Exception during encode", ex);
        } finally {
            lock.release();
            Red5.setConnectionLocal(null);
        }
    } else {
        log.debug("Connection is no longer available for encoding, may have been closed already");
    }
}
 
Example #28
Source File: RTMPMinaIoHandler.java    From red5-client with Apache License 2.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void messageReceived(IoSession session, Object message) throws Exception {
    log.debug("messageReceived");
    if (message instanceof Packet && message != null) {
        String sessionId = (String) session.getAttribute(RTMPConnection.RTMP_SESSION_ID);
        log.trace("Session id: {}", sessionId);
        RTMPMinaConnection conn = (RTMPMinaConnection) getConnectionManager(session).getConnectionBySessionId(sessionId);
        Red5.setConnectionLocal(conn);
        conn.handleMessageReceived((Packet) message);
        Red5.setConnectionLocal(null);
    } else {
        log.debug("Not packet type: {}", message);
    }
}
 
Example #29
Source File: BaseRTMPTConnection.java    From red5-client with Apache License 2.0 5 votes vote down vote up
/**
 * Send RTMP packet down the connection.
 *
 * @param packet
 *            the packet to send
 */
@Override
public void write(final Packet packet) {
    log.debug("write - state: {}", state);
    if (closing || state.getState() == RTMP.STATE_DISCONNECTED) {
        // Connection is being closed, don't send any new packets
        return;
    }
    IoBuffer data;
    try {
        Red5.setConnectionLocal(this);
        data = encoder.encode(packet);
    } catch (Exception e) {
        log.error("Could not encode message {}", packet, e);
        return;
    } finally {
        Red5.setConnectionLocal(null);
    }

    if (data != null) {
        // Mark packet as being written
        writingMessage(packet);
        //add to pending
        pendingMessages.add(new PendingData(data, packet));
    } else {
        log.info("Response buffer was null after encoding");
    }
}
 
Example #30
Source File: SharedObjectClient.java    From red5-client with Apache License 2.0 5 votes vote down vote up
@Override
public void resultReceived(IPendingServiceCall call) {
    log.debug("Received pending call: {}", call);
    Object result = call.getResult();
    if (result instanceof ObjectMap) {
        obj = getSharedObject(soName, false);
        obj.connect(Red5.getConnectionLocal());
        obj.addSharedObjectListener(this);
    }
}