[Red5commits] [1530] applied modified patch by "ce [at] publishing-etc [dot] de" to support client mo
jbauch
luke at codegent.com
Wed Jan 24 10:33:32 EST 2007
applied modified patch by "ce [at] publishing-etc [dot] de" to support client mode in the RTMP library (Trac #94)
Timestamp: 11/09/06 19:22:34 EST (3 months ago)
Change: 1530
Author: jbauch
Files (see diff or trac for details):
doc/trunk/changelog.txt
java/server/trunk/src/org/red5/server/net/rtmp/IRTMPHandler.java
java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java
java/server/trunk/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java
java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java
Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1530
Index: /java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java (revision 1524)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java (revision 1530)
@@ -75,5 +75,5 @@
import org.red5.server.stream.StreamService;
-public class RTMPHandler implements Constants, StatusCodes {
+public class RTMPHandler implements IRTMPHandler, Constants, StatusCodes {
protected static Log log = LogFactory.getLog(RTMPHandler.class.getName());
@@ -103,4 +103,8 @@
}
+ public void connectionOpened(RTMPConnection conn, RTMP state) {
+ // Nothing to do here...
+ }
+
public void messageReceived(RTMPConnection conn, ProtocolState state,
Object in) throws Exception {
Index: /java/server/trunk/src/org/red5/server/net/rtmp/IRTMPHandler.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/IRTMPHandler.java (revision 1530)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/IRTMPHandler.java (revision 1530)
@@ -0,0 +1,35 @@
+package org.red5.server.net.rtmp;
+
+/*
+ * RED5 Open Source Flash Server - http://www.osflash.org/red5
+ *
+ * Copyright (c) 2006 by respective authors (see below). All rights reserved.
+ *
+ * This library is free software; you can redistribute it and/or modify it under the
+ * terms of the GNU Lesser General Public License as published by the Free Software
+ * Foundation; either version 2.1 of the License, or (at your option) any later
+ * version.
+ *
+ * This library is distributed in the hope that it will be useful, but WITHOUT ANY
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License along
+ * with this library; if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+import org.red5.server.net.protocol.ProtocolState;
+import org.red5.server.net.rtmp.codec.RTMP;
+
+public interface IRTMPHandler {
+
+ public void connectionOpened(RTMPConnection conn, RTMP state);
+
+ public void messageReceived(RTMPConnection conn, ProtocolState state, Object message) throws Exception;
+
+ public void messageSent(RTMPConnection conn, Object message);
+
+ public void connectionClosed(RTMPConnection conn, RTMP state);
+
+}
Index: /java/server/trunk/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java (revision 1406)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/RTMPMinaIoHandler.java (revision 1530)
@@ -38,8 +38,13 @@
.getName());
- protected RTMPHandler handler;
+ protected IRTMPHandler handler;
+ protected boolean mode = RTMP.MODE_SERVER;
- public void setHandler(RTMPHandler handler) {
+ public void setHandler(IRTMPHandler handler) {
this.handler = handler;
+ }
+
+ public void setMode(boolean mode) {
+ this.mode = mode;
}
@@ -78,23 +83,35 @@
final RTMP rtmp = (RTMP) state;
+ if (rtmp.getMode()==RTMP.MODE_SERVER) {
+ if (rtmp.getState() != RTMP.STATE_HANDSHAKE) {
+ log.warn("Raw buffer after handshake, something odd going on");
+ }
- if (rtmp.getState() != RTMP.STATE_HANDSHAKE) {
- log.warn("Raw buffer after handshake, something odd going on");
+ if (log.isDebugEnabled()){
+ log.debug("Handshake 2nd phase");
+ log.debug("handshake size:"+in.remaining());
+ }
+ ByteBuffer out = ByteBuffer.allocate((Constants.HANDSHAKE_SIZE*2)+1);
+ out.put((byte)0x03);
+ out.fill((byte)0x00,Constants.HANDSHAKE_SIZE);
+ out.put(in);
+ out.flip();
+ //in.release();
+ session.write(out);
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("Handshake 3d phase");
+ log.debug("handshake size:"+in.remaining());
+ }
+ in.skip(1);
+ ByteBuffer out = ByteBuffer.allocate(Constants.HANDSHAKE_SIZE);
+ int limit=in.limit();
+ in.limit(in.position()+Constants.HANDSHAKE_SIZE);
+ out.put(in);
+ out.flip();
+ in.limit(limit);
+ in.skip(Constants.HANDSHAKE_SIZE);
+ session.write(out);
}
-
- ByteBuffer out = ByteBuffer
- .allocate((Constants.HANDSHAKE_SIZE * 2) + 1);
-
- if (log.isDebugEnabled()) {
- log.debug("Writing handshake reply");
- log.debug("handskake size:" + in.remaining());
- }
-
- out.put((byte) 0x03);
- out.fill((byte) 0x00, Constants.HANDSHAKE_SIZE);
- out.put(in).flip();
- //in.release();
- session.write(out);
-
}
@@ -102,7 +119,15 @@
public void messageSent(IoSession session, Object message) throws Exception {
log.debug("messageSent");
+ final RTMP rtmp = (RTMP) session.getAttribute(RTMP.SESSION_KEY);
final RTMPMinaConnection conn = (RTMPMinaConnection) session
.getAttachment();
handler.messageSent(conn, message);
+ if (mode == RTMP.MODE_CLIENT) {
+ if (message instanceof ByteBuffer) {
+ if (((ByteBuffer)message).limit() == Constants.HANDSHAKE_SIZE) {
+ handler.connectionOpened((RTMPMinaConnection)session.getAttachment(), (RTMP)session.getAttribute(RTMP.SESSION_KEY));
+ }
+ }
+ }
}
@@ -118,4 +143,15 @@
super.sessionOpened(session);
+ RTMP rtmp=(RTMP)session.getAttribute(RTMP.SESSION_KEY);
+ if (rtmp.getMode()==RTMP.MODE_CLIENT) {
+ if (log.isDebugEnabled()){
+ log.debug("Handshake 1st phase");
+ }
+ ByteBuffer out = ByteBuffer.allocate(Constants.HANDSHAKE_SIZE+1);
+ out.put((byte)0x03);
+ out.fill((byte)0x00,Constants.HANDSHAKE_SIZE);
+ out.flip();
+ session.write(out);
+ }
}
@@ -140,6 +176,5 @@
// moved protocol state from connection object to rtmp object
- session.setAttribute(ProtocolState.SESSION_KEY, new RTMP(
- RTMP.MODE_SERVER));
+ session.setAttribute(ProtocolState.SESSION_KEY, new RTMP(mode));
session.getFilterChain().addFirst("protocolFilter",
Index: /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java (revision 1519)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java (revision 1530)
@@ -407,5 +407,5 @@
if (invoke instanceof Invoke) {
serializer.serialize(output, Integer.valueOf(invoke.getInvokeId()));
- serializer.serialize(output, null);
+ serializer.serialize(output, invoke.getConnectionParams());
}
if (!isPending && (invoke instanceof Invoke)) {
Index: /doc/trunk/changelog.txt
===================================================================
--- /doc/trunk/changelog.txt (revision 1528)
+++ /doc/trunk/changelog.txt (revision 1530)
@@ -9,4 +9,5 @@
New features:
- Stream classes can be configured through red5-common.xml (Trac #223)
+- RTMP network library supports client mode (Trac #94)
Bugfixes:
Note:
Diffs are chopped if more than 25k.
This is to get past the limit on the mailing list.
More information about the Red5commits
mailing list