Beispiel #1
0
        /// <summary>
        /// Plays media files.
        /// </summary>
        /// <param name="arguments">The name of a file, start time, duration of playback, reset flag.</param>
        public void Play(params object[] arguments)
        {
            ValidationUtils.ArgumentConditionTrue(arguments != null && arguments.Length > 0, "arguments", "At least the name of a file must be specified");
            ValidationUtils.ArgumentNotNullOrEmptyOrWhitespace(arguments[0] as string, "name");
            _name   = arguments[0] as string;
            _start  = -2;
            _length = -1;
            if (arguments.Length > 1)
            {
                ValidationUtils.ArgumentConditionTrue(arguments[1] is int, "start", "Integer value required for the 'start' parameter");
                _start = (int)arguments[1];
                ValidationUtils.ArgumentConditionTrue(_start > -3, "start", "Allowed values are -2, -1, 0, or a positive number");
            }
            if (arguments.Length > 2)
            {
                ValidationUtils.ArgumentConditionTrue(arguments[2] is int, "len", "Integer value required for the 'len' parameter");
                _length = (int)arguments[2];
                ValidationUtils.ArgumentConditionTrue(_length > -2, "len", "Allowed values are -1, 0, or a positive number");
            }

            INetConnectionClient    client     = _connection.NetConnectionClient;
            RtmpConnection          connection = _connection.NetConnectionClient.Connection as RtmpConnection;
            IPendingServiceCallback callback   = new CreateStreamCallBack(this, connection, this);

            client.Call("createStream", callback);
        }
Beispiel #2
0
        /// <summary>
        /// Connects to a remote shared object on the server through the specified connection. Use this method after
        /// issuing SharedObject.GetRemote(...). After a successful connection, the sync event is dispatched.
        /// </summary>
        /// <param name="connection">A NetConnection object (such as one used to communicate with Flash Media Server) that is using the Real-Time Messaging Protocol (RTMP).</param>
        /// <param name="parameters">Parameters.</param>
        public void Connect(NetConnection connection, string parameters)
        {
            if (_initialSyncReceived)
            {
                throw new InvalidOperationException("SharedObject already connected");
            }
            ValidationUtils.ArgumentNotNull(connection, "connection");
            ValidationUtils.ArgumentNotNull(connection.Uri, "connection");
            ValidationUtils.ArgumentConditionTrue(connection.Uri.Scheme == "rtmp", "connection", "NetConnection object must use the Real-Time Messaging Protocol (RTMP)");
            ValidationUtils.ArgumentConditionTrue(connection.Connected, "connection", "NetConnection object must be connected");
            _connection          = connection;
            _initialSyncReceived = false;

            FluorineFx.Messaging.Rtmp.SO.SharedObjectMessage message;
            if (connection.ObjectEncoding == ObjectEncoding.AMF0)
            {
                message = new FluorineFx.Messaging.Rtmp.SO.SharedObjectMessage(_name, _version, _persistentSO);
            }
            else
            {
                message = new FluorineFx.Messaging.Rtmp.SO.FlexSharedObjectMessage(_name, _version, _persistentSO);
            }
            FluorineFx.Messaging.Rtmp.SO.SharedObjectEvent evt = new FluorineFx.Messaging.Rtmp.SO.SharedObjectEvent(FluorineFx.Messaging.Rtmp.SO.SharedObjectEventType.SERVER_CONNECT, null, null);
            message.AddEvent(evt);
            _connection.NetConnectionClient.Write(message);
        }
Beispiel #3
0
 private static RemoteSharedObject GetRemote(Type type, string name, string remotePath, object persistence, bool secure)
 {
     lock ((SharedObjects as ICollection).SyncRoot) {
         if (SharedObjects.ContainsKey(name))
         {
             return(SharedObjects[name] as RemoteSharedObject);
         }
         RemoteSharedObject rso = Activator.CreateInstance(type) as RemoteSharedObject;
         ValidationUtils.ArgumentConditionTrue(rso != null, "type", "Expecting a RemoteSharedObject type");
         rso._name                = name;
         rso._path                = remotePath;
         rso._persistentSO        = !false.Equals(persistence);
         rso._secure              = secure;
         rso._objectEncoding      = ObjectEncoding.AMF0;
         rso._initialSyncReceived = false;
         rso._ownerMessage        = new SharedObjectMessage(null, null, -1, false);
         SharedObjects[name]      = rso;
         return(rso);
     }
 }
Beispiel #4
0
 private static RemoteSharedObject GetRemote(Type type, string name, string remotePath, object persistence, bool secure)
 {
     lock (((ICollection)SharedObjects).SyncRoot)
     {
         if (SharedObjects.ContainsKey(name))
         {
             return(SharedObjects[name]);
         }
         RemoteSharedObject obj2 = Activator.CreateInstance(type) as RemoteSharedObject;
         ValidationUtils.ArgumentConditionTrue(obj2 != null, "type", "Expecting a RemoteSharedObject type");
         obj2._name = name;
         obj2._path = remotePath;
         bool flag2 = false;
         obj2._persistentSO        = !flag2.Equals(persistence);
         obj2._secure              = secure;
         obj2._objectEncoding      = FluorineFx.ObjectEncoding.AMF0;
         obj2._initialSyncReceived = false;
         obj2._ownerMessage        = new SharedObjectMessage(null, null, -1, false);
         SharedObjects[name]       = obj2;
         return(obj2);
     }
 }
