Exemplo n.º 1
0
        public void TestPixelDeserialization(AdvSourceDataFormat dataFormat, byte dynaBits, CompressionType compression)
        {
            var fileGen = new AdvGenerator();
            var cfg     = new AdvGenerationConfig()
            {
                DynaBits         = dynaBits,
                SourceFormat     = dataFormat,
                NumberOfFrames   = 1,
                Compression      = compression,
                NormalPixelValue = null
            };

            string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            AdvFile2 file = null;

            try
            {
                // Generate
                fileGen.GenerateaAdv_V2(cfg, fileName);

                var    hasher = new Hasher();
                string h1     = hasher.CalcMd5(fileName);
                Console.WriteLine("File hash for {0} at {1} bits: {2}", dataFormat, dynaBits, h1);

                // Verify
                using (file = new AdvFile2(fileName))
                {
                    uint[] pixels = file.GetMainFramePixels(0);

                    var imageGenerator = new ImageGenerator();
                    var verified       = imageGenerator.VerifyImagePattern1UInt32(pixels, cfg.DynaBits);
                    Assert.IsTrue(verified);
                }
            }
            finally
            {
                try
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.WriteLine(ex);
                }
            }
        }
 public void Dispose()
 {
     if (m_AdvFile != null)
     {
         m_AdvFile.Close();
         m_AdvFile = null;
     }
 }
Exemplo n.º 3
0
        public void TestReadingFileWithErrorMessageInTheStatusChannel()
        {
            var fileGen = new AdvGenerator();
            var cfg     = new AdvGenerationConfig()
            {
                DynaBits             = 16,
                SourceFormat         = AdvSourceDataFormat.Format16BitUShort,
                NumberOfFrames       = 1,
                Compression          = CompressionType.Uncompressed,
                NormalPixelValue     = null,
                SystemErrorsCallback = delegate(int id) { return("Sample Error Message"); }
            };

            string fileName = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString("N"));

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }
            AdvFile2 file = null;

            try
            {
                // Generate
                fileGen.GenerateaAdv_V2(cfg, fileName);

                // Verify
                using (file = new AdvFile2(fileName))
                {
                    uint[] pixels = file.GetMainFramePixels(0);

                    var imageGenerator = new ImageGenerator();
                    var verified       = imageGenerator.VerifyImagePattern1UInt32(pixels, cfg.DynaBits);
                    Assert.IsTrue(verified);
                }
            }
            finally
            {
                try
                {
                    if (file != null)
                    {
                        file.Close();
                    }
                    if (File.Exists(fileName))
                    {
                        File.Delete(fileName);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                    Trace.WriteLine(ex);
                }
            }
        }
Exemplo n.º 4
0
        private static void MergeOverlappingAAVFiles(string file1, string file2)
        {
            string fileLocationOut = Path.GetFullPath(Path.GetDirectoryName(file1) + @"\" + Path.GetFileName(file1) + "-fixed.aav");

            int FIRST_FILE_FRAME_NO_SEC_FILE_ZERO = 110;

            var aaFile1 = new AdvFile2(file1);


            int FIRST_OSD_LINE = int.Parse(aaFile1.SystemMetadataTags["OSD-FIRST-LINE"]);
            int LAST_OSD_LINE  = int.Parse(aaFile1.SystemMetadataTags["OSD-LAST-LINE"]);
            int INTEGRATION    = (int)Math.Round(double.Parse(aaFile1.SystemMetadataTags["NATIVE-FRAME-RATE"]) / double.Parse(aaFile1.SystemMetadataTags["EFFECTIVE-FRAME-RATE"]));
            int FRAME_WIDTH    = int.Parse(aaFile1.SystemMetadataTags["WIDTH"]);
            int FRAME_HEIGHT   = int.Parse(aaFile1.SystemMetadataTags["HEIGHT"]);
            int FRAME_PIXELS   = FRAME_WIDTH * FRAME_HEIGHT;

            var frame = new ushort[FRAME_PIXELS];

            List <ushort[]> calFrames = new List <ushort[]>();

            // TODO: Frames of large AAV files should be saved in a temporary file to avoid running OutOfMemory
            List <ushort[]> mainFrames = new List <ushort[]>();
            List <Tuple <object, object, object> > mainFramesInfo = new List <Tuple <object, object, object> >();

            for (uint i = 0; i < aaFile1.CalibrationSteamInfo.FrameCount; i++)
            {
                var calPix = aaFile1.GetCalibrationFramePixels(i);
                for (int j = 0; j < FRAME_PIXELS; j++)
                {
                    frame[j] = (ushort)calPix[j];
                }
                calFrames.Add(frame.ToArray());
            }

            for (uint i = 0; i < FIRST_FILE_FRAME_NO_SEC_FILE_ZERO; i++)
            {
                AdvFrameInfo frameInfo;
                var          framePix = aaFile1.GetMainFramePixels(i, out frameInfo);
                for (int j = 0; j < FRAME_PIXELS; j++)
                {
                    frame[j] = (ushort)framePix[j];
                }

                mainFrames.Add(frame.ToArray());
                mainFramesInfo.Add(Tuple.Create(frameInfo.Status["IntegratedFrames"], frameInfo.Status["StartFrame"], frameInfo.Status["EndFrame"]));
            }
            aaFile1.Close();

            var aaFile2 = new AdvFile2(file2);

            for (uint i = 0; i < aaFile2.MainSteamInfo.FrameCount; i++)
            {
                AdvFrameInfo frameInfo;
                var          framePix = aaFile2.GetMainFramePixels(i, out frameInfo);
                for (int j = 0; j < FRAME_PIXELS; j++)
                {
                    frame[j] = (ushort)framePix[j];
                }

                mainFrames.Add(frame.ToArray());
                mainFramesInfo.Add(Tuple.Create(frameInfo.Status["IntegratedFrames"], frameInfo.Status["StartFrame"], frameInfo.Status["EndFrame"]));
            }
            aaFile2.Close();

            var recorder = new AdvRecorder();

            recorder.ImageConfig.SetImageParameters(
                (ushort)aaFile1.Width,
                (ushort)aaFile1.Height,
                (byte)aaFile1.DataBpp,
                aaFile1.MaxPixelValue);

            recorder.FileMetaData.RecorderSoftwareName    = "Tangra";
            recorder.FileMetaData.RecorderSoftwareVersion = VersionHelper.AssemblyVersion;
            recorder.FileMetaData.CameraModel             = "Unknown";
            recorder.FileMetaData.CameraSensorInfo        = "Unknown";

            var frameRate = 25.00;

            recorder.FileMetaData.NativeFrameRate    = frameRate;
            recorder.FileMetaData.EffectiveFrameRate = 25.0 / INTEGRATION;

            var nativeStandards = string.Empty;

            if (Math.Abs(frameRate - 25.0) < 0.1)
            {
                nativeStandards = "PAL";
            }
            else if (Math.Abs(frameRate - 29.97) < 0.1)
            {
                nativeStandards = "NTSC";
            }
            recorder.FileMetaData.AddUserTag("NATIVE-VIDEO-STANDARD", nativeStandards);
            recorder.FileMetaData.AddUserTag("FRAME-COMBINING", "Binning");
            recorder.FileMetaData.AddUserTag("OSD-FIRST-LINE", FIRST_OSD_LINE.ToString());
            recorder.FileMetaData.AddUserTag("OSD-LAST-LINE", LAST_OSD_LINE.ToString());
            recorder.FileMetaData.AddUserTag("AAV-VERSION", "2");
            recorder.FileMetaData.AddUserTag("AAV16-NORMVAL", (256 * INTEGRATION).ToString());

            recorder.FileMetaData.AddCalibrationStreamTag("TYPE", "VTI-OSD-CALIBRATION");
            recorder.FileMetaData.AddUserTag("OSD-FIRST-LINE", FIRST_OSD_LINE.ToString());
            recorder.FileMetaData.AddUserTag("OSD-LAST-LINE", LAST_OSD_LINE.ToString());

            recorder.StatusSectionConfig.RecordSystemErrors = true;
            recorder.StatusSectionConfig.AddDefineTag("FRAME-TYPE", Adv2TagType.UTF8String);
            recorder.StatusSectionConfig.AddDefineTag("ORIGINAL-FRAME-ID", Adv2TagType.Int32);
            recorder.StatusSectionConfig.AddDefineTag("IntegratedFrames", Adv2TagType.Int16);
            recorder.StatusSectionConfig.AddDefineTag("StartFrame", Adv2TagType.Long64);
            recorder.StatusSectionConfig.AddDefineTag("EndFrame", Adv2TagType.Long64);

            recorder.StartRecordingNewFile(fileLocationOut, 0, true);

            int calFrameId = 0;

            foreach (var calFrame in calFrames)
            {
                recorder.AddCalibrationFrame(calFrame, true,
                                             PreferredCompression.Lagarith16,
                                             new AdvRecorder.AdvStatusEntry()
                {
                    AdditionalStatusTags = new[] { "VTI-OSD-CALIBRATION", (object)calFrameId, (object)(short)0, (object)(long)0, (object)(long)0 }
                },
                                             Adv.AdvImageData.PixelDepth16Bit);
                calFrameId++;
            }

            for (int frameNo = 0; frameNo < mainFrames.Count; frameNo++)
            {
                Tuple <object, object, object> frameInfo = mainFramesInfo[frameNo];
                recorder.AddVideoFrame(mainFrames[frameNo], true,
                                       PreferredCompression.Lagarith16,
                                       new AdvRecorder.AdvStatusEntry()
                {
                    SystemErrors         = "",
                    AdditionalStatusTags = new[] { "DATA", (object)(int)frameNo, frameInfo.Item1, frameInfo.Item2, frameInfo.Item3 }
                },
                                       Adv.AdvImageData.PixelDepth16Bit);
            }

            recorder.FinishRecording();
        }