Пример #1
0
        public bool ValidateDataBlock(IDataBlockBuilder dataBlockBuilder, long startOffset, long endOffset)
        {
            if (!IsValidResult())
            {
                return(false);
            }

            dataBlockBuilder.DataFormat   = _state.IsMpeg2() ? CodecID.Mpeg2System : CodecID.Mpeg1System;
            dataBlockBuilder.IsFullFile   = IsFullFile();
            dataBlockBuilder.IsFragmented = _state.IsFragmented;

            // Trim zero byte stuffing from last header (if any)
            if (_state.LastHeaderZeroByteStuffing > 0)
            {
                dataBlockBuilder.EndOffset = endOffset - _state.LastHeaderZeroByteStuffing;
            }
            foreach (ushort streamId in _state.Streams.StreamIds)
            {
                IDataPacket streamData = _state.Streams[streamId].GetStreamData();
                if (streamData != null)
                {
                    string name = GetStreamName(streamId);
                    if (name != null)
                    {
                        ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder.AddCodecStream();
                        codecStreamBuilder.Name                = name;
                        codecStreamBuilder.DataFormat          = name.StartsWith("Video") ? CodecID.Mpeg2Video : CodecID.Unknown;
                        codecStreamBuilder.StreamNumber        = streamId;
                        codecStreamBuilder.Data                = streamData;
                        codecStreamBuilder.AbsoluteStartOffset = codecStreamBuilder.Data.StartOffset;
                    }
                }
            }
            return(true);
        }
        private static void AddUnknownCodecStream(IDataBlockBuilder dataBlockBuilder, ICodecStream completeCodecStream)
        {
            ICodecStreamBuilder relativeCodecStreamBuilder = dataBlockBuilder.AddCodecStream();

            relativeCodecStreamBuilder.StreamNumber        = completeCodecStream.StreamNumber;
            relativeCodecStreamBuilder.Name                = completeCodecStream.Name;
            relativeCodecStreamBuilder.DataFormat          = CodecID.Unknown;
            relativeCodecStreamBuilder.Detector            = new UnknownFormatDetector();
            relativeCodecStreamBuilder.Data                = completeCodecStream.InputFile.CreateDataPacket().GetSubPacket(0L, completeCodecStream.Length);
            relativeCodecStreamBuilder.IsFragmented        = false;
            relativeCodecStreamBuilder.AbsoluteStartOffset = completeCodecStream.AbsoluteStartOffset;
        }
            private void AddRelativeCodecStream(IDataBlockBuilder dataBlockBuilder, IFragment codecStreamFragment)
            {
                ICodecStreamBuilder relativeCodecStreamBuilder = dataBlockBuilder.AddCodecStream();

                relativeCodecStreamBuilder.StreamNumber          = _completeCodecStream.StreamNumber;
                relativeCodecStreamBuilder.Name                  = _completeCodecStream.Name;
                relativeCodecStreamBuilder.DataFormat            = codecStreamFragment.DataFormat;
                relativeCodecStreamBuilder.Detector              = codecStreamFragment.Detectors.FirstOrDefault();
                relativeCodecStreamBuilder.Data                  = _completeCodecStream.InputFile.CreateDataPacket().GetSubPacket(codecStreamFragment.StartOffset, codecStreamFragment.Length);
                relativeCodecStreamBuilder.IsFragmented          = codecStreamFragment.IsFragmented;
                relativeCodecStreamBuilder.AbsoluteStartOffset   = _completeCodecStream.AbsoluteStartOffset + codecStreamFragment.StartOffset;
                relativeCodecStreamBuilder.ReferenceHeaderOffset = codecStreamFragment.ReferenceHeaderOffset;
                relativeCodecStreamBuilder.ReferenceHeader       = codecStreamFragment.ReferenceHeader;
            }
        private void AddPayload(IDataBlockBuilder dataBlockBuilder, IDictionary <byte, ICodecStreamBuilder> codecStreamBuilders, Payload payload, CodecListObject codecList, AsfObject asfObject)
        {
            if (payload.Streams == null || payload.Streams.Count == 0)
            {
                return;
            }

            byte streamNumber = payload.StreamNumber;

            if (codecStreamBuilders.ContainsKey(streamNumber))
            {
                ICodecStreamBuilder codecStreamBuilder = codecStreamBuilders[streamNumber];

                foreach (IDataPacket streamData in payload.Streams)
                {
                    codecStreamBuilder.Data = codecStreamBuilder.Data.Append(streamData);
                }
            }
            else
            {
                StreamPropertiesObject streamProperty = GetStreamProperty(asfObject, streamNumber);

                ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder.AddCodecStream();
                codecStreamBuilder.Name = GetCodecStreamName(streamNumber, streamProperty, codecList);
                // The DataFormat will be set by the codec detector (if one exists)
                //codecStreamBuilder.DataFormat = GetDataFormat(streamProperty);
                codecStreamBuilder.Data = GetStreamData(streamProperty, payload.Streams[0]);
                for (int streamIndex = 1; streamIndex < payload.Streams.Count; streamIndex++)
                {
                    codecStreamBuilder.Data = codecStreamBuilder.Data.Append(payload.Streams[streamIndex]);
                }
                codecStreamBuilder.AbsoluteStartOffset = codecStreamBuilder.Data.StartOffset;

                codecStreamBuilders.Add(streamNumber, codecStreamBuilder);
            }
        }
