Exemple #1
0
 private object ReadObject(BinaryReader br)
 {
     var obj = new MetaObject();
     while (offset < size)
     {
         var byts = br.ReadBytes(3);
         if (byts[0] == 0 && byts[1] == 0 && byts[2] == 9)
         {
             offset += 3;
             break;
         }
         br.BaseStream.Seek(-3, SeekOrigin.Current);
         string key = ReadString(br);
         if (key[0] == 0)
             break;
         obj[key] = ReadElement(br);
     }
     return obj;
 }
Exemple #2
0
 private MetaObject ReadArray(BinaryReader br)
 {
     var array = new MetaObject();
     br.ReadBytes(4);
     offset += 4;
     while (offset < size)
     {
         var byts = br.ReadBytes(3);
         if (byts[0] == 0 && byts[1] == 0 && byts[2] == 9)
         {
             offset += 3;
             break;
         }
         br.BaseStream.Seek(-3, SeekOrigin.Current);
         string key = ReadString(br);
         //if (key[0] == 0)
         //    break;
         array[key] = ReadElement(br);
     }
     return array;
     //var len = br.ReadBytes(4).ToUInt32(false);
     //offset += 4;
     //var array = new MetaObject();
     //for (uint i = 0; i < len; i++)
     //{
     //    string key = ReadString(br);
     //    array[key] = ReadElement(br);
     //}
     //br.ReadBytes(3); // 00 00 09表示object的结束
     //offset += 3;
     //return array;
 }
Exemple #3
0
        private MetaObject GetSegments(MetaArray filepositions, MetaArray times)
        {
            var timeLine = 0d;
            var segments = new MetaObject();

            segments["extension"] = ".dat";
            var positions = new MetaArray();
            var files = new MetaArray();

            if (filepositions.Length != times.Length)
            {
                throw new InvalidDataException("keyframes data is invalid");
            }

            for (int i = 0, len = times.Length; i < len; i++)
            {
                var time = Convert.ToDouble(times[i]);
                if (time - timeLine >= INTERNAL)
                {
                    positions.Add(Convert.ToDouble(filepositions[i]));
                    files.Add(positions.Length.ToString());
                    timeLine = time;
                }
            }

            positions.Add(Convert.ToDouble(this.endPosition));
            files.Add(positions.Length.ToString());

            segments["positions"] = positions;
            segments["files"] = files;
            return segments;
        }
Exemple #4
0
 private uint WriteObjct(Stream st, MetaObject content)
 {
     var keys = content.Keys;
     var total = 0u;
     foreach (var key in keys)
     {
         total += this.WriteString(st, key);
         total += this.WriteElement(st, content[key]);
     }
     st.WriteByte(0x00);
     st.WriteByte(0x00);
     st.WriteByte(0x09);
     return total + 3;
 }
Exemple #5
0
        private MetaObject GetKeyFrames(MetaObject obj)
        {
            var vTags = info.Body.Tags.Where(t => t.TagType == TagType.Video && ((t as VideoTag).Data as VideoData).Type == FrameType.KeyFrame);
            this.startPosition = info.Body.Tags[0].Start + info.Body.Tags[0].Size + 4;
            //this.endPosition = info.Body.Tags.Last().Start + info.Body.Tags.Last().Size + 4;
            this.endPosition = info.Body.Start + info.Body.Size;

            if (obj.Contains("keyframes"))
            {
                hasKeyFrames = true;
                return obj["keyframes"] as MetaObject;
            }

            hasKeyFrames = false;
            var filepositions = new MetaArray();
            var times = new MetaArray();
            foreach (var tag in vTags)
            {
                filepositions.Add(Convert.ToDouble(tag.Start));
                times.Add(tag.Header.Timestamp / 1000d);
            }
            var keyFrames = new MetaObject();
            keyFrames["filepositions"] = filepositions;
            keyFrames["times"] = times;
            return keyFrames;
        }