예제 #1
0
        public void ReadsSegmentInfo()
        {
            var stream = new MemoryStream();
            var writer = new EbmlWriter(stream);

            using (var segment = writer.StartMasterElement(MatroskaDtd.Segment.Identifier))
            {
                using (var segmentInfo = segment.StartMasterElement(MatroskaDtd.Segment.Info.Identifier))
                {
                    segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.Title.Identifier, "Test data");
                    segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.WritingApp.Identifier, "writing app");
                    segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.MuxingApp.Identifier, "mux app");
                    segmentInfo.Write(MatroskaDtd.Segment.Info.Duration.Identifier, 1234f);
                }

                // write some dummy data
                segment.Write(VInt.MakeId(123), 0);
            }

            stream.Position = 0;
            var infoReader = new SegmentInfoUpdater();
            infoReader.Open(stream);

            Assert.AreEqual("Test data", infoReader.Title);
            Assert.AreEqual("writing app", infoReader.WritingApp);
            Assert.AreEqual("mux app", infoReader.MuxingApp);
            Assert.AreEqual(TimeSpan.FromMilliseconds(1234), infoReader.Duration);
        }
예제 #2
0
        public void ReusesNextFiller()
        {
            var stream = new MemoryStream();
            var writer = new EbmlWriter(stream);

            writer.Write(VInt.MakeId(122), 321);
            using (var segment = writer.StartMasterElement(MatroskaDtd.Segment.Identifier))
            {
                using (var segmentInfo = segment.StartMasterElement(MatroskaDtd.Segment.Info.Identifier))
                {
                    segmentInfo.WriteUtf(MatroskaDtd.Segment.Info.Title.Identifier, "Test data");
                }

                // write some dummy data
                segment.Write(StandardDtd.Void.Identifier, new byte[1000]);
                segment.Write(VInt.MakeId(123), 123);	// marker
            }

            stream.Position = 0;

            // act
            var infoReader = new SegmentInfoUpdater();
            infoReader.Open(stream);
            infoReader.Title = new string('a', 500);
            infoReader.Write();

            // verify the stream is correct
            stream.Position = 0;
            var reader = new EbmlReader(stream);

            reader.ReadNext();
            Assert.AreEqual(122, reader.ElementId.Value, "start marker");
            Assert.AreEqual(321, reader.ReadInt());

            reader.ReadNext();
            Assert.AreEqual(MatroskaDtd.Segment.Identifier, reader.ElementId);
            reader.EnterContainer();

            reader.ReadNext();
            Assert.AreEqual(MatroskaDtd.Segment.Info.Identifier, reader.ElementId);
            Assert.Greater(reader.ElementSize, 500);

            reader.ReadNext();
            Assert.AreEqual(StandardDtd.Void.Identifier, reader.ElementId);

            reader.ReadNext();
            Assert.AreEqual(123, reader.ElementId.Value, "end data marker");
            Assert.AreEqual(123, reader.ReadInt());
        }