}
/** {@inheritDoc} */
public void messageReceived(RTMPConnection conn, ProtocolState state, Object in) throws Exception {
IRTMPEvent message = null;
try {
final Packet packet = (Packet) in;
message = packet.getMessage();
final Header header = packet.getHeader();
final Channel channel = conn.getChannel(header.getChannelId());
final IClientStream stream = conn.getStreamById(header
.getStreamId());
if (log.isDebugEnabled()) {
log.debug("Message recieved");
log.debug("Stream Id: " + header);
log.debug("Channel: " + channel);
}
// Thread local performance ? Should we benchmark
Red5.setConnectionLocal(conn);
// XXX: HACK HACK HACK to support stream ids
BaseRTMPHandler.setStreamId(header.getStreamId());
// Increase number of received messages
conn.messageReceived();
//if (message instanceof IRTMPEvent) {
message.setSource(conn);
//}
switch (header.getDataType()) {
case TYPE_CHUNK_SIZE:
onChunkSize(conn, channel, header, (ChunkSize) message);
break;
case TYPE_INVOKE:
case TYPE_FLEX_MESSAGE:
onInvoke(conn, channel, header, (Invoke) message, (RTMP) state);
if(message.getHeader().getStreamId()!=0
&& ((Invoke)message).getCall().getServiceName()==null
&& ACTION_PUBLISH.equals(((Invoke)message).getCall().getServiceMethodName())) {
if (stream != null) {
// Only dispatch if stream really was created
((IEventDispatcher) stream).dispatchEvent(message);
}
}
break;
case TYPE_NOTIFY: // just like invoke, but does not return
if (((Notify) message).getData() != null && stream != null) {
// Stream metadata
((IEventDispatcher) stream).dispatchEvent(message);
} else {
onInvoke(conn, channel, header, (Notify) message, (RTMP) state);
}
break;
case TYPE_FLEX_STREAM_SEND:
if (stream != null) {
((IEventDispatcher) stream).dispatchEvent(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_AUDIO_DATA:
case TYPE_VIDEO_DATA:
// log.info("in packet: "+source.getSize()+"
// ts:"+source.getTimer());
// 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;
default:
log.debug("Unknown type: {}", header.getDataType());
}
if (message instanceof Unknown) {
log.info("{}", message);
}
} catch (RuntimeException e) {
// TODO Auto-generated catch block
log.error("Exception", e);
}
if (message != null) {
message.release();
}
}