Beispiel #5
0
        /// <summary>
        /// Compresses the byte array using zlib compression. The entire byte array is compressed.
        /// </summary>
        /// <param name="algorithm">The compression algorithm to use when compressing. Valid values are defined as constants in the CompressionAlgorithm class. The default is to use zlib format.</param>
        /// <remarks>
        /// After the call, the Length property of the ByteArray is set to the new length. The position property is set to the end of the byte array.
        /// </remarks>
        public void Compress(string algorithm)
        {
            ValidationUtils.ArgumentConditionTrue(algorithm == CompressionAlgorithm.Deflate || algorithm == CompressionAlgorithm.Zlib, "algorithm", "Invalid parameter");
#if SILVERLIGHT
            throw new NotSupportedException();
#else
            if (algorithm == CompressionAlgorithm.Deflate)
            {
                byte[]        buffer        = _memoryStream.ToArray();
                MemoryStream  ms            = new MemoryStream();
                DeflateStream deflateStream = new DeflateStream(ms, CompressionMode.Compress, true);
                deflateStream.Write(buffer, 0, buffer.Length);
                deflateStream.Close();
                _memoryStream.Close();
                _memoryStream = ms;
                AMFReader amfReader = new AMFReader(_memoryStream);
                AMFWriter amfWriter = new AMFWriter(_memoryStream);
                _dataOutput = new DataOutput(amfWriter);
                _dataInput  = new DataInput(amfReader);
            }
            if (algorithm == CompressionAlgorithm.Zlib)
            {
                byte[]       buffer     = _memoryStream.ToArray();
                MemoryStream ms         = new MemoryStream();
                ZlibStream   zlibStream = new ZlibStream(ms, CompressionMode.Compress, true);
                zlibStream.Write(buffer, 0, buffer.Length);
                zlibStream.Flush();
                zlibStream.Close();
                zlibStream.Dispose();
                _memoryStream.Close();
                _memoryStream = ms;
                AMFReader amfReader = new AMFReader(_memoryStream);
                AMFWriter amfWriter = new AMFWriter(_memoryStream);
                _dataOutput = new DataOutput(amfWriter);
                _dataInput  = new DataInput(amfReader);
            }
#endif
        }
Beispiel #6
0
        /// <summary>
        /// Decompresses the byte array. The byte array must have been previously compressed with the Compress() method.
        /// </summary>
        /// <param name="algorithm">The compression algorithm to use when decompressing. This must be the same compression algorithm used to compress the data. Valid values are defined as constants in the CompressionAlgorithm class. The default is to use zlib format.</param>
        public void Uncompress(string algorithm)
        {
            ValidationUtils.ArgumentConditionTrue(algorithm == CompressionAlgorithm.Deflate || algorithm == CompressionAlgorithm.Zlib, "algorithm", "Invalid parameter");
#if SILVERLIGHT
            throw new NotSupportedException();
#else
            if (algorithm == CompressionAlgorithm.Zlib)
            {
                //The zlib format is specified by RFC 1950. Zlib also uses deflate, plus 2 or 6 header bytes, and a 4 byte checksum at the end.
                //The first 2 bytes indicate the compression method and flags. If the dictionary flag is set, then 4 additional bytes will follow.
                //Preset dictionaries aren't very common and we don't support them
                Position = 0;
                ZlibStream   deflateStream = new ZlibStream(_memoryStream, CompressionMode.Decompress, false);
                MemoryStream ms            = new MemoryStream();
                byte[]       buffer        = new byte[1024];
                // Chop off the first two bytes
                //int b = _memoryStream.ReadByte();
                //b = _memoryStream.ReadByte();
                while (true)
                {
                    int readCount = deflateStream.Read(buffer, 0, buffer.Length);
                    if (readCount > 0)
                    {
                        ms.Write(buffer, 0, readCount);
                    }
                    else
                    {
                        break;
                    }
                }
                deflateStream.Close();
                _memoryStream.Close();
                _memoryStream.Dispose();
                _memoryStream          = ms;
                _memoryStream.Position = 0;
            }
            if (algorithm == CompressionAlgorithm.Deflate)
            {
                Position = 0;
                DeflateStream deflateStream = new DeflateStream(_memoryStream, CompressionMode.Decompress, false);
                MemoryStream  ms            = new MemoryStream();
                byte[]        buffer        = new byte[1024];
                while (true)
                {
                    int readCount = deflateStream.Read(buffer, 0, buffer.Length);
                    if (readCount > 0)
                    {
                        ms.Write(buffer, 0, readCount);
                    }
                    else
                    {
                        break;
                    }
                }
                deflateStream.Close();
                _memoryStream.Close();
                _memoryStream.Dispose();
                _memoryStream          = ms;
                _memoryStream.Position = 0;
            }
            AMFReader amfReader = new AMFReader(_memoryStream);
            AMFWriter amfWriter = new AMFWriter(_memoryStream);
            _dataOutput = new DataOutput(amfWriter);
            _dataInput  = new DataInput(amfReader);
#endif
        }