Пример #1
0
        /// <summary>
        /// Write "onMetaData" tag to the file.
        /// </summary>
        /// <param name="duration">Duration to write in milliseconds.</param>
        /// <param name="videoCodecId">Id of the video codec used while recording.</param>
        /// <param name="audioCodecId">Id of the audio codec used while recording.</param>
        private void WriteMetadataTag(double duration, object videoCodecId, object audioCodecId)
        {
            _metaPosition = _writer.BaseStream.Position;
            MemoryStream ms     = new MemoryStream();
            AMFWriter    output = new AMFWriter(ms);

            output.WriteString("onMetaData");
            Dictionary <string, object> props = new Dictionary <string, object>();

            props.Add("duration", _duration);
            if (videoCodecId != null)
            {
                props.Add("videocodecid", videoCodecId);
            }
            if (audioCodecId != null)
            {
                props.Add("audiocodecid", audioCodecId);
            }
            props.Add("canSeekToEnd", true);
            output.WriteAssociativeArray(ObjectEncoding.AMF0, props);
            byte[] buffer = ms.ToArray();
            if (_fileMetaSize == 0)
            {
                _fileMetaSize = buffer.Length;
            }
            ITag onMetaData = new Tag(IOConstants.TYPE_METADATA, 0, buffer.Length, buffer, 0);

            WriteTag(onMetaData);
        }
Пример #2
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase base2 = data as NameObjectCollectionBase;

            object[] customAttributes = base2.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if ((customAttributes != null) && (customAttributes.Length > 0))
            {
                DefaultMemberAttribute attribute = customAttributes[0] as DefaultMemberAttribute;
                PropertyInfo           property  = base2.GetType().GetProperty(attribute.MemberName, new Type[] { typeof(string) });
                if (property != null)
                {
                    ASObject obj2 = new ASObject();
                    for (int i = 0; i < base2.Keys.Count; i++)
                    {
                        string key  = base2.Keys[i];
                        object obj3 = property.GetValue(base2, new object[] { key });
                        obj2.Add(key, obj3);
                    }
                    writer.WriteByte(10);
                    writer.WriteAMF3Object(obj2);
                    return;
                }
            }
            writer.WriteByte(10);
            writer.WriteAMF3Object(data);
        }
Пример #3
0
        public void WriteData(AMFWriter writer, object data)
        {
            writer.WriteByte(AMF0TypeCode.Number);
            double dbl = (double)Convert.ToInt32(data);

            writer.WriteDouble(dbl);
        }
Пример #4
0
        /// <summary>
        /// Create file metadata object
        /// </summary>
        /// <returns></returns>
        private ITag CreateFileMeta()
        {
            // Create tag for onMetaData event
            ByteBuffer buf = ByteBuffer.Allocate(1024);

            buf.AutoExpand = true;
            AMFWriter output = new AMFWriter(buf);

            output.WriteString("onMetaData");
            Hashtable props = new Hashtable();

            // Duration property
            props.Add("duration", _frameMeta.Timestamps[_frameMeta.Timestamps.Length - 1] / 1000.0);
            props.Add("audiocodecid", IOConstants.FLAG_FORMAT_MP3);
            if (_dataRate > 0)
            {
                props.Add("audiodatarate", _dataRate);
            }
            props.Add("canSeekToEnd", true);
            output.WriteAssociativeArray(ObjectEncoding.AMF0, props);
            buf.Flip();

            ITag result = new Tag(IOConstants.TYPE_METADATA, 0, buf.Limit, buf.ToArray(), _prevSize);

            return(result);
        }
Пример #5
0
        /// <summary>
        /// Create tag for metadata event.
        /// </summary>
        /// <returns></returns>
        ITag CreateFileMeta()
        {
#if LOGGING
            log.Debug("Creating onMetaData");
#endif
            // Create tag for onMetaData event
            ByteBuffer buf = ByteBuffer.Allocate(1024);
            buf.AutoExpand = true;
            AMFWriter output = new AMFWriter(buf);
            output.WriteString("onMetaData");

            Hashtable props = new Hashtable();
            // Duration property
            props.Add("duration", ((double)_duration / (double)_timeScale));
            // Audio codec id - watch for mp3 instead of aac
            props.Add("audiocodecid", _audioCodecId);
            props.Add("aacaot", _audioCodecType);
            props.Add("audiosamplerate", _audioTimeScale);
            props.Add("audiochannels", _audioChannels);

            props.Add("moovposition", _moovOffset);
            //tags will only appear if there is an "ilst" atom in the file
            //props.put("tags", "");

            props.Add("canSeekToEnd", false);
            output.WriteAssociativeArray(ObjectEncoding.AMF0, props);
            buf.Flip();

            //now that all the meta properties are done, update the duration
            _duration = (long)Math.Round(_duration * 1000d);

            ITag result = new Tag(IOConstants.TYPE_METADATA, 0, buf.Limit, buf.ToArray(), 0);
            return(result);
        }
Пример #6
0
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase collection = data as NameObjectCollectionBase;

            object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null && attributes.Length > 0)
            {
                DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                PropertyInfo           pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
                if (pi != null)
                {
                    ASObject aso = new ASObject();
                    for (int i = 0; i < collection.Keys.Count; i++)
                    {
                        string key   = collection.Keys[i];
                        object value = pi.GetValue(collection, new object[] { key });
                        aso.Add(key, value);
                    }
                    writer.WriteByte(AMF3TypeCode.Object);
                    writer.WriteAMF3Object(aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
Пример #7
0
        public void Uncompress()
        {
            DeflateStream stream = new DeflateStream(this._memoryStream, CompressionMode.Decompress, false);

            System.IO.MemoryStream stream2 = new System.IO.MemoryStream();
            byte[] buffer = new byte[0x400];
            this._memoryStream.ReadByte();
            this._memoryStream.ReadByte();
            while (true)
            {
                int count = stream.Read(buffer, 0, buffer.Length);
                if (count <= 0)
                {
                    stream.Close();
                    this._memoryStream.Close();
                    this._memoryStream.Dispose();
                    this._memoryStream          = stream2;
                    this._memoryStream.Position = 0L;
                    AMFReader amfReader = new AMFReader(this._memoryStream);
                    AMFWriter amfWriter = new AMFWriter(this._memoryStream);
                    this._dataOutput = new DataOutput(amfWriter);
                    this._dataInput  = new DataInput(amfReader);
                    return;
                }
                stream2.Write(buffer, 0, count);
            }
        }
Пример #8
0
        private bool SaveObject(IPersistable obj)
        {
            string   filename = GetObjectFilename(obj);
            FileInfo file     = _scope.Context.GetResource(filename).File;
            string   path     = file.DirectoryName;

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }

            lock (this.SyncRoot)
            {
                MemoryStream ms     = new MemoryStream();
                AMFWriter    writer = new AMFWriter(ms);
                writer.UseLegacyCollection = false;
                writer.WriteString(obj.GetType().FullName);
                //amfSerializer.WriteData(ObjectEncoding.AMF0, obj);
                obj.Serialize(writer);
                writer.Flush();
                byte[] buffer = ms.ToArray();
                ms.Close();
                using (FileStream fs = new FileStream(file.FullName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    fs.Write(buffer, 0, buffer.Length);
                    fs.Close();
                }
            }
            return(true);
        }
        public void WriteData(AMFWriter writer, object data)
        {
            NameObjectCollectionBase collection = data as NameObjectCollectionBase;
            object[] attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null  && attributes.Length > 0)
            {
                DefaultMemberAttribute defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                PropertyInfo pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new Type[] { typeof(string) });
                if (pi != null)
                {
                    ASObject aso = new ASObject();
                    for (int i = 0; i < collection.Keys.Count; i++)
                    {
                        string key = collection.Keys[i];
                        object value = pi.GetValue(collection, new object[]{ key });
                        aso.Add(key, value);
                    }
                    writer.WriteByte(AMF3TypeCode.Object);
                    writer.WriteAMF3Object(aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(data);
        }
Пример #10
0
        /// <summary>
        /// Decompresses the byte array. The byte array must have been previously compressed with the Compress() method.
        /// </summary>
        public void Uncompress()
        {
            DeflateStream deflateStream = new DeflateStream(_memoryStream, CompressionMode.Decompress, false);
            MemoryStream  ms            = new MemoryStream();

            byte[] buffer = new byte[1024];
            // Skip first two bytes
            _memoryStream.ReadByte();
            _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;
            AMFReader amfReader = new AMFReader(_memoryStream);
            AMFWriter amfWriter = new AMFWriter(_memoryStream);

            _dataOutput = new DataOutput(amfWriter);
            _dataInput  = new DataInput(amfReader);
        }
Пример #11
0
        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);
        }
Пример #12
0
        private bool SaveObject(IPersistable obj)
        {
            string   objectFilename = this.GetObjectFilename(obj);
            FileInfo file           = base._scope.Context.GetResource(objectFilename).File;
            string   directoryName  = file.DirectoryName;

            if (!Directory.Exists(directoryName))
            {
                Directory.CreateDirectory(directoryName);
            }
            lock (base.SyncRoot)
            {
                MemoryStream stream = new MemoryStream();
                AMFWriter    writer = new AMFWriter(stream)
                {
                    UseLegacyCollection = false
                };
                writer.WriteString(obj.GetType().FullName);
                obj.Serialize(writer);
                writer.Flush();
                byte[] buffer = stream.ToArray();
                stream.Close();
                using (FileStream stream2 = new FileStream(file.FullName, FileMode.Create, FileAccess.ReadWrite, FileShare.ReadWrite))
                {
                    stream2.Write(buffer, 0, buffer.Length);
                    stream2.Close();
                }
            }
            return(true);
        }
Пример #13
0
        private void WriteMetadataTag(double duration, object videoCodecId, object audioCodecId)
        {
            this._metaPosition = this._writer.BaseStream.Position;
            MemoryStream stream = new MemoryStream();
            AMFWriter    writer = new AMFWriter(stream);

            writer.WriteString("onMetaData");
            Hashtable hashtable = new Hashtable();

            hashtable.Add("duration", this._duration);
            if (videoCodecId != null)
            {
                hashtable.Add("videocodecid", videoCodecId);
            }
            if (audioCodecId != null)
            {
                hashtable.Add("audiocodecid", audioCodecId);
            }
            hashtable.Add("canSeekToEnd", true);
            writer.WriteAssociativeArray(ObjectEncoding.AMF0, hashtable);
            byte[] body = stream.ToArray();
            if (this._fileMetaSize == 0)
            {
                this._fileMetaSize = body.Length;
            }
            ITag tag = new Tag(IOConstants.TYPE_METADATA, 0, body.Length, body, 0);

            this.WriteTag(tag);
        }
Пример #14
0
        public void WriteData(AMFWriter writer, object data)
        {
            writer.WriteByte(0);
            double num = Convert.ToInt32(data);

            writer.WriteDouble(num);
        }
        public void WriteData(AMFWriter writer, object data)
        {
            var collection = data as NameObjectCollectionBase;
            var attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);

            if (attributes != null && attributes.Length > 0)
            {
                var defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                var pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new[] { typeof(string) });
                if (pi != null)
                {
                    var aso = new ASObject();
                    for (var i = 0; i < collection.Keys.Count; i++)
                    {
                        var key   = collection.Keys[i];
                        var value = pi.GetValue(collection, new object[] { key });
                        aso.Add(key, value);
                    }
                    writer.WriteASO(ObjectEncoding.AMF0, aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteObject(ObjectEncoding.AMF0, data);
        }
Пример #16
0
        public void WriteData(AMFWriter writer, object data)
        {
            var aso = TypeHelper.ConvertDataSetToASO(data as DataSet, false);

            writer.WriteByte(AMF3TypeCode.Object);
            writer.WriteAMF3Object(aso);
        }
Пример #17
0
        public void WriteData(AMFWriter writer, object data)
        {
            if (data is ArrayCollection)
            {
                writer.WriteByte(AMF3TypeCode.Object);

                writer.WriteAMF3Object(data);
            }
            else if (data is IList)
            {
                writer.WriteByte(AMF3TypeCode.Array);

                writer.WriteAMF3Array((IList)data);
            }
            else if (data is IDictionary)
            {
                writer.WriteByte(AMF3TypeCode.Array);

                writer.WriteAMF3AssociativeArray((IDictionary)data);
            }
            else
            {
                writer.WriteByte(AMF3TypeCode.Object);

                writer.WriteAMF3Object(data);
            }
        }
Пример #18
0
		public void WriteData(AMFWriter writer, object data) {
			if (data is INullable) {
				if ((data as INullable).IsNull) {
					writer.WriteAMF3Null();
					return;
				}
			}
			if (data is SqlByte) {
				writer.WriteAMF3Data(((SqlByte)data).Value);
				return;
			}
			if (data is SqlInt16) {
				writer.WriteAMF3Data(((SqlInt16)data).Value);
				return;
			}
			if (data is SqlInt32) {
				writer.WriteAMF3Data(((SqlInt32)data).Value);
				return;
			}
			if (data is SqlInt64) {
				writer.WriteAMF3Data(((SqlInt64)data).Value);
				return;
			}
			if (data is SqlSingle) {
				writer.WriteAMF3Data(((SqlSingle)data).Value);
				return;
			}
			if (data is SqlDouble) {
				writer.WriteAMF3Data(((SqlDouble)data).Value);
				return;
			}
			if (data is SqlDecimal) {
				writer.WriteAMF3Data(((SqlDecimal)data).Value);
				return;
			}
			if (data is SqlMoney) {
				writer.WriteAMF3Data(((SqlMoney)data).Value);
				return;
			}
			if (data is SqlDateTime) {
				writer.WriteAMF3Data(((SqlDateTime)data).Value);
				return;
			}
			if (data is SqlString) {
				writer.WriteAMF3String(((SqlString)data).Value);
				return;
			}
			if (data is SqlGuid) {
				writer.WriteAMF3Data(((SqlGuid)data).Value.ToString("D"));
				return;
			}
			if (data is SqlBoolean) {
				writer.WriteAMF3Bool(((SqlBoolean)data).Value);
				return;
			}
			string msg = string.Format("Could not find serializer for type {0}", data.GetType().FullName);
			if (_log.IsErrorEnabled)
				_log.Error(msg);
			throw new FluorineException(msg);
		}
Пример #19
0
        public void WriteData(AMFWriter writer, object data)
        {
            writer.WriteByte(AMF0TypeCode.Number);
            double value = Convert.ToDouble(data);

            writer.WriteDouble(value);
        }
Пример #20
0
        public void WriteData(AMFWriter writer, object data)
        {
            ASObject obj2 = TypeHelper.ConvertDataTableToASO(data as DataTable, false);

            writer.WriteByte(10);
            writer.WriteAMF3Object(obj2);
        }
        public void WriteData(AMFWriter writer, object data)
        {
            var collection = data as NameObjectCollectionBase;
            var attributes = collection.GetType().GetCustomAttributes(typeof(DefaultMemberAttribute), false);
            if (attributes != null  && attributes.Length > 0)
            {
                var defaultMemberAttribute = attributes[0] as DefaultMemberAttribute;
                var pi = collection.GetType().GetProperty(defaultMemberAttribute.MemberName, new[] { typeof(string) });
                if (pi != null)
                {
                    var aso = new ASObject();
                    for (var i = 0; i < collection.Keys.Count; i++)
                    {
                        var key = collection.Keys[i];
                        var value = pi.GetValue(collection, new object[]{ key });
                        aso.Add(key, value);
                    }
                    writer.WriteASO(ObjectEncoding.AMF0, aso);
                    return;
                }
            }

            //We could not access an indexer so write out as it is.
            writer.WriteObject(ObjectEncoding.AMF0, data);
        }
Пример #22
0
        public void WriteData(AMFWriter writer, object data)
        {
            writer.WriteByte(AMF3TypeCode.ObjectVector);

            //仅处理String,未处理Bool等其它数据类型
            writer.WriteAMF3ObjectVector(data as IList <string>);
        }
Пример #23
0
        public FlvWriter(Stream stream, bool append)
        {
            _writer = new AMFWriter(stream);
            _append = append;
            if (_append)
            {
                if (stream.Length > 9 + 15)
                {
                    try
                    {
                        //Skip header
                        stream.Position = 9;
                        byte[] tagBuffer = new byte[15];
                        //previousTagSize
                        stream.Read(tagBuffer, 0, 4);
                        //start of flv tag
                        byte dataType = (byte)stream.ReadByte();
                        if (dataType == IOConstants.TYPE_METADATA)
                        {
                            _metaPosition = stream.Position - 1;
                            //body size
                            stream.Read(tagBuffer, 5, 3);
                            int bodySize = tagBuffer[5] << 16 | tagBuffer[6] << 8 | tagBuffer[7];
                            //timestamp
                            stream.Read(tagBuffer, 8, 4);
                            //streamid
                            stream.Read(tagBuffer, 12, 3);
                            byte[] buffer = new byte[bodySize];
                            stream.Read(buffer, 0, buffer.Length);
                            MemoryStream ms = new MemoryStream(buffer);
                            AMFReader input = new AMFReader(ms);
                            string onMetaData = input.ReadData() as string;//input.ReadString();
                            IDictionary properties = input.ReadData() as IDictionary;
                            if (properties.Contains("duration"))
                                _duration = System.Convert.ToInt32(properties["duration"]);
                            else
                            {
#if !SILVERLIGHT
                                log.Warn("Could not read Flv duration from metadata");
#endif
                            }
                        }
                        else
                        {
#if !SILVERLIGHT
                            log.Warn("Could not read Flv duration");
#endif
                        }
                    }
                    catch (Exception ex)
                    {
#if !SILVERLIGHT
                        log.Warn("Error reading Flv duration", ex);
#endif
                    }
                }
                stream.Seek(0, SeekOrigin.End);//Appending
            }
        }
Пример #24
0
		/// <summary>
		/// Initializes a new instance of the ByteArray class.
		/// </summary>
		public ByteArray() {
			_memoryStream = new MemoryStream();
			AMFReader amfReader = new AMFReader(_memoryStream);
			AMFWriter amfWriter = new AMFWriter(_memoryStream);
			_dataOutput = new DataOutput(amfWriter);
			_dataInput = new DataInput(amfReader);
			_objectEncoding = ObjectEncoding.AMF3;
		}
Пример #25
0
		public void WriteData(AMFWriter writer, object data) {
			if (data is byte[])
				data = new ByteArray(data as byte[]);

			if (data is ByteArray) {
				writer.WriteByteArray(data as ByteArray);
			}
		}
Пример #26
0
        public FlvWriter(Stream stream, bool append)
        {
            _writer = new AMFWriter(stream);
            _append = append;
            if (_append)
            {
                if (stream.Length > 9 + 15)
                {
                    try {
                        //Skip header
                        stream.Position = 9;
                        byte[] tagBuffer = new byte[15];
                        //previousTagSize
                        stream.Read(tagBuffer, 0, 4);
                        //start of flv tag
                        byte dataType = (byte)stream.ReadByte();
                        if (dataType == IOConstants.TYPE_METADATA)
                        {
                            _metaPosition = stream.Position - 1;
                            //body size
                            stream.Read(tagBuffer, 5, 3);
                            int bodySize = tagBuffer[5] << 16 | tagBuffer[6] << 8 | tagBuffer[7];
                            //timestamp
                            stream.Read(tagBuffer, 8, 4);
                            //streamid
                            stream.Read(tagBuffer, 12, 3);
                            byte[] buffer = new byte[bodySize];
                            stream.Read(buffer, 0, buffer.Length);
                            MemoryStream ms         = new MemoryStream(buffer);
                            AMFReader    input      = new AMFReader(ms);
                            string       onMetaData = input.ReadData() as string;                      //input.ReadString();
                            IDictionary  properties = input.ReadData() as IDictionary;
                            if (properties.Contains("duration"))
                            {
                                _duration = System.Convert.ToInt32(properties["duration"]);
                            }
                            else
                            {
#if !SILVERLIGHT
                                log.Warn("Could not read Flv duration from metadata");
#endif
                            }
                        }
                        else
                        {
#if !SILVERLIGHT
                            log.Warn("Could not read Flv duration");
#endif
                        }
                    } catch (Exception ex) {
#if !SILVERLIGHT
                        log.Warn("Error reading Flv duration", ex);
#endif
                    }
                }
                stream.Seek(0, SeekOrigin.End);                //Appending
            }
        }
Пример #27
0
        public void Reset()
        {
            AMFReader amfReader = new AMFReader(_memoryStream);

            AMFWriter amfWriter = new AMFWriter(_memoryStream);

            dataOutput = new DataOutput(amfWriter);

            dataInput = new DataInput(amfReader);
        }
Пример #28
0
        public ByteArray(System.IO.MemoryStream ms)
        {
            this._memoryStream = ms;
            AMFReader amfReader = new AMFReader(this._memoryStream);
            AMFWriter amfWriter = new AMFWriter(this._memoryStream);

            this._dataOutput     = new DataOutput(amfWriter);
            this._dataInput      = new DataInput(amfReader);
            this._objectEncoding = FluorineFx.ObjectEncoding.AMF3;
        }
Пример #29
0
        /// <summary>
        /// Injects metadata (Cue Points) into a tag.
        /// </summary>
        /// <param name="meta">Metadata.</param>
        /// <param name="tag">Tag.</param>
        /// <returns></returns>
        private ITag InjectMetaCue(MetaCue meta, ITag tag)
        {
            MemoryStream ms     = new MemoryStream();
            AMFWriter    writer = new AMFWriter(ms);

            writer.WriteData(ObjectEncoding.AMF0, "onCuePoint");
            writer.WriteData(ObjectEncoding.AMF0, meta);
            byte[] buffer = ms.ToArray();
            return(new Tag(IOConstants.TYPE_METADATA, GetTimeInMilliseconds(meta), buffer.Length, buffer, tag.PreviousTagSize));
        }
Пример #30
0
        /// <summary>
        /// Injects metadata (other than Cue points) into a tag.
        /// </summary>
        /// <param name="meta">Metadata.</param>
        /// <param name="tag">Tag.</param>
        /// <returns></returns>
        private ITag InjectMetaData(MetaData meta, ITag tag)
        {
            MemoryStream ms     = new MemoryStream();
            AMFWriter    writer = new AMFWriter(ms);

            writer.WriteData(ObjectEncoding.AMF0, "onMetaData");
            writer.WriteData(ObjectEncoding.AMF0, meta);
            byte[] buffer = ms.ToArray();
            return(new Tag(IOConstants.TYPE_METADATA, 0, buffer.Length, buffer, tag.PreviousTagSize));
        }
Пример #31
0
        /// <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;
        }
Пример #32
0
 public void WriteData(AMFWriter writer, object data)
 {
     if (data is byte[])
     {
         data = new ByteArray(data as byte[]);
     }
     if (data is ByteArray)
     {
         writer.WriteByteArray(data as ByteArray);
     }
 }
Пример #33
0
        protected void StreamMessage(IMessage message, HttpResponse response)
        {
            MemoryStream ms     = new MemoryStream();
            AMFWriter    writer = new AMFWriter(ms);

            writer.UseLegacyCollection = this.IsLegacyCollection;
            writer.UseLegacyThrowable  = this.IsLegacyThrowable;
            writer.WriteAMF3Data(message);
            ms.Close();
            byte[] messageBytes = ms.ToArray();
            StreamChunk(messageBytes, response);
        }
Пример #34
0
        internal ByteArray(byte[] buffer)
        {
            this._memoryStream = new System.IO.MemoryStream();
            this._memoryStream.Write(buffer, 0, buffer.Length);
            this._memoryStream.Position = 0L;
            AMFReader amfReader = new AMFReader(this._memoryStream);
            AMFWriter amfWriter = new AMFWriter(this._memoryStream);

            this._dataOutput     = new DataOutput(amfWriter);
            this._dataInput      = new DataInput(amfReader);
            this._objectEncoding = FluorineFx.ObjectEncoding.AMF3;
        }
Пример #35
0
        /// <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;
        }
Пример #36
0
        public void Compress()
        {
            byte[]        buffer = this._memoryStream.GetBuffer();
            DeflateStream stream = new DeflateStream(this._memoryStream, CompressionMode.Compress, true);

            stream.Write(buffer, 0, buffer.Length);
            stream.Close();
            AMFReader amfReader = new AMFReader(this._memoryStream);
            AMFWriter amfWriter = new AMFWriter(this._memoryStream);

            this._dataOutput = new DataOutput(amfWriter);
            this._dataInput  = new DataInput(amfReader);
        }
Пример #37
0
		public void WriteData(AMFWriter writer, object data)
		{
			if( data is IList )
			{
				IList list = data as IList;
				object[] array = new object[list.Count];
				list.CopyTo(array, 0);
				writer.WriteArray(ObjectEncoding.AMF0, array);
				return;
			}
#if !(SILVERLIGHT)
            IListSource listSource = data as IListSource;
            if (listSource != null)
            {
                IList list = listSource.GetList();
                object[] array = new object[list.Count];
                list.CopyTo(array, 0);
                writer.WriteArray(ObjectEncoding.AMF0, array);
                return;
            }
#endif
			if(data is IDictionary)
			{
				writer.WriteAssociativeArray(ObjectEncoding.AMF0, data as IDictionary);
				return;
			}
			if(data is Exception)
			{
				writer.WriteASO(ObjectEncoding.AMF0, new ExceptionASO(data as Exception) );
				return;
			}
            if (data is IEnumerable)
            {
                List<object> tmp = new List<object>();
                foreach (object element in (data as IEnumerable))
                {
                    tmp.Add(element);
                }
                writer.WriteArray(ObjectEncoding.AMF0, tmp.ToArray());
                return;
            }
			writer.WriteObject(ObjectEncoding.AMF0, data);
		}
Пример #38
0
		/// <summary>
		/// Injects metadata (other than Cue points) into a tag.
		/// </summary>
		/// <param name="meta">Metadata.</param>
		/// <param name="tag">Tag.</param>
		/// <returns></returns>
		private ITag InjectMetaData(MetaData meta, ITag tag) {
			MemoryStream ms = new MemoryStream();
			AMFWriter writer = new AMFWriter(ms);
			writer.WriteData(ObjectEncoding.AMF0, "onMetaData");
			writer.WriteData(ObjectEncoding.AMF0, meta);
			byte[] buffer = ms.ToArray();
			return new Tag(IOConstants.TYPE_METADATA, 0, buffer.Length, buffer, tag.PreviousTagSize);
		}
Пример #39
0
		/// <summary>
		/// Injects metadata (Cue Points) into a tag.
		/// </summary>
		/// <param name="meta">Metadata.</param>
		/// <param name="tag">Tag.</param>
		/// <returns></returns>
		private ITag InjectMetaCue(MetaCue meta, ITag tag) {
			MemoryStream ms = new MemoryStream();
			AMFWriter writer = new AMFWriter(ms);
			writer.WriteData(ObjectEncoding.AMF0, "onCuePoint");
			writer.WriteData(ObjectEncoding.AMF0, meta);
			byte[] buffer = ms.ToArray();
			return new Tag(IOConstants.TYPE_METADATA, GetTimeInMilliseconds(meta), buffer.Length, buffer, tag.PreviousTagSize);
		}
Пример #40
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteData(ObjectEncoding.AMF0, (data as CacheableObject).Object);
 }
Пример #41
0
		public void WriteData(AMFWriter writer, object data) {
			writer.WriteByte(AMF0TypeCode.Boolean);
			writer.WriteBoolean((bool)data);
		}
Пример #42
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteBytes((data as RawBinary).Buffer);
 }
Пример #43
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteByte(AMF0TypeCode.String);
     writer.WriteUTF( new String( (char)data, 1)  );
 }
Пример #44
0
		public void WriteData(AMFWriter writer, object data)
		{
			writer.WriteByte(AMF0TypeCode.AMF3Tag);
			writer.WriteAMF3Data(data);
		}
Пример #45
0
		public void WriteData(AMFWriter writer, object data)
		{
            ASObject aso = TypeHelper.ConvertDataSetToASO(data as DataSet, false);
			writer.WriteByte(AMF3TypeCode.Object);
			writer.WriteAMF3Object(aso);
		}
Пример #46
0
        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);
        }
Пример #47
0
		public void WriteData(AMFWriter writer, object data)
		{
			writer.WriteAMF3Bool((bool)data);
		}
Пример #48
0
        public void Serialize(AMFWriter writer)
		{
            writer.WriteString(this.Name);
            writer.WriteString(this.Path);
            writer.WriteData(ObjectEncoding.AMF0, _attributes);
		}
Пример #49
0
        /// <summary>
        /// Create tag for metadata event.
        /// 
        /// Info from http://www.kaourantin.net/2007/08/what-just-happened-to-video-on-web_20.html
        /// <para>
        /// duration - Obvious. But unlike for FLV files this field will always be present.
        /// videocodecid - For H.264 we report 'avc1'.
        /// audiocodecid - For AAC we report 'mp4a', for MP3 we report '.mp3'.
        /// avcprofile - 66, 77, 88, 100, 110, 122 or 144 which corresponds to the H.264 profiles.
        /// avclevel - A number between 10 and 51. Consult this list to find out more.
        /// aottype - Either 0, 1 or 2. This corresponds to AAC Main, AAC LC and SBR audio types.
        /// moovposition - The offset in bytes of the moov atom in a file.
        /// trackinfo - An array of objects containing various infomation about all the tracks in a file
        ///   ex.
        ///     trackinfo[0].length: 7081
        ///     trackinfo[0].timescale: 600
        ///     trackinfo[0].sampledescription.sampletype: avc1
        ///     trackinfo[0].language: und
        ///     trackinfo[1].length: 525312
        ///     trackinfo[1].timescale: 44100
        ///     trackinfo[1].sampledescription.sampletype: mp4a
        ///     trackinfo[1].language: und
        /// 
        /// chapters - As mentioned above information about chapters in audiobooks.
        /// seekpoints - As mentioned above times you can directly feed into NetStream.seek();
        /// videoframerate - The frame rate of the video if a monotone frame rate is used. Most videos will have a monotone frame rate.
        /// audiosamplerate - The original sampling rate of the audio track.
        /// audiochannels - The original number of channels of the audio track.
        /// tags - As mentioned above ID3 like tag information.
        /// </para>
        /// 
        /// <para>
        /// width: Display width in pixels.
        /// height: Display height in pixels.
        /// duration: Duration in seconds.
        /// avcprofile: AVC profile number such as 55, 77, 100 etc.
        /// avclevel: AVC IDC level number such as 10, 11, 20, 21 etc.
        /// aacaot: AAC audio object type; 0, 1 or 2 are supported.
        /// videoframerate: Frame rate of the video in this MP4.
        /// seekpoints: Array that lists the available keyframes in a file as time stamps in milliseconds. 
        ///     This is optional as the MP4 file might not contain this information. Generally speaking, 
        ///     most MP4 files will include this by default.
        /// videocodecid: Usually a string such as "avc1" or "VP6F."
        /// audiocodecid: Usually a string such as ".mp3" or "mp4a."
        /// progressivedownloadinfo: Object that provides information from the "pdin" atom. This is optional 
        ///     and many files will not have this field.
        /// trackinfo: Object that provides information on all the tracks in the MP4 file, including their sample description ID.
        /// tags: Array of key value pairs representing the information present in the "ilst" atom, which is 
        ///     the equivalent of ID3 tags for MP4 files. These tags are mostly used by iTunes. 
        /// </para>
        /// </summary>
        /// <returns>Metadata event tag.</returns>
        ITag CreateFileMeta()
        {
#if !SILVERLIGHT
            log.Debug("Creating onMetaData");
#endif
            // Create tag for onMetaData event
            ByteBuffer buf = ByteBuffer.Allocate(1024);
            buf.AutoExpand = true;
            AMFWriter output = new AMFWriter(buf);
            output.WriteString("onMetaData");

            Dictionary<string, object> props = new Dictionary<string, object>();
            // Duration property
            props.Add("duration", ((double)_duration / (double)_timeScale));
            props.Add("width", _width);
            props.Add("height", _height);

            // Video codec id
            props.Add("videocodecid", _videoCodecId);
            props.Add("avcprofile", _avcProfile);
            props.Add("avclevel", _avcLevel);
            props.Add("videoframerate", _fps);
            // Audio codec id - watch for mp3 instead of aac
            props.Add("audiocodecid", _audioCodecId);
            props.Add("aacaot", _audioCodecType);
            props.Add("audiosamplerate", _audioTimeScale);
            props.Add("audiochannels", _audioChannels);

            props.Add("moovposition", _moovOffset);
            //props.put("chapters", ""); //this is for f4b - books
            if (_seekPoints != null)
            {
                props.Add("seekpoints", _seekPoints);
            }
            //tags will only appear if there is an "ilst" atom in the file
            //props.put("tags", "");

            List<Dictionary<String, Object>> arr = new List<Dictionary<String, Object>>(2);
            if (_hasAudio)
            {
                Dictionary<String, Object> audioMap = new Dictionary<String, Object>(4);
                audioMap.Add("timescale", _audioTimeScale);
                audioMap.Add("language", "und");

                List<Dictionary<String, String>> desc = new List<Dictionary<String, String>>(1);
                audioMap.Add("sampledescription", desc);

                Dictionary<String, String> sampleMap = new Dictionary<String, String>(1);
                sampleMap.Add("sampletype", _audioCodecId);
                desc.Add(sampleMap);

                if (_audioSamples != null)
                {
                    audioMap.Add("length_property", _audioSampleDuration * _audioSamples.Count);
                    //release some memory, since we're done with the vectors
                    _audioSamples.Clear();
                    _audioSamples = null;
                }
                arr.Add(audioMap);
            }
            if (_hasVideo)
            {
                Dictionary<String, Object> videoMap = new Dictionary<String, Object>(3);
                videoMap.Add("timescale", _videoTimeScale);
                videoMap.Add("language", "und");

                List<Dictionary<String, String>> desc = new List<Dictionary<String, String>>(1);
                videoMap.Add("sampledescription", desc);

                Dictionary<String, String> sampleMap = new Dictionary<String, String>(1);
                sampleMap.Add("sampletype", _videoCodecId);
                desc.Add(sampleMap);

                if (_videoSamples != null)
                {
                    videoMap.Add("length_property", _videoSampleDuration * _videoSamples.Count);
                    //release some memory, since we're done with the vectors
                    _videoSamples.Clear();
                    _videoSamples = null;
                }
                arr.Add(videoMap);
            }
            props.Add("trackinfo", arr.ToArray());
            //set this based on existence of seekpoints
            props.Add("canSeekToEnd", (_seekPoints != null));

            output.WriteAssociativeArray(ObjectEncoding.AMF0, props);
            buf.Flip();

            //now that all the meta properties are done, update the duration
            _duration = (long)Math.Round(_duration * 1000d);

            ITag result = new Tag(IOConstants.TYPE_METADATA, 0, buf.Limit, buf.ToArray(), 0);
            return result;
        }
Пример #50
0
		public void WriteData(AMFWriter writer, object data) {
			writer.WriteASO(ObjectEncoding.AMF0, TypeHelper.ConvertDataSetToASO(data as DataSet, true));
		}
Пример #51
0
		public void WriteData(AMFWriter writer, object data)
		{
			int value = Convert.ToInt32(data);
			writer.WriteAMF3Int(value);
		}
Пример #52
0
		public void WriteData(AMFWriter writer, object data)
		{
			writer.WriteAMF3String(data as string);
		}
Пример #53
0
 public void WriteData(AMFWriter writer, object data)
 {
     writer.WriteByte(AMF3TypeCode.IntVector);
     writer.WriteAMF3IntVector(data as IList<int>);
 }
Пример #54
0
		public void WriteData(AMFWriter writer, object data) {
			writer.WriteByte(AMF3TypeCode.Object);
			writer.WriteAMF3Object(data);
		}
Пример #55
0
		public void WriteData(AMFWriter writer, object data)
		{
			writer.WriteByte(AMF0TypeCode.Number);
			double dbl = (double)Convert.ToInt32(data);
			writer.WriteDouble(dbl);
		}
Пример #56
0
 /// <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);
 }
Пример #57
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
        }
Пример #58
0
		/// <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>
        /// Writes the object to the specified output stream.
        /// </summary>
        /// <param name="writer">Writer to write to.</param>
        public void Serialize(AMFWriter writer)
        {
#if !(NET_1_1)
            Dictionary<string, object> persistentAttributes = new Dictionary<string, object>();
#else
            Hashtable persistentAttributes = new Hashtable();
#endif
            foreach (string attribute in this.GetAttributeNames())
            {
                if (attribute.StartsWith(Constants.TransientPrefix))
                    continue;
                persistentAttributes.Add(attribute, this[attribute]);
            }
            writer.WriteData(ObjectEncoding.AMF0, persistentAttributes);
        }
Пример #60
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
        }