/// <summary> /// Initializes a new instance of the RtmpContext class. /// </summary> /// <param name="mode"></param> public RtmpContext(RtmpMode mode) { //_mode = mode; _readerWriterLock = new FastReaderWriterLock(); SetMode(mode); _objectEncoding = ObjectEncoding.AMF0; }
public static StatusASO GetStatusObject(string statusCode, ObjectEncoding objectEncoding) { switch (statusCode) { case "NetConnection.Call.Failed": return(new StatusASO("NetConnection.Call.Failed", "error", string.Empty, null, objectEncoding)); case "NetConnection.Call.BadVersion": return(new StatusASO("NetConnection.Call.BadVersion", "error", string.Empty, null, objectEncoding)); case "NetConnection.Connect.AppShutdown": return(new StatusASO("NetConnection.Connect.AppShutdown", "error", string.Empty, null, objectEncoding)); case "NetConnection.Connect.Closed": return(new StatusASO("NetConnection.Connect.Closed", "error", string.Empty, null, objectEncoding)); case "NetConnection.Connect.Failed": return(new StatusASO("NetConnection.Connect.Failed", "error", string.Empty, null, objectEncoding)); case "NetConnection.Connect.Rejected": return(new StatusASO("NetConnection.Connect.Rejected", "error", string.Empty, null, objectEncoding)); case "NetConnection.Connect.Success": return(new StatusASO("NetConnection.Connect.Success", "status", string.Empty, null, objectEncoding)); } return(new StatusASO("NetConnection.Call.BadVersion", "error", string.Empty, null, objectEncoding)); }
// this method is required because of the functionality specified by classes like `IDataOutput`. public void WriteAmfItem(ObjectEncoding encoding, object data) { // if it's null, we don't need to do expensive operations to determine how to write it if (data == null) { WriteMarker(Amf0TypeMarkers.Null); return; } if (WriteAmf0ReferenceOnExistence(data)) { return; } var type = data.GetType(); switch (encoding) { case ObjectEncoding.Amf0: var writer = GetAmfWriter(Amf0Writers, type); writer.WriteData(this, data); break; case ObjectEncoding.Amf3: WriteMarker(Amf0TypeMarkers.Amf3Object); WriteAmf3Item(data); break; default: throw new ArgumentOutOfRangeException("encoding"); } }
public void WriteAmfItem(ObjectEncoding objectEncoding, object data) { if (data == null) { this.WriteMarker(Amf0TypeMarkers.Null); } else { if (this.WriteAmf0ReferenceOnExistence(data)) { return; } Type type = data.GetType(); if (objectEncoding != ObjectEncoding.Amf0) { if (objectEncoding != ObjectEncoding.Amf3) { throw new ArgumentOutOfRangeException("objectEncoding"); } this.WriteMarker(Amf0TypeMarkers.Amf3Object); this.WriteAmf3Item(data); } else { AmfWriter.GetAmfWriter(AmfWriter.Amf0Writers, type).WriteData(this, data); } } }
// writes an object, with the specified encoding. if amf3 encoding is specified, then it is wrapped in an // amf0 envelope that says to upgrade the encoding to amf3 public void WriteBoxedItem(ObjectEncoding encoding, object value) { if (value == null) { WriteMarker(Marker.Null); } else if (ReferenceGet(value, out var index)) { WriteMarker(Marker.Reference); b.WriteUInt16(index); } else { switch (encoding) { case ObjectEncoding.Amf0: WriteItemInternal(value); break; case ObjectEncoding.Amf3: WriteMarker(Marker.Amf3Object); amf3.WriteItem(value); break; default: throw new ArgumentOutOfRangeException(nameof(encoding)); } } }
public RtmpServer( SerializationContext context, X509Certificate2 cert = null, ObjectEncoding object_encoding = ObjectEncoding.Amf0, ParameterAuthCallback publishParameterAuth = null, ParameterAuthCallback playParameterAuth = null, string bindIp = "0.0.0.0", int bindRtmpPort = 1935, int bindWebsocketPort = 1936 ) { this.Context = context; this.AmfEncoding = object_encoding; this.Certificate = cert; if (publishParameterAuth != null) { this.PublishParameterAuth = publishParameterAuth; } if (playParameterAuth != null) { this.PlayParameterAuth = playParameterAuth; } this._bindIp = bindIp; this._bindRtmpPort = bindRtmpPort; this._bindWebsocketPort = bindWebsocketPort; this.ClientWorkHandler(); }
// This method is required because of the functionality specified by classes like `IDataOutput`. public void WriteAmfItem(ObjectEncoding objectEncoding, object data) { // Short circuit - no need to perform expensive operations to write a null if (data == null) { WriteMarker(Amf0TypeMarkers.Null); return; } if (WriteAmf0ReferenceOnExistence(data)) { return; } var type = data.GetType(); switch (objectEncoding) { case ObjectEncoding.Amf0: var writer = GetAmfWriter(Amf0Writers, type); writer.WriteData(this, data); break; case ObjectEncoding.Amf3: WriteMarker(Amf0TypeMarkers.Amf3Object); WriteAmf3Item(data); break; default: throw new ArgumentOutOfRangeException("objectEncoding"); } }
/// <summary> /// AMF0ASObjectReader->3 /// </summary> /// <param name="objectEncoding"></param> /// <param name="asObject"></param> public void WriteASObject(ObjectEncoding objectEncoding, ASObject asObject) { if (asObject != null) { AddAMF0ObjectReference(asObject); if (asObject.TypeName == null) { WriteByte(AMF0TypeCode.ASObject); } else { WriteByte(AMF0TypeCode.CustomClass); WriteUTF(asObject.TypeName); } foreach (KeyValuePair <string, object> entry in asObject) { WriteUTF(entry.Key); WriteData(objectEncoding, entry.Value); } WriteEndMarkup(); } else { WriteNull(); } }
/// <summary> /// Gets a Status ActionScript Object with the specified status code. /// </summary> /// <param name="statusCode">Status code.</param> /// <param name="objectEncoding">Encoding.</param> /// <returns>A Status ActionScript Object.</returns> public static StatusASO GetStatusObject(string statusCode, ObjectEncoding objectEncoding) { switch (statusCode) { case NC_CALL_FAILED: return(new StatusASO(NC_CALL_FAILED, ERROR, string.Empty, null, objectEncoding)); case NC_CALL_BADVERSION: return(new StatusASO(NC_CALL_BADVERSION, ERROR, string.Empty, null, objectEncoding)); case NC_CONNECT_APPSHUTDOWN: return(new StatusASO(NC_CONNECT_APPSHUTDOWN, ERROR, string.Empty, null, objectEncoding)); case NC_CONNECT_CLOSED: return(new StatusASO(NC_CONNECT_CLOSED, STATUS, string.Empty, null, objectEncoding)); case NC_CONNECT_FAILED: return(new StatusASO(NC_CONNECT_FAILED, ERROR, string.Empty, null, objectEncoding)); case NC_CONNECT_REJECTED: return(new StatusASO(NC_CONNECT_REJECTED, ERROR, string.Empty, null, objectEncoding)); case NC_CONNECT_SUCCESS: return(new StatusASO(NC_CONNECT_SUCCESS, STATUS, string.Empty, null, objectEncoding)); default: return(new StatusASO(NC_CALL_BADVERSION, ERROR, string.Empty, null, objectEncoding)); } }
public RtmpProxySource(SerializationContext serializationContext, Stream stream) : this(serializationContext) { this.DoHandshake(stream); this.EstablishThreads(stream); this._objectEncoding = ObjectEncoding.Amf3; }
public void WriteASO(ObjectEncoding objectEncoding, ASObject asObject) { if (asObject != null) { this.AddReference(asObject); if (asObject.TypeName == null) { this.BaseStream.WriteByte(3); } else { this.BaseStream.WriteByte(0x10); this.WriteUTF(asObject.TypeName); } foreach (KeyValuePair <string, object> pair in asObject) { this.WriteUTF(pair.Key.ToString()); this.WriteData(objectEncoding, pair.Value); } this.WriteEndMarkup(); } else { this.WriteNull(); } }
internal void WriteBody(ObjectEncoding objectEncoding, AMFWriter writer) { writer.Reset(); if (Target == null) { writer.WriteUTF("null"); } else { writer.WriteUTF(Target); } if (Response == null) { writer.WriteUTF("null"); } else { writer.WriteUTF(Response); } writer.WriteInt32(-1); WriteBodyData(objectEncoding, writer); }
public void WriteData(ObjectEncoding objectEncoding, object data) { if (data == null) { WriteNull(); return; } Type type = data.GetType(); if (amf0ObjectReferences.ContainsKey(data)) { WriteReference(data); return; } IAMFWriter amfWriter = null; if (AmfWriterTable[0].ContainsKey(type)) { amfWriter = AmfWriterTable[0][type] as IAMFWriter; } if (amfWriter == null) { if (type.BaseType != null) { if (AmfWriterTable[0].ContainsKey(type.BaseType)) { amfWriter = AmfWriterTable[0][type.BaseType] as IAMFWriter; } } } if (amfWriter == null) { amfWriter = new AMF0ObjectWriter(); } if (objectEncoding == ObjectEncoding.AMF0) { amfWriter.WriteData(this, data); } else { if (amfWriter.IsPrimitive) { amfWriter.WriteData(this, data); } else { WriteByte(AMF0TypeCode.AMF3Tag); WriteAMF3Data(data); } } }
private void WriteHeader(AMFHeader header, ObjectEncoding objectEncoding) { base.Reset(); base.WriteUTF(header.Name); base.WriteBoolean(header.MustUnderstand); base.WriteInt32(-1); base.WriteData(objectEncoding, header.Content); }
internal void WriteBody(ObjectEncoding objectEncoding, AMFWriter writer) { writer.Reset(); writer.WriteUTF(Target ?? "null"); writer.WriteUTF(Response ?? "null"); writer.WriteInt32(-1); WriteBodyData(objectEncoding, writer); }
private void WriteHeader(AmfPacketHeader header, ObjectEncoding objectEncoding) { base.Reset(); base.WriteUtfPrefixed(header.Name); base.WriteBoolean(header.MustUnderstand); base.WriteInt32(-1); base.WriteAmfItem(objectEncoding, header.Content); }
public StatusAsObject(string code, string level, string description, object application, ObjectEncoding objectEncoding) { this["code"] = code; this["level"] = level; this["description"] = description; this["application"] = application; this["objectEncoding"] = (double)objectEncoding; }
public StatusAsObject(string code, string level, string description, object application, ObjectEncoding objectEncoding) { this["code"] = code; this["level"] = level; this["description"] = description; this["application"] = application; this["objectEncoding"] = (double)objectEncoding; }
/// <summary> /// Initializes a new instance of the ByteArray class. /// </summary> /// <param name="ms">The MemoryStream from which to create the current ByteArray.</param> public ByteArray(MemoryStream ms) { _memoryStream = ms; var amfReader = new AMFReader(_memoryStream); var amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); _objectEncoding = ObjectEncoding.AMF3; }
public RtmpClient(Uri uri, ObjectEncoding objectEncoding, SerializationContext serializationContext, RemoteCertificateValidationCallback certificateValidator) : this(uri, serializationContext, objectEncoding) { if (certificateValidator == null) { throw new ArgumentNullException("certificateValidator"); } this._certificateValidator = certificateValidator; }
public FlvPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding) { this.objectEncoding = objectEncoding; this.writer = writer; queuedPackets = new ConcurrentQueue <RtmpPacket>(); packetAvailableEvent = new AutoResetEvent(false); Continue = true; }
public RtmpPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding) { this._objectEncoding = objectEncoding; this._writer = writer; this._rtmpHeaders = new Dictionary <int, RtmpHeader>(); this._rtmpPackets = new Dictionary <int, RtmpPacket>(); this._queuedPackets = new ConcurrentQueue <RtmpPacket>(); this._packetAvailableEvent = new AutoResetEvent(false); this.Continue = true; }
private RemoteSharedObject(string name, string remotePath, object persistence, bool secure) { _name = name; _path = remotePath; _persistentSO = !false.Equals(persistence); _secure = secure; _objectEncoding = ObjectEncoding.AMF0; _initialSyncReceived = false; _ownerMessage = new SharedObjectMessage(null, null, -1, false); }
public AmfWriter(Stream stream, SerializationContext serializationContext, ObjectEncoding objectEncoding) { this._objectEncoding = objectEncoding; this._underlying = new BinaryWriter(stream); this._amf0ObjectReferences = new Dictionary <object, int>(); this._amf3ObjectReferences = new Dictionary <object, int>(); this._amf3StringReferences = new Dictionary <object, int>(); this._amf3ClassDefinitionReferences = new Dictionary <ClassDescription, int>(); this.SerializationContext = serializationContext; }
/// <summary> /// Initializes a new instance of the ByteArray class. /// </summary> /// <param name="ms">The MemoryStream from which to create the current ByteArray.</param> public ByteArray(MemoryStream ms) { _memoryStream = ms; AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); _objectEncoding = ObjectEncoding.AMF3; }
void WriteData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding) { if (o is Command) { WriteCommandOrData(writer, o, encoding); } else if (o is ByteData) { writer.WriteBytes(((ByteData)o).Data); } }
public RtmpPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding) { this.objectEncoding = objectEncoding; this.writer = writer; rtmpHeaders = new Dictionary<int, RtmpHeader>(); queuedPackets = new ConcurrentQueue<RtmpPacket>(); packetAvailableEvent = new AutoResetEvent(false); Continue = true; }
public FlvPacketWriter(AmfWriter writer, ObjectEncoding objectEncoding) { this._objectEncoding = objectEncoding; this._writer = writer; _packetQueue = new ConcurrentQueue <RtmpPacket>(); _packetAvailableEvent = new AutoResetEvent(false); _started = true; }
/// <summary> /// Initializes a new instance of the ByteArray class. /// </summary> /// <param name="buffer">The array of unsigned bytes from which to create the current ByteArray.</param> public ByteArray(byte[] buffer) { _memoryStream = new MemoryStream(); _memoryStream.Write(buffer, 0, buffer.Length); _memoryStream.Position = 0; AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); _objectEncoding = ObjectEncoding.AMF3; }
/// <summary> /// Initializes a new instance of the NetConnection class. /// </summary> public NetConnection() { _clientId = null; _playerVersion = "WIN 9,0,115,0"; _objectEncoding = ObjectEncoding.AMF0; _headers = new Dictionary <string, AMFHeader>(); _client = this; #if !(SILVERLIGHT) _cookieContainer = new CookieContainer(); #endif TypeHelper._Init(); }
void WriteData(AmfWriter writer, RtmpMessage o, ObjectEncoding encoding) { var command = o as Command; if (command.MethodCall == null) { WriteCommandOrData(writer, o, encoding); } else { writer.WriteBytes(command.Buffer); } }
private void WriteData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding) { Command command = o as Command; if (command.MethodCall == null) { this.WriteCommandOrData(writer, o, encoding); } else { writer.WriteBytes(command.Buffer); } }
public RtmpConnect(Socket client_socket, Stream stream, RtmpServer server, ushort client_id, SerializationContext context, ObjectEncoding objectEncoding = ObjectEncoding.Amf0, bool asyncMode = false) { ClientId = client_id; clientSocket = client_socket; this.server = server; this.objectEncoding = objectEncoding; writer = new RtmpPacketWriter(new AmfWriter(stream, context, ObjectEncoding.Amf0, asyncMode), ObjectEncoding.Amf0); reader = new RtmpPacketReader(new AmfReader(stream, context, asyncMode)); reader.EventReceived += EventReceivedCallback; reader.Disconnected += OnPacketProcessorDisconnected; writer.Disconnected += OnPacketProcessorDisconnected; callbackManager = new TaskCallbackManager <int, object>(); }
/// <summary> /// Initializes a new instance of the BaseConnection class. /// </summary> /// <param name="path">Scope path on server.</param> /// <param name="connectionId">Connection id.</param> /// <param name="parameters">Parameters passed from client.</param> internal BaseConnection(string path, string connectionId, IDictionary parameters) { _readerWriterLock = new FastReaderWriterLock(); _readMessages = new AtomicLong(); _writtenMessages = new AtomicLong(); _droppedMessages = new AtomicLong(); //V4 GUID should be safe to remove the 4 so we can use the id for rtmpt _connectionId = connectionId; _objectEncoding = ObjectEncoding.AMF0; _path = path; _parameters = parameters; SetIsClosed(false); }
internal void WriteBody(ObjectEncoding objectEncoding, AMFWriter writer) { writer.Reset(); writer.WriteUTF(Target ?? "null"); writer.WriteUTF(Response ?? "null"); writer.WriteInt32(-1); WriteBodyData(objectEncoding, writer); }
public DataOutput(AmfWriter writer) { this.writer = writer; this.objectEncoding = ObjectEncoding.Amf3; }
/// <summary> /// Gets a Status ActionScript Object with the specified status code. /// </summary> /// <param name="statusCode">Status code.</param> /// <param name="objectEncoding">Encoding.</param> /// <returns>A Status ActionScript Object.</returns> public static StatusASO GetStatusObject(string statusCode, ObjectEncoding objectEncoding) { switch(statusCode) { case NC_CALL_FAILED: return new StatusASO(NC_CALL_FAILED, ERROR, string.Empty, null, objectEncoding); case NC_CALL_BADVERSION: return new StatusASO(NC_CALL_BADVERSION, ERROR, string.Empty, null, objectEncoding); case NC_CONNECT_APPSHUTDOWN: return new StatusASO(NC_CONNECT_APPSHUTDOWN, ERROR, string.Empty, null, objectEncoding); case NC_CONNECT_CLOSED: return new StatusASO(NC_CONNECT_CLOSED, STATUS, string.Empty, null, objectEncoding); case NC_CONNECT_FAILED: return new StatusASO(NC_CONNECT_FAILED, ERROR, string.Empty, null, objectEncoding); case NC_CONNECT_REJECTED: return new StatusASO(NC_CONNECT_REJECTED, ERROR, string.Empty, null, objectEncoding); case NC_CONNECT_SUCCESS: return new StatusASO(NC_CONNECT_SUCCESS, STATUS, string.Empty, null, objectEncoding); default: return new StatusASO(NC_CALL_BADVERSION, ERROR, string.Empty, null, objectEncoding); } }
/// <summary> /// Initializes a new instance of the StatusASO class. /// </summary> /// <param name="code">Status code.</param> /// <param name="level">Level.</param> /// <param name="description">Description.</param> /// <param name="application"></param> /// <param name="objectEncoding"></param> internal StatusASO(string code, string level, string description, object application, ObjectEncoding objectEncoding) { Add("code", code); Add("level", level); Add("description", description); Add("application", application); Add("objectEncoding", (double)objectEncoding); }
protected override void WriteBodyData(ObjectEncoding objectEncoding, AMFWriter writer) { writer.WriteData(objectEncoding, this.Content); }
void WriteCommandOrData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding) { var command = o as Command; var methodCall = command.MethodCall; var isInvoke = command is Invoke; // write the method name or result type (first section) var isRequest = methodCall.CallStatus == CallStatus.Request; if (isRequest) writer.WriteAmfItem(encoding, methodCall.Name); else writer.WriteAmfItem(encoding, methodCall.IsSuccess ? "_result" : "_error"); if (isInvoke) { writer.WriteAmfItem(encoding, command.InvokeId); writer.WriteAmfItem(encoding, command.ConnectionParameters); } if (isRequest) { // write arguments foreach (var arg in methodCall.Parameters) writer.WriteAmfItem(encoding, arg); } else if (isInvoke) { // write the result if (!methodCall.IsSuccess) methodCall.Parameters = new object[] { new StatusAsObject(StatusCode.CallFailed, "error", "Call failed.") }; writer.WriteAmfItem(encoding, methodCall.Parameters); } }
public DataOutput(AMFWriter amfWriter) { _amfWriter = amfWriter; _objectEncoding = ObjectEncoding.AMF3; }
public DataInput(AmfReader reader) { this.reader = reader; this.objectEncoding = ObjectEncoding.Amf3; }
public RtmpProxySource(SerializationContext serializationContext, Stream stream) : this(serializationContext) { DoHandshake(stream); EstablishThreads(stream); objectEncoding = ObjectEncoding.Amf3; }
/// <summary> /// This method supports the Fluorine infrastructure and is not intended to be used directly from your code. /// </summary> protected virtual void WriteBodyData(ObjectEncoding objectEncoding, AMFWriter writer) { object content = this.Content; writer.WriteData(objectEncoding, content); }
public DataInput(AMFReader amfReader) { _amfReader = amfReader; _objectEncoding = ObjectEncoding.AMF3; }
/// <summary> /// Initializes a new instance of the ByteArray class. /// </summary> /// <param name="buffer">The array of unsigned bytes from which to create the current ByteArray.</param> public ByteArray(byte[] buffer) { _memoryStream = new MemoryStream(); _memoryStream.Write(buffer, 0, buffer.Length); _memoryStream.Position = 0; AMFReader amfReader = new AMFReader(_memoryStream); AMFWriter amfWriter = new AMFWriter(_memoryStream); _dataOutput = new DataOutput(amfWriter); _dataInput = new DataInput(amfReader); _objectEncoding = ObjectEncoding.AMF3; }
void WriteData(AmfWriter writer, RtmpEvent o, ObjectEncoding encoding) { var command = o as Command; if (command.MethodCall == null) WriteCommandOrData(writer, o, encoding); else writer.WriteBytes(command.Buffer); }
/// <summary> /// Initializes a new instance of the RtmpContext class. /// </summary> /// <param name="mode"></param> public RtmpContext(RtmpMode mode) { //_mode = mode; _readerWriterLock = new FastReaderWriterLock(); SetMode(mode); _objectEncoding = ObjectEncoding.AMF0; }
internal void WriteBody(ObjectEncoding objectEncoding, AMFWriter writer) { writer.Reset(); if (this.Target == null) writer.WriteUTF("null"); else writer.WriteUTF(this.Target); if (this.Response == null) writer.WriteUTF("null"); else writer.WriteUTF(this.Response); writer.WriteInt32(-1); WriteBodyData(objectEncoding, writer); }
private void WriteHeader(AMFHeader header, ObjectEncoding objectEncoding) { base.Reset(); base.WriteUTF(header.Name); base.WriteBoolean(header.MustUnderstand); base.WriteInt32(-1); base.WriteData(objectEncoding, header.Content); }