Skip to content
Snippets Groups Projects
Commit 8d278bb3 authored by Paul Gregoire's avatar Paul Gregoire
Browse files

Refactor RTMPProtocolDecoder to favor fill packet vs tiny chunk size if available bytes

parent e6b34590
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ public class RTMPMinaProtocolDecoder extends ProtocolDecoderAdapter { ...@@ -72,7 +72,7 @@ public class RTMPMinaProtocolDecoder extends ProtocolDecoderAdapter {
log.trace("Buffers info before: position {}, limit {}, remaining {}", new Object[] { buf.position(), buf.limit(), buf.remaining() }); log.trace("Buffers info before: position {}, limit {}, remaining {}", new Object[] { buf.position(), buf.limit(), buf.remaining() });
} }
try { try {
// construct any objects from the decoded bugger // construct any objects from the decoded buffer
List<?> objects = decoder.decodeBuffer(conn, buf); List<?> objects = decoder.decodeBuffer(conn, buf);
log.trace("Decoded: {}", objects); log.trace("Decoded: {}", objects);
if (objects != null) { if (objects != null) {
......
...@@ -69,6 +69,8 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -69,6 +69,8 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
protected static final Logger log = LoggerFactory.getLogger(RTMPProtocolDecoder.class); protected static final Logger log = LoggerFactory.getLogger(RTMPProtocolDecoder.class);
protected static final boolean isTrace = log.isTraceEnabled(), isDebug = log.isDebugEnabled();
// close when header errors occur // close when header errors occur
protected boolean closeOnHeaderError; protected boolean closeOnHeaderError;
...@@ -90,7 +92,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -90,7 +92,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
*/ */
public List<Object> decodeBuffer(RTMPConnection conn, IoBuffer buffer) { public List<Object> decodeBuffer(RTMPConnection conn, IoBuffer buffer) {
final int position = buffer.position(); final int position = buffer.position();
//if (log.isTraceEnabled()) { //if (isTrace) {
// log.trace("decodeBuffer: {}", Hex.encodeHexString(Arrays.copyOfRange(buffer.array(), position, buffer.limit()))); // log.trace("decodeBuffer: {}", Hex.encodeHexString(Arrays.copyOfRange(buffer.array(), position, buffer.limit())));
//} //}
// decoded results // decoded results
...@@ -102,9 +104,9 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -102,9 +104,9 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
result = new LinkedList<>(); result = new LinkedList<>();
// get the local decode state // get the local decode state
RTMPDecodeState state = conn.getDecoderState(); RTMPDecodeState state = conn.getDecoderState();
//if (log.isTraceEnabled()) { if (isTrace) {
//log.trace("RTMP decode state {}", state); log.trace("RTMP decode state {}", state);
//} }
if (!conn.getSessionId().equals(state.getSessionId())) { if (!conn.getSessionId().equals(state.getSessionId())) {
log.warn("Session decode overlap: {} != {}", conn.getSessionId(), state.getSessionId()); log.warn("Session decode overlap: {} != {}", conn.getSessionId(), state.getSessionId());
} }
...@@ -140,7 +142,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -140,7 +142,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
// close connection because we can't parse data from it // close connection because we can't parse data from it
conn.close(); conn.close();
} finally { } finally {
//if (log.isTraceEnabled()) { //if (isTrace) {
// log.trace("decodeBuffer - post decode input buffer position: {} remaining: {}", buffer.position(), buffer.remaining()); // log.trace("decodeBuffer - post decode input buffer position: {} remaining: {}", buffer.position(), buffer.remaining());
//} //}
buffer.compact(); buffer.compact();
...@@ -171,7 +173,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -171,7 +173,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
* on error * on error
*/ */
public Object decode(RTMPConnection conn, RTMPDecodeState state, IoBuffer in) throws ProtocolException { public Object decode(RTMPConnection conn, RTMPDecodeState state, IoBuffer in) throws ProtocolException {
//if (log.isTraceEnabled()) { //if (isTrace) {
//log.trace("Decoding for {}", conn.getSessionId()); //log.trace("Decoding for {}", conn.getSessionId());
//} //}
try { try {
...@@ -194,7 +196,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -194,7 +196,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
} catch (RuntimeException e) { } catch (RuntimeException e) {
throw new ProtocolException("Error during decoding", e); throw new ProtocolException("Error during decoding", e);
} finally { } finally {
//if (log.isTraceEnabled()) { //if (isTrace) {
//log.trace("Decoding finished for {}", conn.getSessionId()); //log.trace("Decoding finished for {}", conn.getSessionId());
//} //}
} }
...@@ -213,7 +215,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -213,7 +215,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
*/ */
public Packet decodePacket(RTMPConnection conn, RTMPDecodeState state, IoBuffer in) { public Packet decodePacket(RTMPConnection conn, RTMPDecodeState state, IoBuffer in) {
final int position = in.position(); final int position = in.position();
//if (log.isTraceEnabled()) { //if (isTrace) {
//log.trace("decodePacket - state: {} buffer: {}", state, in); //log.trace("decodePacket - state: {} buffer: {}", state, in);
//log.trace("decodePacket: position {}, limit {}, {}", position, in.limit(), Hex.encodeHexString(Arrays.copyOfRange(in.array(), position, in.limit()))); //log.trace("decodePacket: position {}, limit {}, {}", position, in.limit(), Hex.encodeHexString(Arrays.copyOfRange(in.array(), position, in.limit())));
//log.trace("decodePacket: position {}, limit {}", position, in.limit()); //log.trace("decodePacket: position {}, limit {}", position, in.limit());
...@@ -236,7 +238,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -236,7 +238,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
final int channelId = header != null ? header.getChannelId() : chunkHeader.getChannelId(); final int channelId = header != null ? header.getChannelId() : chunkHeader.getChannelId();
// header empty vs header null will return the NS_FAILED message // header empty vs header null will return the NS_FAILED message
if (header.isEmpty()) { if (header.isEmpty()) {
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Header was null or empty - chh: {}", chunkHeader); log.trace("Header was null or empty - chh: {}", chunkHeader);
} }
// send a NetStream.Failed message // send a NetStream.Failed message
...@@ -250,20 +252,12 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -250,20 +252,12 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
// ensure that we dont exceed maximum packet size // ensure that we dont exceed maximum packet size
int size = header.getSize(); int size = header.getSize();
log.debug("Packet size: {}", size); log.debug("Packet size: {}", size);
/* XXX(paul): This is a hack to prevent OOM when decoding has failed in some way
if (size > MAX_PACKET_SIZE) {
// Reject packets that are too big, to protect against OOM when decoding has failed in some way
log.warn("Packet size exceeded. size={}, max={}, connId={}", size, MAX_PACKET_SIZE, conn.getSessionId());
// send a NetStream.Failed message
StreamService.sendNetStreamStatus(conn, StatusCodes.NS_FAILED, "Data exceeded maximum allowed by " + (size - MAX_PACKET_SIZE) + " bytes", "no-name", Status.ERROR, conn.getStreamIdForChannelId(channelId));
throw new ProtocolException(String.format("Packet size exceeded. size: %s", header.getSize()));
}
*/
// get the size of our chunks // get the size of our chunks
int readChunkSize = rtmp.getReadChunkSize(); int readChunkSize = rtmp.getReadChunkSize();
// check to see if this is a new packet or continue decoding an existing one // check to see if this is a new packet or continue decoding an existing one
Packet packet = rtmp.getLastReadPacket(channelId); Packet packet = rtmp.getLastReadPacket(channelId);
if (packet == null) { if (packet == null) {
log.trace("Creating new packet");
// create a new packet // create a new packet
packet = new Packet(header.clone()); packet = new Packet(header.clone());
// store the packet based on its channel id // store the packet based on its channel id
...@@ -271,13 +265,13 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -271,13 +265,13 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
} }
// get the packet data // get the packet data
IoBuffer buf = packet.getData(); IoBuffer buf = packet.getData();
//if (log.isTraceEnabled()) { if (isTrace) {
//log.trace("Source buffer position: {}, limit: {}, packet-buf.position {}, packet size: {}", new Object[] { in.position(), in.limit(), buf.position(), header.getSize() }); log.trace("Source buffer position: {}, limit: {}, packet-buf.position {}, packet size: {}", in.position(), in.limit(), buf.position(), header.getSize());
//} }
// read chunk // read chunk
int length = Math.min(buf.remaining(), readChunkSize); int length = Math.max(buf.remaining(), readChunkSize);
if (in.remaining() < length) { if (in.remaining() < length) {
//log.debug("Chunk too small, buffering ({},{})", in.remaining(), length); log.debug("In buffer is too small, buffering ({},{})", in.remaining(), length);
// how much more data we need to continue? // how much more data we need to continue?
state.bufferDecoding(in.position() - position + length); state.bufferDecoding(in.position() - position + length);
// we need to move back position so header will be available during another decode round // we need to move back position so header will be available during another decode round
...@@ -286,17 +280,17 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -286,17 +280,17 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
} }
// get the chunk from our input // get the chunk from our input
byte[] chunk = Arrays.copyOfRange(in.array(), in.position(), in.position() + length); byte[] chunk = Arrays.copyOfRange(in.array(), in.position(), in.position() + length);
//if (log.isTraceEnabled()) { if (isTrace) {
//log.trace("Read chunkSize: {}, length: {}, chunk: {}", readChunkSize, length, Hex.encodeHexString(chunk)); log.trace("Read chunkSize: {}, length: {}, chunk: {}", readChunkSize, length, Hex.encodeHexString(chunk));
//} }
// move the position // move the position
in.skip(length); in.skip(length);
// put the chunk into the packet // put the chunk into the packet
buf.put(chunk); buf.put(chunk);
if (buf.hasRemaining()) { if (buf.hasRemaining()) {
//if (log.isTraceEnabled()) { if (isTrace) {
//log.trace("Packet is incomplete ({},{})", buf.remaining(), buf.limit()); log.trace("Packet is incomplete ({},{})", buf.remaining(), buf.limit());
//} }
return null; return null;
} }
// flip so we can read / decode the packet data into a message // flip so we can read / decode the packet data into a message
...@@ -310,7 +304,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -310,7 +304,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
// flash will send an earlier time stamp when resetting a video stream with a new key frame. To avoid dropping it, we give it the // flash will send an earlier time stamp when resetting a video stream with a new key frame. To avoid dropping it, we give it the
// minimal increment since the last message. To avoid relative time stamps being mis-computed, we don't reset the header we stored. // minimal increment since the last message. To avoid relative time stamps being mis-computed, we don't reset the header we stored.
message.setTimestamp(timestamp); message.setTimestamp(timestamp);
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Decoded message: {}", message); log.trace("Decoded message: {}", message);
} }
packet.setMessage(message); packet.setMessage(message);
...@@ -329,7 +323,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -329,7 +323,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
lastHeader.setTimerBase(timestamp); lastHeader.setTimerBase(timestamp);
// clear the delta // clear the delta
//lastHeader.setTimerDelta(0); //lastHeader.setTimerDelta(0);
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Last read header after decode: {}", lastHeader); log.trace("Last read header after decode: {}", lastHeader);
} }
} finally { } finally {
...@@ -354,7 +348,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -354,7 +348,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
* @return Decoded header * @return Decoded header
*/ */
public Header decodeHeader(ChunkHeader chh, RTMPDecodeState state, IoBuffer in, RTMP rtmp, int startPostion) { public Header decodeHeader(ChunkHeader chh, RTMPDecodeState state, IoBuffer in, RTMP rtmp, int startPostion) {
//if (log.isTraceEnabled()) { //if (isTrace) {
//log.trace("decodeHeader - chh: {} input: {}", chh, Hex.encodeHexString(Arrays.copyOfRange(in.array(), in.position(), in.limit()))); //log.trace("decodeHeader - chh: {} input: {}", chh, Hex.encodeHexString(Arrays.copyOfRange(in.array(), in.position(), in.limit())));
//log.trace("decodeHeader - chh: {}", chh); //log.trace("decodeHeader - chh: {}", chh);
//} //}
...@@ -373,7 +367,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -373,7 +367,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
} }
Header lastHeader = rtmp.getLastReadHeader(channelId); Header lastHeader = rtmp.getLastReadHeader(channelId);
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("{} lastHeader: {}", Header.HeaderType.values()[headerSize], lastHeader); log.trace("{} lastHeader: {}", Header.HeaderType.values()[headerSize], lastHeader);
} }
// got a non-new header for a channel which has no last-read header // got a non-new header for a channel which has no last-read header
...@@ -390,7 +384,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -390,7 +384,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
return null; return null;
} }
} }
// if (log.isTraceEnabled()) { // if (isTrace) {
// log.trace("headerLength: {}", headerLength); // log.trace("headerLength: {}", headerLength);
// } // }
...@@ -414,7 +408,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -414,7 +408,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
} }
long ext = in.getUnsignedInt(); long ext = in.getUnsignedInt();
timeBase = (int) (ext ^ (ext >>> 32)); timeBase = (int) (ext ^ (ext >>> 32));
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Extended time read: {}", timeBase); log.trace("Extended time read: {}", timeBase);
} }
header.setExtended(true); header.setExtended(true);
...@@ -487,7 +481,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -487,7 +481,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
} }
long ext = in.getUnsignedInt(); long ext = in.getUnsignedInt();
int timeExt = (int) (ext ^ (ext >>> 32)); int timeExt = (int) (ext ^ (ext >>> 32));
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Extended time read: {} {}", ext, timeExt); log.trace("Extended time read: {} {}", ext, timeExt);
} }
timeBase = timeExt; timeBase = timeExt;
...@@ -542,7 +536,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -542,7 +536,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
message = decodeAction(conn.getEncoding(), in, header); message = decodeAction(conn.getEncoding(), in, header);
break; break;
case TYPE_FLEX_STREAM_SEND: case TYPE_FLEX_STREAM_SEND:
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Decoding flex stream send on stream id: {}", header.getStreamId()); log.trace("Decoding flex stream send on stream id: {}", header.getStreamId());
} }
// skip first byte // skip first byte
...@@ -551,7 +545,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -551,7 +545,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
message = decodeStreamData(in.slice()); message = decodeStreamData(in.slice());
break; break;
case TYPE_NOTIFY: case TYPE_NOTIFY:
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Decoding notify on stream id: {}", header.getStreamId()); log.trace("Decoding notify on stream id: {}", header.getStreamId());
} }
if (header.getStreamId().doubleValue() != 0.0d) { if (header.getStreamId().doubleValue() != 0.0d) {
...@@ -616,7 +610,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -616,7 +610,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
/** {@inheritDoc} */ /** {@inheritDoc} */
public Unknown decodeUnknown(byte dataType, IoBuffer in) { public Unknown decodeUnknown(byte dataType, IoBuffer in) {
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("decodeUnknown: {}", dataType); log.debug("decodeUnknown: {}", dataType);
} }
return new Unknown(dataType, in); return new Unknown(dataType, in);
...@@ -784,7 +778,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -784,7 +778,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
if (action == null) { if (action == null) {
throw new RuntimeException("Action was null"); throw new RuntimeException("Action was null");
} }
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Action: {}", action); log.trace("Action: {}", action);
} }
// instance the invoke // instance the invoke
...@@ -827,7 +821,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -827,7 +821,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
*/ */
public Ping decodePing(IoBuffer in) { public Ping decodePing(IoBuffer in) {
Ping ping = null; Ping ping = null;
if (log.isTraceEnabled()) { if (isTrace) {
// gets the raw data as hex without changing the data or pointer // gets the raw data as hex without changing the data or pointer
String hexDump = in.getHexDump(); String hexDump = in.getHexDump();
log.trace("Ping dump: {}", hexDump); log.trace("Ping dump: {}", hexDump);
...@@ -881,7 +875,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -881,7 +875,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
*/ */
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public Notify decodeStreamData(IoBuffer in) { public Notify decodeStreamData(IoBuffer in) {
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("decodeStreamData"); log.debug("decodeStreamData");
} }
// our result is a notify // our result is a notify
...@@ -939,7 +933,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -939,7 +933,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
params = Collections.EMPTY_MAP; params = Collections.EMPTY_MAP;
} }
} }
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("Dataframe: {} params: {}", onCueOrOnMeta, params.toString()); log.debug("Dataframe: {} params: {}", onCueOrOnMeta, params.toString());
} }
IoBuffer buf = IoBuffer.allocate(64); IoBuffer buf = IoBuffer.allocate(64);
...@@ -967,27 +961,27 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -967,27 +961,27 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
log.debug("Params type: {}", object); log.debug("Params type: {}", object);
if (object == DataTypes.CORE_MAP) { if (object == DataTypes.CORE_MAP) {
params = (Map<Object, Object>) input.readMap(); params = (Map<Object, Object>) input.readMap();
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("Map params: {}", params.toString()); log.debug("Map params: {}", params.toString());
} }
} else if (object == DataTypes.CORE_ARRAY) { } else if (object == DataTypes.CORE_ARRAY) {
params = (Map<Object, Object>) input.readArray(Object[].class); params = (Map<Object, Object>) input.readArray(Object[].class);
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("Array params: {}", params); log.debug("Array params: {}", params);
} }
} else if (object == DataTypes.CORE_STRING) { } else if (object == DataTypes.CORE_STRING) {
String str = input.readString(); String str = input.readString();
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("String params: {}", str); log.debug("String params: {}", str);
} }
params = new HashMap<>(); params = new HashMap<>();
params.put("0", str); params.put("0", str);
} else if (object == DataTypes.CORE_OBJECT) { } else if (object == DataTypes.CORE_OBJECT) {
params = (Map<Object, Object>) input.readObject(); params = (Map<Object, Object>) input.readObject();
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("Object params: {}", params); log.debug("Object params: {}", params);
} }
} else if (log.isDebugEnabled()) { } else if (isDebug) {
log.debug("Stream send did not provide a parameter map"); log.debug("Stream send did not provide a parameter map");
} }
// need to debug this further // need to debug this further
...@@ -1017,7 +1011,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -1017,7 +1011,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
* @return FlexMessage event * @return FlexMessage event
*/ */
public FlexMessage decodeFlexMessage(IoBuffer in) { public FlexMessage decodeFlexMessage(IoBuffer in) {
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("decodeFlexMessage"); log.debug("decodeFlexMessage");
} }
// TODO: Unknown byte, probably encoding as with Flex SOs? // TODO: Unknown byte, probably encoding as with Flex SOs?
...@@ -1063,7 +1057,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -1063,7 +1057,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
paramList.add(Deserializer.deserialize(input, Object.class)); paramList.add(Deserializer.deserialize(input, Object.class));
} }
params = paramList.toArray(); params = paramList.toArray();
if (log.isTraceEnabled()) { if (isTrace) {
log.trace("Parameter count: {}", paramList.size()); log.trace("Parameter count: {}", paramList.size());
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
log.trace(" > {}: {}", i, params[i]); log.trace(" > {}: {}", i, params[i]);
...@@ -1143,7 +1137,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -1143,7 +1137,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
paramList.add(Deserializer.deserialize(input, Object.class)); paramList.add(Deserializer.deserialize(input, Object.class));
} }
params = paramList.toArray(); params = paramList.toArray();
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("Num params: {}", paramList.size()); log.debug("Num params: {}", paramList.size());
for (int i = 0; i < params.length; i++) { for (int i = 0; i < params.length; i++) {
log.debug(" > {}: {}", i, params[i]); log.debug(" > {}: {}", i, params[i]);
...@@ -1159,7 +1153,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder { ...@@ -1159,7 +1153,7 @@ public class RTMPProtocolDecoder implements Constants, IEventDecoder {
*/ */
public static void setMaxPacketSize(int maxPacketSize) { public static void setMaxPacketSize(int maxPacketSize) {
MAX_PACKET_SIZE = maxPacketSize; MAX_PACKET_SIZE = maxPacketSize;
if (log.isDebugEnabled()) { if (isDebug) {
log.debug("Max packet size: {}", MAX_PACKET_SIZE); log.debug("Max packet size: {}", MAX_PACKET_SIZE);
} }
} }
......
...@@ -21,7 +21,6 @@ import org.red5.server.net.rtmp.RTMPConnection; ...@@ -21,7 +21,6 @@ import org.red5.server.net.rtmp.RTMPConnection;
import org.red5.server.net.rtmp.RTMPMinaConnection; import org.red5.server.net.rtmp.RTMPMinaConnection;
import org.red5.server.net.rtmp.RTMPUtils; import org.red5.server.net.rtmp.RTMPUtils;
import org.red5.server.net.rtmp.event.Invoke; import org.red5.server.net.rtmp.event.Invoke;
import org.red5.server.net.rtmp.event.Notify;
import org.red5.server.net.rtmp.message.ChunkHeader; import org.red5.server.net.rtmp.message.ChunkHeader;
import org.red5.server.net.rtmp.message.Header; import org.red5.server.net.rtmp.message.Header;
import org.red5.server.net.rtmp.message.Packet; import org.red5.server.net.rtmp.message.Packet;
...@@ -256,13 +255,13 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler { ...@@ -256,13 +255,13 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler {
log.debug("\n testNullJsonKV"); log.debug("\n testNullJsonKV");
RTMPProtocolEncoder enc = new RTMPProtocolEncoder(); RTMPProtocolEncoder enc = new RTMPProtocolEncoder();
RTMPProtocolDecoder dec = new RTMPProtocolDecoder(); RTMPProtocolDecoder dec = new RTMPProtocolDecoder();
RTMPMinaConnection conn = new RTMPMinaConnection(); //RTMPMinaConnection conn = new RTMPMinaConnection();
// RTMPMinaConnection conn = new RTMPMinaConnection() { RTMPMinaConnection conn = new RTMPMinaConnection() {
// @Override @Override
// public Encoding getEncoding() { public Encoding getEncoding() {
// return Encoding.AMF3; return Encoding.AMF3;
// } }
// }; };
conn.getState().setState(RTMP.STATE_CONNECTED); conn.getState().setState(RTMP.STATE_CONNECTED);
conn.setHandler(this); conn.setHandler(this);
...@@ -270,10 +269,6 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler { ...@@ -270,10 +269,6 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler {
String json = "{Server=NGINX RTMP (github.com/arut/nginx-rtmp-module), width=1280.0, height=720.0, displayWidth=1280.0, displayHeight=720.0, duration=0.0, framerate=30.0, fps=30.0, videodatarate=2500.0, videocodecid=7.0, audiodatarate=160.0, audiocodecid=10.0, profile=, level=}"; String json = "{Server=NGINX RTMP (github.com/arut/nginx-rtmp-module), width=1280.0, height=720.0, displayWidth=1280.0, displayHeight=720.0, duration=0.0, framerate=30.0, fps=30.0, videodatarate=2500.0, videocodecid=7.0, audiodatarate=160.0, audiocodecid=10.0, profile=, level=}";
Header header = new Header();
header.setStreamId(1);
header.setDataType(Notify.TYPE_STREAM_METADATA);
IoBuffer bf = IoBuffer.allocate(128); IoBuffer bf = IoBuffer.allocate(128);
bf.setAutoExpand(true); bf.setAutoExpand(true);
Output writer = new Output(bf); Output writer = new Output(bf);
...@@ -283,6 +278,9 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler { ...@@ -283,6 +278,9 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler {
writer.buf().flip(); writer.buf().flip();
/* using notify event using a Notify object /* using notify event using a Notify object
Header header = new Header();
header.setStreamId(1);
header.setDataType(Notify.TYPE_STREAM_METADATA);
Notify notify = new Notify(writer.buf()); Notify notify = new Notify(writer.buf());
notify.setSourceType(Constants.SOURCE_TYPE_LIVE); notify.setSourceType(Constants.SOURCE_TYPE_LIVE);
notify.setTimestamp(0); notify.setTimestamp(0);
...@@ -292,13 +290,24 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler { ...@@ -292,13 +290,24 @@ public class TestRTMPProtocolDecoder implements IRTMPHandler {
IoBuffer encoded = enc.encodeStreamMetadata(notify); IoBuffer encoded = enc.encodeStreamMetadata(notify);
*/ */
IoBuffer encoded = writer.buf(); //IoBuffer encoded = writer.buf();
IoBuffer encoded = IoBuffer.wrap(IOUtils.hexStringToByteArray(
"05000000000183120100000002000a6f6e4d6574614461746103000653657276657202002e4e47494e582052544d5020286769746875622e636f6d2f617275742f6e67696e782d72746d702d6d6f64756c65290005776964746800409e0000000000000006686569676874004090e00000000000000c646973706c6179576964746800409e000000000000000d646973706c6179486569676874004090e0000000000000086475726174696f6e00000000000000000000096672616d657261746500403e000000000000000366707300403e000000000000000d766964656f64617461726174650040b1940000000000000c766964656f636f646563696400401c000000000000000d617564696f6461746172617465004064000000000000000c617564696f636f6465636964004024000000000000000770726f66696c65020020000000000000000000000000000000000000000000000000000000000000000000056c6576656c0200200000000000000000000000000000000000000000000000000000000000000000000009"));
byte[] copy = Arrays.copyOfRange(encoded.array(), encoded.arrayOffset(), encoded.remaining()); byte[] copy = Arrays.copyOfRange(encoded.array(), encoded.arrayOffset(), encoded.remaining());
log.debug("Encoded: {}", Hex.encodeHexString(copy)); log.debug("Encoded: {}", Hex.encodeHexString(copy));
Notify event = (Notify) dec.decodeMessage(conn, header, encoded); List<?> objects = dec.decodeBuffer(conn, encoded);
log.debug("Decoded: {}", event.toString()); log.info("Decoded: {}", objects);
if (objects != null) {
for (Object object : objects) {
log.info("Decoded object: {}", object);
}
}
//Notify event = dec.decodePacket(encoded);
//log.debug("Decoded: {}", event.toString());
Red5.setConnectionLocal(null); Red5.setConnectionLocal(null);
} }
......
...@@ -19,12 +19,4 @@ ...@@ -19,12 +19,4 @@
<appender-ref ref="CONSOLE" /> <appender-ref ref="CONSOLE" />
<appender-ref ref="FILE" /> <appender-ref ref="FILE" />
</root> </root>
<!--
<logger name="org.red5.server" level="TRACE">
<appender-ref ref="FILE"/>
</logger>
<logger name="org.red5.server.net.rtmp" level="TRACE" />
<logger name="org.springframework" level="INFO" />
<logger name="org.apache" level="INFO" />
-->
</configuration> </configuration>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment