/// <summary>
        /// Writes this object into the data stream at the current position. Note that this method
        /// reverses some spacefor further additions in the stream,
        /// if the stream is seekable. Following subsequent additions to the object, the update()
        /// method can be used to update the originally written object.
        /// </summary>
        /// <param name="writer">FileStream to write to.</param>
        /// <returns>Length of data written</returns>
        public ulong Write(FileStream writer)
        {
            ulong elementLength = seekHeadElem.WriteElement(writer);
            ulong voidLength    = placeHolderElement.WriteElement(writer);

            if (elementLength + voidLength != BLOCK_RESEVER_SIZE)
            {
                throw new Exception("ElementLength + VoidLength != Reserved size. Something went wrong");
            }
            return(BLOCK_RESEVER_SIZE);
        }
Exemplo n.º 2
0
        public long WriteElement(FileStream writer)
        {
            MasterElement segmentInfoElement = MatroskaDocTypes.Info.GetInstance();

            StringElement writingAppElement = MatroskaDocTypes.WritingApp.GetInstance();

            writingAppElement.Value = "Matroska File Writer v1.0 C#";

            StringElement muxingAppElement = MatroskaDocTypes.MuxingApp.GetInstance();

            muxingAppElement.Value = ".NET EBML v1.0";

            DateElement dateElement = MatroskaDocTypes.DateUTC.GetInstance();

            dateElement.Date = SegmentDate;

            UnsignedIntegerElement timecodeScaleElement = MatroskaDocTypes.TimecodeScale.GetInstance();

            timecodeScaleElement.Value = TimecodeScale;

            segmentInfoElement.AddChildElement(dateElement);
            segmentInfoElement.AddChildElement(timecodeScaleElement);

            if (Duration != null)
            {
                FloatElement durationElement = MatroskaDocTypes.Duration.GetInstance();
                durationElement.Value = (double)Duration;
                segmentInfoElement.AddChildElement(durationElement);
            }

            segmentInfoElement.AddChildElement(writingAppElement);
            segmentInfoElement.AddChildElement(muxingAppElement);

            ulong       len    = segmentInfoElement.WriteElement(writer);
            VoidElement spacer = new VoidElement((ulong)BLOCK_SIZE - len);

            spacer.WriteElement(writer);
            return(1);
        }