Пример #5
0
        private static void AddMovieEntry(IDataBlockBuilder dataBlockBuilder, IDictionary <byte, ICodecStreamBuilder> codecStreamBuilders, MovieEntry movieEntry, IEnumerable <HeaderList> headerLists)
        {
            if (movieEntry.StreamType != InformationType.AudioData &&
                movieEntry.StreamType != InformationType.UncompressedVideoFrame &&
                movieEntry.StreamType != InformationType.CompressedVideoFrame)
            {
                //if (movieEntry.StreamType == InformationType.PaletteChanged) { TODO ask Rikkert }
                return;
            }

            IDataPacket streamData = movieEntry.StreamData;

            if (streamData == null)
            {
                return;
            }

            byte channel = movieEntry.Channel;

            if (codecStreamBuilders.ContainsKey(channel))
            {
                ICodecStreamBuilder codecStreamBuilder = codecStreamBuilders[channel];
                codecStreamBuilder.Data = codecStreamBuilder.Data.Append(streamData);
            }
            else
            {
                ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder.AddCodecStream();
                codecStreamBuilder.Name = GetCodecStreamName(channel, movieEntry, headerLists);
                codecStreamBuilder.AbsoluteStartOffset = streamData.StartOffset;
                codecStreamBuilder.Data = streamData;

                // The DataFormat will be set by the codec detector (if one exists)
                //codecStreamBuilder.DataFormat = GetDataFormat(headerLists);
                codecStreamBuilders.Add(channel, codecStreamBuilder);
            }
        }
        public void SerializeProject()
        {
            IProject project = TestFramework.ProjectManager.CreateProject(ProjectPath, ProjectInvestigator, DateTime.Now, ProjectDescription);

            IDetector  systemDetector = TestFramework.DetectorFactory.ContainerDetectors.Single(x => x.Name == "MPEG-1/2 Systems");
            IDetector  videoDetector  = TestFramework.DetectorFactory.CodecDetectors.Single(x => x.Name == Mpeg2VideoDetector.DetectorName);
            IInputFile inputFile1     = project.AddFile(FileName1, new[] { systemDetector, videoDetector });
            IInputFile inputFile2     = project.AddFile(FileName2, new[] { videoDetector });

            IDataBlockBuilder dataBlockBuilder1 = TestFramework.CreateDataBlockBuilder();

            dataBlockBuilder1.DataFormat  = CodecID.Mpeg2System;
            dataBlockBuilder1.Detectors   = new[] { systemDetector };
            dataBlockBuilder1.InputFile   = inputFile1;
            dataBlockBuilder1.StartOffset = 0L;
            dataBlockBuilder1.EndOffset   = 20480L;
            dataBlockBuilder1.IsFullFile  = true;
            ICodecStreamBuilder codecStreamBuilder = dataBlockBuilder1.AddCodecStream();

            codecStreamBuilder.Name       = "Video Stream #1";
            codecStreamBuilder.DataFormat = CodecID.Mpeg2Video;
            codecStreamBuilder.Detector   = videoDetector;
            codecStreamBuilder.Data       = TestFramework.CreateDataPacket(inputFile1, 0L, 3033L);
            IDataBlock dataBlock1 = dataBlockBuilder1.Build();

            IDataBlockBuilder dataBlockBuilder2 = TestFramework.CreateDataBlockBuilder();

            dataBlockBuilder2.DataFormat  = CodecID.Mpeg2Video;
            dataBlockBuilder2.Detectors   = new[] { videoDetector };
            dataBlockBuilder2.InputFile   = inputFile1;
            dataBlockBuilder2.StartOffset = 130303L;
            dataBlockBuilder2.EndOffset   = 130327L;
            dataBlockBuilder2.IsFullFile  = false;
            IDataBlock dataBlock2 = dataBlockBuilder2.Build();

            IDataBlockBuilder dataBlockBuilder3 = TestFramework.CreateDataBlockBuilder();

            dataBlockBuilder3.DataFormat  = CodecID.Mpeg2Video;
            dataBlockBuilder3.Detectors   = new[] { videoDetector };
            dataBlockBuilder3.InputFile   = inputFile2;
            dataBlockBuilder3.StartOffset = 0L;
            dataBlockBuilder3.EndOffset   = FileLength2;
            dataBlockBuilder3.IsFullFile  = true;
            IDataBlock dataBlock3 = dataBlockBuilder3.Build();

            project.AddDataBlock(dataBlock1);
            project.AddDataBlock(dataBlock2);
            project.AddDataBlock(dataBlock3);
            project.SetMetadata(_fullMetadata);
//			project.SetVisibleColumns(systemDetector, TwoColumns);

            IProject deserializedProject;

            using (FileStream fileStream = new FileStream(_project.FileName, FileMode.Create))
            {
                TestFramework.CreateXmlObjectSerializer().WriteObject(fileStream, project);
            }
            using (FileStream fileStream = new FileStream(ProjectPath, FileMode.Open))
            {
                deserializedProject = TestFramework.CreateXmlObjectSerializer().ReadObject(fileStream) as IProject;
            }

            IList <IInputFile> inputFiles = deserializedProject.GetInputFiles();

            Assert.AreEqual(2, inputFiles.Count, "Serialization, input files (2 files)");
            AreEqual(inputFile1, inputFiles[0], "1");
            AreEqual(inputFile2, inputFiles[1], "2");

            IList <IDataBlock> dataBlocks = deserializedProject.GetDataBlocks(inputFiles[0]);

            Assert.AreEqual(2, dataBlocks.Count, "Serialization, data blocks (file 1, 2 blocks)");
            AreEqual(dataBlock1, dataBlocks[0], "1", "1");
            AreEqual(dataBlock2, dataBlocks[1], "1", "2");
            dataBlocks = deserializedProject.GetDataBlocks(inputFiles[1]);
            Assert.AreEqual(1, dataBlocks.Count, "Serialization, data blocks (file 2, 1 block)");
            AreEqual(dataBlock3, dataBlocks[0], "2", "1");

            IDictionary <ProjectMetadataKey, string> metadata = deserializedProject.GetMetadata();

            Assert.AreEqual(5, metadata.Count, "Serialization, metadata (5 entries)");
            Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.FileVersion), "Serialization, metadata (FileVersion)");
            Assert.AreEqual("1.0.0.4", metadata[ProjectMetadataKey.FileVersion], "Serialization, metadata (FileVersion)");
            Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.ProjectDescription), "Serialization, metadata (ProjectDescription)");
            Assert.AreEqual(ProjectDescription, metadata[ProjectMetadataKey.ProjectDescription], "Serialization, metadata (ProjectDescription)");
            Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.InvestigatorName), "Serialization, metadata (InvestigatorName)");
            Assert.AreEqual(ProjectInvestigator, metadata[ProjectMetadataKey.InvestigatorName], "Serialization, metadata (InvestigatorName)");
            Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.DateCreated), "Serialization, metadata (DateCreated)");
            Assert.AreEqual(ProjectCreationDate, metadata[ProjectMetadataKey.DateCreated], "Serialization, metadata (DateCreated)");
            Assert.IsTrue(metadata.ContainsKey(ProjectMetadataKey.DateLastModified), "Serialization, metadata (DateLastModified)");
            Assert.AreEqual(ProjectModificationDate, metadata[ProjectMetadataKey.DateLastModified], "Serialization, metadata (DateLastModified)");

            //IList<IColumnInfo> visibleColumns = deserializedProject.GetVisibleColumns(systemDetector);
            //Assert.AreEqual(2, visibleColumns.Count, "Serialization, visible columns (2 columns)");
            //Assert.IsTrue(visibleColumns.Contains(_columnInfo1), "Serialization, visible columns (column 1)");
            //Assert.IsTrue(visibleColumns.Contains(_columnInfo2), "Serialization, visible columns (column 2)");

            TestFramework.ProjectManager.CloseProject(project);
        }