[Red5commits] [1631] keep AMF encoding to use in protocol statethis fixes APPSERVER-32 and SN-15

jbauch luke at codegent.com
Wed Jan 24 11:10:12 EST 2007


keep AMF encoding to use in protocol state
this fixes APPSERVER-32 and SN-15


Timestamp: 01/18/07 18:36:28 EST (6 days ago) 
Change: 1631 
Author: jbauch

Files (see diff or trac for details): 
java/server/trunk/src/org/red5/server/net/rtmp/BaseRTMPHandler.java
java/server/trunk/src/org/red5/server/net/rtmp/RTMPClient.java
java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java
java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventDecoder.java
java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventEncoder.java
java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMP.java
java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java
java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java


Trac: http://mirror1.cvsdude.com/trac/osflash/red5/changeset/1631

Index: /java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java (revision 1628)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/RTMPHandler.java (revision 1631)
@@ -24,4 +24,6 @@
 import org.red5.server.api.*;
 import static org.red5.server.api.ScopeUtils.getScopeService;
+
+import org.red5.server.api.IConnection.Encoding;
 import org.red5.server.api.service.IPendingServiceCall;
 import org.red5.server.api.service.IServiceCall;
@@ -35,4 +37,5 @@
 import org.red5.server.messaging.IConsumer;
 import org.red5.server.messaging.OOBControlMessage;
+import org.red5.server.net.rtmp.codec.RTMP;
 import org.red5.server.net.rtmp.event.ChunkSize;
 import org.red5.server.net.rtmp.event.Invoke;
@@ -166,5 +169,5 @@
 	/** {@inheritDoc} */
     protected void onInvoke(RTMPConnection conn, Channel channel, Header source,
-			Notify invoke) {
+			Notify invoke, RTMP rtmp) {
 
 		log.debug("Invoke");
@@ -270,7 +273,9 @@
 											result.put("application", status.getApplication());
 											result.put("level", status.getLevel());
-											if (params.get("objectEncoding") == Integer.valueOf(3))
+											if (params.get("objectEncoding") == Integer.valueOf(3)) {
 												// Client wants to use AMF3 encoding
 												result.put("objectEncoding", 3);
+												rtmp.setEncoding(Encoding.AMF3);
+											}
 											pc.setResult(result);
 										}
Index: /java/server/trunk/src/org/red5/server/net/rtmp/RTMPClient.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/RTMPClient.java (revision 1625)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/RTMPClient.java (revision 1631)
@@ -222,5 +222,5 @@
 	/** {@inheritDoc} */
     protected void onInvoke(RTMPConnection conn, Channel channel,
-			Header source, Notify invoke) {
+			Header source, Notify invoke, RTMP rtmp) {
 		final IServiceCall call = invoke.getCall();
 		if (call.getServiceMethodName().equals("_result")
Index: /java/server/trunk/src/org/red5/server/net/rtmp/BaseRTMPHandler.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/BaseRTMPHandler.java (revision 1625)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/BaseRTMPHandler.java (revision 1631)
@@ -118,5 +118,5 @@
 				case TYPE_INVOKE:
 				case TYPE_FLEX_MESSAGE:
-					onInvoke(conn, channel, header, (Invoke) message);
+					onInvoke(conn, channel, header, (Invoke) message, (RTMP) state);
 					if(message.getHeader().getStreamId()!=0  
 							&& ((Invoke)message).getCall().getServiceName()==null
@@ -134,5 +134,5 @@
 						((IEventDispatcher) stream).dispatchEvent(message);
 					} else {
-						onInvoke(conn, channel, header, (Notify) message);
+						onInvoke(conn, channel, header, (Notify) message, (RTMP) state);
 					}
 					break;
@@ -269,7 +269,8 @@
      * @param source       Header
      * @param invoke       Invocation event context
+     * @param rtmp		   RTMP connection state
      */
     protected abstract void onInvoke(RTMPConnection conn, Channel channel,
-			Header source, Notify invoke);
+			Header source, Notify invoke, RTMP rtmp);
 
     /**
Index: /java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventDecoder.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventDecoder.java (revision 1606)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventDecoder.java (revision 1631)
@@ -54,21 +54,24 @@
      * Decodes shared object message event
      * @param in                     Byte buffer to decode
+     * @param rtmp					 RTMP protocol state
      * @return                       ISharedObjectMessage event
      */
-	public abstract ISharedObjectMessage decodeSharedObject(ByteBuffer in);
+	public abstract ISharedObjectMessage decodeSharedObject(ByteBuffer in, RTMP rtmp);
 
     /**
      * Decodes notification event
      * @param in                     Byte buffer to decode
+     * @param rtmp					 RTMP protocol state
      * @return                       Notify event
      */
-    public abstract Notify decodeNotify(ByteBuffer in);
+    public abstract Notify decodeNotify(ByteBuffer in, RTMP rtmp);
 
     /**
      * Decodes invocation event
      * @param in                     Byte buffer to decode
+     * @param rtmp					 RTMP protocol state
      * @return                       Invoke event
      */
-    public abstract Invoke decodeInvoke(ByteBuffer in);
+    public abstract Invoke decodeInvoke(ByteBuffer in, RTMP rtmp);
 
     /**
@@ -103,6 +106,7 @@
      * Decodes Flex message event
      * @param in                     Byte buffer to decode
+     * @param rtmp					 RTMP protocol state
      * @return                       FlexMessage event
      */
-    public abstract FlexMessage decodeFlexMessage(ByteBuffer in);
+    public abstract FlexMessage decodeFlexMessage(ByteBuffer in, RTMP rtmp);
 }
