Ejemplo n.º 1
0
        /// <summary>
        /// Creates an anonymous usage record.  This method spends 10 seconds measuring CPU usage.  Returns null if any BlueIris.exe processes close while CPU usage is being measured, or if no BlueIris.exe processes were open.
        /// </summary>
        /// <returns></returns>
        private static Upload_Record GetPerfDataRecord()
        {
            Upload_Record record = new Upload_Record();

            BlueIrisConfiguration c = new BlueIrisConfiguration();

            c.Load();

            record.CpuUsage                = c.activeStats.CpuUsage;
            record.BiCpuUsage              = c.activeStats.BiCpuUsage;
            record.CpuThreads              = (short)Environment.ProcessorCount;
            record.BiVersion               = c.activeStats.BiVersion;
            record.BiMemUsageMB            = c.activeStats.BiMemUsageMB;
            record.BiPeakVirtualMemUsageMB = c.activeStats.BiPeakVirtualMemUsageMB;
            record.ConsoleOpen             = c.activeStats.ConsoleOpen;
            record.ConsoleWidth            = c.activeStats.ConsoleWidth;
            record.ConsoleHeight           = c.activeStats.ConsoleHeight;
            record.Secret = getSecretString();
            record.OS     = c.OS;

            if (c.cpu == null)
            {
                record.CpuModel = "Unknown";
                record.CpuMHz   = 0;
            }
            else
            {
                record.CpuModel = c.cpu.GetModel();
                record.CpuMHz   = NumberUtil.ParseInt(c.cpu.maxClockSpeed);
            }

            record.HelperVersion  = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
            record.HwAccel        = (byte)c.global.HardwareAcceleration;
            record.ServiceMode    = c.global.ServiceMode;
            record.LivePreviewFPS = (short)c.global.LivePreviewFPS;

            record.MemMB     = c.activeStats.MemMB;
            record.MemFreeMB = c.activeStats.MemFreeMB;

            record.RamGiB        = c.mem.GiB;
            record.RamChannels   = c.mem.Channels;
            record.DimmLocations = c.mem.DimmLocations;
            record.RamMHz        = c.mem.MHz;

            // Get camera info.
            // Get frame rates, current profile (only accessible via BI's web server).
            Dictionary <string, double> fpsMap = new Dictionary <string, double>();

            int  currentProfile = 1;
            bool isAdmin        = false;
            bool gotCamlist     = false;
            bool gotStatus      = false;

            BiServerInfo.Reload();
            //BiUserInfo.Reload();
            if (BiServerInfo.enabled)
            {
                try
                {
                    using (WebClient wc = new WebClient())
                    {
                        UserInfo user    = BiUserInfo.CreateTemporaryUser();
                        string   session = CameraWebInterfaceLinker.GetSecureAuthenticatedSession(wc, out isAdmin, user.name, user.GetDecodedPassword());
                        try
                        {
                            try
                            {
                                string          response        = wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"camlist\",\"session\":\"" + session + "\"}");
                                CamListResponse camListResponse = JsonConvert.DeserializeObject <CamListResponse>(response);
                                if (camListResponse != null && camListResponse.result == "success")
                                {
                                    foreach (CameraListCamera camera in camListResponse.data)
                                    {
                                        if (camera.group == null)
                                        {
                                            fpsMap[camera.optionValue] = camera.FPS;
                                        }
                                    }
                                    gotCamlist = true;
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.Debug(ex, "Error reading camera list from web server.");
                            }

                            try
                            {
                                string         response       = wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"status\",\"session\":\"" + session + "\"}");
                                StatusResponse statusResponse = JsonConvert.DeserializeObject <StatusResponse>(response);
                                if (statusResponse != null && statusResponse.result == "success")
                                {
                                    currentProfile = statusResponse.data.profile;
                                    gotStatus      = true;
                                    if (currentProfile < 1 || currentProfile > 7)
                                    {
                                        currentProfile = 1;
                                        gotStatus      = false;
                                    }
                                    else
                                    {
                                        record.ProfileConfirmed = true;
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                Logger.Debug(ex, "Error reading camera list from web server.");
                            }
                        }
                        finally
                        {
                            wc.UploadString(CameraWebInterfaceLinker.GetJsonURL(), "{\"cmd\":\"logout\",\"session\":\"" + session + "\"}");
                        }
                    }
                }
                catch (Exception ex)
                {
                    Logger.Debug(ex, "Error dealing with web server.");
                }
            }
            record.webserverState = 0;
            if (gotCamlist && gotStatus)
            {
                record.webserverState = 1;
                if (isAdmin)                 // and any future admin-requiring stuff all worked
                {
                    record.webserverState = 2;
                }
            }


            // Get camera info
            List <Upload_Camera> cameras = new List <Upload_Camera>();

            foreach (Camera camSrc in c.cameras.Values)
            {
                if (!camSrc.enabled)
                {
                    continue;
                }

                Upload_Camera cam = new Upload_Camera();

                if (fpsMap.TryGetValue(camSrc.shortname, out double fps))
                {
                    cam.FPS          = (byte)Math.Round(fps).Clamp(0, 255);
                    cam.FPSConfirmed = true;
                }
                else
                {
                    cam.FPS = (byte)(Math.Round(camSrc.MaxRate).Clamp(0, 255));
                }
                cam.CapType     = (byte)camSrc.CapType;
                cam.Hwaccel     = (byte)camSrc.Hwva;
                cam.LimitDecode = camSrc.LimitDecode;
                cam.Pixels      = camSrc.Pixels;
                if (camSrc.hasSubStream)
                {
                    cam.MainPixels = camSrc.MainPixels;
                }
                cam.Type              = (byte)camSrc.Type;
                cam.MotionDetector    = camSrc.triggerSettings[currentProfile].motionDetectionEnabled;
                cam.RecordTriggerType = (byte)camSrc.recordSettings[currentProfile].triggerType;
                cam.RecordFormat      = (byte)camSrc.recordSettings[currentProfile].recordingFormat;
                cam.DirectToDisk      = camSrc.recordSettings[currentProfile].DirectToDisc;
                cam.VCodec            = camSrc.recordSettings[currentProfile].VCodec;
                cameras.Add(cam);
            }

            record.AllFPSConfirmed = cameras.All(cam => cam.FPSConfirmed);             // Ignored and recalculated by server. This exists here for the sake of local json output.
            record.cameras         = cameras.ToArray();
            record.gpus            = c.gpus.Select(g => new Upload_Gpu()
            {
                Name = g.Name, Version = g.DriverVersion
            }).ToArray();

            record.Total_FPS = record.Total_Megapixels = record.Total_MPPS = 0;
            foreach (Upload_Camera cam in cameras)
            {
                float MP = cam.Pixels / 1000000f;
                record.Total_Megapixels += MP;
                record.Total_FPS        += cam.FPS;
                record.Total_MPPS       += MP * cam.FPS;
            }

            return(record);
        }
Ejemplo n.º 2
0
        private void AdviceThread()
        {
            try
            {
                BlueIrisConfiguration c = new BlueIrisConfiguration();
                c.Load();
                if (c.global == null)
                {
                    error = "Unable to generate advice. Blue Iris may not be installed properly.";
                    return;
                }
                if (c.BiVersionBytes[0] != 5)
                {
                    error = "Unable to generate advice. Detected an unsupported Blue Iris version \"" + c.BiVersionFromRegistry + "\".";
                    return;
                }

                List <AdviceBase> listAdvice = new List <AdviceBase>();

                foreach (Camera cam in c.cameras.Values)
                {
                    if (cam.Type == CameraType.Network)
                    {
                        List <int> profilesWithDirectToDiscDisabled = new List <int>();
                        for (int profile = 1; profile < cam.recordSettings.Length; profile++)
                        {
                            RecordTabSettings recordSettings = cam.recordSettings[profile];
                            if (string.IsNullOrEmpty(recordSettings.camsync))
                            {
                                // We only care about settings that are not automatically copied from another camera.
                                if (!recordSettings.DirectToDisc)
                                {
                                    profilesWithDirectToDiscDisabled.Add(profile);
                                }
                            }
                        }

                        if (profilesWithDirectToDiscDisabled.Count > 0)
                        {
                            listAdvice.Add(new EnableDirectToDiscAdvice(c, cam.name, profilesWithDirectToDiscDisabled.ToArray()));
                        }
                    }
                }

                bool hasIntelGPU  = c.gpus.Any(gpu => gpu.Intel);
                bool hasNvidiaGPU = c.gpus.Any(gpu => gpu.Nvidia);
                if (hasIntelGPU)
                {
                    if (c.global.HardwareAcceleration == HWAccel.Intel)
                    {
                        // Good!
                    }
                    else if (c.global.HardwareAcceleration == HWAccel.IntelVPP && c.cameras.Count > 4)
                    {
                        listAdvice.Add(new DontUseVPPAdvice(c));
                    }
                    else
                    {
                        listAdvice.Add(new UseIntelHwvaAdvice(c));
                    }
                }
                else if (hasNvidiaGPU)
                {
                    if (c.global.HardwareAcceleration == HWAccel.Intel || c.global.HardwareAcceleration == HWAccel.IntelVPP)
                    {
                        listAdvice.Add(new UseNvidiaHwvaAdvice(c));
                    }
                    else if (c.global.HardwareAcceleration == HWAccel.No && c.activeStats.BiCpuUsage > 50)
                    {
                        listAdvice.Add(new UseNvidiaHwvaAdvice(c));
                    }
                }
                else
                {
                    if (c.global.HardwareAcceleration != HWAccel.No)
                    {
                        listAdvice.Add(new UseNoHwvaAdvice(c));
                    }
                }

                AdviceReady(this, listAdvice);
            }
            catch (ThreadAbortException) { }
            catch (Exception ex)
            {
                Logger.Debug(ex);
                error = "An error occurred: " + ex.Message + Environment.NewLine + "See log for more information.";
            }
            finally
            {
                if (error != null)
                {
                    AdviceReady(this, null);
                }
            }
        }