Java Code Examples for org.red5.server.net.rtmp.event.IRTMPEvent#setSourceType()
The following examples show how to use
org.red5.server.net.rtmp.event.IRTMPEvent#setSourceType() .
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: RTMPProtocolDecoder.java From red5-server-common with Apache License 2.0 | 4 votes |
/** * Decodes RTMP message event. * * @param conn * RTMP connection * @param header * RTMP header * @param in * Input IoBuffer * @return RTMP event */ public IRTMPEvent decodeMessage(RTMPConnection conn, Header header, IoBuffer in) { IRTMPEvent message; byte dataType = header.getDataType(); switch (dataType) { case TYPE_AUDIO_DATA: message = decodeAudioData(in); message.setSourceType(Constants.SOURCE_TYPE_LIVE); break; case TYPE_VIDEO_DATA: message = decodeVideoData(in); message.setSourceType(Constants.SOURCE_TYPE_LIVE); break; case TYPE_AGGREGATE: message = decodeAggregate(in); break; case TYPE_FLEX_SHARED_OBJECT: // represents an SO in an AMF3 container message = decodeFlexSharedObject(in); break; case TYPE_SHARED_OBJECT: message = decodeSharedObject(in); break; case TYPE_FLEX_MESSAGE: message = decodeFlexMessage(in); break; case TYPE_INVOKE: message = decodeAction(conn.getEncoding(), in, header); break; case TYPE_FLEX_STREAM_SEND: if (log.isTraceEnabled()) { log.trace("Decoding flex stream send on stream id: {}", header.getStreamId()); } // skip first byte in.get(); // decode stream data; slice from the current position message = decodeStreamData(in.slice()); break; case TYPE_NOTIFY: if (log.isTraceEnabled()) { log.trace("Decoding notify on stream id: {}", header.getStreamId()); } if (header.getStreamId().doubleValue() != 0.0d) { message = decodeStreamData(in); } else { message = decodeAction(conn.getEncoding(), in, header); } break; case TYPE_PING: message = decodePing(in); break; case TYPE_BYTES_READ: message = decodeBytesRead(in); break; case TYPE_CHUNK_SIZE: message = decodeChunkSize(in); break; case TYPE_SERVER_BANDWIDTH: message = decodeServerBW(in); break; case TYPE_CLIENT_BANDWIDTH: message = decodeClientBW(in); break; case TYPE_ABORT: message = decodeAbort(in); break; default: log.warn("Unknown object type: {}", dataType); message = decodeUnknown(dataType, in); break; } // add the header to the message message.setHeader(header); return message; }
Example 2
Source File: BaseRTMPHandler.java From red5-server-common with Apache License 2.0 | 4 votes |
/** {@inheritDoc} */ public void messageReceived(RTMPConnection conn, Packet packet) throws Exception { log.trace("messageReceived connection: {}", conn.getSessionId()); if (conn != null) { IRTMPEvent message = null; try { message = packet.getMessage(); final Header header = packet.getHeader(); final Number streamId = header.getStreamId(); final Channel channel = conn.getChannel(header.getChannelId()); final IClientStream stream = conn.getStreamById(streamId); if (log.isTraceEnabled()) { log.trace("Message received - header: {}", header); } // set stream id on the connection conn.setStreamId(streamId); // increase number of received messages conn.messageReceived(); // set the source of the message message.setSource(conn); // process based on data type final byte headerDataType = header.getDataType(); if (log.isTraceEnabled()) { log.trace("Header / message data type: {}", headerDataType); } switch (headerDataType) { case TYPE_AGGREGATE: log.debug("Aggregate type data - header timer: {} size: {}", header.getTimer(), header.getSize()); case TYPE_AUDIO_DATA: case TYPE_VIDEO_DATA: // mark the event as from a live source // log.trace("Marking message as originating from a Live source"); message.setSourceType(Constants.SOURCE_TYPE_LIVE); // NOTE: If we respond to "publish" with "NetStream.Publish.BadName", // the client sends a few stream packets before stopping. We need to ignore them if (stream != null) { ((IEventDispatcher) stream).dispatchEvent(message); } break; case TYPE_FLEX_SHARED_OBJECT: case TYPE_SHARED_OBJECT: onSharedObject(conn, channel, header, (SharedObjectMessage) message); break; case TYPE_INVOKE: case TYPE_FLEX_MESSAGE: onCommand(conn, channel, header, (Invoke) message); IPendingServiceCall call = ((Invoke) message).getCall(); if (message.getHeader().getStreamId().intValue() != 0 && call.getServiceName() == null && StreamAction.PUBLISH.equals(call.getServiceMethodName())) { if (stream != null) { // Only dispatch if stream really was created ((IEventDispatcher) stream).dispatchEvent(message); } } break; case TYPE_NOTIFY: // like an invoke, but does not return anything and has a invoke / transaction id of 0 case TYPE_FLEX_STREAM_SEND: if (((Notify) message).getData() != null && stream != null) { // Stream metadata ((IEventDispatcher) stream).dispatchEvent(message); } else { onCommand(conn, channel, header, (Notify) message); } break; case TYPE_PING: onPing(conn, channel, header, (Ping) message); break; case TYPE_BYTES_READ: onStreamBytesRead(conn, channel, header, (BytesRead) message); break; case TYPE_CHUNK_SIZE: onChunkSize(conn, channel, header, (ChunkSize) message); break; case Constants.TYPE_CLIENT_BANDWIDTH: // onBWDone / peer bw log.debug("Client bandwidth: {}", message); onClientBandwidth(conn, channel, (ClientBW) message); break; case Constants.TYPE_SERVER_BANDWIDTH: // window ack size log.debug("Server bandwidth: {}", message); onServerBandwidth(conn, channel, (ServerBW) message); break; default: log.debug("Unknown type: {}", header.getDataType()); } if (message instanceof Unknown) { log.info("Message type unknown: {}", message); } } catch (Throwable t) { log.error("Exception", t); } // XXX this may be causing 'missing' data if previous methods are not making copies before buffering etc.. if (message != null) { message.release(); } } }