Index: /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMP.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMP.java (revision 1606)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMP.java (revision 1631)
@@ -20,4 +20,5 @@
  */
 
+import org.red5.server.api.IConnection.Encoding;
 import org.red5.server.net.protocol.ProtocolState;
 import org.red5.server.net.rtmp.message.Header;
@@ -104,5 +105,9 @@
      */
 	private int writeChunkSize = DEFAULT_CHUNK_SIZE;
-
+	/**
+	 * Encoding type for objects
+	 */
+	private Encoding encoding = Encoding.AMF0;
+	
     /**
      * Creates RTMP object with initial mode
@@ -316,3 +321,21 @@
 	}
 
+    /**
+     * Getter for encoding version.
+     * 
+     * @return Encoding version
+     */
+    public Encoding getEncoding() {
+    	return encoding;
+    }
+    
+    /**
+     * Setter for encoding version.
+     * 
+     * @param encoding	Encoding version
+     */
+    public void setEncoding(Encoding encoding) {
+    	this.encoding = encoding;
+    }
+    
 }
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 1628)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolEncoder.java (revision 1631)
@@ -75,7 +75,6 @@
      * @return
      */
-    private Output getOutput(ByteBuffer buffer) {
-		IConnection conn = Red5.getConnectionLocal();
-		if (conn.getEncoding() == Encoding.AMF3) {
+    private Output getOutput(RTMP rtmp, ByteBuffer buffer) {
+		if (rtmp.getEncoding() == Encoding.AMF3) {
 			return new org.red5.io.amf3.Output(buffer);
 		} else {
@@ -119,5 +118,5 @@
 
 		try {
-			data = encodeMessage(header, message);
+			data = encodeMessage(rtmp, header, message);
 		} finally {
 			message.release();
@@ -226,19 +225,20 @@
     /**
      * Encode message
+     * @param rtmp        RTMP protocol state
      * @param header      RTMP message header
      * @param message     RTMP message (event)
      * @return            Encoded message data
      */
-    public ByteBuffer encodeMessage(Header header, IRTMPEvent message) {
+    public ByteBuffer encodeMessage(RTMP rtmp, Header header, IRTMPEvent message) {
 		switch (header.getDataType()) {
 			case TYPE_CHUNK_SIZE:
 				return encodeChunkSize((ChunkSize) message);
 			case TYPE_INVOKE:
-				return encodeInvoke((Invoke) message);
+				return encodeInvoke((Invoke) message, rtmp);
 			case TYPE_NOTIFY:
 				if (((Notify) message).getCall() == null) {
 					return encodeStreamMetadata((Notify) message);
 				} else {
-					return encodeNotify((Notify) message);
+					return encodeNotify((Notify) message, rtmp);
 				}
 			case TYPE_PING:
@@ -251,5 +251,5 @@
 				return encodeVideoData((VideoData) message);
 			case TYPE_SHARED_OBJECT:
-				return encodeSharedObject((ISharedObjectMessage) message);
+				return encodeSharedObject((ISharedObjectMessage) message, rtmp);
 			case TYPE_SERVER_BANDWIDTH:
 				return encodeServerBW((ServerBW) message);
@@ -257,5 +257,5 @@
 				return encodeClientBW((ClientBW) message);
 			case TYPE_FLEX_MESSAGE:
-				return encodeFlexMessage((FlexMessage) message);
+				return encodeFlexMessage((FlexMessage) message, rtmp);
 			default:
 				return null;
@@ -294,9 +294,9 @@
 
 	/** {@inheritDoc} */
-    public ByteBuffer encodeSharedObject(ISharedObjectMessage so) {
+    public ByteBuffer encodeSharedObject(ISharedObjectMessage so, RTMP rtmp) {
 
 		final ByteBuffer out = ByteBuffer.allocate(128);
 		out.setAutoExpand(true);
-		final Output output = getOutput(out);
+		final Output output = getOutput(rtmp, out);
 
 		output.putString(so.getName());
@@ -413,11 +413,11 @@
 
 	/** {@inheritDoc} */
-	public ByteBuffer encodeNotify(Notify notify) {
-		return encodeNotifyOrInvoke(notify);
-	}
-
-	/** {@inheritDoc} */
-	public ByteBuffer encodeInvoke(Invoke invoke) {
-		return encodeNotifyOrInvoke(invoke);
+	public ByteBuffer encodeNotify(Notify notify, RTMP rtmp) {
+		return encodeNotifyOrInvoke(notify, rtmp);
+	}
+
+	/** {@inheritDoc} */
+	public ByteBuffer encodeInvoke(Invoke invoke, RTMP rtmp) {
+		return encodeNotifyOrInvoke(invoke, rtmp);
 	}
 
@@ -427,8 +427,8 @@
      * @return                  Encoded event data
      */
-    protected ByteBuffer encodeNotifyOrInvoke(Notify invoke) {
+    protected ByteBuffer encodeNotifyOrInvoke(Notify invoke, RTMP rtmp) {
 		ByteBuffer out = ByteBuffer.allocate(1024);
 		out.setAutoExpand(true);
-		encodeNotifyOrInvoke(out, invoke);
+		encodeNotifyOrInvoke(out, invoke, rtmp);
 		return out;
 	}
@@ -439,5 +439,5 @@
      * @param invoke            Notification event
      */
-	protected void encodeNotifyOrInvoke(ByteBuffer out, Notify invoke) {
+	protected void encodeNotifyOrInvoke(ByteBuffer out, Notify invoke, RTMP rtmp) {
 		// TODO: tidy up here
 		// log.debug("Encode invoke");
@@ -469,5 +469,5 @@
 			output = new org.red5.io.amf.Output(out);
 		} else {
-			output = getOutput(out);
+			output = getOutput(rtmp, out);
 		}
 		
@@ -552,10 +552,10 @@
      * @return                   Encoded data
      */
-    public ByteBuffer encodeFlexMessage(FlexMessage msg) {
+    public ByteBuffer encodeFlexMessage(FlexMessage msg, RTMP rtmp) {
 		ByteBuffer out = ByteBuffer.allocate(1024);
 		out.setAutoExpand(true);
 		// Unknown byte, always 0?
 		out.put((byte) 0);
-		encodeNotifyOrInvoke(out, msg);
+		encodeNotifyOrInvoke(out, msg, rtmp);
 		return out;
 	}
Index: /java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventEncoder.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventEncoder.java (revision 1606)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/codec/IEventEncoder.java (revision 1631)
@@ -38,14 +38,16 @@
      * Encodes Notify event to byte buffer
      * @param notify         Notify event
+     * @param rtmp			 RTMP protocol state
      * @return               Byte buffer
      */
-	public abstract ByteBuffer encodeNotify(Notify notify);
+	public abstract ByteBuffer encodeNotify(Notify notify, RTMP rtmp);
 
     /**
      * Encodes Invoke event to byte buffer
      * @param invoke         Invoke event
+     * @param rtmp			 RTMP protocol state
      * @return               Byte buffer
      */
-	public abstract ByteBuffer encodeInvoke(Invoke invoke);
+	public abstract ByteBuffer encodeInvoke(Invoke invoke, RTMP rtmp);
 
     /**
@@ -94,7 +96,8 @@
      * Encodes SharedObjectMessage event to byte buffer
      * @param so                 ISharedObjectMessage event
+     * @param rtmp			 RTMP protocol state
      * @return                   Byte buffer
      */
-    public abstract ByteBuffer encodeSharedObject(ISharedObjectMessage so);
+    public abstract ByteBuffer encodeSharedObject(ISharedObjectMessage so, RTMP rtmp);
 
 }
Index: /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java
===================================================================
--- /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java (revision 1614)
+++ /java/server/trunk/src/org/red5/server/net/rtmp/codec/RTMPProtocolDecoder.java (revision 1631)
@@ -79,10 +79,10 @@
      * Return input (data values provider) object from byte buffer. 
      *
+     * @param rtmp			RTMP protocol state
      * @param buffer        Byte buffer
      * @return              Input object
      */
-    private Input getInput(ByteBuffer buffer) {
-		IConnection conn = Red5.getConnectionLocal();
-		if (conn != null && conn.getEncoding() == Encoding.AMF3) {
+    private Input getInput(RTMP rtmp, ByteBuffer buffer) {
+		if (rtmp.getEncoding() == Encoding.AMF3) {
 			return new org.red5.io.amf3.Input(buffer);
 		} else {
@@ -408,5 +408,5 @@
 				break;
 			case TYPE_INVOKE:
-				message = decodeInvoke(in);
+				message = decodeInvoke(in, rtmp);
 				break;
 			case TYPE_NOTIFY:
@@ -426,5 +426,5 @@
 				break;
 			case TYPE_SHARED_OBJECT:
-				message = decodeSharedObject(in);
+				message = decodeSharedObject(in, rtmp);
 				break;
 			case TYPE_SERVER_BANDWIDTH:
@@ -435,5 +435,5 @@
 				break;
 			case TYPE_FLEX_MESSAGE:
-				message = decodeFlexMessage(in);
+				message = decodeFlexMessage(in, rtmp);
 				break;
 			default:
@@ -475,7 +475,7 @@
 
 	/** {@inheritDoc} */
-	public ISharedObjectMessage decodeSharedObject(ByteBuffer in) {
-
-		final Input input = getInput(in);
+	public ISharedObjectMessage decodeSharedObject(ByteBuffer in, RTMP rtmp) {
+
+		final Input input = getInput(rtmp, in);
 		String name = input.getString();
 		// Read version of SO to modify
@@ -545,6 +545,6 @@
 
 	/** {@inheritDoc} */
-	public Notify decodeNotify(ByteBuffer in) {
-		return decodeNotify(in, null, null);
+	public Notify decodeNotify(ByteBuffer in, RTMP rtmp) {
+		return decodeNotify(in, null, rtmp);
 	}
 
@@ -554,6 +554,6 @@
 
 	/** {@inheritDoc} */
-	public Invoke decodeInvoke(ByteBuffer in) {
-		return (Invoke) decodeNotifyOrInvoke(new Invoke(), in, null, null);
+	public Invoke decodeInvoke(ByteBuffer in, RTMP rtmp) {
+		return (Invoke) decodeNotifyOrInvoke(new Invoke(), in, null, rtmp);
 	}
 
@@ -585,5 +585,5 @@
 		// TODO: we should use different code depending on server or client mode
 		int start = in.position();
-		Input input = getInput(in);
+		Input input = getInput(rtmp, in);
 
 		String action = (String) deserializer.deserialize(input);
@@ -692,7 +692,8 @@
      * Decodes FlexMessage event
      * @param in               Byte buffer
+     * @param rtmp			   RTMP protocol state
      * @return                 FlexMessage event
      */
-    public FlexMessage decodeFlexMessage(ByteBuffer in) {
+    public FlexMessage decodeFlexMessage(ByteBuffer in, RTMP rtmp) {
 		// Unknown byte, always 0?
 		in.skip(1);


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